diff --git a/lib/URL-impl.js b/lib/URL-impl.js index eb66cae..f1138eb 100644 --- a/lib/URL-impl.js +++ b/lib/URL-impl.js @@ -6,10 +6,7 @@ const URLSearchParams = require("./URLSearchParams"); exports.implementation = class URLImpl { // Unlike the spec, we duplicate some code between the constructor and canParse, because we want to give useful error // messages in the constructor that distinguish between the different causes of failure. - constructor(globalObject, constructorArgs) { - const url = constructorArgs[0]; - const base = constructorArgs[1]; - + constructor(globalObject, [url, base]) { let parsedBase = null; if (base !== undefined) { parsedBase = usm.basicURLParse(base); @@ -33,6 +30,14 @@ exports.implementation = class URLImpl { this._query._url = this; } + static parse(globalObject, input, base) { + try { + return new URLImpl(globalObject, [input, base]); + } catch { + return null; + } + } + static canParse(url, base) { let parsedBase = null; if (base !== undefined) { diff --git a/lib/URL.webidl b/lib/URL.webidl index 3a376a3..45446bc 100644 --- a/lib/URL.webidl +++ b/lib/URL.webidl @@ -3,6 +3,7 @@ interface URL { constructor(USVString url, optional USVString base); + [WebIDL2JSCallWithGlobal] static URL? parse(USVString url, optional USVString base); static boolean canParse(USVString url, optional USVString base); stringifier attribute USVString href; diff --git a/scripts/get-latest-platform-tests.js b/scripts/get-latest-platform-tests.js index 50e2401..fb0a936 100644 --- a/scripts/get-latest-platform-tests.js +++ b/scripts/get-latest-platform-tests.js @@ -13,7 +13,7 @@ const path = require("path"); // 1. Go to https://github.com/web-platform-tests/wpt/tree/master/url // 2. Press "y" on your keyboard to get a permalink // 3. Copy the commit hash -const commitHash = "72b915d4b3754f081ef5899bf6a777efe71b2fc5"; +const commitHash = "48178346fe87222856812842fb7af7b01baa1530"; const urlPrefix = `https://raw.githubusercontent.com/web-platform-tests/wpt/${commitHash}/url/`; const targetDir = path.resolve(__dirname, "..", "test", "web-platform-tests"); @@ -32,6 +32,7 @@ exports.directlyRunnableTests = [ "url-searchparams.any.js", "url-setters-stripping.any.js", "url-statics-canparse.any.js", + "url-statics-parse.any.js", "url-tojson.any.js", "urlencoded-parser.any.js", "urlsearchparams-append.any.js", diff --git a/test/testharness.js b/test/testharness.js index 0c2bf8b..3b4c2eb 100644 --- a/test/testharness.js +++ b/test/testharness.js @@ -29,6 +29,10 @@ module.exports = { assert.strictEqual(actual, expected); }, + assert_not_equals(actual, expected) { + assert.notStrictEqual(actual, expected); + }, + assert_array_equals(actual, expected) { assert.deepStrictEqual([...actual], [...expected]); },