Skip to content

Commit

Permalink
Merge pull request #12 from fritzm/fritzm/objectwrap-fix
Browse files Browse the repository at this point in the history
Fix crashes after throw from ctor of Napi::ObjectWrap subclasses
  • Loading branch information
fritzm authored Dec 11, 2019
2 parents a1c34b2 + 029ad07 commit e329187
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 e329187

Please sign in to comment.