summaryrefslogtreecommitdiff
path: root/test/js-native-api
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2020-07-29 10:48:00 -0700
committerGabriel Schulhof <gabriel.schulhof@intel.com>2020-07-31 13:45:25 -0700
commit0cc2a54a53831968d5c955cb6cc09a2c46bd75ea (patch)
treed9171f77fbcfaf6667ee88058abf36d50f0a55e2 /test/js-native-api
parenta97b5f9c6acd101ec20d9278a840b2cb6ef94ac9 (diff)
downloadnode-new-0cc2a54a53831968d5c955cb6cc09a2c46bd75ea.tar.gz
n-api: simplify bigint-from-word creation
Macro `CHECK_MAYBE_EMPTY_WITH_PREAMBLE()` does the work of checking the `TryCatch` and returning `napi_pending_exception` so this change reuses it for `napi_create_bigint_words()`. Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> PR-URL: https://github.com/nodejs/node/pull/34554 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'test/js-native-api')
-rw-r--r--test/js-native-api/test_bigint/test.js7
-rw-r--r--test/js-native-api/test_bigint/test_bigint.c18
2 files changed, 25 insertions, 0 deletions
diff --git a/test/js-native-api/test_bigint/test.js b/test/js-native-api/test_bigint/test.js
index 85a1831717..bf9ce5066d 100644
--- a/test/js-native-api/test_bigint/test.js
+++ b/test/js-native-api/test_bigint/test.js
@@ -7,6 +7,7 @@ const {
TestUint64,
TestWords,
CreateTooBigBigInt,
+ MakeBigIntWordsThrow,
} = require(`./build/${common.buildType}/test_bigint`);
[
@@ -43,3 +44,9 @@ assert.throws(CreateTooBigBigInt, {
name: 'Error',
message: 'Invalid argument',
});
+
+// Test that we correctly forward exceptions from the engine.
+assert.throws(MakeBigIntWordsThrow, {
+ name: 'RangeError',
+ message: 'Maximum BigInt size exceeded'
+});
diff --git a/test/js-native-api/test_bigint/test_bigint.c b/test/js-native-api/test_bigint/test_bigint.c
index c62a0a6a6c..181f9103fa 100644
--- a/test/js-native-api/test_bigint/test_bigint.c
+++ b/test/js-native-api/test_bigint/test_bigint.c
@@ -1,3 +1,4 @@
+#include <limits.h>
#include <inttypes.h>
#include <stdio.h>
#include <js_native_api.h>
@@ -122,6 +123,22 @@ static napi_value CreateTooBigBigInt(napi_env env, napi_callback_info info) {
return output;
}
+// Test that we correctly forward exceptions from the engine.
+static napi_value MakeBigIntWordsThrow(napi_env env, napi_callback_info info) {
+ uint64_t words[10];
+ napi_value output;
+
+ napi_status status = napi_create_bigint_words(env,
+ 0,
+ INT_MAX,
+ words,
+ &output);
+ if (status != napi_pending_exception)
+ napi_throw_error(env, NULL, "Expected status `napi_pending_exception`");
+
+ return NULL;
+}
+
EXTERN_C_START
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
@@ -130,6 +147,7 @@ napi_value Init(napi_env env, napi_value exports) {
DECLARE_NAPI_PROPERTY("TestUint64", TestUint64),
DECLARE_NAPI_PROPERTY("TestWords", TestWords),
DECLARE_NAPI_PROPERTY("CreateTooBigBigInt", CreateTooBigBigInt),
+ DECLARE_NAPI_PROPERTY("MakeBigIntWordsThrow", MakeBigIntWordsThrow),
};
NAPI_CALL(env, napi_define_properties(