Skip to content

Commit 266c409

Browse files
committed
contextify: cleanup weak ref for global proxy
Cleanup how node_contextify keeps weak references in order to prepare for new style phantom weakness API. We didn't need to keep a weak reference to the context's global proxy, as the context holds it. PR-URL: #5392 Reviewed-By: Reviewed-By: bnoordhuis - Ben Noordhuis <[email protected]>
1 parent 7a863af commit 266c409

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/node_contextify.cc

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,19 @@ class ContextifyContext {
5252
protected:
5353
enum Kind {
5454
kSandbox,
55-
kContext,
56-
kProxyGlobal
55+
kContext
5756
};
5857

5958
Environment* const env_;
6059
Persistent<Object> sandbox_;
6160
Persistent<Context> context_;
62-
Persistent<Object> proxy_global_;
6361
int references_;
6462

6563
public:
6664
explicit ContextifyContext(Environment* env, Local<Object> sandbox)
6765
: env_(env),
6866
sandbox_(env->isolate(), sandbox),
69-
// Wait for sandbox_, proxy_global_, and context_ to die
67+
// Wait for sandbox_ and context_ to die
7068
references_(0) {
7169
context_.Reset(env->isolate(), CreateV8Context(env));
7270

@@ -80,17 +78,11 @@ class ContextifyContext {
8078
context_.SetWeak(this, WeakCallback<Context, kContext>);
8179
context_.MarkIndependent();
8280
references_++;
83-
84-
proxy_global_.Reset(env->isolate(), context()->Global());
85-
proxy_global_.SetWeak(this, WeakCallback<Object, kProxyGlobal>);
86-
proxy_global_.MarkIndependent();
87-
references_++;
8881
}
8982

9083

9184
~ContextifyContext() {
9285
context_.Reset();
93-
proxy_global_.Reset();
9486
sandbox_.Reset();
9587
}
9688

@@ -105,6 +97,10 @@ class ContextifyContext {
10597
}
10698

10799

100+
inline Local<Object> global_proxy() const {
101+
return context()->Global();
102+
}
103+
108104
// XXX(isaacs): This function only exists because of a shortcoming of
109105
// the V8 SetNamedPropertyHandler function.
110106
//
@@ -321,10 +317,8 @@ class ContextifyContext {
321317
ContextifyContext* context = data.GetParameter();
322318
if (kind == kSandbox)
323319
context->sandbox_.ClearWeak();
324-
else if (kind == kContext)
325-
context->context_.ClearWeak();
326320
else
327-
context->proxy_global_.ClearWeak();
321+
context->context_.ClearWeak();
328322

329323
if (--context->references_ == 0)
330324
delete context;
@@ -362,15 +356,14 @@ class ContextifyContext {
362356
MaybeLocal<Value> maybe_rv =
363357
sandbox->GetRealNamedProperty(ctx->context(), property);
364358
if (maybe_rv.IsEmpty()) {
365-
Local<Object> proxy_global = PersistentToLocal(isolate,
366-
ctx->proxy_global_);
367-
maybe_rv = proxy_global->GetRealNamedProperty(ctx->context(), property);
359+
maybe_rv =
360+
ctx->global_proxy()->GetRealNamedProperty(ctx->context(), property);
368361
}
369362

370363
Local<Value> rv;
371364
if (maybe_rv.ToLocal(&rv)) {
372365
if (rv == ctx->sandbox_)
373-
rv = PersistentToLocal(isolate, ctx->proxy_global_);
366+
rv = ctx->global_proxy();
374367

375368
args.GetReturnValue().Set(rv);
376369
}
@@ -411,11 +404,8 @@ class ContextifyContext {
411404
sandbox->GetRealNamedPropertyAttributes(ctx->context(), property);
412405

413406
if (maybe_prop_attr.IsNothing()) {
414-
Local<Object> proxy_global = PersistentToLocal(isolate,
415-
ctx->proxy_global_);
416-
417407
maybe_prop_attr =
418-
proxy_global->GetRealNamedPropertyAttributes(ctx->context(),
408+
ctx->global_proxy()->GetRealNamedPropertyAttributes(ctx->context(),
419409
property);
420410
}
421411

0 commit comments

Comments
 (0)