Skip to content

Commit 0a8c331

Browse files
XadillaXtargos
authored andcommitted
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: #39848 Backport-PR-URL: #40383 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent abf3b84 commit 0a8c331

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

lib/internal/url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ function onParseHashComplete(flags, protocol, username, password,
617617
}
618618

619619
class URL {
620-
constructor(input, base) {
620+
constructor(input, base = undefined) {
621621
// toUSVString is not needed.
622622
input = `${input}`;
623623
let base_context;

test/common/wpt.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class WPTRunner {
288288
this.resource = new ResourceLoader(path);
289289

290290
this.flags = [];
291+
this.dummyGlobalThisScript = null;
291292
this.initScript = null;
292293

293294
this.status = new StatusLoader(path);
@@ -318,6 +319,43 @@ class WPTRunner {
318319
this.initScript = script;
319320
}
320321

322+
get fullInitScript() {
323+
if (this.initScript === null && this.dummyGlobalThisScript === null) {
324+
return null;
325+
}
326+
327+
if (this.initScript === null) {
328+
return this.dummyGlobalThisScript;
329+
} else if (this.dummyGlobalThisScript === null) {
330+
return this.initScript;
331+
}
332+
333+
return `${this.fullInitScript}\n\n//===\n${this.initScript}`;
334+
}
335+
336+
/**
337+
* Pretend the runner is run in `name`'s environment (globalThis).
338+
* @param {'Window'} name
339+
* @see {@link https://github.com/nodejs/node/blob/24673ace8ae196bd1c6d4676507d6e8c94cf0b90/test/fixtures/wpt/resources/idlharness.js#L654-L671}
340+
*/
341+
pretendGlobalThisAs(name) {
342+
switch (name) {
343+
case 'Window': {
344+
this.dummyGlobalThisScript =
345+
'global.Window = Object.getPrototypeOf(globalThis).constructor;';
346+
break;
347+
}
348+
349+
// TODO(XadillaX): implement `ServiceWorkerGlobalScope`,
350+
// `DedicateWorkerGlobalScope`, etc.
351+
//
352+
// e.g. `ServiceWorkerGlobalScope` should implement dummy
353+
// `addEventListener` and so on.
354+
355+
default: throw new Error(`Invalid globalThis type ${name}.`);
356+
}
357+
}
358+
321359
// TODO(joyeecheung): work with the upstream to port more tests in .html
322360
// to .js.
323361
runJsTests() {
@@ -368,7 +406,7 @@ class WPTRunner {
368406
testRelativePath: relativePath,
369407
wptRunner: __filename,
370408
wptPath: this.path,
371-
initScript: this.initScript,
409+
initScript: this.fullInitScript,
372410
harness: {
373411
code: fs.readFileSync(harnessPath, 'utf8'),
374412
filename: harnessPath,

test/wpt/status/url.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
"urlencoded-parser.any.js": {
1414
"fail": "missing Request and Response"
1515
},
16-
"idlharness.any.js": {
17-
"fail": "getter/setter names are wrong, etc."
18-
},
1916
"urlsearchparams-constructor.any.js": {
2017
"fail": "FormData is not defined"
2118
},
@@ -30,5 +27,8 @@
3027
},
3128
"url-setters-a-area.window.js": {
3229
"skip": "already tested in url-setters.any.js"
30+
},
31+
"idlharness.any.js": {
32+
"fail": "Fixed in a semver-major change: https://github.com/nodejs/node/pull/39752"
3333
}
3434
}

test/wpt/test-url.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ runner.setInitScript(`
1515
global.DOMException = DOMException;
1616
`);
1717

18+
runner.pretendGlobalThisAs('Window');
1819
runner.runJsTests();

0 commit comments

Comments
 (0)