| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| if (arguments.length < 1) { | ||
| throw new TypeError('The `callback` argument needs to be specified'); | ||
| } | ||
| if (typeof callback !== 'function') { |
There was a problem hiding this comment.
Does this make the check on line 817 obsolete?
Sorry, something went wrong.
There was a problem hiding this comment.
@cjihrig, this provides more granular error messages, which I think is a good thing. Do you prefer me to just use the same error message for both cases?
In the browser, they have different error messages as well:
>> new URLSearchParams().forEach()
** TypeError: Failed to execute 'forEach' on 'URLSearchParams':
1 argument required, but only 0 present.
>> new URLSearchParams().forEach(2)
** TypeError: Failed to execute 'forEach' on 'URLSearchParams':
The callback provided as parameter 1 is not a function.
Sorry, something went wrong.
There was a problem hiding this comment.
I would remove the extraneous check as suggested
Sorry, something went wrong.
There was a problem hiding this comment.
Our error messages don't even seem to match up though. I'd still change it, but I won't fight it too much.
Sorry, something went wrong.
There was a problem hiding this comment.
Changed.
Sorry, something went wrong.
| sp.forEach(function() { | ||
| assert.strictEqual(this, m); | ||
| }, m); | ||
| assert.throws(() => sp.forEach(), TypeError); |
There was a problem hiding this comment.
Instead of the TypeError constructor, can you pass a regular expression like /^TypeError: The callback argument must be a function$/
Sorry, something went wrong.
There was a problem hiding this comment.
Fixed.
Sorry, something went wrong.
|
/cc @nodejs/url |
Sorry, something went wrong.
| throw new TypeError('The `callback` argument needs to be specified'); | ||
| } | ||
| if (typeof callback !== 'function') { | ||
| throw new TypeError('The `callback` argument must be a function'); |
There was a problem hiding this comment.
our standard way of writing this would be TypeError('"callback" argument must be a function')
Sorry, something went wrong.
There was a problem hiding this comment.
Fixed.
Sorry, something went wrong.
Sorry, something went wrong.
The Web IDL spec mandates such a check. Also make error messages consistent with rest of Node.js and add additional tests for forEach(). PR-URL: #10905 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
The Web IDL spec mandates such a check. Also make error messages consistent with rest of Node.js and add additional tests for forEach(). PR-URL: nodejs#10905 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
The Web IDL spec mandates such a check. Also make error messages consistent with rest of Node.js and add additional tests for forEach(). PR-URL: nodejs#10905 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
The Web IDL spec mandates such a check. Also make error messages consistent with rest of Node.js and add additional tests for forEach(). PR-URL: nodejs#10905 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
The Web IDL spec mandates such a check. Also make error messages consistent with rest of Node.js and add additional tests for forEach(). PR-URL: nodejs#10905 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
| Back | FazBrowse Home | New Git URL |
Currently, URLSearchParams' forEach function does not have a check to make sure that the type of the provided callback is a function. However, the Web IDL spec, to which this function should conform, insists that a TypeError be thrown if the callback is not callable.
This PR fulfills that requirement. Also included in this PR are additional tests for certain aspects of forEach that are defined in the spec but not yet tested.
Web IDL defines forEach as the following:
callback therefore has type Function, which in turn is defined as a callback function:
The process to convert an ECMAScript value to an IDL callback function then contains the following:
And since callback is not declared with [TreatNonObjectAsNull], forEach should throw a TypeError in case callback is not a function.
Checklist
Affected core subsystem(s)
url