From 66566df5773c8ef2f0e1181e8f9e47403e68c4b7 Mon Sep 17 00:00:00 2001 From: Ali Ijaz Sheikh Date: Wed, 24 Feb 2016 09:52:08 -0800 Subject: [PATCH] contextify: cache sandbox and context in locals PR-URL: https://github.com/nodejs/node/pull/5392 Reviewed-By: Reviewed-By: bnoordhuis - Ben Noordhuis --- src/node_contextify.cc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 22759af8ccb4f5..5d86515b1b13bf 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -58,8 +58,7 @@ class ContextifyContext { Persistent context_; public: - explicit ContextifyContext(Environment* env, Local sandbox_obj) - : env_(env) { + ContextifyContext(Environment* env, Local sandbox_obj) : env_(env) { Local v8_context = CreateV8Context(env, sandbox_obj); context_.Reset(env->isolate(), v8_context); @@ -122,6 +121,7 @@ class ContextifyContext { Local context = PersistentToLocal(env()->isolate(), context_); Local global = context->Global()->GetPrototype()->ToObject(env()->isolate()); + Local sandbox_obj = sandbox(); Local clone_property_method; @@ -129,7 +129,7 @@ class ContextifyContext { int length = names->Length(); for (int i = 0; i < length; i++) { Local key = names->Get(i)->ToString(env()->isolate()); - bool has = sandbox()->HasOwnProperty(context, key).FromJust(); + bool has = sandbox_obj->HasOwnProperty(context, key).FromJust(); if (!has) { // Could also do this like so: // @@ -161,7 +161,7 @@ class ContextifyContext { clone_property_method = Local::Cast(script->Run()); CHECK(clone_property_method->IsFunction()); } - Local args[] = { global, key, sandbox() }; + Local args[] = { global, key, sandbox_obj }; clone_property_method->Call(global, ARRAY_SIZE(args), args); } } @@ -335,16 +335,18 @@ class ContextifyContext { if (ctx->context_.IsEmpty()) return; + Local context = ctx->context(); + Local sandbox = ctx->sandbox(); MaybeLocal maybe_rv = - ctx->sandbox()->GetRealNamedProperty(ctx->context(), property); + sandbox->GetRealNamedProperty(context, property); if (maybe_rv.IsEmpty()) { maybe_rv = - ctx->global_proxy()->GetRealNamedProperty(ctx->context(), property); + ctx->global_proxy()->GetRealNamedProperty(context, property); } Local rv; if (maybe_rv.ToLocal(&rv)) { - if (rv == ctx->sandbox()) + if (rv == sandbox) rv = ctx->global_proxy(); args.GetReturnValue().Set(rv); @@ -377,14 +379,14 @@ class ContextifyContext { if (ctx->context_.IsEmpty()) return; + Local context = ctx->context(); Maybe maybe_prop_attr = - ctx->sandbox()->GetRealNamedPropertyAttributes(ctx->context(), - property); + ctx->sandbox()->GetRealNamedPropertyAttributes(context, property); if (maybe_prop_attr.IsNothing()) { maybe_prop_attr = - ctx->global_proxy()->GetRealNamedPropertyAttributes(ctx->context(), - property); + ctx->global_proxy()->GetRealNamedPropertyAttributes(context, + property); } if (maybe_prop_attr.IsJust()) {