diff --git a/lib/internal/url.js b/lib/internal/url.js index 5fcabb803ef473..7fafc783dba4ae 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1308,11 +1308,17 @@ function originFor(url, base) { } function domainToASCII(domain) { + if (arguments.length < 1) + throw new TypeError('"domain" argument must be specified'); + // toUSVString is not needed. return binding.domainToASCII(`${domain}`); } function domainToUnicode(domain) { + if (arguments.length < 1) + throw new TypeError('"domain" argument must be specified'); + // toUSVString is not needed. return binding.domainToUnicode(`${domain}`); } diff --git a/test/parallel/test-whatwg-url-domainto.js b/test/parallel/test-whatwg-url-domainto.js index f891f95a19cd3b..70b32c8dce279c 100644 --- a/test/parallel/test-whatwg-url-domainto.js +++ b/test/parallel/test-whatwg-url-domainto.js @@ -12,6 +12,15 @@ const { domainToASCII, domainToUnicode } = require('url'); // Tests below are not from WPT. const tests = require('../fixtures/url-idna.js'); +{ + assert.throws(() => domainToASCII(), + /^TypeError: "domain" argument must be specified$/); + assert.throws(() => domainToUnicode(), + /^TypeError: "domain" argument must be specified$/); + assert.strictEqual(domainToASCII(undefined), 'undefined'); + assert.strictEqual(domainToUnicode(undefined), 'undefined'); +} + { for (const [i, { ascii, unicode }] of tests.valid.entries()) { assert.strictEqual(ascii, domainToASCII(unicode),