Chromium Code Reviews| 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 2513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2524 bool first_declaration = true; | 2524 bool first_declaration = true; |
| 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 bool is_pattern = false; | |
|
rossberg
2015/11/04 10:52:35
Nit: declare this after the block and initialise d
| |
| 2535 int decl_pos = peek_position(); | |
| 2534 { | 2536 { |
| 2535 ExpressionClassifier pattern_classifier; | 2537 ExpressionClassifier pattern_classifier; |
| 2536 Token::Value next = peek(); | 2538 Token::Value next = peek(); |
| 2537 pattern = ParsePrimaryExpression(&pattern_classifier, ok); | 2539 pattern = ParsePrimaryExpression(&pattern_classifier, ok); |
| 2538 if (!*ok) return; | 2540 if (!*ok) return; |
| 2539 ValidateBindingPattern(&pattern_classifier, ok); | 2541 ValidateBindingPattern(&pattern_classifier, ok); |
| 2540 if (!*ok) return; | 2542 if (!*ok) return; |
| 2541 if (IsLexicalVariableMode(parsing_result->descriptor.mode)) { | 2543 if (IsLexicalVariableMode(parsing_result->descriptor.mode)) { |
| 2542 ValidateLetPattern(&pattern_classifier, ok); | 2544 ValidateLetPattern(&pattern_classifier, ok); |
| 2543 if (!*ok) return; | 2545 if (!*ok) return; |
| 2544 } | 2546 } |
| 2545 if (!allow_harmony_destructuring() && !pattern->IsVariableProxy()) { | 2547 if (!allow_harmony_destructuring() && !pattern->IsVariableProxy()) { |
| 2546 ReportUnexpectedToken(next); | 2548 ReportUnexpectedToken(next); |
| 2547 *ok = false; | 2549 *ok = false; |
| 2548 return; | 2550 return; |
| 2549 } | 2551 } |
| 2552 is_pattern = pattern->IsObjectLiteral() || pattern->IsArrayLiteral(); | |
| 2550 } | 2553 } |
| 2551 | 2554 |
| 2552 Scanner::Location variable_loc = scanner()->location(); | 2555 Scanner::Location variable_loc = scanner()->location(); |
| 2553 const AstRawString* single_name = | 2556 const AstRawString* single_name = |
| 2554 pattern->IsVariableProxy() ? pattern->AsVariableProxy()->raw_name() | 2557 pattern->IsVariableProxy() ? pattern->AsVariableProxy()->raw_name() |
| 2555 : nullptr; | 2558 : nullptr; |
| 2556 if (single_name != nullptr) { | 2559 if (single_name != nullptr) { |
| 2557 if (fni_ != NULL) fni_->PushVariableName(single_name); | 2560 if (fni_ != NULL) fni_->PushVariableName(single_name); |
| 2558 } | 2561 } |
| 2559 | 2562 |
| 2560 is_for_iteration_variable = | 2563 is_for_iteration_variable = |
| 2561 var_context == kForStatement && | 2564 var_context == kForStatement && |
| 2562 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of"))); | 2565 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of"))); |
| 2563 if (is_for_iteration_variable && | 2566 if (is_for_iteration_variable && |
| 2564 (parsing_result->descriptor.mode == CONST || | 2567 (parsing_result->descriptor.mode == CONST || |
| 2565 parsing_result->descriptor.mode == CONST_LEGACY)) { | 2568 parsing_result->descriptor.mode == CONST_LEGACY)) { |
| 2566 parsing_result->descriptor.needs_init = false; | 2569 parsing_result->descriptor.needs_init = false; |
| 2567 } | 2570 } |
| 2568 | 2571 |
| 2569 Expression* value = NULL; | 2572 Expression* value = NULL; |
| 2570 // Harmony consts have non-optional initializers. | 2573 // Harmony consts have non-optional initializers. |
| 2571 int initializer_position = RelocInfo::kNoPosition; | 2574 int initializer_position = RelocInfo::kNoPosition; |
| 2572 if (peek() == Token::ASSIGN || (parsing_result->descriptor.mode == CONST && | 2575 if (peek() == Token::ASSIGN || |
| 2573 !is_for_iteration_variable)) { | 2576 ((parsing_result->descriptor.mode == CONST || is_pattern) && |
|
rossberg
2015/11/04 10:52:35
Why not test these in the else branch and move the
caitp (gmail)
2015/11/04 15:07:28
I think I've done what you're asking for here ---
| |
| 2574 Expect(Token::ASSIGN, ok); | 2577 !is_for_iteration_variable)) { |
| 2575 if (!*ok) return; | 2578 if (peek() != Token::ASSIGN) { |
|
adamk
2015/11/04 00:37:54
You can also consume here to avoid mentioning ASSI
caitp (gmail)
2015/11/04 00:50:02
Yeah, it messes up the positioning a bit if i do t
adamk
2015/11/04 00:55:10
Ah, right, feel free to leave as-is.
| |
| 2579 ParserTraits::ReportMessageAt( | |
| 2580 Scanner::Location(decl_pos, scanner()->location().end_pos), | |
|
adamk
2015/11/04 00:37:54
I'm not sure this location makes any more sense th
caitp (gmail)
2015/11/04 00:50:02
If the devtools actually showed the positions, I'd
adamk
2015/11/04 00:55:10
I too have been wondering why devtools doesn't sho
| |
| 2581 MessageTemplate::kDeclarationMissingInitializer, | |
| 2582 is_pattern ? "destructuring" : "const"); | |
| 2583 *ok = false; | |
| 2584 return; | |
| 2585 } | |
| 2586 Consume(Token::ASSIGN); | |
| 2576 ExpressionClassifier classifier; | 2587 ExpressionClassifier classifier; |
| 2577 value = ParseAssignmentExpression(var_context != kForStatement, | 2588 value = ParseAssignmentExpression(var_context != kForStatement, |
| 2578 &classifier, ok); | 2589 &classifier, ok); |
| 2579 if (!*ok) return; | 2590 if (!*ok) return; |
| 2580 ValidateExpression(&classifier, ok); | 2591 ValidateExpression(&classifier, ok); |
| 2581 if (!*ok) return; | 2592 if (!*ok) return; |
| 2582 variable_loc.end_pos = scanner()->location().end_pos; | 2593 variable_loc.end_pos = scanner()->location().end_pos; |
| 2583 | 2594 |
| 2584 if (!parsing_result->first_initializer_loc.IsValid()) { | 2595 if (!parsing_result->first_initializer_loc.IsValid()) { |
| 2585 parsing_result->first_initializer_loc = variable_loc; | 2596 parsing_result->first_initializer_loc = variable_loc; |
| (...skipping 3795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6381 | 6392 |
| 6382 Expression* Parser::SpreadCallNew(Expression* function, | 6393 Expression* Parser::SpreadCallNew(Expression* function, |
| 6383 ZoneList<v8::internal::Expression*>* args, | 6394 ZoneList<v8::internal::Expression*>* args, |
| 6384 int pos) { | 6395 int pos) { |
| 6385 args->InsertAt(0, function, zone()); | 6396 args->InsertAt(0, function, zone()); |
| 6386 | 6397 |
| 6387 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6398 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
| 6388 } | 6399 } |
| 6389 } // namespace internal | 6400 } // namespace internal |
| 6390 } // namespace v8 | 6401 } // namespace v8 |
| OLD | NEW |