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

Side by Side Diff: src/scopes.cc

Issue 10872084: Allocate block-scoped global bindings to global context. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 temps_(4, zone), 111 temps_(4, zone),
112 params_(4, zone), 112 params_(4, zone),
113 unresolved_(16, zone), 113 unresolved_(16, zone),
114 decls_(4, zone), 114 decls_(4, zone),
115 interface_(FLAG_harmony_modules && 115 interface_(FLAG_harmony_modules &&
116 (type == MODULE_SCOPE || type == GLOBAL_SCOPE) 116 (type == MODULE_SCOPE || type == GLOBAL_SCOPE)
117 ? Interface::NewModule(zone) : NULL), 117 ? Interface::NewModule(zone) : NULL),
118 already_resolved_(false), 118 already_resolved_(false),
119 zone_(zone) { 119 zone_(zone) {
120 SetDefaults(type, outer_scope, Handle<ScopeInfo>::null()); 120 SetDefaults(type, outer_scope, Handle<ScopeInfo>::null());
121 // At some point we might want to provide outer scopes to 121 // The outermost scope must be a global scope.
122 // eval scopes (by walking the stack and reading the scope info). 122 ASSERT(type == GLOBAL_SCOPE || outer_scope != NULL);
123 // In that case, the ASSERT below needs to be adjusted.
124 ASSERT_EQ(type == GLOBAL_SCOPE, outer_scope == NULL);
125 ASSERT(!HasIllegalRedeclaration()); 123 ASSERT(!HasIllegalRedeclaration());
126 } 124 }
127 125
128 126
129 Scope::Scope(Scope* inner_scope, 127 Scope::Scope(Scope* inner_scope,
130 ScopeType type, 128 ScopeType type,
131 Handle<ScopeInfo> scope_info, 129 Handle<ScopeInfo> scope_info,
132 Zone* zone) 130 Zone* zone)
133 : isolate_(Isolate::Current()), 131 : isolate_(Isolate::Current()),
134 inner_scopes_(4, zone), 132 inner_scopes_(4, zone),
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 switch (binding_kind) { 1032 switch (binding_kind) {
1035 case BOUND: 1033 case BOUND:
1036 // We found a variable binding. 1034 // We found a variable binding.
1037 break; 1035 break;
1038 1036
1039 case BOUND_EVAL_SHADOWED: 1037 case BOUND_EVAL_SHADOWED:
1040 // We either found a variable binding that might be shadowed by eval or 1038 // We either found a variable binding that might be shadowed by eval or
1041 // gave up on it (e.g. by encountering a local with the same in the outer 1039 // gave up on it (e.g. by encountering a local with the same in the outer
1042 // scope which was not promoted to a context, this can happen if we use 1040 // scope which was not promoted to a context, this can happen if we use
1043 // debugger to evaluate arbitrary expressions at a break point). 1041 // debugger to evaluate arbitrary expressions at a break point).
1044 if (var->is_global()) { 1042 if (var->IsGlobalObjectProperty()) {
1045 var = NonLocal(proxy->name(), DYNAMIC_GLOBAL); 1043 var = NonLocal(proxy->name(), DYNAMIC_GLOBAL);
1046 } else if (var->is_dynamic()) { 1044 } else if (var->is_dynamic()) {
1047 var = NonLocal(proxy->name(), DYNAMIC); 1045 var = NonLocal(proxy->name(), DYNAMIC);
1048 } else { 1046 } else {
1049 Variable* invalidated = var; 1047 Variable* invalidated = var;
1050 var = NonLocal(proxy->name(), DYNAMIC_LOCAL); 1048 var = NonLocal(proxy->name(), DYNAMIC_LOCAL);
1051 var->set_local_if_not_shadowed(invalidated); 1049 var->set_local_if_not_shadowed(invalidated);
1052 } 1050 }
1053 break; 1051 break;
1054 1052
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 // Give var a read/write use if there is a chance it might be accessed 1153 // Give var a read/write use if there is a chance it might be accessed
1156 // via an eval() call. This is only possible if the variable has a 1154 // via an eval() call. This is only possible if the variable has a
1157 // visible name. 1155 // visible name.
1158 if ((var->is_this() || var->name()->length() > 0) && 1156 if ((var->is_this() || var->name()->length() > 0) &&
1159 (var->has_forced_context_allocation() || 1157 (var->has_forced_context_allocation() ||
1160 scope_calls_eval_ || 1158 scope_calls_eval_ ||
1161 inner_scope_calls_eval_ || 1159 inner_scope_calls_eval_ ||
1162 scope_contains_with_ || 1160 scope_contains_with_ ||
1163 is_catch_scope() || 1161 is_catch_scope() ||
1164 is_block_scope() || 1162 is_block_scope() ||
1165 is_module_scope())) { 1163 is_module_scope() ||
1164 is_global_scope())) {
1166 var->set_is_used(true); 1165 var->set_is_used(true);
1167 } 1166 }
1168 // Global variables do not need to be allocated. 1167 // Global variables do not need to be allocated.
1169 return !var->is_global() && var->is_used(); 1168 return !var->IsGlobalObjectProperty() && var->is_used();
1170 } 1169 }
1171 1170
1172 1171
1173 bool Scope::MustAllocateInContext(Variable* var) { 1172 bool Scope::MustAllocateInContext(Variable* var) {
1174 // If var is accessed from an inner scope, or if there is a possibility 1173 // If var is accessed from an inner scope, or if there is a possibility
1175 // that it might be accessed from the current or an inner scope (through 1174 // that it might be accessed from the current or an inner scope (through
1176 // an eval() call or a runtime with lookup), it must be allocated in the 1175 // an eval() call or a runtime with lookup), it must be allocated in the
1177 // context. 1176 // context.
1178 // 1177 //
1179 // Exceptions: temporary variables are never allocated in a context; 1178 // Exceptions: temporary variables are never allocated in a context;
1180 // catch-bound variables are always allocated in a context. 1179 // catch-bound variables are always allocated in a context.
1181 if (var->mode() == TEMPORARY) return false; 1180 if (var->mode() == TEMPORARY) return false;
1182 if (is_catch_scope() || is_block_scope() || is_module_scope()) return true; 1181 if (is_catch_scope() || is_block_scope() || is_module_scope()) return true;
1182 if (is_global_scope() && (var->mode() == LET || var->mode() == CONST_HARMONY))
1183 return true;
1183 return var->has_forced_context_allocation() || 1184 return var->has_forced_context_allocation() ||
1184 scope_calls_eval_ || 1185 scope_calls_eval_ ||
1185 inner_scope_calls_eval_ || 1186 inner_scope_calls_eval_ ||
1186 scope_contains_with_ || 1187 scope_contains_with_;
1187 var->is_global();
1188 } 1188 }
1189 1189
1190 1190
1191 bool Scope::HasArgumentsParameter() { 1191 bool Scope::HasArgumentsParameter() {
1192 for (int i = 0; i < params_.length(); i++) { 1192 for (int i = 0; i < params_.length(); i++) {
1193 if (params_[i]->name().is_identical_to( 1193 if (params_[i]->name().is_identical_to(
1194 isolate_->factory()->arguments_symbol())) { 1194 isolate_->factory()->arguments_symbol())) {
1195 return true; 1195 return true;
1196 } 1196 }
1197 } 1197 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 for (int i = 0; i < inner_scopes_.length(); i++) { 1425 for (int i = 0; i < inner_scopes_.length(); i++) {
1426 Scope* inner_scope = inner_scopes_.at(i); 1426 Scope* inner_scope = inner_scopes_.at(i);
1427 if (inner_scope->is_module_scope()) { 1427 if (inner_scope->is_module_scope()) {
1428 inner_scope->LinkModules(info); 1428 inner_scope->LinkModules(info);
1429 } 1429 }
1430 } 1430 }
1431 } 1431 }
1432 1432
1433 1433
1434 } } // namespace v8::internal 1434 } } // namespace v8::internal
OLDNEW
« src/parser.cc ('K') | « src/runtime.cc ('k') | src/variables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698