Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 #include <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #include "src/allocation.h" | 7 #include "src/allocation.h" |
| 8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
| 9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
| 10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 // The ES6 Draft Rev3 specifies the following grammar for const declarations | 524 // The ES6 Draft Rev3 specifies the following grammar for const declarations |
| 525 // | 525 // |
| 526 // ConstDeclaration :: | 526 // ConstDeclaration :: |
| 527 // const ConstBinding (',' ConstBinding)* ';' | 527 // const ConstBinding (',' ConstBinding)* ';' |
| 528 // ConstBinding :: | 528 // ConstBinding :: |
| 529 // Identifier '=' AssignmentExpression | 529 // Identifier '=' AssignmentExpression |
| 530 // | 530 // |
| 531 // TODO(ES6): | 531 // TODO(ES6): |
| 532 // ConstBinding :: | 532 // ConstBinding :: |
| 533 // BindingPattern '=' AssignmentExpression | 533 // BindingPattern '=' AssignmentExpression |
| 534 bool require_initializer = false; | 534 bool require_initializer = false; |
|
adamk
2015/11/03 20:13:53
Similarly (though sadly differently), this is alre
caitp (gmail)
2015/11/03 23:55:31
The preparser doesn't do an amazing job of trackin
| |
| 535 bool is_strict_const = false; | 535 bool is_strict_const = false; |
| 536 bool lexical = false; | 536 bool lexical = false; |
| 537 if (peek() == Token::VAR) { | 537 if (peek() == Token::VAR) { |
| 538 if (is_strong(language_mode())) { | 538 if (is_strong(language_mode())) { |
| 539 Scanner::Location location = scanner()->peek_location(); | 539 Scanner::Location location = scanner()->peek_location(); |
| 540 ReportMessageAt(location, MessageTemplate::kStrongVar); | 540 ReportMessageAt(location, MessageTemplate::kStrongVar); |
| 541 *ok = false; | 541 *ok = false; |
| 542 return Statement::Default(); | 542 return Statement::Default(); |
| 543 } | 543 } |
| 544 Consume(Token::VAR); | 544 Consume(Token::VAR); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 573 // The scope of a var/const declared variable anywhere inside a function | 573 // The scope of a var/const declared variable anywhere inside a function |
| 574 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope | 574 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope |
| 575 // of a let declared variable is the scope of the immediately enclosing | 575 // of a let declared variable is the scope of the immediately enclosing |
| 576 // block. | 576 // block. |
| 577 int nvars = 0; // the number of variables declared | 577 int nvars = 0; // the number of variables declared |
| 578 int bindings_start = peek_position(); | 578 int bindings_start = peek_position(); |
| 579 do { | 579 do { |
| 580 // Parse binding pattern. | 580 // Parse binding pattern. |
| 581 if (nvars > 0) Consume(Token::COMMA); | 581 if (nvars > 0) Consume(Token::COMMA); |
| 582 { | 582 { |
| 583 int decl_pos = peek_position(); | |
| 583 ExpressionClassifier pattern_classifier; | 584 ExpressionClassifier pattern_classifier; |
| 584 Token::Value next = peek(); | 585 Token::Value next = peek(); |
| 585 PreParserExpression pattern = | 586 PreParserExpression pattern = |
| 586 ParsePrimaryExpression(&pattern_classifier, CHECK_OK); | 587 ParsePrimaryExpression(&pattern_classifier, CHECK_OK); |
| 587 ValidateBindingPattern(&pattern_classifier, CHECK_OK); | 588 ValidateBindingPattern(&pattern_classifier, CHECK_OK); |
| 588 if (lexical) { | 589 if (lexical) { |
| 589 ValidateLetPattern(&pattern_classifier, CHECK_OK); | 590 ValidateLetPattern(&pattern_classifier, CHECK_OK); |
| 590 } | 591 } |
| 591 | 592 |
| 592 if (!allow_harmony_destructuring() && !pattern.IsIdentifier()) { | 593 if (!allow_harmony_destructuring() && !pattern.IsIdentifier()) { |
| 593 ReportUnexpectedToken(next); | 594 ReportUnexpectedToken(next); |
| 594 *ok = false; | 595 *ok = false; |
| 595 return Statement::Default(); | 596 return Statement::Default(); |
| 596 } | 597 } |
| 598 | |
| 599 bool is_for_iteration_variable = | |
| 600 var_context == kForStatement && | |
| 601 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of"))); | |
| 602 | |
| 603 if (!is_for_iteration_variable && | |
| 604 (pattern.IsObjectLiteral() || pattern.IsArrayLiteral()) && | |
| 605 peek() != Token::ASSIGN) { | |
| 606 ReportMessageAt( | |
| 607 Scanner::Location(decl_pos, scanner()->location().end_pos), | |
| 608 MessageTemplate::kInvalidDestructuringDeclaration); | |
| 609 *ok = false; | |
| 610 return Statement::Default(); | |
| 611 } | |
| 597 } | 612 } |
| 598 | 613 |
| 599 Scanner::Location variable_loc = scanner()->location(); | 614 Scanner::Location variable_loc = scanner()->location(); |
| 600 nvars++; | 615 nvars++; |
| 601 if (peek() == Token::ASSIGN || require_initializer || | 616 if (peek() == Token::ASSIGN || require_initializer || |
| 602 // require initializers for multiple consts. | 617 // require initializers for multiple consts. |
| 603 (is_strict_const && peek() == Token::COMMA)) { | 618 (is_strict_const && peek() == Token::COMMA)) { |
| 604 Expect(Token::ASSIGN, CHECK_OK); | 619 Expect(Token::ASSIGN, CHECK_OK); |
| 605 ExpressionClassifier classifier; | 620 ExpressionClassifier classifier; |
| 606 ParseAssignmentExpression(var_context != kForStatement, &classifier, | 621 ParseAssignmentExpression(var_context != kForStatement, &classifier, |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1254 Expect(Token::RBRACE, CHECK_OK); | 1269 Expect(Token::RBRACE, CHECK_OK); |
| 1255 return PreParserExpression::Default(); | 1270 return PreParserExpression::Default(); |
| 1256 } | 1271 } |
| 1257 } | 1272 } |
| 1258 | 1273 |
| 1259 #undef CHECK_OK | 1274 #undef CHECK_OK |
| 1260 | 1275 |
| 1261 | 1276 |
| 1262 } // namespace internal | 1277 } // namespace internal |
| 1263 } // namespace v8 | 1278 } // namespace v8 |
| OLD | NEW |