Skip to content

Commit ccc6cd5

Browse files
committed
n-api: return napi_invalid_arg on napi_create_bigint_words
N-API statuses shall be preferred over throwing JavaScript Errors on checks occurred in N-APIs.
1 parent be055d1 commit ccc6cd5

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/js_native_api_v8.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,10 +1530,8 @@ napi_status napi_create_bigint_words(napi_env env,
15301530

15311531
v8::Local<v8::Context> context = env->context();
15321532

1533-
if (word_count > INT_MAX) {
1534-
napi_throw_range_error(env, nullptr, "Maximum BigInt size exceeded");
1535-
return napi_set_last_error(env, napi_pending_exception);
1536-
}
1533+
RETURN_STATUS_IF_FALSE(
1534+
env, word_count <= INT_MAX, napi_invalid_arg);
15371535

15381536
v8::MaybeLocal<v8::BigInt> b = v8::BigInt::NewFromWords(
15391537
context, sign_bit, word_count, words);

test/js-native-api/test_bigint/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ const {
4040
});
4141

4242
assert.throws(CreateTooBigBigInt, {
43-
name: 'RangeError',
44-
message: 'Maximum BigInt size exceeded',
43+
name: 'Error',
44+
message: 'Invalid argument',
4545
});

0 commit comments

Comments
 (0)