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

Side by Side Diff: src/preparser.h

Issue 1225223004: Fix spread array inside array literal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add flag Created 5 years, 5 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/ast.cc ('k') | test/mjsunit/harmony/regress/regress-4298.js » ('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 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 bool is_strong, 1168 bool is_strong,
1169 int pos) { 1169 int pos) {
1170 return PreParserExpression::Default(); 1170 return PreParserExpression::Default();
1171 } 1171 }
1172 PreParserExpression NewArrayLiteral(PreParserExpressionList values, 1172 PreParserExpression NewArrayLiteral(PreParserExpressionList values,
1173 int literal_index, 1173 int literal_index,
1174 bool is_strong, 1174 bool is_strong,
1175 int pos) { 1175 int pos) {
1176 return PreParserExpression::Default(); 1176 return PreParserExpression::Default();
1177 } 1177 }
1178 PreParserExpression NewArrayLiteral(PreParserExpressionList values,
1179 int first_spread_index, int literal_index,
1180 bool is_strong, int pos) {
1181 return PreParserExpression::Default();
1182 }
1178 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, 1183 PreParserExpression NewObjectLiteralProperty(PreParserExpression key,
1179 PreParserExpression value, 1184 PreParserExpression value,
1180 ObjectLiteralProperty::Kind kind, 1185 ObjectLiteralProperty::Kind kind,
1181 bool is_static, 1186 bool is_static,
1182 bool is_computed_name) { 1187 bool is_computed_name) {
1183 return PreParserExpression::Default(); 1188 return PreParserExpression::Default();
1184 } 1189 }
1185 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, 1190 PreParserExpression NewObjectLiteralProperty(PreParserExpression key,
1186 PreParserExpression value, 1191 PreParserExpression value,
1187 bool is_static, 1192 bool is_static,
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2381 2386
2382 template <class Traits> 2387 template <class Traits>
2383 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral( 2388 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral(
2384 ExpressionClassifier* classifier, bool* ok) { 2389 ExpressionClassifier* classifier, bool* ok) {
2385 // ArrayLiteral :: 2390 // ArrayLiteral ::
2386 // '[' Expression? (',' Expression?)* ']' 2391 // '[' Expression? (',' Expression?)* ']'
2387 2392
2388 int pos = peek_position(); 2393 int pos = peek_position();
2389 typename Traits::Type::ExpressionList values = 2394 typename Traits::Type::ExpressionList values =
2390 this->NewExpressionList(4, zone_); 2395 this->NewExpressionList(4, zone_);
2396 int first_spread_index = -1;
2391 Expect(Token::LBRACK, CHECK_OK); 2397 Expect(Token::LBRACK, CHECK_OK);
2392 while (peek() != Token::RBRACK) { 2398 while (peek() != Token::RBRACK) {
2393 bool seen_spread = false; 2399 bool seen_spread = false;
2394 ExpressionT elem = this->EmptyExpression(); 2400 ExpressionT elem = this->EmptyExpression();
2395 if (peek() == Token::COMMA) { 2401 if (peek() == Token::COMMA) {
2396 if (is_strong(language_mode())) { 2402 if (is_strong(language_mode())) {
2397 ReportMessageAt(scanner()->peek_location(), 2403 ReportMessageAt(scanner()->peek_location(),
2398 MessageTemplate::kStrongEllision); 2404 MessageTemplate::kStrongEllision);
2399 *ok = false; 2405 *ok = false;
2400 return this->EmptyExpression(); 2406 return this->EmptyExpression();
2401 } 2407 }
2402 elem = this->GetLiteralTheHole(peek_position(), factory()); 2408 elem = this->GetLiteralTheHole(peek_position(), factory());
2403 } else if (peek() == Token::ELLIPSIS) { 2409 } else if (peek() == Token::ELLIPSIS) {
2404 if (!allow_harmony_spread_arrays()) { 2410 if (!allow_harmony_spread_arrays()) {
2405 ExpressionUnexpectedToken(classifier); 2411 ExpressionUnexpectedToken(classifier);
2406 } 2412 }
2407 int start_pos = peek_position(); 2413 int start_pos = peek_position();
2408 Consume(Token::ELLIPSIS); 2414 Consume(Token::ELLIPSIS);
2409 ExpressionT argument = 2415 ExpressionT argument =
2410 this->ParseAssignmentExpression(true, classifier, CHECK_OK); 2416 this->ParseAssignmentExpression(true, classifier, CHECK_OK);
2411 elem = factory()->NewSpread(argument, start_pos); 2417 elem = factory()->NewSpread(argument, start_pos);
2412 seen_spread = true; 2418 seen_spread = true;
2419 if (first_spread_index < 0) {
2420 first_spread_index = values->length();
2421 }
2413 } else { 2422 } else {
2414 elem = this->ParseAssignmentExpression(true, classifier, CHECK_OK); 2423 elem = this->ParseAssignmentExpression(true, classifier, CHECK_OK);
2415 } 2424 }
2416 values->Add(elem, zone_); 2425 values->Add(elem, zone_);
2417 if (peek() != Token::RBRACK) { 2426 if (peek() != Token::RBRACK) {
2418 if (seen_spread) { 2427 if (seen_spread) {
2419 BindingPatternUnexpectedToken(classifier); 2428 BindingPatternUnexpectedToken(classifier);
2420 } 2429 }
2421 Expect(Token::COMMA, CHECK_OK); 2430 Expect(Token::COMMA, CHECK_OK);
2422 } 2431 }
2423 } 2432 }
2424 Expect(Token::RBRACK, CHECK_OK); 2433 Expect(Token::RBRACK, CHECK_OK);
2425 2434
2426 // Update the scope information before the pre-parsing bailout. 2435 // Update the scope information before the pre-parsing bailout.
2427 int literal_index = function_state_->NextMaterializedLiteralIndex(); 2436 int literal_index = function_state_->NextMaterializedLiteralIndex();
2428 2437
2429 return factory()->NewArrayLiteral(values, literal_index, 2438 return factory()->NewArrayLiteral(values, first_spread_index, literal_index,
2430 is_strong(language_mode()), pos); 2439 is_strong(language_mode()), pos);
2431 } 2440 }
2432 2441
2433 2442
2434 template <class Traits> 2443 template <class Traits>
2435 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( 2444 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
2436 IdentifierT* name, bool* is_get, bool* is_set, bool* is_static, 2445 IdentifierT* name, bool* is_get, bool* is_set, bool* is_static,
2437 bool* is_computed_name, ExpressionClassifier* classifier, bool* ok) { 2446 bool* is_computed_name, ExpressionClassifier* classifier, bool* ok) {
2438 Token::Value token = peek(); 2447 Token::Value token = peek();
2439 int pos = peek_position(); 2448 int pos = peek_position();
(...skipping 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after
3980 *ok = false; 3989 *ok = false;
3981 return; 3990 return;
3982 } 3991 }
3983 has_seen_constructor_ = true; 3992 has_seen_constructor_ = true;
3984 return; 3993 return;
3985 } 3994 }
3986 } 3995 }
3987 } } // v8::internal 3996 } } // v8::internal
3988 3997
3989 #endif // V8_PREPARSER_H 3998 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/ast.cc ('k') | test/mjsunit/harmony/regress/regress-4298.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698