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

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

Issue 1139773005: [destructuring] More tests for object literal pattern (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comments addressed, landing Created 5 years, 7 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.h" 5 #include "src/ast.h"
6 #include "src/messages.h" 6 #include "src/messages.h"
7 #include "src/parser.h" 7 #include "src/parser.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 10
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 Assignment* assignment = factory()->NewAssignment( 202 Assignment* assignment = factory()->NewAssignment(
203 descriptor_->init_op, proxy, value, descriptor_->pos); 203 descriptor_->init_op, proxy, value, descriptor_->pos);
204 block_->AddStatement( 204 block_->AddStatement(
205 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), 205 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition),
206 zone()); 206 zone());
207 } 207 }
208 } 208 }
209 209
210 210
211 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern) { 211 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern) {
212 auto temp = descriptor_->declaration_scope->NewTemporary( 212 auto temp = TemporaryDeclarationScope()->NewTemporary(
213 ast_value_factory()->empty_string()); 213 ast_value_factory()->empty_string());
214 auto assignment = 214 auto assignment =
215 factory()->NewAssignment(Token::ASSIGN, factory()->NewVariableProxy(temp), 215 factory()->NewAssignment(Token::ASSIGN, factory()->NewVariableProxy(temp),
216 current_value_, RelocInfo::kNoPosition); 216 current_value_, RelocInfo::kNoPosition);
217
217 block_->AddStatement( 218 block_->AddStatement(
218 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), 219 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition),
219 zone()); 220 zone());
221
222 if (pattern->properties()->length() == 0) {
223 block_->AddStatement(descriptor_->parser->BuildAssertIsCoercible(temp),
224 zone());
225 }
226
220 for (ObjectLiteralProperty* property : *pattern->properties()) { 227 for (ObjectLiteralProperty* property : *pattern->properties()) {
221 // TODO(dslomov): computed property names. 228 // TODO(dslomov): computed property names.
222 RecurseIntoSubpattern( 229 RecurseIntoSubpattern(
223 property->value(), 230 property->value(),
224 factory()->NewProperty(factory()->NewVariableProxy(temp), 231 factory()->NewProperty(factory()->NewVariableProxy(temp),
225 property->key(), RelocInfo::kNoPosition)); 232 property->key(), RelocInfo::kNoPosition));
226 } 233 }
227 } 234 }
228 235
229 236
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 NOT_A_PATTERN(TryFinallyStatement) 295 NOT_A_PATTERN(TryFinallyStatement)
289 NOT_A_PATTERN(UnaryOperation) 296 NOT_A_PATTERN(UnaryOperation)
290 NOT_A_PATTERN(VariableDeclaration) 297 NOT_A_PATTERN(VariableDeclaration)
291 NOT_A_PATTERN(WhileStatement) 298 NOT_A_PATTERN(WhileStatement)
292 NOT_A_PATTERN(WithStatement) 299 NOT_A_PATTERN(WithStatement)
293 NOT_A_PATTERN(Yield) 300 NOT_A_PATTERN(Yield)
294 301
295 #undef NOT_A_PATTERN 302 #undef NOT_A_PATTERN
296 } 303 }
297 } // namespace v8::internal 304 } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698