diff --git a/lib/internal/url.js b/lib/internal/url.js index a5e3bb96908e2e..30b6701055f20d 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -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; diff --git a/test/common/wpt.js b/test/common/wpt.js index 3e2f8151a6c20b..82163f68b5adb4 100644 --- a/test/common/wpt.js +++ b/test/common/wpt.js @@ -318,6 +318,29 @@ class WPTRunner { this.initScript = script; } + /** + * 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.setInitScript( + '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() { diff --git a/test/wpt/status/url.json b/test/wpt/status/url.json index ab89356f82c805..2372a367e982a9 100644 --- a/test/wpt/status/url.json +++ b/test/wpt/status/url.json @@ -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" }, diff --git a/test/wpt/test-url.js b/test/wpt/test-url.js index c1cb3e4f850c4e..d2991773cf0d01 100644 --- a/test/wpt/test-url.js +++ b/test/wpt/test-url.js @@ -5,4 +5,5 @@ const { WPTRunner } = require('../common/wpt'); const runner = new WPTRunner('url'); +runner.pretendGlobalThisAs('Window'); runner.runJsTests();