diff --git a/native_mate/function_template.h b/native_mate/function_template.h index 50c427a1dab2..abbe7b5326e1 100644 --- a/native_mate/function_template.h +++ b/native_mate/function_template.h @@ -21,6 +21,9 @@ namespace internal { struct Destroyable { static void Destroy(Arguments* args) { + if (IsDestroyed(args)) + return; + v8::Local holder = args->GetHolder(); delete static_cast( holder->GetAlignedPointerFromInternalField(0)); diff --git a/native_mate/wrappable.cc b/native_mate/wrappable.cc index 6743a139f54e..005c83b8dc0a 100644 --- a/native_mate/wrappable.cc +++ b/native_mate/wrappable.cc @@ -24,8 +24,11 @@ WrappableBase::~WrappableBase() { } v8::Local WrappableBase::GetWrapper() { - CHECK(!wrapper_.IsEmpty()); - return v8::Local::New(isolate_, wrapper_); + DCHECK(!wrapper_.IsEmpty()); + if (!wrapper_.IsEmpty()) + return v8::Local::New(isolate_, wrapper_); + else + return v8::Local(); } void WrappableBase::InitWith(v8::Isolate* isolate,