OLD | NEW |
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/parser.h" | 6 #include "src/parser.h" |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 | 9 |
10 namespace internal { | 10 namespace internal { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 Assignment* assignment = factory()->NewAssignment( | 201 Assignment* assignment = factory()->NewAssignment( |
202 descriptor_->init_op, proxy, value, descriptor_->pos); | 202 descriptor_->init_op, proxy, value, descriptor_->pos); |
203 block_->AddStatement( | 203 block_->AddStatement( |
204 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), | 204 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), |
205 zone()); | 205 zone()); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 | 209 |
210 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern) { | 210 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern) { |
211 auto temp = descriptor_->declaration_scope->NewTemporary( | 211 auto temp = TemporaryDeclarationScope()->NewTemporary( |
212 ast_value_factory()->empty_string()); | 212 ast_value_factory()->empty_string()); |
213 auto assignment = | 213 auto assignment = |
214 factory()->NewAssignment(Token::ASSIGN, factory()->NewVariableProxy(temp), | 214 factory()->NewAssignment(Token::ASSIGN, factory()->NewVariableProxy(temp), |
215 current_value_, RelocInfo::kNoPosition); | 215 current_value_, RelocInfo::kNoPosition); |
| 216 |
216 block_->AddStatement( | 217 block_->AddStatement( |
217 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), | 218 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), |
218 zone()); | 219 zone()); |
| 220 |
| 221 if (pattern->properties()->length() == 0) { |
| 222 block_->AddStatement(descriptor_->parser->BuildAssertIsCoercible(temp), |
| 223 zone()); |
| 224 } |
| 225 |
219 for (ObjectLiteralProperty* property : *pattern->properties()) { | 226 for (ObjectLiteralProperty* property : *pattern->properties()) { |
220 // TODO(dslomov): computed property names. | 227 // TODO(dslomov): computed property names. |
221 RecurseIntoSubpattern( | 228 RecurseIntoSubpattern( |
222 property->value(), | 229 property->value(), |
223 factory()->NewProperty(factory()->NewVariableProxy(temp), | 230 factory()->NewProperty(factory()->NewVariableProxy(temp), |
224 property->key(), RelocInfo::kNoPosition)); | 231 property->key(), RelocInfo::kNoPosition)); |
225 } | 232 } |
226 } | 233 } |
227 | 234 |
228 | 235 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 NOT_A_PATTERN(TryFinallyStatement) | 294 NOT_A_PATTERN(TryFinallyStatement) |
288 NOT_A_PATTERN(UnaryOperation) | 295 NOT_A_PATTERN(UnaryOperation) |
289 NOT_A_PATTERN(VariableDeclaration) | 296 NOT_A_PATTERN(VariableDeclaration) |
290 NOT_A_PATTERN(WhileStatement) | 297 NOT_A_PATTERN(WhileStatement) |
291 NOT_A_PATTERN(WithStatement) | 298 NOT_A_PATTERN(WithStatement) |
292 NOT_A_PATTERN(Yield) | 299 NOT_A_PATTERN(Yield) |
293 | 300 |
294 #undef NOT_A_PATTERN | 301 #undef NOT_A_PATTERN |
295 } | 302 } |
296 } // namespace v8::internal | 303 } // namespace v8::internal |
OLD | NEW |