-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
url: check forEach callback is a function #10905
Changes from 2 commits
f0f65de
44acced
182ce97
c6f5900
6775629
593a0d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -817,6 +817,9 @@ class URLSearchParams { | |
if (arguments.length < 1) { | ||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. our standard way of writing this would be 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. Fixed. |
||
} | ||
|
||
let list = this[searchParams]; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,18 @@ n = 0; | |
for (val of sp.values()) { | ||
assert.strictEqual(val, String(values[n++])); | ||
} | ||
n = 0; | ||
sp.forEach(function(val, key, obj) { | ||
assert.strictEqual(this, undefined); | ||
assert.strictEqual(key, 'a'); | ||
assert.strictEqual(val, String(values[n++])); | ||
assert.strictEqual(obj, sp); | ||
}); | ||
sp.forEach(function() { | ||
assert.strictEqual(this, m); | ||
}, m); | ||
assert.throws(() => sp.forEach(), TypeError); | ||
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. Instead of the 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. Fixed. |
||
assert.throws(() => sp.forEach(1), TypeError); | ||
|
||
m.search = '?a=a&b=b'; | ||
assert.strictEqual(sp.toString(), 'a=a&b=b'); |
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.
Does this make the check on line 817 obsolete?
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.
@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:
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.
I would remove the extraneous check as suggested
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.
Our error messages don't even seem to match up though. I'd still change it, but I won't fight it too much.
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.
Changed.