Skip to content

Commit

Permalink
contextify: ignore getters during initialization
Browse files Browse the repository at this point in the history
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: #2091
Reviewed-By: Trevor Norris <[email protected]>
  • Loading branch information
indutny authored and rvagg committed Sep 5, 2015
1 parent b30f393 commit def8dea
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ class ContextifyContext {
explicit ContextifyContext(Environment* env, Local<Object> 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<Object, kSandbox>);
sandbox_.MarkIndependent();
references_++;
Expand Down Expand Up @@ -355,6 +356,10 @@ class ContextifyContext {
ContextifyContext* ctx =
Unwrap<ContextifyContext>(args.Data().As<Object>());

// Stil initializing
if (ctx->context_.IsEmpty())
return;

Local<Object> sandbox = PersistentToLocal(isolate, ctx->sandbox_);
MaybeLocal<Value> maybe_rv =
sandbox->GetRealNamedProperty(ctx->context(), property);
Expand Down Expand Up @@ -383,6 +388,10 @@ class ContextifyContext {
ContextifyContext* ctx =
Unwrap<ContextifyContext>(args.Data().As<Object>());

// Stil initializing
if (ctx->context_.IsEmpty())
return;

PersistentToLocal(isolate, ctx->sandbox_)->Set(property, value);
}

Expand All @@ -395,6 +404,10 @@ class ContextifyContext {
ContextifyContext* ctx =
Unwrap<ContextifyContext>(args.Data().As<Object>());

// Stil initializing
if (ctx->context_.IsEmpty())
return;

Local<Object> sandbox = PersistentToLocal(isolate, ctx->sandbox_);
Maybe<PropertyAttribute> maybe_prop_attr =
sandbox->GetRealNamedPropertyAttributes(ctx->context(), property);
Expand Down Expand Up @@ -422,6 +435,11 @@ class ContextifyContext {

ContextifyContext* ctx =
Unwrap<ContextifyContext>(args.Data().As<Object>());

// Stil initializing
if (ctx->context_.IsEmpty())
return;

Local<Object> sandbox = PersistentToLocal(isolate, ctx->sandbox_);

Maybe<bool> success = sandbox->Delete(ctx->context(), property);
Expand All @@ -436,6 +454,10 @@ class ContextifyContext {
ContextifyContext* ctx =
Unwrap<ContextifyContext>(args.Data().As<Object>());

// Stil initializing
if (ctx->context_.IsEmpty())
return;

Local<Object> sandbox = PersistentToLocal(args.GetIsolate(), ctx->sandbox_);
args.GetReturnValue().Set(sandbox->GetPropertyNames());
}
Expand Down

0 comments on commit def8dea

Please sign in to comment.