mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
lib,url: correct URL's argument to pass idlharness
`url.idl` defines URL's constructor as: ``` constructor(USVString url, optional USVString base); ``` `idlharness.any.js` checks its length as `1`. So we should remove constructor's second argument and use `arguments[1]` in constructor's logic. Refs: https://url.spec.whatwg.org/#idl-index PR-URL: https://github.com/nodejs/node/pull/39848 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
31772a4e85
commit
48655e17e1
@ -621,7 +621,7 @@ function isURLThis(self) {
|
||||
}
|
||||
|
||||
class URL {
|
||||
constructor(input, base) {
|
||||
constructor(input, base = undefined) {
|
||||
// toUSVString is not needed.
|
||||
input = `${input}`;
|
||||
let base_context;
|
||||
|
@ -288,6 +288,7 @@ class WPTRunner {
|
||||
this.resource = new ResourceLoader(path);
|
||||
|
||||
this.flags = [];
|
||||
this.dummyGlobalThisScript = null;
|
||||
this.initScript = null;
|
||||
|
||||
this.status = new StatusLoader(path);
|
||||
@ -318,6 +319,43 @@ class WPTRunner {
|
||||
this.initScript = script;
|
||||
}
|
||||
|
||||
get fullInitScript() {
|
||||
if (this.initScript === null && this.dummyGlobalThisScript === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.initScript === null) {
|
||||
return this.dummyGlobalThisScript;
|
||||
} else if (this.dummyGlobalThisScript === null) {
|
||||
return this.initScript;
|
||||
}
|
||||
|
||||
return `${this.fullInitScript}\n\n//===\n${this.initScript}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pretend the runner is run in `name`'s environment (globalThis).
|
||||
* @param {'Window'} name
|
||||
* @see {@link https://github.com/nodejs/node/blob/24673ace8ae196bd1c6d4676507d6e8c94cf0b90/test/fixtures/wpt/resources/idlharness.js#L654-L671}
|
||||
*/
|
||||
pretendGlobalThisAs(name) {
|
||||
switch (name) {
|
||||
case 'Window': {
|
||||
this.dummyGlobalThisScript =
|
||||
'global.Window = Object.getPrototypeOf(globalThis).constructor;';
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO(XadillaX): implement `ServiceWorkerGlobalScope`,
|
||||
// `DedicateWorkerGlobalScope`, etc.
|
||||
//
|
||||
// e.g. `ServiceWorkerGlobalScope` should implement dummy
|
||||
// `addEventListener` and so on.
|
||||
|
||||
default: throw new Error(`Invalid globalThis type ${name}.`);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(joyeecheung): work with the upstream to port more tests in .html
|
||||
// to .js.
|
||||
runJsTests() {
|
||||
@ -368,7 +406,7 @@ class WPTRunner {
|
||||
testRelativePath: relativePath,
|
||||
wptRunner: __filename,
|
||||
wptPath: this.path,
|
||||
initScript: this.initScript,
|
||||
initScript: this.fullInitScript,
|
||||
harness: {
|
||||
code: fs.readFileSync(harnessPath, 'utf8'),
|
||||
filename: harnessPath,
|
||||
|
@ -13,9 +13,6 @@
|
||||
"urlencoded-parser.any.js": {
|
||||
"fail": "missing Request and Response"
|
||||
},
|
||||
"idlharness.any.js": {
|
||||
"fail": "getter/setter names are wrong, etc."
|
||||
},
|
||||
"urlsearchparams-constructor.any.js": {
|
||||
"fail": "FormData is not defined"
|
||||
},
|
||||
|
@ -5,4 +5,5 @@ const { WPTRunner } = require('../common/wpt');
|
||||
|
||||
const runner = new WPTRunner('url');
|
||||
|
||||
runner.pretendGlobalThisAs('Window');
|
||||
runner.runJsTests();
|
||||
|
Loading…
Reference in New Issue
Block a user