Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 95faa55

Browse filesBrowse files
TimothyGuItalo A. Casas
authored andcommitted
url: check forEach callback is a function
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>
1 parent 8778fca commit 95faa55
Copy full SHA for 95faa55

File tree

Expand file treeCollapse file tree

2 files changed

+22
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-10
lines changed
Open diff view settings
Collapse file

‎lib/internal/url.js‎

Copy file name to clipboardExpand all lines: lib/internal/url.js
+8-10Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,7 @@ class URLSearchParams {
672672
throw new TypeError('Value of `this` is not a URLSearchParams');
673673
}
674674
if (arguments.length < 2) {
675-
throw new TypeError(
676-
'Both `name` and `value` arguments need to be specified');
675+
throw new TypeError('"name" and "value" arguments must be specified');
677676
}
678677

679678
name = String(name);
@@ -687,7 +686,7 @@ class URLSearchParams {
687686
throw new TypeError('Value of `this` is not a URLSearchParams');
688687
}
689688
if (arguments.length < 1) {
690-
throw new TypeError('The `name` argument needs to be specified');
689+
throw new TypeError('"name" argument must be specified');
691690
}
692691

693692
const list = this[searchParams];
@@ -708,8 +707,7 @@ class URLSearchParams {
708707
throw new TypeError('Value of `this` is not a URLSearchParams');
709708
}
710709
if (arguments.length < 2) {
711-
throw new TypeError(
712-
'Both `name` and `value` arguments need to be specified');
710+
throw new TypeError('"name" and "value" arguments must be specified');
713711
}
714712

715713
const list = this[searchParams];
@@ -749,7 +747,7 @@ class URLSearchParams {
749747
throw new TypeError('Value of `this` is not a URLSearchParams');
750748
}
751749
if (arguments.length < 1) {
752-
throw new TypeError('The `name` argument needs to be specified');
750+
throw new TypeError('"name" argument must be specified');
753751
}
754752

755753
const list = this[searchParams];
@@ -767,7 +765,7 @@ class URLSearchParams {
767765
throw new TypeError('Value of `this` is not a URLSearchParams');
768766
}
769767
if (arguments.length < 1) {
770-
throw new TypeError('The `name` argument needs to be specified');
768+
throw new TypeError('"name" argument must be specified');
771769
}
772770

773771
const list = this[searchParams];
@@ -786,7 +784,7 @@ class URLSearchParams {
786784
throw new TypeError('Value of `this` is not a URLSearchParams');
787785
}
788786
if (arguments.length < 1) {
789-
throw new TypeError('The `name` argument needs to be specified');
787+
throw new TypeError('"name" argument must be specified');
790788
}
791789

792790
const list = this[searchParams];
@@ -814,8 +812,8 @@ class URLSearchParams {
814812
if (!this || !(this instanceof URLSearchParams)) {
815813
throw new TypeError('Value of `this` is not a URLSearchParams');
816814
}
817-
if (arguments.length < 1) {
818-
throw new TypeError('The `callback` argument needs to be specified');
815+
if (typeof callback !== 'function') {
816+
throw new TypeError('"callback" argument must be a function');
819817
}
820818

821819
let list = this[searchParams];
Collapse file

‎test/parallel/test-whatwg-url-searchparams.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-searchparams.js
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ n = 0;
4444
for (val of sp.values()) {
4545
assert.strictEqual(val, String(values[n++]));
4646
}
47+
n = 0;
48+
sp.forEach(function(val, key, obj) {
49+
assert.strictEqual(this, undefined);
50+
assert.strictEqual(key, 'a');
51+
assert.strictEqual(val, String(values[n++]));
52+
assert.strictEqual(obj, sp);
53+
});
54+
sp.forEach(function() {
55+
assert.strictEqual(this, m);
56+
}, m);
57+
assert.throws(() => sp.forEach(),
58+
/^TypeError: "callback" argument must be a function$/);
59+
assert.throws(() => sp.forEach(1),
60+
/^TypeError: "callback" argument must be a function$/);
4761

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.