Skip to content

Commit 48655e1

Browse files
committed
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 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 31772a4 commit 48655e1

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

lib/internal/url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ function isURLThis(self) {
621621
}
622622

623623
class URL {
624-
constructor(input, base) {
624+
constructor(input, base = undefined) {
625625
// toUSVString is not needed.
626626
input = `${input}`;
627627
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
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
},

test/wpt/test-url.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ const { WPTRunner } = require('../common/wpt');
55

66
const runner = new WPTRunner('url');
77

8+
runner.pretendGlobalThisAs('Window');
89
runner.runJsTests();

0 commit comments

Comments
 (0)