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

Side by Side Diff: src/preparser.h

Issue 1167393005: [destructuring] Parse binding patterns in formal parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: CR feedback + rebase Created 5 years, 6 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 | « src/parser.cc ('k') | src/preparser.cc » ('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 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 !classifier->is_valid_strong_mode_formal_parameters()) { 548 !classifier->is_valid_strong_mode_formal_parameters()) {
549 ReportClassifierError(classifier->strong_mode_formal_parameter_error()); 549 ReportClassifierError(classifier->strong_mode_formal_parameter_error());
550 *ok = false; 550 *ok = false;
551 } 551 }
552 } 552 }
553 553
554 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, 554 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier,
555 ExpressionT expr, bool* ok) { 555 ExpressionT expr, bool* ok) {
556 if (classifier->is_valid_binding_pattern()) { 556 if (classifier->is_valid_binding_pattern()) {
557 // A simple arrow formal parameter: IDENTIFIER => BODY. 557 // A simple arrow formal parameter: IDENTIFIER => BODY.
558 if (!this->IsIdentifier(expr)) { 558 if (!allow_harmony_destructuring() && !this->IsIdentifier(expr)) {
559 Traits::ReportMessageAt(scanner()->location(), 559 Traits::ReportMessageAt(scanner()->location(),
560 MessageTemplate::kUnexpectedToken, 560 MessageTemplate::kUnexpectedToken,
561 Token::String(scanner()->current_token())); 561 Token::String(scanner()->current_token()));
562 *ok = false; 562 *ok = false;
563 } 563 }
564 } else if (!classifier->is_valid_arrow_formal_parameters()) { 564 } else if (!classifier->is_valid_arrow_formal_parameters()) {
565 ReportClassifierError(classifier->arrow_formal_parameters_error()); 565 ReportClassifierError(classifier->arrow_formal_parameters_error());
566 *ok = false; 566 *ok = false;
567 } 567 }
568 } 568 }
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 return EmptyExpression(); 1548 return EmptyExpression();
1549 } 1549 }
1550 inline void MaterializeTemplateCallsiteLiterals(); 1550 inline void MaterializeTemplateCallsiteLiterals();
1551 PreParserExpression NoTemplateTag() { 1551 PreParserExpression NoTemplateTag() {
1552 return PreParserExpression::NoTemplateTag(); 1552 return PreParserExpression::NoTemplateTag();
1553 } 1553 }
1554 static bool IsTaggedTemplate(const PreParserExpression tag) { 1554 static bool IsTaggedTemplate(const PreParserExpression tag) {
1555 return !tag.IsNoTemplateTag(); 1555 return !tag.IsNoTemplateTag();
1556 } 1556 }
1557 1557
1558 void DeclareFormalParameter(Scope* scope, PreParserIdentifier param, 1558 void DeclareFormalParameter(Scope* scope, PreParserExpression pattern,
1559 ExpressionClassifier* classifier, bool is_rest) {} 1559 ExpressionClassifier* classifier, bool is_rest) {}
1560 1560
1561 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} 1561 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {}
1562 1562
1563 // Temporary glue; these functions will move to ParserBase. 1563 // Temporary glue; these functions will move to ParserBase.
1564 PreParserExpression ParseV8Intrinsic(bool* ok); 1564 PreParserExpression ParseV8Intrinsic(bool* ok);
1565 PreParserExpression ParseFunctionLiteral( 1565 PreParserExpression ParseFunctionLiteral(
1566 PreParserIdentifier name, Scanner::Location function_name_location, 1566 PreParserIdentifier name, Scanner::Location function_name_location,
1567 bool name_is_strict_reserved, FunctionKind kind, 1567 bool name_is_strict_reserved, FunctionKind kind,
1568 int function_token_position, FunctionLiteral::FunctionType type, 1568 int function_token_position, FunctionLiteral::FunctionType type,
(...skipping 1911 matching lines...) Expand 10 before | Expand all | Expand 10 after
3480 return this->EmptyExpression(); 3480 return this->EmptyExpression();
3481 } 3481 }
3482 3482
3483 3483
3484 template <class Traits> 3484 template <class Traits>
3485 void ParserBase<Traits>::ParseFormalParameter(Scope* scope, bool is_rest, 3485 void ParserBase<Traits>::ParseFormalParameter(Scope* scope, bool is_rest,
3486 ExpressionClassifier* classifier, 3486 ExpressionClassifier* classifier,
3487 bool* ok) { 3487 bool* ok) {
3488 // FormalParameter[Yield,GeneratorParameter] : 3488 // FormalParameter[Yield,GeneratorParameter] :
3489 // BindingElement[?Yield, ?GeneratorParameter] 3489 // BindingElement[?Yield, ?GeneratorParameter]
3490 IdentifierT name = ParseAndClassifyIdentifier(classifier, ok); 3490
3491 Token::Value next = peek();
3492 ExpressionT pattern = ParsePrimaryExpression(classifier, ok);
3491 if (!*ok) return; 3493 if (!*ok) return;
3492 3494
3493 Traits::DeclareFormalParameter(scope, name, classifier, is_rest); 3495 ValidateBindingPattern(classifier, ok);
3496 if (!*ok) return;
3497
3498 if (!allow_harmony_destructuring() && !Traits::IsIdentifier(pattern)) {
3499 ReportUnexpectedToken(next);
3500 *ok = false;
3501 return;
3502 }
3503
3504 Traits::DeclareFormalParameter(scope, pattern, classifier, is_rest);
3494 } 3505 }
3495 3506
3496 3507
3497 template <class Traits> 3508 template <class Traits>
3498 int ParserBase<Traits>::ParseFormalParameterList( 3509 int ParserBase<Traits>::ParseFormalParameterList(
3499 Scope* scope, bool* is_rest, ExpressionClassifier* classifier, bool* ok) { 3510 Scope* scope, bool* is_rest, ExpressionClassifier* classifier, bool* ok) {
3500 // FormalParameters[Yield,GeneratorParameter] : 3511 // FormalParameters[Yield,GeneratorParameter] :
3501 // [empty] 3512 // [empty]
3502 // FormalParameterList[?Yield, ?GeneratorParameter] 3513 // FormalParameterList[?Yield, ?GeneratorParameter]
3503 // 3514 //
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
3846 *ok = false; 3857 *ok = false;
3847 return; 3858 return;
3848 } 3859 }
3849 has_seen_constructor_ = true; 3860 has_seen_constructor_ = true;
3850 return; 3861 return;
3851 } 3862 }
3852 } 3863 }
3853 } } // v8::internal 3864 } } // v8::internal
3854 3865
3855 #endif // V8_PREPARSER_H 3866 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698