@@ -50,21 +50,19 @@ class ContextifyContext {
5050 protected:
5151 enum Kind {
5252 kSandbox ,
53- kContext ,
54- kProxyGlobal
53+ kContext
5554 };
5655
5756 Environment* const env_;
5857 Persistent<Object> sandbox_;
5958 Persistent<Context> context_;
60- Persistent<Object> proxy_global_;
6159 int references_;
6260
6361 public:
6462 explicit ContextifyContext (Environment* env, Local<Object> sandbox)
6563 : env_(env),
6664 sandbox_(env->isolate (), sandbox),
67- // Wait for sandbox_, proxy_global_, and context_ to die
65+ // Wait for sandbox_ and context_ to die
6866 references_(0 ) {
6967 context_.Reset (env->isolate (), CreateV8Context (env));
7068
@@ -78,17 +76,11 @@ class ContextifyContext {
7876 context_.SetWeak (this , WeakCallback<Context, kContext >);
7977 context_.MarkIndependent ();
8078 references_++;
81-
82- proxy_global_.Reset (env->isolate (), context ()->Global ());
83- proxy_global_.SetWeak (this , WeakCallback<Object, kProxyGlobal >);
84- proxy_global_.MarkIndependent ();
85- references_++;
8679 }
8780
8881
8982 ~ContextifyContext () {
9083 context_.Reset ();
91- proxy_global_.Reset ();
9284 sandbox_.Reset ();
9385 }
9486
@@ -103,6 +95,10 @@ class ContextifyContext {
10395 }
10496
10597
98+ inline Local<Object> global_proxy () const {
99+ return context ()->Global ();
100+ }
101+
106102 // XXX(isaacs): This function only exists because of a shortcoming of
107103 // the V8 SetNamedPropertyHandler function.
108104 //
@@ -318,10 +314,8 @@ class ContextifyContext {
318314 ContextifyContext* context = data.GetParameter ();
319315 if (kind == kSandbox )
320316 context->sandbox_ .ClearWeak ();
321- else if (kind == kContext )
322- context->context_ .ClearWeak ();
323317 else
324- context->proxy_global_ .ClearWeak ();
318+ context->context_ .ClearWeak ();
325319
326320 if (--context->references_ == 0 )
327321 delete context;
@@ -359,15 +353,14 @@ class ContextifyContext {
359353 MaybeLocal<Value> maybe_rv =
360354 sandbox->GetRealNamedProperty (ctx->context (), property);
361355 if (maybe_rv.IsEmpty ()) {
362- Local<Object> proxy_global = PersistentToLocal (isolate,
363- ctx->proxy_global_ );
364- maybe_rv = proxy_global->GetRealNamedProperty (ctx->context (), property);
356+ maybe_rv =
357+ ctx->global_proxy ()->GetRealNamedProperty (ctx->context (), property);
365358 }
366359
367360 Local<Value> rv;
368361 if (maybe_rv.ToLocal (&rv)) {
369362 if (rv == ctx->sandbox_ )
370- rv = PersistentToLocal (isolate, ctx->proxy_global_ );
363+ rv = ctx->global_proxy ( );
371364
372365 args.GetReturnValue ().Set (rv);
373366 }
@@ -408,11 +401,8 @@ class ContextifyContext {
408401 sandbox->GetRealNamedPropertyAttributes (ctx->context (), property);
409402
410403 if (maybe_prop_attr.IsNothing ()) {
411- Local<Object> proxy_global = PersistentToLocal (isolate,
412- ctx->proxy_global_ );
413-
414404 maybe_prop_attr =
415- proxy_global ->GetRealNamedPropertyAttributes (ctx->context (),
405+ ctx-> global_proxy () ->GetRealNamedPropertyAttributes (ctx->context (),
416406 property);
417407 }
418408
0 commit comments