Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 93f60cd

Browse filesBrowse files
ofrobotsrvagg
authored andcommitted
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 <info@bnoordhuis.nl>
1 parent f3e9daa commit 93f60cd
Copy full SHA for 93f60cd

File tree

Expand file treeCollapse file tree

1 file changed

+11
-21
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-21
lines changed
Open diff view settings
Collapse file

‎src/node_contextify.cc‎

Copy file name to clipboardExpand all lines: src/node_contextify.cc
+11-21Lines 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
//
@@ -320,10 +316,8 @@ class ContextifyContext {
320316
ContextifyContext* context = data.GetParameter();
321317
if (kind == kSandbox)
322318
context->sandbox_.ClearWeak();
323-
else if (kind == kContext)
324-
context->context_.ClearWeak();
325319
else
326-
context->proxy_global_.ClearWeak();
320+
context->context_.ClearWeak();
327321

328322
if (--context->references_ == 0)
329323
delete context;
@@ -361,15 +355,14 @@ class ContextifyContext {
361355
MaybeLocal<Value> maybe_rv =
362356
sandbox->GetRealNamedProperty(ctx->context(), property);
363357
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);
367360
}
368361

369362
Local<Value> rv;
370363
if (maybe_rv.ToLocal(&rv)) {
371364
if (rv == ctx->sandbox_)
372-
rv = PersistentToLocal(isolate, ctx->proxy_global_);
365+
rv = ctx->global_proxy();
373366

374367
args.GetReturnValue().Set(rv);
375368
}
@@ -410,11 +403,8 @@ class ContextifyContext {
410403
sandbox->GetRealNamedPropertyAttributes(ctx->context(), property);
411404

412405
if (maybe_prop_attr.IsNothing()) {
413-
Local<Object> proxy_global = PersistentToLocal(isolate,
414-
ctx->proxy_global_);
415-
416406
maybe_prop_attr =
417-
proxy_global->GetRealNamedPropertyAttributes(ctx->context(),
407+
ctx->global_proxy()->GetRealNamedPropertyAttributes(ctx->context(),
418408
property);
419409
}
420410

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.