@@ -50,21 +50,19 @@ class ContextifyContext {
50
50
protected:
51
51
enum Kind {
52
52
kSandbox ,
53
- kContext ,
54
- kProxyGlobal
53
+ kContext
55
54
};
56
55
57
56
Environment* const env_;
58
57
Persistent<Object> sandbox_;
59
58
Persistent<Context> context_;
60
- Persistent<Object> proxy_global_;
61
59
int references_;
62
60
63
61
public:
64
62
explicit ContextifyContext (Environment* env, Local<Object> sandbox)
65
63
: env_(env),
66
64
sandbox_(env->isolate (), sandbox),
67
- // Wait for sandbox_, proxy_global_, and context_ to die
65
+ // Wait for sandbox_ and context_ to die
68
66
references_(0 ) {
69
67
context_.Reset (env->isolate (), CreateV8Context (env));
70
68
@@ -78,17 +76,11 @@ class ContextifyContext {
78
76
context_.SetWeak (this , WeakCallback<Context, kContext >);
79
77
context_.MarkIndependent ();
80
78
references_++;
81
-
82
- proxy_global_.Reset (env->isolate (), context ()->Global ());
83
- proxy_global_.SetWeak (this , WeakCallback<Object, kProxyGlobal >);
84
- proxy_global_.MarkIndependent ();
85
- references_++;
86
79
}
87
80
88
81
89
82
~ContextifyContext () {
90
83
context_.Reset ();
91
- proxy_global_.Reset ();
92
84
sandbox_.Reset ();
93
85
}
94
86
@@ -103,6 +95,10 @@ class ContextifyContext {
103
95
}
104
96
105
97
98
+ inline Local<Object> global_proxy () const {
99
+ return context ()->Global ();
100
+ }
101
+
106
102
// XXX(isaacs): This function only exists because of a shortcoming of
107
103
// the V8 SetNamedPropertyHandler function.
108
104
//
@@ -318,10 +314,8 @@ class ContextifyContext {
318
314
ContextifyContext* context = data.GetParameter ();
319
315
if (kind == kSandbox )
320
316
context->sandbox_ .ClearWeak ();
321
- else if (kind == kContext )
322
- context->context_ .ClearWeak ();
323
317
else
324
- context->proxy_global_ .ClearWeak ();
318
+ context->context_ .ClearWeak ();
325
319
326
320
if (--context->references_ == 0 )
327
321
delete context;
@@ -359,15 +353,14 @@ class ContextifyContext {
359
353
MaybeLocal<Value> maybe_rv =
360
354
sandbox->GetRealNamedProperty (ctx->context (), property);
361
355
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);
365
358
}
366
359
367
360
Local<Value> rv;
368
361
if (maybe_rv.ToLocal (&rv)) {
369
362
if (rv == ctx->sandbox_ )
370
- rv = PersistentToLocal (isolate, ctx->proxy_global_ );
363
+ rv = ctx->global_proxy ( );
371
364
372
365
args.GetReturnValue ().Set (rv);
373
366
}
@@ -408,11 +401,8 @@ class ContextifyContext {
408
401
sandbox->GetRealNamedPropertyAttributes (ctx->context (), property);
409
402
410
403
if (maybe_prop_attr.IsNothing ()) {
411
- Local<Object> proxy_global = PersistentToLocal (isolate,
412
- ctx->proxy_global_ );
413
-
414
404
maybe_prop_attr =
415
- proxy_global ->GetRealNamedPropertyAttributes (ctx->context (),
405
+ ctx-> global_proxy () ->GetRealNamedPropertyAttributes (ctx->context (),
416
406
property);
417
407
}
418
408
0 commit comments