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>
This commit is contained in:
parent
7334aaf2ea
commit
e6edd66c10
@ -655,7 +655,7 @@ static void ToUnicode(const FunctionCallbackInfo<Value>& args) {
|
|||||||
int32_t len = ToUnicode(&buf, *val, val.length());
|
int32_t len = ToUnicode(&buf, *val, val.length());
|
||||||
|
|
||||||
if (len < 0) {
|
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(
|
args.GetReturnValue().Set(
|
||||||
@ -678,7 +678,7 @@ static void ToASCII(const FunctionCallbackInfo<Value>& args) {
|
|||||||
int32_t len = ToASCII(&buf, *val, val.length(), mode);
|
int32_t len = ToASCII(&buf, *val, val.length(), mode);
|
||||||
|
|
||||||
if (len < 0) {
|
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(
|
args.GetReturnValue().Set(
|
||||||
|
@ -33,8 +33,6 @@ const wptToASCIITests = require(
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const errMessage = /^Error: Cannot convert name to ASCII$/;
|
|
||||||
|
|
||||||
for (const [i, test] of wptToASCIITests.entries()) {
|
for (const [i, test] of wptToASCIITests.entries()) {
|
||||||
if (typeof test === 'string')
|
if (typeof test === 'string')
|
||||||
continue; // skip comments
|
continue; // skip comments
|
||||||
@ -43,8 +41,14 @@ const wptToASCIITests = require(
|
|||||||
if (comment)
|
if (comment)
|
||||||
caseComment += ` (${comment})`;
|
caseComment += ` (${comment})`;
|
||||||
if (output === null) {
|
if (output === null) {
|
||||||
assert.throws(() => icu.toASCII(input),
|
common.expectsError(
|
||||||
errMessage, `ToASCII ${caseComment}`);
|
() => icu.toASCII(input),
|
||||||
|
{
|
||||||
|
code: 'ERR_INVALID_ARG_VALUE',
|
||||||
|
type: TypeError,
|
||||||
|
message: 'Cannot convert name to ASCII'
|
||||||
|
}
|
||||||
|
);
|
||||||
icu.toASCII(input, true); // Should not throw.
|
icu.toASCII(input, true); // Should not throw.
|
||||||
} else {
|
} else {
|
||||||
assert.strictEqual(icu.toASCII(input), output, `ToASCII ${caseComment}`);
|
assert.strictEqual(icu.toASCII(input), output, `ToASCII ${caseComment}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user