diff --git a/lib/internal/url.js b/lib/internal/url.js index 9c11377aef1f24..1cb733e1ae2490 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -964,6 +964,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..997c90c343c2f2 --- /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' +});