Skip to content

Commit

Permalink
n-api: return napi_invalid_arg on napi_create_bigint_words
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
legendecas authored and MylesBorins committed Jan 16, 2020
1 parent e1fd6ae commit c8aa08e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1596,10 +1596,8 @@ napi_status napi_create_bigint_words(napi_env env,

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

if (word_count > INT_MAX) {
napi_throw_range_error(env, nullptr, "Maximum BigInt size exceeded");
return napi_set_last_error(env, napi_pending_exception);
}
RETURN_STATUS_IF_FALSE(
env, word_count <= INT_MAX, napi_invalid_arg);

v8::MaybeLocal<v8::BigInt> b = v8::BigInt::NewFromWords(
context, sign_bit, word_count, words);
Expand Down
4 changes: 2 additions & 2 deletions test/js-native-api/test_bigint/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ const {
});

assert.throws(CreateTooBigBigInt, {
name: 'RangeError',
message: 'Maximum BigInt size exceeded',
name: 'Error',
message: 'Invalid argument',
});

0 comments on commit c8aa08e

Please sign in to comment.