From c89f0bfb0b4df5e47b4c34b05a4379fa21caded7 Mon Sep 17 00:00:00 2001 From: JckXia Date: Mon, 20 Sep 2021 22:09:07 -0400 Subject: [PATCH] Remove un-necessary comment/iostream and updated docs to reflect on limitations with this impl --- doc/error_handling.md | 4 ++++ napi-inl.h | 14 +------------- napi.h | 1 - 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/doc/error_handling.md b/doc/error_handling.md index 642c223e5..709d5aedd 100644 --- a/doc/error_handling.md +++ b/doc/error_handling.md @@ -14,6 +14,10 @@ If C++ exceptions are enabled (for more info see: [Setup](setup.md)), then the `Napi::Error` class extends `std::exception` and enables integrated error-handling for C++ exceptions and JavaScript exceptions. +Note, that due to limitations of the N-API, if one attempt to cast the error object thrown as a primitive, an +wrapped object will be received instead. (With properties ```isWrapObject``` and ```errorVal``` containing the primitive value thrown) + + The following sections explain the approach for each case: - [Handling Errors With C++ Exceptions](#exceptions) diff --git a/napi-inl.h b/napi-inl.h index 351e03593..befcc5871 100644 --- a/napi-inl.h +++ b/napi-inl.h @@ -2628,13 +2628,12 @@ inline Object Error::Value() const { if (_ref == nullptr) { return Object(_env, nullptr); } - // Most likely will mess up thread execution napi_value refValue; napi_status status = napi_get_reference_value(_env, _ref, &refValue); NAPI_THROW_IF_FAILED(_env, status, Object()); - // We are wrapping this object + // We are checking if the object is wrapped bool isWrappedObject = false; napi_has_property( _env, refValue, String::From(_env, "isWrapObject"), &isWrappedObject); @@ -2650,17 +2649,6 @@ inline Object Error::Value() const { return Object(_env, refValue); } -// template -// inline T Error::Value() const { -// // if (_ref == nullptr) { -// // return T(_env, nullptr); -// // } - -// // napi_value value; -// // napi_status status = napi_get_reference_value(_env, _ref, &value); -// // NAPI_THROW_IF_FAILED(_env, status, T()); -// return nullptr; -// } inline Error::Error(Error&& other) : ObjectReference(std::move(other)) { } diff --git a/napi.h b/napi.h index 950a41d87..29a2a47e0 100644 --- a/napi.h +++ b/napi.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include