diff --git a/src/node_contextify.cc b/src/node_contextify.cc index a13eed9d0ffdeb..c6b9dc18de9bd0 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -255,24 +255,21 @@ void ContextifyContext::MakeContext(const FunctionCallbackInfo& args) { options.allow_code_gen_wasm = args[4].As(); TryCatchScope try_catch(env); - ContextifyContext* context = new ContextifyContext(env, sandbox, options); + auto context_ptr = std::make_unique(env, sandbox, options); if (try_catch.HasCaught()) { if (!try_catch.HasTerminated()) try_catch.ReThrow(); - delete context; return; } - if (context->context().IsEmpty()) { - delete context; + if (context_ptr->context().IsEmpty()) return; - } sandbox->SetPrivate( env->context(), env->contextify_context_private_symbol(), - External::New(env->isolate(), context)); + External::New(env->isolate(), context_ptr.release())); }