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 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 2635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2646 // direct eval calls. These calls are all of the form eval(...), with | 2646 // direct eval calls. These calls are all of the form eval(...), with |
2647 // no explicit receiver. | 2647 // no explicit receiver. |
2648 // These calls are marked as potentially direct eval calls. Whether | 2648 // These calls are marked as potentially direct eval calls. Whether |
2649 // they are actually direct calls to eval is determined at run time. | 2649 // they are actually direct calls to eval is determined at run time. |
2650 this->CheckPossibleEvalCall(result, scope_); | 2650 this->CheckPossibleEvalCall(result, scope_); |
2651 result = factory()->NewCall(result, args, pos); | 2651 result = factory()->NewCall(result, args, pos); |
2652 if (fni_ != NULL) fni_->RemoveLastFunction(); | 2652 if (fni_ != NULL) fni_->RemoveLastFunction(); |
2653 break; | 2653 break; |
2654 } | 2654 } |
2655 | 2655 |
2656 case Token::TEMPLATE_SPAN: | |
2657 case Token::TEMPLATE_TAIL: { | |
2658 int pos; | |
2659 if (scanner()->current_token() == Token::IDENTIFIER) { | |
2660 pos = position(); | |
2661 } else { | |
2662 pos = peek_position(); | |
2663 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | |
2664 // If the tag function looks like an IIFE, set_parenthesized() to | |
2665 // force eager compilation. | |
2666 result->AsFunctionLiteral()->set_parenthesized(); | |
2667 } | |
2668 } | |
2669 result = ParseTemplateLiteral(result, pos, CHECK_OK); | |
2670 break; | |
2671 } | |
2672 | |
2673 case Token::PERIOD: { | 2656 case Token::PERIOD: { |
2674 Consume(Token::PERIOD); | 2657 Consume(Token::PERIOD); |
2675 int pos = position(); | 2658 int pos = position(); |
2676 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2659 IdentifierT name = ParseIdentifierName(CHECK_OK); |
2677 result = factory()->NewProperty( | 2660 result = factory()->NewProperty( |
2678 result, factory()->NewStringLiteral(name, pos), pos); | 2661 result, factory()->NewStringLiteral(name, pos), pos); |
2679 if (fni_ != NULL) this->PushLiteralName(fni_, name); | 2662 if (fni_ != NULL) this->PushLiteralName(fni_, name); |
2680 break; | 2663 break; |
2681 } | 2664 } |
2682 | 2665 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2718 result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK); | 2701 result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK); |
2719 } | 2702 } |
2720 if (peek() == Token::LPAREN) { | 2703 if (peek() == Token::LPAREN) { |
2721 // NewExpression with arguments. | 2704 // NewExpression with arguments. |
2722 typename Traits::Type::ExpressionList args = | 2705 typename Traits::Type::ExpressionList args = |
2723 this->ParseArguments(CHECK_OK); | 2706 this->ParseArguments(CHECK_OK); |
2724 result = factory()->NewCallNew(result, args, new_pos); | 2707 result = factory()->NewCallNew(result, args, new_pos); |
2725 // The expression can still continue with . or [ after the arguments. | 2708 // The expression can still continue with . or [ after the arguments. |
2726 result = this->ParseMemberExpressionContinuation(result, CHECK_OK); | 2709 result = this->ParseMemberExpressionContinuation(result, CHECK_OK); |
2727 return result; | 2710 return result; |
2711 } else if (peek() == Token::TEMPLATE_SPAN || | |
2712 peek() == Token::TEMPLATE_TAIL) { | |
2713 // new tag`a` -> new(tag`a`) | |
marja
2015/03/12 11:43:35
Pls move this comment up in the comment block, it'
caitp (gmail)
2015/03/12 13:34:15
this whole block seems to be unneeded, since Parse
| |
2714 result = this->ParseMemberExpressionContinuation(result, CHECK_OK); | |
2728 } | 2715 } |
2729 // NewExpression without arguments. | 2716 // NewExpression without arguments. |
2730 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), | 2717 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), |
2731 new_pos); | 2718 new_pos); |
2732 } | 2719 } |
2733 // No 'new' or 'super' keyword. | 2720 // No 'new' or 'super' keyword. |
2734 return this->ParseMemberExpression(ok); | 2721 return this->ParseMemberExpression(ok); |
2735 } | 2722 } |
2736 | 2723 |
2737 | 2724 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2809 ReportMessageAt(scanner()->location(), "unexpected_super"); | 2796 ReportMessageAt(scanner()->location(), "unexpected_super"); |
2810 *ok = false; | 2797 *ok = false; |
2811 return this->EmptyExpression(); | 2798 return this->EmptyExpression(); |
2812 } | 2799 } |
2813 | 2800 |
2814 | 2801 |
2815 template <class Traits> | 2802 template <class Traits> |
2816 typename ParserBase<Traits>::ExpressionT | 2803 typename ParserBase<Traits>::ExpressionT |
2817 ParserBase<Traits>::ParseMemberExpressionContinuation(ExpressionT expression, | 2804 ParserBase<Traits>::ParseMemberExpressionContinuation(ExpressionT expression, |
2818 bool* ok) { | 2805 bool* ok) { |
2819 // Parses this part of MemberExpression: | 2806 // Parses this part of MemberExpression: |
marja
2015/03/12 11:43:35
You probably need to change the comment in ParseMe
| |
2820 // ('[' Expression ']' | '.' Identifier)* | 2807 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* |
2821 while (true) { | 2808 while (true) { |
2822 switch (peek()) { | 2809 switch (peek()) { |
2823 case Token::LBRACK: { | 2810 case Token::LBRACK: { |
2824 Consume(Token::LBRACK); | 2811 Consume(Token::LBRACK); |
2825 int pos = position(); | 2812 int pos = position(); |
2826 ExpressionT index = this->ParseExpression(true, CHECK_OK); | 2813 ExpressionT index = this->ParseExpression(true, CHECK_OK); |
2827 expression = factory()->NewProperty(expression, index, pos); | 2814 expression = factory()->NewProperty(expression, index, pos); |
2828 if (fni_ != NULL) { | 2815 if (fni_ != NULL) { |
2829 this->PushPropertyName(fni_, index); | 2816 this->PushPropertyName(fni_, index); |
2830 } | 2817 } |
2831 Expect(Token::RBRACK, CHECK_OK); | 2818 Expect(Token::RBRACK, CHECK_OK); |
2832 break; | 2819 break; |
2833 } | 2820 } |
2834 case Token::PERIOD: { | 2821 case Token::PERIOD: { |
2835 Consume(Token::PERIOD); | 2822 Consume(Token::PERIOD); |
2836 int pos = position(); | 2823 int pos = position(); |
2837 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2824 IdentifierT name = ParseIdentifierName(CHECK_OK); |
2838 expression = factory()->NewProperty( | 2825 expression = factory()->NewProperty( |
2839 expression, factory()->NewStringLiteral(name, pos), pos); | 2826 expression, factory()->NewStringLiteral(name, pos), pos); |
2840 if (fni_ != NULL) { | 2827 if (fni_ != NULL) { |
2841 this->PushLiteralName(fni_, name); | 2828 this->PushLiteralName(fni_, name); |
2842 } | 2829 } |
2843 break; | 2830 break; |
2844 } | 2831 } |
2832 case Token::TEMPLATE_SPAN: | |
2833 case Token::TEMPLATE_TAIL: { | |
2834 int pos; | |
2835 if (scanner()->current_token() == Token::IDENTIFIER) { | |
2836 pos = position(); | |
2837 } else { | |
2838 pos = peek_position(); | |
2839 if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | |
2840 // If the tag function looks like an IIFE, set_parenthesized() to | |
2841 // force eager compilation. | |
2842 expression->AsFunctionLiteral()->set_parenthesized(); | |
2843 } | |
2844 } | |
2845 expression = ParseTemplateLiteral(expression, pos, CHECK_OK); | |
2846 break; | |
2847 } | |
2845 default: | 2848 default: |
2846 return expression; | 2849 return expression; |
2847 } | 2850 } |
2848 } | 2851 } |
2849 DCHECK(false); | 2852 DCHECK(false); |
2850 return this->EmptyExpression(); | 2853 return this->EmptyExpression(); |
2851 } | 2854 } |
2852 | 2855 |
2853 | 2856 |
2854 template <class Traits> | 2857 template <class Traits> |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3135 *ok = false; | 3138 *ok = false; |
3136 return; | 3139 return; |
3137 } | 3140 } |
3138 has_seen_constructor_ = true; | 3141 has_seen_constructor_ = true; |
3139 return; | 3142 return; |
3140 } | 3143 } |
3141 } | 3144 } |
3142 } } // v8::internal | 3145 } } // v8::internal |
3143 | 3146 |
3144 #endif // V8_PREPARSER_H | 3147 #endif // V8_PREPARSER_H |
OLD | NEW |