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 0662fcf

Browse filesBrowse files
ofrobotsrvagg
authored andcommitted
contextify: cache sandbox and context in locals
PR-URL: #5392 Reviewed-By: Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
1 parent 4f2c839 commit 0662fcf
Copy full SHA for 0662fcf

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

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

‎src/node_contextify.cc‎

Copy file name to clipboardExpand all lines: src/node_contextify.cc
+13-11Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ class ContextifyContext {
5858
Persistent<Context> context_;
5959

6060
public:
61-
explicit ContextifyContext(Environment* env, Local<Object> sandbox_obj)
62-
: env_(env) {
61+
ContextifyContext(Environment* env, Local<Object> sandbox_obj) : env_(env) {
6362
Local<Context> v8_context = CreateV8Context(env, sandbox_obj);
6463
context_.Reset(env->isolate(), v8_context);
6564

@@ -122,14 +121,15 @@ class ContextifyContext {
122121
Local<Context> context = PersistentToLocal(env()->isolate(), context_);
123122
Local<Object> global =
124123
context->Global()->GetPrototype()->ToObject(env()->isolate());
124+
Local<Object> sandbox_obj = sandbox();
125125

126126
Local<Function> clone_property_method;
127127

128128
Local<Array> names = global->GetOwnPropertyNames();
129129
int length = names->Length();
130130
for (int i = 0; i < length; i++) {
131131
Local<String> key = names->Get(i)->ToString(env()->isolate());
132-
bool has = sandbox()->HasOwnProperty(context, key).FromJust();
132+
bool has = sandbox_obj->HasOwnProperty(context, key).FromJust();
133133
if (!has) {
134134
// Could also do this like so:
135135
//
@@ -162,7 +162,7 @@ class ContextifyContext {
162162
clone_property_method = Local<Function>::Cast(script->Run());
163163
CHECK(clone_property_method->IsFunction());
164164
}
165-
Local<Value> args[] = { global, key, sandbox() };
165+
Local<Value> args[] = { global, key, sandbox_obj };
166166
clone_property_method->Call(global, ARRAY_SIZE(args), args);
167167
}
168168
}
@@ -335,16 +335,18 @@ class ContextifyContext {
335335
if (ctx->context_.IsEmpty())
336336
return;
337337

338+
Local<Context> context = ctx->context();
339+
Local<Object> sandbox = ctx->sandbox();
338340
MaybeLocal<Value> maybe_rv =
339-
ctx->sandbox()->GetRealNamedProperty(ctx->context(), property);
341+
sandbox->GetRealNamedProperty(context, property);
340342
if (maybe_rv.IsEmpty()) {
341343
maybe_rv =
342-
ctx->global_proxy()->GetRealNamedProperty(ctx->context(), property);
344+
ctx->global_proxy()->GetRealNamedProperty(context, property);
343345
}
344346

345347
Local<Value> rv;
346348
if (maybe_rv.ToLocal(&rv)) {
347-
if (rv == ctx->sandbox())
349+
if (rv == sandbox)
348350
rv = ctx->global_proxy();
349351

350352
args.GetReturnValue().Set(rv);
@@ -377,14 +379,14 @@ class ContextifyContext {
377379
if (ctx->context_.IsEmpty())
378380
return;
379381

382+
Local<Context> context = ctx->context();
380383
Maybe<PropertyAttribute> maybe_prop_attr =
381-
ctx->sandbox()->GetRealNamedPropertyAttributes(ctx->context(),
382-
property);
384+
ctx->sandbox()->GetRealNamedPropertyAttributes(context, property);
383385

384386
if (maybe_prop_attr.IsNothing()) {
385387
maybe_prop_attr =
386-
ctx->global_proxy()->GetRealNamedPropertyAttributes(ctx->context(),
387-
property);
388+
ctx->global_proxy()->GetRealNamedPropertyAttributes(context,
389+
property);
388390
}
389391

390392
if (maybe_prop_attr.IsJust()) {

0 commit comments

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