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

Side by Side Diff: src/runtime/runtime-scopes.cc

Issue 1281883002: Group lexical context variables for faster look up. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: added comments and TODOs Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | src/scopeinfo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/arguments.h" 8 #include "src/arguments.h"
9 #include "src/frames-inl.h" 9 #include "src/frames-inl.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 18 matching lines...) Expand all
29 } 29 }
30 30
31 31
32 // May throw a RedeclarationError. 32 // May throw a RedeclarationError.
33 static Object* DeclareGlobals(Isolate* isolate, Handle<GlobalObject> global, 33 static Object* DeclareGlobals(Isolate* isolate, Handle<GlobalObject> global,
34 Handle<String> name, Handle<Object> value, 34 Handle<String> name, Handle<Object> value,
35 PropertyAttributes attr, bool is_var, 35 PropertyAttributes attr, bool is_var,
36 bool is_const, bool is_function) { 36 bool is_const, bool is_function) {
37 Handle<ScriptContextTable> script_contexts( 37 Handle<ScriptContextTable> script_contexts(
38 global->native_context()->script_context_table()); 38 global->native_context()->script_context_table());
39 ScriptContextTable::LookupResult lookup; 39 // We use LookupLexical to limit lookup to lexical variables. As long as
40 if (ScriptContextTable::Lookup(script_contexts, name, &lookup) && 40 // lexical variables are not used extensively, this is a performance win.
41 IsLexicalVariableMode(lookup.mode)) { 41 // TODO(yangguo): reconsider this shortcut.
42 if (ScriptContextTable::LookupLexical(script_contexts, name)) {
42 return ThrowRedeclarationError(isolate, name); 43 return ThrowRedeclarationError(isolate, name);
43 } 44 }
44 45
45 // Do the lookup own properties only, see ES5 erratum. 46 // Do the lookup own properties only, see ES5 erratum.
46 LookupIterator it(global, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); 47 LookupIterator it(global, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
47 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); 48 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
48 if (!maybe.IsJust()) return isolate->heap()->exception(); 49 if (!maybe.IsJust()) return isolate->heap()->exception();
49 50
50 if (it.IsFound()) { 51 if (it.IsFound()) {
51 PropertyAttributes old_attributes = maybe.FromJust(); 52 PropertyAttributes old_attributes = maybe.FromJust();
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 pretenure_flag); 618 pretenure_flag);
618 } 619 }
619 620
620 static Object* FindNameClash(Handle<ScopeInfo> scope_info, 621 static Object* FindNameClash(Handle<ScopeInfo> scope_info,
621 Handle<GlobalObject> global_object, 622 Handle<GlobalObject> global_object,
622 Handle<ScriptContextTable> script_context) { 623 Handle<ScriptContextTable> script_context) {
623 Isolate* isolate = scope_info->GetIsolate(); 624 Isolate* isolate = scope_info->GetIsolate();
624 for (int var = 0; var < scope_info->ContextLocalCount(); var++) { 625 for (int var = 0; var < scope_info->ContextLocalCount(); var++) {
625 Handle<String> name(scope_info->ContextLocalName(var)); 626 Handle<String> name(scope_info->ContextLocalName(var));
626 VariableMode mode = scope_info->ContextLocalMode(var); 627 VariableMode mode = scope_info->ContextLocalMode(var);
627 ScriptContextTable::LookupResult lookup; 628 if (IsLexicalVariableMode(mode)) {
628 if (ScriptContextTable::Lookup(script_context, name, &lookup)) { 629 ScriptContextTable::LookupResult lookup;
629 if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode)) { 630 if (ScriptContextTable::Lookup(script_context, name, &lookup)) {
631 return ThrowRedeclarationError(isolate, name);
632 }
633 } else {
634 if (ScriptContextTable::LookupLexical(script_context, name)) {
630 return ThrowRedeclarationError(isolate, name); 635 return ThrowRedeclarationError(isolate, name);
631 } 636 }
632 } 637 }
633 638
634 if (IsLexicalVariableMode(mode)) { 639 if (IsLexicalVariableMode(mode)) {
635 LookupIterator it(global_object, name, 640 LookupIterator it(global_object, name,
636 LookupIterator::HIDDEN_SKIP_INTERCEPTOR); 641 LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
637 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); 642 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
638 if (!maybe.IsJust()) return isolate->heap()->exception(); 643 if (!maybe.IsJust()) return isolate->heap()->exception();
639 if ((maybe.FromJust() & DONT_DELETE) != 0) { 644 if ((maybe.FromJust() & DONT_DELETE) != 0) {
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 1166
1162 // Lookup in the initial Object.prototype object. 1167 // Lookup in the initial Object.prototype object.
1163 Handle<Object> result; 1168 Handle<Object> result;
1164 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1169 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1165 isolate, result, 1170 isolate, result,
1166 Object::GetProperty(isolate->initial_object_prototype(), key)); 1171 Object::GetProperty(isolate->initial_object_prototype(), key));
1167 return *result; 1172 return *result;
1168 } 1173 }
1169 } // namespace internal 1174 } // namespace internal
1170 } // namespace v8 1175 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698