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

Side by Side Diff: src/parsing/parser.cc

Issue 2179423002: [parser] Refactor parser and preparser traits (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: More changes after reviewers' comments Created 4 years, 4 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 | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('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/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 #define DUMMY ) // to make indentation work 382 #define DUMMY ) // to make indentation work
383 #undef DUMMY 383 #undef DUMMY
384 384
385 // ---------------------------------------------------------------------------- 385 // ----------------------------------------------------------------------------
386 // Implementation of Parser 386 // Implementation of Parser
387 387
388 bool ParserTraits::IsEval(const AstRawString* identifier) const { 388 bool ParserTraits::IsEval(const AstRawString* identifier) const {
389 return identifier == parser_->ast_value_factory()->eval_string(); 389 return identifier == parser_->ast_value_factory()->eval_string();
390 } 390 }
391 391
392
393 bool ParserTraits::IsArguments(const AstRawString* identifier) const { 392 bool ParserTraits::IsArguments(const AstRawString* identifier) const {
394 return identifier == parser_->ast_value_factory()->arguments_string(); 393 return identifier == parser_->ast_value_factory()->arguments_string();
395 } 394 }
396 395
397
398 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { 396 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const {
399 return IsEval(identifier) || IsArguments(identifier); 397 return IsEval(identifier) || IsArguments(identifier);
400 } 398 }
401 399
402 bool ParserTraits::IsUndefined(const AstRawString* identifier) const { 400 bool ParserTraits::IsUndefined(const AstRawString* identifier) const {
403 return identifier == parser_->ast_value_factory()->undefined_string(); 401 return identifier == parser_->ast_value_factory()->undefined_string();
404 } 402 }
405 403
406 bool ParserTraits::IsAwait(const AstRawString* identifier) const { 404 bool ParserTraits::IsAwait(const AstRawString* identifier) const {
407 return identifier == parser_->ast_value_factory()->await_string(); 405 return identifier == parser_->ast_value_factory()->await_string();
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 auto args = new (zone) ZoneList<Expression*>(2, zone); 582 auto args = new (zone) ZoneList<Expression*>(2, zone);
585 args->Add(value, zone); 583 args->Add(value, zone);
586 args->Add(factory->NewBooleanLiteral(done, pos), zone); 584 args->Add(factory->NewBooleanLiteral(done, pos), zone);
587 585
588 return factory->NewCallRuntime(Runtime::kInlineCreateIterResultObject, args, 586 return factory->NewCallRuntime(Runtime::kInlineCreateIterResultObject, args,
589 pos); 587 pos);
590 } 588 }
591 589
592 Expression* ParserTraits::NewThrowReferenceError( 590 Expression* ParserTraits::NewThrowReferenceError(
593 MessageTemplate::Template message, int pos) { 591 MessageTemplate::Template message, int pos) {
594 return NewThrowError(Runtime::kNewReferenceError, message, 592 return parser_->NewThrowError(Runtime::kNewReferenceError, message,
595 parser_->ast_value_factory()->empty_string(), pos); 593 parser_->ast_value_factory()->empty_string(),
594 pos);
596 } 595 }
597 596
598 597
599 Expression* ParserTraits::NewThrowSyntaxError(MessageTemplate::Template message, 598 Expression* ParserTraits::NewThrowSyntaxError(MessageTemplate::Template message,
600 const AstRawString* arg, 599 const AstRawString* arg,
601 int pos) { 600 int pos) {
602 return NewThrowError(Runtime::kNewSyntaxError, message, arg, pos); 601 return parser_->NewThrowError(Runtime::kNewSyntaxError, message, arg, pos);
603 } 602 }
604 603
605 604
606 Expression* ParserTraits::NewThrowTypeError(MessageTemplate::Template message, 605 Expression* ParserTraits::NewThrowTypeError(MessageTemplate::Template message,
607 const AstRawString* arg, int pos) { 606 const AstRawString* arg, int pos) {
608 return NewThrowError(Runtime::kNewTypeError, message, arg, pos); 607 return parser_->NewThrowError(Runtime::kNewTypeError, message, arg, pos);
608 }
609
610 Expression* Parser::NewThrowError(Runtime::FunctionId id,
611 MessageTemplate::Template message,
612 const AstRawString* arg, int pos) {
613 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone());
614 args->Add(factory()->NewSmiLiteral(message, pos), zone());
615 args->Add(factory()->NewStringLiteral(arg, pos), zone());
616 CallRuntime* call_constructor = factory()->NewCallRuntime(id, args, pos);
617 return factory()->NewThrow(call_constructor, pos);
609 } 618 }
610 619
611 620
612 Expression* ParserTraits::NewThrowError(Runtime::FunctionId id,
613 MessageTemplate::Template message,
614 const AstRawString* arg, int pos) {
615 Zone* zone = parser_->zone();
616 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone);
617 args->Add(parser_->factory()->NewSmiLiteral(message, pos), zone);
618 args->Add(parser_->factory()->NewStringLiteral(arg, pos), zone);
619 CallRuntime* call_constructor =
620 parser_->factory()->NewCallRuntime(id, args, pos);
621 return parser_->factory()->NewThrow(call_constructor, pos);
622 }
623
624
625 void ParserTraits::ReportMessageAt(Scanner::Location source_location, 621 void ParserTraits::ReportMessageAt(Scanner::Location source_location,
626 MessageTemplate::Template message, 622 MessageTemplate::Template message,
627 const char* arg, ParseErrorType error_type) { 623 const char* arg, ParseErrorType error_type) {
628 if (parser_->stack_overflow()) { 624 if (parser_->stack_overflow()) {
629 // Suppress the error message (syntax error or such) in the presence of a 625 // Suppress the error message (syntax error or such) in the presence of a
630 // stack overflow. The isolate allows only one pending exception at at time 626 // stack overflow. The isolate allows only one pending exception at at time
631 // and we want to report the stack overflow later. 627 // and we want to report the stack overflow later.
632 return; 628 return;
633 } 629 }
634 parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos, 630 parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos,
635 source_location.end_pos, 631 source_location.end_pos,
636 message, arg, error_type); 632 message, arg, error_type);
637 } 633 }
638 634
639 635
640 void ParserTraits::ReportMessage(MessageTemplate::Template message,
641 const char* arg, ParseErrorType error_type) {
642 Scanner::Location source_location = parser_->scanner()->location();
643 ReportMessageAt(source_location, message, arg, error_type);
644 }
645
646
647 void ParserTraits::ReportMessage(MessageTemplate::Template message,
648 const AstRawString* arg,
649 ParseErrorType error_type) {
650 Scanner::Location source_location = parser_->scanner()->location();
651 ReportMessageAt(source_location, message, arg, error_type);
652 }
653
654
655 void ParserTraits::ReportMessageAt(Scanner::Location source_location, 636 void ParserTraits::ReportMessageAt(Scanner::Location source_location,
656 MessageTemplate::Template message, 637 MessageTemplate::Template message,
657 const AstRawString* arg, 638 const AstRawString* arg,
658 ParseErrorType error_type) { 639 ParseErrorType error_type) {
659 if (parser_->stack_overflow()) { 640 if (parser_->stack_overflow()) {
660 // Suppress the error message (syntax error or such) in the presence of a 641 // Suppress the error message (syntax error or such) in the presence of a
661 // stack overflow. The isolate allows only one pending exception at at time 642 // stack overflow. The isolate allows only one pending exception at at time
662 // and we want to report the stack overflow later. 643 // and we want to report the stack overflow later.
663 return; 644 return;
664 } 645 }
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 if (use_strict_found) { 1291 if (use_strict_found) {
1311 if (is_sloppy(language_mode())) { 1292 if (is_sloppy(language_mode())) {
1312 RaiseLanguageMode(STRICT); 1293 RaiseLanguageMode(STRICT);
1313 } 1294 }
1314 1295
1315 if (!this->scope()->HasSimpleParameters()) { 1296 if (!this->scope()->HasSimpleParameters()) {
1316 // TC39 deemed "use strict" directives to be an error when occurring 1297 // TC39 deemed "use strict" directives to be an error when occurring
1317 // in the body of a function with non-simple parameter list, on 1298 // in the body of a function with non-simple parameter list, on
1318 // 29/7/2015. https://goo.gl/ueA7Ln 1299 // 29/7/2015. https://goo.gl/ueA7Ln
1319 const AstRawString* string = literal->raw_value()->AsString(); 1300 const AstRawString* string = literal->raw_value()->AsString();
1320 ParserTraits::ReportMessageAt( 1301 ReportMessageAt(token_loc,
1321 token_loc, MessageTemplate::kIllegalLanguageModeDirective, 1302 MessageTemplate::kIllegalLanguageModeDirective,
1322 string); 1303 string);
1323 *ok = false; 1304 *ok = false;
1324 return; 1305 return;
1325 } 1306 }
1326 // Because declarations in strict eval code don't leak into the scope 1307 // Because declarations in strict eval code don't leak into the scope
1327 // of the eval call, it is likely that functions declared in strict 1308 // of the eval call, it is likely that functions declared in strict
1328 // eval code will be used within the eval code, so lazy parsing is 1309 // eval code will be used within the eval code, so lazy parsing is
1329 // probably not a win. 1310 // probably not a win.
1330 if (this->scope()->is_eval_scope()) mode_ = PARSE_EAGERLY; 1311 if (this->scope()->is_eval_scope()) mode_ = PARSE_EAGERLY;
1331 } else if (literal->raw_value()->AsString() == 1312 } else if (literal->raw_value()->AsString() ==
1332 ast_value_factory()->use_asm_string() && 1313 ast_value_factory()->use_asm_string() &&
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 // check also covers the special case 2043 // check also covers the special case
2063 // 2044 //
2064 // function () { let x; { var x; } } 2045 // function () { let x; { var x; } }
2065 // 2046 //
2066 // because the var declaration is hoisted to the function scope where 2047 // because the var declaration is hoisted to the function scope where
2067 // 'x' is already bound. 2048 // 'x' is already bound.
2068 DCHECK(IsDeclaredVariableMode(var->mode())); 2049 DCHECK(IsDeclaredVariableMode(var->mode()));
2069 // In harmony we treat re-declarations as early errors. See 2050 // In harmony we treat re-declarations as early errors. See
2070 // ES5 16 for a definition of early errors. 2051 // ES5 16 for a definition of early errors.
2071 if (declaration_kind == DeclarationDescriptor::NORMAL) { 2052 if (declaration_kind == DeclarationDescriptor::NORMAL) {
2072 ParserTraits::ReportMessage(MessageTemplate::kVarRedeclaration, name); 2053 ReportMessage(MessageTemplate::kVarRedeclaration, name);
2073 } else { 2054 } else {
2074 ParserTraits::ReportMessage(MessageTemplate::kParamDupe); 2055 ReportMessage(MessageTemplate::kParamDupe);
2075 } 2056 }
2076 *ok = false; 2057 *ok = false;
2077 return nullptr; 2058 return nullptr;
2078 } 2059 }
2079 } else if (mode == VAR) { 2060 } else if (mode == VAR) {
2080 var->set_maybe_assigned(); 2061 var->set_maybe_assigned();
2081 } 2062 }
2082 } 2063 }
2083 DCHECK_NOT_NULL(var); 2064 DCHECK_NOT_NULL(var);
2084 2065
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
2457 2438
2458 // End position of the initializer is after the assignment expression. 2439 // End position of the initializer is after the assignment expression.
2459 initializer_position = scanner()->location().end_pos; 2440 initializer_position = scanner()->location().end_pos;
2460 } else { 2441 } else {
2461 // Initializers may be either required or implied unless this is a 2442 // Initializers may be either required or implied unless this is a
2462 // for-in/of iteration variable. 2443 // for-in/of iteration variable.
2463 if (var_context != kForStatement || !PeekInOrOf()) { 2444 if (var_context != kForStatement || !PeekInOrOf()) {
2464 // ES6 'const' and binding patterns require initializers. 2445 // ES6 'const' and binding patterns require initializers.
2465 if (parsing_result->descriptor.mode == CONST || 2446 if (parsing_result->descriptor.mode == CONST ||
2466 !pattern->IsVariableProxy()) { 2447 !pattern->IsVariableProxy()) {
2467 ParserTraits::ReportMessageAt( 2448 ReportMessageAt(
2468 Scanner::Location(decl_pos, scanner()->location().end_pos), 2449 Scanner::Location(decl_pos, scanner()->location().end_pos),
2469 MessageTemplate::kDeclarationMissingInitializer, 2450 MessageTemplate::kDeclarationMissingInitializer,
2470 !pattern->IsVariableProxy() ? "destructuring" : "const"); 2451 !pattern->IsVariableProxy() ? "destructuring" : "const");
2471 *ok = false; 2452 *ok = false;
2472 return nullptr; 2453 return nullptr;
2473 } 2454 }
2474 2455
2475 // 'let x' initializes 'x' to undefined. 2456 // 'let x' initializes 'x' to undefined.
2476 if (parsing_result->descriptor.mode == LET) { 2457 if (parsing_result->descriptor.mode == LET) {
2477 value = GetLiteralUndefined(position()); 2458 value = GetLiteralUndefined(position());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 return false; 2501 return false;
2521 } 2502 }
2522 2503
2523 Statement* Parser::ParseFunctionDeclaration(bool* ok) { 2504 Statement* Parser::ParseFunctionDeclaration(bool* ok) {
2524 Consume(Token::FUNCTION); 2505 Consume(Token::FUNCTION);
2525 int pos = position(); 2506 int pos = position();
2526 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; 2507 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
2527 if (Check(Token::MUL)) { 2508 if (Check(Token::MUL)) {
2528 flags |= ParseFunctionFlags::kIsGenerator; 2509 flags |= ParseFunctionFlags::kIsGenerator;
2529 if (allow_harmony_restrictive_declarations()) { 2510 if (allow_harmony_restrictive_declarations()) {
2530 ParserTraits::ReportMessageAt(scanner()->location(), 2511 ReportMessageAt(scanner()->location(),
2531 MessageTemplate::kGeneratorInLegacyContext); 2512 MessageTemplate::kGeneratorInLegacyContext);
2532 *ok = false; 2513 *ok = false;
2533 return nullptr; 2514 return nullptr;
2534 } 2515 }
2535 } 2516 }
2536 2517
2537 return ParseHoistableDeclaration(pos, flags, nullptr, false, CHECK_OK); 2518 return ParseHoistableDeclaration(pos, flags, nullptr, false, CHECK_OK);
2538 } 2519 }
2539 2520
2540 Statement* Parser::ParseExpressionOrLabelledStatement( 2521 Statement* Parser::ParseExpressionOrLabelledStatement(
2541 ZoneList<const AstRawString*>* labels, 2522 ZoneList<const AstRawString*>* labels,
(...skipping 27 matching lines...) Expand all
2569 // Expression is a single identifier, and not, e.g., a parenthesized 2550 // Expression is a single identifier, and not, e.g., a parenthesized
2570 // identifier. 2551 // identifier.
2571 VariableProxy* var = expr->AsVariableProxy(); 2552 VariableProxy* var = expr->AsVariableProxy();
2572 const AstRawString* label = var->raw_name(); 2553 const AstRawString* label = var->raw_name();
2573 // TODO(1240780): We don't check for redeclaration of labels 2554 // TODO(1240780): We don't check for redeclaration of labels
2574 // during preparsing since keeping track of the set of active 2555 // during preparsing since keeping track of the set of active
2575 // labels requires nontrivial changes to the way scopes are 2556 // labels requires nontrivial changes to the way scopes are
2576 // structured. However, these are probably changes we want to 2557 // structured. However, these are probably changes we want to
2577 // make later anyway so we should go back and fix this then. 2558 // make later anyway so we should go back and fix this then.
2578 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { 2559 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
2579 ParserTraits::ReportMessage(MessageTemplate::kLabelRedeclaration, label); 2560 ReportMessage(MessageTemplate::kLabelRedeclaration, label);
2580 *ok = false; 2561 *ok = false;
2581 return NULL; 2562 return NULL;
2582 } 2563 }
2583 if (labels == NULL) { 2564 if (labels == NULL) {
2584 labels = new(zone()) ZoneList<const AstRawString*>(4, zone()); 2565 labels = new(zone()) ZoneList<const AstRawString*>(4, zone());
2585 } 2566 }
2586 labels->Add(label, zone()); 2567 labels->Add(label, zone());
2587 // Remove the "ghost" variable that turned out to be a label 2568 // Remove the "ghost" variable that turned out to be a label
2588 // from the top scope. This way, we don't try to resolve it 2569 // from the top scope. This way, we don't try to resolve it
2589 // during the scope processing. 2570 // during the scope processing.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2654 // ECMA allows "eval" or "arguments" as labels even in strict mode. 2635 // ECMA allows "eval" or "arguments" as labels even in strict mode.
2655 label = ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK); 2636 label = ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
2656 } 2637 }
2657 IterationStatement* target = LookupContinueTarget(label, CHECK_OK); 2638 IterationStatement* target = LookupContinueTarget(label, CHECK_OK);
2658 if (target == NULL) { 2639 if (target == NULL) {
2659 // Illegal continue statement. 2640 // Illegal continue statement.
2660 MessageTemplate::Template message = MessageTemplate::kIllegalContinue; 2641 MessageTemplate::Template message = MessageTemplate::kIllegalContinue;
2661 if (label != NULL) { 2642 if (label != NULL) {
2662 message = MessageTemplate::kUnknownLabel; 2643 message = MessageTemplate::kUnknownLabel;
2663 } 2644 }
2664 ParserTraits::ReportMessage(message, label); 2645 ReportMessage(message, label);
2665 *ok = false; 2646 *ok = false;
2666 return NULL; 2647 return NULL;
2667 } 2648 }
2668 ExpectSemicolon(CHECK_OK); 2649 ExpectSemicolon(CHECK_OK);
2669 return factory()->NewContinueStatement(target, pos); 2650 return factory()->NewContinueStatement(target, pos);
2670 } 2651 }
2671 2652
2672 2653
2673 Statement* Parser::ParseBreakStatement(ZoneList<const AstRawString*>* labels, 2654 Statement* Parser::ParseBreakStatement(ZoneList<const AstRawString*>* labels,
2674 bool* ok) { 2655 bool* ok) {
(...skipping 16 matching lines...) Expand all
2691 return factory()->NewEmptyStatement(pos); 2672 return factory()->NewEmptyStatement(pos);
2692 } 2673 }
2693 BreakableStatement* target = NULL; 2674 BreakableStatement* target = NULL;
2694 target = LookupBreakTarget(label, CHECK_OK); 2675 target = LookupBreakTarget(label, CHECK_OK);
2695 if (target == NULL) { 2676 if (target == NULL) {
2696 // Illegal break statement. 2677 // Illegal break statement.
2697 MessageTemplate::Template message = MessageTemplate::kIllegalBreak; 2678 MessageTemplate::Template message = MessageTemplate::kIllegalBreak;
2698 if (label != NULL) { 2679 if (label != NULL) {
2699 message = MessageTemplate::kUnknownLabel; 2680 message = MessageTemplate::kUnknownLabel;
2700 } 2681 }
2701 ParserTraits::ReportMessage(message, label); 2682 ReportMessage(message, label);
2702 *ok = false; 2683 *ok = false;
2703 return NULL; 2684 return NULL;
2704 } 2685 }
2705 ExpectSemicolon(CHECK_OK); 2686 ExpectSemicolon(CHECK_OK);
2706 return factory()->NewBreakStatement(target, pos); 2687 return factory()->NewBreakStatement(target, pos);
2707 } 2688 }
2708 2689
2709 2690
2710 Statement* Parser::ParseReturnStatement(bool* ok) { 2691 Statement* Parser::ParseReturnStatement(bool* ok) {
2711 // ReturnStatement :: 2692 // ReturnStatement ::
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
3074 Declaration* decl = 3055 Declaration* decl =
3075 inner_block_scope->CheckLexDeclarationsConflictingWith( 3056 inner_block_scope->CheckLexDeclarationsConflictingWith(
3076 bound_names); 3057 bound_names);
3077 if (decl != nullptr) { 3058 if (decl != nullptr) {
3078 const AstRawString* name = decl->proxy()->raw_name(); 3059 const AstRawString* name = decl->proxy()->raw_name();
3079 int position = decl->proxy()->position(); 3060 int position = decl->proxy()->position();
3080 Scanner::Location location = 3061 Scanner::Location location =
3081 position == kNoSourcePosition 3062 position == kNoSourcePosition
3082 ? Scanner::Location::invalid() 3063 ? Scanner::Location::invalid()
3083 : Scanner::Location(position, position + 1); 3064 : Scanner::Location(position, position + 1);
3084 ParserTraits::ReportMessageAt( 3065 ReportMessageAt(location, MessageTemplate::kVarRedeclaration, name);
3085 location, MessageTemplate::kVarRedeclaration, name);
3086 *ok = false; 3066 *ok = false;
3087 return nullptr; 3067 return nullptr;
3088 } 3068 }
3089 } 3069 }
3090 block_state.set_end_position(scanner()->location().end_pos); 3070 block_state.set_end_position(scanner()->location().end_pos);
3091 catch_block->set_scope(block_state.FinalizedBlockScope()); 3071 catch_block->set_scope(block_state.FinalizedBlockScope());
3092 } 3072 }
3093 } 3073 }
3094 3074
3095 catch_scope->set_end_position(scanner()->location().end_pos); 3075 catch_scope->set_end_position(scanner()->location().end_pos);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
3385 // Statement* body (gets overwritten) 3365 // Statement* body (gets overwritten)
3386 if (finalize) { 3366 if (finalize) {
3387 Block* block = factory()->NewBlock(nullptr, 2, false, nopos); 3367 Block* block = factory()->NewBlock(nullptr, 2, false, nopos);
3388 block->statements()->Add(body, zone()); 3368 block->statements()->Add(body, zone());
3389 block->statements()->Add(set_completion_normal, zone()); 3369 block->statements()->Add(set_completion_normal, zone());
3390 body = block; 3370 body = block;
3391 } 3371 }
3392 3372
3393 for_of->Initialize(body, iterator, assign_iterator, next_result, result_done, 3373 for_of->Initialize(body, iterator, assign_iterator, next_result, result_done,
3394 assign_each); 3374 assign_each);
3395 return finalize 3375 return finalize ? FinalizeForOfStatement(for_of, completion, nopos) : for_of;
3396 ? ParserTraits::FinalizeForOfStatement(for_of, completion, nopos)
3397 : for_of;
3398 } 3376 }
3399 3377
3400 Statement* Parser::DesugarLexicalBindingsInForStatement( 3378 Statement* Parser::DesugarLexicalBindingsInForStatement(
3401 Scope* inner_scope, VariableMode mode, ZoneList<const AstRawString*>* names, 3379 Scope* inner_scope, VariableMode mode, ZoneList<const AstRawString*>* names,
3402 ForStatement* loop, Statement* init, Expression* cond, Statement* next, 3380 ForStatement* loop, Statement* init, Expression* cond, Statement* next,
3403 Statement* body, bool* ok) { 3381 Statement* body, bool* ok) {
3404 // ES6 13.7.4.8 specifies that on each loop iteration the let variables are 3382 // ES6 13.7.4.8 specifies that on each loop iteration the let variables are
3405 // copied into a new environment. Moreover, the "next" statement must be 3383 // copied into a new environment. Moreover, the "next" statement must be
3406 // evaluated not in the environment of the just completed iteration but in 3384 // evaluated not in the environment of the just completed iteration but in
3407 // that of the upcoming one. We achieve this with the following desugaring. 3385 // that of the upcoming one. We achieve this with the following desugaring.
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
3679 ParseVariableDeclarations(kForStatement, &parsing_result, nullptr, 3657 ParseVariableDeclarations(kForStatement, &parsing_result, nullptr,
3680 CHECK_OK); 3658 CHECK_OK);
3681 3659
3682 ForEachStatement::VisitMode mode = ForEachStatement::ENUMERATE; 3660 ForEachStatement::VisitMode mode = ForEachStatement::ENUMERATE;
3683 int each_beg_pos = scanner()->location().beg_pos; 3661 int each_beg_pos = scanner()->location().beg_pos;
3684 int each_end_pos = scanner()->location().end_pos; 3662 int each_end_pos = scanner()->location().end_pos;
3685 3663
3686 if (CheckInOrOf(&mode, ok)) { 3664 if (CheckInOrOf(&mode, ok)) {
3687 if (!*ok) return nullptr; 3665 if (!*ok) return nullptr;
3688 if (parsing_result.declarations.length() != 1) { 3666 if (parsing_result.declarations.length() != 1) {
3689 ParserTraits::ReportMessageAt( 3667 ReportMessageAt(parsing_result.bindings_loc,
3690 parsing_result.bindings_loc, 3668 MessageTemplate::kForInOfLoopMultiBindings,
3691 MessageTemplate::kForInOfLoopMultiBindings, 3669 ForEachStatement::VisitModeString(mode));
3692 ForEachStatement::VisitModeString(mode));
3693 *ok = false; 3670 *ok = false;
3694 return nullptr; 3671 return nullptr;
3695 } 3672 }
3696 DeclarationParsingResult::Declaration& decl = 3673 DeclarationParsingResult::Declaration& decl =
3697 parsing_result.declarations[0]; 3674 parsing_result.declarations[0];
3698 if (parsing_result.first_initializer_loc.IsValid() && 3675 if (parsing_result.first_initializer_loc.IsValid() &&
3699 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE || 3676 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE ||
3700 IsLexicalVariableMode(parsing_result.descriptor.mode) || 3677 IsLexicalVariableMode(parsing_result.descriptor.mode) ||
3701 !decl.pattern->IsVariableProxy() || allow_harmony_for_in())) { 3678 !decl.pattern->IsVariableProxy() || allow_harmony_for_in())) {
3702 // Only increment the use count if we would have let this through 3679 // Only increment the use count if we would have let this through
3703 // without the flag. 3680 // without the flag.
3704 if (allow_harmony_for_in()) { 3681 if (allow_harmony_for_in()) {
3705 ++use_counts_[v8::Isolate::kForInInitializer]; 3682 ++use_counts_[v8::Isolate::kForInInitializer];
3706 } 3683 }
3707 ParserTraits::ReportMessageAt( 3684 ReportMessageAt(parsing_result.first_initializer_loc,
3708 parsing_result.first_initializer_loc, 3685 MessageTemplate::kForInOfLoopInitializer,
3709 MessageTemplate::kForInOfLoopInitializer, 3686 ForEachStatement::VisitModeString(mode));
3710 ForEachStatement::VisitModeString(mode));
3711 *ok = false; 3687 *ok = false;
3712 return nullptr; 3688 return nullptr;
3713 } 3689 }
3714 3690
3715 Block* init_block = nullptr; 3691 Block* init_block = nullptr;
3716 bound_names_are_lexical = 3692 bound_names_are_lexical =
3717 IsLexicalVariableMode(parsing_result.descriptor.mode); 3693 IsLexicalVariableMode(parsing_result.descriptor.mode);
3718 3694
3719 // special case for legacy for (var ... = ... in ...) 3695 // special case for legacy for (var ... = ... in ...)
3720 if (!bound_names_are_lexical && decl.pattern->IsVariableProxy() && 3696 if (!bound_names_are_lexical && decl.pattern->IsVariableProxy() &&
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
3809 if (is_for_var_of) { 3785 if (is_for_var_of) {
3810 Scope* catch_scope = scope(); 3786 Scope* catch_scope = scope();
3811 while (catch_scope != nullptr && 3787 while (catch_scope != nullptr &&
3812 !catch_scope->is_declaration_scope()) { 3788 !catch_scope->is_declaration_scope()) {
3813 if (catch_scope->is_catch_scope()) { 3789 if (catch_scope->is_catch_scope()) {
3814 auto name = catch_scope->catch_variable_name(); 3790 auto name = catch_scope->catch_variable_name();
3815 if (name != 3791 if (name !=
3816 ast_value_factory() 3792 ast_value_factory()
3817 ->dot_catch_string()) { // i.e. is a simple binding 3793 ->dot_catch_string()) { // i.e. is a simple binding
3818 if (bound_names.Contains(name)) { 3794 if (bound_names.Contains(name)) {
3819 ParserTraits::ReportMessageAt( 3795 ReportMessageAt(parsing_result.bindings_loc,
3820 parsing_result.bindings_loc, 3796 MessageTemplate::kVarRedeclaration, name);
3821 MessageTemplate::kVarRedeclaration, name);
3822 *ok = false; 3797 *ok = false;
3823 return nullptr; 3798 return nullptr;
3824 } 3799 }
3825 } 3800 }
3826 } 3801 }
3827 catch_scope = catch_scope->outer_scope(); 3802 catch_scope = catch_scope->outer_scope();
3828 } 3803 }
3829 } 3804 }
3830 } 3805 }
3831 3806
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
4059 Handle<FixedArray> value) { 4034 Handle<FixedArray> value) {
4060 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); 4035 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot));
4061 return static_cast<LiteralType>(literal_type->value()); 4036 return static_cast<LiteralType>(literal_type->value());
4062 } 4037 }
4063 4038
4064 4039
4065 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { 4040 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
4066 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); 4041 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
4067 } 4042 }
4068 4043
4069 void ParserTraits::ParseArrowFunctionFormalParameters( 4044 void Parser::ParseArrowFunctionFormalParameters(
4070 ParserFormalParameters* parameters, Expression* expr, int end_pos, 4045 ParserFormalParameters* parameters, Expression* expr, int end_pos,
4071 bool* ok) { 4046 bool* ok) {
4072 // ArrowFunctionFormals :: 4047 // ArrowFunctionFormals ::
4073 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail) 4048 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail)
4074 // Tail 4049 // Tail
4075 // NonTailArrowFunctionFormals :: 4050 // NonTailArrowFunctionFormals ::
4076 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy) 4051 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy)
4077 // VariableProxy 4052 // VariableProxy
4078 // Tail :: 4053 // Tail ::
4079 // VariableProxy 4054 // VariableProxy
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
4191 } 4166 }
4192 return expr; 4167 return expr;
4193 } 4168 }
4194 4169
4195 void ParserTraits::ParseArrowFunctionFormalParameterList( 4170 void ParserTraits::ParseArrowFunctionFormalParameterList(
4196 ParserFormalParameters* parameters, Expression* expr, 4171 ParserFormalParameters* parameters, Expression* expr,
4197 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, 4172 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
4198 const Scope::Snapshot& scope_snapshot, bool* ok) { 4173 const Scope::Snapshot& scope_snapshot, bool* ok) {
4199 if (expr->IsEmptyParentheses()) return; 4174 if (expr->IsEmptyParentheses()) return;
4200 4175
4201 ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos, 4176 parser_->ParseArrowFunctionFormalParameters(
4202 CHECK_OK_VOID); 4177 parameters, expr, params_loc.end_pos, CHECK_OK_VOID);
4203 4178
4204 scope_snapshot.Reparent(parameters->scope); 4179 scope_snapshot.Reparent(parameters->scope);
4205 4180
4206 if (parameters->Arity() > Code::kMaxArguments) { 4181 if (parameters->Arity() > Code::kMaxArguments) {
4207 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); 4182 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList);
4208 *ok = false; 4183 *ok = false;
4209 return; 4184 return;
4210 } 4185 }
4211 4186
4212 Type::ExpressionClassifier classifier(parser_); 4187 Type::ExpressionClassifier classifier(parser_);
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
4566 if (bookmark && bookmark->HasBeenReset()) { 4541 if (bookmark && bookmark->HasBeenReset()) {
4567 return; // Return immediately if pre-parser devided to abort parsing. 4542 return; // Return immediately if pre-parser devided to abort parsing.
4568 } 4543 }
4569 if (result == PreParser::kPreParseStackOverflow) { 4544 if (result == PreParser::kPreParseStackOverflow) {
4570 // Propagate stack overflow. 4545 // Propagate stack overflow.
4571 set_stack_overflow(); 4546 set_stack_overflow();
4572 *ok = false; 4547 *ok = false;
4573 return; 4548 return;
4574 } 4549 }
4575 if (logger.has_error()) { 4550 if (logger.has_error()) {
4576 ParserTraits::ReportMessageAt( 4551 ReportMessageAt(Scanner::Location(logger.start(), logger.end()),
4577 Scanner::Location(logger.start(), logger.end()), logger.message(), 4552 logger.message(), logger.argument_opt(),
4578 logger.argument_opt(), logger.error_type()); 4553 logger.error_type());
4579 *ok = false; 4554 *ok = false;
4580 return; 4555 return;
4581 } 4556 }
4582 scope()->set_end_position(logger.end()); 4557 scope()->set_end_position(logger.end());
4583 Expect(Token::RBRACE, CHECK_OK_VOID); 4558 Expect(Token::RBRACE, CHECK_OK_VOID);
4584 total_preparse_skipped_ += scope()->end_position() - function_block_pos; 4559 total_preparse_skipped_ += scope()->end_position() - function_block_pos;
4585 *materialized_literal_count = logger.literals(); 4560 *materialized_literal_count = logger.literals();
4586 *expected_property_count = logger.properties(); 4561 *expected_property_count = logger.properties();
4587 SetLanguageMode(scope(), logger.language_mode()); 4562 SetLanguageMode(scope(), logger.language_mode());
4588 if (logger.uses_super_property()) { 4563 if (logger.uses_super_property()) {
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
5162 return NULL; 5137 return NULL;
5163 } 5138 }
5164 5139
5165 return factory()->NewCallRuntime(function, args, pos); 5140 return factory()->NewCallRuntime(function, args, pos);
5166 } 5141 }
5167 5142
5168 int context_index = Context::IntrinsicIndexForName(name->string()); 5143 int context_index = Context::IntrinsicIndexForName(name->string());
5169 5144
5170 // Check that the function is defined. 5145 // Check that the function is defined.
5171 if (context_index == Context::kNotFound) { 5146 if (context_index == Context::kNotFound) {
5172 ParserTraits::ReportMessage(MessageTemplate::kNotDefined, name); 5147 ReportMessage(MessageTemplate::kNotDefined, name);
5173 *ok = false; 5148 *ok = false;
5174 return NULL; 5149 return NULL;
5175 } 5150 }
5176 5151
5177 return factory()->NewCallRuntime(context_index, args, pos); 5152 return factory()->NewCallRuntime(context_index, args, pos);
5178 } 5153 }
5179 5154
5180 5155
5181 Literal* Parser::GetLiteralUndefined(int position) { 5156 Literal* Parser::GetLiteralUndefined(int position) {
5182 return factory()->NewUndefinedLiteral(position); 5157 return factory()->NewUndefinedLiteral(position);
5183 } 5158 }
5184 5159
5185 5160
5186 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { 5161 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
5187 Declaration* decl = scope->CheckConflictingVarDeclarations(); 5162 Declaration* decl = scope->CheckConflictingVarDeclarations();
5188 if (decl != NULL) { 5163 if (decl != NULL) {
5189 // In ES6, conflicting variable bindings are early errors. 5164 // In ES6, conflicting variable bindings are early errors.
5190 const AstRawString* name = decl->proxy()->raw_name(); 5165 const AstRawString* name = decl->proxy()->raw_name();
5191 int position = decl->proxy()->position(); 5166 int position = decl->proxy()->position();
5192 Scanner::Location location = 5167 Scanner::Location location =
5193 position == kNoSourcePosition 5168 position == kNoSourcePosition
5194 ? Scanner::Location::invalid() 5169 ? Scanner::Location::invalid()
5195 : Scanner::Location(position, position + 1); 5170 : Scanner::Location(position, position + 1);
5196 ParserTraits::ReportMessageAt(location, MessageTemplate::kVarRedeclaration, 5171 ReportMessageAt(location, MessageTemplate::kVarRedeclaration, name);
5197 name);
5198 *ok = false; 5172 *ok = false;
5199 } 5173 }
5200 } 5174 }
5201 5175
5202 5176
5203 void Parser::InsertShadowingVarBindingInitializers(Block* inner_block) { 5177 void Parser::InsertShadowingVarBindingInitializers(Block* inner_block) {
5204 // For each var-binding that shadows a parameter, insert an assignment 5178 // For each var-binding that shadows a parameter, insert an assignment
5205 // initializing the variable with the parameter. 5179 // initializing the variable with the parameter.
5206 Scope* inner_scope = inner_block->scope(); 5180 Scope* inner_scope = inner_block->scope();
5207 DCHECK(inner_scope->is_declaration_scope()); 5181 DCHECK(inner_scope->is_declaration_scope());
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
6086 return; 6060 return;
6087 } 6061 }
6088 } 6062 }
6089 6063
6090 // Ignore "__proto__" as a name when it's being used to set the [[Prototype]] 6064 // Ignore "__proto__" as a name when it's being used to set the [[Prototype]]
6091 // of an object literal. 6065 // of an object literal.
6092 if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return; 6066 if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return;
6093 6067
6094 DCHECK(!value->IsAnonymousFunctionDefinition() || 6068 DCHECK(!value->IsAnonymousFunctionDefinition() ||
6095 property->kind() == ObjectLiteralProperty::COMPUTED); 6069 property->kind() == ObjectLiteralProperty::COMPUTED);
6096 SetFunctionName(value, name); 6070 parser_->SetFunctionName(value, name);
6097 } 6071 }
6098 6072
6099 6073
6100 void ParserTraits::SetFunctionNameFromIdentifierRef(Expression* value, 6074 void ParserTraits::SetFunctionNameFromIdentifierRef(Expression* value,
6101 Expression* identifier) { 6075 Expression* identifier) {
6102 if (!identifier->IsVariableProxy()) return; 6076 if (!identifier->IsVariableProxy()) return;
6103 SetFunctionName(value, identifier->AsVariableProxy()->raw_name()); 6077 parser_->SetFunctionName(value, identifier->AsVariableProxy()->raw_name());
6104 } 6078 }
6105 6079
6106 6080 void Parser::SetFunctionName(Expression* value, const AstRawString* name) {
6107 void ParserTraits::SetFunctionName(Expression* value,
6108 const AstRawString* name) {
6109 DCHECK_NOT_NULL(name); 6081 DCHECK_NOT_NULL(name);
6110 if (!value->IsAnonymousFunctionDefinition()) return; 6082 if (!value->IsAnonymousFunctionDefinition()) return;
6111 auto function = value->AsFunctionLiteral(); 6083 auto function = value->AsFunctionLiteral();
6112 if (function != nullptr) { 6084 if (function != nullptr) {
6113 function->set_raw_name(name); 6085 function->set_raw_name(name);
6114 } else { 6086 } else {
6115 DCHECK(value->IsDoExpression()); 6087 DCHECK(value->IsDoExpression());
6116 value->AsDoExpression()->represented_function()->set_raw_name(name); 6088 value->AsDoExpression()->represented_function()->set_raw_name(name);
6117 } 6089 }
6118 } 6090 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
6191 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); 6163 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output);
6192 // } 6164 // }
6193 // 6165 //
6194 // IteratorClose(iterator, input, output) expands to the following: 6166 // IteratorClose(iterator, input, output) expands to the following:
6195 // 6167 //
6196 // let iteratorReturn = iterator.return; 6168 // let iteratorReturn = iterator.return;
6197 // if (IS_NULL_OR_UNDEFINED(iteratorReturn)) return input; 6169 // if (IS_NULL_OR_UNDEFINED(iteratorReturn)) return input;
6198 // output = %_Call(iteratorReturn, iterator, input); 6170 // output = %_Call(iteratorReturn, iterator, input);
6199 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); 6171 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output);
6200 6172
6201 Expression* ParserTraits::RewriteYieldStar( 6173 Expression* Parser::RewriteYieldStar(Expression* generator,
6202 Expression* generator, Expression* iterable, int pos) { 6174 Expression* iterable, int pos) {
6203 const int nopos = kNoSourcePosition; 6175 const int nopos = kNoSourcePosition;
6204 6176
6205 auto factory = parser_->factory();
6206 auto avfactory = parser_->ast_value_factory();
6207 auto zone = parser_->zone();
6208
6209
6210 // Forward definition for break/continue statements. 6177 // Forward definition for break/continue statements.
6211 WhileStatement* loop = factory->NewWhileStatement(nullptr, nopos); 6178 WhileStatement* loop = factory()->NewWhileStatement(nullptr, nopos);
6212
6213 6179
6214 // let input = undefined; 6180 // let input = undefined;
6215 Variable* var_input = parser_->NewTemporary(avfactory->empty_string()); 6181 Variable* var_input = NewTemporary(ast_value_factory()->empty_string());
6216 Statement* initialize_input; 6182 Statement* initialize_input;
6217 { 6183 {
6218 Expression* input_proxy = factory->NewVariableProxy(var_input); 6184 Expression* input_proxy = factory()->NewVariableProxy(var_input);
6219 Expression* assignment = factory->NewAssignment( 6185 Expression* assignment =
6220 Token::ASSIGN, input_proxy, factory->NewUndefinedLiteral(nopos), nopos); 6186 factory()->NewAssignment(Token::ASSIGN, input_proxy,
6221 initialize_input = factory->NewExpressionStatement(assignment, nopos); 6187 factory()->NewUndefinedLiteral(nopos), nopos);
6222 } 6188 initialize_input = factory()->NewExpressionStatement(assignment, nopos);
6223 6189 }
6224 6190
6225 // let mode = kNext; 6191 // let mode = kNext;
6226 Variable* var_mode = parser_->NewTemporary(avfactory->empty_string()); 6192 Variable* var_mode = NewTemporary(ast_value_factory()->empty_string());
6227 Statement* initialize_mode; 6193 Statement* initialize_mode;
6228 { 6194 {
6229 Expression* mode_proxy = factory->NewVariableProxy(var_mode); 6195 Expression* mode_proxy = factory()->NewVariableProxy(var_mode);
6230 Expression* knext = factory->NewSmiLiteral(JSGeneratorObject::kNext, nopos); 6196 Expression* knext =
6231 Expression* assignment = 6197 factory()->NewSmiLiteral(JSGeneratorObject::kNext, nopos);
6232 factory->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos); 6198 Expression* assignment =
6233 initialize_mode = factory->NewExpressionStatement(assignment, nopos); 6199 factory()->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos);
6234 } 6200 initialize_mode = factory()->NewExpressionStatement(assignment, nopos);
6235 6201 }
6236 6202
6237 // let output = undefined; 6203 // let output = undefined;
6238 Variable* var_output = parser_->NewTemporary(avfactory->empty_string()); 6204 Variable* var_output = NewTemporary(ast_value_factory()->empty_string());
6239 Statement* initialize_output; 6205 Statement* initialize_output;
6240 { 6206 {
6241 Expression* output_proxy = factory->NewVariableProxy(var_output); 6207 Expression* output_proxy = factory()->NewVariableProxy(var_output);
6242 Expression* assignment = factory->NewAssignment( 6208 Expression* assignment =
6243 Token::ASSIGN, output_proxy, factory->NewUndefinedLiteral(nopos), 6209 factory()->NewAssignment(Token::ASSIGN, output_proxy,
6244 nopos); 6210 factory()->NewUndefinedLiteral(nopos), nopos);
6245 initialize_output = factory->NewExpressionStatement(assignment, nopos); 6211 initialize_output = factory()->NewExpressionStatement(assignment, nopos);
6246 } 6212 }
6247
6248 6213
6249 // let iterator = iterable[Symbol.iterator]; 6214 // let iterator = iterable[Symbol.iterator];
6250 Variable* var_iterator = parser_->NewTemporary(avfactory->empty_string()); 6215 Variable* var_iterator = NewTemporary(ast_value_factory()->empty_string());
6251 Statement* get_iterator; 6216 Statement* get_iterator;
6252 { 6217 {
6253 Expression* iterator = GetIterator(iterable, factory, nopos); 6218 Expression* iterator = GetIterator(iterable, factory(), nopos);
6254 Expression* iterator_proxy = factory->NewVariableProxy(var_iterator); 6219 Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator);
6255 Expression* assignment = factory->NewAssignment( 6220 Expression* assignment = factory()->NewAssignment(
6256 Token::ASSIGN, iterator_proxy, iterator, nopos); 6221 Token::ASSIGN, iterator_proxy, iterator, nopos);
6257 get_iterator = factory->NewExpressionStatement(assignment, nopos); 6222 get_iterator = factory()->NewExpressionStatement(assignment, nopos);
6258 } 6223 }
6259
6260 6224
6261 // if (!IS_RECEIVER(iterator)) throw MakeTypeError(kSymbolIteratorInvalid); 6225 // if (!IS_RECEIVER(iterator)) throw MakeTypeError(kSymbolIteratorInvalid);
6262 Statement* validate_iterator; 6226 Statement* validate_iterator;
6263 { 6227 {
6264 Expression* is_receiver_call; 6228 Expression* is_receiver_call;
6265 { 6229 {
6266 auto args = new (zone) ZoneList<Expression*>(1, zone); 6230 auto args = new (zone()) ZoneList<Expression*>(1, zone());
6267 args->Add(factory->NewVariableProxy(var_iterator), zone); 6231 args->Add(factory()->NewVariableProxy(var_iterator), zone());
6268 is_receiver_call = 6232 is_receiver_call =
6269 factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos); 6233 factory()->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
6270 } 6234 }
6271 6235
6272 Statement* throw_call; 6236 Statement* throw_call;
6273 { 6237 {
6274 Expression* call = NewThrowTypeError( 6238 Expression* call =
6275 MessageTemplate::kSymbolIteratorInvalid, avfactory->empty_string(), 6239 NewThrowTypeError(MessageTemplate::kSymbolIteratorInvalid,
6276 nopos); 6240 ast_value_factory()->empty_string(), nopos);
6277 throw_call = factory->NewExpressionStatement(call, nopos); 6241 throw_call = factory()->NewExpressionStatement(call, nopos);
6278 } 6242 }
6279 6243
6280 validate_iterator = factory->NewIfStatement( 6244 validate_iterator = factory()->NewIfStatement(
6281 is_receiver_call, factory->NewEmptyStatement(nopos), throw_call, nopos); 6245 is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call,
6282 } 6246 nopos);
6283 6247 }
6284 6248
6285 // output = iterator.next(input); 6249 // output = iterator.next(input);
6286 Statement* call_next; 6250 Statement* call_next;
6287 { 6251 {
6288 Expression* iterator_proxy = factory->NewVariableProxy(var_iterator); 6252 Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator);
6289 Expression* literal = 6253 Expression* literal =
6290 factory->NewStringLiteral(avfactory->next_string(), nopos); 6254 factory()->NewStringLiteral(ast_value_factory()->next_string(), nopos);
6291 Expression* next_property = 6255 Expression* next_property =
6292 factory->NewProperty(iterator_proxy, literal, nopos); 6256 factory()->NewProperty(iterator_proxy, literal, nopos);
6293 Expression* input_proxy = factory->NewVariableProxy(var_input); 6257 Expression* input_proxy = factory()->NewVariableProxy(var_input);
6294 auto args = new (zone) ZoneList<Expression*>(1, zone); 6258 auto args = new (zone()) ZoneList<Expression*>(1, zone());
6295 args->Add(input_proxy, zone); 6259 args->Add(input_proxy, zone());
6296 Expression* call = factory->NewCall(next_property, args, nopos); 6260 Expression* call = factory()->NewCall(next_property, args, nopos);
6297 Expression* output_proxy = factory->NewVariableProxy(var_output); 6261 Expression* output_proxy = factory()->NewVariableProxy(var_output);
6298 Expression* assignment = 6262 Expression* assignment =
6299 factory->NewAssignment(Token::ASSIGN, output_proxy, call, nopos); 6263 factory()->NewAssignment(Token::ASSIGN, output_proxy, call, nopos);
6300 call_next = factory->NewExpressionStatement(assignment, nopos); 6264 call_next = factory()->NewExpressionStatement(assignment, nopos);
6301 } 6265 }
6302
6303 6266
6304 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); 6267 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output);
6305 Statement* validate_next_output; 6268 Statement* validate_next_output;
6306 { 6269 {
6307 Expression* is_receiver_call; 6270 Expression* is_receiver_call;
6308 { 6271 {
6309 auto args = new (zone) ZoneList<Expression*>(1, zone); 6272 auto args = new (zone()) ZoneList<Expression*>(1, zone());
6310 args->Add(factory->NewVariableProxy(var_output), zone); 6273 args->Add(factory()->NewVariableProxy(var_output), zone());
6311 is_receiver_call = 6274 is_receiver_call =
6312 factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos); 6275 factory()->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
6313 } 6276 }
6314 6277
6315 Statement* throw_call; 6278 Statement* throw_call;
6316 { 6279 {
6317 auto args = new (zone) ZoneList<Expression*>(1, zone); 6280 auto args = new (zone()) ZoneList<Expression*>(1, zone());
6318 args->Add(factory->NewVariableProxy(var_output), zone); 6281 args->Add(factory()->NewVariableProxy(var_output), zone());
6319 Expression* call = factory->NewCallRuntime( 6282 Expression* call = factory()->NewCallRuntime(
6320 Runtime::kThrowIteratorResultNotAnObject, args, nopos); 6283 Runtime::kThrowIteratorResultNotAnObject, args, nopos);
6321 throw_call = factory->NewExpressionStatement(call, nopos); 6284 throw_call = factory()->NewExpressionStatement(call, nopos);
6322 } 6285 }
6323 6286
6324 validate_next_output = factory->NewIfStatement( 6287 validate_next_output = factory()->NewIfStatement(
6325 is_receiver_call, factory->NewEmptyStatement(nopos), throw_call, nopos); 6288 is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call,
6326 } 6289 nopos);
6327 6290 }
6328 6291
6329 // let iteratorThrow = iterator.throw; 6292 // let iteratorThrow = iterator.throw;
6330 Variable* var_throw = parser_->NewTemporary(avfactory->empty_string()); 6293 Variable* var_throw = NewTemporary(ast_value_factory()->empty_string());
6331 Statement* get_throw; 6294 Statement* get_throw;
6332 { 6295 {
6333 Expression* iterator_proxy = factory->NewVariableProxy(var_iterator); 6296 Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator);
6334 Expression* literal = 6297 Expression* literal =
6335 factory->NewStringLiteral(avfactory->throw_string(), nopos); 6298 factory()->NewStringLiteral(ast_value_factory()->throw_string(), nopos);
6336 Expression* property = 6299 Expression* property =
6337 factory->NewProperty(iterator_proxy, literal, nopos); 6300 factory()->NewProperty(iterator_proxy, literal, nopos);
6338 Expression* throw_proxy = factory->NewVariableProxy(var_throw); 6301 Expression* throw_proxy = factory()->NewVariableProxy(var_throw);
6339 Expression* assignment = factory->NewAssignment( 6302 Expression* assignment =
6340 Token::ASSIGN, throw_proxy, property, nopos); 6303 factory()->NewAssignment(Token::ASSIGN, throw_proxy, property, nopos);
6341 get_throw = factory->NewExpressionStatement(assignment, nopos); 6304 get_throw = factory()->NewExpressionStatement(assignment, nopos);
6342 } 6305 }
6343
6344 6306
6345 // if (IS_NULL_OR_UNDEFINED(iteratorThrow) { 6307 // if (IS_NULL_OR_UNDEFINED(iteratorThrow) {
6346 // IteratorClose(iterator); 6308 // IteratorClose(iterator);
6347 // throw MakeTypeError(kThrowMethodMissing); 6309 // throw MakeTypeError(kThrowMethodMissing);
6348 // } 6310 // }
6349 Statement* check_throw; 6311 Statement* check_throw;
6350 { 6312 {
6351 Expression* condition = factory->NewCompareOperation( 6313 Expression* condition = factory()->NewCompareOperation(
6352 Token::EQ, factory->NewVariableProxy(var_throw), 6314 Token::EQ, factory()->NewVariableProxy(var_throw),
6353 factory->NewNullLiteral(nopos), nopos); 6315 factory()->NewNullLiteral(nopos), nopos);
6354 6316 Expression* call =
6355 Expression* call = NewThrowTypeError( 6317 NewThrowTypeError(MessageTemplate::kThrowMethodMissing,
6356 MessageTemplate::kThrowMethodMissing, 6318 ast_value_factory()->empty_string(), nopos);
6357 avfactory->empty_string(), nopos); 6319 Statement* throw_call = factory()->NewExpressionStatement(call, nopos);
6358 Statement* throw_call = factory->NewExpressionStatement(call, nopos); 6320
6359 6321 Block* then = factory()->NewBlock(nullptr, 4 + 1, false, nopos);
6360 Block* then = factory->NewBlock(nullptr, 4+1, false, nopos); 6322 BuildIteratorCloseForCompletion(
6361 parser_->BuildIteratorCloseForCompletion(
6362 then->statements(), var_iterator, 6323 then->statements(), var_iterator,
6363 factory->NewSmiLiteral(Parser::kNormalCompletion, nopos)); 6324 factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos));
6364 then->statements()->Add(throw_call, zone); 6325 then->statements()->Add(throw_call, zone());
6365 check_throw = factory->NewIfStatement( 6326 check_throw = factory()->NewIfStatement(
6366 condition, then, factory->NewEmptyStatement(nopos), nopos); 6327 condition, then, factory()->NewEmptyStatement(nopos), nopos);
6367 } 6328 }
6368
6369 6329
6370 // output = %_Call(iteratorThrow, iterator, input); 6330 // output = %_Call(iteratorThrow, iterator, input);
6371 Statement* call_throw; 6331 Statement* call_throw;
6372 { 6332 {
6373 auto args = new (zone) ZoneList<Expression*>(3, zone); 6333 auto args = new (zone()) ZoneList<Expression*>(3, zone());
6374 args->Add(factory->NewVariableProxy(var_throw), zone); 6334 args->Add(factory()->NewVariableProxy(var_throw), zone());
6375 args->Add(factory->NewVariableProxy(var_iterator), zone); 6335 args->Add(factory()->NewVariableProxy(var_iterator), zone());
6376 args->Add(factory->NewVariableProxy(var_input), zone); 6336 args->Add(factory()->NewVariableProxy(var_input), zone());
6377 Expression* call = 6337 Expression* call =
6378 factory->NewCallRuntime(Runtime::kInlineCall, args, nopos); 6338 factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos);
6379 Expression* assignment = factory->NewAssignment( 6339 Expression* assignment = factory()->NewAssignment(
6380 Token::ASSIGN, factory->NewVariableProxy(var_output), call, nopos); 6340 Token::ASSIGN, factory()->NewVariableProxy(var_output), call, nopos);
6381 call_throw = factory->NewExpressionStatement(assignment, nopos); 6341 call_throw = factory()->NewExpressionStatement(assignment, nopos);
6382 } 6342 }
6383
6384 6343
6385 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); 6344 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output);
6386 Statement* validate_throw_output; 6345 Statement* validate_throw_output;
6387 { 6346 {
6388 Expression* is_receiver_call; 6347 Expression* is_receiver_call;
6389 { 6348 {
6390 auto args = new (zone) ZoneList<Expression*>(1, zone); 6349 auto args = new (zone()) ZoneList<Expression*>(1, zone());
6391 args->Add(factory->NewVariableProxy(var_output), zone); 6350 args->Add(factory()->NewVariableProxy(var_output), zone());
6392 is_receiver_call = 6351 is_receiver_call =
6393 factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos); 6352 factory()->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
6394 } 6353 }
6395 6354
6396 Statement* throw_call; 6355 Statement* throw_call;
6397 { 6356 {
6398 auto args = new (zone) ZoneList<Expression*>(1, zone); 6357 auto args = new (zone()) ZoneList<Expression*>(1, zone());
6399 args->Add(factory->NewVariableProxy(var_output), zone); 6358 args->Add(factory()->NewVariableProxy(var_output), zone());
6400 Expression* call = factory->NewCallRuntime( 6359 Expression* call = factory()->NewCallRuntime(
6401 Runtime::kThrowIteratorResultNotAnObject, args, nopos); 6360 Runtime::kThrowIteratorResultNotAnObject, args, nopos);
6402 throw_call = factory->NewExpressionStatement(call, nopos); 6361 throw_call = factory()->NewExpressionStatement(call, nopos);
6403 } 6362 }
6404 6363
6405 validate_throw_output = factory->NewIfStatement( 6364 validate_throw_output = factory()->NewIfStatement(
6406 is_receiver_call, factory->NewEmptyStatement(nopos), throw_call, nopos); 6365 is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call,
6407 } 6366 nopos);
6408 6367 }
6409 6368
6410 // if (output.done) break; 6369 // if (output.done) break;
6411 Statement* if_done; 6370 Statement* if_done;
6412 { 6371 {
6413 Expression* output_proxy = factory->NewVariableProxy(var_output); 6372 Expression* output_proxy = factory()->NewVariableProxy(var_output);
6414 Expression* literal = 6373 Expression* literal =
6415 factory->NewStringLiteral(avfactory->done_string(), nopos); 6374 factory()->NewStringLiteral(ast_value_factory()->done_string(), nopos);
6416 Expression* property = factory->NewProperty(output_proxy, literal, nopos); 6375 Expression* property = factory()->NewProperty(output_proxy, literal, nopos);
6417 BreakStatement* break_loop = factory->NewBreakStatement(loop, nopos); 6376 BreakStatement* break_loop = factory()->NewBreakStatement(loop, nopos);
6418 if_done = factory->NewIfStatement( 6377 if_done = factory()->NewIfStatement(
6419 property, break_loop, factory->NewEmptyStatement(nopos), nopos); 6378 property, break_loop, factory()->NewEmptyStatement(nopos), nopos);
6420 } 6379 }
6421 6380
6422 6381
6423 // mode = kReturn; 6382 // mode = kReturn;
6424 Statement* set_mode_return; 6383 Statement* set_mode_return;
6425 { 6384 {
6426 Expression* mode_proxy = factory->NewVariableProxy(var_mode); 6385 Expression* mode_proxy = factory()->NewVariableProxy(var_mode);
6427 Expression* kreturn = 6386 Expression* kreturn =
6428 factory->NewSmiLiteral(JSGeneratorObject::kReturn, nopos); 6387 factory()->NewSmiLiteral(JSGeneratorObject::kReturn, nopos);
6429 Expression* assignment = 6388 Expression* assignment =
6430 factory->NewAssignment(Token::ASSIGN, mode_proxy, kreturn, nopos); 6389 factory()->NewAssignment(Token::ASSIGN, mode_proxy, kreturn, nopos);
6431 set_mode_return = factory->NewExpressionStatement(assignment, nopos); 6390 set_mode_return = factory()->NewExpressionStatement(assignment, nopos);
6432 } 6391 }
6433 6392
6434 // Yield(output); 6393 // Yield(output);
6435 Statement* yield_output; 6394 Statement* yield_output;
6436 { 6395 {
6437 Expression* output_proxy = factory->NewVariableProxy(var_output); 6396 Expression* output_proxy = factory()->NewVariableProxy(var_output);
6438 Yield* yield = factory->NewYield(generator, output_proxy, nopos, 6397 Yield* yield = factory()->NewYield(generator, output_proxy, nopos,
6439 Yield::kOnExceptionThrow); 6398 Yield::kOnExceptionThrow);
6440 yield_output = factory->NewExpressionStatement(yield, nopos); 6399 yield_output = factory()->NewExpressionStatement(yield, nopos);
6441 } 6400 }
6442
6443 6401
6444 // mode = kNext; 6402 // mode = kNext;
6445 Statement* set_mode_next; 6403 Statement* set_mode_next;
6446 { 6404 {
6447 Expression* mode_proxy = factory->NewVariableProxy(var_mode); 6405 Expression* mode_proxy = factory()->NewVariableProxy(var_mode);
6448 Expression* knext = factory->NewSmiLiteral(JSGeneratorObject::kNext, nopos); 6406 Expression* knext =
6449 Expression* assignment = 6407 factory()->NewSmiLiteral(JSGeneratorObject::kNext, nopos);
6450 factory->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos); 6408 Expression* assignment =
6451 set_mode_next = factory->NewExpressionStatement(assignment, nopos); 6409 factory()->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos);
6452 } 6410 set_mode_next = factory()->NewExpressionStatement(assignment, nopos);
6453 6411 }
6454 6412
6455 // mode = kThrow; 6413 // mode = kThrow;
6456 Statement* set_mode_throw; 6414 Statement* set_mode_throw;
6457 { 6415 {
6458 Expression* mode_proxy = factory->NewVariableProxy(var_mode); 6416 Expression* mode_proxy = factory()->NewVariableProxy(var_mode);
6459 Expression* kthrow = 6417 Expression* kthrow =
6460 factory->NewSmiLiteral(JSGeneratorObject::kThrow, nopos); 6418 factory()->NewSmiLiteral(JSGeneratorObject::kThrow, nopos);
6461 Expression* assignment = 6419 Expression* assignment =
6462 factory->NewAssignment(Token::ASSIGN, mode_proxy, kthrow, nopos); 6420 factory()->NewAssignment(Token::ASSIGN, mode_proxy, kthrow, nopos);
6463 set_mode_throw = factory->NewExpressionStatement(assignment, nopos); 6421 set_mode_throw = factory()->NewExpressionStatement(assignment, nopos);
6464 } 6422 }
6465
6466 6423
6467 // input = function.sent; 6424 // input = function.sent;
6468 Statement* get_input; 6425 Statement* get_input;
6469 { 6426 {
6470 Expression* function_sent = FunctionSentExpression(factory, nopos); 6427 Expression* function_sent = FunctionSentExpression(factory(), nopos);
6471 Expression* input_proxy = factory->NewVariableProxy(var_input); 6428 Expression* input_proxy = factory()->NewVariableProxy(var_input);
6472 Expression* assignment = factory->NewAssignment( 6429 Expression* assignment = factory()->NewAssignment(
6473 Token::ASSIGN, input_proxy, function_sent, nopos); 6430 Token::ASSIGN, input_proxy, function_sent, nopos);
6474 get_input = factory->NewExpressionStatement(assignment, nopos); 6431 get_input = factory()->NewExpressionStatement(assignment, nopos);
6475 } 6432 }
6476
6477 6433
6478 // if (mode === kReturn) { 6434 // if (mode === kReturn) {
6479 // return {value: output.value, done: true}; 6435 // return {value: output.value, done: true};
6480 // } 6436 // }
6481 Statement* maybe_return_value; 6437 Statement* maybe_return_value;
6482 { 6438 {
6483 Expression* mode_proxy = factory->NewVariableProxy(var_mode); 6439 Expression* mode_proxy = factory()->NewVariableProxy(var_mode);
6484 Expression* kreturn = 6440 Expression* kreturn =
6485 factory->NewSmiLiteral(JSGeneratorObject::kReturn, nopos); 6441 factory()->NewSmiLiteral(JSGeneratorObject::kReturn, nopos);
6486 Expression* condition = factory->NewCompareOperation( 6442 Expression* condition = factory()->NewCompareOperation(
6487 Token::EQ_STRICT, mode_proxy, kreturn, nopos); 6443 Token::EQ_STRICT, mode_proxy, kreturn, nopos);
6488 6444
6489 Expression* output_proxy = factory->NewVariableProxy(var_output); 6445 Expression* output_proxy = factory()->NewVariableProxy(var_output);
6490 Expression* literal = 6446 Expression* literal =
6491 factory->NewStringLiteral(avfactory->value_string(), nopos); 6447 factory()->NewStringLiteral(ast_value_factory()->value_string(), nopos);
6492 Expression* property = factory->NewProperty(output_proxy, literal, nopos); 6448 Expression* property = factory()->NewProperty(output_proxy, literal, nopos);
6493 Statement* return_value = 6449 Statement* return_value = factory()->NewReturnStatement(
6494 factory->NewReturnStatement(BuildIteratorResult(property, true), nopos); 6450 BuildIteratorResult(property, true), nopos);
6495 6451
6496 maybe_return_value = factory->NewIfStatement( 6452 maybe_return_value = factory()->NewIfStatement(
6497 condition, return_value, factory->NewEmptyStatement(nopos), nopos); 6453 condition, return_value, factory()->NewEmptyStatement(nopos), nopos);
6498 } 6454 }
6499
6500 6455
6501 // output.value 6456 // output.value
6502 Statement* get_value; 6457 Statement* get_value;
6503 { 6458 {
6504 Expression* output_proxy = factory->NewVariableProxy(var_output); 6459 Expression* output_proxy = factory()->NewVariableProxy(var_output);
6505 Expression* literal = 6460 Expression* literal =
6506 factory->NewStringLiteral(avfactory->value_string(), nopos); 6461 factory()->NewStringLiteral(ast_value_factory()->value_string(), nopos);
6507 Expression* property = factory->NewProperty(output_proxy, literal, nopos); 6462 Expression* property = factory()->NewProperty(output_proxy, literal, nopos);
6508 get_value = factory->NewExpressionStatement(property, nopos); 6463 get_value = factory()->NewExpressionStatement(property, nopos);
6509 } 6464 }
6510
6511 6465
6512 // Now put things together. 6466 // Now put things together.
6513 6467
6514
6515 // try { ... } catch(e) { ... } 6468 // try { ... } catch(e) { ... }
6516 Statement* try_catch; 6469 Statement* try_catch;
6517 { 6470 {
6518 Block* try_block = factory->NewBlock(nullptr, 2, false, nopos); 6471 Block* try_block = factory()->NewBlock(nullptr, 2, false, nopos);
6519 try_block->statements()->Add(yield_output, zone); 6472 try_block->statements()->Add(yield_output, zone());
6520 try_block->statements()->Add(set_mode_next, zone); 6473 try_block->statements()->Add(set_mode_next, zone());
6521 6474
6522 Block* catch_block = factory->NewBlock(nullptr, 1, false, nopos); 6475 Block* catch_block = factory()->NewBlock(nullptr, 1, false, nopos);
6523 catch_block->statements()->Add(set_mode_throw, zone); 6476 catch_block->statements()->Add(set_mode_throw, zone());
6524 6477
6525 Scope* catch_scope = NewScope(CATCH_SCOPE); 6478 Scope* catch_scope = NewScope(CATCH_SCOPE);
6526 catch_scope->set_is_hidden(); 6479 catch_scope->set_is_hidden();
6527 const AstRawString* name = avfactory->dot_catch_string(); 6480 const AstRawString* name = ast_value_factory()->dot_catch_string();
6528 Variable* catch_variable = 6481 Variable* catch_variable =
6529 catch_scope->DeclareLocal(name, VAR, kCreatedInitialized, 6482 catch_scope->DeclareLocal(name, VAR, kCreatedInitialized,
6530 Variable::NORMAL); 6483 Variable::NORMAL);
6531 6484
6532 try_catch = factory->NewTryCatchStatementForDesugaring( 6485 try_catch = factory()->NewTryCatchStatementForDesugaring(
6533 try_block, catch_scope, catch_variable, catch_block, nopos); 6486 try_block, catch_scope, catch_variable, catch_block, nopos);
6534 } 6487 }
6535 6488
6536
6537 // try { ... } finally { ... } 6489 // try { ... } finally { ... }
6538 Statement* try_finally; 6490 Statement* try_finally;
6539 { 6491 {
6540 Block* try_block = factory->NewBlock(nullptr, 1, false, nopos); 6492 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos);
6541 try_block->statements()->Add(try_catch, zone); 6493 try_block->statements()->Add(try_catch, zone());
6542 6494
6543 Block* finally = factory->NewBlock(nullptr, 2, false, nopos); 6495 Block* finally = factory()->NewBlock(nullptr, 2, false, nopos);
6544 finally->statements()->Add(get_input, zone); 6496 finally->statements()->Add(get_input, zone());
6545 finally->statements()->Add( 6497 finally->statements()->Add(factory()->NewContinueStatement(loop, nopos),
6546 factory->NewContinueStatement(loop, nopos), zone); 6498 zone());
6547 6499
6548 try_finally = factory->NewTryFinallyStatement(try_block, finally, nopos); 6500 try_finally = factory()->NewTryFinallyStatement(try_block, finally, nopos);
6549 } 6501 }
6550
6551 6502
6552 // switch (mode) { ... } 6503 // switch (mode) { ... }
6553 SwitchStatement* switch_mode = factory->NewSwitchStatement(nullptr, nopos); 6504 SwitchStatement* switch_mode = factory()->NewSwitchStatement(nullptr, nopos);
6554 { 6505 {
6555 auto case_next = new (zone) ZoneList<Statement*>(3, zone); 6506 auto case_next = new (zone()) ZoneList<Statement*>(3, zone());
6556 case_next->Add(call_next, zone); 6507 case_next->Add(call_next, zone());
6557 case_next->Add(validate_next_output, zone); 6508 case_next->Add(validate_next_output, zone());
6558 case_next->Add(factory->NewBreakStatement(switch_mode, nopos), zone); 6509 case_next->Add(factory()->NewBreakStatement(switch_mode, nopos), zone());
6559 6510
6560 auto case_return = new (zone) ZoneList<Statement*>(5, zone); 6511 auto case_return = new (zone()) ZoneList<Statement*>(5, zone());
6561 BuildIteratorClose(case_return, var_iterator, var_input, var_output); 6512 BuildIteratorClose(case_return, var_iterator, var_input, var_output);
6562 case_return->Add(factory->NewBreakStatement(switch_mode, nopos), zone); 6513 case_return->Add(factory()->NewBreakStatement(switch_mode, nopos), zone());
6563 6514
6564 auto case_throw = new (zone) ZoneList<Statement*>(5, zone); 6515 auto case_throw = new (zone()) ZoneList<Statement*>(5, zone());
6565 case_throw->Add(get_throw, zone); 6516 case_throw->Add(get_throw, zone());
6566 case_throw->Add(check_throw, zone); 6517 case_throw->Add(check_throw, zone());
6567 case_throw->Add(call_throw, zone); 6518 case_throw->Add(call_throw, zone());
6568 case_throw->Add(validate_throw_output, zone); 6519 case_throw->Add(validate_throw_output, zone());
6569 case_throw->Add(factory->NewBreakStatement(switch_mode, nopos), zone); 6520 case_throw->Add(factory()->NewBreakStatement(switch_mode, nopos), zone());
6570 6521
6571 auto cases = new (zone) ZoneList<CaseClause*>(3, zone); 6522 auto cases = new (zone()) ZoneList<CaseClause*>(3, zone());
6572 Expression* knext = factory->NewSmiLiteral(JSGeneratorObject::kNext, nopos); 6523 Expression* knext =
6524 factory()->NewSmiLiteral(JSGeneratorObject::kNext, nopos);
6573 Expression* kreturn = 6525 Expression* kreturn =
6574 factory->NewSmiLiteral(JSGeneratorObject::kReturn, nopos); 6526 factory()->NewSmiLiteral(JSGeneratorObject::kReturn, nopos);
6575 Expression* kthrow = 6527 Expression* kthrow =
6576 factory->NewSmiLiteral(JSGeneratorObject::kThrow, nopos); 6528 factory()->NewSmiLiteral(JSGeneratorObject::kThrow, nopos);
6577 cases->Add(factory->NewCaseClause(knext, case_next, nopos), zone); 6529 cases->Add(factory()->NewCaseClause(knext, case_next, nopos), zone());
6578 cases->Add(factory->NewCaseClause(kreturn, case_return, nopos), zone); 6530 cases->Add(factory()->NewCaseClause(kreturn, case_return, nopos), zone());
6579 cases->Add(factory->NewCaseClause(kthrow, case_throw, nopos), zone); 6531 cases->Add(factory()->NewCaseClause(kthrow, case_throw, nopos), zone());
6580 6532
6581 switch_mode->Initialize(factory->NewVariableProxy(var_mode), cases); 6533 switch_mode->Initialize(factory()->NewVariableProxy(var_mode), cases);
6582 } 6534 }
6583
6584 6535
6585 // while (true) { ... } 6536 // while (true) { ... }
6586 // Already defined earlier: WhileStatement* loop = ... 6537 // Already defined earlier: WhileStatement* loop = ...
6587 { 6538 {
6588 Block* loop_body = factory->NewBlock(nullptr, 4, false, nopos); 6539 Block* loop_body = factory()->NewBlock(nullptr, 4, false, nopos);
6589 loop_body->statements()->Add(switch_mode, zone); 6540 loop_body->statements()->Add(switch_mode, zone());
6590 loop_body->statements()->Add(if_done, zone); 6541 loop_body->statements()->Add(if_done, zone());
6591 loop_body->statements()->Add(set_mode_return, zone); 6542 loop_body->statements()->Add(set_mode_return, zone());
6592 loop_body->statements()->Add(try_finally, zone); 6543 loop_body->statements()->Add(try_finally, zone());
6593 6544
6594 loop->Initialize(factory->NewBooleanLiteral(true, nopos), loop_body); 6545 loop->Initialize(factory()->NewBooleanLiteral(true, nopos), loop_body);
6595 } 6546 }
6596
6597 6547
6598 // do { ... } 6548 // do { ... }
6599 DoExpression* yield_star; 6549 DoExpression* yield_star;
6600 { 6550 {
6601 // The rewriter needs to process the get_value statement only, hence we 6551 // The rewriter needs to process the get_value statement only, hence we
6602 // put the preceding statements into an init block. 6552 // put the preceding statements into an init block.
6603 6553
6604 Block* do_block_ = factory->NewBlock(nullptr, 7, true, nopos); 6554 Block* do_block_ = factory()->NewBlock(nullptr, 7, true, nopos);
6605 do_block_->statements()->Add(initialize_input, zone); 6555 do_block_->statements()->Add(initialize_input, zone());
6606 do_block_->statements()->Add(initialize_mode, zone); 6556 do_block_->statements()->Add(initialize_mode, zone());
6607 do_block_->statements()->Add(initialize_output, zone); 6557 do_block_->statements()->Add(initialize_output, zone());
6608 do_block_->statements()->Add(get_iterator, zone); 6558 do_block_->statements()->Add(get_iterator, zone());
6609 do_block_->statements()->Add(validate_iterator, zone); 6559 do_block_->statements()->Add(validate_iterator, zone());
6610 do_block_->statements()->Add(loop, zone); 6560 do_block_->statements()->Add(loop, zone());
6611 do_block_->statements()->Add(maybe_return_value, zone); 6561 do_block_->statements()->Add(maybe_return_value, zone());
6612 6562
6613 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); 6563 Block* do_block = factory()->NewBlock(nullptr, 2, false, nopos);
6614 do_block->statements()->Add(do_block_, zone); 6564 do_block->statements()->Add(do_block_, zone());
6615 do_block->statements()->Add(get_value, zone); 6565 do_block->statements()->Add(get_value, zone());
6616 6566
6617 Variable* dot_result = 6567 Variable* dot_result =
6618 parser_->NewTemporary(avfactory->dot_result_string()); 6568 NewTemporary(ast_value_factory()->dot_result_string());
6619 yield_star = factory->NewDoExpression(do_block, dot_result, nopos); 6569 yield_star = factory()->NewDoExpression(do_block, dot_result, nopos);
6620 Rewriter::Rewrite(parser_, parser_->GetClosureScope(), yield_star, 6570 Rewriter::Rewrite(this, GetClosureScope(), yield_star, ast_value_factory());
6621 avfactory);
6622 } 6571 }
6623 6572
6624 return yield_star; 6573 return yield_star;
6625 } 6574 }
6626 6575
6627 Statement* ParserTraits::CheckCallable(Variable* var, Expression* error, 6576 Statement* Parser::CheckCallable(Variable* var, Expression* error, int pos) {
6628 int pos) {
6629 auto factory = parser_->factory();
6630 auto avfactory = parser_->ast_value_factory();
6631 const int nopos = kNoSourcePosition; 6577 const int nopos = kNoSourcePosition;
6632 Statement* validate_var; 6578 Statement* validate_var;
6633 { 6579 {
6634 Expression* type_of = factory->NewUnaryOperation( 6580 Expression* type_of = factory()->NewUnaryOperation(
6635 Token::TYPEOF, factory->NewVariableProxy(var), nopos); 6581 Token::TYPEOF, factory()->NewVariableProxy(var), nopos);
6636 Expression* function_literal = 6582 Expression* function_literal = factory()->NewStringLiteral(
6637 factory->NewStringLiteral(avfactory->function_string(), nopos); 6583 ast_value_factory()->function_string(), nopos);
6638 Expression* condition = factory->NewCompareOperation( 6584 Expression* condition = factory()->NewCompareOperation(
6639 Token::EQ_STRICT, type_of, function_literal, nopos); 6585 Token::EQ_STRICT, type_of, function_literal, nopos);
6640 6586
6641 Statement* throw_call = factory->NewExpressionStatement(error, pos); 6587 Statement* throw_call = factory()->NewExpressionStatement(error, pos);
6642 6588
6643 validate_var = factory->NewIfStatement( 6589 validate_var = factory()->NewIfStatement(
6644 condition, factory->NewEmptyStatement(nopos), throw_call, nopos); 6590 condition, factory()->NewEmptyStatement(nopos), throw_call, nopos);
6645 } 6591 }
6646 return validate_var; 6592 return validate_var;
6647 } 6593 }
6648 6594
6649 void ParserTraits::BuildIteratorClose(ZoneList<Statement*>* statements, 6595 void Parser::BuildIteratorClose(ZoneList<Statement*>* statements,
6650 Variable* iterator, Variable* input, 6596 Variable* iterator, Variable* input,
6651 Variable* var_output) { 6597 Variable* var_output) {
6652 // 6598 //
6653 // This function adds four statements to [statements], corresponding to the 6599 // This function adds four statements to [statements], corresponding to the
6654 // following code: 6600 // following code:
6655 // 6601 //
6656 // let iteratorReturn = iterator.return; 6602 // let iteratorReturn = iterator.return;
6657 // if (IS_NULL_OR_UNDEFINED(iteratorReturn) { 6603 // if (IS_NULL_OR_UNDEFINED(iteratorReturn) {
6658 // return {value: input, done: true}; 6604 // return {value: input, done: true};
6659 // } 6605 // }
6660 // output = %_Call(iteratorReturn, iterator, input); 6606 // output = %_Call(iteratorReturn, iterator, input);
6661 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); 6607 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output);
6662 // 6608 //
6663 6609
6664 const int nopos = kNoSourcePosition; 6610 const int nopos = kNoSourcePosition;
6665 auto factory = parser_->factory();
6666 auto avfactory = parser_->ast_value_factory();
6667 auto zone = parser_->zone();
6668 6611
6669 // let iteratorReturn = iterator.return; 6612 // let iteratorReturn = iterator.return;
6670 Variable* var_return = var_output; // Reusing the output variable. 6613 Variable* var_return = var_output; // Reusing the output variable.
6671 Statement* get_return; 6614 Statement* get_return;
6672 { 6615 {
6673 Expression* iterator_proxy = factory->NewVariableProxy(iterator); 6616 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
6674 Expression* literal = 6617 Expression* literal = factory()->NewStringLiteral(
6675 factory->NewStringLiteral(avfactory->return_string(), nopos); 6618 ast_value_factory()->return_string(), nopos);
6676 Expression* property = 6619 Expression* property =
6677 factory->NewProperty(iterator_proxy, literal, nopos); 6620 factory()->NewProperty(iterator_proxy, literal, nopos);
6678 Expression* return_proxy = factory->NewVariableProxy(var_return); 6621 Expression* return_proxy = factory()->NewVariableProxy(var_return);
6679 Expression* assignment = factory->NewAssignment( 6622 Expression* assignment =
6680 Token::ASSIGN, return_proxy, property, nopos); 6623 factory()->NewAssignment(Token::ASSIGN, return_proxy, property, nopos);
6681 get_return = factory->NewExpressionStatement(assignment, nopos); 6624 get_return = factory()->NewExpressionStatement(assignment, nopos);
6682 } 6625 }
6683 6626
6684 // if (IS_NULL_OR_UNDEFINED(iteratorReturn) { 6627 // if (IS_NULL_OR_UNDEFINED(iteratorReturn) {
6685 // return {value: input, done: true}; 6628 // return {value: input, done: true};
6686 // } 6629 // }
6687 Statement* check_return; 6630 Statement* check_return;
6688 { 6631 {
6689 Expression* condition = factory->NewCompareOperation( 6632 Expression* condition = factory()->NewCompareOperation(
6690 Token::EQ, factory->NewVariableProxy(var_return), 6633 Token::EQ, factory()->NewVariableProxy(var_return),
6691 factory->NewNullLiteral(nopos), nopos); 6634 factory()->NewNullLiteral(nopos), nopos);
6692 6635
6693 Expression* value = factory->NewVariableProxy(input); 6636 Expression* value = factory()->NewVariableProxy(input);
6694 6637
6695 Statement* return_input = 6638 Statement* return_input =
6696 factory->NewReturnStatement(BuildIteratorResult(value, true), nopos); 6639 factory()->NewReturnStatement(BuildIteratorResult(value, true), nopos);
6697 6640
6698 check_return = factory->NewIfStatement( 6641 check_return = factory()->NewIfStatement(
6699 condition, return_input, factory->NewEmptyStatement(nopos), nopos); 6642 condition, return_input, factory()->NewEmptyStatement(nopos), nopos);
6700 } 6643 }
6701 6644
6702 // output = %_Call(iteratorReturn, iterator, input); 6645 // output = %_Call(iteratorReturn, iterator, input);
6703 Statement* call_return; 6646 Statement* call_return;
6704 { 6647 {
6705 auto args = new (zone) ZoneList<Expression*>(3, zone); 6648 auto args = new (zone()) ZoneList<Expression*>(3, zone());
6706 args->Add(factory->NewVariableProxy(var_return), zone); 6649 args->Add(factory()->NewVariableProxy(var_return), zone());
6707 args->Add(factory->NewVariableProxy(iterator), zone); 6650 args->Add(factory()->NewVariableProxy(iterator), zone());
6708 args->Add(factory->NewVariableProxy(input), zone); 6651 args->Add(factory()->NewVariableProxy(input), zone());
6709 6652
6710 Expression* call = 6653 Expression* call =
6711 factory->NewCallRuntime(Runtime::kInlineCall, args, nopos); 6654 factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos);
6712 Expression* output_proxy = factory->NewVariableProxy(var_output); 6655 Expression* output_proxy = factory()->NewVariableProxy(var_output);
6713 Expression* assignment = factory->NewAssignment( 6656 Expression* assignment =
6714 Token::ASSIGN, output_proxy, call, nopos); 6657 factory()->NewAssignment(Token::ASSIGN, output_proxy, call, nopos);
6715 call_return = factory->NewExpressionStatement(assignment, nopos); 6658 call_return = factory()->NewExpressionStatement(assignment, nopos);
6716 } 6659 }
6717 6660
6718 // if (!IS_RECEIVER(output)) %ThrowIteratorResultNotAnObject(output); 6661 // if (!IS_RECEIVER(output)) %ThrowIteratorResultNotAnObject(output);
6719 Statement* validate_output; 6662 Statement* validate_output;
6720 { 6663 {
6721 Expression* is_receiver_call; 6664 Expression* is_receiver_call;
6722 { 6665 {
6723 auto args = new (zone) ZoneList<Expression*>(1, zone); 6666 auto args = new (zone()) ZoneList<Expression*>(1, zone());
6724 args->Add(factory->NewVariableProxy(var_output), zone); 6667 args->Add(factory()->NewVariableProxy(var_output), zone());
6725 is_receiver_call = 6668 is_receiver_call =
6726 factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos); 6669 factory()->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
6727 } 6670 }
6728 6671
6729 Statement* throw_call; 6672 Statement* throw_call;
6730 { 6673 {
6731 auto args = new (zone) ZoneList<Expression*>(1, zone); 6674 auto args = new (zone()) ZoneList<Expression*>(1, zone());
6732 args->Add(factory->NewVariableProxy(var_output), zone); 6675 args->Add(factory()->NewVariableProxy(var_output), zone());
6733 Expression* call = factory->NewCallRuntime( 6676 Expression* call = factory()->NewCallRuntime(
6734 Runtime::kThrowIteratorResultNotAnObject, args, nopos); 6677 Runtime::kThrowIteratorResultNotAnObject, args, nopos);
6735 throw_call = factory->NewExpressionStatement(call, nopos); 6678 throw_call = factory()->NewExpressionStatement(call, nopos);
6736 } 6679 }
6737 6680
6738 validate_output = factory->NewIfStatement( 6681 validate_output = factory()->NewIfStatement(
6739 is_receiver_call, factory->NewEmptyStatement(nopos), throw_call, nopos); 6682 is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call,
6683 nopos);
6740 } 6684 }
6741 6685
6742 statements->Add(get_return, zone); 6686 statements->Add(get_return, zone());
6743 statements->Add(check_return, zone); 6687 statements->Add(check_return, zone());
6744 statements->Add(call_return, zone); 6688 statements->Add(call_return, zone());
6745 statements->Add(validate_output, zone); 6689 statements->Add(validate_output, zone());
6746 } 6690 }
6747 6691
6748 void ParserTraits::FinalizeIteratorUse(Variable* completion, 6692 void Parser::FinalizeIteratorUse(Variable* completion, Expression* condition,
6749 Expression* condition, Variable* iter, 6693 Variable* iter, Block* iterator_use,
6750 Block* iterator_use, Block* target) { 6694 Block* target) {
6751 // 6695 //
6752 // This function adds two statements to [target], corresponding to the 6696 // This function adds two statements to [target], corresponding to the
6753 // following code: 6697 // following code:
6754 // 6698 //
6755 // completion = kNormalCompletion; 6699 // completion = kNormalCompletion;
6756 // try { 6700 // try {
6757 // try { 6701 // try {
6758 // iterator_use 6702 // iterator_use
6759 // } catch(e) { 6703 // } catch(e) {
6760 // if (completion === kAbruptCompletion) completion = kThrowCompletion; 6704 // if (completion === kAbruptCompletion) completion = kThrowCompletion;
6761 // %ReThrow(e); 6705 // %ReThrow(e);
6762 // } 6706 // }
6763 // } finally { 6707 // } finally {
6764 // if (condition) { 6708 // if (condition) {
6765 // #BuildIteratorCloseForCompletion(iter, completion) 6709 // #BuildIteratorCloseForCompletion(iter, completion)
6766 // } 6710 // }
6767 // } 6711 // }
6768 // 6712 //
6769 6713
6770 const int nopos = kNoSourcePosition; 6714 const int nopos = kNoSourcePosition;
6771 auto factory = parser_->factory();
6772 auto avfactory = parser_->ast_value_factory();
6773 auto scope = parser_->scope();
6774 auto zone = parser_->zone();
6775 6715
6776 // completion = kNormalCompletion; 6716 // completion = kNormalCompletion;
6777 Statement* initialize_completion; 6717 Statement* initialize_completion;
6778 { 6718 {
6779 Expression* proxy = factory->NewVariableProxy(completion); 6719 Expression* proxy = factory()->NewVariableProxy(completion);
6780 Expression* assignment = factory->NewAssignment( 6720 Expression* assignment = factory()->NewAssignment(
6781 Token::ASSIGN, proxy, 6721 Token::ASSIGN, proxy,
6782 factory->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos); 6722 factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos);
6783 initialize_completion = factory->NewExpressionStatement(assignment, nopos); 6723 initialize_completion =
6724 factory()->NewExpressionStatement(assignment, nopos);
6784 } 6725 }
6785 6726
6786 // if (completion === kAbruptCompletion) completion = kThrowCompletion; 6727 // if (completion === kAbruptCompletion) completion = kThrowCompletion;
6787 Statement* set_completion_throw; 6728 Statement* set_completion_throw;
6788 { 6729 {
6789 Expression* condition = factory->NewCompareOperation( 6730 Expression* condition = factory()->NewCompareOperation(
6790 Token::EQ_STRICT, factory->NewVariableProxy(completion), 6731 Token::EQ_STRICT, factory()->NewVariableProxy(completion),
6791 factory->NewSmiLiteral(Parser::kAbruptCompletion, nopos), nopos); 6732 factory()->NewSmiLiteral(Parser::kAbruptCompletion, nopos), nopos);
6792 6733
6793 Expression* proxy = factory->NewVariableProxy(completion); 6734 Expression* proxy = factory()->NewVariableProxy(completion);
6794 Expression* assignment = factory->NewAssignment( 6735 Expression* assignment = factory()->NewAssignment(
6795 Token::ASSIGN, proxy, 6736 Token::ASSIGN, proxy,
6796 factory->NewSmiLiteral(Parser::kThrowCompletion, nopos), nopos); 6737 factory()->NewSmiLiteral(Parser::kThrowCompletion, nopos), nopos);
6797 Statement* statement = factory->NewExpressionStatement(assignment, nopos); 6738 Statement* statement = factory()->NewExpressionStatement(assignment, nopos);
6798 set_completion_throw = factory->NewIfStatement( 6739 set_completion_throw = factory()->NewIfStatement(
6799 condition, statement, factory->NewEmptyStatement(nopos), nopos); 6740 condition, statement, factory()->NewEmptyStatement(nopos), nopos);
6800 } 6741 }
6801 6742
6802 // if (condition) { 6743 // if (condition) {
6803 // #BuildIteratorCloseForCompletion(iter, completion) 6744 // #BuildIteratorCloseForCompletion(iter, completion)
6804 // } 6745 // }
6805 Block* maybe_close; 6746 Block* maybe_close;
6806 { 6747 {
6807 Block* block = factory->NewBlock(nullptr, 2, true, nopos); 6748 Block* block = factory()->NewBlock(nullptr, 2, true, nopos);
6808 Expression* proxy = factory->NewVariableProxy(completion); 6749 Expression* proxy = factory()->NewVariableProxy(completion);
6809 parser_->BuildIteratorCloseForCompletion(block->statements(), iter, proxy); 6750 BuildIteratorCloseForCompletion(block->statements(), iter, proxy);
6810 DCHECK(block->statements()->length() == 2); 6751 DCHECK(block->statements()->length() == 2);
6811 6752
6812 maybe_close = factory->NewBlock(nullptr, 1, true, nopos); 6753 maybe_close = factory()->NewBlock(nullptr, 1, true, nopos);
6813 maybe_close->statements()->Add( 6754 maybe_close->statements()->Add(
6814 factory->NewIfStatement(condition, block, 6755 factory()->NewIfStatement(condition, block,
6815 factory->NewEmptyStatement(nopos), nopos), 6756 factory()->NewEmptyStatement(nopos), nopos),
6816 zone); 6757 zone());
6817 } 6758 }
6818 6759
6819 // try { #try_block } 6760 // try { #try_block }
6820 // catch(e) { 6761 // catch(e) {
6821 // #set_completion_throw; 6762 // #set_completion_throw;
6822 // %ReThrow(e); 6763 // %ReThrow(e);
6823 // } 6764 // }
6824 Statement* try_catch; 6765 Statement* try_catch;
6825 { 6766 {
6826 Scope* catch_scope = parser_->NewScopeWithParent(scope, CATCH_SCOPE); 6767 Scope* catch_scope = NewScopeWithParent(scope(), CATCH_SCOPE);
6827 Variable* catch_variable = 6768 Variable* catch_variable =
6828 catch_scope->DeclareLocal(avfactory->dot_catch_string(), VAR, 6769 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR,
6829 kCreatedInitialized, Variable::NORMAL); 6770 kCreatedInitialized, Variable::NORMAL);
6830 catch_scope->set_is_hidden(); 6771 catch_scope->set_is_hidden();
6831 6772
6832 Statement* rethrow; 6773 Statement* rethrow;
6833 // We use %ReThrow rather than the ordinary throw because we want to 6774 // We use %ReThrow rather than the ordinary throw because we want to
6834 // preserve the original exception message. This is also why we create a 6775 // preserve the original exception message. This is also why we create a
6835 // TryCatchStatementForReThrow below (which does not clear the pending 6776 // TryCatchStatementForReThrow below (which does not clear the pending
6836 // message), rather than a TryCatchStatement. 6777 // message), rather than a TryCatchStatement.
6837 { 6778 {
6838 auto args = new (zone) ZoneList<Expression*>(1, zone); 6779 auto args = new (zone()) ZoneList<Expression*>(1, zone());
6839 args->Add(factory->NewVariableProxy(catch_variable), zone); 6780 args->Add(factory()->NewVariableProxy(catch_variable), zone());
6840 rethrow = factory->NewExpressionStatement( 6781 rethrow = factory()->NewExpressionStatement(
6841 factory->NewCallRuntime(Runtime::kReThrow, args, nopos), nopos); 6782 factory()->NewCallRuntime(Runtime::kReThrow, args, nopos), nopos);
6842 } 6783 }
6843 6784
6844 Block* catch_block = factory->NewBlock(nullptr, 2, false, nopos); 6785 Block* catch_block = factory()->NewBlock(nullptr, 2, false, nopos);
6845 catch_block->statements()->Add(set_completion_throw, zone); 6786 catch_block->statements()->Add(set_completion_throw, zone());
6846 catch_block->statements()->Add(rethrow, zone); 6787 catch_block->statements()->Add(rethrow, zone());
6847 6788
6848 try_catch = factory->NewTryCatchStatementForReThrow( 6789 try_catch = factory()->NewTryCatchStatementForReThrow(
6849 iterator_use, catch_scope, catch_variable, catch_block, nopos); 6790 iterator_use, catch_scope, catch_variable, catch_block, nopos);
6850 } 6791 }
6851 6792
6852 // try { #try_catch } finally { #maybe_close } 6793 // try { #try_catch } finally { #maybe_close }
6853 Statement* try_finally; 6794 Statement* try_finally;
6854 { 6795 {
6855 Block* try_block = factory->NewBlock(nullptr, 1, false, nopos); 6796 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos);
6856 try_block->statements()->Add(try_catch, zone); 6797 try_block->statements()->Add(try_catch, zone());
6857 6798
6858 try_finally = 6799 try_finally =
6859 factory->NewTryFinallyStatement(try_block, maybe_close, nopos); 6800 factory()->NewTryFinallyStatement(try_block, maybe_close, nopos);
6860 } 6801 }
6861 6802
6862 target->statements()->Add(initialize_completion, zone); 6803 target->statements()->Add(initialize_completion, zone());
6863 target->statements()->Add(try_finally, zone); 6804 target->statements()->Add(try_finally, zone());
6864 } 6805 }
6865 6806
6866 void ParserTraits::BuildIteratorCloseForCompletion( 6807 void Parser::BuildIteratorCloseForCompletion(ZoneList<Statement*>* statements,
6867 ZoneList<Statement*>* statements, Variable* iterator, 6808 Variable* iterator,
6868 Expression* completion) { 6809 Expression* completion) {
6869 // 6810 //
6870 // This function adds two statements to [statements], corresponding to the 6811 // This function adds two statements to [statements], corresponding to the
6871 // following code: 6812 // following code:
6872 // 6813 //
6873 // let iteratorReturn = iterator.return; 6814 // let iteratorReturn = iterator.return;
6874 // if (!IS_NULL_OR_UNDEFINED(iteratorReturn)) { 6815 // if (!IS_NULL_OR_UNDEFINED(iteratorReturn)) {
6875 // if (completion === kThrowCompletion) { 6816 // if (completion === kThrowCompletion) {
6876 // if (!IS_CALLABLE(iteratorReturn)) { 6817 // if (!IS_CALLABLE(iteratorReturn)) {
6877 // throw MakeTypeError(kReturnMethodNotCallable); 6818 // throw MakeTypeError(kReturnMethodNotCallable);
6878 // } 6819 // }
6879 // try { %_Call(iteratorReturn, iterator) } catch (_) { } 6820 // try { %_Call(iteratorReturn, iterator) } catch (_) { }
6880 // } else { 6821 // } else {
6881 // let output = %_Call(iteratorReturn, iterator); 6822 // let output = %_Call(iteratorReturn, iterator);
6882 // if (!IS_RECEIVER(output)) { 6823 // if (!IS_RECEIVER(output)) {
6883 // %ThrowIterResultNotAnObject(output); 6824 // %ThrowIterResultNotAnObject(output);
6884 // } 6825 // }
6885 // } 6826 // }
6886 // } 6827 // }
6887 // 6828 //
6888 6829
6889 const int nopos = kNoSourcePosition; 6830 const int nopos = kNoSourcePosition;
6890 auto factory = parser_->factory();
6891 auto avfactory = parser_->ast_value_factory();
6892 auto zone = parser_->zone();
6893
6894
6895 // let iteratorReturn = iterator.return; 6831 // let iteratorReturn = iterator.return;
6896 Variable* var_return = parser_->NewTemporary(avfactory->empty_string()); 6832 Variable* var_return = NewTemporary(ast_value_factory()->empty_string());
6897 Statement* get_return; 6833 Statement* get_return;
6898 { 6834 {
6899 Expression* iterator_proxy = factory->NewVariableProxy(iterator); 6835 Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
6900 Expression* literal = 6836 Expression* literal = factory()->NewStringLiteral(
6901 factory->NewStringLiteral(avfactory->return_string(), nopos); 6837 ast_value_factory()->return_string(), nopos);
6902 Expression* property = 6838 Expression* property =
6903 factory->NewProperty(iterator_proxy, literal, nopos); 6839 factory()->NewProperty(iterator_proxy, literal, nopos);
6904 Expression* return_proxy = factory->NewVariableProxy(var_return); 6840 Expression* return_proxy = factory()->NewVariableProxy(var_return);
6905 Expression* assignment = factory->NewAssignment( 6841 Expression* assignment =
6906 Token::ASSIGN, return_proxy, property, nopos); 6842 factory()->NewAssignment(Token::ASSIGN, return_proxy, property, nopos);
6907 get_return = factory->NewExpressionStatement(assignment, nopos); 6843 get_return = factory()->NewExpressionStatement(assignment, nopos);
6908 } 6844 }
6909 6845
6910 // if (!IS_CALLABLE(iteratorReturn)) { 6846 // if (!IS_CALLABLE(iteratorReturn)) {
6911 // throw MakeTypeError(kReturnMethodNotCallable); 6847 // throw MakeTypeError(kReturnMethodNotCallable);
6912 // } 6848 // }
6913 Statement* check_return_callable; 6849 Statement* check_return_callable;
6914 { 6850 {
6915 Expression* throw_expr = NewThrowTypeError( 6851 Expression* throw_expr =
6916 MessageTemplate::kReturnMethodNotCallable, 6852 NewThrowTypeError(MessageTemplate::kReturnMethodNotCallable,
6917 avfactory->empty_string(), nopos); 6853 ast_value_factory()->empty_string(), nopos);
6918 check_return_callable = CheckCallable(var_return, throw_expr, nopos); 6854 check_return_callable = CheckCallable(var_return, throw_expr, nopos);
6919 } 6855 }
6920 6856
6921 // try { %_Call(iteratorReturn, iterator) } catch (_) { } 6857 // try { %_Call(iteratorReturn, iterator) } catch (_) { }
6922 Statement* try_call_return; 6858 Statement* try_call_return;
6923 { 6859 {
6924 auto args = new (zone) ZoneList<Expression*>(2, zone); 6860 auto args = new (zone()) ZoneList<Expression*>(2, zone());
6925 args->Add(factory->NewVariableProxy(var_return), zone); 6861 args->Add(factory()->NewVariableProxy(var_return), zone());
6926 args->Add(factory->NewVariableProxy(iterator), zone); 6862 args->Add(factory()->NewVariableProxy(iterator), zone());
6927 6863
6928 Expression* call = 6864 Expression* call =
6929 factory->NewCallRuntime(Runtime::kInlineCall, args, nopos); 6865 factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos);
6930 6866
6931 Block* try_block = factory->NewBlock(nullptr, 1, false, nopos); 6867 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos);
6932 try_block->statements()->Add(factory->NewExpressionStatement(call, nopos), 6868 try_block->statements()->Add(factory()->NewExpressionStatement(call, nopos),
6933 zone); 6869 zone());
6934 6870
6935 Block* catch_block = factory->NewBlock(nullptr, 0, false, nopos); 6871 Block* catch_block = factory()->NewBlock(nullptr, 0, false, nopos);
6936 6872
6937 Scope* catch_scope = NewScope(CATCH_SCOPE); 6873 Scope* catch_scope = NewScope(CATCH_SCOPE);
6938 Variable* catch_variable = catch_scope->DeclareLocal( 6874 Variable* catch_variable =
6939 avfactory->dot_catch_string(), VAR, kCreatedInitialized, 6875 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR,
6940 Variable::NORMAL); 6876 kCreatedInitialized, Variable::NORMAL);
6941 catch_scope->set_is_hidden(); 6877 catch_scope->set_is_hidden();
6942 6878
6943 try_call_return = factory->NewTryCatchStatement( 6879 try_call_return = factory()->NewTryCatchStatement(
6944 try_block, catch_scope, catch_variable, catch_block, nopos); 6880 try_block, catch_scope, catch_variable, catch_block, nopos);
6945 } 6881 }
6946 6882
6947 // let output = %_Call(iteratorReturn, iterator); 6883 // let output = %_Call(iteratorReturn, iterator);
6948 // if (!IS_RECEIVER(output)) { 6884 // if (!IS_RECEIVER(output)) {
6949 // %ThrowIteratorResultNotAnObject(output); 6885 // %ThrowIteratorResultNotAnObject(output);
6950 // } 6886 // }
6951 Block* validate_return; 6887 Block* validate_return;
6952 { 6888 {
6953 Variable* var_output = parser_->NewTemporary(avfactory->empty_string()); 6889 Variable* var_output = NewTemporary(ast_value_factory()->empty_string());
6954 Statement* call_return; 6890 Statement* call_return;
6955 { 6891 {
6956 auto args = new (zone) ZoneList<Expression*>(2, zone); 6892 auto args = new (zone()) ZoneList<Expression*>(2, zone());
6957 args->Add(factory->NewVariableProxy(var_return), zone); 6893 args->Add(factory()->NewVariableProxy(var_return), zone());
6958 args->Add(factory->NewVariableProxy(iterator), zone); 6894 args->Add(factory()->NewVariableProxy(iterator), zone());
6959 Expression* call = 6895 Expression* call =
6960 factory->NewCallRuntime(Runtime::kInlineCall, args, nopos); 6896 factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos);
6961 6897
6962 Expression* output_proxy = factory->NewVariableProxy(var_output); 6898 Expression* output_proxy = factory()->NewVariableProxy(var_output);
6963 Expression* assignment = 6899 Expression* assignment =
6964 factory->NewAssignment(Token::ASSIGN, output_proxy, call, nopos); 6900 factory()->NewAssignment(Token::ASSIGN, output_proxy, call, nopos);
6965 call_return = factory->NewExpressionStatement(assignment, nopos); 6901 call_return = factory()->NewExpressionStatement(assignment, nopos);
6966 } 6902 }
6967 6903
6968 Expression* is_receiver_call; 6904 Expression* is_receiver_call;
6969 { 6905 {
6970 auto args = new (zone) ZoneList<Expression*>(1, zone); 6906 auto args = new (zone()) ZoneList<Expression*>(1, zone());
6971 args->Add(factory->NewVariableProxy(var_output), zone); 6907 args->Add(factory()->NewVariableProxy(var_output), zone());
6972 is_receiver_call = 6908 is_receiver_call =
6973 factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos); 6909 factory()->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
6974 } 6910 }
6975 6911
6976 Statement* throw_call; 6912 Statement* throw_call;
6977 { 6913 {
6978 auto args = new (zone) ZoneList<Expression*>(1, zone); 6914 auto args = new (zone()) ZoneList<Expression*>(1, zone());
6979 args->Add(factory->NewVariableProxy(var_output), zone); 6915 args->Add(factory()->NewVariableProxy(var_output), zone());
6980 Expression* call = factory->NewCallRuntime( 6916 Expression* call = factory()->NewCallRuntime(
6981 Runtime::kThrowIteratorResultNotAnObject, args, nopos); 6917 Runtime::kThrowIteratorResultNotAnObject, args, nopos);
6982 throw_call = factory->NewExpressionStatement(call, nopos); 6918 throw_call = factory()->NewExpressionStatement(call, nopos);
6983 } 6919 }
6984 6920
6985 Statement* check_return = factory->NewIfStatement( 6921 Statement* check_return = factory()->NewIfStatement(
6986 is_receiver_call, factory->NewEmptyStatement(nopos), throw_call, nopos); 6922 is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call,
6923 nopos);
6987 6924
6988 validate_return = factory->NewBlock(nullptr, 2, false, nopos); 6925 validate_return = factory()->NewBlock(nullptr, 2, false, nopos);
6989 validate_return->statements()->Add(call_return, zone); 6926 validate_return->statements()->Add(call_return, zone());
6990 validate_return->statements()->Add(check_return, zone); 6927 validate_return->statements()->Add(check_return, zone());
6991 } 6928 }
6992 6929
6993 // if (completion === kThrowCompletion) { 6930 // if (completion === kThrowCompletion) {
6994 // #check_return_callable; 6931 // #check_return_callable;
6995 // #try_call_return; 6932 // #try_call_return;
6996 // } else { 6933 // } else {
6997 // #validate_return; 6934 // #validate_return;
6998 // } 6935 // }
6999 Statement* call_return_carefully; 6936 Statement* call_return_carefully;
7000 { 6937 {
7001 Expression* condition = factory->NewCompareOperation( 6938 Expression* condition = factory()->NewCompareOperation(
7002 Token::EQ_STRICT, completion, 6939 Token::EQ_STRICT, completion,
7003 factory->NewSmiLiteral(Parser::kThrowCompletion, nopos), nopos); 6940 factory()->NewSmiLiteral(Parser::kThrowCompletion, nopos), nopos);
7004 6941
7005 Block* then_block = factory->NewBlock(nullptr, 2, false, nopos); 6942 Block* then_block = factory()->NewBlock(nullptr, 2, false, nopos);
7006 then_block->statements()->Add(check_return_callable, zone); 6943 then_block->statements()->Add(check_return_callable, zone());
7007 then_block->statements()->Add(try_call_return, zone); 6944 then_block->statements()->Add(try_call_return, zone());
7008 6945
7009 call_return_carefully = 6946 call_return_carefully = factory()->NewIfStatement(condition, then_block,
7010 factory->NewIfStatement(condition, then_block, validate_return, nopos); 6947 validate_return, nopos);
7011 } 6948 }
7012 6949
7013 // if (!IS_NULL_OR_UNDEFINED(iteratorReturn)) { ... } 6950 // if (!IS_NULL_OR_UNDEFINED(iteratorReturn)) { ... }
7014 Statement* maybe_call_return; 6951 Statement* maybe_call_return;
7015 { 6952 {
7016 Expression* condition = factory->NewCompareOperation( 6953 Expression* condition = factory()->NewCompareOperation(
7017 Token::EQ, factory->NewVariableProxy(var_return), 6954 Token::EQ, factory()->NewVariableProxy(var_return),
7018 factory->NewNullLiteral(nopos), nopos); 6955 factory()->NewNullLiteral(nopos), nopos);
7019 6956
7020 maybe_call_return = 6957 maybe_call_return = factory()->NewIfStatement(
7021 factory->NewIfStatement(condition, factory->NewEmptyStatement(nopos), 6958 condition, factory()->NewEmptyStatement(nopos), call_return_carefully,
7022 call_return_carefully, nopos); 6959 nopos);
7023 } 6960 }
7024 6961
7025 6962 statements->Add(get_return, zone());
7026 statements->Add(get_return, zone); 6963 statements->Add(maybe_call_return, zone());
7027 statements->Add(maybe_call_return, zone);
7028 } 6964 }
7029 6965
7030 Statement* ParserTraits::FinalizeForOfStatement(ForOfStatement* loop, 6966 Statement* Parser::FinalizeForOfStatement(ForOfStatement* loop,
7031 Variable* var_completion, 6967 Variable* var_completion, int pos) {
7032 int pos) {
7033 // 6968 //
7034 // This function replaces the loop with the following wrapping: 6969 // This function replaces the loop with the following wrapping:
7035 // 6970 //
7036 // completion = kNormalCompletion; 6971 // completion = kNormalCompletion;
7037 // try { 6972 // try {
7038 // try { 6973 // try {
7039 // #loop; 6974 // #loop;
7040 // } catch(e) { 6975 // } catch(e) {
7041 // if (completion === kAbruptCompletion) completion = kThrowCompletion; 6976 // if (completion === kAbruptCompletion) completion = kThrowCompletion;
7042 // %ReThrow(e); 6977 // %ReThrow(e);
7043 // } 6978 // }
7044 // } finally { 6979 // } finally {
7045 // if (!(completion === kNormalCompletion || IS_UNDEFINED(#iterator))) { 6980 // if (!(completion === kNormalCompletion || IS_UNDEFINED(#iterator))) {
7046 // #BuildIteratorCloseForCompletion(#iterator, completion) 6981 // #BuildIteratorCloseForCompletion(#iterator, completion)
7047 // } 6982 // }
7048 // } 6983 // }
7049 // 6984 //
7050 // Note that the loop's body and its assign_each already contain appropriate 6985 // Note that the loop's body and its assign_each already contain appropriate
7051 // assignments to completion (see InitializeForOfStatement). 6986 // assignments to completion (see InitializeForOfStatement).
7052 // 6987 //
7053 6988
7054 const int nopos = kNoSourcePosition; 6989 const int nopos = kNoSourcePosition;
7055 auto factory = parser_->factory();
7056 auto zone = parser_->zone();
7057 6990
7058 // !(completion === kNormalCompletion || IS_UNDEFINED(#iterator)) 6991 // !(completion === kNormalCompletion || IS_UNDEFINED(#iterator))
7059 Expression* closing_condition; 6992 Expression* closing_condition;
7060 { 6993 {
7061 Expression* lhs = factory->NewCompareOperation( 6994 Expression* lhs = factory()->NewCompareOperation(
7062 Token::EQ_STRICT, factory->NewVariableProxy(var_completion), 6995 Token::EQ_STRICT, factory()->NewVariableProxy(var_completion),
7063 factory->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos); 6996 factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos);
7064 Expression* rhs = factory->NewCompareOperation( 6997 Expression* rhs = factory()->NewCompareOperation(
7065 Token::EQ_STRICT, factory->NewVariableProxy(loop->iterator()), 6998 Token::EQ_STRICT, factory()->NewVariableProxy(loop->iterator()),
7066 factory->NewUndefinedLiteral(nopos), nopos); 6999 factory()->NewUndefinedLiteral(nopos), nopos);
7067 closing_condition = factory->NewUnaryOperation( 7000 closing_condition = factory()->NewUnaryOperation(
7068 Token::NOT, factory->NewBinaryOperation(Token::OR, lhs, rhs, nopos), 7001 Token::NOT, factory()->NewBinaryOperation(Token::OR, lhs, rhs, nopos),
7069 nopos); 7002 nopos);
7070 } 7003 }
7071 7004
7072 Block* final_loop = factory->NewBlock(nullptr, 2, false, nopos); 7005 Block* final_loop = factory()->NewBlock(nullptr, 2, false, nopos);
7073 { 7006 {
7074 Block* try_block = factory->NewBlock(nullptr, 1, false, nopos); 7007 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos);
7075 try_block->statements()->Add(loop, zone); 7008 try_block->statements()->Add(loop, zone());
7076 7009
7077 FinalizeIteratorUse(var_completion, closing_condition, loop->iterator(), 7010 FinalizeIteratorUse(var_completion, closing_condition, loop->iterator(),
7078 try_block, final_loop); 7011 try_block, final_loop);
7079 } 7012 }
7080 7013
7081 return final_loop; 7014 return final_loop;
7082 } 7015 }
7083 7016
7084 #ifdef DEBUG 7017 #ifdef DEBUG
7085 void Parser::Print(AstNode* node) { 7018 void Parser::Print(AstNode* node) {
7086 ast_value_factory()->Internalize(Isolate::Current()); 7019 ast_value_factory()->Internalize(Isolate::Current());
7087 node->Print(Isolate::Current()); 7020 node->Print(Isolate::Current());
7088 } 7021 }
7089 #endif // DEBUG 7022 #endif // DEBUG
7090 7023
7091 #undef CHECK_OK 7024 #undef CHECK_OK
7092 #undef CHECK_OK_VOID 7025 #undef CHECK_OK_VOID
7093 #undef CHECK_FAILED 7026 #undef CHECK_FAILED
7094 7027
7095 } // namespace internal 7028 } // namespace internal
7096 } // namespace v8 7029 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698