From def8dea8acdd578c4f579a80b33c5f3690f51dca Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Tue, 7 Jul 2015 15:27:14 -0700 Subject: [PATCH] contextify: ignore getters during initialization The `context_` is not initialized until the `CreateV8Context` will return. Make sure that it will be empty (by moving away initialization from constructor) at start, and ignore getter callbacks until it will have some value. PR-URL: https://github.com/nodejs/io.js/pull/2091 Reviewed-By: Trevor Norris --- src/node_contextify.cc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/node_contextify.cc b/src/node_contextify.cc index ae043eb376a115..2c52e7f0f8b4e2 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_++; @@ -355,6 +356,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); @@ -383,6 +388,10 @@ class ContextifyContext { ContextifyContext* ctx = Unwrap(args.Data().As()); + // Stil initializing + if (ctx->context_.IsEmpty()) + return; + PersistentToLocal(isolate, ctx->sandbox_)->Set(property, value); } @@ -395,6 +404,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); @@ -422,6 +435,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); @@ -436,6 +454,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()); }