Skip to content

Commit 66def25

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
1 parent 28113ed commit 66def25

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

lib/internal/url.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,29 @@ class WPTRunner {
318318
this.initScript = script;
319319
}
320320

321+
/**
322+
* Pretend the runner is run in `name`'s environment (globalThis).
323+
* @param {'Window'} name
324+
* @see {@link https://github.com/nodejs/node/blob/24673ace8ae196bd1c6d4676507d6e8c94cf0b90/test/fixtures/wpt/resources/idlharness.js#L654-L671}
325+
*/
326+
pretendGlobalThisAs(name) {
327+
switch (name) {
328+
case 'Window': {
329+
this.setInitScript(
330+
'global.Window = Object.getPrototypeOf(globalThis).constructor;');
331+
break;
332+
}
333+
334+
// TODO(Xadillax): implement `ServiceWorkerGlobalScope`,
335+
// `DedicateWorkerGlobalScope`, etc.
336+
//
337+
// e.g. `ServiceWorkerGlobalScope` should implement dummy
338+
// `addEventListener` and so on.
339+
340+
default: throw new Error(`Invalid globalThis type ${name}.`);
341+
}
342+
}
343+
321344
// TODO(joyeecheung): work with the upstream to port more tests in .html
322345
// to .js.
323346
runJsTests() {

test/wpt/status/url.json

Lines changed: 0 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
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)