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