Skip to content

Commit

Permalink
macros: create errors fully namespaced
Browse files Browse the repository at this point in the history
Errors in `NAPI_THROW()` and Co. were being thrown as `Error:New(...)`
but they should be thrown as `Napi::Error::New(...)` because the former
assumes that the user has opted to declare `using namespace Napi;`.

PR-URL: nodejs/node-addon-api#506
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
Marlyfleitas committed Jul 10, 2019
1 parent a859f6b commit fb5b44f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t), "Size mismatch between char16
#define NAPI_THROW_VOID(e) throw e

#define NAPI_THROW_IF_FAILED(env, status, ...) \
if ((status) != napi_ok) throw Error::New(env);
if ((status) != napi_ok) throw Napi::Error::New(env);

#define NAPI_THROW_IF_FAILED_VOID(env, status) \
if ((status) != napi_ok) throw Error::New(env);
if ((status) != napi_ok) throw Napi::Error::New(env);

#else // NAPI_CPP_EXCEPTIONS

Expand All @@ -78,13 +78,13 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t), "Size mismatch between char16

#define NAPI_THROW_IF_FAILED(env, status, ...) \
if ((status) != napi_ok) { \
Error::New(env).ThrowAsJavaScriptException(); \
Napi::Error::New(env).ThrowAsJavaScriptException(); \
return __VA_ARGS__; \
}

#define NAPI_THROW_IF_FAILED_VOID(env, status) \
if ((status) != napi_ok) { \
Error::New(env).ThrowAsJavaScriptException(); \
Napi::Error::New(env).ThrowAsJavaScriptException(); \
return; \
}

Expand All @@ -93,7 +93,7 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t), "Size mismatch between char16
#define NAPI_FATAL_IF_FAILED(status, location, message) \
do { \
if ((status) != napi_ok) { \
Error::Fatal((location), (message)); \
Napi::Error::Fatal((location), (message)); \
} \
} while (0)

Expand Down

0 comments on commit fb5b44f

Please sign in to comment.