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

Side by Side Diff: src/parsing/pattern-rewriter.cc

Issue 2620943002: [ESnext] Implement Object Rest (Closed)
Patch Set: Remove comment Created 3 years, 11 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/ast/ast.h" 5 #include "src/ast/ast.h"
6 #include "src/messages.h" 6 #include "src/messages.h"
7 #include "src/objects-inl.h" 7 #include "src/objects-inl.h"
8 #include "src/parsing/parameter-initializer-rewriter.h" 8 #include "src/parsing/parameter-initializer-rewriter.h"
9 #include "src/parsing/parser.h" 9 #include "src/parsing/parser.h"
10 10
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 DCHECK(scope()->outer_scope()->is_function_scope()); 325 DCHECK(scope()->outer_scope()->is_function_scope());
326 DCHECK(scope()->calls_sloppy_eval()); 326 DCHECK(scope()->calls_sloppy_eval());
327 327
328 ReparentParameterExpressionScope(parser_->stack_limit(), expr, scope()); 328 ReparentParameterExpressionScope(parser_->stack_limit(), expr, scope());
329 } 329 }
330 330
331 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern, 331 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern,
332 Variable** temp_var) { 332 Variable** temp_var) {
333 auto temp = *temp_var = CreateTempVar(current_value_); 333 auto temp = *temp_var = CreateTempVar(current_value_);
334 334
335 ZoneList<Expression*>* excluded_properties;
336 if (pattern->has_rest_property()) {
337 int non_rest_properties = pattern->properties()->length() - 1;
338 excluded_properties =
339 new (zone()) ZoneList<Expression*>(non_rest_properties, zone());
340 } else {
341 excluded_properties = new (zone()) ZoneList<Expression*>(0, zone());
342 }
343
335 block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone()); 344 block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone());
336 345
337 for (ObjectLiteralProperty* property : *pattern->properties()) { 346 for (ObjectLiteralProperty* property : *pattern->properties()) {
338 PatternContext context = SetInitializerContextIfNeeded(property->value()); 347 PatternContext context = SetInitializerContextIfNeeded(property->value());
348 Expression* value;
339 349
340 // Computed property names contain expressions which might require 350 if (property->kind() == ObjectLiteralProperty::Kind::SPREAD) {
341 // scope rewriting. 351 // var { a, b, ...c } = temp
342 if (!property->key()->IsLiteral()) RewriteParameterScopes(property->key()); 352 // becomes
353 // var c;
354 // c = %CopyDataProperties(temp, [a, b]);
adamk 2017/01/10 23:22:56 Can you add something about the desugaring of comp
gsathya 2017/01/12 21:27:41 There's a comment below where I handle the compute
adamk 2017/01/12 22:43:08 Yeah, I was thinking that this should basically re
355 auto args = new (zone()) ZoneList<Expression*>(2, zone());
356 args->Add(factory()->NewVariableProxy(temp), zone());
357 args->Add(
358 factory()->NewArrayLiteral(
359 excluded_properties, pattern->literal_index(), kNoSourcePosition),
360 zone());
343 361
344 RecurseIntoSubpattern( 362 value = factory()->NewCallRuntime(
345 property->value(), 363 Runtime::kCopyDataPropertiesWithExcludedProperties, args,
346 factory()->NewProperty(factory()->NewVariableProxy(temp), 364 kNoSourcePosition);
347 property->key(), kNoSourcePosition)); 365 } else {
366 Expression* key = property->key();
367
368 if (!key->IsLiteral()) {
369 // Computed property names contain expressions which might require
370 // scope rewriting.
371 RewriteParameterScopes(key);
372
373 // We create a temporary variable for a computed property name
374 // so that we don't evaluate it twice when we include it in
375 // the excluded_properties list.
376 key = factory()->NewVariableProxy(CreateTempVar(key));
adamk 2017/01/10 23:22:56 You need to assign CreateTempVar to something so t
gsathya 2017/01/12 21:27:41 Done.
377 }
378
379 if (pattern->has_rest_property()) {
380 excluded_properties->Add(key, zone());
adamk 2017/01/10 23:22:56 As noted above, this needs to be a NewVariableProx
gsathya 2017/01/12 21:27:41 Done.
381 }
382
383 value = factory()->NewProperty(factory()->NewVariableProxy(temp), key,
384 kNoSourcePosition);
385 }
386
387 RecurseIntoSubpattern(property->value(), value);
348 set_context(context); 388 set_context(context);
349 } 389 }
350 } 390 }
351 391
352 392
353 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* node) { 393 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* node) {
354 Variable* temp_var = nullptr; 394 Variable* temp_var = nullptr;
355 VisitObjectLiteral(node, &temp_var); 395 VisitObjectLiteral(node, &temp_var);
356 } 396 }
357 397
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 NOT_A_PATTERN(TryFinallyStatement) 732 NOT_A_PATTERN(TryFinallyStatement)
693 NOT_A_PATTERN(UnaryOperation) 733 NOT_A_PATTERN(UnaryOperation)
694 NOT_A_PATTERN(VariableDeclaration) 734 NOT_A_PATTERN(VariableDeclaration)
695 NOT_A_PATTERN(WhileStatement) 735 NOT_A_PATTERN(WhileStatement)
696 NOT_A_PATTERN(WithStatement) 736 NOT_A_PATTERN(WithStatement)
697 NOT_A_PATTERN(Yield) 737 NOT_A_PATTERN(Yield)
698 738
699 #undef NOT_A_PATTERN 739 #undef NOT_A_PATTERN
700 } // namespace internal 740 } // namespace internal
701 } // namespace v8 741 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698