Skip to content

Commit

Permalink
Update doc and appending GUID to object property
Browse files Browse the repository at this point in the history
  • Loading branch information
JckXia committed Oct 23, 2021
1 parent c89f0bf commit 02bcfbc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions doc/error_handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ 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)
Note, that due to limitations of the N-API, if one attempts to cast the error object wrapping a primitive inside a C++ addon, the wrapped object
will be received instead. (With properties ```4b3d96fd-fb87-4951-a979-eb4f9d2f2ce9-isWrapObject``` and ```errorVal``` containing the primitive value thrown)


The following sections explain the approach for each case:
Expand Down
15 changes: 10 additions & 5 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2609,10 +2609,12 @@ inline Error::Error(napi_env env, napi_value value) : ObjectReference(env, nullp
Value::From(env, value));
NAPI_FATAL_IF_FAILED(status, "Error::Error", "napi_set_property");

status = napi_set_property(env,
wrappedErrorObj,
String::From(env, "isWrapObject"),
Value::From(env, value));
status = napi_set_property(
env,
wrappedErrorObj,
String::From(env,
"4b3d96fd-fb87-4951-a979-eb4f9d2f2ce9-isWrapObject"),
Value::From(env, value));
NAPI_FATAL_IF_FAILED(status, "Error::Error", "napi_set_property");

status = napi_create_reference(env, wrappedErrorObj, 1, &_ref);
Expand All @@ -2636,7 +2638,10 @@ inline Object Error::Value() const {
// We are checking if the object is wrapped
bool isWrappedObject = false;
napi_has_property(
_env, refValue, String::From(_env, "isWrapObject"), &isWrappedObject);
_env,
refValue,
String::From(_env, "4b3d96fd-fb87-4951-a979-eb4f9d2f2ce9-isWrapObject"),
&isWrappedObject);
// Don't care about status

if (isWrappedObject == true) {
Expand Down

0 comments on commit 02bcfbc

Please sign in to comment.