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

Side by Side Diff: src/ast/scopes.cc

Issue 1490783002: [bootstrapper] add checks for variable bindings in native scripts. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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 | « no previous file | src/bootstrapper.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/ast/scopes.h" 5 #include "src/ast/scopes.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/ast/scopeinfo.h" 8 #include "src/ast/scopeinfo.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 AstNodeFactory ast_node_factory(info->ast_value_factory()); 301 AstNodeFactory ast_node_factory(info->ast_value_factory());
302 if (!top->AllocateVariables(info, &ast_node_factory)) { 302 if (!top->AllocateVariables(info, &ast_node_factory)) {
303 DCHECK(top->pending_error_handler_.has_pending_error()); 303 DCHECK(top->pending_error_handler_.has_pending_error());
304 top->pending_error_handler_.ThrowPendingError(info->isolate(), 304 top->pending_error_handler_.ThrowPendingError(info->isolate(),
305 info->script()); 305 info->script());
306 return false; 306 return false;
307 } 307 }
308 } 308 }
309 309
310 #ifdef DEBUG 310 #ifdef DEBUG
311 bool native = info->isolate()->bootstrapper()->IsActive(); 311 if (info->script_is_native() ? FLAG_print_builtin_scopes
312 if (!info->shared_info().is_null()) { 312 : FLAG_print_scopes) {
313 Object* script = info->shared_info()->script(); 313 scope->Print();
314 native = script->IsScript() &&
315 Script::cast(script)->type() == Script::TYPE_NATIVE;
316 } 314 }
317
318 if (native ? FLAG_print_builtin_scopes : FLAG_print_scopes) scope->Print();
319 #endif 315 #endif
320 316
321 info->set_scope(scope); 317 info->set_scope(scope);
322 return true; 318 return true;
323 } 319 }
324 320
325 321
326 void Scope::Initialize() { 322 void Scope::Initialize() {
327 DCHECK(!already_resolved()); 323 DCHECK(!already_resolved());
328 324
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 AstNodeFactory* factory) { 1150 AstNodeFactory* factory) {
1155 DCHECK(info->script_scope()->is_script_scope()); 1151 DCHECK(info->script_scope()->is_script_scope());
1156 1152
1157 // If the proxy is already resolved there's nothing to do 1153 // If the proxy is already resolved there's nothing to do
1158 // (functions and consts may be resolved by the parser). 1154 // (functions and consts may be resolved by the parser).
1159 if (proxy->is_resolved()) return true; 1155 if (proxy->is_resolved()) return true;
1160 1156
1161 // Otherwise, try to resolve the variable. 1157 // Otherwise, try to resolve the variable.
1162 BindingKind binding_kind; 1158 BindingKind binding_kind;
1163 Variable* var = LookupRecursive(proxy, &binding_kind, factory); 1159 Variable* var = LookupRecursive(proxy, &binding_kind, factory);
1160
1161 #ifdef DEBUG
1162 if (info->script_is_native()) {
1163 // To avoid polluting the global object in native scripts
1164 // - Variables must not be allocated to the global scope.
1165 CHECK_NOT_NULL(outer_scope());
1166 // - Variables must be bound locally or unallocated.
1167 CHECK_EQ(BOUND, binding_kind);
1168 VariableLocation location = var->location();
1169 CHECK(location == VariableLocation::LOCAL ||
1170 location == VariableLocation::CONTEXT ||
1171 location == VariableLocation::PARAMETER ||
1172 location == VariableLocation::UNALLOCATED);
1173 }
1174 #endif
1175
1164 switch (binding_kind) { 1176 switch (binding_kind) {
1165 case BOUND: 1177 case BOUND:
1166 // We found a variable binding. 1178 // We found a variable binding.
1167 if (is_strong(language_mode())) { 1179 if (is_strong(language_mode())) {
1168 if (!CheckStrongModeDeclaration(proxy, var)) return false; 1180 if (!CheckStrongModeDeclaration(proxy, var)) return false;
1169 } 1181 }
1170 break; 1182 break;
1171 1183
1172 case BOUND_EVAL_SHADOWED: 1184 case BOUND_EVAL_SHADOWED:
1173 // We either found a variable binding that might be shadowed by eval or 1185 // We either found a variable binding that might be shadowed by eval or
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 function_ != NULL && function_->proxy()->var()->IsContextSlot(); 1677 function_ != NULL && function_->proxy()->var()->IsContextSlot();
1666 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1678 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1667 (is_function_var_in_context ? 1 : 0); 1679 (is_function_var_in_context ? 1 : 0);
1668 } 1680 }
1669 1681
1670 1682
1671 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1683 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1672 1684
1673 } // namespace internal 1685 } // namespace internal
1674 } // namespace v8 1686 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698