diff --git a/src/node_api.cc b/src/node_api.cc index 63d755e614..13352c8800 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -1857,7 +1857,10 @@ napi_status napi_unwrap(napi_env env, napi_value js_object, void** result) { // via napi_define_class() can be (un)wrapped. RETURN_STATUS_IF_FALSE(obj->InternalFieldCount() > 0, napi_invalid_arg); - *result = v8::Local::Cast(obj->GetInternalField(0))->Value(); + v8::Local unwrappedValue = obj->GetInternalField(0); + RETURN_STATUS_IF_FALSE(unwrappedValue->IsExternal(), napi_invalid_arg); + + *result = unwrappedValue.As()->Value(); return napi_ok; } diff --git a/test/addons-napi/3_callbacks/binding.c b/test/addons-napi/3_callbacks/binding.c index 7e2750a2a9..8e96043d5d 100644 --- a/test/addons-napi/3_callbacks/binding.c +++ b/test/addons-napi/3_callbacks/binding.c @@ -1,7 +1,7 @@ #include #define NAPI_CALL(theCall) \ - if (theCall != napi_ok) { \ + if ((theCall) != napi_ok) { \ const char* errorMessage = napi_get_last_error_info()->error_message; \ errorMessage = errorMessage ? errorMessage : "empty error message"; \ napi_throw_error((env), errorMessage); \ diff --git a/test/addons-napi/test_buffer/test_buffer.c b/test/addons-napi/test_buffer/test_buffer.c index d99ab45c42..c0c5209abf 100644 --- a/test/addons-napi/test_buffer/test_buffer.c +++ b/test/addons-napi/test_buffer/test_buffer.c @@ -11,7 +11,7 @@ } #define NAPI_CALL(env, theCall) \ - if (theCall != napi_ok) { \ + if ((theCall) != napi_ok) { \ const char* errorMessage = napi_get_last_error_info()->error_message; \ errorMessage = errorMessage ? errorMessage : "empty error message"; \ napi_throw_error((env), errorMessage); \