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

Side by Side Diff: src/parser.cc

Issue 1385913003: Fix legacy const for-of/in destructuring (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | test/mjsunit/harmony/destructuring.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 #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 2535 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 const AstRawString* single_name = 2546 const AstRawString* single_name =
2547 pattern->IsVariableProxy() ? pattern->AsVariableProxy()->raw_name() 2547 pattern->IsVariableProxy() ? pattern->AsVariableProxy()->raw_name()
2548 : nullptr; 2548 : nullptr;
2549 if (single_name != nullptr) { 2549 if (single_name != nullptr) {
2550 if (fni_ != NULL) fni_->PushVariableName(single_name); 2550 if (fni_ != NULL) fni_->PushVariableName(single_name);
2551 } 2551 }
2552 2552
2553 is_for_iteration_variable = 2553 is_for_iteration_variable =
2554 var_context == kForStatement && 2554 var_context == kForStatement &&
2555 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of"))); 2555 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of")));
2556 if (is_for_iteration_variable && parsing_result->descriptor.mode == CONST) { 2556 if (is_for_iteration_variable && parsing_result->descriptor.mode == CONST) {
adamk 2015/10/05 20:13:19 Could you fix this here instead, by resetting need
2557 parsing_result->descriptor.needs_init = false; 2557 parsing_result->descriptor.needs_init = false;
2558 } 2558 }
2559 2559
2560 Expression* value = NULL; 2560 Expression* value = NULL;
2561 // Harmony consts have non-optional initializers. 2561 // Harmony consts have non-optional initializers.
2562 int initializer_position = RelocInfo::kNoPosition; 2562 int initializer_position = RelocInfo::kNoPosition;
2563 if (peek() == Token::ASSIGN || (parsing_result->descriptor.mode == CONST && 2563 if (peek() == Token::ASSIGN || (parsing_result->descriptor.mode == CONST &&
2564 !is_for_iteration_variable)) { 2564 !is_for_iteration_variable)) {
2565 Expect(Token::ASSIGN, ok); 2565 Expect(Token::ASSIGN, ok);
2566 if (!*ok) return; 2566 if (!*ok) return;
(...skipping 19 matching lines...) Expand all
2586 } 2586 }
2587 } 2587 }
2588 // End position of the initializer is after the assignment expression. 2588 // End position of the initializer is after the assignment expression.
2589 initializer_position = scanner()->location().end_pos; 2589 initializer_position = scanner()->location().end_pos;
2590 } else { 2590 } else {
2591 // End position of the initializer is after the variable. 2591 // End position of the initializer is after the variable.
2592 initializer_position = position(); 2592 initializer_position = position();
2593 } 2593 }
2594 2594
2595 // Make sure that 'const x' and 'let x' initialize 'x' to undefined. 2595 // Make sure that 'const x' and 'let x' initialize 'x' to undefined.
2596 if (value == NULL && parsing_result->descriptor.needs_init) { 2596 // If in a for-of/in loop, no need to initialize here.
2597 if (value == NULL && parsing_result->descriptor.needs_init &&
2598 !is_for_iteration_variable) {
2597 value = GetLiteralUndefined(position()); 2599 value = GetLiteralUndefined(position());
2598 } 2600 }
2599 2601
2600 if (single_name && fni_ != NULL) fni_->Leave(); 2602 if (single_name && fni_ != NULL) fni_->Leave();
2601 parsing_result->declarations.Add(DeclarationParsingResult::Declaration( 2603 parsing_result->declarations.Add(DeclarationParsingResult::Declaration(
2602 pattern, initializer_position, value)); 2604 pattern, initializer_position, value));
2603 first_declaration = false; 2605 first_declaration = false;
2604 } while (peek() == Token::COMMA); 2606 } while (peek() == Token::COMMA);
2605 2607
2606 parsing_result->bindings_loc = 2608 parsing_result->bindings_loc =
(...skipping 3712 matching lines...) Expand 10 before | Expand all | Expand 10 after
6319 6321
6320 Expression* Parser::SpreadCallNew(Expression* function, 6322 Expression* Parser::SpreadCallNew(Expression* function,
6321 ZoneList<v8::internal::Expression*>* args, 6323 ZoneList<v8::internal::Expression*>* args,
6322 int pos) { 6324 int pos) {
6323 args->InsertAt(0, function, zone()); 6325 args->InsertAt(0, function, zone());
6324 6326
6325 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6327 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6326 } 6328 }
6327 } // namespace internal 6329 } // namespace internal
6328 } // namespace v8 6330 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/destructuring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698