diff --git a/cli/tests/unit/url_test.ts b/cli/tests/unit/url_test.ts index 644b8dd39a..28cf9a0e2c 100644 --- a/cli/tests/unit/url_test.ts +++ b/cli/tests/unit/url_test.ts @@ -32,6 +32,21 @@ Deno.test(function urlParsing() { ); }); +Deno.test(function emptyUrl() { + assertThrows( + // @ts-ignore for test + () => new URL(), + TypeError, + "1 argument required, but only 0 present", + ); + assertThrows( + // @ts-ignore for test + () => URL.canParse(), + TypeError, + "1 argument required, but only 0 present", + ); +}); + Deno.test(function urlProtocolParsing() { assertEquals(new URL("Aa+-.1://foo").protocol, "aa+-.1:"); assertEquals(new URL("aA+-.1://foo").protocol, "aa+-.1:"); diff --git a/ext/url/00_url.js b/ext/url/00_url.js index d76366cfae..7f674e9aa2 100644 --- a/ext/url/00_url.js +++ b/ext/url/00_url.js @@ -371,6 +371,7 @@ class URL { */ constructor(url, base = undefined) { const prefix = "Failed to construct 'URL'"; + webidl.requiredArguments(arguments.length, 1, prefix); url = webidl.converters.DOMString(url, { prefix, context: "Argument 1" }); if (base !== undefined) { base = webidl.converters.DOMString(base, { @@ -390,6 +391,7 @@ class URL { */ static canParse(url, base = undefined) { const prefix = "Failed to call 'URL.canParse'"; + webidl.requiredArguments(arguments.length, 1, prefix); url = webidl.converters.DOMString(url, { prefix, context: "Argument 1" }); if (base !== undefined) { base = webidl.converters.DOMString(base, {