| 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/ast.h" | 5 #include "src/ast/ast.h" |
| 6 #include "src/messages.h" | 6 #include "src/messages.h" |
| 7 #include "src/parsing/parameter-initializer-rewriter.h" | 7 #include "src/parsing/parameter-initializer-rewriter.h" |
| 8 #include "src/parsing/parser.h" | 8 #include "src/parsing/parser.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 | 108 |
| 109 | 109 |
| 110 void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) { | 110 void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) { |
| 111 Expression* value = current_value_; | 111 Expression* value = current_value_; |
| 112 | 112 |
| 113 if (IsAssignmentContext()) { | 113 if (IsAssignmentContext()) { |
| 114 // In an assignment context, simply perform the assignment | 114 // In an assignment context, simply perform the assignment |
| 115 Assignment* assignment = factory()->NewAssignment( | 115 Assignment* assignment = factory()->NewAssignment( |
| 116 Token::ASSIGN, pattern, value, pattern->position()); | 116 Token::ASSIGN, pattern, value, pattern->position()); |
| 117 block_->statements()->Add( | 117 block_->statements()->push_back( |
| 118 factory()->NewExpressionStatement(assignment, pattern->position()), | 118 factory()->NewExpressionStatement(assignment, pattern->position())); |
| 119 zone()); | |
| 120 return; | 119 return; |
| 121 } | 120 } |
| 122 | 121 |
| 123 descriptor_->scope->RemoveUnresolved(pattern); | 122 descriptor_->scope->RemoveUnresolved(pattern); |
| 124 | 123 |
| 125 // Declare variable. | 124 // Declare variable. |
| 126 // Note that we *always* must treat the initial value via a separate init | 125 // Note that we *always* must treat the initial value via a separate init |
| 127 // assignment for variables and constants because the value must be assigned | 126 // assignment for variables and constants because the value must be assigned |
| 128 // when the variable is encountered in the source. But the variable/constant | 127 // when the variable is encountered in the source. But the variable/constant |
| 129 // is declared (and set to 'undefined') upon entering the function within | 128 // is declared (and set to 'undefined') upon entering the function within |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 arguments->Add( | 201 arguments->Add( |
| 203 factory()->NewStringLiteral(name, descriptor_->declaration_pos), | 202 factory()->NewStringLiteral(name, descriptor_->declaration_pos), |
| 204 zone()); | 203 zone()); |
| 205 arguments->Add(factory()->NewNumberLiteral(var_init_scope->language_mode(), | 204 arguments->Add(factory()->NewNumberLiteral(var_init_scope->language_mode(), |
| 206 kNoSourcePosition), | 205 kNoSourcePosition), |
| 207 zone()); | 206 zone()); |
| 208 arguments->Add(value, zone()); | 207 arguments->Add(value, zone()); |
| 209 | 208 |
| 210 CallRuntime* initialize = factory()->NewCallRuntime( | 209 CallRuntime* initialize = factory()->NewCallRuntime( |
| 211 Runtime::kInitializeVarGlobal, arguments, value->position()); | 210 Runtime::kInitializeVarGlobal, arguments, value->position()); |
| 212 block_->statements()->Add( | 211 block_->statements()->push_back( |
| 213 factory()->NewExpressionStatement(initialize, initialize->position()), | 212 factory()->NewExpressionStatement(initialize, initialize->position())); |
| 214 zone()); | |
| 215 } else { | 213 } else { |
| 216 // For 'let' and 'const' declared variables the initialization always | 214 // For 'let' and 'const' declared variables the initialization always |
| 217 // assigns to the declared variable. | 215 // assigns to the declared variable. |
| 218 // But for var declarations we need to do a new lookup. | 216 // But for var declarations we need to do a new lookup. |
| 219 if (descriptor_->mode == VAR) { | 217 if (descriptor_->mode == VAR) { |
| 220 proxy = var_init_scope->NewUnresolved(factory(), name); | 218 proxy = var_init_scope->NewUnresolved(factory(), name); |
| 221 } else { | 219 } else { |
| 222 DCHECK_NOT_NULL(proxy); | 220 DCHECK_NOT_NULL(proxy); |
| 223 DCHECK_NOT_NULL(proxy->var()); | 221 DCHECK_NOT_NULL(proxy->var()); |
| 224 } | 222 } |
| 225 // Add break location for destructured sub-pattern. | 223 // Add break location for destructured sub-pattern. |
| 226 int pos = IsSubPattern() ? pattern->position() : value->position(); | 224 int pos = IsSubPattern() ? pattern->position() : value->position(); |
| 227 Assignment* assignment = | 225 Assignment* assignment = |
| 228 factory()->NewAssignment(Token::INIT, proxy, value, pos); | 226 factory()->NewAssignment(Token::INIT, proxy, value, pos); |
| 229 block_->statements()->Add( | 227 block_->statements()->push_back( |
| 230 factory()->NewExpressionStatement(assignment, pos), zone()); | 228 factory()->NewExpressionStatement(assignment, pos)); |
| 231 } | 229 } |
| 232 } | 230 } |
| 233 | 231 |
| 234 | 232 |
| 235 Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) { | 233 Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) { |
| 236 auto temp = scope()->NewTemporary(ast_value_factory()->empty_string()); | 234 auto temp = scope()->NewTemporary(ast_value_factory()->empty_string()); |
| 237 if (value != nullptr) { | 235 if (value != nullptr) { |
| 238 auto assignment = factory()->NewAssignment( | 236 auto assignment = factory()->NewAssignment( |
| 239 Token::ASSIGN, factory()->NewVariableProxy(temp), value, | 237 Token::ASSIGN, factory()->NewVariableProxy(temp), value, |
| 240 kNoSourcePosition); | 238 kNoSourcePosition); |
| 241 | 239 |
| 242 block_->statements()->Add( | 240 block_->statements()->push_back( |
| 243 factory()->NewExpressionStatement(assignment, kNoSourcePosition), | 241 factory()->NewExpressionStatement(assignment, kNoSourcePosition)); |
| 244 zone()); | |
| 245 } | 242 } |
| 246 return temp; | 243 return temp; |
| 247 } | 244 } |
| 248 | 245 |
| 249 | 246 |
| 250 void Parser::PatternRewriter::VisitRewritableExpression( | 247 void Parser::PatternRewriter::VisitRewritableExpression( |
| 251 RewritableExpression* node) { | 248 RewritableExpression* node) { |
| 252 // If this is not a destructuring assignment... | 249 // If this is not a destructuring assignment... |
| 253 if (!IsAssignmentContext()) { | 250 if (!IsAssignmentContext()) { |
| 254 // Mark the node as rewritten to prevent redundant rewriting, and | 251 // Mark the node as rewritten to prevent redundant rewriting, and |
| (...skipping 24 matching lines...) Expand all Loading... |
| 279 Token::EQ_STRICT, factory()->NewVariableProxy(temp_var), | 276 Token::EQ_STRICT, factory()->NewVariableProxy(temp_var), |
| 280 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition); | 277 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition); |
| 281 value = factory()->NewConditional(is_undefined, initializer, | 278 value = factory()->NewConditional(is_undefined, initializer, |
| 282 factory()->NewVariableProxy(temp_var), | 279 factory()->NewVariableProxy(temp_var), |
| 283 kNoSourcePosition); | 280 kNoSourcePosition); |
| 284 } | 281 } |
| 285 | 282 |
| 286 PatternContext old_context = SetAssignmentContextIfNeeded(initializer); | 283 PatternContext old_context = SetAssignmentContextIfNeeded(initializer); |
| 287 int pos = assign->position(); | 284 int pos = assign->position(); |
| 288 Block* old_block = block_; | 285 Block* old_block = block_; |
| 289 block_ = factory()->NewBlock(nullptr, 8, true, pos); | 286 block_ = factory()->NewBlock(nullptr, true, pos); |
| 290 Variable* temp = nullptr; | 287 Variable* temp = nullptr; |
| 291 Expression* pattern = assign->target(); | 288 Expression* pattern = assign->target(); |
| 292 Expression* old_value = current_value_; | 289 Expression* old_value = current_value_; |
| 293 current_value_ = value; | 290 current_value_ = value; |
| 294 if (pattern->IsObjectLiteral()) { | 291 if (pattern->IsObjectLiteral()) { |
| 295 VisitObjectLiteral(pattern->AsObjectLiteral(), &temp); | 292 VisitObjectLiteral(pattern->AsObjectLiteral(), &temp); |
| 296 } else { | 293 } else { |
| 297 DCHECK(pattern->IsArrayLiteral()); | 294 DCHECK(pattern->IsArrayLiteral()); |
| 298 VisitArrayLiteral(pattern->AsArrayLiteral(), &temp); | 295 VisitArrayLiteral(pattern->AsArrayLiteral(), &temp); |
| 299 } | 296 } |
| 300 DCHECK_NOT_NULL(temp); | 297 DCHECK_NOT_NULL(temp); |
| 301 current_value_ = old_value; | 298 current_value_ = old_value; |
| 302 Expression* expr = factory()->NewDoExpression(block_, temp, pos); | 299 Expression* expr = factory()->NewDoExpression(block_, temp, pos); |
| 303 node->Rewrite(expr); | 300 node->Rewrite(expr); |
| 304 block_ = old_block; | 301 block_ = old_block; |
| 305 if (block_) { | 302 if (block_) { |
| 306 block_->statements()->Add(factory()->NewExpressionStatement(expr, pos), | 303 block_->statements()->push_back( |
| 307 zone()); | 304 factory()->NewExpressionStatement(expr, pos)); |
| 308 } | 305 } |
| 309 return set_context(old_context); | 306 return set_context(old_context); |
| 310 } | 307 } |
| 311 | 308 |
| 312 // When an extra declaration scope needs to be inserted to account for | 309 // When an extra declaration scope needs to be inserted to account for |
| 313 // a sloppy eval in a default parameter or function body, the expressions | 310 // a sloppy eval in a default parameter or function body, the expressions |
| 314 // needs to be in that new inner scope which was added after initial | 311 // needs to be in that new inner scope which was added after initial |
| 315 // parsing. | 312 // parsing. |
| 316 void Parser::PatternRewriter::RewriteParameterScopes(Expression* expr) { | 313 void Parser::PatternRewriter::RewriteParameterScopes(Expression* expr) { |
| 317 if (!IsBindingContext()) return; | 314 if (!IsBindingContext()) return; |
| 318 if (descriptor_->declaration_kind != DeclarationDescriptor::PARAMETER) return; | 315 if (descriptor_->declaration_kind != DeclarationDescriptor::PARAMETER) return; |
| 319 if (!scope()->is_block_scope()) return; | 316 if (!scope()->is_block_scope()) return; |
| 320 | 317 |
| 321 DCHECK(scope()->is_declaration_scope()); | 318 DCHECK(scope()->is_declaration_scope()); |
| 322 DCHECK(scope()->outer_scope()->is_function_scope()); | 319 DCHECK(scope()->outer_scope()->is_function_scope()); |
| 323 DCHECK(scope()->calls_sloppy_eval()); | 320 DCHECK(scope()->calls_sloppy_eval()); |
| 324 | 321 |
| 325 ReparentParameterExpressionScope(parser_->stack_limit(), expr, scope()); | 322 ReparentParameterExpressionScope(parser_->stack_limit(), expr, scope()); |
| 326 } | 323 } |
| 327 | 324 |
| 328 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern, | 325 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern, |
| 329 Variable** temp_var) { | 326 Variable** temp_var) { |
| 330 auto temp = *temp_var = CreateTempVar(current_value_); | 327 auto temp = *temp_var = CreateTempVar(current_value_); |
| 331 | 328 |
| 332 block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone()); | 329 block_->statements()->push_back(parser_->BuildAssertIsCoercible(temp)); |
| 333 | 330 |
| 334 for (ObjectLiteralProperty* property : *pattern->properties()) { | 331 for (ObjectLiteralProperty* property : *pattern->properties()) { |
| 335 PatternContext context = SetInitializerContextIfNeeded(property->value()); | 332 PatternContext context = SetInitializerContextIfNeeded(property->value()); |
| 336 | 333 |
| 337 // Computed property names contain expressions which might require | 334 // Computed property names contain expressions which might require |
| 338 // scope rewriting. | 335 // scope rewriting. |
| 339 if (!property->key()->IsLiteral()) RewriteParameterScopes(property->key()); | 336 if (!property->key()->IsLiteral()) RewriteParameterScopes(property->key()); |
| 340 | 337 |
| 341 RecurseIntoSubpattern( | 338 RecurseIntoSubpattern( |
| 342 property->value(), | 339 property->value(), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 366 auto v = CreateTempVar(); | 363 auto v = CreateTempVar(); |
| 367 auto completion = CreateTempVar(); | 364 auto completion = CreateTempVar(); |
| 368 auto nopos = kNoSourcePosition; | 365 auto nopos = kNoSourcePosition; |
| 369 | 366 |
| 370 // For the purpose of iterator finalization, we temporarily set block_ to a | 367 // For the purpose of iterator finalization, we temporarily set block_ to a |
| 371 // new block. In the main body of this function, we write to block_ (both | 368 // new block. In the main body of this function, we write to block_ (both |
| 372 // explicitly and implicitly via recursion). At the end of the function, we | 369 // explicitly and implicitly via recursion). At the end of the function, we |
| 373 // wrap this new block in a try-finally statement, restore block_ to its | 370 // wrap this new block in a try-finally statement, restore block_ to its |
| 374 // original value, and add the try-finally statement to block_. | 371 // original value, and add the try-finally statement to block_. |
| 375 auto target = block_; | 372 auto target = block_; |
| 376 block_ = factory()->NewBlock(nullptr, 8, true, nopos); | 373 block_ = factory()->NewBlock(nullptr, true, nopos); |
| 377 | 374 |
| 378 Spread* spread = nullptr; | 375 Spread* spread = nullptr; |
| 379 for (Expression* value : *node->values()) { | 376 for (Expression* value : *node->values()) { |
| 380 if (value->IsSpread()) { | 377 if (value->IsSpread()) { |
| 381 spread = value->AsSpread(); | 378 spread = value->AsSpread(); |
| 382 break; | 379 break; |
| 383 } | 380 } |
| 384 | 381 |
| 385 PatternContext context = SetInitializerContextIfNeeded(value); | 382 PatternContext context = SetInitializerContextIfNeeded(value); |
| 386 | 383 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 413 factory()->NewStringLiteral(ast_value_factory()->value_string(), | 410 factory()->NewStringLiteral(ast_value_factory()->value_string(), |
| 414 kNoSourcePosition), | 411 kNoSourcePosition), |
| 415 kNoSourcePosition), | 412 kNoSourcePosition), |
| 416 kNoSourcePosition); | 413 kNoSourcePosition); |
| 417 | 414 |
| 418 auto unset_done = factory()->NewAssignment( | 415 auto unset_done = factory()->NewAssignment( |
| 419 Token::ASSIGN, factory()->NewVariableProxy(done), | 416 Token::ASSIGN, factory()->NewVariableProxy(done), |
| 420 factory()->NewBooleanLiteral(false, kNoSourcePosition), | 417 factory()->NewBooleanLiteral(false, kNoSourcePosition), |
| 421 kNoSourcePosition); | 418 kNoSourcePosition); |
| 422 | 419 |
| 423 auto inner_else = | 420 auto inner_else = factory()->NewBlock(nullptr, true, kNoSourcePosition); |
| 424 factory()->NewBlock(nullptr, 2, true, kNoSourcePosition); | 421 inner_else->statements()->push_back( |
| 425 inner_else->statements()->Add( | 422 factory()->NewExpressionStatement(assign_value, nopos)); |
| 426 factory()->NewExpressionStatement(assign_value, nopos), zone()); | 423 inner_else->statements()->push_back( |
| 427 inner_else->statements()->Add( | 424 factory()->NewExpressionStatement(unset_done, nopos)); |
| 428 factory()->NewExpressionStatement(unset_done, nopos), zone()); | |
| 429 | 425 |
| 430 auto inner_if = factory()->NewIfStatement( | 426 auto inner_if = factory()->NewIfStatement( |
| 431 result_done, | 427 result_done, |
| 432 factory()->NewExpressionStatement(assign_undefined, nopos), | 428 factory()->NewExpressionStatement(assign_undefined, nopos), |
| 433 inner_else, nopos); | 429 inner_else, nopos); |
| 434 | 430 |
| 435 auto next_block = | 431 auto next_block = factory()->NewBlock(nullptr, true, kNoSourcePosition); |
| 436 factory()->NewBlock(nullptr, 3, true, kNoSourcePosition); | 432 next_block->statements()->push_back(factory()->NewExpressionStatement( |
| 437 next_block->statements()->Add( | 433 factory()->NewAssignment( |
| 438 factory()->NewExpressionStatement( | 434 Token::ASSIGN, factory()->NewVariableProxy(done), |
| 439 factory()->NewAssignment( | 435 factory()->NewBooleanLiteral(true, nopos), nopos), |
| 440 Token::ASSIGN, factory()->NewVariableProxy(done), | 436 nopos)); |
| 441 factory()->NewBooleanLiteral(true, nopos), nopos), | 437 next_block->statements()->push_back(factory()->NewExpressionStatement( |
| 442 nopos), | 438 parser_->BuildIteratorNextResult( |
| 443 zone()); | 439 factory()->NewVariableProxy(iterator), result, kNoSourcePosition), |
| 444 next_block->statements()->Add( | 440 kNoSourcePosition)); |
| 445 factory()->NewExpressionStatement( | 441 next_block->statements()->push_back(inner_if); |
| 446 parser_->BuildIteratorNextResult( | |
| 447 factory()->NewVariableProxy(iterator), result, | |
| 448 kNoSourcePosition), | |
| 449 kNoSourcePosition), | |
| 450 zone()); | |
| 451 next_block->statements()->Add(inner_if, zone()); | |
| 452 | 442 |
| 453 if_not_done = factory()->NewIfStatement( | 443 if_not_done = factory()->NewIfStatement( |
| 454 factory()->NewUnaryOperation( | 444 factory()->NewUnaryOperation( |
| 455 Token::NOT, factory()->NewVariableProxy(done), kNoSourcePosition), | 445 Token::NOT, factory()->NewVariableProxy(done), kNoSourcePosition), |
| 456 next_block, factory()->NewEmptyStatement(kNoSourcePosition), | 446 next_block, factory()->NewEmptyStatement(kNoSourcePosition), |
| 457 kNoSourcePosition); | 447 kNoSourcePosition); |
| 458 } | 448 } |
| 459 block_->statements()->Add(if_not_done, zone()); | 449 block_->statements()->push_back(if_not_done); |
| 460 | 450 |
| 461 if (!(value->IsLiteral() && value->AsLiteral()->raw_value()->IsTheHole())) { | 451 if (!(value->IsLiteral() && value->AsLiteral()->raw_value()->IsTheHole())) { |
| 462 { | 452 { |
| 463 // completion = kAbruptCompletion; | 453 // completion = kAbruptCompletion; |
| 464 Expression* proxy = factory()->NewVariableProxy(completion); | 454 Expression* proxy = factory()->NewVariableProxy(completion); |
| 465 Expression* assignment = factory()->NewAssignment( | 455 Expression* assignment = factory()->NewAssignment( |
| 466 Token::ASSIGN, proxy, | 456 Token::ASSIGN, proxy, |
| 467 factory()->NewSmiLiteral(kAbruptCompletion, nopos), nopos); | 457 factory()->NewSmiLiteral(kAbruptCompletion, nopos), nopos); |
| 468 block_->statements()->Add( | 458 block_->statements()->push_back( |
| 469 factory()->NewExpressionStatement(assignment, nopos), zone()); | 459 factory()->NewExpressionStatement(assignment, nopos)); |
| 470 } | 460 } |
| 471 | 461 |
| 472 RecurseIntoSubpattern(value, factory()->NewVariableProxy(v)); | 462 RecurseIntoSubpattern(value, factory()->NewVariableProxy(v)); |
| 473 | 463 |
| 474 { | 464 { |
| 475 // completion = kNormalCompletion; | 465 // completion = kNormalCompletion; |
| 476 Expression* proxy = factory()->NewVariableProxy(completion); | 466 Expression* proxy = factory()->NewVariableProxy(completion); |
| 477 Expression* assignment = factory()->NewAssignment( | 467 Expression* assignment = factory()->NewAssignment( |
| 478 Token::ASSIGN, proxy, | 468 Token::ASSIGN, proxy, |
| 479 factory()->NewSmiLiteral(kNormalCompletion, nopos), nopos); | 469 factory()->NewSmiLiteral(kNormalCompletion, nopos), nopos); |
| 480 block_->statements()->Add( | 470 block_->statements()->push_back( |
| 481 factory()->NewExpressionStatement(assignment, nopos), zone()); | 471 factory()->NewExpressionStatement(assignment, nopos)); |
| 482 } | 472 } |
| 483 } | 473 } |
| 484 set_context(context); | 474 set_context(context); |
| 485 } | 475 } |
| 486 | 476 |
| 487 if (spread != nullptr) { | 477 if (spread != nullptr) { |
| 488 // A spread can only occur as the last component. It is not handled by | 478 // A spread can only occur as the last component. It is not handled by |
| 489 // RecurseIntoSubpattern above. | 479 // RecurseIntoSubpattern above. |
| 490 | 480 |
| 491 // let array = []; | 481 // let array = []; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 537 |
| 548 // if (!result.done) { #append_element; #unset_done } | 538 // if (!result.done) { #append_element; #unset_done } |
| 549 Statement* maybe_append_and_unset_done; | 539 Statement* maybe_append_and_unset_done; |
| 550 { | 540 { |
| 551 Expression* result_done = | 541 Expression* result_done = |
| 552 factory()->NewProperty(factory()->NewVariableProxy(result), | 542 factory()->NewProperty(factory()->NewVariableProxy(result), |
| 553 factory()->NewStringLiteral( | 543 factory()->NewStringLiteral( |
| 554 ast_value_factory()->done_string(), nopos), | 544 ast_value_factory()->done_string(), nopos), |
| 555 nopos); | 545 nopos); |
| 556 | 546 |
| 557 Block* then = factory()->NewBlock(nullptr, 2, true, nopos); | 547 Block* then = factory()->NewBlock(nullptr, true, nopos); |
| 558 then->statements()->Add(append_element, zone()); | 548 then->statements()->push_back(append_element); |
| 559 then->statements()->Add(unset_done, zone()); | 549 then->statements()->push_back(unset_done); |
| 560 | 550 |
| 561 maybe_append_and_unset_done = factory()->NewIfStatement( | 551 maybe_append_and_unset_done = factory()->NewIfStatement( |
| 562 factory()->NewUnaryOperation(Token::NOT, result_done, nopos), then, | 552 factory()->NewUnaryOperation(Token::NOT, result_done, nopos), then, |
| 563 factory()->NewEmptyStatement(nopos), nopos); | 553 factory()->NewEmptyStatement(nopos), nopos); |
| 564 } | 554 } |
| 565 | 555 |
| 566 // while (!done) { | 556 // while (!done) { |
| 567 // #set_done; | 557 // #set_done; |
| 568 // #get_next; | 558 // #get_next; |
| 569 // #maybe_append_and_unset_done; | 559 // #maybe_append_and_unset_done; |
| 570 // } | 560 // } |
| 571 WhileStatement* loop = factory()->NewWhileStatement(nullptr, nopos); | 561 WhileStatement* loop = factory()->NewWhileStatement(nullptr, nopos); |
| 572 { | 562 { |
| 573 Expression* condition = factory()->NewUnaryOperation( | 563 Expression* condition = factory()->NewUnaryOperation( |
| 574 Token::NOT, factory()->NewVariableProxy(done), nopos); | 564 Token::NOT, factory()->NewVariableProxy(done), nopos); |
| 575 Block* body = factory()->NewBlock(nullptr, 3, true, nopos); | 565 Block* body = factory()->NewBlock(nullptr, true, nopos); |
| 576 body->statements()->Add(set_done, zone()); | 566 body->statements()->push_back(set_done); |
| 577 body->statements()->Add(get_next, zone()); | 567 body->statements()->push_back(get_next); |
| 578 body->statements()->Add(maybe_append_and_unset_done, zone()); | 568 body->statements()->push_back(maybe_append_and_unset_done); |
| 579 loop->Initialize(condition, body); | 569 loop->Initialize(condition, body); |
| 580 } | 570 } |
| 581 | 571 |
| 582 block_->statements()->Add(loop, zone()); | 572 block_->statements()->push_back(loop); |
| 583 RecurseIntoSubpattern(spread->expression(), | 573 RecurseIntoSubpattern(spread->expression(), |
| 584 factory()->NewVariableProxy(array)); | 574 factory()->NewVariableProxy(array)); |
| 585 } | 575 } |
| 586 | 576 |
| 587 Expression* closing_condition = factory()->NewUnaryOperation( | 577 Expression* closing_condition = factory()->NewUnaryOperation( |
| 588 Token::NOT, factory()->NewVariableProxy(done), nopos); | 578 Token::NOT, factory()->NewVariableProxy(done), nopos); |
| 589 parser_->FinalizeIteratorUse(completion, closing_condition, iterator, block_, | 579 parser_->FinalizeIteratorUse(completion, closing_condition, iterator, block_, |
| 590 target); | 580 target); |
| 591 block_ = target; | 581 block_ = target; |
| 592 } | 582 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 | 619 |
| 630 // =============== AssignmentPattern only ================== | 620 // =============== AssignmentPattern only ================== |
| 631 | 621 |
| 632 void Parser::PatternRewriter::VisitProperty(v8::internal::Property* node) { | 622 void Parser::PatternRewriter::VisitProperty(v8::internal::Property* node) { |
| 633 DCHECK(IsAssignmentContext()); | 623 DCHECK(IsAssignmentContext()); |
| 634 auto value = current_value_; | 624 auto value = current_value_; |
| 635 | 625 |
| 636 Assignment* assignment = | 626 Assignment* assignment = |
| 637 factory()->NewAssignment(Token::ASSIGN, node, value, node->position()); | 627 factory()->NewAssignment(Token::ASSIGN, node, value, node->position()); |
| 638 | 628 |
| 639 block_->statements()->Add( | 629 block_->statements()->push_back( |
| 640 factory()->NewExpressionStatement(assignment, kNoSourcePosition), zone()); | 630 factory()->NewExpressionStatement(assignment, kNoSourcePosition)); |
| 641 } | 631 } |
| 642 | 632 |
| 643 | 633 |
| 644 // =============== UNREACHABLE ============================= | 634 // =============== UNREACHABLE ============================= |
| 645 | 635 |
| 646 #define NOT_A_PATTERN(Node) \ | 636 #define NOT_A_PATTERN(Node) \ |
| 647 void Parser::PatternRewriter::Visit##Node(v8::internal::Node*) { \ | 637 void Parser::PatternRewriter::Visit##Node(v8::internal::Node*) { \ |
| 648 UNREACHABLE(); \ | 638 UNREACHABLE(); \ |
| 649 } | 639 } |
| 650 | 640 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 NOT_A_PATTERN(TryFinallyStatement) | 677 NOT_A_PATTERN(TryFinallyStatement) |
| 688 NOT_A_PATTERN(UnaryOperation) | 678 NOT_A_PATTERN(UnaryOperation) |
| 689 NOT_A_PATTERN(VariableDeclaration) | 679 NOT_A_PATTERN(VariableDeclaration) |
| 690 NOT_A_PATTERN(WhileStatement) | 680 NOT_A_PATTERN(WhileStatement) |
| 691 NOT_A_PATTERN(WithStatement) | 681 NOT_A_PATTERN(WithStatement) |
| 692 NOT_A_PATTERN(Yield) | 682 NOT_A_PATTERN(Yield) |
| 693 | 683 |
| 694 #undef NOT_A_PATTERN | 684 #undef NOT_A_PATTERN |
| 695 } // namespace internal | 685 } // namespace internal |
| 696 } // namespace v8 | 686 } // namespace v8 |
| OLD | NEW |