Skip to content

Commit

Permalink
Fix crashes after throw from ctor of Napi::ObjectWrap subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzm committed Dec 11, 2019
1 parent a1c34b2 commit 029ad07
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/CGALWrapper-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,25 @@ CGALWrapper<WrapperClass, CGALClass>::CGALWrapper(Napi::CallbackInfo const& info
: Napi::ObjectWrap<WrapperClass>(info)
{
Napi::Env env = info.Env();
ARGS_ASSERT(env, info.Length() <= 1);
if (info.Length() == 1) {
ARGS_ASSERT(env, WrapperClass::ParseArg(env, info[0], mWrapped));

// This try/catch/rethrow is a workaround for a bug in Napi::ObjectWrap<> destruction;
// see https://github.com/nodejs/node-addon-api/pull/475

try {
ARGS_ASSERT(env, info.Length() <= 1);
if (info.Length() == 1) {
ARGS_ASSERT(env, WrapperClass::ParseArg(env, info[0], mWrapped));
}
}

catch(std::exception const&) {
if (!CGALWrapper::IsEmpty()) {
Napi::Object object = CGALWrapper::Value();
if (!object.IsEmpty()) {
napi_remove_wrap(env, object, nullptr);
}
}
throw;
}
}

Expand Down

0 comments on commit 029ad07

Please sign in to comment.