Skip to content

Commit

Permalink
url: check forEach callback is a function
Browse files Browse the repository at this point in the history
Per spec.
  • Loading branch information
TimothyGu committed Jan 20, 2017
1 parent f0f65de commit 44acced
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

let list = this[searchParams];

Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-whatwg-url-searchparams.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ sp.forEach(function(val, key, obj) {
sp.forEach(function() {
assert.strictEqual(this, m);
}, m);
assert.throws(() => sp.forEach(), TypeError);
assert.throws(() => sp.forEach(1), TypeError);

m.search = '?a=a&b=b';
assert.strictEqual(sp.toString(), 'a=a&b=b');

0 comments on commit 44acced

Please sign in to comment.