| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9c442f9 commit 2703fe4
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1602,13 +1602,10 @@ napi_status napi_create_bigint_words(napi_env env, | |||
| 1602 | 1602 | v8::MaybeLocal<v8::BigInt> b = v8::BigInt::NewFromWords( | |
| 1603 | 1603 | context, sign_bit, word_count, words); | |
| 1604 | 1604 | ||
| 1605 | - if (try_catch.HasCaught()) { | ||
| 1606 | - return napi_set_last_error(env, napi_pending_exception); | ||
| 1607 | - } else { | ||
| 1608 | - CHECK_MAYBE_EMPTY(env, b, napi_generic_failure); | ||
| 1609 | - *result = v8impl::JsValueFromV8LocalValue(b.ToLocalChecked()); | ||
| 1610 | - return napi_clear_last_error(env); | ||
| 1611 | - } | ||
| 1605 | + CHECK_MAYBE_EMPTY_WITH_PREAMBLE(env, b, napi_generic_failure); | ||
| 1606 | + | ||
| 1607 | + *result = v8impl::JsValueFromV8LocalValue(b.ToLocalChecked()); | ||
| 1608 | + return GET_RETURN_STATUS(env); | ||
| 1612 | 1609 | } | |
| 1613 | 1610 | ||
| 1614 | 1611 | napi_status napi_get_boolean(napi_env env, bool value, napi_value* result) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ const { | |||
| 7 | 7 | TestUint64, | |
| 8 | 8 | TestWords, | |
| 9 | 9 | CreateTooBigBigInt, | |
| 10 | + MakeBigIntWordsThrow, | ||
| 10 | 11 | } = require(`./build/${common.buildType}/test_bigint`); | |
| 11 | 12 | ||
| 12 | 13 | [ | |
@@ -43,3 +44,9 @@ assert.throws(CreateTooBigBigInt, { | |||
| 43 | 44 | name: 'Error', | |
| 44 | 45 | message: 'Invalid argument', | |
| 45 | 46 | }); | |
| 47 | + | ||
| 48 | + // Test that we correctly forward exceptions from the engine. | ||
| 49 | + assert.throws(MakeBigIntWordsThrow, { | ||
| 50 | + name: 'RangeError', | ||
| 51 | + message: 'Maximum BigInt size exceeded' | ||
| 52 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,4 @@ | |||
| 1 | + #include <limits.h> | ||
| 1 | 2 | #include <inttypes.h> | |
| 2 | 3 | #include <stdio.h> | |
| 3 | 4 | #include <js_native_api.h> | |
@@ -122,6 +123,22 @@ static napi_value CreateTooBigBigInt(napi_env env, napi_callback_info info) { | |||
| 122 | 123 | return output; | |
| 123 | 124 | } | |
| 124 | 125 | ||
| 126 | + // Test that we correctly forward exceptions from the engine. | ||
| 127 | + static napi_value MakeBigIntWordsThrow(napi_env env, napi_callback_info info) { | ||
| 128 | + uint64_t words[10]; | ||
| 129 | + napi_value output; | ||
| 130 | + | ||
| 131 | + napi_status status = napi_create_bigint_words(env, | ||
| 132 | + 0, | ||
| 133 | + INT_MAX, | ||
| 134 | + words, | ||
| 135 | + &output); | ||
| 136 | + if (status != napi_pending_exception) | ||
| 137 | + napi_throw_error(env, NULL, "Expected status `napi_pending_exception`"); | ||
| 138 | + | ||
| 139 | + return NULL; | ||
| 140 | + } | ||
| 141 | + | ||
| 125 | 142 | EXTERN_C_START | |
| 126 | 143 | napi_value Init(napi_env env, napi_value exports) { | |
| 127 | 144 | napi_property_descriptor descriptors[] = { | |
@@ -130,6 +147,7 @@ napi_value Init(napi_env env, napi_value exports) { | |||
| 130 | 147 | DECLARE_NAPI_PROPERTY("TestUint64", TestUint64), | |
| 131 | 148 | DECLARE_NAPI_PROPERTY("TestWords", TestWords), | |
| 132 | 149 | DECLARE_NAPI_PROPERTY("CreateTooBigBigInt", CreateTooBigBigInt), | |
| 150 | + DECLARE_NAPI_PROPERTY("MakeBigIntWordsThrow", MakeBigIntWordsThrow), | ||
| 133 | 151 | }; | |
| 134 | 152 | ||
| 135 | 153 | NAPI_CALL(env, napi_define_properties( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments