diff --git a/lib/internal/url.js b/lib/internal/url.js index cb662b90ac052c..b6412dd6a5480b 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -978,6 +978,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' +});