| 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/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast.h" | 8 #include "src/ast.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 342 |
| 343 | 343 |
| 344 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor | 344 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor |
| 345 : FunctionKind::kDefaultBaseConstructor; | 345 : FunctionKind::kDefaultBaseConstructor; |
| 346 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind); | 346 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind); |
| 347 function_scope->SetLanguageMode( | 347 function_scope->SetLanguageMode( |
| 348 static_cast<LanguageMode>(scope->language_mode() | STRICT_BIT)); | 348 static_cast<LanguageMode>(scope->language_mode() | STRICT_BIT)); |
| 349 // Set start and end position to the same value | 349 // Set start and end position to the same value |
| 350 function_scope->set_start_position(pos); | 350 function_scope->set_start_position(pos); |
| 351 function_scope->set_end_position(pos); | 351 function_scope->set_end_position(pos); |
| 352 if (call_super) { |
| 353 function_scope->RecordNewTargetUsage(); |
| 354 } |
| 352 ZoneList<Statement*>* body = NULL; | 355 ZoneList<Statement*>* body = NULL; |
| 353 | 356 |
| 354 { | 357 { |
| 355 AstNodeFactory function_factory(ast_value_factory()); | 358 AstNodeFactory function_factory(ast_value_factory()); |
| 356 FunctionState function_state(&function_state_, &scope_, function_scope, | 359 FunctionState function_state(&function_state_, &scope_, function_scope, |
| 357 kind, &function_factory); | 360 kind, &function_factory); |
| 358 | 361 |
| 359 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); | 362 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); |
| 360 AddAssertIsConstruct(body, pos); | 363 AddAssertIsConstruct(body, pos); |
| 361 if (call_super) { | 364 if (call_super) { |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { | 738 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { |
| 736 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); | 739 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); |
| 737 } | 740 } |
| 738 | 741 |
| 739 | 742 |
| 740 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, | 743 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, |
| 741 int pos) { | 744 int pos) { |
| 742 return factory->NewVariableProxy(scope->receiver(), pos); | 745 return factory->NewVariableProxy(scope->receiver(), pos); |
| 743 } | 746 } |
| 744 | 747 |
| 748 |
| 749 Expression* ParserTraits::NewTargetExpression(Scope* scope, |
| 750 AstNodeFactory* factory, |
| 751 int start_position, |
| 752 int end_position) { |
| 753 return scope->NewUnresolved( |
| 754 factory, parser_->ast_value_factory()->new_target_string(), |
| 755 Variable::NEW_TARGET, start_position, end_position); |
| 756 } |
| 757 |
| 758 |
| 745 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, | 759 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, |
| 746 int pos) { | 760 int pos) { |
| 747 return factory->NewSuperReference( | 761 return factory->NewSuperReference( |
| 748 ThisExpression(scope, factory, pos)->AsVariableProxy(), | 762 ThisExpression(scope, factory, pos)->AsVariableProxy(), |
| 749 pos); | 763 pos); |
| 750 } | 764 } |
| 751 | 765 |
| 752 | 766 |
| 753 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, | 767 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, |
| 754 int pos, int end_pos) { | 768 int pos, int end_pos) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 780 return NULL; | 794 return NULL; |
| 781 } | 795 } |
| 782 | 796 |
| 783 | 797 |
| 784 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, | 798 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, |
| 785 int start_position, | 799 int start_position, |
| 786 int end_position, | 800 int end_position, |
| 787 Scope* scope, | 801 Scope* scope, |
| 788 AstNodeFactory* factory) { | 802 AstNodeFactory* factory) { |
| 789 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); | 803 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); |
| 790 return scope->NewUnresolved(factory, name, start_position, end_position); | 804 return scope->NewUnresolved(factory, name, Variable::NORMAL, start_position, |
| 805 end_position); |
| 791 } | 806 } |
| 792 | 807 |
| 793 | 808 |
| 794 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, | 809 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, |
| 795 AstNodeFactory* factory) { | 810 AstNodeFactory* factory) { |
| 796 const AstRawString* symbol = GetSymbol(scanner); | 811 const AstRawString* symbol = GetSymbol(scanner); |
| 797 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 812 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
| 798 return factory->NewStringLiteral(symbol, pos); | 813 return factory->NewStringLiteral(symbol, pos); |
| 799 } | 814 } |
| 800 | 815 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 878 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
| 864 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules); | 879 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules); |
| 865 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); | 880 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); |
| 866 set_allow_harmony_classes(FLAG_harmony_classes); | 881 set_allow_harmony_classes(FLAG_harmony_classes); |
| 867 set_allow_harmony_object_literals(FLAG_harmony_object_literals); | 882 set_allow_harmony_object_literals(FLAG_harmony_object_literals); |
| 868 set_allow_harmony_sloppy(FLAG_harmony_sloppy); | 883 set_allow_harmony_sloppy(FLAG_harmony_sloppy); |
| 869 set_allow_harmony_unicode(FLAG_harmony_unicode); | 884 set_allow_harmony_unicode(FLAG_harmony_unicode); |
| 870 set_allow_harmony_computed_property_names( | 885 set_allow_harmony_computed_property_names( |
| 871 FLAG_harmony_computed_property_names); | 886 FLAG_harmony_computed_property_names); |
| 872 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters); | 887 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters); |
| 888 set_allow_harmony_new_target(FLAG_harmony_new_target); |
| 873 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls); | 889 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls); |
| 874 set_allow_strong_mode(FLAG_strong_mode); | 890 set_allow_strong_mode(FLAG_strong_mode); |
| 875 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 891 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 876 ++feature) { | 892 ++feature) { |
| 877 use_counts_[feature] = 0; | 893 use_counts_[feature] = 0; |
| 878 } | 894 } |
| 879 if (info->ast_value_factory() == NULL) { | 895 if (info->ast_value_factory() == NULL) { |
| 880 // info takes ownership of AstValueFactory. | 896 // info takes ownership of AstValueFactory. |
| 881 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); | 897 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); |
| 882 info->set_ast_value_factory_owned(); | 898 info->set_ast_value_factory_owned(); |
| (...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1905 } | 1921 } |
| 1906 | 1922 |
| 1907 | 1923 |
| 1908 VariableProxy* Parser::NewUnresolved(const AstRawString* name, | 1924 VariableProxy* Parser::NewUnresolved(const AstRawString* name, |
| 1909 VariableMode mode) { | 1925 VariableMode mode) { |
| 1910 // If we are inside a function, a declaration of a var/const variable is a | 1926 // If we are inside a function, a declaration of a var/const variable is a |
| 1911 // truly local variable, and the scope of the variable is always the function | 1927 // truly local variable, and the scope of the variable is always the function |
| 1912 // scope. | 1928 // scope. |
| 1913 // Let/const variables in harmony mode are always added to the immediately | 1929 // Let/const variables in harmony mode are always added to the immediately |
| 1914 // enclosing scope. | 1930 // enclosing scope. |
| 1915 return DeclarationScope(mode)->NewUnresolved(factory(), name, | 1931 return DeclarationScope(mode)->NewUnresolved( |
| 1916 scanner()->location().beg_pos, | 1932 factory(), name, Variable::NORMAL, scanner()->location().beg_pos, |
| 1917 scanner()->location().end_pos); | 1933 scanner()->location().end_pos); |
| 1918 } | 1934 } |
| 1919 | 1935 |
| 1920 | 1936 |
| 1921 Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { | 1937 Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { |
| 1922 VariableProxy* proxy = declaration->proxy(); | 1938 VariableProxy* proxy = declaration->proxy(); |
| 1923 DCHECK(proxy->raw_name() != NULL); | 1939 DCHECK(proxy->raw_name() != NULL); |
| 1924 const AstRawString* name = proxy->raw_name(); | 1940 const AstRawString* name = proxy->raw_name(); |
| 1925 VariableMode mode = declaration->mode(); | 1941 VariableMode mode = declaration->mode(); |
| 1926 Scope* declaration_scope = DeclarationScope(mode); | 1942 Scope* declaration_scope = DeclarationScope(mode); |
| 1927 Variable* var = NULL; | 1943 Variable* var = NULL; |
| (...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3447 *ok = false; | 3463 *ok = false; |
| 3448 return nullptr; | 3464 return nullptr; |
| 3449 } | 3465 } |
| 3450 ForEachStatement* loop = | 3466 ForEachStatement* loop = |
| 3451 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3467 factory()->NewForEachStatement(mode, labels, stmt_pos); |
| 3452 Target target(&this->target_stack_, loop); | 3468 Target target(&this->target_stack_, loop); |
| 3453 | 3469 |
| 3454 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3470 Expression* enumerable = ParseExpression(true, CHECK_OK); |
| 3455 Expect(Token::RPAREN, CHECK_OK); | 3471 Expect(Token::RPAREN, CHECK_OK); |
| 3456 | 3472 |
| 3457 VariableProxy* each = | 3473 VariableProxy* each = scope_->NewUnresolved( |
| 3458 scope_->NewUnresolved(factory(), name, each_beg_pos, each_end_pos); | 3474 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); |
| 3459 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3475 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
| 3460 InitializeForEachStatement(loop, each, enumerable, body); | 3476 InitializeForEachStatement(loop, each, enumerable, body); |
| 3461 Block* result = | 3477 Block* result = |
| 3462 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); | 3478 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); |
| 3463 result->AddStatement(variable_statement, zone()); | 3479 result->AddStatement(variable_statement, zone()); |
| 3464 result->AddStatement(loop, zone()); | 3480 result->AddStatement(loop, zone()); |
| 3465 scope_ = saved_scope; | 3481 scope_ = saved_scope; |
| 3466 for_scope->set_end_position(scanner()->location().end_pos); | 3482 for_scope->set_end_position(scanner()->location().end_pos); |
| 3467 for_scope = for_scope->FinalizeBlockScope(); | 3483 for_scope = for_scope->FinalizeBlockScope(); |
| 3468 DCHECK(for_scope == NULL); | 3484 DCHECK(for_scope == NULL); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3529 ForEachStatement* loop = | 3545 ForEachStatement* loop = |
| 3530 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3546 factory()->NewForEachStatement(mode, labels, stmt_pos); |
| 3531 Target target(&this->target_stack_, loop); | 3547 Target target(&this->target_stack_, loop); |
| 3532 | 3548 |
| 3533 // The expression does not see the loop variable. | 3549 // The expression does not see the loop variable. |
| 3534 scope_ = saved_scope; | 3550 scope_ = saved_scope; |
| 3535 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3551 Expression* enumerable = ParseExpression(true, CHECK_OK); |
| 3536 scope_ = for_scope; | 3552 scope_ = for_scope; |
| 3537 Expect(Token::RPAREN, CHECK_OK); | 3553 Expect(Token::RPAREN, CHECK_OK); |
| 3538 | 3554 |
| 3539 VariableProxy* each = | 3555 VariableProxy* each = scope_->NewUnresolved( |
| 3540 scope_->NewUnresolved(factory(), name, each_beg_pos, each_end_pos); | 3556 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); |
| 3541 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3557 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
| 3542 Block* body_block = | 3558 Block* body_block = |
| 3543 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 3559 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
| 3544 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; | 3560 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; |
| 3545 Assignment* assignment = factory()->NewAssignment( | 3561 Assignment* assignment = factory()->NewAssignment( |
| 3546 init_op, each, temp_proxy, RelocInfo::kNoPosition); | 3562 init_op, each, temp_proxy, RelocInfo::kNoPosition); |
| 3547 Statement* assignment_statement = factory()->NewExpressionStatement( | 3563 Statement* assignment_statement = factory()->NewExpressionStatement( |
| 3548 assignment, RelocInfo::kNoPosition); | 3564 assignment, RelocInfo::kNoPosition); |
| 3549 body_block->AddStatement(variable_statement, zone()); | 3565 body_block->AddStatement(variable_statement, zone()); |
| 3550 body_block->AddStatement(assignment_statement, zone()); | 3566 body_block->AddStatement(assignment_statement, zone()); |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4115 if (!*ok) { | 4131 if (!*ok) { |
| 4116 return; | 4132 return; |
| 4117 } | 4133 } |
| 4118 total_preparse_skipped_ += scope_->end_position() - function_block_pos; | 4134 total_preparse_skipped_ += scope_->end_position() - function_block_pos; |
| 4119 *materialized_literal_count = logger.literals(); | 4135 *materialized_literal_count = logger.literals(); |
| 4120 *expected_property_count = logger.properties(); | 4136 *expected_property_count = logger.properties(); |
| 4121 scope_->SetLanguageMode(logger.language_mode()); | 4137 scope_->SetLanguageMode(logger.language_mode()); |
| 4122 if (logger.scope_uses_super_property()) { | 4138 if (logger.scope_uses_super_property()) { |
| 4123 scope_->RecordSuperPropertyUsage(); | 4139 scope_->RecordSuperPropertyUsage(); |
| 4124 } | 4140 } |
| 4141 if (logger.scope_uses_new_target()) { |
| 4142 fprintf(stderr, "SkipLazyFunctionBody uses new target\n"); |
| 4143 scope_->RecordNewTargetUsage(); |
| 4144 } |
| 4125 if (produce_cached_parse_data()) { | 4145 if (produce_cached_parse_data()) { |
| 4126 DCHECK(log_); | 4146 DCHECK(log_); |
| 4127 // Position right after terminal '}'. | 4147 // Position right after terminal '}'. |
| 4128 int body_end = scanner()->location().end_pos; | 4148 int body_end = scanner()->location().end_pos; |
| 4129 log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, | 4149 log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, |
| 4130 *expected_property_count, scope_->language_mode(), | 4150 *expected_property_count, scope_->language_mode(), |
| 4131 scope_->uses_super_property()); | 4151 scope_->uses_super_property(), scope_->uses_new_target()); |
| 4132 } | 4152 } |
| 4133 } | 4153 } |
| 4134 | 4154 |
| 4135 | 4155 |
| 4136 void Parser::AddAssertIsConstruct(ZoneList<Statement*>* body, int pos) { | 4156 void Parser::AddAssertIsConstruct(ZoneList<Statement*>* body, int pos) { |
| 4137 ZoneList<Expression*>* arguments = | 4157 ZoneList<Expression*>* arguments = |
| 4138 new (zone()) ZoneList<Expression*>(0, zone()); | 4158 new (zone()) ZoneList<Expression*>(0, zone()); |
| 4139 CallRuntime* construct_check = factory()->NewCallRuntime( | 4159 CallRuntime* construct_check = factory()->NewCallRuntime( |
| 4140 ast_value_factory()->is_construct_call_string(), | 4160 ast_value_factory()->is_construct_call_string(), |
| 4141 Runtime::FunctionForId(Runtime::kInlineIsConstructCall), arguments, pos); | 4161 Runtime::FunctionForId(Runtime::kInlineIsConstructCall), arguments, pos); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4243 allow_harmony_arrow_functions()); | 4263 allow_harmony_arrow_functions()); |
| 4244 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes()); | 4264 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes()); |
| 4245 reusable_preparser_->set_allow_harmony_object_literals( | 4265 reusable_preparser_->set_allow_harmony_object_literals( |
| 4246 allow_harmony_object_literals()); | 4266 allow_harmony_object_literals()); |
| 4247 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy()); | 4267 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy()); |
| 4248 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode()); | 4268 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode()); |
| 4249 reusable_preparser_->set_allow_harmony_computed_property_names( | 4269 reusable_preparser_->set_allow_harmony_computed_property_names( |
| 4250 allow_harmony_computed_property_names()); | 4270 allow_harmony_computed_property_names()); |
| 4251 reusable_preparser_->set_allow_harmony_rest_params( | 4271 reusable_preparser_->set_allow_harmony_rest_params( |
| 4252 allow_harmony_rest_params()); | 4272 allow_harmony_rest_params()); |
| 4273 reusable_preparser_->set_allow_harmony_new_target( |
| 4274 allow_harmony_new_target()); |
| 4253 reusable_preparser_->set_allow_harmony_spreadcalls( | 4275 reusable_preparser_->set_allow_harmony_spreadcalls( |
| 4254 allow_harmony_spreadcalls()); | 4276 allow_harmony_spreadcalls()); |
| 4255 reusable_preparser_->set_allow_strong_mode(allow_strong_mode()); | 4277 reusable_preparser_->set_allow_strong_mode(allow_strong_mode()); |
| 4256 } | 4278 } |
| 4257 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 4279 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( |
| 4258 language_mode(), function_state_->kind(), logger); | 4280 language_mode(), function_state_->kind(), logger); |
| 4259 if (pre_parse_timer_ != NULL) { | 4281 if (pre_parse_timer_ != NULL) { |
| 4260 pre_parse_timer_->Stop(); | 4282 pre_parse_timer_->Stop(); |
| 4261 } | 4283 } |
| 4262 return result; | 4284 return result; |
| (...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5747 | 5769 |
| 5748 Expression* Parser::SpreadCallNew(Expression* function, | 5770 Expression* Parser::SpreadCallNew(Expression* function, |
| 5749 ZoneList<v8::internal::Expression*>* args, | 5771 ZoneList<v8::internal::Expression*>* args, |
| 5750 int pos) { | 5772 int pos) { |
| 5751 args->InsertAt(0, function, zone()); | 5773 args->InsertAt(0, function, zone()); |
| 5752 | 5774 |
| 5753 return factory()->NewCallRuntime( | 5775 return factory()->NewCallRuntime( |
| 5754 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5776 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
| 5755 } | 5777 } |
| 5756 } } // namespace v8::internal | 5778 } } // namespace v8::internal |
| OLD | NEW |