diff --git a/lib/internal/url.js b/lib/internal/url.js index 9ab469c9ff..84e04ee9d8 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -223,10 +223,6 @@ class URL { parse(this, input, base); } - get [Symbol.toStringTag]() { - return this instanceof URL ? 'URL' : 'URLPrototype'; - } - get [special]() { return (this[context].flags & binding.URL_FLAGS_SPECIAL) !== 0; } @@ -314,6 +310,10 @@ Object.defineProperties(URL.prototype, { return ret; } }, + [Symbol.toStringTag]: { + configurable: true, + value: 'URL' + }, href: { enumerable: true, configurable: true, diff --git a/test/parallel/test-whatwg-url-properties.js b/test/parallel/test-whatwg-url-properties.js index 0b5e633677..b762659fb6 100644 --- a/test/parallel/test-whatwg-url-properties.js +++ b/test/parallel/test-whatwg-url-properties.js @@ -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 URL\\] which has only a getter')); assert.strictEqual(url.origin, 'http://foo.bar.com:21'); assert.strictEqual(url.toString(), 'http://user:pass@foo.bar.com:21/aaa/zzz?l=25#test'); @@ -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 URL\\] which has only a getter')); assert.strictEqual(url.searchParams, oldParams); assert.strictEqual(url.toString(), 'https://user2:pass2@foo.bar.org:23/aaa/bbb?k=99#abcd'); diff --git a/test/parallel/test-whatwg-url-tostringtag.js b/test/parallel/test-whatwg-url-tostringtag.js index 9e0927955f..55b0a48ce7 100644 --- a/test/parallel/test-whatwg-url-tostringtag.js +++ b/test/parallel/test-whatwg-url-tostringtag.js @@ -10,9 +10,12 @@ const sp = url.searchParams; const test = [ [toString.call(url), 'URL'], - [toString.call(Object.getPrototypeOf(url)), 'URLPrototype'], [toString.call(sp), 'URLSearchParams'], - [toString.call(Object.getPrototypeOf(sp)), 'URLSearchParamsPrototype'] + [toString.call(Object.getPrototypeOf(sp)), 'URLSearchParamsPrototype'], + // Web IDL spec says we have to return 'URLPrototype', but it is too + // expensive to implement; therefore, use Chrome's behavior for now, until + // spec is changed. + [toString.call(Object.getPrototypeOf(url)), 'URL'] ]; test.forEach((row) => {