Skip to content

Commit 2616fd9

Browse files
committed
url: do not define @@toStringTag with a getter
1 parent 0ee8fdb commit 2616fd9

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/internal/url.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,11 @@ class URL {
221221
if (base !== undefined && !(base instanceof URL))
222222
base = new URL(String(base));
223223
parse(this, input, base);
224-
}
225224

226-
get [Symbol.toStringTag]() {
227-
return this instanceof URL ? 'URL' : 'URLPrototype';
225+
Object.defineProperty(this, Symbol.toStringTag, {
226+
configurable: true,
227+
value: 'URL'
228+
});
228229
}
229230

230231
get [special]() {
@@ -314,6 +315,10 @@ Object.defineProperties(URL.prototype, {
314315
return ret;
315316
}
316317
},
318+
[Symbol.toStringTag]: {
319+
configurable: true,
320+
value: 'URLPrototype'
321+
},
317322
href: {
318323
enumerable: true,
319324
configurable: 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 Object\\] which has only a getter'));
48+
' \\[object URLPrototype\\] which has only a getter'));
4949
assert.strictEqual(url.origin, 'http://foo.bar.com:21');
5050
assert.strictEqual(url.toString(),
5151
'http://user:[email protected]: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 Object\\] which has only a getter'));
124+
' \\[object URLPrototype\\] which has only a getter'));
125125
assert.strictEqual(url.searchParams, oldParams);
126126
assert.strictEqual(url.toString(),
127127
'https://user2:[email protected]:23/aaa/bbb?k=99#abcd');

0 commit comments

Comments
 (0)