| 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 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 // string table to internalize strings and values right after they're | 950 // string table to internalize strings and values right after they're |
| 951 // created. This kind of parsing can only be done in the main thread. | 951 // created. This kind of parsing can only be done in the main thread. |
| 952 DCHECK(parsing_on_main_thread_); | 952 DCHECK(parsing_on_main_thread_); |
| 953 ast_value_factory()->Internalize(info->isolate()); | 953 ast_value_factory()->Internalize(info->isolate()); |
| 954 } | 954 } |
| 955 original_scope_ = scope; | 955 original_scope_ = scope; |
| 956 if (info->is_eval()) { | 956 if (info->is_eval()) { |
| 957 if (!scope->is_script_scope() || is_strict(info->language_mode())) { | 957 if (!scope->is_script_scope() || is_strict(info->language_mode())) { |
| 958 parsing_mode = PARSE_EAGERLY; | 958 parsing_mode = PARSE_EAGERLY; |
| 959 } | 959 } |
| 960 scope = NewScope(scope, EVAL_SCOPE); | 960 scope = NewScopeWithParent(scope, EVAL_SCOPE); |
| 961 } else if (info->is_module()) { | 961 } else if (info->is_module()) { |
| 962 scope = NewScope(scope, MODULE_SCOPE); | 962 scope = NewScopeWithParent(scope, MODULE_SCOPE); |
| 963 } | 963 } |
| 964 | 964 |
| 965 scope->set_start_position(0); | 965 scope->set_start_position(0); |
| 966 | 966 |
| 967 // Enter 'scope' with the given parsing mode. | 967 // Enter 'scope' with the given parsing mode. |
| 968 ParsingModeScope parsing_mode_scope(this, parsing_mode); | 968 ParsingModeScope parsing_mode_scope(this, parsing_mode); |
| 969 AstNodeFactory function_factory(ast_value_factory()); | 969 AstNodeFactory function_factory(ast_value_factory()); |
| 970 FunctionState function_state(&function_state_, &scope_state_, scope, | 970 FunctionState function_state(&function_state_, &scope_state_, scope, |
| 971 kNormalFunction, &function_factory); | 971 kNormalFunction, &function_factory); |
| 972 | 972 |
| (...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2287 | 2287 |
| 2288 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, | 2288 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, |
| 2289 bool finalize_block_scope, bool* ok) { | 2289 bool finalize_block_scope, bool* ok) { |
| 2290 // The harmony mode uses block elements instead of statements. | 2290 // The harmony mode uses block elements instead of statements. |
| 2291 // | 2291 // |
| 2292 // Block :: | 2292 // Block :: |
| 2293 // '{' StatementList '}' | 2293 // '{' StatementList '}' |
| 2294 | 2294 |
| 2295 // Construct block expecting 16 statements. | 2295 // Construct block expecting 16 statements. |
| 2296 Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition); | 2296 Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition); |
| 2297 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE); | 2297 Scope* block_scope = NewScope(BLOCK_SCOPE); |
| 2298 | 2298 |
| 2299 // Parse the statements and collect escaping labels. | 2299 // Parse the statements and collect escaping labels. |
| 2300 Expect(Token::LBRACE, CHECK_OK); | 2300 Expect(Token::LBRACE, CHECK_OK); |
| 2301 block_scope->set_start_position(scanner()->location().beg_pos); | 2301 block_scope->set_start_position(scanner()->location().beg_pos); |
| 2302 { | 2302 { |
| 2303 BlockState block_state(&scope_state_, block_scope); | 2303 BlockState block_state(&scope_state_, block_scope); |
| 2304 Target target(&this->target_stack_, body); | 2304 Target target(&this->target_stack_, body); |
| 2305 | 2305 |
| 2306 while (peek() != Token::RBRACE) { | 2306 while (peek() != Token::RBRACE) { |
| 2307 Statement* stat = ParseStatementListItem(CHECK_OK); | 2307 Statement* stat = ParseStatementListItem(CHECK_OK); |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2826 if (is_strict(language_mode())) { | 2826 if (is_strict(language_mode())) { |
| 2827 ReportMessage(MessageTemplate::kStrictWith); | 2827 ReportMessage(MessageTemplate::kStrictWith); |
| 2828 *ok = false; | 2828 *ok = false; |
| 2829 return NULL; | 2829 return NULL; |
| 2830 } | 2830 } |
| 2831 | 2831 |
| 2832 Expect(Token::LPAREN, CHECK_OK); | 2832 Expect(Token::LPAREN, CHECK_OK); |
| 2833 Expression* expr = ParseExpression(true, CHECK_OK); | 2833 Expression* expr = ParseExpression(true, CHECK_OK); |
| 2834 Expect(Token::RPAREN, CHECK_OK); | 2834 Expect(Token::RPAREN, CHECK_OK); |
| 2835 | 2835 |
| 2836 Scope* with_scope = NewScope(scope(), WITH_SCOPE); | 2836 Scope* with_scope = NewScope(WITH_SCOPE); |
| 2837 Statement* body; | 2837 Statement* body; |
| 2838 { | 2838 { |
| 2839 BlockState block_state(&scope_state_, with_scope); | 2839 BlockState block_state(&scope_state_, with_scope); |
| 2840 with_scope->set_start_position(scanner()->peek_location().beg_pos); | 2840 with_scope->set_start_position(scanner()->peek_location().beg_pos); |
| 2841 body = ParseScopedStatement(labels, true, CHECK_OK); | 2841 body = ParseScopedStatement(labels, true, CHECK_OK); |
| 2842 with_scope->set_end_position(scanner()->location().end_pos); | 2842 with_scope->set_end_position(scanner()->location().end_pos); |
| 2843 } | 2843 } |
| 2844 return factory()->NewWithStatement(with_scope, expr, body, pos); | 2844 return factory()->NewWithStatement(with_scope, expr, body, pos); |
| 2845 } | 2845 } |
| 2846 | 2846 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2911 | 2911 |
| 2912 // make statement: undefined; | 2912 // make statement: undefined; |
| 2913 // This is needed so the tag isn't returned as the value, in case the switch | 2913 // This is needed so the tag isn't returned as the value, in case the switch |
| 2914 // statements don't have a value. | 2914 // statements don't have a value. |
| 2915 switch_block->statements()->Add( | 2915 switch_block->statements()->Add( |
| 2916 factory()->NewExpressionStatement( | 2916 factory()->NewExpressionStatement( |
| 2917 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition), | 2917 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition), |
| 2918 zone()); | 2918 zone()); |
| 2919 | 2919 |
| 2920 Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); | 2920 Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); |
| 2921 Scope* cases_scope = NewScope(scope(), BLOCK_SCOPE); | 2921 Scope* cases_scope = NewScope(BLOCK_SCOPE); |
| 2922 cases_scope->SetNonlinear(); | 2922 cases_scope->SetNonlinear(); |
| 2923 | 2923 |
| 2924 SwitchStatement* switch_statement = | 2924 SwitchStatement* switch_statement = |
| 2925 factory()->NewSwitchStatement(labels, switch_pos); | 2925 factory()->NewSwitchStatement(labels, switch_pos); |
| 2926 | 2926 |
| 2927 cases_scope->set_start_position(scanner()->location().beg_pos); | 2927 cases_scope->set_start_position(scanner()->location().beg_pos); |
| 2928 { | 2928 { |
| 2929 BlockState cases_block_state(&scope_state_, cases_scope); | 2929 BlockState cases_block_state(&scope_state_, cases_scope); |
| 2930 Target target(&this->target_stack_, switch_statement); | 2930 Target target(&this->target_stack_, switch_statement); |
| 2931 | 2931 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3003 } | 3003 } |
| 3004 | 3004 |
| 3005 Scope* catch_scope = NULL; | 3005 Scope* catch_scope = NULL; |
| 3006 Variable* catch_variable = NULL; | 3006 Variable* catch_variable = NULL; |
| 3007 Block* catch_block = NULL; | 3007 Block* catch_block = NULL; |
| 3008 TailCallExpressionList tail_call_expressions_in_catch_block(zone()); | 3008 TailCallExpressionList tail_call_expressions_in_catch_block(zone()); |
| 3009 if (tok == Token::CATCH) { | 3009 if (tok == Token::CATCH) { |
| 3010 Consume(Token::CATCH); | 3010 Consume(Token::CATCH); |
| 3011 | 3011 |
| 3012 Expect(Token::LPAREN, CHECK_OK); | 3012 Expect(Token::LPAREN, CHECK_OK); |
| 3013 catch_scope = NewScope(scope(), CATCH_SCOPE); | 3013 catch_scope = NewScope(CATCH_SCOPE); |
| 3014 catch_scope->set_start_position(scanner()->location().beg_pos); | 3014 catch_scope->set_start_position(scanner()->location().beg_pos); |
| 3015 | 3015 |
| 3016 { | 3016 { |
| 3017 CollectExpressionsInTailPositionToListScope | 3017 CollectExpressionsInTailPositionToListScope |
| 3018 collect_tail_call_expressions_scope( | 3018 collect_tail_call_expressions_scope( |
| 3019 function_state_, &tail_call_expressions_in_catch_block); | 3019 function_state_, &tail_call_expressions_in_catch_block); |
| 3020 BlockState block_state(&scope_state_, catch_scope); | 3020 BlockState block_state(&scope_state_, catch_scope); |
| 3021 | 3021 |
| 3022 catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition); | 3022 catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition); |
| 3023 | 3023 |
| 3024 // Create a block scope to hold any lexical declarations created | 3024 // Create a block scope to hold any lexical declarations created |
| 3025 // as part of destructuring the catch parameter. | 3025 // as part of destructuring the catch parameter. |
| 3026 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE); | 3026 Scope* block_scope = NewScope(BLOCK_SCOPE); |
| 3027 block_scope->set_start_position(scanner()->location().beg_pos); | 3027 block_scope->set_start_position(scanner()->location().beg_pos); |
| 3028 { | 3028 { |
| 3029 BlockState block_state(&scope_state_, block_scope); | 3029 BlockState block_state(&scope_state_, block_scope); |
| 3030 Target target(&this->target_stack_, catch_block); | 3030 Target target(&this->target_stack_, catch_block); |
| 3031 | 3031 |
| 3032 const AstRawString* name = ast_value_factory()->dot_catch_string(); | 3032 const AstRawString* name = ast_value_factory()->dot_catch_string(); |
| 3033 Expression* pattern = nullptr; | 3033 Expression* pattern = nullptr; |
| 3034 if (peek_any_identifier()) { | 3034 if (peek_any_identifier()) { |
| 3035 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); | 3035 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); |
| 3036 } else { | 3036 } else { |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3643 bool legacy, bool* ok) { | 3643 bool legacy, bool* ok) { |
| 3644 if (is_strict(language_mode()) || peek() != Token::FUNCTION || | 3644 if (is_strict(language_mode()) || peek() != Token::FUNCTION || |
| 3645 (legacy && allow_harmony_restrictive_declarations())) { | 3645 (legacy && allow_harmony_restrictive_declarations())) { |
| 3646 return ParseSubStatement(labels, kDisallowLabelledFunctionStatement, ok); | 3646 return ParseSubStatement(labels, kDisallowLabelledFunctionStatement, ok); |
| 3647 } else { | 3647 } else { |
| 3648 if (legacy) { | 3648 if (legacy) { |
| 3649 ++use_counts_[v8::Isolate::kLegacyFunctionDeclaration]; | 3649 ++use_counts_[v8::Isolate::kLegacyFunctionDeclaration]; |
| 3650 } | 3650 } |
| 3651 // Make a block around the statement for a lexical binding | 3651 // Make a block around the statement for a lexical binding |
| 3652 // is introduced by a FunctionDeclaration. | 3652 // is introduced by a FunctionDeclaration. |
| 3653 Scope* body_scope = NewScope(scope(), BLOCK_SCOPE); | 3653 Scope* body_scope = NewScope(BLOCK_SCOPE); |
| 3654 body_scope->set_start_position(scanner()->location().beg_pos); | 3654 body_scope->set_start_position(scanner()->location().beg_pos); |
| 3655 BlockState block_state(&scope_state_, body_scope); | 3655 BlockState block_state(&scope_state_, body_scope); |
| 3656 Block* block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); | 3656 Block* block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); |
| 3657 Statement* body = ParseFunctionDeclaration(CHECK_OK); | 3657 Statement* body = ParseFunctionDeclaration(CHECK_OK); |
| 3658 block->statements()->Add(body, zone()); | 3658 block->statements()->Add(body, zone()); |
| 3659 body_scope->set_end_position(scanner()->location().end_pos); | 3659 body_scope->set_end_position(scanner()->location().end_pos); |
| 3660 body_scope = body_scope->FinalizeBlockScope(); | 3660 body_scope = body_scope->FinalizeBlockScope(); |
| 3661 block->set_scope(body_scope); | 3661 block->set_scope(body_scope); |
| 3662 return block; | 3662 return block; |
| 3663 } | 3663 } |
| 3664 } | 3664 } |
| 3665 | 3665 |
| 3666 Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, | 3666 Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| 3667 bool* ok) { | 3667 bool* ok) { |
| 3668 int stmt_pos = peek_position(); | 3668 int stmt_pos = peek_position(); |
| 3669 Statement* init = NULL; | 3669 Statement* init = NULL; |
| 3670 ZoneList<const AstRawString*> bound_names(1, zone()); | 3670 ZoneList<const AstRawString*> bound_names(1, zone()); |
| 3671 bool bound_names_are_lexical = false; | 3671 bool bound_names_are_lexical = false; |
| 3672 | 3672 |
| 3673 // Create an in-between scope for let-bound iteration variables. | 3673 // Create an in-between scope for let-bound iteration variables. |
| 3674 Scope* for_scope = NewScope(scope(), BLOCK_SCOPE); | 3674 Scope* for_scope = NewScope(BLOCK_SCOPE); |
| 3675 | 3675 |
| 3676 BlockState block_state(&scope_state_, for_scope); | 3676 BlockState block_state(&scope_state_, for_scope); |
| 3677 Expect(Token::FOR, CHECK_OK); | 3677 Expect(Token::FOR, CHECK_OK); |
| 3678 Expect(Token::LPAREN, CHECK_OK); | 3678 Expect(Token::LPAREN, CHECK_OK); |
| 3679 for_scope->set_start_position(scanner()->location().beg_pos); | 3679 for_scope->set_start_position(scanner()->location().beg_pos); |
| 3680 for_scope->set_is_hidden(); | 3680 for_scope->set_is_hidden(); |
| 3681 DeclarationParsingResult parsing_result; | 3681 DeclarationParsingResult parsing_result; |
| 3682 if (peek() != Token::SEMICOLON) { | 3682 if (peek() != Token::SEMICOLON) { |
| 3683 if (peek() == Token::VAR || peek() == Token::CONST || | 3683 if (peek() == Token::VAR || peek() == Token::CONST || |
| 3684 (peek() == Token::LET && IsNextLetKeyword())) { | 3684 (peek() == Token::LET && IsNextLetKeyword())) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3769 if (mode == ForEachStatement::ITERATE) { | 3769 if (mode == ForEachStatement::ITERATE) { |
| 3770 ExpressionClassifier classifier(this); | 3770 ExpressionClassifier classifier(this); |
| 3771 enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK); | 3771 enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK); |
| 3772 RewriteNonPattern(&classifier, CHECK_OK); | 3772 RewriteNonPattern(&classifier, CHECK_OK); |
| 3773 } else { | 3773 } else { |
| 3774 enumerable = ParseExpression(true, CHECK_OK); | 3774 enumerable = ParseExpression(true, CHECK_OK); |
| 3775 } | 3775 } |
| 3776 | 3776 |
| 3777 Expect(Token::RPAREN, CHECK_OK); | 3777 Expect(Token::RPAREN, CHECK_OK); |
| 3778 | 3778 |
| 3779 Scope* body_scope = NewScope(scope(), BLOCK_SCOPE); | 3779 Scope* body_scope = NewScope(BLOCK_SCOPE); |
| 3780 body_scope->set_start_position(scanner()->location().beg_pos); | 3780 body_scope->set_start_position(scanner()->location().beg_pos); |
| 3781 | 3781 |
| 3782 Block* body_block = | 3782 Block* body_block = |
| 3783 factory()->NewBlock(NULL, 3, false, kNoSourcePosition); | 3783 factory()->NewBlock(NULL, 3, false, kNoSourcePosition); |
| 3784 | 3784 |
| 3785 Statement* final_loop; | 3785 Statement* final_loop; |
| 3786 { | 3786 { |
| 3787 ReturnExprScope no_tail_calls(function_state_, | 3787 ReturnExprScope no_tail_calls(function_state_, |
| 3788 ReturnExprContext::kInsideForInOfBody); | 3788 ReturnExprContext::kInsideForInOfBody); |
| 3789 BlockState block_state(&scope_state_, body_scope); | 3789 BlockState block_state(&scope_state_, body_scope); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3952 Expect(Token::SEMICOLON, CHECK_OK); | 3952 Expect(Token::SEMICOLON, CHECK_OK); |
| 3953 | 3953 |
| 3954 Expression* cond = NULL; | 3954 Expression* cond = NULL; |
| 3955 Statement* next = NULL; | 3955 Statement* next = NULL; |
| 3956 Statement* body = NULL; | 3956 Statement* body = NULL; |
| 3957 | 3957 |
| 3958 // If there are let bindings, then condition and the next statement of the | 3958 // If there are let bindings, then condition and the next statement of the |
| 3959 // for loop must be parsed in a new scope. | 3959 // for loop must be parsed in a new scope. |
| 3960 Scope* inner_scope = scope(); | 3960 Scope* inner_scope = scope(); |
| 3961 if (bound_names_are_lexical && bound_names.length() > 0) { | 3961 if (bound_names_are_lexical && bound_names.length() > 0) { |
| 3962 inner_scope = NewScope(for_scope, BLOCK_SCOPE); | 3962 inner_scope = NewScopeWithParent(for_scope, BLOCK_SCOPE); |
| 3963 inner_scope->set_start_position(scanner()->location().beg_pos); | 3963 inner_scope->set_start_position(scanner()->location().beg_pos); |
| 3964 } | 3964 } |
| 3965 { | 3965 { |
| 3966 BlockState block_state(&scope_state_, inner_scope); | 3966 BlockState block_state(&scope_state_, inner_scope); |
| 3967 | 3967 |
| 3968 if (peek() != Token::SEMICOLON) { | 3968 if (peek() != Token::SEMICOLON) { |
| 3969 cond = ParseExpression(true, CHECK_OK); | 3969 cond = ParseExpression(true, CHECK_OK); |
| 3970 } | 3970 } |
| 3971 Expect(Token::SEMICOLON, CHECK_OK); | 3971 Expect(Token::SEMICOLON, CHECK_OK); |
| 3972 | 3972 |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4700 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition); | 4700 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition); |
| 4701 initial_value = factory()->NewConditional( | 4701 initial_value = factory()->NewConditional( |
| 4702 condition, parameter.initializer, initial_value, kNoSourcePosition); | 4702 condition, parameter.initializer, initial_value, kNoSourcePosition); |
| 4703 descriptor.initialization_pos = parameter.initializer->position(); | 4703 descriptor.initialization_pos = parameter.initializer->position(); |
| 4704 initializer_position = parameter.initializer_end_position; | 4704 initializer_position = parameter.initializer_end_position; |
| 4705 } | 4705 } |
| 4706 | 4706 |
| 4707 Scope* param_scope = scope(); | 4707 Scope* param_scope = scope(); |
| 4708 Block* param_block = init_block; | 4708 Block* param_block = init_block; |
| 4709 if (!parameter.is_simple() && scope()->calls_sloppy_eval()) { | 4709 if (!parameter.is_simple() && scope()->calls_sloppy_eval()) { |
| 4710 param_scope = NewScope(scope(), BLOCK_SCOPE); | 4710 param_scope = NewScope(BLOCK_SCOPE); |
| 4711 param_scope->set_is_declaration_scope(); | 4711 param_scope->set_is_declaration_scope(); |
| 4712 param_scope->set_start_position(descriptor.initialization_pos); | 4712 param_scope->set_start_position(descriptor.initialization_pos); |
| 4713 param_scope->set_end_position(parameter.initializer_end_position); | 4713 param_scope->set_end_position(parameter.initializer_end_position); |
| 4714 param_scope->RecordEvalCall(); | 4714 param_scope->RecordEvalCall(); |
| 4715 param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); | 4715 param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); |
| 4716 param_block->set_scope(param_scope); | 4716 param_block->set_scope(param_scope); |
| 4717 descriptor.hoist_scope = scope(); | 4717 descriptor.hoist_scope = scope(); |
| 4718 // Pass the appropriate scope in so that PatternRewriter can appropriately | 4718 // Pass the appropriate scope in so that PatternRewriter can appropriately |
| 4719 // rewrite inner initializers of the pattern to param_scope | 4719 // rewrite inner initializers of the pattern to param_scope |
| 4720 descriptor.scope = param_scope; | 4720 descriptor.scope = param_scope; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4738 } | 4738 } |
| 4739 init_block->statements()->Add(param_block, zone()); | 4739 init_block->statements()->Add(param_block, zone()); |
| 4740 } | 4740 } |
| 4741 } | 4741 } |
| 4742 return init_block; | 4742 return init_block; |
| 4743 } | 4743 } |
| 4744 | 4744 |
| 4745 Block* Parser::BuildRejectPromiseOnException(Block* block) { | 4745 Block* Parser::BuildRejectPromiseOnException(Block* block) { |
| 4746 // try { <block> } catch (error) { return Promise.reject(error); } | 4746 // try { <block> } catch (error) { return Promise.reject(error); } |
| 4747 Block* try_block = block; | 4747 Block* try_block = block; |
| 4748 Scope* catch_scope = NewScope(scope(), CATCH_SCOPE); | 4748 Scope* catch_scope = NewScope(CATCH_SCOPE); |
| 4749 catch_scope->set_is_hidden(); | 4749 catch_scope->set_is_hidden(); |
| 4750 Variable* catch_variable = | 4750 Variable* catch_variable = |
| 4751 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, | 4751 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, |
| 4752 kCreatedInitialized, Variable::NORMAL); | 4752 kCreatedInitialized, Variable::NORMAL); |
| 4753 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 4753 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
| 4754 | 4754 |
| 4755 Expression* promise_reject = BuildPromiseReject( | 4755 Expression* promise_reject = BuildPromiseReject( |
| 4756 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); | 4756 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); |
| 4757 | 4757 |
| 4758 ReturnStatement* return_promise_reject = | 4758 ReturnStatement* return_promise_reject = |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4810 // Not having parsed the function body, the language mode may still change, | 4810 // Not having parsed the function body, the language mode may still change, |
| 4811 // so we reserve a spot and create the actual const assignment later. | 4811 // so we reserve a spot and create the actual const assignment later. |
| 4812 DCHECK_EQ(kFunctionNameAssignmentIndex, result->length()); | 4812 DCHECK_EQ(kFunctionNameAssignmentIndex, result->length()); |
| 4813 result->Add(NULL, zone()); | 4813 result->Add(NULL, zone()); |
| 4814 } | 4814 } |
| 4815 | 4815 |
| 4816 ZoneList<Statement*>* body = result; | 4816 ZoneList<Statement*>* body = result; |
| 4817 Scope* inner_scope = scope(); | 4817 Scope* inner_scope = scope(); |
| 4818 Block* inner_block = nullptr; | 4818 Block* inner_block = nullptr; |
| 4819 if (!parameters.is_simple) { | 4819 if (!parameters.is_simple) { |
| 4820 inner_scope = NewScope(scope(), BLOCK_SCOPE); | 4820 inner_scope = NewScope(BLOCK_SCOPE); |
| 4821 inner_scope->set_is_declaration_scope(); | 4821 inner_scope->set_is_declaration_scope(); |
| 4822 inner_scope->set_start_position(scanner()->location().beg_pos); | 4822 inner_scope->set_start_position(scanner()->location().beg_pos); |
| 4823 inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); | 4823 inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); |
| 4824 inner_block->set_scope(inner_scope); | 4824 inner_block->set_scope(inner_scope); |
| 4825 body = inner_block->statements(); | 4825 body = inner_block->statements(); |
| 4826 } | 4826 } |
| 4827 | 4827 |
| 4828 { | 4828 { |
| 4829 BlockState block_state(&scope_state_, inner_scope); | 4829 BlockState block_state(&scope_state_, inner_scope); |
| 4830 | 4830 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5010 MessageTemplate::kUnexpectedStrictReserved); | 5010 MessageTemplate::kUnexpectedStrictReserved); |
| 5011 *ok = false; | 5011 *ok = false; |
| 5012 return NULL; | 5012 return NULL; |
| 5013 } | 5013 } |
| 5014 if (IsEvalOrArguments(name)) { | 5014 if (IsEvalOrArguments(name)) { |
| 5015 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); | 5015 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); |
| 5016 *ok = false; | 5016 *ok = false; |
| 5017 return NULL; | 5017 return NULL; |
| 5018 } | 5018 } |
| 5019 | 5019 |
| 5020 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE); | 5020 Scope* block_scope = NewScope(BLOCK_SCOPE); |
| 5021 BlockState block_state(&scope_state_, block_scope); | 5021 BlockState block_state(&scope_state_, block_scope); |
| 5022 RaiseLanguageMode(STRICT); | 5022 RaiseLanguageMode(STRICT); |
| 5023 scope()->SetScopeName(name); | 5023 scope()->SetScopeName(name); |
| 5024 | 5024 |
| 5025 VariableProxy* proxy = NULL; | 5025 VariableProxy* proxy = NULL; |
| 5026 if (name != NULL) { | 5026 if (name != NULL) { |
| 5027 proxy = NewUnresolved(name, CONST); | 5027 proxy = NewUnresolved(name, CONST); |
| 5028 Declaration* declaration = | 5028 Declaration* declaration = |
| 5029 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | 5029 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); |
| 5030 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 5030 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
| (...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6504 // try { ... } catch(e) { ... } | 6504 // try { ... } catch(e) { ... } |
| 6505 Statement* try_catch; | 6505 Statement* try_catch; |
| 6506 { | 6506 { |
| 6507 Block* try_block = factory->NewBlock(nullptr, 2, false, nopos); | 6507 Block* try_block = factory->NewBlock(nullptr, 2, false, nopos); |
| 6508 try_block->statements()->Add(yield_output, zone); | 6508 try_block->statements()->Add(yield_output, zone); |
| 6509 try_block->statements()->Add(set_mode_next, zone); | 6509 try_block->statements()->Add(set_mode_next, zone); |
| 6510 | 6510 |
| 6511 Block* catch_block = factory->NewBlock(nullptr, 1, false, nopos); | 6511 Block* catch_block = factory->NewBlock(nullptr, 1, false, nopos); |
| 6512 catch_block->statements()->Add(set_mode_throw, zone); | 6512 catch_block->statements()->Add(set_mode_throw, zone); |
| 6513 | 6513 |
| 6514 Scope* catch_scope = NewScope(scope, CATCH_SCOPE); | 6514 Scope* catch_scope = NewScopeWithParent(scope, CATCH_SCOPE); |
| 6515 catch_scope->set_is_hidden(); | 6515 catch_scope->set_is_hidden(); |
| 6516 const AstRawString* name = avfactory->dot_catch_string(); | 6516 const AstRawString* name = avfactory->dot_catch_string(); |
| 6517 Variable* catch_variable = | 6517 Variable* catch_variable = |
| 6518 catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, | 6518 catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, |
| 6519 Variable::NORMAL); | 6519 Variable::NORMAL); |
| 6520 | 6520 |
| 6521 try_catch = factory->NewTryCatchStatement( | 6521 try_catch = factory->NewTryCatchStatement( |
| 6522 try_block, catch_scope, catch_variable, catch_block, nopos); | 6522 try_block, catch_scope, catch_variable, catch_block, nopos); |
| 6523 } | 6523 } |
| 6524 | 6524 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6803 zone); | 6803 zone); |
| 6804 } | 6804 } |
| 6805 | 6805 |
| 6806 // try { #try_block } | 6806 // try { #try_block } |
| 6807 // catch(e) { | 6807 // catch(e) { |
| 6808 // #set_completion_throw; | 6808 // #set_completion_throw; |
| 6809 // %ReThrow(e); | 6809 // %ReThrow(e); |
| 6810 // } | 6810 // } |
| 6811 Statement* try_catch; | 6811 Statement* try_catch; |
| 6812 { | 6812 { |
| 6813 Scope* catch_scope = parser_->NewScope(scope, CATCH_SCOPE); | 6813 Scope* catch_scope = parser_->NewScopeWithParent(scope, CATCH_SCOPE); |
| 6814 Variable* catch_variable = | 6814 Variable* catch_variable = |
| 6815 catch_scope->DeclareLocal(avfactory->dot_catch_string(), VAR, | 6815 catch_scope->DeclareLocal(avfactory->dot_catch_string(), VAR, |
| 6816 kCreatedInitialized, Variable::NORMAL); | 6816 kCreatedInitialized, Variable::NORMAL); |
| 6817 catch_scope->set_is_hidden(); | 6817 catch_scope->set_is_hidden(); |
| 6818 | 6818 |
| 6819 Statement* rethrow; | 6819 Statement* rethrow; |
| 6820 // We use %ReThrow rather than the ordinary throw because we want to | 6820 // We use %ReThrow rather than the ordinary throw because we want to |
| 6821 // preserve the original exception message. This is also why we create a | 6821 // preserve the original exception message. This is also why we create a |
| 6822 // TryCatchStatementForReThrow below (which does not clear the pending | 6822 // TryCatchStatementForReThrow below (which does not clear the pending |
| 6823 // message), rather than a TryCatchStatement. | 6823 // message), rather than a TryCatchStatement. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6915 | 6915 |
| 6916 Expression* call = | 6916 Expression* call = |
| 6917 factory->NewCallRuntime(Runtime::kInlineCall, args, nopos); | 6917 factory->NewCallRuntime(Runtime::kInlineCall, args, nopos); |
| 6918 | 6918 |
| 6919 Block* try_block = factory->NewBlock(nullptr, 1, false, nopos); | 6919 Block* try_block = factory->NewBlock(nullptr, 1, false, nopos); |
| 6920 try_block->statements()->Add(factory->NewExpressionStatement(call, nopos), | 6920 try_block->statements()->Add(factory->NewExpressionStatement(call, nopos), |
| 6921 zone); | 6921 zone); |
| 6922 | 6922 |
| 6923 Block* catch_block = factory->NewBlock(nullptr, 0, false, nopos); | 6923 Block* catch_block = factory->NewBlock(nullptr, 0, false, nopos); |
| 6924 | 6924 |
| 6925 Scope* catch_scope = NewScope(scope, CATCH_SCOPE); | 6925 Scope* catch_scope = NewScopeWithParent(scope, CATCH_SCOPE); |
| 6926 Variable* catch_variable = catch_scope->DeclareLocal( | 6926 Variable* catch_variable = catch_scope->DeclareLocal( |
| 6927 avfactory->dot_catch_string(), VAR, kCreatedInitialized, | 6927 avfactory->dot_catch_string(), VAR, kCreatedInitialized, |
| 6928 Variable::NORMAL); | 6928 Variable::NORMAL); |
| 6929 catch_scope->set_is_hidden(); | 6929 catch_scope->set_is_hidden(); |
| 6930 | 6930 |
| 6931 try_call_return = factory->NewTryCatchStatement( | 6931 try_call_return = factory->NewTryCatchStatement( |
| 6932 try_block, catch_scope, catch_variable, catch_block, nopos); | 6932 try_block, catch_scope, catch_variable, catch_block, nopos); |
| 6933 } | 6933 } |
| 6934 | 6934 |
| 6935 // let output = %_Call(iteratorReturn, iterator); | 6935 // let output = %_Call(iteratorReturn, iterator); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7075 node->Print(Isolate::Current()); | 7075 node->Print(Isolate::Current()); |
| 7076 } | 7076 } |
| 7077 #endif // DEBUG | 7077 #endif // DEBUG |
| 7078 | 7078 |
| 7079 #undef CHECK_OK | 7079 #undef CHECK_OK |
| 7080 #undef CHECK_OK_VOID | 7080 #undef CHECK_OK_VOID |
| 7081 #undef CHECK_FAILED | 7081 #undef CHECK_FAILED |
| 7082 | 7082 |
| 7083 } // namespace internal | 7083 } // namespace internal |
| 7084 } // namespace v8 | 7084 } // namespace v8 |
| OLD | NEW |