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 #include "src/parser.h" | 5 #include "src/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/ast-literal-reindexer.h" | 9 #include "src/ast-literal-reindexer.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 2514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2525 int bindings_start = peek_position(); | 2525 int bindings_start = peek_position(); |
2526 bool is_for_iteration_variable; | 2526 bool is_for_iteration_variable; |
2527 do { | 2527 do { |
2528 if (fni_ != NULL) fni_->Enter(); | 2528 if (fni_ != NULL) fni_->Enter(); |
2529 | 2529 |
2530 // Parse name. | 2530 // Parse name. |
2531 if (!first_declaration) Consume(Token::COMMA); | 2531 if (!first_declaration) Consume(Token::COMMA); |
2532 | 2532 |
2533 Expression* pattern; | 2533 Expression* pattern; |
2534 { | 2534 { |
2535 int decl_pos = peek_position(); | |
2535 ExpressionClassifier pattern_classifier; | 2536 ExpressionClassifier pattern_classifier; |
2536 Token::Value next = peek(); | 2537 Token::Value next = peek(); |
2537 pattern = ParsePrimaryExpression(&pattern_classifier, ok); | 2538 pattern = ParsePrimaryExpression(&pattern_classifier, ok); |
2538 if (!*ok) return; | 2539 if (!*ok) return; |
2539 ValidateBindingPattern(&pattern_classifier, ok); | 2540 ValidateBindingPattern(&pattern_classifier, ok); |
2540 if (!*ok) return; | 2541 if (!*ok) return; |
2541 if (IsLexicalVariableMode(parsing_result->descriptor.mode)) { | 2542 if (IsLexicalVariableMode(parsing_result->descriptor.mode)) { |
2542 ValidateLetPattern(&pattern_classifier, ok); | 2543 ValidateLetPattern(&pattern_classifier, ok); |
2543 if (!*ok) return; | 2544 if (!*ok) return; |
2544 } | 2545 } |
2545 if (!allow_harmony_destructuring() && !pattern->IsVariableProxy()) { | 2546 if (!allow_harmony_destructuring() && !pattern->IsVariableProxy()) { |
2546 ReportUnexpectedToken(next); | 2547 ReportUnexpectedToken(next); |
2547 *ok = false; | 2548 *ok = false; |
2548 return; | 2549 return; |
2549 } | 2550 } |
2551 | |
2552 is_for_iteration_variable = | |
2553 var_context == kForStatement && | |
2554 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of"))); | |
2555 | |
2556 if (!is_for_iteration_variable && | |
2557 (pattern->IsObjectLiteral() || pattern->IsArrayLiteral()) && | |
2558 peek() != Token::ASSIGN) { | |
2559 ReportMessageAt( | |
2560 Scanner::Location(decl_pos, scanner()->location().end_pos), | |
2561 MessageTemplate::kInvalidDestructuringDeclaration); | |
2562 *ok = false; | |
2563 return; | |
2564 } | |
2550 } | 2565 } |
2551 | 2566 |
2552 Scanner::Location variable_loc = scanner()->location(); | 2567 Scanner::Location variable_loc = scanner()->location(); |
2553 const AstRawString* single_name = | 2568 const AstRawString* single_name = |
2554 pattern->IsVariableProxy() ? pattern->AsVariableProxy()->raw_name() | 2569 pattern->IsVariableProxy() ? pattern->AsVariableProxy()->raw_name() |
2555 : nullptr; | 2570 : nullptr; |
2556 if (single_name != nullptr) { | 2571 if (single_name != nullptr) { |
2557 if (fni_ != NULL) fni_->PushVariableName(single_name); | 2572 if (fni_ != NULL) fni_->PushVariableName(single_name); |
2558 } | 2573 } |
2559 | 2574 |
2560 is_for_iteration_variable = | 2575 is_for_iteration_variable = |
2561 var_context == kForStatement && | 2576 var_context == kForStatement && |
2562 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of"))); | 2577 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of"))); |
2563 if (is_for_iteration_variable && | 2578 if (is_for_iteration_variable && |
2564 (parsing_result->descriptor.mode == CONST || | 2579 (parsing_result->descriptor.mode == CONST || |
2565 parsing_result->descriptor.mode == CONST_LEGACY)) { | 2580 parsing_result->descriptor.mode == CONST_LEGACY)) { |
2566 parsing_result->descriptor.needs_init = false; | 2581 parsing_result->descriptor.needs_init = false; |
2567 } | 2582 } |
2568 | 2583 |
2569 Expression* value = NULL; | 2584 Expression* value = NULL; |
2570 // Harmony consts have non-optional initializers. | 2585 // Harmony consts have non-optional initializers. |
2571 int initializer_position = RelocInfo::kNoPosition; | 2586 int initializer_position = RelocInfo::kNoPosition; |
2572 if (peek() == Token::ASSIGN || (parsing_result->descriptor.mode == CONST && | 2587 if (peek() == Token::ASSIGN || (parsing_result->descriptor.mode == CONST && |
adamk
2015/11/03 20:13:53
This if statement is already set up for handling t
caitp (gmail)
2015/11/03 23:55:31
Done.
| |
2573 !is_for_iteration_variable)) { | 2588 !is_for_iteration_variable)) { |
2574 Expect(Token::ASSIGN, ok); | 2589 Expect(Token::ASSIGN, ok); |
2575 if (!*ok) return; | 2590 if (!*ok) return; |
2576 ExpressionClassifier classifier; | 2591 ExpressionClassifier classifier; |
2577 value = ParseAssignmentExpression(var_context != kForStatement, | 2592 value = ParseAssignmentExpression(var_context != kForStatement, |
2578 &classifier, ok); | 2593 &classifier, ok); |
2579 if (!*ok) return; | 2594 if (!*ok) return; |
2580 ValidateExpression(&classifier, ok); | 2595 ValidateExpression(&classifier, ok); |
2581 if (!*ok) return; | 2596 if (!*ok) return; |
2582 variable_loc.end_pos = scanner()->location().end_pos; | 2597 variable_loc.end_pos = scanner()->location().end_pos; |
(...skipping 3798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6381 | 6396 |
6382 Expression* Parser::SpreadCallNew(Expression* function, | 6397 Expression* Parser::SpreadCallNew(Expression* function, |
6383 ZoneList<v8::internal::Expression*>* args, | 6398 ZoneList<v8::internal::Expression*>* args, |
6384 int pos) { | 6399 int pos) { |
6385 args->InsertAt(0, function, zone()); | 6400 args->InsertAt(0, function, zone()); |
6386 | 6401 |
6387 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6402 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6388 } | 6403 } |
6389 } // namespace internal | 6404 } // namespace internal |
6390 } // namespace v8 | 6405 } // namespace v8 |
OLD | NEW |