From 0351599d5b986ba2c0fb6e4594a61f3213f2b667 Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Sat, 29 Apr 2023 01:45:28 +0900 Subject: [PATCH 1/3] Fix empty URL --- cli/tests/unit/url_test.ts | 7 +++++++ ext/url/00_url.js | 2 ++ 2 files changed, 9 insertions(+) diff --git a/cli/tests/unit/url_test.ts b/cli/tests/unit/url_test.ts index 644b8dd39a759e..d3ee7542c570ef 100644 --- a/cli/tests/unit/url_test.ts +++ b/cli/tests/unit/url_test.ts @@ -32,6 +32,13 @@ Deno.test(function urlParsing() { ); }); +Deno.test(function emptyUrl() { + // @ts-ignore + assertThrows(() => new URL(), TypeError, "1 argument required, but only 0 present"); + // @ts-ignore + assertThrows(() => 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 d76366cfae2040..7f674e9aa2b685 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, { From f941bc34106c9e53506c51e348b429a491de9dae Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Sat, 29 Apr 2023 01:57:15 +0900 Subject: [PATCH 2/3] Format --- cli/tests/unit/url_test.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cli/tests/unit/url_test.ts b/cli/tests/unit/url_test.ts index d3ee7542c570ef..ac814e0cec071a 100644 --- a/cli/tests/unit/url_test.ts +++ b/cli/tests/unit/url_test.ts @@ -33,10 +33,18 @@ Deno.test(function urlParsing() { }); Deno.test(function emptyUrl() { - // @ts-ignore - assertThrows(() => new URL(), TypeError, "1 argument required, but only 0 present"); - // @ts-ignore - assertThrows(() => URL.canParse(), TypeError, "1 argument required, but only 0 present"); + assertThrows( + // @ts-ignore + () => new URL(), + TypeError, + "1 argument required, but only 0 present", + ); + assertThrows( + // @ts-ignore + () => URL.canParse(), + TypeError, + "1 argument required, but only 0 present", + ); }); Deno.test(function urlProtocolParsing() { From 015a08b9fb6f2df2665b0a6ab39504b15fa25c7b Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Sat, 29 Apr 2023 02:04:16 +0900 Subject: [PATCH 3/3] Tweak --- cli/tests/unit/url_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/tests/unit/url_test.ts b/cli/tests/unit/url_test.ts index ac814e0cec071a..28cf9a0e2c436b 100644 --- a/cli/tests/unit/url_test.ts +++ b/cli/tests/unit/url_test.ts @@ -34,13 +34,13 @@ Deno.test(function urlParsing() { Deno.test(function emptyUrl() { assertThrows( - // @ts-ignore + // @ts-ignore for test () => new URL(), TypeError, "1 argument required, but only 0 present", ); assertThrows( - // @ts-ignore + // @ts-ignore for test () => URL.canParse(), TypeError, "1 argument required, but only 0 present",