Skip to content

Commit c8aa08e

Browse files
legendecasMylesBorins
authored andcommitted
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. PR-URL: #31312 Refs: #29849 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent e1fd6ae commit c8aa08e

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
@@ -1596,10 +1596,8 @@ napi_status napi_create_bigint_words(napi_env env,
15961596

15971597
v8::Local<v8::Context> context = env->context();
15981598

1599-
if (word_count > INT_MAX) {
1600-
napi_throw_range_error(env, nullptr, "Maximum BigInt size exceeded");
1601-
return napi_set_last_error(env, napi_pending_exception);
1602-
}
1599+
RETURN_STATUS_IF_FALSE(
1600+
env, word_count <= INT_MAX, napi_invalid_arg);
16031601

16041602
v8::MaybeLocal<v8::BigInt> b = v8::BigInt::NewFromWords(
16051603
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)