summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYaniv Friedensohn <yaniv.friedensohn@gmail.com>2019-06-14 13:17:40 +0300
committerRich Trott <rtrott@gmail.com>2019-06-21 04:10:48 -0600
commite6edd66c10632715326a3ef830c6808d7da069f6 (patch)
treee1d966147107bef3b52c68a108fd88d8d421f2eb
parent7334aaf2eaf3ae9a0bca30329bf833bb5f9f84d2 (diff)
downloadandroid-node-v8-e6edd66c10632715326a3ef830c6808d7da069f6.tar.gz
android-node-v8-e6edd66c10632715326a3ef830c6808d7da069f6.tar.bz2
android-node-v8-e6edd66c10632715326a3ef830c6808d7da069f6.zip
src: add error codes to errors thrown in node_i18n.cc
PR-URL: https://github.com/nodejs/node/pull/28221 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
-rw-r--r--src/node_i18n.cc4
-rw-r--r--test/parallel/test-icu-punycode.js12
2 files changed, 10 insertions, 6 deletions
diff --git a/src/node_i18n.cc b/src/node_i18n.cc
index ad5c828392..162f5fda5d 100644
--- a/src/node_i18n.cc
+++ b/src/node_i18n.cc
@@ -655,7 +655,7 @@ static void ToUnicode(const FunctionCallbackInfo<Value>& args) {
int32_t len = ToUnicode(&buf, *val, val.length());
if (len < 0) {
- return env->ThrowError("Cannot convert name to Unicode");
+ return THROW_ERR_INVALID_ARG_VALUE(env, "Cannot convert name to Unicode");
}
args.GetReturnValue().Set(
@@ -678,7 +678,7 @@ static void ToASCII(const FunctionCallbackInfo<Value>& args) {
int32_t len = ToASCII(&buf, *val, val.length(), mode);
if (len < 0) {
- return env->ThrowError("Cannot convert name to ASCII");
+ return THROW_ERR_INVALID_ARG_VALUE(env, "Cannot convert name to ASCII");
}
args.GetReturnValue().Set(
diff --git a/test/parallel/test-icu-punycode.js b/test/parallel/test-icu-punycode.js
index 7e8dcf3759..7706c1d837 100644
--- a/test/parallel/test-icu-punycode.js
+++ b/test/parallel/test-icu-punycode.js
@@ -33,8 +33,6 @@ const wptToASCIITests = require(
}
{
- const errMessage = /^Error: Cannot convert name to ASCII$/;
-
for (const [i, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
@@ -43,8 +41,14 @@ const wptToASCIITests = require(
if (comment)
caseComment += ` (${comment})`;
if (output === null) {
- assert.throws(() => icu.toASCII(input),
- errMessage, `ToASCII ${caseComment}`);
+ common.expectsError(
+ () => icu.toASCII(input),
+ {
+ code: 'ERR_INVALID_ARG_VALUE',
+ type: TypeError,
+ message: 'Cannot convert name to ASCII'
+ }
+ );
icu.toASCII(input, true); // Should not throw.
} else {
assert.strictEqual(icu.toASCII(input), output, `ToASCII ${caseComment}`);