Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: src/preparser.h

Issue 996223003: [es6] support template literals after MemberExpression (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: New tests, delete unneeded code, some comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/scanner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2733 // No 'new' or 'super' keyword. 2716 // No 'new' or 'super' keyword.
2734 return this->ParseMemberExpression(ok); 2717 return this->ParseMemberExpression(ok);
2735 } 2718 }
2736 2719
2737 2720
2738 template <class Traits> 2721 template <class Traits>
2739 typename ParserBase<Traits>::ExpressionT 2722 typename ParserBase<Traits>::ExpressionT
2740 ParserBase<Traits>::ParseMemberExpression(bool* ok) { 2723 ParserBase<Traits>::ParseMemberExpression(bool* ok) {
2741 // MemberExpression :: 2724 // MemberExpression ::
2742 // (PrimaryExpression | FunctionLiteral | ClassLiteral) 2725 // (PrimaryExpression | FunctionLiteral | ClassLiteral)
2743 // ('[' Expression ']' | '.' Identifier | Arguments)* 2726 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)*
2744 2727
2745 // The '[' Expression ']' and '.' Identifier parts are parsed by 2728 // The '[' Expression ']' and '.' Identifier parts are parsed by
2746 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the 2729 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the
2747 // caller. 2730 // caller.
2748 2731
2749 // Parse the initial primary or function expression. 2732 // Parse the initial primary or function expression.
2750 ExpressionT result = this->EmptyExpression(); 2733 ExpressionT result = this->EmptyExpression();
2751 if (peek() == Token::FUNCTION) { 2734 if (peek() == Token::FUNCTION) {
2752 Consume(Token::FUNCTION); 2735 Consume(Token::FUNCTION);
2753 int function_token_position = position(); 2736 int function_token_position = position();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2810 *ok = false; 2793 *ok = false;
2811 return this->EmptyExpression(); 2794 return this->EmptyExpression();
2812 } 2795 }
2813 2796
2814 2797
2815 template <class Traits> 2798 template <class Traits>
2816 typename ParserBase<Traits>::ExpressionT 2799 typename ParserBase<Traits>::ExpressionT
2817 ParserBase<Traits>::ParseMemberExpressionContinuation(ExpressionT expression, 2800 ParserBase<Traits>::ParseMemberExpressionContinuation(ExpressionT expression,
2818 bool* ok) { 2801 bool* ok) {
2819 // Parses this part of MemberExpression: 2802 // Parses this part of MemberExpression:
2820 // ('[' Expression ']' | '.' Identifier)* 2803 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)*
2821 while (true) { 2804 while (true) {
2822 switch (peek()) { 2805 switch (peek()) {
2823 case Token::LBRACK: { 2806 case Token::LBRACK: {
2824 Consume(Token::LBRACK); 2807 Consume(Token::LBRACK);
2825 int pos = position(); 2808 int pos = position();
2826 ExpressionT index = this->ParseExpression(true, CHECK_OK); 2809 ExpressionT index = this->ParseExpression(true, CHECK_OK);
2827 expression = factory()->NewProperty(expression, index, pos); 2810 expression = factory()->NewProperty(expression, index, pos);
2828 if (fni_ != NULL) { 2811 if (fni_ != NULL) {
2829 this->PushPropertyName(fni_, index); 2812 this->PushPropertyName(fni_, index);
2830 } 2813 }
2831 Expect(Token::RBRACK, CHECK_OK); 2814 Expect(Token::RBRACK, CHECK_OK);
2832 break; 2815 break;
2833 } 2816 }
2834 case Token::PERIOD: { 2817 case Token::PERIOD: {
2835 Consume(Token::PERIOD); 2818 Consume(Token::PERIOD);
2836 int pos = position(); 2819 int pos = position();
2837 IdentifierT name = ParseIdentifierName(CHECK_OK); 2820 IdentifierT name = ParseIdentifierName(CHECK_OK);
2838 expression = factory()->NewProperty( 2821 expression = factory()->NewProperty(
2839 expression, factory()->NewStringLiteral(name, pos), pos); 2822 expression, factory()->NewStringLiteral(name, pos), pos);
2840 if (fni_ != NULL) { 2823 if (fni_ != NULL) {
2841 this->PushLiteralName(fni_, name); 2824 this->PushLiteralName(fni_, name);
2842 } 2825 }
2843 break; 2826 break;
2844 } 2827 }
2828 case Token::TEMPLATE_SPAN:
2829 case Token::TEMPLATE_TAIL: {
2830 int pos;
2831 if (scanner()->current_token() == Token::IDENTIFIER) {
2832 pos = position();
2833 } else {
2834 pos = peek_position();
2835 if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) {
2836 // If the tag function looks like an IIFE, set_parenthesized() to
2837 // force eager compilation.
2838 expression->AsFunctionLiteral()->set_parenthesized();
2839 }
2840 }
2841 expression = ParseTemplateLiteral(expression, pos, CHECK_OK);
2842 break;
2843 }
2845 default: 2844 default:
2846 return expression; 2845 return expression;
2847 } 2846 }
2848 } 2847 }
2849 DCHECK(false); 2848 DCHECK(false);
2850 return this->EmptyExpression(); 2849 return this->EmptyExpression();
2851 } 2850 }
2852 2851
2853 2852
2854 template <class Traits> 2853 template <class Traits>
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
3135 *ok = false; 3134 *ok = false;
3136 return; 3135 return;
3137 } 3136 }
3138 has_seen_constructor_ = true; 3137 has_seen_constructor_ = true;
3139 return; 3138 return;
3140 } 3139 }
3141 } 3140 }
3142 } } // v8::internal 3141 } } // v8::internal
3143 3142
3144 #endif // V8_PREPARSER_H 3143 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « no previous file | src/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698