url: set toStringTag for the URL class
PR-URL: https://github.com/nodejs/node/pull/10562 Fixes: https://github.com/nodejs/node/issues/10554 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
134481dbe9
commit
f5d92f3563
@ -222,6 +222,10 @@ class URL {
|
|||||||
parse(this, input, base);
|
parse(this, input, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get [Symbol.toStringTag]() {
|
||||||
|
return this instanceof URL ? 'URL' : 'URLPrototype';
|
||||||
|
}
|
||||||
|
|
||||||
get [special]() {
|
get [special]() {
|
||||||
return (this[context].flags & binding.URL_FLAGS_SPECIAL) !== 0;
|
return (this[context].flags & binding.URL_FLAGS_SPECIAL) !== 0;
|
||||||
}
|
}
|
||||||
@ -641,15 +645,11 @@ class URLSearchParams {
|
|||||||
|
|
||||||
// "associated url object"
|
// "associated url object"
|
||||||
this[context] = null;
|
this[context] = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Class string for an instance of URLSearchParams. This is different from
|
get [Symbol.toStringTag]() {
|
||||||
// the class string of the prototype object (set below).
|
return this instanceof URLSearchParams ?
|
||||||
Object.defineProperty(this, Symbol.toStringTag, {
|
'URLSearchParams' : 'URLSearchParamsPrototype';
|
||||||
value: 'URLSearchParams',
|
|
||||||
writable: false,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
append(name, value) {
|
append(name, value) {
|
||||||
@ -804,12 +804,6 @@ class URLSearchParams {
|
|||||||
}
|
}
|
||||||
// https://heycam.github.io/webidl/#es-iterable-entries
|
// https://heycam.github.io/webidl/#es-iterable-entries
|
||||||
URLSearchParams.prototype[Symbol.iterator] = URLSearchParams.prototype.entries;
|
URLSearchParams.prototype[Symbol.iterator] = URLSearchParams.prototype.entries;
|
||||||
Object.defineProperty(URLSearchParams.prototype, Symbol.toStringTag, {
|
|
||||||
value: 'URLSearchParamsPrototype',
|
|
||||||
writable: false,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
|
|
||||||
// https://heycam.github.io/webidl/#dfn-default-iterator-object
|
// https://heycam.github.io/webidl/#dfn-default-iterator-object
|
||||||
function createSearchParamsIterator(target, kind) {
|
function createSearchParamsIterator(target, kind) {
|
||||||
|
21
test/parallel/test-whatwg-url-tostringtag.js
Normal file
21
test/parallel/test-whatwg-url-tostringtag.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const URL = require('url').URL;
|
||||||
|
const toString = Object.prototype.toString;
|
||||||
|
|
||||||
|
const url = new URL('http://example.org');
|
||||||
|
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']
|
||||||
|
];
|
||||||
|
|
||||||
|
test.forEach((row) => {
|
||||||
|
assert.strictEqual(row[0], `[object ${row[1]}]`,
|
||||||
|
`${row[0]} !== [object ${row[1]}]`);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user