Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1466)

Unified Diff: src/contexts.cc

Issue 28027: Speed up access to global variables from eval scopes. Traverse the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/contexts.cc
===================================================================
--- src/contexts.cc (revision 1344)
+++ src/contexts.cc (working copy)
@@ -198,6 +198,42 @@
}
+bool Context::GlobalIfNotShadowedByEval(Handle<String> name) {
+ Context* context = this;
+
+ // Check that there is no local with the given name in contexts
+ // before the global context and check that there are no context
+ // extension objects (conservative check for with statements).
+ while (!context->IsGlobalContext()) {
+ // Check if the context is a potentially a with context.
+ if (context->has_extension()) return false;
+
+ // Not a with context so it must be a function context.
+ ASSERT(context->is_function_context());
+
+ // Check non-parameter locals.
+ Handle<Code> code(context->closure()->code());
+ Variable::Mode mode;
+ int index = ScopeInfo<>::ContextSlotIndex(*code, *name, &mode);
+ ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS);
+ if (index >= 0) return false;
+
+ // Check parameter locals.
+ int param_index = ScopeInfo<>::ParameterIndex(*code, *name);
+ if (param_index >= 0) return false;
+
+ // Check context only holding the function name variable.
+ index = ScopeInfo<>::FunctionContextSlotIndex(*code, *name);
+ if (index >= 0) return false;
+ context = Context::cast(context->closure()->context());
+ }
+
+ // No local or potential with statement found so the variable is
+ // global unless it is shadowed by an eval-introduced variable.
+ return true;
+}
+
+
#ifdef DEBUG
bool Context::IsBootstrappingOrContext(Object* object) {
// During bootstrapping we allow all objects to pass as

Powered by Google App Engine
This is Rietveld 408576698