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 2479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2490 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral( | 2490 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral( |
2491 ExpressionClassifier* classifier, bool* ok) { | 2491 ExpressionClassifier* classifier, bool* ok) { |
2492 // ArrayLiteral :: | 2492 // ArrayLiteral :: |
2493 // '[' Expression? (',' Expression?)* ']' | 2493 // '[' Expression? (',' Expression?)* ']' |
2494 | 2494 |
2495 int pos = peek_position(); | 2495 int pos = peek_position(); |
2496 typename Traits::Type::ExpressionList values = | 2496 typename Traits::Type::ExpressionList values = |
2497 this->NewExpressionList(4, zone_); | 2497 this->NewExpressionList(4, zone_); |
2498 Expect(Token::LBRACK, CHECK_OK); | 2498 Expect(Token::LBRACK, CHECK_OK); |
2499 while (peek() != Token::RBRACK) { | 2499 while (peek() != Token::RBRACK) { |
| 2500 bool seen_spread = false; |
2500 ExpressionT elem = this->EmptyExpression(); | 2501 ExpressionT elem = this->EmptyExpression(); |
2501 if (peek() == Token::COMMA) { | 2502 if (peek() == Token::COMMA) { |
2502 if (is_strong(language_mode())) { | 2503 if (is_strong(language_mode())) { |
2503 ReportMessageAt(scanner()->peek_location(), | 2504 ReportMessageAt(scanner()->peek_location(), |
2504 MessageTemplate::kStrongEllision); | 2505 MessageTemplate::kStrongEllision); |
2505 *ok = false; | 2506 *ok = false; |
2506 return this->EmptyExpression(); | 2507 return this->EmptyExpression(); |
2507 } | 2508 } |
2508 elem = this->GetLiteralTheHole(peek_position(), factory()); | 2509 elem = this->GetLiteralTheHole(peek_position(), factory()); |
| 2510 } else if (peek() == Token::ELLIPSIS) { |
| 2511 ExpressionUnexpectedToken(classifier); |
| 2512 int start_pos = peek_position(); |
| 2513 Consume(Token::ELLIPSIS); |
| 2514 ExpressionT argument = |
| 2515 this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
| 2516 |
| 2517 elem = factory()->NewSpread(argument, start_pos); |
| 2518 seen_spread = true; |
2509 } else { | 2519 } else { |
2510 elem = this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 2520 elem = this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
2511 } | 2521 } |
2512 values->Add(elem, zone_); | 2522 values->Add(elem, zone_); |
2513 if (peek() != Token::RBRACK) { | 2523 if (peek() != Token::RBRACK) { |
| 2524 if (seen_spread) { |
| 2525 BindingPatternUnexpectedToken(classifier); |
| 2526 } |
2514 Expect(Token::COMMA, CHECK_OK); | 2527 Expect(Token::COMMA, CHECK_OK); |
2515 } | 2528 } |
2516 } | 2529 } |
2517 Expect(Token::RBRACK, CHECK_OK); | 2530 Expect(Token::RBRACK, CHECK_OK); |
2518 | 2531 |
2519 // Update the scope information before the pre-parsing bailout. | 2532 // Update the scope information before the pre-parsing bailout. |
2520 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 2533 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
2521 | 2534 |
2522 return factory()->NewArrayLiteral(values, literal_index, | 2535 return factory()->NewArrayLiteral(values, literal_index, |
2523 is_strong(language_mode()), pos); | 2536 is_strong(language_mode()), pos); |
(...skipping 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4007 *ok = false; | 4020 *ok = false; |
4008 return; | 4021 return; |
4009 } | 4022 } |
4010 has_seen_constructor_ = true; | 4023 has_seen_constructor_ = true; |
4011 return; | 4024 return; |
4012 } | 4025 } |
4013 } | 4026 } |
4014 } } // v8::internal | 4027 } } // v8::internal |
4015 | 4028 |
4016 #endif // V8_PREPARSER_H | 4029 #endif // V8_PREPARSER_H |
OLD | NEW |