mirror of
https://github.com/nodejs/node.git
synced 2025-05-14 15:26:29 +00:00

Even though this is not fully Web IDL spec-compliant, it is arguably the best we can do. Following the spec would mean non-trivial performance deterioration (10% when parsing a medium-length URL), while the current getter behavior is not adopted by any implementer, and it causes some spec ambiguity when the getter is called with !(this instanceof URL). This commit adopts Chrome's behavior, and is consistent with ECMAScript-defined classes while providing reasonable behaviors for corner cases as well. Until the Web IDL spec is changed one way or another, this is the way to go. PR-URL: https://github.com/nodejs/node/pull/10906 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
25 lines
747 B
JavaScript
25 lines
747 B
JavaScript
'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(sp), 'URLSearchParams'],
|
|
[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) => {
|
|
assert.strictEqual(row[0], `[object ${row[1]}]`,
|
|
`${row[0]} !== [object ${row[1]}]`);
|
|
});
|