Skip to content

Commit

Permalink
don't try to escape null
Browse files Browse the repository at this point in the history
If an exception is pending from Call Or MakeCallback on
FunctionReference the return value may be nullptr.
Check for a pending exception and don't try to escape in these cases.

PR-URL: nodejs/node-addon-api#245
Refs: nodejs/node-addon-api#233
Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
  • Loading branch information
Marlyfleitas committed Apr 10, 2018
1 parent 40d65a2 commit 24300d7
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2285,36 +2285,60 @@ inline Napi::Value FunctionReference::operator ()(

inline Napi::Value FunctionReference::Call(const std::initializer_list<napi_value>& args) const {
EscapableHandleScope scope(_env);
return scope.Escape(Value().Call(args));
Napi::Value result = Value().Call(args);
if (scope.Env().IsExceptionPending()) {
return Value();
}
return scope.Escape(result);
}

inline Napi::Value FunctionReference::Call(const std::vector<napi_value>& args) const {
EscapableHandleScope scope(_env);
return scope.Escape(Value().Call(args));
Napi::Value result = Value().Call(args);
if (scope.Env().IsExceptionPending()) {
return Value();
}
return scope.Escape(result);
}

inline Napi::Value FunctionReference::Call(
napi_value recv, const std::initializer_list<napi_value>& args) const {
EscapableHandleScope scope(_env);
return scope.Escape(Value().Call(recv, args));
Napi::Value result = Value().Call(recv, args);
if (scope.Env().IsExceptionPending()) {
return Value();
}
return scope.Escape(result);
}

inline Napi::Value FunctionReference::Call(
napi_value recv, const std::vector<napi_value>& args) const {
EscapableHandleScope scope(_env);
return scope.Escape(Value().Call(recv, args));
Napi::Value result = Value().Call(recv, args);
if (scope.Env().IsExceptionPending()) {
return Value();
}
return scope.Escape(result);
}

inline Napi::Value FunctionReference::MakeCallback(
napi_value recv, const std::initializer_list<napi_value>& args) const {
EscapableHandleScope scope(_env);
return scope.Escape(Value().MakeCallback(recv, args));
Napi::Value result = Value().MakeCallback(recv, args);
if (scope.Env().IsExceptionPending()) {
return Value();
}
return scope.Escape(result);
}

inline Napi::Value FunctionReference::MakeCallback(
napi_value recv, const std::vector<napi_value>& args) const {
EscapableHandleScope scope(_env);
return scope.Escape(Value().MakeCallback(recv, args));
Napi::Value result = Value().MakeCallback(recv, args);
if (scope.Env().IsExceptionPending()) {
return Value();
}
return scope.Escape(result);
}

inline Object FunctionReference::New(const std::initializer_list<napi_value>& args) const {
Expand Down

0 comments on commit 24300d7

Please sign in to comment.