Skip to content

Commit

Permalink
url: do not define @@toStringTag with a getter
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Jan 27, 2017
1 parent 0ee8fdb commit 2616fd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,11 @@ class URL {
if (base !== undefined && !(base instanceof URL))
base = new URL(String(base));
parse(this, input, base);
}

get [Symbol.toStringTag]() {
return this instanceof URL ? 'URL' : 'URLPrototype';
Object.defineProperty(this, Symbol.toStringTag, {
configurable: true,
value: 'URL'
});
}

get [special]() {
Expand Down Expand Up @@ -314,6 +315,10 @@ Object.defineProperties(URL.prototype, {
return ret;
}
},
[Symbol.toStringTag]: {
configurable: true,
value: 'URLPrototype'
},
href: {
enumerable: true,
configurable: true,
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-whatwg-url-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ assert.strictEqual(url.searchParams, oldParams); // [SameObject]
// Note: this error message is subject to change in V8 updates
assert.throws(() => url.origin = 'http://foo.bar.com:22',
new RegExp('TypeError: Cannot set property origin of' +
' \\[object Object\\] which has only a getter'));
' \\[object URLPrototype\\] which has only a getter'));
assert.strictEqual(url.origin, 'http://foo.bar.com:21');
assert.strictEqual(url.toString(),
'http://user:[email protected]:21/aaa/zzz?l=25#test');
Expand Down Expand Up @@ -121,7 +121,7 @@ assert.strictEqual(url.hash, '#abcd');
// Note: this error message is subject to change in V8 updates
assert.throws(() => url.searchParams = '?k=88',
new RegExp('TypeError: Cannot set property searchParams of' +
' \\[object Object\\] which has only a getter'));
' \\[object URLPrototype\\] which has only a getter'));
assert.strictEqual(url.searchParams, oldParams);
assert.strictEqual(url.toString(),
'https://user2:[email protected]:23/aaa/bbb?k=99#abcd');
Expand Down

0 comments on commit 2616fd9

Please sign in to comment.