From 3a84634cc1f5227bdd4e2779d64378a8449d4890 Mon Sep 17 00:00:00 2001 From: legendecas Date: Sun, 1 Dec 2019 16:04:57 +0800 Subject: [PATCH] n-api: return napi_invalid_arg on napi_create_bigint_words MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit N-API statuses shall be preferred over throwing JavaScript Errors on checks occurred in N-APIs. PR-URL: https://github.com/nodejs/node/pull/31312 Refs: https://github.com/nodejs/node/issues/29849 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: Ruben Bridgewater Reviewed-By: Rich Trott Reviewed-By: Michael Dawson --- src/js_native_api_v8.cc | 6 ++---- test/js-native-api/test_bigint/test.js | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index da5d5eca03a2e1..aaacc63785eab1 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -1530,10 +1530,8 @@ napi_status napi_create_bigint_words(napi_env env, v8::Local 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 b = v8::BigInt::NewFromWords( context, sign_bit, word_count, words); diff --git a/test/js-native-api/test_bigint/test.js b/test/js-native-api/test_bigint/test.js index b92c810459321b..85a183171743c7 100644 --- a/test/js-native-api/test_bigint/test.js +++ b/test/js-native-api/test_bigint/test.js @@ -40,6 +40,6 @@ const { }); assert.throws(CreateTooBigBigInt, { - name: 'RangeError', - message: 'Maximum BigInt size exceeded', + name: 'Error', + message: 'Invalid argument', });