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

Side by Side Diff: src/preparser.h

Issue 1151503002: [destructuring] Implement spread binding patterns. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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
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 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 Scope* scope, PreParserStatementList body, int materialized_literal_count, 1478 Scope* scope, PreParserStatementList body, int materialized_literal_count,
1479 int expected_property_count, int handler_count, int parameter_count, 1479 int expected_property_count, int handler_count, int parameter_count,
1480 FunctionLiteral::ParameterFlag has_duplicate_parameters, 1480 FunctionLiteral::ParameterFlag has_duplicate_parameters,
1481 FunctionLiteral::FunctionType function_type, 1481 FunctionLiteral::FunctionType function_type,
1482 FunctionLiteral::IsFunctionFlag is_function, 1482 FunctionLiteral::IsFunctionFlag is_function,
1483 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, 1483 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind,
1484 int position) { 1484 int position) {
1485 return PreParserExpression::Default(); 1485 return PreParserExpression::Default();
1486 } 1486 }
1487 1487
1488 PreParserExpression NewSpread(PreParserExpression expression, int pos) { 1488 PreParserExpression NewSpread(PreParserExpression expression,
1489 int literal_index, int pos) {
1489 return PreParserExpression::Spread(expression); 1490 return PreParserExpression::Spread(expression);
1490 } 1491 }
1491 1492
1492 // Return the object itself as AstVisitor and implement the needed 1493 // Return the object itself as AstVisitor and implement the needed
1493 // dummy method right in this class. 1494 // dummy method right in this class.
1494 PreParserFactory* visitor() { return this; } 1495 PreParserFactory* visitor() { return this; }
1495 int* ast_properties() { 1496 int* ast_properties() {
1496 static int dummy = 42; 1497 static int dummy = 42;
1497 return &dummy; 1498 return &dummy;
1498 } 1499 }
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after
2490 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral( 2491 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral(
2491 ExpressionClassifier* classifier, bool* ok) { 2492 ExpressionClassifier* classifier, bool* ok) {
2492 // ArrayLiteral :: 2493 // ArrayLiteral ::
2493 // '[' Expression? (',' Expression?)* ']' 2494 // '[' Expression? (',' Expression?)* ']'
2494 2495
2495 int pos = peek_position(); 2496 int pos = peek_position();
2496 typename Traits::Type::ExpressionList values = 2497 typename Traits::Type::ExpressionList values =
2497 this->NewExpressionList(4, zone_); 2498 this->NewExpressionList(4, zone_);
2498 Expect(Token::LBRACK, CHECK_OK); 2499 Expect(Token::LBRACK, CHECK_OK);
2499 while (peek() != Token::RBRACK) { 2500 while (peek() != Token::RBRACK) {
2501 bool seen_spread = false;
2500 ExpressionT elem = this->EmptyExpression(); 2502 ExpressionT elem = this->EmptyExpression();
2501 if (peek() == Token::COMMA) { 2503 if (peek() == Token::COMMA) {
2502 if (is_strong(language_mode())) { 2504 if (is_strong(language_mode())) {
2503 ReportMessageAt(scanner()->peek_location(), 2505 ReportMessageAt(scanner()->peek_location(),
2504 MessageTemplate::kStrongEllision); 2506 MessageTemplate::kStrongEllision);
2505 *ok = false; 2507 *ok = false;
2506 return this->EmptyExpression(); 2508 return this->EmptyExpression();
2507 } 2509 }
2508 elem = this->GetLiteralTheHole(peek_position(), factory()); 2510 elem = this->GetLiteralTheHole(peek_position(), factory());
2511 } else if (peek() == Token::ELLIPSIS) {
2512 ExpressionUnexpectedToken(classifier);
2513 int start_pos = peek_position();
2514 Consume(Token::ELLIPSIS);
2515 ExpressionT argument =
2516 this->ParseAssignmentExpression(true, classifier, CHECK_OK);
2517
2518 int literal_index = function_state_->NextMaterializedLiteralIndex();
arv (Not doing code reviews) 2015/05/20 13:52:25 Is this going to be a problem in the case of array
Dmitry Lomov (no reviews) 2015/05/20 14:07:19 I don't think so - we will just have an unused lit
Dmitry Lomov (no reviews) 2015/05/20 14:22:03 Scratch that - I have One Weird Trick in mind here
2519 elem = factory()->NewSpread(argument, literal_index, start_pos);
2520 seen_spread = true;
2509 } else { 2521 } else {
2510 elem = this->ParseAssignmentExpression(true, classifier, CHECK_OK); 2522 elem = this->ParseAssignmentExpression(true, classifier, CHECK_OK);
2511 } 2523 }
2512 values->Add(elem, zone_); 2524 values->Add(elem, zone_);
2513 if (peek() != Token::RBRACK) { 2525 if (peek() != Token::RBRACK) {
2526 if (seen_spread) {
2527 BindingPatternUnexpectedToken(classifier);
2528 }
2514 Expect(Token::COMMA, CHECK_OK); 2529 Expect(Token::COMMA, CHECK_OK);
2515 } 2530 }
2516 } 2531 }
2517 Expect(Token::RBRACK, CHECK_OK); 2532 Expect(Token::RBRACK, CHECK_OK);
2518 2533
2519 // Update the scope information before the pre-parsing bailout. 2534 // Update the scope information before the pre-parsing bailout.
2520 int literal_index = function_state_->NextMaterializedLiteralIndex(); 2535 int literal_index = function_state_->NextMaterializedLiteralIndex();
2521 2536
2522 return factory()->NewArrayLiteral(values, literal_index, 2537 return factory()->NewArrayLiteral(values, literal_index,
2523 is_strong(language_mode()), pos); 2538 is_strong(language_mode()), pos);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 int start_pos = peek_position(); 2830 int start_pos = peek_position();
2816 if (is_spread) Consume(Token::ELLIPSIS); 2831 if (is_spread) Consume(Token::ELLIPSIS);
2817 2832
2818 ExpressionT argument = this->ParseAssignmentExpression( 2833 ExpressionT argument = this->ParseAssignmentExpression(
2819 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); 2834 true, classifier, CHECK_OK_CUSTOM(NullExpressionList));
2820 if (is_spread) { 2835 if (is_spread) {
2821 if (!spread_arg.IsValid()) { 2836 if (!spread_arg.IsValid()) {
2822 spread_arg.beg_pos = start_pos; 2837 spread_arg.beg_pos = start_pos;
2823 spread_arg.end_pos = peek_position(); 2838 spread_arg.end_pos = peek_position();
2824 } 2839 }
2825 argument = factory()->NewSpread(argument, start_pos); 2840 argument = factory()->NewSpread(argument, -1, start_pos);
2826 } 2841 }
2827 result->Add(argument, zone_); 2842 result->Add(argument, zone_);
2828 2843
2829 // unspread_sequences_count is the number of sequences of parameters which 2844 // unspread_sequences_count is the number of sequences of parameters which
2830 // are not prefixed with a spread '...' operator. 2845 // are not prefixed with a spread '...' operator.
2831 if (is_spread) { 2846 if (is_spread) {
2832 was_unspread = false; 2847 was_unspread = false;
2833 } else if (!was_unspread) { 2848 } else if (!was_unspread) {
2834 was_unspread = true; 2849 was_unspread = true;
2835 unspread_sequences_count++; 2850 unspread_sequences_count++;
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after
4007 *ok = false; 4022 *ok = false;
4008 return; 4023 return;
4009 } 4024 }
4010 has_seen_constructor_ = true; 4025 has_seen_constructor_ = true;
4011 return; 4026 return;
4012 } 4027 }
4013 } 4028 }
4014 } } // v8::internal 4029 } } // v8::internal
4015 4030
4016 #endif // V8_PREPARSER_H 4031 #endif // V8_PREPARSER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698