Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Schulhof committed Nov 14, 2019
1 parent e7800f5 commit bf8519d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3370,9 +3370,30 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
}

T* instance;
auto handleConstructorException = [](const CallbackInfo& info) {
napi_status status = napi_remove_wrap(info.Env(), info.This(), nullptr);
NAPI_FATAL_IF_FAILED(status,
"ObjectWrap<T>::ConstructorCallbackWrapper",
"Failed to remove wrap from failed ObjectWrap instance construction");
};
napi_value wrapper = details::WrapCallback([&] {
CallbackInfo callbackInfo(env, info);
#ifdef NAPI_CPP_EXCEPTIONS
try {
instance = new T(callbackInfo);
} catch (const Error& e) {
handleConstructorException(callbackInfo);
e.ThrowAsJavaScriptException();
}
#else
instance = new T(callbackInfo);
if (callbackInfo.Env().IsExceptionPending()) {
Error e = callbackInfo.Env().GetAndClearPendingException();
handleConstructorException(callbackInfo);
e.ThrowAsJavaScriptException();
delete instance;
}
# endif // NAPI_CPP_EXCEPTIONS
return callbackInfo.This();
});

Expand Down

0 comments on commit bf8519d

Please sign in to comment.