we created an object on the &_ref
| 3490 | |
| 3491 | // we created an object on the &_ref |
| 3492 | inline void Error::ThrowAsJavaScriptException() const { |
| 3493 | HandleScope scope(_env); |
| 3494 | if (!IsEmpty()) { |
| 3495 | #ifdef NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS |
| 3496 | bool pendingException = false; |
| 3497 | |
| 3498 | // check if there is already a pending exception. If so don't try to throw a |
| 3499 | // new one as that is not allowed/possible |
| 3500 | napi_status status = napi_is_exception_pending(_env, &pendingException); |
| 3501 | |
| 3502 | if ((status != napi_ok) || |
| 3503 | ((status == napi_ok) && (pendingException == false))) { |
| 3504 | // We intentionally don't use `NAPI_THROW_*` macros here to ensure |
| 3505 | // that there is no possible recursion as `ThrowAsJavaScriptException` |
| 3506 | // is part of `NAPI_THROW_*` macro definition for noexcept. |
| 3507 | |
| 3508 | status = napi_throw(_env, Value()); |
| 3509 | |
| 3510 | #if (NAPI_VERSION >= 10) |
| 3511 | napi_status expected_failure_mode = napi_cannot_run_js; |
| 3512 | #else |
| 3513 | napi_status expected_failure_mode = napi_pending_exception; |
| 3514 | #endif |
| 3515 | if (status == expected_failure_mode) { |
| 3516 | // The environment must be terminating as we checked earlier and there |
| 3517 | // was no pending exception. In this case continuing will result |
| 3518 | // in a fatal error and there is nothing the author has done incorrectly |
| 3519 | // in their code that is worth flagging through a fatal error |
| 3520 | return; |
| 3521 | } |
| 3522 | } else { |
| 3523 | status = napi_pending_exception; |
| 3524 | } |
| 3525 | #else |
| 3526 | // We intentionally don't use `NAPI_THROW_*` macros here to ensure |
| 3527 | // that there is no possible recursion as `ThrowAsJavaScriptException` |
| 3528 | // is part of `NAPI_THROW_*` macro definition for noexcept. |
| 3529 | |
| 3530 | napi_status status = napi_throw(_env, Value()); |
| 3531 | #endif |
| 3532 | |
| 3533 | #ifdef NODE_ADDON_API_CPP_EXCEPTIONS |
| 3534 | if (status != napi_ok) { |
| 3535 | throw Error::New(_env); |
| 3536 | } |
| 3537 | #else // NODE_ADDON_API_CPP_EXCEPTIONS |
| 3538 | NAPI_FATAL_IF_FAILED( |
| 3539 | status, "Error::ThrowAsJavaScriptException", "napi_throw"); |
| 3540 | #endif // NODE_ADDON_API_CPP_EXCEPTIONS |
| 3541 | } |
| 3542 | } |
| 3543 | |
| 3544 | #ifdef NODE_ADDON_API_CPP_EXCEPTIONS |
| 3545 |