-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
dns: refactor dns to more modern JavaScript #5762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8d6c22e
f5c4f55
2784847
48fde13
bfe0f40
2d54ae9
85f9b87
457de39
4f124f7
6fe93ed
b3ced41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,7 @@ function makeAsync(callback) { | |
| return function asyncCallback() { | ||
| if (asyncCallback.immediately) { | ||
| // The API already returned, we can invoke the callback immediately. | ||
| callback(...arguments); | ||
| callback.apply(null, arguments); | ||
| } else { | ||
| var args = new Array(arguments.length + 1); | ||
| args[0] = callback; | ||
|
|
@@ -96,12 +96,12 @@ function onlookupall(err, addresses) { | |
| } | ||
|
|
||
| const results = Array(addresses.length); | ||
|
|
||
| for (var i = 0; i < addresses.length; i++) { | ||
| results.push({ | ||
| results[i] = { | ||
| address: addresses[i], | ||
| family: this.family || (addresses[i].indexOf(':') >= 0 ? 6 : 4) | ||
| }); | ||
| }; | ||
| } | ||
|
|
||
| this.callback(null, results); | ||
|
|
@@ -182,7 +182,8 @@ exports.lookup = function lookup(hostname, options, callback) { | |
|
|
||
| function onlookupservice(err, host, service) { | ||
| if (err) { | ||
| return this.callback(errnoException(err, 'getnameinfo', this.host)); | ||
| this.callback(errnoException(err, 'getnameinfo', this.host)); | ||
| return; | ||
| } | ||
|
|
||
| this.callback(null, host, service); | ||
|
|
@@ -192,7 +193,7 @@ function onlookupservice(err, host, service) { | |
| // lookupService(address, port, callback) | ||
| exports.lookupService = function(host, port, callback) { | ||
| if (arguments.length !== 3) { | ||
| throw new Error('Invalid arguments'); | ||
| throw new TypeError(`Expected 3 arguments, got ${arguments.length}`); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't really a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the type of For example - when you call I don't feel very strongly about this - but the language and most APIs I know throw type errors in this case. |
||
| } | ||
|
|
||
| if (cares.isIP(host) === 0) { | ||
|
|
@@ -236,9 +237,10 @@ function resolver(bindingName) { | |
|
|
||
| return function query(name, callback) { | ||
| if (typeof name !== 'string') { | ||
| throw new Error('"name" argument must be a string'); | ||
| const msg = `"name" argument must be a string, got ${typeof name}`; | ||
| throw new TypeError(msg); | ||
| } else if (typeof callback !== 'function') { | ||
| throw new Error('"callback" argument must be a function'); | ||
| throw new TypeError('"callback" argument must be a function'); | ||
| } | ||
|
|
||
| callback = makeAsync(callback); | ||
|
|
@@ -272,7 +274,7 @@ exports.resolveSoa = resolveMap.SOA = resolver('querySoa'); | |
| exports.reverse = resolver('getHostByAddr'); | ||
|
|
||
|
|
||
| exports.resolve = function(hostname, type_, callback_) { | ||
| exports.resolve = (hostname, type_, callback_) => { | ||
| var resolver, callback; | ||
| if (typeof type_ === 'string') { | ||
| resolver = resolveMap[type_]; | ||
|
|
@@ -292,7 +294,7 @@ exports.resolve = function(hostname, type_, callback_) { | |
| }; | ||
|
|
||
|
|
||
| exports.getServers = function() { | ||
| exports.getServers = () => { | ||
| return cares.getServers(); | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exports.getServers = () => cares.getServers();Are the curlys required by coding convention here? ::shrugs::
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think they're required in multi-line functions. I recall talking about it but I'm not sure what conclusion was reached and I'm fine with either - @thefourtheye ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember the discussion regarding the parens in arrow function parameters, but not sure about the body. I'll have to look. But I feel that having curly braces for even a single expression kinda beats the purpose of arrow functions. |
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For array instantiation like this
newshould be used. Also,results.push()below will need to be changed too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks