diff --git a/src/node_contextify.cc b/src/node_contextify.cc index e1f11c6a401b07..16fc91836c40ea 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -65,9 +65,10 @@ class ContextifyContext { explicit ContextifyContext(Environment* env, Local sandbox) : env_(env), sandbox_(env->isolate(), sandbox), - context_(env->isolate(), CreateV8Context(env)), // Wait for sandbox_, proxy_global_, and context_ to die references_(0) { + context_.Reset(env->isolate(), CreateV8Context(env)); + sandbox_.SetWeak(this, WeakCallback); sandbox_.MarkIndependent(); references_++; @@ -361,6 +362,10 @@ class ContextifyContext { ContextifyContext* ctx = Unwrap(args.Data().As()); + // Stil initializing + if (ctx->context_.IsEmpty()) + return; + Local sandbox = PersistentToLocal(isolate, ctx->sandbox_); MaybeLocal maybe_rv = sandbox->GetRealNamedProperty(ctx->context(), property); @@ -389,6 +394,10 @@ class ContextifyContext { ContextifyContext* ctx = Unwrap(args.Data().As()); + // Stil initializing + if (ctx->context_.IsEmpty()) + return; + PersistentToLocal(isolate, ctx->sandbox_)->Set(property, value); } @@ -401,6 +410,10 @@ class ContextifyContext { ContextifyContext* ctx = Unwrap(args.Data().As()); + // Stil initializing + if (ctx->context_.IsEmpty()) + return; + Local sandbox = PersistentToLocal(isolate, ctx->sandbox_); Maybe maybe_prop_attr = sandbox->GetRealNamedPropertyAttributes(ctx->context(), property); @@ -428,6 +441,11 @@ class ContextifyContext { ContextifyContext* ctx = Unwrap(args.Data().As()); + + // Stil initializing + if (ctx->context_.IsEmpty()) + return; + Local sandbox = PersistentToLocal(isolate, ctx->sandbox_); Maybe success = sandbox->Delete(ctx->context(), property); @@ -442,6 +460,10 @@ class ContextifyContext { ContextifyContext* ctx = Unwrap(args.Data().As()); + // Stil initializing + if (ctx->context_.IsEmpty()) + return; + Local sandbox = PersistentToLocal(args.GetIsolate(), ctx->sandbox_); args.GetReturnValue().Set(sandbox->GetPropertyNames()); }