Skip to content

Commit b9eb737

Browse files
committed
Do not assign different @@toStringTag to URL.prototype
For performance and consistency with Chrome.
1 parent 2616fd9 commit b9eb737

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

lib/internal/url.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,6 @@ class URL {
221221
if (base !== undefined && !(base instanceof URL))
222222
base = new URL(String(base));
223223
parse(this, input, base);
224-
225-
Object.defineProperty(this, Symbol.toStringTag, {
226-
configurable: true,
227-
value: 'URL'
228-
});
229224
}
230225

231226
get [special]() {
@@ -317,7 +312,7 @@ Object.defineProperties(URL.prototype, {
317312
},
318313
[Symbol.toStringTag]: {
319314
configurable: true,
320-
value: 'URLPrototype'
315+
value: 'URL'
321316
},
322317
href: {
323318
enumerable: true,

test/parallel/test-whatwg-url-properties.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ assert.strictEqual(url.searchParams, oldParams); // [SameObject]
4545
// Note: this error message is subject to change in V8 updates
4646
assert.throws(() => url.origin = 'http://foo.bar.com:22',
4747
new RegExp('TypeError: Cannot set property origin of' +
48-
' \\[object URLPrototype\\] which has only a getter'));
48+
' \\[object URL\\] which has only a getter'));
4949
assert.strictEqual(url.origin, 'http://foo.bar.com:21');
5050
assert.strictEqual(url.toString(),
5151
'http://user:pass@foo.bar.com:21/aaa/zzz?l=25#test');
@@ -121,7 +121,7 @@ assert.strictEqual(url.hash, '#abcd');
121121
// Note: this error message is subject to change in V8 updates
122122
assert.throws(() => url.searchParams = '?k=88',
123123
new RegExp('TypeError: Cannot set property searchParams of' +
124-
' \\[object URLPrototype\\] which has only a getter'));
124+
' \\[object URL\\] which has only a getter'));
125125
assert.strictEqual(url.searchParams, oldParams);
126126
assert.strictEqual(url.toString(),
127127
'https://user2:pass2@foo.bar.org:23/aaa/bbb?k=99#abcd');

test/parallel/test-whatwg-url-tostringtag.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ const sp = url.searchParams;
1010

1111
const test = [
1212
[toString.call(url), 'URL'],
13-
[toString.call(Object.getPrototypeOf(url)), 'URLPrototype'],
1413
[toString.call(sp), 'URLSearchParams'],
15-
[toString.call(Object.getPrototypeOf(sp)), 'URLSearchParamsPrototype']
14+
[toString.call(Object.getPrototypeOf(sp)), 'URLSearchParamsPrototype'],
15+
// Web IDL spec says we have to return 'URLPrototype', but it is too
16+
// expensive to implement; therefore, use Chrome's behavior for now, until
17+
// spec is changed.
18+
[toString.call(Object.getPrototypeOf(url)), 'URL']
1619
];
1720

1821
test.forEach((row) => {

0 commit comments

Comments
 (0)