| OLD | NEW |
| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
| 9 #include "src/messages.h" | 9 #include "src/messages.h" |
| 10 #include "src/parser.h" | 10 #include "src/parser.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 new_target_ = nullptr; | 149 new_target_ = nullptr; |
| 150 function_ = NULL; | 150 function_ = NULL; |
| 151 arguments_ = NULL; | 151 arguments_ = NULL; |
| 152 illegal_redecl_ = NULL; | 152 illegal_redecl_ = NULL; |
| 153 scope_inside_with_ = false; | 153 scope_inside_with_ = false; |
| 154 scope_contains_with_ = false; | 154 scope_contains_with_ = false; |
| 155 scope_calls_eval_ = false; | 155 scope_calls_eval_ = false; |
| 156 scope_uses_arguments_ = false; | 156 scope_uses_arguments_ = false; |
| 157 scope_uses_super_property_ = false; | 157 scope_uses_super_property_ = false; |
| 158 scope_uses_this_ = false; | 158 scope_uses_this_ = false; |
| 159 scope_uses_new_target_ = false; |
| 159 asm_module_ = false; | 160 asm_module_ = false; |
| 160 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; | 161 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; |
| 161 // Inherit the language mode from the parent scope. | 162 // Inherit the language mode from the parent scope. |
| 162 language_mode_ = outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY; | 163 language_mode_ = outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY; |
| 163 outer_scope_calls_sloppy_eval_ = false; | 164 outer_scope_calls_sloppy_eval_ = false; |
| 164 inner_scope_calls_eval_ = false; | 165 inner_scope_calls_eval_ = false; |
| 165 inner_scope_uses_arguments_ = false; | 166 inner_scope_uses_arguments_ = false; |
| 166 inner_scope_uses_this_ = false; | 167 inner_scope_uses_this_ = false; |
| 168 inner_scope_uses_new_target_ = false; |
| 167 inner_scope_uses_super_property_ = false; | 169 inner_scope_uses_super_property_ = false; |
| 168 force_eager_compilation_ = false; | 170 force_eager_compilation_ = false; |
| 169 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) | 171 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |
| 170 ? outer_scope->has_forced_context_allocation() : false; | 172 ? outer_scope->has_forced_context_allocation() : false; |
| 171 num_var_or_const_ = 0; | 173 num_var_or_const_ = 0; |
| 172 num_stack_slots_ = 0; | 174 num_stack_slots_ = 0; |
| 173 num_heap_slots_ = 0; | 175 num_heap_slots_ = 0; |
| 174 num_modules_ = 0; | 176 num_modules_ = 0; |
| 175 module_var_ = NULL, | 177 module_var_ = NULL, |
| 176 rest_parameter_ = NULL; | 178 rest_parameter_ = NULL; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // invoking scripts | 311 // invoking scripts |
| 310 if (is_declaration_scope()) { | 312 if (is_declaration_scope()) { |
| 311 DCHECK(!subclass_constructor || is_function_scope()); | 313 DCHECK(!subclass_constructor || is_function_scope()); |
| 312 Variable* var = variables_.Declare( | 314 Variable* var = variables_.Declare( |
| 313 this, ast_value_factory_->this_string(), | 315 this, ast_value_factory_->this_string(), |
| 314 subclass_constructor ? CONST : VAR, Variable::THIS, | 316 subclass_constructor ? CONST : VAR, Variable::THIS, |
| 315 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); | 317 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); |
| 316 var->AllocateTo(Variable::PARAMETER, -1); | 318 var->AllocateTo(Variable::PARAMETER, -1); |
| 317 receiver_ = var; | 319 receiver_ = var; |
| 318 | 320 |
| 319 if (subclass_constructor) { | 321 // if (subclass_constructor) { |
| 320 new_target_ = | 322 // new_target_ = |
| 321 variables_.Declare(this, ast_value_factory_->new_target_string(), | 323 // variables_.Declare(this, ast_value_factory_->new_target_string(), |
| 322 CONST, Variable::NEW_TARGET, kCreatedInitialized); | 324 // CONST, Variable::NEW_TARGET, |
| 323 new_target_->AllocateTo(Variable::PARAMETER, -2); | 325 // kCreatedInitialized); |
| 324 new_target_->set_is_used(); | 326 // new_target_->AllocateTo(Variable::PARAMETER, -2); |
| 325 } | 327 // new_target_->set_is_used(); |
| 328 // } |
| 326 } else { | 329 } else { |
| 327 DCHECK(outer_scope() != NULL); | 330 DCHECK(outer_scope() != NULL); |
| 328 receiver_ = outer_scope()->receiver(); | 331 receiver_ = outer_scope()->receiver(); |
| 329 } | 332 } |
| 330 | 333 |
| 331 if (is_function_scope() && !is_arrow_scope()) { | 334 if (is_function_scope() && !is_arrow_scope()) { |
| 332 // Declare 'arguments' variable which exists in all non arrow functions. | 335 // Declare 'arguments' variable which exists in all non arrow functions. |
| 333 // Note that it might never be accessed, in which case it won't be | 336 // Note that it might never be accessed, in which case it won't be |
| 334 // allocated during variable allocation. | 337 // allocated during variable allocation. |
| 335 variables_.Declare(this, | 338 variables_.Declare(this, |
| 336 ast_value_factory_->arguments_string(), | 339 ast_value_factory_->arguments_string(), |
| 337 VAR, | 340 VAR, |
| 338 Variable::ARGUMENTS, | 341 Variable::ARGUMENTS, |
| 339 kCreatedInitialized); | 342 kCreatedInitialized); |
| 343 |
| 344 variables_.Declare(this, ast_value_factory_->new_target_string(), CONST, |
| 345 Variable::NEW_TARGET, kNeedsInitialization); |
| 340 } | 346 } |
| 341 } | 347 } |
| 342 | 348 |
| 343 | 349 |
| 344 Scope* Scope::FinalizeBlockScope() { | 350 Scope* Scope::FinalizeBlockScope() { |
| 345 DCHECK(is_block_scope()); | 351 DCHECK(is_block_scope()); |
| 346 DCHECK(internals_.is_empty()); | 352 DCHECK(internals_.is_empty()); |
| 347 DCHECK(temps_.is_empty()); | 353 DCHECK(temps_.is_empty()); |
| 348 DCHECK(params_.is_empty()); | 354 DCHECK(params_.is_empty()); |
| 349 | 355 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 364 | 370 |
| 365 // Move unresolved variables | 371 // Move unresolved variables |
| 366 for (int i = 0; i < unresolved_.length(); i++) { | 372 for (int i = 0; i < unresolved_.length(); i++) { |
| 367 outer_scope()->unresolved_.Add(unresolved_[i], zone()); | 373 outer_scope()->unresolved_.Add(unresolved_[i], zone()); |
| 368 } | 374 } |
| 369 | 375 |
| 370 // Propagate usage flags to outer scope. | 376 // Propagate usage flags to outer scope. |
| 371 if (uses_arguments()) outer_scope_->RecordArgumentsUsage(); | 377 if (uses_arguments()) outer_scope_->RecordArgumentsUsage(); |
| 372 if (uses_super_property()) outer_scope_->RecordSuperPropertyUsage(); | 378 if (uses_super_property()) outer_scope_->RecordSuperPropertyUsage(); |
| 373 if (uses_this()) outer_scope_->RecordThisUsage(); | 379 if (uses_this()) outer_scope_->RecordThisUsage(); |
| 380 if (uses_new_target()) outer_scope_->RecordNewTargetUsage(); |
| 374 | 381 |
| 375 return NULL; | 382 return NULL; |
| 376 } | 383 } |
| 377 | 384 |
| 378 | 385 |
| 379 Variable* Scope::LookupLocal(const AstRawString* name) { | 386 Variable* Scope::LookupLocal(const AstRawString* name) { |
| 380 Variable* result = variables_.Lookup(name); | 387 Variable* result = variables_.Lookup(name); |
| 381 if (result != NULL || scope_info_.is_null()) { | 388 if (result != NULL || scope_info_.is_null()) { |
| 382 return result; | 389 return result; |
| 383 } | 390 } |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 } else if (is_strict(language_mode())) { | 917 } else if (is_strict(language_mode())) { |
| 911 Indent(n1, "// strict mode scope\n"); | 918 Indent(n1, "// strict mode scope\n"); |
| 912 } | 919 } |
| 913 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); | 920 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); |
| 914 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); | 921 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); |
| 915 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); | 922 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); |
| 916 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n"); | 923 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n"); |
| 917 if (scope_uses_super_property_) | 924 if (scope_uses_super_property_) |
| 918 Indent(n1, "// scope uses 'super' property\n"); | 925 Indent(n1, "// scope uses 'super' property\n"); |
| 919 if (scope_uses_this_) Indent(n1, "// scope uses 'this'\n"); | 926 if (scope_uses_this_) Indent(n1, "// scope uses 'this'\n"); |
| 927 if (scope_uses_new_target_) Indent(n1, "// scope uses 'new.target'\n"); |
| 920 if (inner_scope_uses_arguments_) { | 928 if (inner_scope_uses_arguments_) { |
| 921 Indent(n1, "// inner scope uses 'arguments'\n"); | 929 Indent(n1, "// inner scope uses 'arguments'\n"); |
| 922 } | 930 } |
| 923 if (inner_scope_uses_super_property_) | 931 if (inner_scope_uses_super_property_) |
| 924 Indent(n1, "// inner scope uses 'super' property\n"); | 932 Indent(n1, "// inner scope uses 'super' property\n"); |
| 925 if (inner_scope_uses_this_) Indent(n1, "// inner scope uses 'this'\n"); | 933 if (inner_scope_uses_this_) Indent(n1, "// inner scope uses 'this'\n"); |
| 934 if (inner_scope_uses_new_target_) { |
| 935 Indent(n1, "// inner scope uses 'new.target'\n"); |
| 936 } |
| 926 if (outer_scope_calls_sloppy_eval_) { | 937 if (outer_scope_calls_sloppy_eval_) { |
| 927 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); | 938 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); |
| 928 } | 939 } |
| 929 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); | 940 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); |
| 930 if (num_stack_slots_ > 0) { Indent(n1, "// "); | 941 if (num_stack_slots_ > 0) { Indent(n1, "// "); |
| 931 PrintF("%d stack slots\n", num_stack_slots_); } | 942 PrintF("%d stack slots\n", num_stack_slots_); } |
| 932 if (num_heap_slots_ > 0) { Indent(n1, "// "); | 943 if (num_heap_slots_ > 0) { Indent(n1, "// "); |
| 933 PrintF("%d heap slots\n", num_heap_slots_); } | 944 PrintF("%d heap slots\n", num_heap_slots_); } |
| 934 | 945 |
| 935 // Print locals. | 946 // Print locals. |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) { | 1252 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) { |
| 1242 inner_scope_uses_arguments_ = true; | 1253 inner_scope_uses_arguments_ = true; |
| 1243 } | 1254 } |
| 1244 if (inner->scope_uses_super_property_ || | 1255 if (inner->scope_uses_super_property_ || |
| 1245 inner->inner_scope_uses_super_property_) { | 1256 inner->inner_scope_uses_super_property_) { |
| 1246 inner_scope_uses_super_property_ = true; | 1257 inner_scope_uses_super_property_ = true; |
| 1247 } | 1258 } |
| 1248 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) { | 1259 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) { |
| 1249 inner_scope_uses_this_ = true; | 1260 inner_scope_uses_this_ = true; |
| 1250 } | 1261 } |
| 1262 if (inner->scope_uses_new_target_ || |
| 1263 inner->inner_scope_uses_new_target_) { |
| 1264 inner_scope_uses_new_target_ = true; |
| 1265 } |
| 1251 } | 1266 } |
| 1252 if (inner->force_eager_compilation_) { | 1267 if (inner->force_eager_compilation_) { |
| 1253 force_eager_compilation_ = true; | 1268 force_eager_compilation_ = true; |
| 1254 } | 1269 } |
| 1255 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { | 1270 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { |
| 1256 inner->asm_function_ = true; | 1271 inner->asm_function_ = true; |
| 1257 } | 1272 } |
| 1258 } | 1273 } |
| 1259 } | 1274 } |
| 1260 | 1275 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 AllocateHeapSlot(var); | 1387 AllocateHeapSlot(var); |
| 1373 } | 1388 } |
| 1374 } else { | 1389 } else { |
| 1375 DCHECK(var->IsUnallocated() || var->IsParameter()); | 1390 DCHECK(var->IsUnallocated() || var->IsParameter()); |
| 1376 if (var->IsUnallocated()) { | 1391 if (var->IsUnallocated()) { |
| 1377 var->AllocateTo(Variable::PARAMETER, i); | 1392 var->AllocateTo(Variable::PARAMETER, i); |
| 1378 } | 1393 } |
| 1379 } | 1394 } |
| 1380 } | 1395 } |
| 1381 } | 1396 } |
| 1397 |
| 1398 Variable* new_target = LookupLocal(ast_value_factory_->new_target_string()); |
| 1399 // Functions have 'new_target' declared implicitly in all non arrow functions. |
| 1400 DCHECK(new_target != nullptr || is_arrow_scope()); |
| 1401 |
| 1402 if (new_target != nullptr) { |
| 1403 if (IsSubclassConstructor(function_kind_)) { |
| 1404 new_target->ForceContextAllocation(); |
| 1405 new_target_ = new_target; |
| 1406 } else if (MustAllocate(new_target)) { |
| 1407 new_target_ = new_target; |
| 1408 } |
| 1409 } |
| 1382 } | 1410 } |
| 1383 | 1411 |
| 1384 | 1412 |
| 1385 void Scope::AllocateNonParameterLocal(Isolate* isolate, Variable* var) { | 1413 void Scope::AllocateNonParameterLocal(Isolate* isolate, Variable* var) { |
| 1386 DCHECK(var->scope() == this); | 1414 DCHECK(var->scope() == this); |
| 1387 DCHECK(!var->IsVariable(isolate->factory()->dot_result_string()) || | 1415 DCHECK(!var->IsVariable(isolate->factory()->dot_result_string()) || |
| 1388 !var->IsStackLocal()); | 1416 !var->IsStackLocal()); |
| 1389 if (var->IsUnallocated() && MustAllocate(var)) { | 1417 if (var->IsUnallocated() && MustAllocate(var)) { |
| 1390 if (MustAllocateInContext(var)) { | 1418 if (MustAllocateInContext(var)) { |
| 1391 AllocateHeapSlot(var); | 1419 AllocateHeapSlot(var); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1518 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
| 1491 } | 1519 } |
| 1492 | 1520 |
| 1493 | 1521 |
| 1494 int Scope::ContextLocalCount() const { | 1522 int Scope::ContextLocalCount() const { |
| 1495 if (num_heap_slots() == 0) return 0; | 1523 if (num_heap_slots() == 0) return 0; |
| 1496 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1524 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1497 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1525 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1498 } | 1526 } |
| 1499 } } // namespace v8::internal | 1527 } } // namespace v8::internal |
| OLD | NEW |