@@ -65,9 +65,10 @@ class ContextifyContext {
6565 explicit ContextifyContext (Environment* env, Local<Object> sandbox)
6666 : env_(env),
6767 sandbox_(env->isolate (), sandbox),
68- context_(env->isolate (), CreateV8Context(env)),
6968 // Wait for sandbox_, proxy_global_, and context_ to die
7069 references_(0 ) {
70+ context_.Reset (env->isolate (), CreateV8Context (env));
71+
7172 sandbox_.SetWeak (this , WeakCallback<Object, kSandbox >);
7273 sandbox_.MarkIndependent ();
7374 references_++;
@@ -361,6 +362,10 @@ class ContextifyContext {
361362 ContextifyContext* ctx =
362363 Unwrap<ContextifyContext>(args.Data ().As <Object>());
363364
365+ // Stil initializing
366+ if (ctx->context_ .IsEmpty ())
367+ return ;
368+
364369 Local<Object> sandbox = PersistentToLocal (isolate, ctx->sandbox_ );
365370 MaybeLocal<Value> maybe_rv =
366371 sandbox->GetRealNamedProperty (ctx->context (), property);
@@ -389,6 +394,10 @@ class ContextifyContext {
389394 ContextifyContext* ctx =
390395 Unwrap<ContextifyContext>(args.Data ().As <Object>());
391396
397+ // Stil initializing
398+ if (ctx->context_ .IsEmpty ())
399+ return ;
400+
392401 PersistentToLocal (isolate, ctx->sandbox_ )->Set (property, value);
393402 }
394403
@@ -401,6 +410,10 @@ class ContextifyContext {
401410 ContextifyContext* ctx =
402411 Unwrap<ContextifyContext>(args.Data ().As <Object>());
403412
413+ // Stil initializing
414+ if (ctx->context_ .IsEmpty ())
415+ return ;
416+
404417 Local<Object> sandbox = PersistentToLocal (isolate, ctx->sandbox_ );
405418 Maybe<PropertyAttribute> maybe_prop_attr =
406419 sandbox->GetRealNamedPropertyAttributes (ctx->context (), property);
@@ -428,6 +441,11 @@ class ContextifyContext {
428441
429442 ContextifyContext* ctx =
430443 Unwrap<ContextifyContext>(args.Data ().As <Object>());
444+
445+ // Stil initializing
446+ if (ctx->context_ .IsEmpty ())
447+ return ;
448+
431449 Local<Object> sandbox = PersistentToLocal (isolate, ctx->sandbox_ );
432450
433451 Maybe<bool > success = sandbox->Delete (ctx->context (), property);
@@ -442,6 +460,10 @@ class ContextifyContext {
442460 ContextifyContext* ctx =
443461 Unwrap<ContextifyContext>(args.Data ().As <Object>());
444462
463+ // Stil initializing
464+ if (ctx->context_ .IsEmpty ())
465+ return ;
466+
445467 Local<Object> sandbox = PersistentToLocal (args.GetIsolate (), ctx->sandbox_ );
446468 args.GetReturnValue ().Set (sandbox->GetPropertyNames ());
447469 }
0 commit comments