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 <trev.norris@gmail.com>
This commit is contained in:
parent
0159ac9c99
commit
56db28b6d7
@ -65,9 +65,10 @@ class ContextifyContext {
|
|||||||
explicit ContextifyContext(Environment* env, Local<Object> sandbox)
|
explicit ContextifyContext(Environment* env, Local<Object> sandbox)
|
||||||
: env_(env),
|
: env_(env),
|
||||||
sandbox_(env->isolate(), sandbox),
|
sandbox_(env->isolate(), sandbox),
|
||||||
context_(env->isolate(), CreateV8Context(env)),
|
|
||||||
// Wait for sandbox_, proxy_global_, and context_ to die
|
// Wait for sandbox_, proxy_global_, and context_ to die
|
||||||
references_(0) {
|
references_(0) {
|
||||||
|
context_.Reset(env->isolate(), CreateV8Context(env));
|
||||||
|
|
||||||
sandbox_.SetWeak(this, WeakCallback<Object, kSandbox>);
|
sandbox_.SetWeak(this, WeakCallback<Object, kSandbox>);
|
||||||
sandbox_.MarkIndependent();
|
sandbox_.MarkIndependent();
|
||||||
references_++;
|
references_++;
|
||||||
@ -361,6 +362,10 @@ class ContextifyContext {
|
|||||||
ContextifyContext* ctx =
|
ContextifyContext* ctx =
|
||||||
Unwrap<ContextifyContext>(args.Data().As<Object>());
|
Unwrap<ContextifyContext>(args.Data().As<Object>());
|
||||||
|
|
||||||
|
// Stil initializing
|
||||||
|
if (ctx->context_.IsEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
Local<Object> sandbox = PersistentToLocal(isolate, ctx->sandbox_);
|
Local<Object> sandbox = PersistentToLocal(isolate, ctx->sandbox_);
|
||||||
MaybeLocal<Value> maybe_rv =
|
MaybeLocal<Value> maybe_rv =
|
||||||
sandbox->GetRealNamedProperty(ctx->context(), property);
|
sandbox->GetRealNamedProperty(ctx->context(), property);
|
||||||
@ -389,6 +394,10 @@ class ContextifyContext {
|
|||||||
ContextifyContext* ctx =
|
ContextifyContext* ctx =
|
||||||
Unwrap<ContextifyContext>(args.Data().As<Object>());
|
Unwrap<ContextifyContext>(args.Data().As<Object>());
|
||||||
|
|
||||||
|
// Stil initializing
|
||||||
|
if (ctx->context_.IsEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
PersistentToLocal(isolate, ctx->sandbox_)->Set(property, value);
|
PersistentToLocal(isolate, ctx->sandbox_)->Set(property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,6 +410,10 @@ class ContextifyContext {
|
|||||||
ContextifyContext* ctx =
|
ContextifyContext* ctx =
|
||||||
Unwrap<ContextifyContext>(args.Data().As<Object>());
|
Unwrap<ContextifyContext>(args.Data().As<Object>());
|
||||||
|
|
||||||
|
// Stil initializing
|
||||||
|
if (ctx->context_.IsEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
Local<Object> sandbox = PersistentToLocal(isolate, ctx->sandbox_);
|
Local<Object> sandbox = PersistentToLocal(isolate, ctx->sandbox_);
|
||||||
Maybe<PropertyAttribute> maybe_prop_attr =
|
Maybe<PropertyAttribute> maybe_prop_attr =
|
||||||
sandbox->GetRealNamedPropertyAttributes(ctx->context(), property);
|
sandbox->GetRealNamedPropertyAttributes(ctx->context(), property);
|
||||||
@ -428,6 +441,11 @@ class ContextifyContext {
|
|||||||
|
|
||||||
ContextifyContext* ctx =
|
ContextifyContext* ctx =
|
||||||
Unwrap<ContextifyContext>(args.Data().As<Object>());
|
Unwrap<ContextifyContext>(args.Data().As<Object>());
|
||||||
|
|
||||||
|
// Stil initializing
|
||||||
|
if (ctx->context_.IsEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
Local<Object> sandbox = PersistentToLocal(isolate, ctx->sandbox_);
|
Local<Object> sandbox = PersistentToLocal(isolate, ctx->sandbox_);
|
||||||
|
|
||||||
Maybe<bool> success = sandbox->Delete(ctx->context(), property);
|
Maybe<bool> success = sandbox->Delete(ctx->context(), property);
|
||||||
@ -442,6 +460,10 @@ class ContextifyContext {
|
|||||||
ContextifyContext* ctx =
|
ContextifyContext* ctx =
|
||||||
Unwrap<ContextifyContext>(args.Data().As<Object>());
|
Unwrap<ContextifyContext>(args.Data().As<Object>());
|
||||||
|
|
||||||
|
// Stil initializing
|
||||||
|
if (ctx->context_.IsEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
Local<Object> sandbox = PersistentToLocal(args.GetIsolate(), ctx->sandbox_);
|
Local<Object> sandbox = PersistentToLocal(args.GetIsolate(), ctx->sandbox_);
|
||||||
args.GetReturnValue().Set(sandbox->GetPropertyNames());
|
args.GetReturnValue().Set(sandbox->GetPropertyNames());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user