diff --git a/lib/internal/url.js b/lib/internal/url.js index cb662b90ac052c..a6dc1272b0ce6b 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -706,6 +706,10 @@ class URL { #searchParams; constructor(input, base = undefined) { + if (arguments.length === 0) { + throw new ERR_MISSING_ARGS('url'); + } + // toUSVString is not needed. input = `${input}`; @@ -978,6 +982,10 @@ class URL { } static canParse(url, base = undefined) { + if (arguments.length === 0) { + throw new ERR_MISSING_ARGS('url'); + } + url = `${url}`; if (base !== undefined) { diff --git a/test/parallel/test-url-canParse-whatwg.js b/test/parallel/test-url-canParse-whatwg.js new file mode 100644 index 00000000000000..7f7d5d40aa7a28 --- /dev/null +++ b/test/parallel/test-url-canParse-whatwg.js @@ -0,0 +1,12 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); + +// One argument is required +assert.throws(() => { + URL.canParse(); +}, { + code: 'ERR_MISSING_ARGS', + name: 'TypeError', +}); diff --git a/test/parallel/test-whatwg-url-custom-parsing.js b/test/parallel/test-whatwg-url-custom-parsing.js index a3532374ca684e..905028fee3812c 100644 --- a/test/parallel/test-whatwg-url-custom-parsing.js +++ b/test/parallel/test-whatwg-url-custom-parsing.js @@ -78,3 +78,10 @@ for (const test of additional_tests) { if (test.search) assert.strictEqual(url.search, test.search); if (test.hash) assert.strictEqual(url.hash, test.hash); } + +assert.throws(() => { + new URL(); +}, { + name: 'TypeError', + code: 'ERR_MISSING_ARGS', +});