url: error when domainTo*() is called w/o argument

PR-URL: https://github.com/nodejs/node/pull/12134
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Timothy Gu 2017-03-20 14:29:54 -07:00 committed by James M Snell
parent f6ddbaff8a
commit c4469c49ec
2 changed files with 15 additions and 0 deletions

View File

@ -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}`);
}

View File

@ -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),