Chromium Code Reviews| 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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
| 10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
| (...skipping 2272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2283 } | 2283 } |
| 2284 | 2284 |
| 2285 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { | 2285 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { |
| 2286 // The harmony mode uses block elements instead of statements. | 2286 // The harmony mode uses block elements instead of statements. |
| 2287 // | 2287 // |
| 2288 // Block :: | 2288 // Block :: |
| 2289 // '{' StatementList '}' | 2289 // '{' StatementList '}' |
| 2290 | 2290 |
| 2291 // Construct block expecting 16 statements. | 2291 // Construct block expecting 16 statements. |
| 2292 Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition); | 2292 Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition); |
| 2293 Scope* block_scope = NewScope(BLOCK_SCOPE); | |
| 2294 | 2293 |
| 2295 // Parse the statements and collect escaping labels. | 2294 // Parse the statements and collect escaping labels. |
| 2296 Expect(Token::LBRACE, CHECK_OK); | 2295 Expect(Token::LBRACE, CHECK_OK); |
| 2297 block_scope->set_start_position(scanner()->location().beg_pos); | |
| 2298 { | 2296 { |
| 2299 BlockState block_state(&scope_state_, block_scope); | 2297 BlockState block_state(&scope_state_); |
| 2298 block_state.set_start_position(scanner()->location().beg_pos); | |
| 2300 Target target(&this->target_stack_, body); | 2299 Target target(&this->target_stack_, body); |
| 2301 | 2300 |
| 2302 while (peek() != Token::RBRACE) { | 2301 while (peek() != Token::RBRACE) { |
| 2303 Statement* stat = ParseStatementListItem(CHECK_OK); | 2302 Statement* stat = ParseStatementListItem(CHECK_OK); |
| 2304 if (stat && !stat->IsEmpty()) { | 2303 if (stat && !stat->IsEmpty()) { |
| 2305 body->statements()->Add(stat, zone()); | 2304 body->statements()->Add(stat, zone()); |
| 2306 } | 2305 } |
| 2307 } | 2306 } |
| 2307 | |
| 2308 Expect(Token::RBRACE, CHECK_OK); | |
| 2309 block_state.set_end_position(scanner()->location().end_pos); | |
| 2310 body->set_scope(block_state.FinalizedBlockScope()); | |
|
adamk
2016/07/21 17:48:05
Calling FinalizeBlockScope while still inside the
marja
2016/07/22 07:17:00
(I like this version because it has the set_scope
| |
| 2308 } | 2311 } |
| 2309 Expect(Token::RBRACE, CHECK_OK); | |
| 2310 block_scope->set_end_position(scanner()->location().end_pos); | |
| 2311 block_scope = block_scope->FinalizeBlockScope(); | |
| 2312 body->set_scope(block_scope); | |
| 2313 return body; | 2312 return body; |
| 2314 } | 2313 } |
| 2315 | 2314 |
| 2316 | 2315 |
| 2317 Block* Parser::DeclarationParsingResult::BuildInitializationBlock( | 2316 Block* Parser::DeclarationParsingResult::BuildInitializationBlock( |
| 2318 ZoneList<const AstRawString*>* names, bool* ok) { | 2317 ZoneList<const AstRawString*>* names, bool* ok) { |
| 2319 Block* result = descriptor.parser->factory()->NewBlock( | 2318 Block* result = descriptor.parser->factory()->NewBlock( |
| 2320 NULL, 1, true, descriptor.declaration_pos); | 2319 NULL, 1, true, descriptor.declaration_pos); |
| 2321 for (auto declaration : declarations) { | 2320 for (auto declaration : declarations) { |
| 2322 PatternRewriter::DeclareAndInitializeVariables( | 2321 PatternRewriter::DeclareAndInitializeVariables( |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2900 | 2899 |
| 2901 // make statement: undefined; | 2900 // make statement: undefined; |
| 2902 // This is needed so the tag isn't returned as the value, in case the switch | 2901 // This is needed so the tag isn't returned as the value, in case the switch |
| 2903 // statements don't have a value. | 2902 // statements don't have a value. |
| 2904 switch_block->statements()->Add( | 2903 switch_block->statements()->Add( |
| 2905 factory()->NewExpressionStatement( | 2904 factory()->NewExpressionStatement( |
| 2906 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition), | 2905 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition), |
| 2907 zone()); | 2906 zone()); |
| 2908 | 2907 |
| 2909 Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); | 2908 Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); |
| 2910 Scope* cases_scope = NewScope(BLOCK_SCOPE); | |
| 2911 cases_scope->SetNonlinear(); | |
| 2912 | 2909 |
| 2913 SwitchStatement* switch_statement = | 2910 SwitchStatement* switch_statement = |
| 2914 factory()->NewSwitchStatement(labels, switch_pos); | 2911 factory()->NewSwitchStatement(labels, switch_pos); |
| 2915 | 2912 |
| 2916 cases_scope->set_start_position(scanner()->location().beg_pos); | |
| 2917 { | 2913 { |
| 2918 BlockState cases_block_state(&scope_state_, cases_scope); | 2914 BlockState cases_block_state(&scope_state_); |
| 2915 cases_block_state.set_start_position(scanner()->location().beg_pos); | |
| 2916 cases_block_state.SetNonlinear(); | |
| 2919 Target target(&this->target_stack_, switch_statement); | 2917 Target target(&this->target_stack_, switch_statement); |
| 2920 | 2918 |
| 2921 Expression* tag_read = factory()->NewVariableProxy(tag_variable); | 2919 Expression* tag_read = factory()->NewVariableProxy(tag_variable); |
| 2922 | 2920 |
| 2923 bool default_seen = false; | 2921 bool default_seen = false; |
| 2924 ZoneList<CaseClause*>* cases = | 2922 ZoneList<CaseClause*>* cases = |
| 2925 new (zone()) ZoneList<CaseClause*>(4, zone()); | 2923 new (zone()) ZoneList<CaseClause*>(4, zone()); |
| 2926 Expect(Token::LBRACE, CHECK_OK); | 2924 Expect(Token::LBRACE, CHECK_OK); |
| 2927 while (peek() != Token::RBRACE) { | 2925 while (peek() != Token::RBRACE) { |
| 2928 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK); | 2926 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK); |
| 2929 cases->Add(clause, zone()); | 2927 cases->Add(clause, zone()); |
| 2930 } | 2928 } |
| 2931 switch_statement->Initialize(tag_read, cases); | 2929 switch_statement->Initialize(tag_read, cases); |
| 2932 cases_block->statements()->Add(switch_statement, zone()); | 2930 cases_block->statements()->Add(switch_statement, zone()); |
| 2931 Expect(Token::RBRACE, CHECK_OK); | |
| 2932 | |
| 2933 cases_block_state.set_end_position(scanner()->location().end_pos); | |
| 2934 cases_block->set_scope(cases_block_state.FinalizedBlockScope()); | |
| 2933 } | 2935 } |
| 2934 Expect(Token::RBRACE, CHECK_OK); | |
| 2935 | |
| 2936 cases_scope->set_end_position(scanner()->location().end_pos); | |
| 2937 cases_scope = cases_scope->FinalizeBlockScope(); | |
| 2938 cases_block->set_scope(cases_scope); | |
| 2939 | 2936 |
| 2940 switch_block->statements()->Add(cases_block, zone()); | 2937 switch_block->statements()->Add(cases_block, zone()); |
| 2941 | 2938 |
| 2942 return switch_block; | 2939 return switch_block; |
| 2943 } | 2940 } |
| 2944 | 2941 |
| 2945 | 2942 |
| 2946 Statement* Parser::ParseThrowStatement(bool* ok) { | 2943 Statement* Parser::ParseThrowStatement(bool* ok) { |
| 2947 // ThrowStatement :: | 2944 // ThrowStatement :: |
| 2948 // 'throw' Expression ';' | 2945 // 'throw' Expression ';' |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3005 { | 3002 { |
| 3006 CollectExpressionsInTailPositionToListScope | 3003 CollectExpressionsInTailPositionToListScope |
| 3007 collect_tail_call_expressions_scope( | 3004 collect_tail_call_expressions_scope( |
| 3008 function_state_, &tail_call_expressions_in_catch_block); | 3005 function_state_, &tail_call_expressions_in_catch_block); |
| 3009 BlockState block_state(&scope_state_, catch_scope); | 3006 BlockState block_state(&scope_state_, catch_scope); |
| 3010 | 3007 |
| 3011 catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition); | 3008 catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition); |
| 3012 | 3009 |
| 3013 // Create a block scope to hold any lexical declarations created | 3010 // Create a block scope to hold any lexical declarations created |
| 3014 // as part of destructuring the catch parameter. | 3011 // as part of destructuring the catch parameter. |
| 3015 Scope* block_scope = NewScope(BLOCK_SCOPE); | |
| 3016 block_scope->set_start_position(scanner()->location().beg_pos); | |
| 3017 { | 3012 { |
| 3018 BlockState block_state(&scope_state_, block_scope); | 3013 BlockState block_state(&scope_state_); |
| 3014 block_state.set_start_position(scanner()->location().beg_pos); | |
| 3019 Target target(&this->target_stack_, catch_block); | 3015 Target target(&this->target_stack_, catch_block); |
| 3020 | 3016 |
| 3021 const AstRawString* name = ast_value_factory()->dot_catch_string(); | 3017 const AstRawString* name = ast_value_factory()->dot_catch_string(); |
| 3022 Expression* pattern = nullptr; | 3018 Expression* pattern = nullptr; |
| 3023 if (peek_any_identifier()) { | 3019 if (peek_any_identifier()) { |
| 3024 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); | 3020 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); |
| 3025 } else { | 3021 } else { |
| 3026 ExpressionClassifier pattern_classifier(this); | 3022 ExpressionClassifier pattern_classifier(this); |
| 3027 pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK); | 3023 pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK); |
| 3028 ValidateBindingPattern(&pattern_classifier, CHECK_OK); | 3024 ValidateBindingPattern(&pattern_classifier, CHECK_OK); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3074 Scanner::Location location = | 3070 Scanner::Location location = |
| 3075 position == kNoSourcePosition | 3071 position == kNoSourcePosition |
| 3076 ? Scanner::Location::invalid() | 3072 ? Scanner::Location::invalid() |
| 3077 : Scanner::Location(position, position + 1); | 3073 : Scanner::Location(position, position + 1); |
| 3078 ParserTraits::ReportMessageAt( | 3074 ParserTraits::ReportMessageAt( |
| 3079 location, MessageTemplate::kVarRedeclaration, name); | 3075 location, MessageTemplate::kVarRedeclaration, name); |
| 3080 *ok = false; | 3076 *ok = false; |
| 3081 return nullptr; | 3077 return nullptr; |
| 3082 } | 3078 } |
| 3083 } | 3079 } |
| 3080 block_state.set_end_position(scanner()->location().end_pos); | |
| 3081 catch_block->set_scope(block_state.FinalizedBlockScope()); | |
| 3084 } | 3082 } |
| 3085 block_scope->set_end_position(scanner()->location().end_pos); | |
| 3086 block_scope = block_scope->FinalizeBlockScope(); | |
| 3087 catch_block->set_scope(block_scope); | |
| 3088 } | 3083 } |
| 3089 | 3084 |
| 3090 catch_scope->set_end_position(scanner()->location().end_pos); | 3085 catch_scope->set_end_position(scanner()->location().end_pos); |
| 3091 tok = peek(); | 3086 tok = peek(); |
| 3092 } | 3087 } |
| 3093 | 3088 |
| 3094 Block* finally_block = NULL; | 3089 Block* finally_block = NULL; |
| 3095 DCHECK(tok == Token::FINALLY || catch_block != NULL); | 3090 DCHECK(tok == Token::FINALLY || catch_block != NULL); |
| 3096 if (tok == Token::FINALLY) { | 3091 if (tok == Token::FINALLY) { |
| 3097 Consume(Token::FINALLY); | 3092 Consume(Token::FINALLY); |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3632 bool legacy, bool* ok) { | 3627 bool legacy, bool* ok) { |
| 3633 if (is_strict(language_mode()) || peek() != Token::FUNCTION || | 3628 if (is_strict(language_mode()) || peek() != Token::FUNCTION || |
| 3634 (legacy && allow_harmony_restrictive_declarations())) { | 3629 (legacy && allow_harmony_restrictive_declarations())) { |
| 3635 return ParseSubStatement(labels, kDisallowLabelledFunctionStatement, ok); | 3630 return ParseSubStatement(labels, kDisallowLabelledFunctionStatement, ok); |
| 3636 } else { | 3631 } else { |
| 3637 if (legacy) { | 3632 if (legacy) { |
| 3638 ++use_counts_[v8::Isolate::kLegacyFunctionDeclaration]; | 3633 ++use_counts_[v8::Isolate::kLegacyFunctionDeclaration]; |
| 3639 } | 3634 } |
| 3640 // Make a block around the statement for a lexical binding | 3635 // Make a block around the statement for a lexical binding |
| 3641 // is introduced by a FunctionDeclaration. | 3636 // is introduced by a FunctionDeclaration. |
| 3642 Scope* body_scope = NewScope(BLOCK_SCOPE); | 3637 BlockState block_state(&scope_state_); |
| 3643 body_scope->set_start_position(scanner()->location().beg_pos); | 3638 block_state.set_start_position(scanner()->location().beg_pos); |
| 3644 BlockState block_state(&scope_state_, body_scope); | |
| 3645 Block* block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); | 3639 Block* block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); |
| 3646 Statement* body = ParseFunctionDeclaration(CHECK_OK); | 3640 Statement* body = ParseFunctionDeclaration(CHECK_OK); |
| 3647 block->statements()->Add(body, zone()); | 3641 block->statements()->Add(body, zone()); |
| 3648 body_scope->set_end_position(scanner()->location().end_pos); | 3642 block_state.set_end_position(scanner()->location().end_pos); |
| 3649 body_scope = body_scope->FinalizeBlockScope(); | 3643 block->set_scope(block_state.FinalizedBlockScope()); |
| 3650 block->set_scope(body_scope); | |
| 3651 return block; | 3644 return block; |
| 3652 } | 3645 } |
| 3653 } | 3646 } |
| 3654 | 3647 |
| 3655 Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, | 3648 Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| 3656 bool* ok) { | 3649 bool* ok) { |
| 3657 int stmt_pos = peek_position(); | 3650 int stmt_pos = peek_position(); |
| 3658 Statement* init = NULL; | 3651 Statement* init = NULL; |
| 3659 ZoneList<const AstRawString*> bound_names(1, zone()); | 3652 ZoneList<const AstRawString*> bound_names(1, zone()); |
| 3660 bool bound_names_are_lexical = false; | 3653 bool bound_names_are_lexical = false; |
| 3661 | 3654 |
| 3662 // Create an in-between scope for let-bound iteration variables. | 3655 // Create an in-between scope for let-bound iteration variables. |
| 3663 Scope* for_scope = NewScope(BLOCK_SCOPE); | 3656 BlockState for_state(&scope_state_); |
| 3664 | |
| 3665 BlockState block_state(&scope_state_, for_scope); | |
| 3666 Expect(Token::FOR, CHECK_OK); | 3657 Expect(Token::FOR, CHECK_OK); |
| 3667 Expect(Token::LPAREN, CHECK_OK); | 3658 Expect(Token::LPAREN, CHECK_OK); |
| 3668 for_scope->set_start_position(scanner()->location().beg_pos); | 3659 for_state.set_start_position(scanner()->location().beg_pos); |
| 3669 for_scope->set_is_hidden(); | 3660 for_state.set_is_hidden(); |
| 3670 DeclarationParsingResult parsing_result; | 3661 DeclarationParsingResult parsing_result; |
| 3671 if (peek() != Token::SEMICOLON) { | 3662 if (peek() != Token::SEMICOLON) { |
| 3672 if (peek() == Token::VAR || peek() == Token::CONST || | 3663 if (peek() == Token::VAR || peek() == Token::CONST || |
| 3673 (peek() == Token::LET && IsNextLetKeyword())) { | 3664 (peek() == Token::LET && IsNextLetKeyword())) { |
| 3674 ParseVariableDeclarations(kForStatement, &parsing_result, nullptr, | 3665 ParseVariableDeclarations(kForStatement, &parsing_result, nullptr, |
| 3675 CHECK_OK); | 3666 CHECK_OK); |
| 3676 | 3667 |
| 3677 ForEachStatement::VisitMode mode = ForEachStatement::ENUMERATE; | 3668 ForEachStatement::VisitMode mode = ForEachStatement::ENUMERATE; |
| 3678 int each_beg_pos = scanner()->location().beg_pos; | 3669 int each_beg_pos = scanner()->location().beg_pos; |
| 3679 int each_end_pos = scanner()->location().end_pos; | 3670 int each_end_pos = scanner()->location().end_pos; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3758 if (mode == ForEachStatement::ITERATE) { | 3749 if (mode == ForEachStatement::ITERATE) { |
| 3759 ExpressionClassifier classifier(this); | 3750 ExpressionClassifier classifier(this); |
| 3760 enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK); | 3751 enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK); |
| 3761 RewriteNonPattern(&classifier, CHECK_OK); | 3752 RewriteNonPattern(&classifier, CHECK_OK); |
| 3762 } else { | 3753 } else { |
| 3763 enumerable = ParseExpression(true, CHECK_OK); | 3754 enumerable = ParseExpression(true, CHECK_OK); |
| 3764 } | 3755 } |
| 3765 | 3756 |
| 3766 Expect(Token::RPAREN, CHECK_OK); | 3757 Expect(Token::RPAREN, CHECK_OK); |
| 3767 | 3758 |
| 3768 Scope* body_scope = NewScope(BLOCK_SCOPE); | |
| 3769 body_scope->set_start_position(scanner()->location().beg_pos); | |
| 3770 | 3759 |
| 3771 Block* body_block = | 3760 Block* body_block = |
| 3772 factory()->NewBlock(NULL, 3, false, kNoSourcePosition); | 3761 factory()->NewBlock(NULL, 3, false, kNoSourcePosition); |
| 3773 | 3762 |
| 3774 Statement* final_loop; | 3763 Statement* final_loop; |
| 3775 { | 3764 { |
| 3776 ReturnExprScope no_tail_calls(function_state_, | 3765 ReturnExprScope no_tail_calls(function_state_, |
| 3777 ReturnExprContext::kInsideForInOfBody); | 3766 ReturnExprContext::kInsideForInOfBody); |
| 3778 BlockState block_state(&scope_state_, body_scope); | 3767 BlockState block_state(&scope_state_); |
| 3768 block_state.set_start_position(scanner()->location().beg_pos); | |
| 3779 | 3769 |
| 3780 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); | 3770 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); |
| 3781 | 3771 |
| 3782 auto each_initialization_block = | 3772 auto each_initialization_block = |
| 3783 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 3773 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
| 3784 { | 3774 { |
| 3785 auto descriptor = parsing_result.descriptor; | 3775 auto descriptor = parsing_result.descriptor; |
| 3786 descriptor.declaration_pos = kNoSourcePosition; | 3776 descriptor.declaration_pos = kNoSourcePosition; |
| 3787 descriptor.initialization_pos = kNoSourcePosition; | 3777 descriptor.initialization_pos = kNoSourcePosition; |
| 3788 decl.initializer = factory()->NewVariableProxy(temp); | 3778 decl.initializer = factory()->NewVariableProxy(temp); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3826 } | 3816 } |
| 3827 } | 3817 } |
| 3828 } | 3818 } |
| 3829 | 3819 |
| 3830 body_block->statements()->Add(each_initialization_block, zone()); | 3820 body_block->statements()->Add(each_initialization_block, zone()); |
| 3831 body_block->statements()->Add(body, zone()); | 3821 body_block->statements()->Add(body, zone()); |
| 3832 VariableProxy* temp_proxy = | 3822 VariableProxy* temp_proxy = |
| 3833 factory()->NewVariableProxy(temp, each_beg_pos, each_end_pos); | 3823 factory()->NewVariableProxy(temp, each_beg_pos, each_end_pos); |
| 3834 final_loop = InitializeForEachStatement( | 3824 final_loop = InitializeForEachStatement( |
| 3835 loop, temp_proxy, enumerable, body_block, each_keyword_position); | 3825 loop, temp_proxy, enumerable, body_block, each_keyword_position); |
| 3826 block_state.set_end_position(scanner()->location().end_pos); | |
| 3827 body_block->set_scope(block_state.FinalizedBlockScope()); | |
| 3836 } | 3828 } |
| 3837 body_scope->set_end_position(scanner()->location().end_pos); | |
| 3838 body_scope = body_scope->FinalizeBlockScope(); | |
| 3839 body_block->set_scope(body_scope); | |
| 3840 | 3829 |
| 3841 // Create a TDZ for any lexically-bound names. | 3830 // Create a TDZ for any lexically-bound names. |
| 3842 if (bound_names_are_lexical) { | 3831 if (bound_names_are_lexical) { |
| 3843 DCHECK_NULL(init_block); | 3832 DCHECK_NULL(init_block); |
| 3844 | 3833 |
| 3845 init_block = | 3834 init_block = |
| 3846 factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); | 3835 factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); |
| 3847 | 3836 |
| 3848 for (int i = 0; i < bound_names.length(); ++i) { | 3837 for (int i = 0; i < bound_names.length(); ++i) { |
| 3849 // TODO(adamk): This needs to be some sort of special | 3838 // TODO(adamk): This needs to be some sort of special |
| 3850 // INTERNAL variable that's invisible to the debugger | 3839 // INTERNAL variable that's invisible to the debugger |
| 3851 // but visible to everything else. | 3840 // but visible to everything else. |
| 3852 VariableProxy* tdz_proxy = NewUnresolved(bound_names[i], LET); | 3841 VariableProxy* tdz_proxy = NewUnresolved(bound_names[i], LET); |
| 3853 Declaration* tdz_decl = factory()->NewVariableDeclaration( | 3842 Declaration* tdz_decl = factory()->NewVariableDeclaration( |
| 3854 tdz_proxy, LET, scope(), kNoSourcePosition); | 3843 tdz_proxy, LET, scope(), kNoSourcePosition); |
| 3855 Variable* tdz_var = Declare( | 3844 Variable* tdz_var = Declare( |
| 3856 tdz_decl, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 3845 tdz_decl, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
| 3857 tdz_var->set_initializer_position(position()); | 3846 tdz_var->set_initializer_position(position()); |
| 3858 } | 3847 } |
| 3859 } | 3848 } |
| 3860 | 3849 |
| 3861 for_scope->set_end_position(scanner()->location().end_pos); | 3850 for_state.set_end_position(scanner()->location().end_pos); |
| 3862 for_scope = for_scope->FinalizeBlockScope(); | 3851 Scope* for_scope = for_state.FinalizedBlockScope(); |
| 3863 // Parsed for-in loop w/ variable declarations. | 3852 // Parsed for-in loop w/ variable declarations. |
| 3864 if (init_block != nullptr) { | 3853 if (init_block != nullptr) { |
| 3865 init_block->statements()->Add(final_loop, zone()); | 3854 init_block->statements()->Add(final_loop, zone()); |
| 3866 init_block->set_scope(for_scope); | 3855 init_block->set_scope(for_scope); |
| 3867 return init_block; | 3856 return init_block; |
| 3868 } else { | 3857 } else { |
| 3869 DCHECK_NULL(for_scope); | 3858 DCHECK_NULL(for_scope); |
| 3870 return final_loop; | 3859 return final_loop; |
| 3871 } | 3860 } |
| 3872 } else { | 3861 } else { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3915 } | 3904 } |
| 3916 | 3905 |
| 3917 Expect(Token::RPAREN, CHECK_OK); | 3906 Expect(Token::RPAREN, CHECK_OK); |
| 3918 | 3907 |
| 3919 // For legacy compat reasons, give for loops similar treatment to | 3908 // For legacy compat reasons, give for loops similar treatment to |
| 3920 // if statements in allowing a function declaration for a body | 3909 // if statements in allowing a function declaration for a body |
| 3921 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); | 3910 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); |
| 3922 Statement* final_loop = InitializeForEachStatement( | 3911 Statement* final_loop = InitializeForEachStatement( |
| 3923 loop, expression, enumerable, body, each_keyword_position); | 3912 loop, expression, enumerable, body, each_keyword_position); |
| 3924 | 3913 |
| 3925 for_scope->set_end_position(scanner()->location().end_pos); | 3914 DCHECK_NULL(for_state.FinalizedBlockScope()); |
| 3926 for_scope = for_scope->FinalizeBlockScope(); | |
| 3927 DCHECK(for_scope == nullptr); | |
| 3928 return final_loop; | 3915 return final_loop; |
| 3929 | 3916 |
| 3930 } else { | 3917 } else { |
| 3931 init = factory()->NewExpressionStatement(expression, lhs_beg_pos); | 3918 init = factory()->NewExpressionStatement(expression, lhs_beg_pos); |
| 3932 } | 3919 } |
| 3933 } | 3920 } |
| 3934 } | 3921 } |
| 3935 | 3922 |
| 3936 // Standard 'for' loop | 3923 // Standard 'for' loop |
| 3937 ForStatement* loop = factory()->NewForStatement(labels, stmt_pos); | 3924 ForStatement* loop = factory()->NewForStatement(labels, stmt_pos); |
| 3938 Target target(&this->target_stack_, loop); | 3925 Target target(&this->target_stack_, loop); |
| 3939 | 3926 |
| 3940 // Parsed initializer at this point. | 3927 // Parsed initializer at this point. |
| 3941 Expect(Token::SEMICOLON, CHECK_OK); | 3928 Expect(Token::SEMICOLON, CHECK_OK); |
| 3942 | 3929 |
| 3943 Expression* cond = NULL; | 3930 Expression* cond = NULL; |
| 3944 Statement* next = NULL; | 3931 Statement* next = NULL; |
| 3945 Statement* body = NULL; | 3932 Statement* body = NULL; |
| 3946 | 3933 |
| 3947 // If there are let bindings, then condition and the next statement of the | 3934 // If there are let bindings, then condition and the next statement of the |
| 3948 // for loop must be parsed in a new scope. | 3935 // for loop must be parsed in a new scope. |
| 3949 Scope* inner_scope = scope(); | 3936 Scope* inner_scope = scope(); |
| 3937 // TODO(verwaest): Allocate this through a ScopeState as well. | |
| 3950 if (bound_names_are_lexical && bound_names.length() > 0) { | 3938 if (bound_names_are_lexical && bound_names.length() > 0) { |
| 3951 inner_scope = NewScopeWithParent(for_scope, BLOCK_SCOPE); | 3939 inner_scope = NewScopeWithParent(inner_scope, BLOCK_SCOPE); |
| 3952 inner_scope->set_start_position(scanner()->location().beg_pos); | 3940 inner_scope->set_start_position(scanner()->location().beg_pos); |
| 3953 } | 3941 } |
| 3954 { | 3942 { |
| 3955 BlockState block_state(&scope_state_, inner_scope); | 3943 BlockState block_state(&scope_state_, inner_scope); |
| 3956 | 3944 |
| 3957 if (peek() != Token::SEMICOLON) { | 3945 if (peek() != Token::SEMICOLON) { |
| 3958 cond = ParseExpression(true, CHECK_OK); | 3946 cond = ParseExpression(true, CHECK_OK); |
| 3959 } | 3947 } |
| 3960 Expect(Token::SEMICOLON, CHECK_OK); | 3948 Expect(Token::SEMICOLON, CHECK_OK); |
| 3961 | 3949 |
| 3962 if (peek() != Token::RPAREN) { | 3950 if (peek() != Token::RPAREN) { |
| 3963 Expression* exp = ParseExpression(true, CHECK_OK); | 3951 Expression* exp = ParseExpression(true, CHECK_OK); |
| 3964 next = factory()->NewExpressionStatement(exp, exp->position()); | 3952 next = factory()->NewExpressionStatement(exp, exp->position()); |
| 3965 } | 3953 } |
| 3966 Expect(Token::RPAREN, CHECK_OK); | 3954 Expect(Token::RPAREN, CHECK_OK); |
| 3967 | 3955 |
| 3968 body = ParseScopedStatement(NULL, true, CHECK_OK); | 3956 body = ParseScopedStatement(NULL, true, CHECK_OK); |
| 3969 } | 3957 } |
| 3970 | 3958 |
| 3971 Statement* result = NULL; | 3959 Statement* result = NULL; |
| 3972 if (bound_names_are_lexical && bound_names.length() > 0) { | 3960 if (bound_names_are_lexical && bound_names.length() > 0) { |
| 3973 BlockState block_state(&scope_state_, for_scope); | |
| 3974 result = DesugarLexicalBindingsInForStatement( | 3961 result = DesugarLexicalBindingsInForStatement( |
| 3975 inner_scope, parsing_result.descriptor.mode, &bound_names, loop, init, | 3962 inner_scope, parsing_result.descriptor.mode, &bound_names, loop, init, |
| 3976 cond, next, body, CHECK_OK); | 3963 cond, next, body, CHECK_OK); |
| 3977 for_scope->set_end_position(scanner()->location().end_pos); | 3964 for_state.set_end_position(scanner()->location().end_pos); |
| 3978 } else { | 3965 } else { |
| 3979 for_scope->set_end_position(scanner()->location().end_pos); | 3966 for_state.set_end_position(scanner()->location().end_pos); |
| 3980 for_scope = for_scope->FinalizeBlockScope(); | 3967 Scope* for_scope = for_state.FinalizedBlockScope(); |
| 3981 if (for_scope) { | 3968 if (for_scope) { |
| 3982 // Rewrite a for statement of the form | 3969 // Rewrite a for statement of the form |
| 3983 // for (const x = i; c; n) b | 3970 // for (const x = i; c; n) b |
| 3984 // | 3971 // |
| 3985 // into | 3972 // into |
| 3986 // | 3973 // |
| 3987 // { | 3974 // { |
| 3988 // const x = i; | 3975 // const x = i; |
| 3989 // for (; c; n) b | 3976 // for (; c; n) b |
| 3990 // } | 3977 // } |
| (...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4988 ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier, | 4975 ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier, |
| 4989 const AstRawString* name, | 4976 const AstRawString* name, |
| 4990 Scanner::Location class_name_location, | 4977 Scanner::Location class_name_location, |
| 4991 bool name_is_strict_reserved, int pos, | 4978 bool name_is_strict_reserved, int pos, |
| 4992 bool* ok) { | 4979 bool* ok) { |
| 4993 // All parts of a ClassDeclaration and ClassExpression are strict code. | 4980 // All parts of a ClassDeclaration and ClassExpression are strict code. |
| 4994 if (name_is_strict_reserved) { | 4981 if (name_is_strict_reserved) { |
| 4995 ReportMessageAt(class_name_location, | 4982 ReportMessageAt(class_name_location, |
| 4996 MessageTemplate::kUnexpectedStrictReserved); | 4983 MessageTemplate::kUnexpectedStrictReserved); |
| 4997 *ok = false; | 4984 *ok = false; |
| 4998 return NULL; | 4985 return nullptr; |
| 4999 } | 4986 } |
| 5000 if (IsEvalOrArguments(name)) { | 4987 if (IsEvalOrArguments(name)) { |
| 5001 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); | 4988 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); |
| 5002 *ok = false; | 4989 *ok = false; |
| 5003 return NULL; | 4990 return nullptr; |
| 5004 } | 4991 } |
| 5005 | 4992 |
| 5006 Scope* block_scope = NewScope(BLOCK_SCOPE); | 4993 BlockState block_state(&scope_state_); |
| 5007 BlockState block_state(&scope_state_, block_scope); | |
| 5008 RaiseLanguageMode(STRICT); | 4994 RaiseLanguageMode(STRICT); |
| 5009 scope()->SetScopeName(name); | 4995 scope()->SetScopeName(name); |
| 5010 | 4996 |
| 5011 VariableProxy* proxy = NULL; | 4997 VariableProxy* proxy = nullptr; |
| 5012 if (name != NULL) { | 4998 if (name != nullptr) { |
| 5013 proxy = NewUnresolved(name, CONST); | 4999 proxy = NewUnresolved(name, CONST); |
| 5014 Declaration* declaration = | 5000 // TODO(verwaest): declare via block_state. |
| 5015 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | 5001 Declaration* declaration = factory()->NewVariableDeclaration( |
| 5002 proxy, CONST, block_state.scope(), pos); | |
| 5016 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 5003 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
| 5017 } | 5004 } |
| 5018 | 5005 |
| 5019 Expression* extends = NULL; | 5006 Expression* extends = nullptr; |
| 5020 if (Check(Token::EXTENDS)) { | 5007 if (Check(Token::EXTENDS)) { |
| 5021 block_scope->set_start_position(scanner()->location().end_pos); | 5008 block_state.set_start_position(scanner()->location().end_pos); |
| 5022 ExpressionClassifier extends_classifier(this); | 5009 ExpressionClassifier extends_classifier(this); |
| 5023 extends = ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); | 5010 extends = ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); |
| 5024 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); | 5011 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); |
| 5025 RewriteNonPattern(&extends_classifier, CHECK_OK); | 5012 RewriteNonPattern(&extends_classifier, CHECK_OK); |
| 5026 if (classifier != nullptr) { | 5013 if (classifier != nullptr) { |
| 5027 classifier->Accumulate(&extends_classifier, | 5014 classifier->Accumulate(&extends_classifier, |
| 5028 ExpressionClassifier::ExpressionProductions); | 5015 ExpressionClassifier::ExpressionProductions); |
| 5029 } | 5016 } |
| 5030 } else { | 5017 } else { |
| 5031 block_scope->set_start_position(scanner()->location().end_pos); | 5018 block_state.set_start_position(scanner()->location().end_pos); |
| 5032 } | 5019 } |
| 5033 | 5020 |
| 5034 | 5021 |
| 5035 ClassLiteralChecker checker(this); | 5022 ClassLiteralChecker checker(this); |
| 5036 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); | 5023 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); |
| 5037 FunctionLiteral* constructor = NULL; | 5024 FunctionLiteral* constructor = nullptr; |
| 5038 bool has_seen_constructor = false; | 5025 bool has_seen_constructor = false; |
| 5039 | 5026 |
| 5040 Expect(Token::LBRACE, CHECK_OK); | 5027 Expect(Token::LBRACE, CHECK_OK); |
| 5041 | 5028 |
| 5042 const bool has_extends = extends != nullptr; | 5029 const bool has_extends = extends != nullptr; |
| 5043 while (peek() != Token::RBRACE) { | 5030 while (peek() != Token::RBRACE) { |
| 5044 if (Check(Token::SEMICOLON)) continue; | 5031 if (Check(Token::SEMICOLON)) continue; |
| 5045 FuncNameInferrer::State fni_state(fni_); | 5032 FuncNameInferrer::State fni_state(fni_); |
| 5046 const bool in_class = true; | 5033 const bool in_class = true; |
| 5047 bool is_computed_name = false; // Classes do not care about computed | 5034 bool is_computed_name = false; // Classes do not care about computed |
| 5048 // property names here. | 5035 // property names here. |
| 5049 ExpressionClassifier property_classifier(this); | 5036 ExpressionClassifier property_classifier(this); |
| 5050 const AstRawString* property_name = nullptr; | 5037 const AstRawString* property_name = nullptr; |
| 5051 ObjectLiteral::Property* property = ParsePropertyDefinition( | 5038 ObjectLiteral::Property* property = ParsePropertyDefinition( |
| 5052 &checker, in_class, has_extends, MethodKind::Normal, &is_computed_name, | 5039 &checker, in_class, has_extends, MethodKind::Normal, &is_computed_name, |
| 5053 &has_seen_constructor, &property_classifier, &property_name, CHECK_OK); | 5040 &has_seen_constructor, &property_classifier, &property_name, CHECK_OK); |
| 5054 RewriteNonPattern(&property_classifier, CHECK_OK); | 5041 RewriteNonPattern(&property_classifier, CHECK_OK); |
| 5055 if (classifier != nullptr) { | 5042 if (classifier != nullptr) { |
| 5056 classifier->Accumulate(&property_classifier, | 5043 classifier->Accumulate(&property_classifier, |
| 5057 ExpressionClassifier::ExpressionProductions); | 5044 ExpressionClassifier::ExpressionProductions); |
| 5058 } | 5045 } |
| 5059 | 5046 |
| 5060 if (has_seen_constructor && constructor == NULL) { | 5047 if (has_seen_constructor && constructor == nullptr) { |
| 5061 constructor = GetPropertyValue(property)->AsFunctionLiteral(); | 5048 constructor = GetPropertyValue(property)->AsFunctionLiteral(); |
| 5062 DCHECK_NOT_NULL(constructor); | 5049 DCHECK_NOT_NULL(constructor); |
| 5063 constructor->set_raw_name( | 5050 constructor->set_raw_name( |
| 5064 name != nullptr ? name : ast_value_factory()->empty_string()); | 5051 name != nullptr ? name : ast_value_factory()->empty_string()); |
| 5065 } else { | 5052 } else { |
| 5066 properties->Add(property, zone()); | 5053 properties->Add(property, zone()); |
| 5067 } | 5054 } |
| 5068 | 5055 |
| 5069 if (fni_ != NULL) fni_->Infer(); | 5056 if (fni_ != nullptr) fni_->Infer(); |
| 5070 | 5057 |
| 5071 if (property_name != ast_value_factory()->constructor_string()) { | 5058 if (property_name != ast_value_factory()->constructor_string()) { |
| 5072 SetFunctionNameFromPropertyName(property, property_name); | 5059 SetFunctionNameFromPropertyName(property, property_name); |
| 5073 } | 5060 } |
| 5074 } | 5061 } |
| 5075 | 5062 |
| 5076 Expect(Token::RBRACE, CHECK_OK); | 5063 Expect(Token::RBRACE, CHECK_OK); |
| 5077 int end_pos = scanner()->location().end_pos; | 5064 int end_pos = scanner()->location().end_pos; |
| 5078 | 5065 |
| 5079 if (constructor == NULL) { | 5066 if (constructor == nullptr) { |
| 5080 DCHECK_EQ(this->scope(), block_scope); | |
| 5081 constructor = DefaultConstructor(name, has_extends, pos, end_pos, | 5067 constructor = DefaultConstructor(name, has_extends, pos, end_pos, |
| 5082 block_scope->language_mode()); | 5068 block_state.language_mode()); |
| 5083 } | 5069 } |
| 5084 | 5070 |
| 5085 // Note that we do not finalize this block scope because it is | 5071 // Note that we do not finalize this block scope because it is |
| 5086 // used as a sentinel value indicating an anonymous class. | 5072 // used as a sentinel value indicating an anonymous class. |
| 5087 block_scope->set_end_position(end_pos); | 5073 block_state.set_end_position(end_pos); |
| 5088 | 5074 |
| 5089 if (name != NULL) { | 5075 if (name != nullptr) { |
| 5090 DCHECK_NOT_NULL(proxy); | 5076 DCHECK_NOT_NULL(proxy); |
| 5091 proxy->var()->set_initializer_position(end_pos); | 5077 proxy->var()->set_initializer_position(end_pos); |
| 5092 } | 5078 } |
| 5093 | 5079 |
| 5080 // TODO(verwaest): Use FinalizedBlockScope() once supported. | |
| 5081 Scope* block_scope = block_state.scope(); | |
| 5094 return factory()->NewClassLiteral(block_scope, proxy, extends, constructor, | 5082 return factory()->NewClassLiteral(block_scope, proxy, extends, constructor, |
| 5095 properties, pos, end_pos); | 5083 properties, pos, end_pos); |
| 5096 } | 5084 } |
| 5097 | 5085 |
| 5098 | 5086 |
| 5099 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 5087 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
| 5100 // CallRuntime :: | 5088 // CallRuntime :: |
| 5101 // '%' Identifier Arguments | 5089 // '%' Identifier Arguments |
| 5102 | 5090 |
| 5103 int pos = peek_position(); | 5091 int pos = peek_position(); |
| (...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7061 node->Print(Isolate::Current()); | 7049 node->Print(Isolate::Current()); |
| 7062 } | 7050 } |
| 7063 #endif // DEBUG | 7051 #endif // DEBUG |
| 7064 | 7052 |
| 7065 #undef CHECK_OK | 7053 #undef CHECK_OK |
| 7066 #undef CHECK_OK_VOID | 7054 #undef CHECK_OK_VOID |
| 7067 #undef CHECK_FAILED | 7055 #undef CHECK_FAILED |
| 7068 | 7056 |
| 7069 } // namespace internal | 7057 } // namespace internal |
| 7070 } // namespace v8 | 7058 } // namespace v8 |
| OLD | NEW |