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

Side by Side Diff: src/preparser.h

Issue 1531853003: Version 4.7.80.26 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@4.7
Patch Set: Created 5 years 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 | « src/parser.cc ('k') | test/mjsunit/mjsunit.status » ('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/bailout-reason.h" 8 #include "src/bailout-reason.h"
9 #include "src/expression-classifier.h" 9 #include "src/expression-classifier.h"
10 #include "src/func-name-inferrer.h" 10 #include "src/func-name-inferrer.h"
(...skipping 2752 matching lines...) Expand 10 before | Expand all | Expand 10 after
2763 typename Traits::Type::PropertyList properties = 2763 typename Traits::Type::PropertyList properties =
2764 this->NewPropertyList(4, zone_); 2764 this->NewPropertyList(4, zone_);
2765 int number_of_boilerplate_properties = 0; 2765 int number_of_boilerplate_properties = 0;
2766 bool has_function = false; 2766 bool has_function = false;
2767 bool has_computed_names = false; 2767 bool has_computed_names = false;
2768 ObjectLiteralChecker checker(this); 2768 ObjectLiteralChecker checker(this);
2769 2769
2770 Expect(Token::LBRACE, CHECK_OK); 2770 Expect(Token::LBRACE, CHECK_OK);
2771 2771
2772 while (peek() != Token::RBRACE) { 2772 while (peek() != Token::RBRACE) {
2773 if (fni_ != nullptr) fni_->Enter(); 2773 FuncNameInferrer::State fni_state(fni_);
2774 2774
2775 const bool in_class = false; 2775 const bool in_class = false;
2776 const bool is_static = false; 2776 const bool is_static = false;
2777 const bool has_extends = false; 2777 const bool has_extends = false;
2778 bool is_computed_name = false; 2778 bool is_computed_name = false;
2779 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( 2779 ObjectLiteralPropertyT property = this->ParsePropertyDefinition(
2780 &checker, in_class, has_extends, is_static, &is_computed_name, NULL, 2780 &checker, in_class, has_extends, is_static, &is_computed_name, NULL,
2781 classifier, CHECK_OK); 2781 classifier, CHECK_OK);
2782 2782
2783 if (is_computed_name) { 2783 if (is_computed_name) {
(...skipping 10 matching lines...) Expand all
2794 if (!has_computed_names && this->IsBoilerplateProperty(property)) { 2794 if (!has_computed_names && this->IsBoilerplateProperty(property)) {
2795 number_of_boilerplate_properties++; 2795 number_of_boilerplate_properties++;
2796 } 2796 }
2797 properties->Add(property, zone()); 2797 properties->Add(property, zone());
2798 2798
2799 if (peek() != Token::RBRACE) { 2799 if (peek() != Token::RBRACE) {
2800 // Need {} because of the CHECK_OK macro. 2800 // Need {} because of the CHECK_OK macro.
2801 Expect(Token::COMMA, CHECK_OK); 2801 Expect(Token::COMMA, CHECK_OK);
2802 } 2802 }
2803 2803
2804 if (fni_ != nullptr) { 2804 if (fni_ != nullptr) fni_->Infer();
2805 fni_->Infer();
2806 fni_->Leave();
2807 }
2808 } 2805 }
2809 Expect(Token::RBRACE, CHECK_OK); 2806 Expect(Token::RBRACE, CHECK_OK);
2810 2807
2811 // Computation of literal_index must happen before pre parse bailout. 2808 // Computation of literal_index must happen before pre parse bailout.
2812 int literal_index = function_state_->NextMaterializedLiteralIndex(); 2809 int literal_index = function_state_->NextMaterializedLiteralIndex();
2813 2810
2814 return factory()->NewObjectLiteral(properties, 2811 return factory()->NewObjectLiteral(properties,
2815 literal_index, 2812 literal_index,
2816 number_of_boilerplate_properties, 2813 number_of_boilerplate_properties,
2817 has_function, 2814 has_function,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2899 // ArrowFunction 2896 // ArrowFunction
2900 // YieldExpression 2897 // YieldExpression
2901 // LeftHandSideExpression AssignmentOperator AssignmentExpression 2898 // LeftHandSideExpression AssignmentOperator AssignmentExpression
2902 2899
2903 int lhs_beg_pos = peek_position(); 2900 int lhs_beg_pos = peek_position();
2904 2901
2905 if (peek() == Token::YIELD && is_generator()) { 2902 if (peek() == Token::YIELD && is_generator()) {
2906 return this->ParseYieldExpression(classifier, ok); 2903 return this->ParseYieldExpression(classifier, ok);
2907 } 2904 }
2908 2905
2909 if (fni_ != NULL) fni_->Enter(); 2906 FuncNameInferrer::State fni_state(fni_);
2910 ParserBase<Traits>::Checkpoint checkpoint(this); 2907 ParserBase<Traits>::Checkpoint checkpoint(this);
2911 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); 2908 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder());
2912 bool parenthesized_formals = peek() == Token::LPAREN; 2909 bool parenthesized_formals = peek() == Token::LPAREN;
2913 if (!parenthesized_formals) { 2910 if (!parenthesized_formals) {
2914 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); 2911 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier);
2915 } 2912 }
2916 ExpressionT expression = this->ParseConditionalExpression( 2913 ExpressionT expression = this->ParseConditionalExpression(
2917 accept_IN, &arrow_formals_classifier, CHECK_OK); 2914 accept_IN, &arrow_formals_classifier, CHECK_OK);
2918 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { 2915 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) {
2919 BindingPatternUnexpectedToken(classifier); 2916 BindingPatternUnexpectedToken(classifier);
(...skipping 14 matching lines...) Expand all
2934 2931
2935 checkpoint.Restore(&parameters.materialized_literals_count); 2932 checkpoint.Restore(&parameters.materialized_literals_count);
2936 2933
2937 scope->set_start_position(lhs_beg_pos); 2934 scope->set_start_position(lhs_beg_pos);
2938 if (duplicate_loc.IsValid()) { 2935 if (duplicate_loc.IsValid()) {
2939 arrow_formals_classifier.RecordDuplicateFormalParameterError( 2936 arrow_formals_classifier.RecordDuplicateFormalParameterError(
2940 duplicate_loc); 2937 duplicate_loc);
2941 } 2938 }
2942 expression = this->ParseArrowFunctionLiteral( 2939 expression = this->ParseArrowFunctionLiteral(
2943 parameters, arrow_formals_classifier, CHECK_OK); 2940 parameters, arrow_formals_classifier, CHECK_OK);
2941
2942 if (fni_ != nullptr) fni_->Infer();
2943
2944 return expression; 2944 return expression;
2945 } 2945 }
2946 2946
2947 // "expression" was not itself an arrow function parameter list, but it might 2947 // "expression" was not itself an arrow function parameter list, but it might
2948 // form part of one. Propagate speculative formal parameter error locations. 2948 // form part of one. Propagate speculative formal parameter error locations.
2949 classifier->Accumulate(arrow_formals_classifier, 2949 classifier->Accumulate(arrow_formals_classifier,
2950 ExpressionClassifier::StandardProductions | 2950 ExpressionClassifier::StandardProductions |
2951 ExpressionClassifier::FormalParametersProductions); 2951 ExpressionClassifier::FormalParametersProductions);
2952 2952
2953 if (!Token::IsAssignmentOp(peek())) { 2953 if (!Token::IsAssignmentOp(peek())) {
2954 if (fni_ != NULL) fni_->Leave();
2955 // Parsed conditional expression only (no assignment). 2954 // Parsed conditional expression only (no assignment).
2956 return expression; 2955 return expression;
2957 } 2956 }
2958 2957
2959 if (!(allow_harmony_destructuring() || allow_harmony_default_parameters())) { 2958 if (!(allow_harmony_destructuring() || allow_harmony_default_parameters())) {
2960 BindingPatternUnexpectedToken(classifier); 2959 BindingPatternUnexpectedToken(classifier);
2961 } 2960 }
2962 2961
2963 expression = this->CheckAndRewriteReferenceExpression( 2962 expression = this->CheckAndRewriteReferenceExpression(
2964 expression, lhs_beg_pos, scanner()->location().end_pos, 2963 expression, lhs_beg_pos, scanner()->location().end_pos,
(...skipping 30 matching lines...) Expand all
2995 // name if we're dealing with "a = function(){...}();"-like 2994 // name if we're dealing with "a = function(){...}();"-like
2996 // expression. 2995 // expression.
2997 if ((op == Token::INIT_VAR 2996 if ((op == Token::INIT_VAR
2998 || op == Token::INIT_CONST_LEGACY 2997 || op == Token::INIT_CONST_LEGACY
2999 || op == Token::ASSIGN) 2998 || op == Token::ASSIGN)
3000 && (!right->IsCall() && !right->IsCallNew())) { 2999 && (!right->IsCall() && !right->IsCallNew())) {
3001 fni_->Infer(); 3000 fni_->Infer();
3002 } else { 3001 } else {
3003 fni_->RemoveLastFunction(); 3002 fni_->RemoveLastFunction();
3004 } 3003 }
3005 fni_->Leave();
3006 } 3004 }
3007 3005
3008 return factory()->NewAssignment(op, expression, right, pos); 3006 return factory()->NewAssignment(op, expression, right, pos);
3009 } 3007 }
3010 3008
3011 template <class Traits> 3009 template <class Traits>
3012 typename ParserBase<Traits>::ExpressionT 3010 typename ParserBase<Traits>::ExpressionT
3013 ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier, 3011 ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier,
3014 bool* ok) { 3012 bool* ok) {
3015 // YieldExpression :: 3013 // YieldExpression ::
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
3462 3460
3463 3461
3464 template <class Traits> 3462 template <class Traits>
3465 typename ParserBase<Traits>::ExpressionT 3463 typename ParserBase<Traits>::ExpressionT
3466 ParserBase<Traits>::ParseStrongInitializationExpression( 3464 ParserBase<Traits>::ParseStrongInitializationExpression(
3467 ExpressionClassifier* classifier, bool* ok) { 3465 ExpressionClassifier* classifier, bool* ok) {
3468 // InitializationExpression :: (strong mode) 3466 // InitializationExpression :: (strong mode)
3469 // 'this' '.' IdentifierName '=' AssignmentExpression 3467 // 'this' '.' IdentifierName '=' AssignmentExpression
3470 // 'this' '[' Expression ']' '=' AssignmentExpression 3468 // 'this' '[' Expression ']' '=' AssignmentExpression
3471 3469
3472 if (fni_ != NULL) fni_->Enter(); 3470 FuncNameInferrer::State fni_state(fni_);
3473 3471
3474 Consume(Token::THIS); 3472 Consume(Token::THIS);
3475 int pos = position(); 3473 int pos = position();
3476 function_state_->set_this_location(scanner()->location()); 3474 function_state_->set_this_location(scanner()->location());
3477 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); 3475 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos);
3478 3476
3479 ExpressionT left = this->EmptyExpression(); 3477 ExpressionT left = this->EmptyExpression();
3480 switch (peek()) { 3478 switch (peek()) {
3481 case Token::LBRACK: { 3479 case Token::LBRACK: {
3482 Consume(Token::LBRACK); 3480 Consume(Token::LBRACK);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3521 function_state_->AddProperty(); 3519 function_state_->AddProperty();
3522 if (fni_ != NULL) { 3520 if (fni_ != NULL) {
3523 // Check if the right hand side is a call to avoid inferring a 3521 // Check if the right hand side is a call to avoid inferring a
3524 // name if we're dealing with "this.a = function(){...}();"-like 3522 // name if we're dealing with "this.a = function(){...}();"-like
3525 // expression. 3523 // expression.
3526 if (!right->IsCall() && !right->IsCallNew()) { 3524 if (!right->IsCall() && !right->IsCallNew()) {
3527 fni_->Infer(); 3525 fni_->Infer();
3528 } else { 3526 } else {
3529 fni_->RemoveLastFunction(); 3527 fni_->RemoveLastFunction();
3530 } 3528 }
3531 fni_->Leave();
3532 } 3529 }
3533 3530
3534 if (function_state_->return_location().IsValid()) { 3531 if (function_state_->return_location().IsValid()) {
3535 ReportMessageAt(function_state_->return_location(), 3532 ReportMessageAt(function_state_->return_location(),
3536 MessageTemplate::kStrongConstructorReturnMisplaced); 3533 MessageTemplate::kStrongConstructorReturnMisplaced);
3537 *ok = false; 3534 *ok = false;
3538 return this->EmptyExpression(); 3535 return this->EmptyExpression();
3539 } 3536 }
3540 3537
3541 return factory()->NewAssignment(Token::ASSIGN, left, right, pos); 3538 return factory()->NewAssignment(Token::ASSIGN, left, right, pos);
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
4179 *ok = false; 4176 *ok = false;
4180 return; 4177 return;
4181 } 4178 }
4182 has_seen_constructor_ = true; 4179 has_seen_constructor_ = true;
4183 return; 4180 return;
4184 } 4181 }
4185 } 4182 }
4186 } } // v8::internal 4183 } } // v8::internal
4187 4184
4188 #endif // V8_PREPARSER_H 4185 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698