OLD | NEW |
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 "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 506 } |
507 // ...and one more time for '~foo' => 'foo^(~0)'. | 507 // ...and one more time for '~foo' => 'foo^(~0)'. |
508 if (op == Token::BIT_NOT) { | 508 if (op == Token::BIT_NOT) { |
509 return factory->NewBinaryOperation( | 509 return factory->NewBinaryOperation( |
510 Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos); | 510 Token::BIT_XOR, expression, factory->NewNumberLiteral(~0, pos), pos); |
511 } | 511 } |
512 return factory->NewUnaryOperation(op, expression, pos); | 512 return factory->NewUnaryOperation(op, expression, pos); |
513 } | 513 } |
514 | 514 |
515 Expression* ParserTraits::BuildIteratorResult(Expression* value, bool done) { | 515 Expression* ParserTraits::BuildIteratorResult(Expression* value, bool done) { |
516 int pos = RelocInfo::kNoPosition; | 516 int pos = kNoSourcePosition; |
517 AstNodeFactory* factory = parser_->factory(); | 517 AstNodeFactory* factory = parser_->factory(); |
518 Zone* zone = parser_->zone(); | 518 Zone* zone = parser_->zone(); |
519 | 519 |
520 if (value == nullptr) value = factory->NewUndefinedLiteral(pos); | 520 if (value == nullptr) value = factory->NewUndefinedLiteral(pos); |
521 | 521 |
522 auto args = new (zone) ZoneList<Expression*>(2, zone); | 522 auto args = new (zone) ZoneList<Expression*>(2, zone); |
523 args->Add(value, zone); | 523 args->Add(value, zone); |
524 args->Add(factory->NewBooleanLiteral(done, pos), zone); | 524 args->Add(factory->NewBooleanLiteral(done, pos), zone); |
525 | 525 |
526 return factory->NewCallRuntime(Runtime::kInlineCreateIterResultObject, args, | 526 return factory->NewCallRuntime(Runtime::kInlineCreateIterResultObject, args, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 | 636 |
637 | 637 |
638 Expression* ParserTraits::SuperPropertyReference(Scope* scope, | 638 Expression* ParserTraits::SuperPropertyReference(Scope* scope, |
639 AstNodeFactory* factory, | 639 AstNodeFactory* factory, |
640 int pos) { | 640 int pos) { |
641 // this_function[home_object_symbol] | 641 // this_function[home_object_symbol] |
642 VariableProxy* this_function_proxy = scope->NewUnresolved( | 642 VariableProxy* this_function_proxy = scope->NewUnresolved( |
643 factory, parser_->ast_value_factory()->this_function_string(), | 643 factory, parser_->ast_value_factory()->this_function_string(), |
644 Variable::NORMAL, pos); | 644 Variable::NORMAL, pos); |
645 Expression* home_object_symbol_literal = | 645 Expression* home_object_symbol_literal = |
646 factory->NewSymbolLiteral("home_object_symbol", RelocInfo::kNoPosition); | 646 factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); |
647 Expression* home_object = factory->NewProperty( | 647 Expression* home_object = factory->NewProperty( |
648 this_function_proxy, home_object_symbol_literal, pos); | 648 this_function_proxy, home_object_symbol_literal, pos); |
649 return factory->NewSuperPropertyReference( | 649 return factory->NewSuperPropertyReference( |
650 ThisExpression(scope, factory, pos)->AsVariableProxy(), home_object, pos); | 650 ThisExpression(scope, factory, pos)->AsVariableProxy(), home_object, pos); |
651 } | 651 } |
652 | 652 |
653 | 653 |
654 Expression* ParserTraits::SuperCallReference(Scope* scope, | 654 Expression* ParserTraits::SuperCallReference(Scope* scope, |
655 AstNodeFactory* factory, int pos) { | 655 AstNodeFactory* factory, int pos) { |
656 VariableProxy* new_target_proxy = scope->NewUnresolved( | 656 VariableProxy* new_target_proxy = scope->NewUnresolved( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 AstNodeFactory* factory) { | 732 AstNodeFactory* factory) { |
733 const AstRawString* symbol = GetSymbol(scanner); | 733 const AstRawString* symbol = GetSymbol(scanner); |
734 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 734 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
735 return factory->NewStringLiteral(symbol, pos); | 735 return factory->NewStringLiteral(symbol, pos); |
736 } | 736 } |
737 | 737 |
738 | 738 |
739 Expression* ParserTraits::GetIterator(Expression* iterable, | 739 Expression* ParserTraits::GetIterator(Expression* iterable, |
740 AstNodeFactory* factory, int pos) { | 740 AstNodeFactory* factory, int pos) { |
741 Expression* iterator_symbol_literal = | 741 Expression* iterator_symbol_literal = |
742 factory->NewSymbolLiteral("iterator_symbol", RelocInfo::kNoPosition); | 742 factory->NewSymbolLiteral("iterator_symbol", kNoSourcePosition); |
743 Expression* prop = | 743 Expression* prop = |
744 factory->NewProperty(iterable, iterator_symbol_literal, pos); | 744 factory->NewProperty(iterable, iterator_symbol_literal, pos); |
745 Zone* zone = parser_->zone(); | 745 Zone* zone = parser_->zone(); |
746 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); | 746 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); |
747 return factory->NewCall(prop, args, pos); | 747 return factory->NewCall(prop, args, pos); |
748 } | 748 } |
749 | 749 |
750 | 750 |
751 Literal* ParserTraits::GetLiteralTheHole(int position, | 751 Literal* ParserTraits::GetLiteralTheHole(int position, |
752 AstNodeFactory* factory) { | 752 AstNodeFactory* factory) { |
753 return factory->NewTheHoleLiteral(RelocInfo::kNoPosition); | 753 return factory->NewTheHoleLiteral(kNoSourcePosition); |
754 } | 754 } |
755 | 755 |
756 | 756 |
757 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { | 757 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { |
758 return parser_->ParseV8Intrinsic(ok); | 758 return parser_->ParseV8Intrinsic(ok); |
759 } | 759 } |
760 | 760 |
761 | 761 |
762 FunctionLiteral* ParserTraits::ParseFunctionLiteral( | 762 FunctionLiteral* ParserTraits::ParseFunctionLiteral( |
763 const AstRawString* name, Scanner::Location function_name_location, | 763 const AstRawString* name, Scanner::Location function_name_location, |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 } | 1162 } |
1163 } | 1163 } |
1164 } else if (shared_info->is_default_constructor()) { | 1164 } else if (shared_info->is_default_constructor()) { |
1165 result = DefaultConstructor( | 1165 result = DefaultConstructor( |
1166 raw_name, IsSubclassConstructor(shared_info->kind()), scope, | 1166 raw_name, IsSubclassConstructor(shared_info->kind()), scope, |
1167 shared_info->start_position(), shared_info->end_position(), | 1167 shared_info->start_position(), shared_info->end_position(), |
1168 shared_info->language_mode()); | 1168 shared_info->language_mode()); |
1169 } else { | 1169 } else { |
1170 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), | 1170 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), |
1171 kSkipFunctionNameCheck, shared_info->kind(), | 1171 kSkipFunctionNameCheck, shared_info->kind(), |
1172 RelocInfo::kNoPosition, function_type, | 1172 kNoSourcePosition, function_type, |
1173 shared_info->language_mode(), &ok); | 1173 shared_info->language_mode(), &ok); |
1174 } | 1174 } |
1175 // Make sure the results agree. | 1175 // Make sure the results agree. |
1176 DCHECK(ok == (result != NULL)); | 1176 DCHECK(ok == (result != NULL)); |
1177 } | 1177 } |
1178 | 1178 |
1179 // Make sure the target stack is empty. | 1179 // Make sure the target stack is empty. |
1180 DCHECK(target_stack_ == NULL); | 1180 DCHECK(target_stack_ == NULL); |
1181 | 1181 |
1182 if (result != NULL) { | 1182 if (result != NULL) { |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 // 'function' '(' FormalParameters ')' '{' FunctionBody '}' | 1585 // 'function' '(' FormalParameters ')' '{' FunctionBody '}' |
1586 // | 1586 // |
1587 // GeneratorDeclaration[+Default] :: | 1587 // GeneratorDeclaration[+Default] :: |
1588 // 'function' '*' '(' FormalParameters ')' '{' FunctionBody '}' | 1588 // 'function' '*' '(' FormalParameters ')' '{' FunctionBody '}' |
1589 default_export = ParseFunctionLiteral( | 1589 default_export = ParseFunctionLiteral( |
1590 default_string, Scanner::Location::invalid(), | 1590 default_string, Scanner::Location::invalid(), |
1591 kSkipFunctionNameCheck, | 1591 kSkipFunctionNameCheck, |
1592 is_generator ? FunctionKind::kGeneratorFunction | 1592 is_generator ? FunctionKind::kGeneratorFunction |
1593 : FunctionKind::kNormalFunction, | 1593 : FunctionKind::kNormalFunction, |
1594 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); | 1594 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); |
1595 result = factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 1595 result = factory()->NewEmptyStatement(kNoSourcePosition); |
1596 } else { | 1596 } else { |
1597 result = ParseHoistableDeclaration( | 1597 result = ParseHoistableDeclaration( |
1598 pos, is_generator ? ParseFunctionFlags::kIsGenerator | 1598 pos, is_generator ? ParseFunctionFlags::kIsGenerator |
1599 : ParseFunctionFlags::kIsNormal, | 1599 : ParseFunctionFlags::kIsNormal, |
1600 &names, CHECK_OK); | 1600 &names, CHECK_OK); |
1601 } | 1601 } |
1602 break; | 1602 break; |
1603 } | 1603 } |
1604 | 1604 |
1605 case Token::CLASS: | 1605 case Token::CLASS: |
1606 Consume(Token::CLASS); | 1606 Consume(Token::CLASS); |
1607 if (peek() == Token::EXTENDS || peek() == Token::LBRACE) { | 1607 if (peek() == Token::EXTENDS || peek() == Token::LBRACE) { |
1608 // ClassDeclaration[+Default] :: | 1608 // ClassDeclaration[+Default] :: |
1609 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}' | 1609 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}' |
1610 default_export = ParseClassLiteral(nullptr, default_string, | 1610 default_export = ParseClassLiteral(nullptr, default_string, |
1611 Scanner::Location::invalid(), false, | 1611 Scanner::Location::invalid(), false, |
1612 position(), CHECK_OK); | 1612 position(), CHECK_OK); |
1613 result = factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 1613 result = factory()->NewEmptyStatement(kNoSourcePosition); |
1614 } else { | 1614 } else { |
1615 result = ParseClassDeclaration(&names, CHECK_OK); | 1615 result = ParseClassDeclaration(&names, CHECK_OK); |
1616 } | 1616 } |
1617 break; | 1617 break; |
1618 | 1618 |
1619 case Token::ASYNC: | 1619 case Token::ASYNC: |
1620 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION && | 1620 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION && |
1621 !scanner()->HasAnyLineTerminatorAfterNext()) { | 1621 !scanner()->HasAnyLineTerminatorAfterNext()) { |
1622 Consume(Token::ASYNC); | 1622 Consume(Token::ASYNC); |
1623 Consume(Token::FUNCTION); | 1623 Consume(Token::FUNCTION); |
1624 int pos = position(); | 1624 int pos = position(); |
1625 if (peek() == Token::LPAREN) { | 1625 if (peek() == Token::LPAREN) { |
1626 // AsyncFunctionDeclaration[+Default] :: | 1626 // AsyncFunctionDeclaration[+Default] :: |
1627 // async [no LineTerminator here] function ( FormalParameters ) { | 1627 // async [no LineTerminator here] function ( FormalParameters ) { |
1628 // AsyncFunctionBody | 1628 // AsyncFunctionBody |
1629 // } | 1629 // } |
1630 default_export = ParseFunctionLiteral( | 1630 default_export = ParseFunctionLiteral( |
1631 default_string, Scanner::Location::invalid(), | 1631 default_string, Scanner::Location::invalid(), |
1632 kSkipFunctionNameCheck, FunctionKind::kAsyncFunction, pos, | 1632 kSkipFunctionNameCheck, FunctionKind::kAsyncFunction, pos, |
1633 FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); | 1633 FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); |
1634 result = factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 1634 result = factory()->NewEmptyStatement(kNoSourcePosition); |
1635 } else { | 1635 } else { |
1636 result = ParseHoistableDeclaration(pos, ParseFunctionFlags::kIsAsync, | 1636 result = ParseHoistableDeclaration(pos, ParseFunctionFlags::kIsAsync, |
1637 &names, CHECK_OK); | 1637 &names, CHECK_OK); |
1638 } | 1638 } |
1639 break; | 1639 break; |
1640 } | 1640 } |
1641 /* falls through */ | 1641 /* falls through */ |
1642 | 1642 |
1643 default: { | 1643 default: { |
1644 int pos = peek_position(); | 1644 int pos = peek_position(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1795 | 1795 |
1796 Statement* Parser::ParseStatement(ZoneList<const AstRawString*>* labels, | 1796 Statement* Parser::ParseStatement(ZoneList<const AstRawString*>* labels, |
1797 AllowLabelledFunctionStatement allow_function, | 1797 AllowLabelledFunctionStatement allow_function, |
1798 bool* ok) { | 1798 bool* ok) { |
1799 // Statement :: | 1799 // Statement :: |
1800 // EmptyStatement | 1800 // EmptyStatement |
1801 // ... | 1801 // ... |
1802 | 1802 |
1803 if (peek() == Token::SEMICOLON) { | 1803 if (peek() == Token::SEMICOLON) { |
1804 Next(); | 1804 Next(); |
1805 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 1805 return factory()->NewEmptyStatement(kNoSourcePosition); |
1806 } | 1806 } |
1807 return ParseSubStatement(labels, allow_function, ok); | 1807 return ParseSubStatement(labels, allow_function, ok); |
1808 } | 1808 } |
1809 | 1809 |
1810 Statement* Parser::ParseSubStatement( | 1810 Statement* Parser::ParseSubStatement( |
1811 ZoneList<const AstRawString*>* labels, | 1811 ZoneList<const AstRawString*>* labels, |
1812 AllowLabelledFunctionStatement allow_function, bool* ok) { | 1812 AllowLabelledFunctionStatement allow_function, bool* ok) { |
1813 // Statement :: | 1813 // Statement :: |
1814 // Block | 1814 // Block |
1815 // VariableStatement | 1815 // VariableStatement |
(...skipping 16 matching lines...) Expand all Loading... |
1832 // iterations or 'switch' statements (i.e., BreakableStatements), | 1832 // iterations or 'switch' statements (i.e., BreakableStatements), |
1833 // labels can be simply ignored in all other cases; except for | 1833 // labels can be simply ignored in all other cases; except for |
1834 // trivial labeled break statements 'label: break label' which is | 1834 // trivial labeled break statements 'label: break label' which is |
1835 // parsed into an empty statement. | 1835 // parsed into an empty statement. |
1836 switch (peek()) { | 1836 switch (peek()) { |
1837 case Token::LBRACE: | 1837 case Token::LBRACE: |
1838 return ParseBlock(labels, ok); | 1838 return ParseBlock(labels, ok); |
1839 | 1839 |
1840 case Token::SEMICOLON: | 1840 case Token::SEMICOLON: |
1841 Next(); | 1841 Next(); |
1842 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 1842 return factory()->NewEmptyStatement(kNoSourcePosition); |
1843 | 1843 |
1844 case Token::IF: | 1844 case Token::IF: |
1845 return ParseIfStatement(labels, ok); | 1845 return ParseIfStatement(labels, ok); |
1846 | 1846 |
1847 case Token::DO: | 1847 case Token::DO: |
1848 return ParseDoWhileStatement(labels, ok); | 1848 return ParseDoWhileStatement(labels, ok); |
1849 | 1849 |
1850 case Token::WHILE: | 1850 case Token::WHILE: |
1851 return ParseWhileStatement(labels, ok); | 1851 return ParseWhileStatement(labels, ok); |
1852 | 1852 |
1853 case Token::FOR: | 1853 case Token::FOR: |
1854 return ParseForStatement(labels, ok); | 1854 return ParseForStatement(labels, ok); |
1855 | 1855 |
1856 case Token::CONTINUE: | 1856 case Token::CONTINUE: |
1857 case Token::BREAK: | 1857 case Token::BREAK: |
1858 case Token::RETURN: | 1858 case Token::RETURN: |
1859 case Token::THROW: | 1859 case Token::THROW: |
1860 case Token::TRY: { | 1860 case Token::TRY: { |
1861 // These statements must have their labels preserved in an enclosing | 1861 // These statements must have their labels preserved in an enclosing |
1862 // block | 1862 // block |
1863 if (labels == NULL) { | 1863 if (labels == NULL) { |
1864 return ParseStatementAsUnlabelled(labels, ok); | 1864 return ParseStatementAsUnlabelled(labels, ok); |
1865 } else { | 1865 } else { |
1866 Block* result = | 1866 Block* result = |
1867 factory()->NewBlock(labels, 1, false, RelocInfo::kNoPosition); | 1867 factory()->NewBlock(labels, 1, false, kNoSourcePosition); |
1868 Target target(&this->target_stack_, result); | 1868 Target target(&this->target_stack_, result); |
1869 Statement* statement = ParseStatementAsUnlabelled(labels, CHECK_OK); | 1869 Statement* statement = ParseStatementAsUnlabelled(labels, CHECK_OK); |
1870 if (result) result->statements()->Add(statement, zone()); | 1870 if (result) result->statements()->Add(statement, zone()); |
1871 return result; | 1871 return result; |
1872 } | 1872 } |
1873 } | 1873 } |
1874 | 1874 |
1875 case Token::WITH: | 1875 case Token::WITH: |
1876 return ParseWithStatement(labels, ok); | 1876 return ParseWithStatement(labels, ok); |
1877 | 1877 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 // TODO(adamk): Should this be ClosureScope()? | 2125 // TODO(adamk): Should this be ClosureScope()? |
2126 scope_->DeclarationScope()->ForceEagerCompilation(); | 2126 scope_->DeclarationScope()->ForceEagerCompilation(); |
2127 | 2127 |
2128 // TODO(1240846): It's weird that native function declarations are | 2128 // TODO(1240846): It's weird that native function declarations are |
2129 // introduced dynamically when we meet their declarations, whereas | 2129 // introduced dynamically when we meet their declarations, whereas |
2130 // other functions are set up when entering the surrounding scope. | 2130 // other functions are set up when entering the surrounding scope. |
2131 VariableProxy* proxy = NewUnresolved(name, VAR); | 2131 VariableProxy* proxy = NewUnresolved(name, VAR); |
2132 Declaration* declaration = | 2132 Declaration* declaration = |
2133 factory()->NewVariableDeclaration(proxy, VAR, scope_, pos); | 2133 factory()->NewVariableDeclaration(proxy, VAR, scope_, pos); |
2134 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 2134 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
2135 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral( | 2135 NativeFunctionLiteral* lit = |
2136 name, extension_, RelocInfo::kNoPosition); | 2136 factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition); |
2137 return factory()->NewExpressionStatement( | 2137 return factory()->NewExpressionStatement( |
2138 factory()->NewAssignment(Token::INIT, proxy, lit, RelocInfo::kNoPosition), | 2138 factory()->NewAssignment(Token::INIT, proxy, lit, kNoSourcePosition), |
2139 pos); | 2139 pos); |
2140 } | 2140 } |
2141 | 2141 |
2142 | 2142 |
2143 Statement* Parser::ParseHoistableDeclaration( | 2143 Statement* Parser::ParseHoistableDeclaration( |
2144 ZoneList<const AstRawString*>* names, bool* ok) { | 2144 ZoneList<const AstRawString*>* names, bool* ok) { |
2145 Expect(Token::FUNCTION, CHECK_OK); | 2145 Expect(Token::FUNCTION, CHECK_OK); |
2146 int pos = position(); | 2146 int pos = position(); |
2147 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; | 2147 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; |
2148 if (Check(Token::MUL)) { | 2148 if (Check(Token::MUL)) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2206 // In ES6, a function behaves as a lexical binding, except in | 2206 // In ES6, a function behaves as a lexical binding, except in |
2207 // a script scope, or the initial scope of eval or another function. | 2207 // a script scope, or the initial scope of eval or another function. |
2208 VariableMode mode = | 2208 VariableMode mode = |
2209 (!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET | 2209 (!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET |
2210 : VAR; | 2210 : VAR; |
2211 VariableProxy* proxy = NewUnresolved(name, mode); | 2211 VariableProxy* proxy = NewUnresolved(name, mode); |
2212 Declaration* declaration = | 2212 Declaration* declaration = |
2213 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); | 2213 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); |
2214 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 2214 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
2215 if (names) names->Add(name, zone()); | 2215 if (names) names->Add(name, zone()); |
2216 EmptyStatement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 2216 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition); |
2217 // Async functions don't undergo sloppy mode block scoped hoisting, and don't | 2217 // Async functions don't undergo sloppy mode block scoped hoisting, and don't |
2218 // allow duplicates in a block. Both are represented by the | 2218 // allow duplicates in a block. Both are represented by the |
2219 // sloppy_block_function_map. Don't add them to the map for async functions. | 2219 // sloppy_block_function_map. Don't add them to the map for async functions. |
2220 // Generators are also supposed to be prohibited; currently doing this behind | 2220 // Generators are also supposed to be prohibited; currently doing this behind |
2221 // a flag and UseCounting violations to assess web compatibility. | 2221 // a flag and UseCounting violations to assess web compatibility. |
2222 if (is_sloppy(language_mode()) && !scope_->is_declaration_scope() && | 2222 if (is_sloppy(language_mode()) && !scope_->is_declaration_scope() && |
2223 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) { | 2223 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) { |
2224 SloppyBlockFunctionStatement* delegate = | 2224 SloppyBlockFunctionStatement* delegate = |
2225 factory()->NewSloppyBlockFunctionStatement(empty, scope_); | 2225 factory()->NewSloppyBlockFunctionStatement(empty, scope_); |
2226 scope_->DeclarationScope()->sloppy_block_function_map()->Declare(name, | 2226 scope_->DeclarationScope()->sloppy_block_function_map()->Declare(name, |
(...skipping 29 matching lines...) Expand all Loading... |
2256 is_strict_reserved, pos, CHECK_OK); | 2256 is_strict_reserved, pos, CHECK_OK); |
2257 | 2257 |
2258 VariableProxy* proxy = NewUnresolved(name, LET); | 2258 VariableProxy* proxy = NewUnresolved(name, LET); |
2259 Declaration* declaration = | 2259 Declaration* declaration = |
2260 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); | 2260 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); |
2261 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 2261 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
2262 proxy->var()->set_initializer_position(position()); | 2262 proxy->var()->set_initializer_position(position()); |
2263 Assignment* assignment = | 2263 Assignment* assignment = |
2264 factory()->NewAssignment(Token::INIT, proxy, value, pos); | 2264 factory()->NewAssignment(Token::INIT, proxy, value, pos); |
2265 Statement* assignment_statement = | 2265 Statement* assignment_statement = |
2266 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 2266 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
2267 if (names) names->Add(name, zone()); | 2267 if (names) names->Add(name, zone()); |
2268 return assignment_statement; | 2268 return assignment_statement; |
2269 } | 2269 } |
2270 | 2270 |
2271 | 2271 |
2272 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, | 2272 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, |
2273 bool finalize_block_scope, bool* ok) { | 2273 bool finalize_block_scope, bool* ok) { |
2274 // The harmony mode uses block elements instead of statements. | 2274 // The harmony mode uses block elements instead of statements. |
2275 // | 2275 // |
2276 // Block :: | 2276 // Block :: |
2277 // '{' StatementList '}' | 2277 // '{' StatementList '}' |
2278 | 2278 |
2279 // Construct block expecting 16 statements. | 2279 // Construct block expecting 16 statements. |
2280 Block* body = | 2280 Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition); |
2281 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); | |
2282 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 2281 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
2283 | 2282 |
2284 // Parse the statements and collect escaping labels. | 2283 // Parse the statements and collect escaping labels. |
2285 Expect(Token::LBRACE, CHECK_OK); | 2284 Expect(Token::LBRACE, CHECK_OK); |
2286 block_scope->set_start_position(scanner()->location().beg_pos); | 2285 block_scope->set_start_position(scanner()->location().beg_pos); |
2287 { BlockState block_state(&scope_, block_scope); | 2286 { BlockState block_state(&scope_, block_scope); |
2288 Target target(&this->target_stack_, body); | 2287 Target target(&this->target_stack_, body); |
2289 | 2288 |
2290 while (peek() != Token::RBRACE) { | 2289 while (peek() != Token::RBRACE) { |
2291 Statement* stat = ParseStatementListItem(CHECK_OK); | 2290 Statement* stat = ParseStatementListItem(CHECK_OK); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2415 | 2414 |
2416 Scanner::Location variable_loc = scanner()->location(); | 2415 Scanner::Location variable_loc = scanner()->location(); |
2417 const AstRawString* single_name = | 2416 const AstRawString* single_name = |
2418 pattern->IsVariableProxy() ? pattern->AsVariableProxy()->raw_name() | 2417 pattern->IsVariableProxy() ? pattern->AsVariableProxy()->raw_name() |
2419 : nullptr; | 2418 : nullptr; |
2420 if (single_name != nullptr) { | 2419 if (single_name != nullptr) { |
2421 if (fni_ != NULL) fni_->PushVariableName(single_name); | 2420 if (fni_ != NULL) fni_->PushVariableName(single_name); |
2422 } | 2421 } |
2423 | 2422 |
2424 Expression* value = NULL; | 2423 Expression* value = NULL; |
2425 int initializer_position = RelocInfo::kNoPosition; | 2424 int initializer_position = kNoSourcePosition; |
2426 if (Check(Token::ASSIGN)) { | 2425 if (Check(Token::ASSIGN)) { |
2427 ExpressionClassifier classifier(this); | 2426 ExpressionClassifier classifier(this); |
2428 value = ParseAssignmentExpression(var_context != kForStatement, | 2427 value = ParseAssignmentExpression(var_context != kForStatement, |
2429 &classifier, CHECK_OK); | 2428 &classifier, CHECK_OK); |
2430 RewriteNonPattern(&classifier, CHECK_OK); | 2429 RewriteNonPattern(&classifier, CHECK_OK); |
2431 variable_loc.end_pos = scanner()->location().end_pos; | 2430 variable_loc.end_pos = scanner()->location().end_pos; |
2432 | 2431 |
2433 if (!parsing_result->first_initializer_loc.IsValid()) { | 2432 if (!parsing_result->first_initializer_loc.IsValid()) { |
2434 parsing_result->first_initializer_loc = variable_loc; | 2433 parsing_result->first_initializer_loc = variable_loc; |
2435 } | 2434 } |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2618 Expect(Token::IF, CHECK_OK); | 2617 Expect(Token::IF, CHECK_OK); |
2619 Expect(Token::LPAREN, CHECK_OK); | 2618 Expect(Token::LPAREN, CHECK_OK); |
2620 Expression* condition = ParseExpression(true, CHECK_OK); | 2619 Expression* condition = ParseExpression(true, CHECK_OK); |
2621 Expect(Token::RPAREN, CHECK_OK); | 2620 Expect(Token::RPAREN, CHECK_OK); |
2622 Statement* then_statement = ParseScopedStatement(labels, false, CHECK_OK); | 2621 Statement* then_statement = ParseScopedStatement(labels, false, CHECK_OK); |
2623 Statement* else_statement = NULL; | 2622 Statement* else_statement = NULL; |
2624 if (peek() == Token::ELSE) { | 2623 if (peek() == Token::ELSE) { |
2625 Next(); | 2624 Next(); |
2626 else_statement = ParseScopedStatement(labels, false, CHECK_OK); | 2625 else_statement = ParseScopedStatement(labels, false, CHECK_OK); |
2627 } else { | 2626 } else { |
2628 else_statement = factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 2627 else_statement = factory()->NewEmptyStatement(kNoSourcePosition); |
2629 } | 2628 } |
2630 return factory()->NewIfStatement( | 2629 return factory()->NewIfStatement( |
2631 condition, then_statement, else_statement, pos); | 2630 condition, then_statement, else_statement, pos); |
2632 } | 2631 } |
2633 | 2632 |
2634 | 2633 |
2635 Statement* Parser::ParseContinueStatement(bool* ok) { | 2634 Statement* Parser::ParseContinueStatement(bool* ok) { |
2636 // ContinueStatement :: | 2635 // ContinueStatement :: |
2637 // 'continue' Identifier? ';' | 2636 // 'continue' Identifier? ';' |
2638 | 2637 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2755 Runtime::kInlineIsJSReceiver, is_spec_object_args, pos); | 2754 Runtime::kInlineIsJSReceiver, is_spec_object_args, pos); |
2756 | 2755 |
2757 // %_IsJSReceiver(temp) ? temp : 1; | 2756 // %_IsJSReceiver(temp) ? temp : 1; |
2758 Expression* is_object_conditional = factory()->NewConditional( | 2757 Expression* is_object_conditional = factory()->NewConditional( |
2759 is_spec_object_call, factory()->NewVariableProxy(temp), | 2758 is_spec_object_call, factory()->NewVariableProxy(temp), |
2760 factory()->NewSmiLiteral(1, pos), pos); | 2759 factory()->NewSmiLiteral(1, pos), pos); |
2761 | 2760 |
2762 // temp === undefined | 2761 // temp === undefined |
2763 Expression* is_undefined = factory()->NewCompareOperation( | 2762 Expression* is_undefined = factory()->NewCompareOperation( |
2764 Token::EQ_STRICT, assign, | 2763 Token::EQ_STRICT, assign, |
2765 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), pos); | 2764 factory()->NewUndefinedLiteral(kNoSourcePosition), pos); |
2766 | 2765 |
2767 // is_undefined ? this : is_object_conditional | 2766 // is_undefined ? this : is_object_conditional |
2768 return_value = factory()->NewConditional( | 2767 return_value = factory()->NewConditional( |
2769 is_undefined, ThisExpression(scope_, factory(), pos), | 2768 is_undefined, ThisExpression(scope_, factory(), pos), |
2770 is_object_conditional, pos); | 2769 is_object_conditional, pos); |
2771 } else { | 2770 } else { |
2772 ReturnExprScope maybe_allow_tail_calls( | 2771 ReturnExprScope maybe_allow_tail_calls( |
2773 function_state_, ReturnExprContext::kInsideValidReturnStatement); | 2772 function_state_, ReturnExprContext::kInsideValidReturnStatement); |
2774 return_value = ParseExpression(true, CHECK_OK); | 2773 return_value = ParseExpression(true, CHECK_OK); |
2775 | 2774 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2868 // In order to get the CaseClauses to execute in their own lexical scope, | 2867 // In order to get the CaseClauses to execute in their own lexical scope, |
2869 // but without requiring downstream code to have special scope handling | 2868 // but without requiring downstream code to have special scope handling |
2870 // code for switch statements, desugar into blocks as follows: | 2869 // code for switch statements, desugar into blocks as follows: |
2871 // { // To group the statements--harmless to evaluate Expression in scope | 2870 // { // To group the statements--harmless to evaluate Expression in scope |
2872 // .tag_variable = Expression; | 2871 // .tag_variable = Expression; |
2873 // { // To give CaseClauses a scope | 2872 // { // To give CaseClauses a scope |
2874 // switch (.tag_variable) { CaseClause* } | 2873 // switch (.tag_variable) { CaseClause* } |
2875 // } | 2874 // } |
2876 // } | 2875 // } |
2877 | 2876 |
2878 Block* switch_block = | 2877 Block* switch_block = factory()->NewBlock(NULL, 2, false, kNoSourcePosition); |
2879 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); | |
2880 int switch_pos = peek_position(); | 2878 int switch_pos = peek_position(); |
2881 | 2879 |
2882 Expect(Token::SWITCH, CHECK_OK); | 2880 Expect(Token::SWITCH, CHECK_OK); |
2883 Expect(Token::LPAREN, CHECK_OK); | 2881 Expect(Token::LPAREN, CHECK_OK); |
2884 Expression* tag = ParseExpression(true, CHECK_OK); | 2882 Expression* tag = ParseExpression(true, CHECK_OK); |
2885 Expect(Token::RPAREN, CHECK_OK); | 2883 Expect(Token::RPAREN, CHECK_OK); |
2886 | 2884 |
2887 Variable* tag_variable = | 2885 Variable* tag_variable = |
2888 scope_->NewTemporary(ast_value_factory()->dot_switch_tag_string()); | 2886 scope_->NewTemporary(ast_value_factory()->dot_switch_tag_string()); |
2889 Assignment* tag_assign = factory()->NewAssignment( | 2887 Assignment* tag_assign = factory()->NewAssignment( |
2890 Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag, | 2888 Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag, |
2891 tag->position()); | 2889 tag->position()); |
2892 Statement* tag_statement = | 2890 Statement* tag_statement = |
2893 factory()->NewExpressionStatement(tag_assign, RelocInfo::kNoPosition); | 2891 factory()->NewExpressionStatement(tag_assign, kNoSourcePosition); |
2894 switch_block->statements()->Add(tag_statement, zone()); | 2892 switch_block->statements()->Add(tag_statement, zone()); |
2895 | 2893 |
2896 // make statement: undefined; | 2894 // make statement: undefined; |
2897 // This is needed so the tag isn't returned as the value, in case the switch | 2895 // This is needed so the tag isn't returned as the value, in case the switch |
2898 // statements don't have a value. | 2896 // statements don't have a value. |
2899 switch_block->statements()->Add( | 2897 switch_block->statements()->Add( |
2900 factory()->NewExpressionStatement( | 2898 factory()->NewExpressionStatement( |
2901 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | 2899 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition), |
2902 RelocInfo::kNoPosition), | |
2903 zone()); | 2900 zone()); |
2904 | 2901 |
2905 Block* cases_block = | 2902 Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); |
2906 factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); | |
2907 Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE); | 2903 Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE); |
2908 cases_scope->SetNonlinear(); | 2904 cases_scope->SetNonlinear(); |
2909 | 2905 |
2910 SwitchStatement* switch_statement = | 2906 SwitchStatement* switch_statement = |
2911 factory()->NewSwitchStatement(labels, switch_pos); | 2907 factory()->NewSwitchStatement(labels, switch_pos); |
2912 | 2908 |
2913 cases_scope->set_start_position(scanner()->location().beg_pos); | 2909 cases_scope->set_start_position(scanner()->location().beg_pos); |
2914 { | 2910 { |
2915 BlockState cases_block_state(&scope_, cases_scope); | 2911 BlockState cases_block_state(&scope_, cases_scope); |
2916 Target target(&this->target_stack_, switch_statement); | 2912 Target target(&this->target_stack_, switch_statement); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2998 Expect(Token::LPAREN, CHECK_OK); | 2994 Expect(Token::LPAREN, CHECK_OK); |
2999 catch_scope = NewScope(scope_, CATCH_SCOPE); | 2995 catch_scope = NewScope(scope_, CATCH_SCOPE); |
3000 catch_scope->set_start_position(scanner()->location().beg_pos); | 2996 catch_scope->set_start_position(scanner()->location().beg_pos); |
3001 | 2997 |
3002 { | 2998 { |
3003 CollectExpressionsInTailPositionToListScope | 2999 CollectExpressionsInTailPositionToListScope |
3004 collect_tail_call_expressions_scope( | 3000 collect_tail_call_expressions_scope( |
3005 function_state_, &tail_call_expressions_in_catch_block); | 3001 function_state_, &tail_call_expressions_in_catch_block); |
3006 BlockState block_state(&scope_, catch_scope); | 3002 BlockState block_state(&scope_, catch_scope); |
3007 | 3003 |
3008 catch_block = | 3004 catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition); |
3009 factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition); | |
3010 | 3005 |
3011 // Create a block scope to hold any lexical declarations created | 3006 // Create a block scope to hold any lexical declarations created |
3012 // as part of destructuring the catch parameter. | 3007 // as part of destructuring the catch parameter. |
3013 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 3008 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
3014 block_scope->set_start_position(scanner()->location().beg_pos); | 3009 block_scope->set_start_position(scanner()->location().beg_pos); |
3015 { | 3010 { |
3016 BlockState block_state(&scope_, block_scope); | 3011 BlockState block_state(&scope_, block_scope); |
3017 Target target(&this->target_stack_, catch_block); | 3012 Target target(&this->target_stack_, catch_block); |
3018 | 3013 |
3019 ExpressionClassifier pattern_classifier(this); | 3014 ExpressionClassifier pattern_classifier(this); |
(...skipping 21 matching lines...) Expand all Loading... |
3041 descriptor.hoist_scope = nullptr; | 3036 descriptor.hoist_scope = nullptr; |
3042 descriptor.mode = LET; | 3037 descriptor.mode = LET; |
3043 descriptor.declaration_pos = pattern->position(); | 3038 descriptor.declaration_pos = pattern->position(); |
3044 descriptor.initialization_pos = pattern->position(); | 3039 descriptor.initialization_pos = pattern->position(); |
3045 | 3040 |
3046 DeclarationParsingResult::Declaration decl( | 3041 DeclarationParsingResult::Declaration decl( |
3047 pattern, pattern->position(), | 3042 pattern, pattern->position(), |
3048 factory()->NewVariableProxy(catch_variable)); | 3043 factory()->NewVariableProxy(catch_variable)); |
3049 | 3044 |
3050 Block* init_block = | 3045 Block* init_block = |
3051 factory()->NewBlock(nullptr, 8, true, RelocInfo::kNoPosition); | 3046 factory()->NewBlock(nullptr, 8, true, kNoSourcePosition); |
3052 PatternRewriter::DeclareAndInitializeVariables( | 3047 PatternRewriter::DeclareAndInitializeVariables( |
3053 init_block, &descriptor, &decl, nullptr, CHECK_OK); | 3048 init_block, &descriptor, &decl, nullptr, CHECK_OK); |
3054 catch_block->statements()->Add(init_block, zone()); | 3049 catch_block->statements()->Add(init_block, zone()); |
3055 } | 3050 } |
3056 | 3051 |
3057 // TODO(adamk): This should call ParseBlock in order to properly | 3052 // TODO(adamk): This should call ParseBlock in order to properly |
3058 // add an additional block scope for the catch body. | 3053 // add an additional block scope for the catch body. |
3059 Expect(Token::LBRACE, CHECK_OK); | 3054 Expect(Token::LBRACE, CHECK_OK); |
3060 while (peek() != Token::RBRACE) { | 3055 while (peek() != Token::RBRACE) { |
3061 Statement* stat = ParseStatementListItem(CHECK_OK); | 3056 Statement* stat = ParseStatementListItem(CHECK_OK); |
(...skipping 20 matching lines...) Expand all Loading... |
3082 } | 3077 } |
3083 | 3078 |
3084 // Simplify the AST nodes by converting: | 3079 // Simplify the AST nodes by converting: |
3085 // 'try B0 catch B1 finally B2' | 3080 // 'try B0 catch B1 finally B2' |
3086 // to: | 3081 // to: |
3087 // 'try { try B0 catch B1 } finally B2' | 3082 // 'try { try B0 catch B1 } finally B2' |
3088 | 3083 |
3089 if (catch_block != NULL && finally_block != NULL) { | 3084 if (catch_block != NULL && finally_block != NULL) { |
3090 // If we have both, create an inner try/catch. | 3085 // If we have both, create an inner try/catch. |
3091 DCHECK(catch_scope != NULL && catch_variable != NULL); | 3086 DCHECK(catch_scope != NULL && catch_variable != NULL); |
3092 TryCatchStatement* statement = | 3087 TryCatchStatement* statement = factory()->NewTryCatchStatement( |
3093 factory()->NewTryCatchStatement(try_block, catch_scope, catch_variable, | 3088 try_block, catch_scope, catch_variable, catch_block, kNoSourcePosition); |
3094 catch_block, RelocInfo::kNoPosition); | 3089 try_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); |
3095 try_block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); | |
3096 try_block->statements()->Add(statement, zone()); | 3090 try_block->statements()->Add(statement, zone()); |
3097 catch_block = NULL; // Clear to indicate it's been handled. | 3091 catch_block = NULL; // Clear to indicate it's been handled. |
3098 } | 3092 } |
3099 | 3093 |
3100 TryStatement* result = NULL; | 3094 TryStatement* result = NULL; |
3101 if (catch_block != NULL) { | 3095 if (catch_block != NULL) { |
3102 // For a try-catch construct append return expressions from the catch block | 3096 // For a try-catch construct append return expressions from the catch block |
3103 // to the list of return expressions. | 3097 // to the list of return expressions. |
3104 function_state_->tail_call_expressions().Append( | 3098 function_state_->tail_call_expressions().Append( |
3105 tail_call_expressions_in_catch_block); | 3099 tail_call_expressions_in_catch_block); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3171 if (loop != NULL) loop->Initialize(cond, body); | 3165 if (loop != NULL) loop->Initialize(cond, body); |
3172 return loop; | 3166 return loop; |
3173 } | 3167 } |
3174 | 3168 |
3175 | 3169 |
3176 // !%_IsJSReceiver(result = iterator.next()) && | 3170 // !%_IsJSReceiver(result = iterator.next()) && |
3177 // %ThrowIteratorResultNotAnObject(result) | 3171 // %ThrowIteratorResultNotAnObject(result) |
3178 Expression* Parser::BuildIteratorNextResult(Expression* iterator, | 3172 Expression* Parser::BuildIteratorNextResult(Expression* iterator, |
3179 Variable* result, int pos) { | 3173 Variable* result, int pos) { |
3180 Expression* next_literal = factory()->NewStringLiteral( | 3174 Expression* next_literal = factory()->NewStringLiteral( |
3181 ast_value_factory()->next_string(), RelocInfo::kNoPosition); | 3175 ast_value_factory()->next_string(), kNoSourcePosition); |
3182 Expression* next_property = | 3176 Expression* next_property = |
3183 factory()->NewProperty(iterator, next_literal, RelocInfo::kNoPosition); | 3177 factory()->NewProperty(iterator, next_literal, kNoSourcePosition); |
3184 ZoneList<Expression*>* next_arguments = | 3178 ZoneList<Expression*>* next_arguments = |
3185 new (zone()) ZoneList<Expression*>(0, zone()); | 3179 new (zone()) ZoneList<Expression*>(0, zone()); |
3186 Expression* next_call = | 3180 Expression* next_call = |
3187 factory()->NewCall(next_property, next_arguments, pos); | 3181 factory()->NewCall(next_property, next_arguments, pos); |
3188 Expression* result_proxy = factory()->NewVariableProxy(result); | 3182 Expression* result_proxy = factory()->NewVariableProxy(result); |
3189 Expression* left = | 3183 Expression* left = |
3190 factory()->NewAssignment(Token::ASSIGN, result_proxy, next_call, pos); | 3184 factory()->NewAssignment(Token::ASSIGN, result_proxy, next_call, pos); |
3191 | 3185 |
3192 // %_IsJSReceiver(...) | 3186 // %_IsJSReceiver(...) |
3193 ZoneList<Expression*>* is_spec_object_args = | 3187 ZoneList<Expression*>* is_spec_object_args = |
(...skipping 22 matching lines...) Expand all Loading... |
3216 ForOfStatement* for_of = stmt->AsForOfStatement(); | 3210 ForOfStatement* for_of = stmt->AsForOfStatement(); |
3217 if (for_of != NULL) { | 3211 if (for_of != NULL) { |
3218 InitializeForOfStatement(for_of, each, subject, body, each_keyword_pos); | 3212 InitializeForOfStatement(for_of, each, subject, body, each_keyword_pos); |
3219 } else { | 3213 } else { |
3220 if (each->IsArrayLiteral() || each->IsObjectLiteral()) { | 3214 if (each->IsArrayLiteral() || each->IsObjectLiteral()) { |
3221 Variable* temp = | 3215 Variable* temp = |
3222 scope_->NewTemporary(ast_value_factory()->empty_string()); | 3216 scope_->NewTemporary(ast_value_factory()->empty_string()); |
3223 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); | 3217 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); |
3224 Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment( | 3218 Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment( |
3225 this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy, | 3219 this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy, |
3226 RelocInfo::kNoPosition), | 3220 kNoSourcePosition), |
3227 scope_); | 3221 scope_); |
3228 auto block = | 3222 auto block = factory()->NewBlock(nullptr, 2, false, kNoSourcePosition); |
3229 factory()->NewBlock(nullptr, 2, false, RelocInfo::kNoPosition); | 3223 block->statements()->Add( |
3230 block->statements()->Add(factory()->NewExpressionStatement( | 3224 factory()->NewExpressionStatement(assign_each, kNoSourcePosition), |
3231 assign_each, RelocInfo::kNoPosition), | 3225 zone()); |
3232 zone()); | |
3233 block->statements()->Add(body, zone()); | 3226 block->statements()->Add(body, zone()); |
3234 body = block; | 3227 body = block; |
3235 each = factory()->NewVariableProxy(temp); | 3228 each = factory()->NewVariableProxy(temp); |
3236 } | 3229 } |
3237 stmt->AsForInStatement()->Initialize(each, subject, body); | 3230 stmt->AsForInStatement()->Initialize(each, subject, body); |
3238 } | 3231 } |
3239 } | 3232 } |
3240 | 3233 |
3241 void Parser::InitializeForOfStatement(ForOfStatement* for_of, Expression* each, | 3234 void Parser::InitializeForOfStatement(ForOfStatement* for_of, Expression* each, |
3242 Expression* iterable, Statement* body, | 3235 Expression* iterable, Statement* body, |
(...skipping 20 matching lines...) Expand all Loading... |
3263 { | 3256 { |
3264 // result = iterator.next() | 3257 // result = iterator.next() |
3265 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); | 3258 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); |
3266 next_result = | 3259 next_result = |
3267 BuildIteratorNextResult(iterator_proxy, result, next_result_pos); | 3260 BuildIteratorNextResult(iterator_proxy, result, next_result_pos); |
3268 } | 3261 } |
3269 | 3262 |
3270 // result.done | 3263 // result.done |
3271 { | 3264 { |
3272 Expression* done_literal = factory()->NewStringLiteral( | 3265 Expression* done_literal = factory()->NewStringLiteral( |
3273 ast_value_factory()->done_string(), RelocInfo::kNoPosition); | 3266 ast_value_factory()->done_string(), kNoSourcePosition); |
3274 Expression* result_proxy = factory()->NewVariableProxy(result); | 3267 Expression* result_proxy = factory()->NewVariableProxy(result); |
3275 result_done = factory()->NewProperty(result_proxy, done_literal, | 3268 result_done = |
3276 RelocInfo::kNoPosition); | 3269 factory()->NewProperty(result_proxy, done_literal, kNoSourcePosition); |
3277 } | 3270 } |
3278 | 3271 |
3279 // each = result.value | 3272 // each = result.value |
3280 { | 3273 { |
3281 Expression* value_literal = factory()->NewStringLiteral( | 3274 Expression* value_literal = factory()->NewStringLiteral( |
3282 ast_value_factory()->value_string(), RelocInfo::kNoPosition); | 3275 ast_value_factory()->value_string(), kNoSourcePosition); |
3283 Expression* result_proxy = factory()->NewVariableProxy(result); | 3276 Expression* result_proxy = factory()->NewVariableProxy(result); |
3284 Expression* result_value = factory()->NewProperty( | 3277 Expression* result_value = |
3285 result_proxy, value_literal, RelocInfo::kNoPosition); | 3278 factory()->NewProperty(result_proxy, value_literal, kNoSourcePosition); |
3286 assign_each = factory()->NewAssignment(Token::ASSIGN, each, result_value, | 3279 assign_each = factory()->NewAssignment(Token::ASSIGN, each, result_value, |
3287 RelocInfo::kNoPosition); | 3280 kNoSourcePosition); |
3288 if (each->IsArrayLiteral() || each->IsObjectLiteral()) { | 3281 if (each->IsArrayLiteral() || each->IsObjectLiteral()) { |
3289 assign_each = PatternRewriter::RewriteDestructuringAssignment( | 3282 assign_each = PatternRewriter::RewriteDestructuringAssignment( |
3290 this, assign_each->AsAssignment(), scope_); | 3283 this, assign_each->AsAssignment(), scope_); |
3291 } | 3284 } |
3292 } | 3285 } |
3293 | 3286 |
3294 for_of->Initialize(body, iterator, assign_iterator, next_result, result_done, | 3287 for_of->Initialize(body, iterator, assign_iterator, next_result, result_done, |
3295 assign_each); | 3288 assign_each); |
3296 } | 3289 } |
3297 | 3290 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3332 // } | 3325 // } |
3333 // {{ if (flag == 1) // Body used break. | 3326 // {{ if (flag == 1) // Body used break. |
3334 // break; | 3327 // break; |
3335 // }} | 3328 // }} |
3336 // } | 3329 // } |
3337 // } | 3330 // } |
3338 | 3331 |
3339 DCHECK(names->length() > 0); | 3332 DCHECK(names->length() > 0); |
3340 ZoneList<Variable*> temps(names->length(), zone()); | 3333 ZoneList<Variable*> temps(names->length(), zone()); |
3341 | 3334 |
3342 Block* outer_block = factory()->NewBlock(NULL, names->length() + 4, false, | 3335 Block* outer_block = |
3343 RelocInfo::kNoPosition); | 3336 factory()->NewBlock(NULL, names->length() + 4, false, kNoSourcePosition); |
3344 | 3337 |
3345 // Add statement: let/const x = i. | 3338 // Add statement: let/const x = i. |
3346 outer_block->statements()->Add(init, zone()); | 3339 outer_block->statements()->Add(init, zone()); |
3347 | 3340 |
3348 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); | 3341 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); |
3349 | 3342 |
3350 // For each lexical variable x: | 3343 // For each lexical variable x: |
3351 // make statement: temp_x = x. | 3344 // make statement: temp_x = x. |
3352 for (int i = 0; i < names->length(); i++) { | 3345 for (int i = 0; i < names->length(); i++) { |
3353 VariableProxy* proxy = NewUnresolved(names->at(i), LET); | 3346 VariableProxy* proxy = NewUnresolved(names->at(i), LET); |
3354 Variable* temp = scope_->NewTemporary(temp_name); | 3347 Variable* temp = scope_->NewTemporary(temp_name); |
3355 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); | 3348 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); |
3356 Assignment* assignment = factory()->NewAssignment( | 3349 Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy, |
3357 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); | 3350 proxy, kNoSourcePosition); |
3358 Statement* assignment_statement = factory()->NewExpressionStatement( | 3351 Statement* assignment_statement = |
3359 assignment, RelocInfo::kNoPosition); | 3352 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
3360 outer_block->statements()->Add(assignment_statement, zone()); | 3353 outer_block->statements()->Add(assignment_statement, zone()); |
3361 temps.Add(temp, zone()); | 3354 temps.Add(temp, zone()); |
3362 } | 3355 } |
3363 | 3356 |
3364 Variable* first = NULL; | 3357 Variable* first = NULL; |
3365 // Make statement: first = 1. | 3358 // Make statement: first = 1. |
3366 if (next) { | 3359 if (next) { |
3367 first = scope_->NewTemporary(temp_name); | 3360 first = scope_->NewTemporary(temp_name); |
3368 VariableProxy* first_proxy = factory()->NewVariableProxy(first); | 3361 VariableProxy* first_proxy = factory()->NewVariableProxy(first); |
3369 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); | 3362 Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition); |
3370 Assignment* assignment = factory()->NewAssignment( | 3363 Assignment* assignment = factory()->NewAssignment( |
3371 Token::ASSIGN, first_proxy, const1, RelocInfo::kNoPosition); | 3364 Token::ASSIGN, first_proxy, const1, kNoSourcePosition); |
3372 Statement* assignment_statement = | 3365 Statement* assignment_statement = |
3373 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 3366 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
3374 outer_block->statements()->Add(assignment_statement, zone()); | 3367 outer_block->statements()->Add(assignment_statement, zone()); |
3375 } | 3368 } |
3376 | 3369 |
3377 // make statement: undefined; | 3370 // make statement: undefined; |
3378 outer_block->statements()->Add( | 3371 outer_block->statements()->Add( |
3379 factory()->NewExpressionStatement( | 3372 factory()->NewExpressionStatement( |
3380 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | 3373 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition), |
3381 RelocInfo::kNoPosition), | |
3382 zone()); | 3374 zone()); |
3383 | 3375 |
3384 // Make statement: outer: for (;;) | 3376 // Make statement: outer: for (;;) |
3385 // Note that we don't actually create the label, or set this loop up as an | 3377 // Note that we don't actually create the label, or set this loop up as an |
3386 // explicit break target, instead handing it directly to those nodes that | 3378 // explicit break target, instead handing it directly to those nodes that |
3387 // need to know about it. This should be safe because we don't run any code | 3379 // need to know about it. This should be safe because we don't run any code |
3388 // in this function that looks up break targets. | 3380 // in this function that looks up break targets. |
3389 ForStatement* outer_loop = | 3381 ForStatement* outer_loop = |
3390 factory()->NewForStatement(NULL, RelocInfo::kNoPosition); | 3382 factory()->NewForStatement(NULL, kNoSourcePosition); |
3391 outer_block->statements()->Add(outer_loop, zone()); | 3383 outer_block->statements()->Add(outer_loop, zone()); |
3392 outer_block->set_scope(scope_); | 3384 outer_block->set_scope(scope_); |
3393 | 3385 |
3394 Block* inner_block = | 3386 Block* inner_block = factory()->NewBlock(NULL, 3, false, kNoSourcePosition); |
3395 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | |
3396 { | 3387 { |
3397 BlockState block_state(&scope_, inner_scope); | 3388 BlockState block_state(&scope_, inner_scope); |
3398 | 3389 |
3399 Block* ignore_completion_block = factory()->NewBlock( | 3390 Block* ignore_completion_block = |
3400 NULL, names->length() + 3, true, RelocInfo::kNoPosition); | 3391 factory()->NewBlock(NULL, names->length() + 3, true, kNoSourcePosition); |
3401 ZoneList<Variable*> inner_vars(names->length(), zone()); | 3392 ZoneList<Variable*> inner_vars(names->length(), zone()); |
3402 // For each let variable x: | 3393 // For each let variable x: |
3403 // make statement: let/const x = temp_x. | 3394 // make statement: let/const x = temp_x. |
3404 for (int i = 0; i < names->length(); i++) { | 3395 for (int i = 0; i < names->length(); i++) { |
3405 VariableProxy* proxy = NewUnresolved(names->at(i), mode); | 3396 VariableProxy* proxy = NewUnresolved(names->at(i), mode); |
3406 Declaration* declaration = factory()->NewVariableDeclaration( | 3397 Declaration* declaration = factory()->NewVariableDeclaration( |
3407 proxy, mode, scope_, RelocInfo::kNoPosition); | 3398 proxy, mode, scope_, kNoSourcePosition); |
3408 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 3399 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
3409 inner_vars.Add(declaration->proxy()->var(), zone()); | 3400 inner_vars.Add(declaration->proxy()->var(), zone()); |
3410 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); | 3401 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); |
3411 Assignment* assignment = factory()->NewAssignment( | 3402 Assignment* assignment = factory()->NewAssignment( |
3412 Token::INIT, proxy, temp_proxy, RelocInfo::kNoPosition); | 3403 Token::INIT, proxy, temp_proxy, kNoSourcePosition); |
3413 Statement* assignment_statement = | 3404 Statement* assignment_statement = |
3414 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 3405 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
3415 DCHECK(init->position() != RelocInfo::kNoPosition); | 3406 DCHECK(init->position() != kNoSourcePosition); |
3416 proxy->var()->set_initializer_position(init->position()); | 3407 proxy->var()->set_initializer_position(init->position()); |
3417 ignore_completion_block->statements()->Add(assignment_statement, zone()); | 3408 ignore_completion_block->statements()->Add(assignment_statement, zone()); |
3418 } | 3409 } |
3419 | 3410 |
3420 // Make statement: if (first == 1) { first = 0; } else { next; } | 3411 // Make statement: if (first == 1) { first = 0; } else { next; } |
3421 if (next) { | 3412 if (next) { |
3422 DCHECK(first); | 3413 DCHECK(first); |
3423 Expression* compare = NULL; | 3414 Expression* compare = NULL; |
3424 // Make compare expression: first == 1. | 3415 // Make compare expression: first == 1. |
3425 { | 3416 { |
3426 Expression* const1 = | 3417 Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition); |
3427 factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); | |
3428 VariableProxy* first_proxy = factory()->NewVariableProxy(first); | 3418 VariableProxy* first_proxy = factory()->NewVariableProxy(first); |
3429 compare = factory()->NewCompareOperation(Token::EQ, first_proxy, const1, | 3419 compare = factory()->NewCompareOperation(Token::EQ, first_proxy, const1, |
3430 RelocInfo::kNoPosition); | 3420 kNoSourcePosition); |
3431 } | 3421 } |
3432 Statement* clear_first = NULL; | 3422 Statement* clear_first = NULL; |
3433 // Make statement: first = 0. | 3423 // Make statement: first = 0. |
3434 { | 3424 { |
3435 VariableProxy* first_proxy = factory()->NewVariableProxy(first); | 3425 VariableProxy* first_proxy = factory()->NewVariableProxy(first); |
3436 Expression* const0 = | 3426 Expression* const0 = factory()->NewSmiLiteral(0, kNoSourcePosition); |
3437 factory()->NewSmiLiteral(0, RelocInfo::kNoPosition); | |
3438 Assignment* assignment = factory()->NewAssignment( | 3427 Assignment* assignment = factory()->NewAssignment( |
3439 Token::ASSIGN, first_proxy, const0, RelocInfo::kNoPosition); | 3428 Token::ASSIGN, first_proxy, const0, kNoSourcePosition); |
3440 clear_first = factory()->NewExpressionStatement(assignment, | 3429 clear_first = |
3441 RelocInfo::kNoPosition); | 3430 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
3442 } | 3431 } |
3443 Statement* clear_first_or_next = factory()->NewIfStatement( | 3432 Statement* clear_first_or_next = factory()->NewIfStatement( |
3444 compare, clear_first, next, RelocInfo::kNoPosition); | 3433 compare, clear_first, next, kNoSourcePosition); |
3445 ignore_completion_block->statements()->Add(clear_first_or_next, zone()); | 3434 ignore_completion_block->statements()->Add(clear_first_or_next, zone()); |
3446 } | 3435 } |
3447 | 3436 |
3448 Variable* flag = scope_->NewTemporary(temp_name); | 3437 Variable* flag = scope_->NewTemporary(temp_name); |
3449 // Make statement: flag = 1. | 3438 // Make statement: flag = 1. |
3450 { | 3439 { |
3451 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); | 3440 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
3452 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); | 3441 Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition); |
3453 Assignment* assignment = factory()->NewAssignment( | 3442 Assignment* assignment = factory()->NewAssignment( |
3454 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition); | 3443 Token::ASSIGN, flag_proxy, const1, kNoSourcePosition); |
3455 Statement* assignment_statement = | 3444 Statement* assignment_statement = |
3456 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 3445 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
3457 ignore_completion_block->statements()->Add(assignment_statement, zone()); | 3446 ignore_completion_block->statements()->Add(assignment_statement, zone()); |
3458 } | 3447 } |
3459 | 3448 |
3460 // Make statement: if (!cond) break. | 3449 // Make statement: if (!cond) break. |
3461 if (cond) { | 3450 if (cond) { |
3462 Statement* stop = | 3451 Statement* stop = |
3463 factory()->NewBreakStatement(outer_loop, RelocInfo::kNoPosition); | 3452 factory()->NewBreakStatement(outer_loop, kNoSourcePosition); |
3464 Statement* noop = factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 3453 Statement* noop = factory()->NewEmptyStatement(kNoSourcePosition); |
3465 ignore_completion_block->statements()->Add( | 3454 ignore_completion_block->statements()->Add( |
3466 factory()->NewIfStatement(cond, noop, stop, cond->position()), | 3455 factory()->NewIfStatement(cond, noop, stop, cond->position()), |
3467 zone()); | 3456 zone()); |
3468 } | 3457 } |
3469 | 3458 |
3470 inner_block->statements()->Add(ignore_completion_block, zone()); | 3459 inner_block->statements()->Add(ignore_completion_block, zone()); |
3471 // Make cond expression for main loop: flag == 1. | 3460 // Make cond expression for main loop: flag == 1. |
3472 Expression* flag_cond = NULL; | 3461 Expression* flag_cond = NULL; |
3473 { | 3462 { |
3474 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); | 3463 Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition); |
3475 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); | 3464 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
3476 flag_cond = factory()->NewCompareOperation(Token::EQ, flag_proxy, const1, | 3465 flag_cond = factory()->NewCompareOperation(Token::EQ, flag_proxy, const1, |
3477 RelocInfo::kNoPosition); | 3466 kNoSourcePosition); |
3478 } | 3467 } |
3479 | 3468 |
3480 // Create chain of expressions "flag = 0, temp_x = x, ..." | 3469 // Create chain of expressions "flag = 0, temp_x = x, ..." |
3481 Statement* compound_next_statement = NULL; | 3470 Statement* compound_next_statement = NULL; |
3482 { | 3471 { |
3483 Expression* compound_next = NULL; | 3472 Expression* compound_next = NULL; |
3484 // Make expression: flag = 0. | 3473 // Make expression: flag = 0. |
3485 { | 3474 { |
3486 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); | 3475 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
3487 Expression* const0 = | 3476 Expression* const0 = factory()->NewSmiLiteral(0, kNoSourcePosition); |
3488 factory()->NewSmiLiteral(0, RelocInfo::kNoPosition); | 3477 compound_next = factory()->NewAssignment(Token::ASSIGN, flag_proxy, |
3489 compound_next = factory()->NewAssignment( | 3478 const0, kNoSourcePosition); |
3490 Token::ASSIGN, flag_proxy, const0, RelocInfo::kNoPosition); | |
3491 } | 3479 } |
3492 | 3480 |
3493 // Make the comma-separated list of temp_x = x assignments. | 3481 // Make the comma-separated list of temp_x = x assignments. |
3494 int inner_var_proxy_pos = scanner()->location().beg_pos; | 3482 int inner_var_proxy_pos = scanner()->location().beg_pos; |
3495 for (int i = 0; i < names->length(); i++) { | 3483 for (int i = 0; i < names->length(); i++) { |
3496 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); | 3484 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); |
3497 VariableProxy* proxy = | 3485 VariableProxy* proxy = |
3498 factory()->NewVariableProxy(inner_vars.at(i), inner_var_proxy_pos); | 3486 factory()->NewVariableProxy(inner_vars.at(i), inner_var_proxy_pos); |
3499 Assignment* assignment = factory()->NewAssignment( | 3487 Assignment* assignment = factory()->NewAssignment( |
3500 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); | 3488 Token::ASSIGN, temp_proxy, proxy, kNoSourcePosition); |
3501 compound_next = factory()->NewBinaryOperation( | 3489 compound_next = factory()->NewBinaryOperation( |
3502 Token::COMMA, compound_next, assignment, RelocInfo::kNoPosition); | 3490 Token::COMMA, compound_next, assignment, kNoSourcePosition); |
3503 } | 3491 } |
3504 | 3492 |
3505 compound_next_statement = factory()->NewExpressionStatement( | 3493 compound_next_statement = |
3506 compound_next, RelocInfo::kNoPosition); | 3494 factory()->NewExpressionStatement(compound_next, kNoSourcePosition); |
3507 } | 3495 } |
3508 | 3496 |
3509 // Make statement: labels: for (; flag == 1; flag = 0, temp_x = x) | 3497 // Make statement: labels: for (; flag == 1; flag = 0, temp_x = x) |
3510 // Note that we re-use the original loop node, which retains its labels | 3498 // Note that we re-use the original loop node, which retains its labels |
3511 // and ensures that any break or continue statements in body point to | 3499 // and ensures that any break or continue statements in body point to |
3512 // the right place. | 3500 // the right place. |
3513 loop->Initialize(NULL, flag_cond, compound_next_statement, body); | 3501 loop->Initialize(NULL, flag_cond, compound_next_statement, body); |
3514 inner_block->statements()->Add(loop, zone()); | 3502 inner_block->statements()->Add(loop, zone()); |
3515 | 3503 |
3516 // Make statement: {{if (flag == 1) break;}} | 3504 // Make statement: {{if (flag == 1) break;}} |
3517 { | 3505 { |
3518 Expression* compare = NULL; | 3506 Expression* compare = NULL; |
3519 // Make compare expresion: flag == 1. | 3507 // Make compare expresion: flag == 1. |
3520 { | 3508 { |
3521 Expression* const1 = | 3509 Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition); |
3522 factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); | |
3523 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); | 3510 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
3524 compare = factory()->NewCompareOperation(Token::EQ, flag_proxy, const1, | 3511 compare = factory()->NewCompareOperation(Token::EQ, flag_proxy, const1, |
3525 RelocInfo::kNoPosition); | 3512 kNoSourcePosition); |
3526 } | 3513 } |
3527 Statement* stop = | 3514 Statement* stop = |
3528 factory()->NewBreakStatement(outer_loop, RelocInfo::kNoPosition); | 3515 factory()->NewBreakStatement(outer_loop, kNoSourcePosition); |
3529 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 3516 Statement* empty = factory()->NewEmptyStatement(kNoSourcePosition); |
3530 Statement* if_flag_break = factory()->NewIfStatement( | 3517 Statement* if_flag_break = |
3531 compare, stop, empty, RelocInfo::kNoPosition); | 3518 factory()->NewIfStatement(compare, stop, empty, kNoSourcePosition); |
3532 Block* ignore_completion_block = | 3519 Block* ignore_completion_block = |
3533 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); | 3520 factory()->NewBlock(NULL, 1, true, kNoSourcePosition); |
3534 ignore_completion_block->statements()->Add(if_flag_break, zone()); | 3521 ignore_completion_block->statements()->Add(if_flag_break, zone()); |
3535 inner_block->statements()->Add(ignore_completion_block, zone()); | 3522 inner_block->statements()->Add(ignore_completion_block, zone()); |
3536 } | 3523 } |
3537 | 3524 |
3538 inner_scope->set_end_position(scanner()->location().end_pos); | 3525 inner_scope->set_end_position(scanner()->location().end_pos); |
3539 inner_block->set_scope(inner_scope); | 3526 inner_block->set_scope(inner_scope); |
3540 } | 3527 } |
3541 | 3528 |
3542 outer_loop->Initialize(NULL, NULL, NULL, inner_block); | 3529 outer_loop->Initialize(NULL, NULL, NULL, inner_block); |
3543 return outer_block; | 3530 return outer_block; |
3544 } | 3531 } |
3545 | 3532 |
3546 Statement* Parser::ParseScopedStatement(ZoneList<const AstRawString*>* labels, | 3533 Statement* Parser::ParseScopedStatement(ZoneList<const AstRawString*>* labels, |
3547 bool legacy, bool* ok) { | 3534 bool legacy, bool* ok) { |
3548 if (is_strict(language_mode()) || peek() != Token::FUNCTION || | 3535 if (is_strict(language_mode()) || peek() != Token::FUNCTION || |
3549 (legacy && allow_harmony_restrictive_declarations())) { | 3536 (legacy && allow_harmony_restrictive_declarations())) { |
3550 return ParseSubStatement(labels, kDisallowLabelledFunctionStatement, ok); | 3537 return ParseSubStatement(labels, kDisallowLabelledFunctionStatement, ok); |
3551 } else { | 3538 } else { |
3552 if (legacy) { | 3539 if (legacy) { |
3553 ++use_counts_[v8::Isolate::kLegacyFunctionDeclaration]; | 3540 ++use_counts_[v8::Isolate::kLegacyFunctionDeclaration]; |
3554 } | 3541 } |
3555 // Make a block around the statement for a lexical binding | 3542 // Make a block around the statement for a lexical binding |
3556 // is introduced by a FunctionDeclaration. | 3543 // is introduced by a FunctionDeclaration. |
3557 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); | 3544 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); |
3558 body_scope->set_start_position(scanner()->location().beg_pos); | 3545 body_scope->set_start_position(scanner()->location().beg_pos); |
3559 BlockState block_state(&scope_, body_scope); | 3546 BlockState block_state(&scope_, body_scope); |
3560 Block* block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); | 3547 Block* block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); |
3561 Statement* body = ParseFunctionDeclaration(CHECK_OK); | 3548 Statement* body = ParseFunctionDeclaration(CHECK_OK); |
3562 block->statements()->Add(body, zone()); | 3549 block->statements()->Add(body, zone()); |
3563 body_scope->set_end_position(scanner()->location().end_pos); | 3550 body_scope->set_end_position(scanner()->location().end_pos); |
3564 body_scope = body_scope->FinalizeBlockScope(); | 3551 body_scope = body_scope->FinalizeBlockScope(); |
3565 block->set_scope(body_scope); | 3552 block->set_scope(body_scope); |
3566 return block; | 3553 return block; |
3567 } | 3554 } |
3568 } | 3555 } |
3569 | 3556 |
3570 Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, | 3557 Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3630 ++use_counts_[v8::Isolate::kForInInitializer]; | 3617 ++use_counts_[v8::Isolate::kForInInitializer]; |
3631 const AstRawString* name = | 3618 const AstRawString* name = |
3632 decl.pattern->AsVariableProxy()->raw_name(); | 3619 decl.pattern->AsVariableProxy()->raw_name(); |
3633 VariableProxy* single_var = scope_->NewUnresolved( | 3620 VariableProxy* single_var = scope_->NewUnresolved( |
3634 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); | 3621 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); |
3635 init_block = factory()->NewBlock( | 3622 init_block = factory()->NewBlock( |
3636 nullptr, 2, true, parsing_result.descriptor.declaration_pos); | 3623 nullptr, 2, true, parsing_result.descriptor.declaration_pos); |
3637 init_block->statements()->Add( | 3624 init_block->statements()->Add( |
3638 factory()->NewExpressionStatement( | 3625 factory()->NewExpressionStatement( |
3639 factory()->NewAssignment(Token::ASSIGN, single_var, | 3626 factory()->NewAssignment(Token::ASSIGN, single_var, |
3640 decl.initializer, | 3627 decl.initializer, kNoSourcePosition), |
3641 RelocInfo::kNoPosition), | 3628 kNoSourcePosition), |
3642 RelocInfo::kNoPosition), | |
3643 zone()); | 3629 zone()); |
3644 } | 3630 } |
3645 | 3631 |
3646 // Rewrite a for-in/of statement of the form | 3632 // Rewrite a for-in/of statement of the form |
3647 // | 3633 // |
3648 // for (let/const/var x in/of e) b | 3634 // for (let/const/var x in/of e) b |
3649 // | 3635 // |
3650 // into | 3636 // into |
3651 // | 3637 // |
3652 // { | 3638 // { |
(...skipping 22 matching lines...) Expand all Loading... |
3675 } else { | 3661 } else { |
3676 enumerable = ParseExpression(true, CHECK_OK); | 3662 enumerable = ParseExpression(true, CHECK_OK); |
3677 } | 3663 } |
3678 | 3664 |
3679 Expect(Token::RPAREN, CHECK_OK); | 3665 Expect(Token::RPAREN, CHECK_OK); |
3680 | 3666 |
3681 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); | 3667 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); |
3682 body_scope->set_start_position(scanner()->location().beg_pos); | 3668 body_scope->set_start_position(scanner()->location().beg_pos); |
3683 | 3669 |
3684 Block* body_block = | 3670 Block* body_block = |
3685 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 3671 factory()->NewBlock(NULL, 3, false, kNoSourcePosition); |
3686 | 3672 |
3687 { | 3673 { |
3688 ReturnExprScope no_tail_calls(function_state_, | 3674 ReturnExprScope no_tail_calls(function_state_, |
3689 ReturnExprContext::kInsideForInOfBody); | 3675 ReturnExprContext::kInsideForInOfBody); |
3690 BlockState block_state(&scope_, body_scope); | 3676 BlockState block_state(&scope_, body_scope); |
3691 | 3677 |
3692 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); | 3678 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); |
3693 | 3679 |
3694 auto each_initialization_block = | 3680 auto each_initialization_block = |
3695 factory()->NewBlock(nullptr, 1, true, RelocInfo::kNoPosition); | 3681 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
3696 { | 3682 { |
3697 auto descriptor = parsing_result.descriptor; | 3683 auto descriptor = parsing_result.descriptor; |
3698 descriptor.declaration_pos = RelocInfo::kNoPosition; | 3684 descriptor.declaration_pos = kNoSourcePosition; |
3699 descriptor.initialization_pos = RelocInfo::kNoPosition; | 3685 descriptor.initialization_pos = kNoSourcePosition; |
3700 decl.initializer = factory()->NewVariableProxy(temp); | 3686 decl.initializer = factory()->NewVariableProxy(temp); |
3701 | 3687 |
3702 PatternRewriter::DeclareAndInitializeVariables( | 3688 PatternRewriter::DeclareAndInitializeVariables( |
3703 each_initialization_block, &descriptor, &decl, | 3689 each_initialization_block, &descriptor, &decl, |
3704 IsLexicalVariableMode(descriptor.mode) ? &lexical_bindings | 3690 IsLexicalVariableMode(descriptor.mode) ? &lexical_bindings |
3705 : nullptr, | 3691 : nullptr, |
3706 CHECK_OK); | 3692 CHECK_OK); |
3707 } | 3693 } |
3708 | 3694 |
3709 body_block->statements()->Add(each_initialization_block, zone()); | 3695 body_block->statements()->Add(each_initialization_block, zone()); |
3710 body_block->statements()->Add(body, zone()); | 3696 body_block->statements()->Add(body, zone()); |
3711 VariableProxy* temp_proxy = | 3697 VariableProxy* temp_proxy = |
3712 factory()->NewVariableProxy(temp, each_beg_pos, each_end_pos); | 3698 factory()->NewVariableProxy(temp, each_beg_pos, each_end_pos); |
3713 InitializeForEachStatement(loop, temp_proxy, enumerable, body_block, | 3699 InitializeForEachStatement(loop, temp_proxy, enumerable, body_block, |
3714 each_keyword_position); | 3700 each_keyword_position); |
3715 } | 3701 } |
3716 body_scope->set_end_position(scanner()->location().end_pos); | 3702 body_scope->set_end_position(scanner()->location().end_pos); |
3717 body_scope = body_scope->FinalizeBlockScope(); | 3703 body_scope = body_scope->FinalizeBlockScope(); |
3718 body_block->set_scope(body_scope); | 3704 body_block->set_scope(body_scope); |
3719 | 3705 |
3720 // Create a TDZ for any lexically-bound names. | 3706 // Create a TDZ for any lexically-bound names. |
3721 if (IsLexicalVariableMode(parsing_result.descriptor.mode)) { | 3707 if (IsLexicalVariableMode(parsing_result.descriptor.mode)) { |
3722 DCHECK_NULL(init_block); | 3708 DCHECK_NULL(init_block); |
3723 | 3709 |
3724 init_block = | 3710 init_block = |
3725 factory()->NewBlock(nullptr, 1, false, RelocInfo::kNoPosition); | 3711 factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); |
3726 | 3712 |
3727 for (int i = 0; i < lexical_bindings.length(); ++i) { | 3713 for (int i = 0; i < lexical_bindings.length(); ++i) { |
3728 // TODO(adamk): This needs to be some sort of special | 3714 // TODO(adamk): This needs to be some sort of special |
3729 // INTERNAL variable that's invisible to the debugger | 3715 // INTERNAL variable that's invisible to the debugger |
3730 // but visible to everything else. | 3716 // but visible to everything else. |
3731 VariableProxy* tdz_proxy = | 3717 VariableProxy* tdz_proxy = |
3732 NewUnresolved(lexical_bindings[i], LET); | 3718 NewUnresolved(lexical_bindings[i], LET); |
3733 Declaration* tdz_decl = factory()->NewVariableDeclaration( | 3719 Declaration* tdz_decl = factory()->NewVariableDeclaration( |
3734 tdz_proxy, LET, scope_, RelocInfo::kNoPosition); | 3720 tdz_proxy, LET, scope_, kNoSourcePosition); |
3735 Variable* tdz_var = Declare( | 3721 Variable* tdz_var = Declare( |
3736 tdz_decl, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 3722 tdz_decl, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
3737 tdz_var->set_initializer_position(position()); | 3723 tdz_var->set_initializer_position(position()); |
3738 } | 3724 } |
3739 } | 3725 } |
3740 | 3726 |
3741 Statement* final_loop = loop->IsForOfStatement() | 3727 Statement* final_loop = |
3742 ? FinalizeForOfStatement( | 3728 loop->IsForOfStatement() |
3743 loop->AsForOfStatement(), RelocInfo::kNoPosition) | 3729 ? FinalizeForOfStatement(loop->AsForOfStatement(), |
3744 : loop; | 3730 kNoSourcePosition) |
| 3731 : loop; |
3745 | 3732 |
3746 for_scope->set_end_position(scanner()->location().end_pos); | 3733 for_scope->set_end_position(scanner()->location().end_pos); |
3747 for_scope = for_scope->FinalizeBlockScope(); | 3734 for_scope = for_scope->FinalizeBlockScope(); |
3748 // Parsed for-in loop w/ variable declarations. | 3735 // Parsed for-in loop w/ variable declarations. |
3749 if (init_block != nullptr) { | 3736 if (init_block != nullptr) { |
3750 init_block->statements()->Add(final_loop, zone()); | 3737 init_block->statements()->Add(final_loop, zone()); |
3751 init_block->set_scope(for_scope); | 3738 init_block->set_scope(for_scope); |
3752 return init_block; | 3739 return init_block; |
3753 } else { | 3740 } else { |
3754 DCHECK_NULL(for_scope); | 3741 DCHECK_NULL(for_scope); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3802 } | 3789 } |
3803 | 3790 |
3804 Expect(Token::RPAREN, CHECK_OK); | 3791 Expect(Token::RPAREN, CHECK_OK); |
3805 | 3792 |
3806 // For legacy compat reasons, give for loops similar treatment to | 3793 // For legacy compat reasons, give for loops similar treatment to |
3807 // if statements in allowing a function declaration for a body | 3794 // if statements in allowing a function declaration for a body |
3808 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); | 3795 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); |
3809 InitializeForEachStatement(loop, expression, enumerable, body, | 3796 InitializeForEachStatement(loop, expression, enumerable, body, |
3810 each_keyword_position); | 3797 each_keyword_position); |
3811 | 3798 |
3812 Statement* final_loop = loop->IsForOfStatement() | 3799 Statement* final_loop = |
3813 ? FinalizeForOfStatement( | 3800 loop->IsForOfStatement() |
3814 loop->AsForOfStatement(), RelocInfo::kNoPosition) | 3801 ? FinalizeForOfStatement(loop->AsForOfStatement(), |
3815 : loop; | 3802 kNoSourcePosition) |
| 3803 : loop; |
3816 | 3804 |
3817 for_scope->set_end_position(scanner()->location().end_pos); | 3805 for_scope->set_end_position(scanner()->location().end_pos); |
3818 for_scope = for_scope->FinalizeBlockScope(); | 3806 for_scope = for_scope->FinalizeBlockScope(); |
3819 DCHECK(for_scope == nullptr); | 3807 DCHECK(for_scope == nullptr); |
3820 return final_loop; | 3808 return final_loop; |
3821 | 3809 |
3822 } else { | 3810 } else { |
3823 init = factory()->NewExpressionStatement(expression, lhs_beg_pos); | 3811 init = factory()->NewExpressionStatement(expression, lhs_beg_pos); |
3824 } | 3812 } |
3825 } | 3813 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3882 // } | 3870 // } |
3883 // | 3871 // |
3884 // or, desugar | 3872 // or, desugar |
3885 // for (; c; n) b | 3873 // for (; c; n) b |
3886 // into | 3874 // into |
3887 // { | 3875 // { |
3888 // for (; c; n) b | 3876 // for (; c; n) b |
3889 // } | 3877 // } |
3890 // just in case b introduces a lexical binding some other way, e.g., if b | 3878 // just in case b introduces a lexical binding some other way, e.g., if b |
3891 // is a FunctionDeclaration. | 3879 // is a FunctionDeclaration. |
3892 Block* block = | 3880 Block* block = factory()->NewBlock(NULL, 2, false, kNoSourcePosition); |
3893 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); | |
3894 if (init != nullptr) { | 3881 if (init != nullptr) { |
3895 block->statements()->Add(init, zone()); | 3882 block->statements()->Add(init, zone()); |
3896 } | 3883 } |
3897 block->statements()->Add(loop, zone()); | 3884 block->statements()->Add(loop, zone()); |
3898 block->set_scope(for_scope); | 3885 block->set_scope(for_scope); |
3899 loop->Initialize(NULL, cond, next, body); | 3886 loop->Initialize(NULL, cond, next, body); |
3900 result = block; | 3887 result = block; |
3901 } else { | 3888 } else { |
3902 loop->Initialize(init, cond, next, body); | 3889 loop->Initialize(init, cond, next, body); |
3903 result = loop; | 3890 result = loop; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4049 // return Promise.reject(e); | 4036 // return Promise.reject(e); |
4050 // } | 4037 // } |
4051 // } | 4038 // } |
4052 scope->ForceContextAllocation(); | 4039 scope->ForceContextAllocation(); |
4053 Variable* temp = | 4040 Variable* temp = |
4054 scope_->NewTemporary(ast_value_factory()->dot_generator_object_string()); | 4041 scope_->NewTemporary(ast_value_factory()->dot_generator_object_string()); |
4055 function_state_->set_generator_object_variable(temp); | 4042 function_state_->set_generator_object_variable(temp); |
4056 | 4043 |
4057 Expression* init_generator_variable = factory()->NewAssignment( | 4044 Expression* init_generator_variable = factory()->NewAssignment( |
4058 Token::INIT, factory()->NewVariableProxy(temp), | 4045 Token::INIT, factory()->NewVariableProxy(temp), |
4059 BuildCreateJSGeneratorObject(pos, kind), RelocInfo::kNoPosition); | 4046 BuildCreateJSGeneratorObject(pos, kind), kNoSourcePosition); |
4060 body->Add(factory()->NewExpressionStatement(init_generator_variable, | 4047 body->Add(factory()->NewExpressionStatement(init_generator_variable, |
4061 RelocInfo::kNoPosition), | 4048 kNoSourcePosition), |
4062 zone()); | 4049 zone()); |
4063 | 4050 |
4064 Block* try_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); | 4051 Block* try_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); |
4065 | 4052 |
4066 ZoneList<Statement*>* inner_body = try_block->statements(); | 4053 ZoneList<Statement*>* inner_body = try_block->statements(); |
4067 | 4054 |
4068 Expression* return_value = nullptr; | 4055 Expression* return_value = nullptr; |
4069 if (body_type == FunctionBody::Normal) { | 4056 if (body_type == FunctionBody::Normal) { |
4070 ParseStatementList(inner_body, Token::RBRACE, ok); | 4057 ParseStatementList(inner_body, Token::RBRACE, ok); |
4071 if (!*ok) return; | 4058 if (!*ok) return; |
4072 return_value = factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); | 4059 return_value = factory()->NewUndefinedLiteral(kNoSourcePosition); |
4073 } else { | 4060 } else { |
4074 return_value = ParseAssignmentExpression(accept_IN, classifier, ok); | 4061 return_value = ParseAssignmentExpression(accept_IN, classifier, ok); |
4075 if (!*ok) return; | 4062 if (!*ok) return; |
4076 ParserTraits::RewriteNonPattern(classifier, ok); | 4063 ParserTraits::RewriteNonPattern(classifier, ok); |
4077 if (!*ok) return; | 4064 if (!*ok) return; |
4078 } | 4065 } |
4079 | 4066 |
4080 return_value = BuildPromiseResolve(return_value, return_value->position()); | 4067 return_value = BuildPromiseResolve(return_value, return_value->position()); |
4081 inner_body->Add( | 4068 inner_body->Add( |
4082 factory()->NewReturnStatement(return_value, return_value->position()), | 4069 factory()->NewReturnStatement(return_value, return_value->position()), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4156 LanguageMode language_mode, bool* ok) { | 4143 LanguageMode language_mode, bool* ok) { |
4157 // Function :: | 4144 // Function :: |
4158 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 4145 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
4159 // | 4146 // |
4160 // Getter :: | 4147 // Getter :: |
4161 // '(' ')' '{' FunctionBody '}' | 4148 // '(' ')' '{' FunctionBody '}' |
4162 // | 4149 // |
4163 // Setter :: | 4150 // Setter :: |
4164 // '(' PropertySetParameterList ')' '{' FunctionBody '}' | 4151 // '(' PropertySetParameterList ')' '{' FunctionBody '}' |
4165 | 4152 |
4166 int pos = function_token_pos == RelocInfo::kNoPosition | 4153 int pos = function_token_pos == kNoSourcePosition ? peek_position() |
4167 ? peek_position() : function_token_pos; | 4154 : function_token_pos; |
4168 | 4155 |
4169 bool is_generator = IsGeneratorFunction(kind); | 4156 bool is_generator = IsGeneratorFunction(kind); |
4170 | 4157 |
4171 // Anonymous functions were passed either the empty symbol or a null | 4158 // Anonymous functions were passed either the empty symbol or a null |
4172 // handle as the function name. Remember if we were passed a non-empty | 4159 // handle as the function name. Remember if we were passed a non-empty |
4173 // handle to decide whether to invoke function name inference. | 4160 // handle to decide whether to invoke function name inference. |
4174 bool should_infer_name = function_name == NULL; | 4161 bool should_infer_name = function_name == NULL; |
4175 | 4162 |
4176 // We want a non-null handle as the function name. | 4163 // We want a non-null handle as the function name. |
4177 if (should_infer_name) { | 4164 if (should_infer_name) { |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4494 scope_->uses_super_property(), scope_->calls_eval()); | 4481 scope_->uses_super_property(), scope_->calls_eval()); |
4495 } | 4482 } |
4496 } | 4483 } |
4497 | 4484 |
4498 | 4485 |
4499 Statement* Parser::BuildAssertIsCoercible(Variable* var) { | 4486 Statement* Parser::BuildAssertIsCoercible(Variable* var) { |
4500 // if (var === null || var === undefined) | 4487 // if (var === null || var === undefined) |
4501 // throw /* type error kNonCoercible) */; | 4488 // throw /* type error kNonCoercible) */; |
4502 | 4489 |
4503 Expression* condition = factory()->NewBinaryOperation( | 4490 Expression* condition = factory()->NewBinaryOperation( |
4504 Token::OR, factory()->NewCompareOperation( | 4491 Token::OR, |
4505 Token::EQ_STRICT, factory()->NewVariableProxy(var), | |
4506 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | |
4507 RelocInfo::kNoPosition), | |
4508 factory()->NewCompareOperation( | 4492 factory()->NewCompareOperation( |
4509 Token::EQ_STRICT, factory()->NewVariableProxy(var), | 4493 Token::EQ_STRICT, factory()->NewVariableProxy(var), |
4510 factory()->NewNullLiteral(RelocInfo::kNoPosition), | 4494 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition), |
4511 RelocInfo::kNoPosition), | 4495 factory()->NewCompareOperation( |
4512 RelocInfo::kNoPosition); | 4496 Token::EQ_STRICT, factory()->NewVariableProxy(var), |
| 4497 factory()->NewNullLiteral(kNoSourcePosition), kNoSourcePosition), |
| 4498 kNoSourcePosition); |
4513 Expression* throw_type_error = this->NewThrowTypeError( | 4499 Expression* throw_type_error = this->NewThrowTypeError( |
4514 MessageTemplate::kNonCoercible, ast_value_factory()->empty_string(), | 4500 MessageTemplate::kNonCoercible, ast_value_factory()->empty_string(), |
4515 RelocInfo::kNoPosition); | 4501 kNoSourcePosition); |
4516 IfStatement* if_statement = factory()->NewIfStatement( | 4502 IfStatement* if_statement = factory()->NewIfStatement( |
4517 condition, factory()->NewExpressionStatement(throw_type_error, | 4503 condition, |
4518 RelocInfo::kNoPosition), | 4504 factory()->NewExpressionStatement(throw_type_error, kNoSourcePosition), |
4519 factory()->NewEmptyStatement(RelocInfo::kNoPosition), | 4505 factory()->NewEmptyStatement(kNoSourcePosition), kNoSourcePosition); |
4520 RelocInfo::kNoPosition); | |
4521 return if_statement; | 4506 return if_statement; |
4522 } | 4507 } |
4523 | 4508 |
4524 | 4509 |
4525 class InitializerRewriter : public AstExpressionVisitor { | 4510 class InitializerRewriter : public AstExpressionVisitor { |
4526 public: | 4511 public: |
4527 InitializerRewriter(uintptr_t stack_limit, Expression* root, Parser* parser, | 4512 InitializerRewriter(uintptr_t stack_limit, Expression* root, Parser* parser, |
4528 Scope* scope) | 4513 Scope* scope) |
4529 : AstExpressionVisitor(stack_limit, root), | 4514 : AstExpressionVisitor(stack_limit, root), |
4530 parser_(parser), | 4515 parser_(parser), |
(...skipping 21 matching lines...) Expand all Loading... |
4552 void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) { | 4537 void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) { |
4553 InitializerRewriter rewriter(stack_limit_, expr, this, scope); | 4538 InitializerRewriter rewriter(stack_limit_, expr, this, scope); |
4554 rewriter.Run(); | 4539 rewriter.Run(); |
4555 } | 4540 } |
4556 | 4541 |
4557 | 4542 |
4558 Block* Parser::BuildParameterInitializationBlock( | 4543 Block* Parser::BuildParameterInitializationBlock( |
4559 const ParserFormalParameters& parameters, bool* ok) { | 4544 const ParserFormalParameters& parameters, bool* ok) { |
4560 DCHECK(!parameters.is_simple); | 4545 DCHECK(!parameters.is_simple); |
4561 DCHECK(scope_->is_function_scope()); | 4546 DCHECK(scope_->is_function_scope()); |
4562 Block* init_block = | 4547 Block* init_block = factory()->NewBlock(NULL, 1, true, kNoSourcePosition); |
4563 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); | |
4564 for (int i = 0; i < parameters.params.length(); ++i) { | 4548 for (int i = 0; i < parameters.params.length(); ++i) { |
4565 auto parameter = parameters.params[i]; | 4549 auto parameter = parameters.params[i]; |
4566 if (parameter.is_rest && parameter.pattern->IsVariableProxy()) break; | 4550 if (parameter.is_rest && parameter.pattern->IsVariableProxy()) break; |
4567 DeclarationDescriptor descriptor; | 4551 DeclarationDescriptor descriptor; |
4568 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; | 4552 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; |
4569 descriptor.parser = this; | 4553 descriptor.parser = this; |
4570 descriptor.scope = scope_; | 4554 descriptor.scope = scope_; |
4571 descriptor.hoist_scope = nullptr; | 4555 descriptor.hoist_scope = nullptr; |
4572 descriptor.mode = LET; | 4556 descriptor.mode = LET; |
4573 descriptor.declaration_pos = parameter.pattern->position(); | 4557 descriptor.declaration_pos = parameter.pattern->position(); |
4574 // The position that will be used by the AssignmentExpression | 4558 // The position that will be used by the AssignmentExpression |
4575 // which copies from the temp parameter to the pattern. | 4559 // which copies from the temp parameter to the pattern. |
4576 // | 4560 // |
4577 // TODO(adamk): Should this be RelocInfo::kNoPosition, since | 4561 // TODO(adamk): Should this be kNoSourcePosition, since |
4578 // it's just copying from a temp var to the real param var? | 4562 // it's just copying from a temp var to the real param var? |
4579 descriptor.initialization_pos = parameter.pattern->position(); | 4563 descriptor.initialization_pos = parameter.pattern->position(); |
4580 // The initializer position which will end up in, | 4564 // The initializer position which will end up in, |
4581 // Variable::initializer_position(), used for hole check elimination. | 4565 // Variable::initializer_position(), used for hole check elimination. |
4582 int initializer_position = parameter.pattern->position(); | 4566 int initializer_position = parameter.pattern->position(); |
4583 Expression* initial_value = | 4567 Expression* initial_value = |
4584 factory()->NewVariableProxy(parameters.scope->parameter(i)); | 4568 factory()->NewVariableProxy(parameters.scope->parameter(i)); |
4585 if (parameter.initializer != nullptr) { | 4569 if (parameter.initializer != nullptr) { |
4586 // IS_UNDEFINED($param) ? initializer : $param | 4570 // IS_UNDEFINED($param) ? initializer : $param |
4587 | 4571 |
4588 // Ensure initializer is rewritten | 4572 // Ensure initializer is rewritten |
4589 RewriteParameterInitializer(parameter.initializer, scope_); | 4573 RewriteParameterInitializer(parameter.initializer, scope_); |
4590 | 4574 |
4591 auto condition = factory()->NewCompareOperation( | 4575 auto condition = factory()->NewCompareOperation( |
4592 Token::EQ_STRICT, | 4576 Token::EQ_STRICT, |
4593 factory()->NewVariableProxy(parameters.scope->parameter(i)), | 4577 factory()->NewVariableProxy(parameters.scope->parameter(i)), |
4594 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | 4578 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition); |
4595 RelocInfo::kNoPosition); | |
4596 initial_value = factory()->NewConditional( | 4579 initial_value = factory()->NewConditional( |
4597 condition, parameter.initializer, initial_value, | 4580 condition, parameter.initializer, initial_value, kNoSourcePosition); |
4598 RelocInfo::kNoPosition); | |
4599 descriptor.initialization_pos = parameter.initializer->position(); | 4581 descriptor.initialization_pos = parameter.initializer->position(); |
4600 initializer_position = parameter.initializer_end_position; | 4582 initializer_position = parameter.initializer_end_position; |
4601 } | 4583 } |
4602 | 4584 |
4603 Scope* param_scope = scope_; | 4585 Scope* param_scope = scope_; |
4604 Block* param_block = init_block; | 4586 Block* param_block = init_block; |
4605 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { | 4587 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { |
4606 param_scope = NewScope(scope_, BLOCK_SCOPE); | 4588 param_scope = NewScope(scope_, BLOCK_SCOPE); |
4607 param_scope->set_is_declaration_scope(); | 4589 param_scope->set_is_declaration_scope(); |
4608 param_scope->set_start_position(descriptor.initialization_pos); | 4590 param_scope->set_start_position(descriptor.initialization_pos); |
4609 param_scope->set_end_position(parameter.initializer_end_position); | 4591 param_scope->set_end_position(parameter.initializer_end_position); |
4610 param_scope->RecordEvalCall(); | 4592 param_scope->RecordEvalCall(); |
4611 param_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); | 4593 param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); |
4612 param_block->set_scope(param_scope); | 4594 param_block->set_scope(param_scope); |
4613 descriptor.hoist_scope = scope_; | 4595 descriptor.hoist_scope = scope_; |
4614 // Pass the appropriate scope in so that PatternRewriter can appropriately | 4596 // Pass the appropriate scope in so that PatternRewriter can appropriately |
4615 // rewrite inner initializers of the pattern to param_scope | 4597 // rewrite inner initializers of the pattern to param_scope |
4616 descriptor.scope = param_scope; | 4598 descriptor.scope = param_scope; |
4617 // Rewrite the outer initializer to point to param_scope | 4599 // Rewrite the outer initializer to point to param_scope |
4618 RewriteParameterInitializerScope(stack_limit(), initial_value, scope_, | 4600 RewriteParameterInitializerScope(stack_limit(), initial_value, scope_, |
4619 param_scope); | 4601 param_scope); |
4620 } | 4602 } |
4621 | 4603 |
(...skipping 17 matching lines...) Expand all Loading... |
4639 } | 4621 } |
4640 | 4622 |
4641 Block* Parser::BuildRejectPromiseOnException(Block* block) { | 4623 Block* Parser::BuildRejectPromiseOnException(Block* block) { |
4642 // try { <block> } catch (error) { return Promise.reject(error); } | 4624 // try { <block> } catch (error) { return Promise.reject(error); } |
4643 Block* try_block = block; | 4625 Block* try_block = block; |
4644 Scope* catch_scope = NewScope(scope_, CATCH_SCOPE); | 4626 Scope* catch_scope = NewScope(scope_, CATCH_SCOPE); |
4645 catch_scope->set_is_hidden(); | 4627 catch_scope->set_is_hidden(); |
4646 Variable* catch_variable = | 4628 Variable* catch_variable = |
4647 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, | 4629 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, |
4648 kCreatedInitialized, Variable::NORMAL); | 4630 kCreatedInitialized, Variable::NORMAL); |
4649 Block* catch_block = | 4631 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
4650 factory()->NewBlock(nullptr, 1, true, RelocInfo::kNoPosition); | |
4651 | 4632 |
4652 Expression* promise_reject = BuildPromiseReject( | 4633 Expression* promise_reject = BuildPromiseReject( |
4653 factory()->NewVariableProxy(catch_variable), RelocInfo::kNoPosition); | 4634 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); |
4654 | 4635 |
4655 ReturnStatement* return_promise_reject = | 4636 ReturnStatement* return_promise_reject = |
4656 factory()->NewReturnStatement(promise_reject, RelocInfo::kNoPosition); | 4637 factory()->NewReturnStatement(promise_reject, kNoSourcePosition); |
4657 catch_block->statements()->Add(return_promise_reject, zone()); | 4638 catch_block->statements()->Add(return_promise_reject, zone()); |
4658 TryStatement* try_catch_statement = | 4639 TryStatement* try_catch_statement = factory()->NewTryCatchStatement( |
4659 factory()->NewTryCatchStatement(try_block, catch_scope, catch_variable, | 4640 try_block, catch_scope, catch_variable, catch_block, kNoSourcePosition); |
4660 catch_block, RelocInfo::kNoPosition); | |
4661 | 4641 |
4662 block = factory()->NewBlock(nullptr, 1, true, RelocInfo::kNoPosition); | 4642 block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
4663 block->statements()->Add(try_catch_statement, zone()); | 4643 block->statements()->Add(try_catch_statement, zone()); |
4664 return block; | 4644 return block; |
4665 } | 4645 } |
4666 | 4646 |
4667 Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { | 4647 Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { |
4668 DCHECK_NOT_NULL(function_state_->generator_object_variable()); | 4648 DCHECK_NOT_NULL(function_state_->generator_object_variable()); |
4669 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | 4649 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
4670 args->Add(factory()->NewThisFunction(pos), zone()); | 4650 args->Add(factory()->NewThisFunction(pos), zone()); |
4671 args->Add(IsArrowFunction(kind) | 4651 args->Add(IsArrowFunction(kind) |
4672 ? GetLiteralUndefined(pos) | 4652 ? GetLiteralUndefined(pos) |
4673 : ThisExpression(scope_, factory(), RelocInfo::kNoPosition), | 4653 : ThisExpression(scope_, factory(), kNoSourcePosition), |
4674 zone()); | 4654 zone()); |
4675 return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, | 4655 return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, |
4676 pos); | 4656 pos); |
4677 } | 4657 } |
4678 | 4658 |
4679 Expression* Parser::BuildPromiseResolve(Expression* value, int pos) { | 4659 Expression* Parser::BuildPromiseResolve(Expression* value, int pos) { |
4680 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); | 4660 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); |
4681 args->Add(value, zone()); | 4661 args->Add(value, zone()); |
4682 return factory()->NewCallRuntime(Context::PROMISE_CREATE_RESOLVED_INDEX, args, | 4662 return factory()->NewCallRuntime(Context::PROMISE_CREATE_RESOLVED_INDEX, args, |
4683 pos); | 4663 pos); |
(...skipping 27 matching lines...) Expand all Loading... |
4711 result->Add(NULL, zone()); | 4691 result->Add(NULL, zone()); |
4712 } | 4692 } |
4713 | 4693 |
4714 ZoneList<Statement*>* body = result; | 4694 ZoneList<Statement*>* body = result; |
4715 Scope* inner_scope = scope_; | 4695 Scope* inner_scope = scope_; |
4716 Block* inner_block = nullptr; | 4696 Block* inner_block = nullptr; |
4717 if (!parameters.is_simple) { | 4697 if (!parameters.is_simple) { |
4718 inner_scope = NewScope(scope_, BLOCK_SCOPE); | 4698 inner_scope = NewScope(scope_, BLOCK_SCOPE); |
4719 inner_scope->set_is_declaration_scope(); | 4699 inner_scope->set_is_declaration_scope(); |
4720 inner_scope->set_start_position(scanner()->location().beg_pos); | 4700 inner_scope->set_start_position(scanner()->location().beg_pos); |
4721 inner_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); | 4701 inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); |
4722 inner_block->set_scope(inner_scope); | 4702 inner_block->set_scope(inner_scope); |
4723 body = inner_block->statements(); | 4703 body = inner_block->statements(); |
4724 } | 4704 } |
4725 | 4705 |
4726 { | 4706 { |
4727 BlockState block_state(&scope_, inner_scope); | 4707 BlockState block_state(&scope_, inner_scope); |
4728 | 4708 |
4729 if (IsGeneratorFunction(kind)) { | 4709 if (IsGeneratorFunction(kind)) { |
4730 // We produce: | 4710 // We produce: |
4731 // | 4711 // |
4732 // try { InitialYield; ...body...; return {value: undefined, done: true} } | 4712 // try { InitialYield; ...body...; return {value: undefined, done: true} } |
4733 // finally { %_GeneratorClose(generator) } | 4713 // finally { %_GeneratorClose(generator) } |
4734 // | 4714 // |
4735 // - InitialYield yields the actual generator object. | 4715 // - InitialYield yields the actual generator object. |
4736 // - Any return statement inside the body will have its argument wrapped | 4716 // - Any return statement inside the body will have its argument wrapped |
4737 // in a "done" iterator result object. | 4717 // in a "done" iterator result object. |
4738 // - If the generator terminates for whatever reason, we must close it. | 4718 // - If the generator terminates for whatever reason, we must close it. |
4739 // Hence the finally clause. | 4719 // Hence the finally clause. |
4740 | 4720 |
4741 Block* try_block = | 4721 Block* try_block = |
4742 factory()->NewBlock(nullptr, 3, false, RelocInfo::kNoPosition); | 4722 factory()->NewBlock(nullptr, 3, false, kNoSourcePosition); |
4743 | 4723 |
4744 { | 4724 { |
4745 Expression* allocation = BuildCreateJSGeneratorObject(pos, kind); | 4725 Expression* allocation = BuildCreateJSGeneratorObject(pos, kind); |
4746 VariableProxy* init_proxy = factory()->NewVariableProxy( | 4726 VariableProxy* init_proxy = factory()->NewVariableProxy( |
4747 function_state_->generator_object_variable()); | 4727 function_state_->generator_object_variable()); |
4748 Assignment* assignment = factory()->NewAssignment( | 4728 Assignment* assignment = factory()->NewAssignment( |
4749 Token::INIT, init_proxy, allocation, RelocInfo::kNoPosition); | 4729 Token::INIT, init_proxy, allocation, kNoSourcePosition); |
4750 VariableProxy* get_proxy = factory()->NewVariableProxy( | 4730 VariableProxy* get_proxy = factory()->NewVariableProxy( |
4751 function_state_->generator_object_variable()); | 4731 function_state_->generator_object_variable()); |
4752 // The position of the yield is important for reporting the exception | 4732 // The position of the yield is important for reporting the exception |
4753 // caused by calling the .throw method on a generator suspended at the | 4733 // caused by calling the .throw method on a generator suspended at the |
4754 // initial yield (i.e. right after generator instantiation). | 4734 // initial yield (i.e. right after generator instantiation). |
4755 Yield* yield = factory()->NewYield(get_proxy, assignment, | 4735 Yield* yield = factory()->NewYield(get_proxy, assignment, |
4756 scope_->start_position()); | 4736 scope_->start_position()); |
4757 try_block->statements()->Add( | 4737 try_block->statements()->Add( |
4758 factory()->NewExpressionStatement(yield, RelocInfo::kNoPosition), | 4738 factory()->NewExpressionStatement(yield, kNoSourcePosition), |
4759 zone()); | 4739 zone()); |
4760 } | 4740 } |
4761 | 4741 |
4762 ParseStatementList(try_block->statements(), Token::RBRACE, CHECK_OK); | 4742 ParseStatementList(try_block->statements(), Token::RBRACE, CHECK_OK); |
4763 | 4743 |
4764 Statement* final_return = factory()->NewReturnStatement( | 4744 Statement* final_return = factory()->NewReturnStatement( |
4765 BuildIteratorResult(nullptr, true), RelocInfo::kNoPosition); | 4745 BuildIteratorResult(nullptr, true), kNoSourcePosition); |
4766 try_block->statements()->Add(final_return, zone()); | 4746 try_block->statements()->Add(final_return, zone()); |
4767 | 4747 |
4768 Block* finally_block = | 4748 Block* finally_block = |
4769 factory()->NewBlock(nullptr, 1, false, RelocInfo::kNoPosition); | 4749 factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); |
4770 ZoneList<Expression*>* args = | 4750 ZoneList<Expression*>* args = |
4771 new (zone()) ZoneList<Expression*>(1, zone()); | 4751 new (zone()) ZoneList<Expression*>(1, zone()); |
4772 VariableProxy* call_proxy = factory()->NewVariableProxy( | 4752 VariableProxy* call_proxy = factory()->NewVariableProxy( |
4773 function_state_->generator_object_variable()); | 4753 function_state_->generator_object_variable()); |
4774 args->Add(call_proxy, zone()); | 4754 args->Add(call_proxy, zone()); |
4775 Expression* call = factory()->NewCallRuntime( | 4755 Expression* call = factory()->NewCallRuntime( |
4776 Runtime::kInlineGeneratorClose, args, RelocInfo::kNoPosition); | 4756 Runtime::kInlineGeneratorClose, args, kNoSourcePosition); |
4777 finally_block->statements()->Add( | 4757 finally_block->statements()->Add( |
4778 factory()->NewExpressionStatement(call, RelocInfo::kNoPosition), | 4758 factory()->NewExpressionStatement(call, kNoSourcePosition), zone()); |
4779 zone()); | |
4780 | 4759 |
4781 body->Add(factory()->NewTryFinallyStatement(try_block, finally_block, | 4760 body->Add(factory()->NewTryFinallyStatement(try_block, finally_block, |
4782 RelocInfo::kNoPosition), | 4761 kNoSourcePosition), |
4783 zone()); | 4762 zone()); |
4784 } else if (IsAsyncFunction(kind)) { | 4763 } else if (IsAsyncFunction(kind)) { |
4785 const bool accept_IN = true; | 4764 const bool accept_IN = true; |
4786 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind, | 4765 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind, |
4787 FunctionBody::Normal, accept_IN, pos, CHECK_OK); | 4766 FunctionBody::Normal, accept_IN, pos, CHECK_OK); |
4788 } else { | 4767 } else { |
4789 ParseStatementList(body, Token::RBRACE, CHECK_OK); | 4768 ParseStatementList(body, Token::RBRACE, CHECK_OK); |
4790 } | 4769 } |
4791 | 4770 |
4792 if (IsSubclassConstructor(kind)) { | 4771 if (IsSubclassConstructor(kind)) { |
4793 body->Add( | 4772 body->Add(factory()->NewReturnStatement( |
4794 factory()->NewReturnStatement( | 4773 this->ThisExpression(scope_, factory(), kNoSourcePosition), |
4795 this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition), | 4774 kNoSourcePosition), |
4796 RelocInfo::kNoPosition), | 4775 zone()); |
4797 zone()); | |
4798 } | 4776 } |
4799 } | 4777 } |
4800 | 4778 |
4801 Expect(Token::RBRACE, CHECK_OK); | 4779 Expect(Token::RBRACE, CHECK_OK); |
4802 scope_->set_end_position(scanner()->location().end_pos); | 4780 scope_->set_end_position(scanner()->location().end_pos); |
4803 | 4781 |
4804 if (!parameters.is_simple) { | 4782 if (!parameters.is_simple) { |
4805 DCHECK_NOT_NULL(inner_scope); | 4783 DCHECK_NOT_NULL(inner_scope); |
4806 DCHECK_EQ(body, inner_block->statements()); | 4784 DCHECK_EQ(body, inner_block->statements()); |
4807 SetLanguageMode(scope_, inner_scope->language_mode()); | 4785 SetLanguageMode(scope_, inner_scope->language_mode()); |
(...skipping 30 matching lines...) Expand all Loading... |
4838 // in the previously reserved spot. | 4816 // in the previously reserved spot. |
4839 // NOTE: We create a proxy and resolve it here so that in the | 4817 // NOTE: We create a proxy and resolve it here so that in the |
4840 // future we can change the AST to only refer to VariableProxies | 4818 // future we can change the AST to only refer to VariableProxies |
4841 // instead of Variables and Proxies as is the case now. | 4819 // instead of Variables and Proxies as is the case now. |
4842 VariableMode fvar_mode = is_strict(language_mode()) ? CONST : CONST_LEGACY; | 4820 VariableMode fvar_mode = is_strict(language_mode()) ? CONST : CONST_LEGACY; |
4843 Variable* fvar = new (zone()) | 4821 Variable* fvar = new (zone()) |
4844 Variable(scope_, function_name, fvar_mode, Variable::NORMAL, | 4822 Variable(scope_, function_name, fvar_mode, Variable::NORMAL, |
4845 kCreatedInitialized, kNotAssigned); | 4823 kCreatedInitialized, kNotAssigned); |
4846 VariableProxy* proxy = factory()->NewVariableProxy(fvar); | 4824 VariableProxy* proxy = factory()->NewVariableProxy(fvar); |
4847 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( | 4825 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( |
4848 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); | 4826 proxy, fvar_mode, scope_, kNoSourcePosition); |
4849 scope_->DeclareFunctionVar(fvar_declaration); | 4827 scope_->DeclareFunctionVar(fvar_declaration); |
4850 | 4828 |
4851 VariableProxy* fproxy = factory()->NewVariableProxy(fvar); | 4829 VariableProxy* fproxy = factory()->NewVariableProxy(fvar); |
4852 result->Set(kFunctionNameAssignmentIndex, | 4830 result->Set(kFunctionNameAssignmentIndex, |
4853 factory()->NewExpressionStatement( | 4831 factory()->NewExpressionStatement( |
4854 factory()->NewAssignment(Token::INIT, fproxy, | 4832 factory()->NewAssignment(Token::INIT, fproxy, |
4855 factory()->NewThisFunction(pos), | 4833 factory()->NewThisFunction(pos), |
4856 RelocInfo::kNoPosition), | 4834 kNoSourcePosition), |
4857 RelocInfo::kNoPosition)); | 4835 kNoSourcePosition)); |
4858 } | 4836 } |
4859 | 4837 |
4860 MarkCollectedTailCallExpressions(); | 4838 MarkCollectedTailCallExpressions(); |
4861 return result; | 4839 return result; |
4862 } | 4840 } |
4863 | 4841 |
4864 | 4842 |
4865 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( | 4843 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( |
4866 SingletonLogger* logger, Scanner::BookmarkScope* bookmark) { | 4844 SingletonLogger* logger, Scanner::BookmarkScope* bookmark) { |
4867 // This function may be called on a background thread too; record only the | 4845 // This function may be called on a background thread too; record only the |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5077 return factory()->NewUndefinedLiteral(position); | 5055 return factory()->NewUndefinedLiteral(position); |
5078 } | 5056 } |
5079 | 5057 |
5080 | 5058 |
5081 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { | 5059 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { |
5082 Declaration* decl = scope->CheckConflictingVarDeclarations(); | 5060 Declaration* decl = scope->CheckConflictingVarDeclarations(); |
5083 if (decl != NULL) { | 5061 if (decl != NULL) { |
5084 // In ES6, conflicting variable bindings are early errors. | 5062 // In ES6, conflicting variable bindings are early errors. |
5085 const AstRawString* name = decl->proxy()->raw_name(); | 5063 const AstRawString* name = decl->proxy()->raw_name(); |
5086 int position = decl->proxy()->position(); | 5064 int position = decl->proxy()->position(); |
5087 Scanner::Location location = position == RelocInfo::kNoPosition | 5065 Scanner::Location location = |
5088 ? Scanner::Location::invalid() | 5066 position == kNoSourcePosition |
5089 : Scanner::Location(position, position + 1); | 5067 ? Scanner::Location::invalid() |
| 5068 : Scanner::Location(position, position + 1); |
5090 ParserTraits::ReportMessageAt(location, MessageTemplate::kVarRedeclaration, | 5069 ParserTraits::ReportMessageAt(location, MessageTemplate::kVarRedeclaration, |
5091 name); | 5070 name); |
5092 *ok = false; | 5071 *ok = false; |
5093 } | 5072 } |
5094 } | 5073 } |
5095 | 5074 |
5096 | 5075 |
5097 void Parser::InsertShadowingVarBindingInitializers(Block* inner_block) { | 5076 void Parser::InsertShadowingVarBindingInitializers(Block* inner_block) { |
5098 // For each var-binding that shadows a parameter, insert an assignment | 5077 // For each var-binding that shadows a parameter, insert an assignment |
5099 // initializing the variable with the parameter. | 5078 // initializing the variable with the parameter. |
5100 Scope* inner_scope = inner_block->scope(); | 5079 Scope* inner_scope = inner_block->scope(); |
5101 DCHECK(inner_scope->is_declaration_scope()); | 5080 DCHECK(inner_scope->is_declaration_scope()); |
5102 Scope* function_scope = inner_scope->outer_scope(); | 5081 Scope* function_scope = inner_scope->outer_scope(); |
5103 DCHECK(function_scope->is_function_scope()); | 5082 DCHECK(function_scope->is_function_scope()); |
5104 ZoneList<Declaration*>* decls = inner_scope->declarations(); | 5083 ZoneList<Declaration*>* decls = inner_scope->declarations(); |
5105 for (int i = 0; i < decls->length(); ++i) { | 5084 for (int i = 0; i < decls->length(); ++i) { |
5106 Declaration* decl = decls->at(i); | 5085 Declaration* decl = decls->at(i); |
5107 if (decl->mode() != VAR || !decl->IsVariableDeclaration()) continue; | 5086 if (decl->mode() != VAR || !decl->IsVariableDeclaration()) continue; |
5108 const AstRawString* name = decl->proxy()->raw_name(); | 5087 const AstRawString* name = decl->proxy()->raw_name(); |
5109 Variable* parameter = function_scope->LookupLocal(name); | 5088 Variable* parameter = function_scope->LookupLocal(name); |
5110 if (parameter == nullptr) continue; | 5089 if (parameter == nullptr) continue; |
5111 VariableProxy* to = inner_scope->NewUnresolved(factory(), name); | 5090 VariableProxy* to = inner_scope->NewUnresolved(factory(), name); |
5112 VariableProxy* from = factory()->NewVariableProxy(parameter); | 5091 VariableProxy* from = factory()->NewVariableProxy(parameter); |
5113 Expression* assignment = factory()->NewAssignment( | 5092 Expression* assignment = |
5114 Token::ASSIGN, to, from, RelocInfo::kNoPosition); | 5093 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition); |
5115 Statement* statement = factory()->NewExpressionStatement( | 5094 Statement* statement = |
5116 assignment, RelocInfo::kNoPosition); | 5095 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
5117 inner_block->statements()->InsertAt(0, statement, zone()); | 5096 inner_block->statements()->InsertAt(0, statement, zone()); |
5118 } | 5097 } |
5119 } | 5098 } |
5120 | 5099 |
5121 void Parser::InsertSloppyBlockFunctionVarBindings(Scope* scope, | 5100 void Parser::InsertSloppyBlockFunctionVarBindings(Scope* scope, |
5122 Scope* complex_params_scope, | 5101 Scope* complex_params_scope, |
5123 bool* ok) { | 5102 bool* ok) { |
5124 // For each variable which is used as a function declaration in a sloppy | 5103 // For each variable which is used as a function declaration in a sloppy |
5125 // block, | 5104 // block, |
5126 DCHECK(scope->is_declaration_scope()); | 5105 DCHECK(scope->is_declaration_scope()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5174 query_scope = query_scope->outer_scope(); | 5153 query_scope = query_scope->outer_scope(); |
5175 } while (query_scope != outer_scope); | 5154 } while (query_scope != outer_scope); |
5176 | 5155 |
5177 if (!should_hoist) continue; | 5156 if (!should_hoist) continue; |
5178 | 5157 |
5179 // Declare a var-style binding for the function in the outer scope | 5158 // Declare a var-style binding for the function in the outer scope |
5180 if (!var_created) { | 5159 if (!var_created) { |
5181 var_created = true; | 5160 var_created = true; |
5182 VariableProxy* proxy = scope->NewUnresolved(factory(), name); | 5161 VariableProxy* proxy = scope->NewUnresolved(factory(), name); |
5183 Declaration* declaration = factory()->NewVariableDeclaration( | 5162 Declaration* declaration = factory()->NewVariableDeclaration( |
5184 proxy, VAR, scope, RelocInfo::kNoPosition); | 5163 proxy, VAR, scope, kNoSourcePosition); |
5185 Declare(declaration, DeclarationDescriptor::NORMAL, true, ok, scope); | 5164 Declare(declaration, DeclarationDescriptor::NORMAL, true, ok, scope); |
5186 DCHECK(ok); // Based on the preceding check, this should not fail | 5165 DCHECK(ok); // Based on the preceding check, this should not fail |
5187 if (!ok) return; | 5166 if (!ok) return; |
5188 } | 5167 } |
5189 | 5168 |
5190 // Read from the local lexical scope and write to the function scope | 5169 // Read from the local lexical scope and write to the function scope |
5191 VariableProxy* to = scope->NewUnresolved(factory(), name); | 5170 VariableProxy* to = scope->NewUnresolved(factory(), name); |
5192 VariableProxy* from = delegate->scope()->NewUnresolved(factory(), name); | 5171 VariableProxy* from = delegate->scope()->NewUnresolved(factory(), name); |
5193 Expression* assignment = factory()->NewAssignment(Token::ASSIGN, to, from, | 5172 Expression* assignment = |
5194 RelocInfo::kNoPosition); | 5173 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition); |
5195 Statement* statement = | 5174 Statement* statement = |
5196 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 5175 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
5197 delegate->set_statement(statement); | 5176 delegate->set_statement(statement); |
5198 } | 5177 } |
5199 } | 5178 } |
5200 } | 5179 } |
5201 | 5180 |
5202 | 5181 |
5203 // ---------------------------------------------------------------------------- | 5182 // ---------------------------------------------------------------------------- |
5204 // Parser support | 5183 // Parser support |
5205 | 5184 |
5206 bool Parser::TargetStackContainsLabel(const AstRawString* label) { | 5185 bool Parser::TargetStackContainsLabel(const AstRawString* label) { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5494 // Spread-call with single spread argument produces an InternalArray | 5473 // Spread-call with single spread argument produces an InternalArray |
5495 // containing the values from the array. | 5474 // containing the values from the array. |
5496 // | 5475 // |
5497 // Function is called or constructed with the produced array of arguments | 5476 // Function is called or constructed with the produced array of arguments |
5498 // | 5477 // |
5499 // EG: Apply(Func, Spread(spread0)) | 5478 // EG: Apply(Func, Spread(spread0)) |
5500 ZoneList<Expression*>* spread_list = | 5479 ZoneList<Expression*>* spread_list = |
5501 new (zone()) ZoneList<Expression*>(0, zone()); | 5480 new (zone()) ZoneList<Expression*>(0, zone()); |
5502 spread_list->Add(list->at(0)->AsSpread()->expression(), zone()); | 5481 spread_list->Add(list->at(0)->AsSpread()->expression(), zone()); |
5503 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX, | 5482 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX, |
5504 spread_list, RelocInfo::kNoPosition), | 5483 spread_list, kNoSourcePosition), |
5505 zone()); | 5484 zone()); |
5506 return args; | 5485 return args; |
5507 } else { | 5486 } else { |
5508 // Spread-call with multiple arguments produces array literals for each | 5487 // Spread-call with multiple arguments produces array literals for each |
5509 // sequences of unspread arguments, and converts each spread iterable to | 5488 // sequences of unspread arguments, and converts each spread iterable to |
5510 // an Internal array. Finally, all of these produced arrays are flattened | 5489 // an Internal array. Finally, all of these produced arrays are flattened |
5511 // into a single InternalArray, containing the arguments for the call. | 5490 // into a single InternalArray, containing the arguments for the call. |
5512 // | 5491 // |
5513 // EG: Apply(Func, Flatten([unspread0, unspread1], Spread(spread0), | 5492 // EG: Apply(Func, Flatten([unspread0, unspread1], Spread(spread0), |
5514 // Spread(spread1), [unspread2, unspread3])) | 5493 // Spread(spread1), [unspread2, unspread3])) |
5515 int i = 0; | 5494 int i = 0; |
5516 int n = list->length(); | 5495 int n = list->length(); |
5517 while (i < n) { | 5496 while (i < n) { |
5518 if (!list->at(i)->IsSpread()) { | 5497 if (!list->at(i)->IsSpread()) { |
5519 ZoneList<v8::internal::Expression*>* unspread = | 5498 ZoneList<v8::internal::Expression*>* unspread = |
5520 new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); | 5499 new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); |
5521 | 5500 |
5522 // Push array of unspread parameters | 5501 // Push array of unspread parameters |
5523 while (i < n && !list->at(i)->IsSpread()) { | 5502 while (i < n && !list->at(i)->IsSpread()) { |
5524 unspread->Add(list->at(i++), zone()); | 5503 unspread->Add(list->at(i++), zone()); |
5525 } | 5504 } |
5526 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 5505 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
5527 args->Add(factory()->NewArrayLiteral(unspread, literal_index, | 5506 args->Add(factory()->NewArrayLiteral(unspread, literal_index, |
5528 RelocInfo::kNoPosition), | 5507 kNoSourcePosition), |
5529 zone()); | 5508 zone()); |
5530 | 5509 |
5531 if (i == n) break; | 5510 if (i == n) break; |
5532 } | 5511 } |
5533 | 5512 |
5534 // Push eagerly spread argument | 5513 // Push eagerly spread argument |
5535 ZoneList<v8::internal::Expression*>* spread_list = | 5514 ZoneList<v8::internal::Expression*>* spread_list = |
5536 new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); | 5515 new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); |
5537 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone()); | 5516 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone()); |
5538 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX, | 5517 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX, |
5539 spread_list, RelocInfo::kNoPosition), | 5518 spread_list, kNoSourcePosition), |
5540 zone()); | 5519 zone()); |
5541 } | 5520 } |
5542 | 5521 |
5543 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); | 5522 list = new (zone()) ZoneList<v8::internal::Expression*>(1, zone()); |
5544 list->Add(factory()->NewCallRuntime(Context::SPREAD_ARGUMENTS_INDEX, args, | 5523 list->Add(factory()->NewCallRuntime(Context::SPREAD_ARGUMENTS_INDEX, args, |
5545 RelocInfo::kNoPosition), | 5524 kNoSourcePosition), |
5546 zone()); | 5525 zone()); |
5547 return list; | 5526 return list; |
5548 } | 5527 } |
5549 UNREACHABLE(); | 5528 UNREACHABLE(); |
5550 } | 5529 } |
5551 | 5530 |
5552 | 5531 |
5553 Expression* Parser::SpreadCall(Expression* function, | 5532 Expression* Parser::SpreadCall(Expression* function, |
5554 ZoneList<v8::internal::Expression*>* args, | 5533 ZoneList<v8::internal::Expression*>* args, |
5555 int pos) { | 5534 int pos) { |
5556 if (function->IsSuperCallReference()) { | 5535 if (function->IsSuperCallReference()) { |
5557 // Super calls | 5536 // Super calls |
5558 // $super_constructor = %_GetSuperConstructor(<this-function>) | 5537 // $super_constructor = %_GetSuperConstructor(<this-function>) |
5559 // %reflect_construct($super_constructor, args, new.target) | 5538 // %reflect_construct($super_constructor, args, new.target) |
5560 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone()); | 5539 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone()); |
5561 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone()); | 5540 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone()); |
5562 Expression* super_constructor = factory()->NewCallRuntime( | 5541 Expression* super_constructor = factory()->NewCallRuntime( |
5563 Runtime::kInlineGetSuperConstructor, tmp, pos); | 5542 Runtime::kInlineGetSuperConstructor, tmp, pos); |
5564 args->InsertAt(0, super_constructor, zone()); | 5543 args->InsertAt(0, super_constructor, zone()); |
5565 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); | 5544 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); |
5566 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, | 5545 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, |
5567 pos); | 5546 pos); |
5568 } else { | 5547 } else { |
5569 if (function->IsProperty()) { | 5548 if (function->IsProperty()) { |
5570 // Method calls | 5549 // Method calls |
5571 if (function->AsProperty()->IsSuperAccess()) { | 5550 if (function->AsProperty()->IsSuperAccess()) { |
5572 Expression* home = | 5551 Expression* home = ThisExpression(scope_, factory(), kNoSourcePosition); |
5573 ThisExpression(scope_, factory(), RelocInfo::kNoPosition); | |
5574 args->InsertAt(0, function, zone()); | 5552 args->InsertAt(0, function, zone()); |
5575 args->InsertAt(1, home, zone()); | 5553 args->InsertAt(1, home, zone()); |
5576 } else { | 5554 } else { |
5577 Variable* temp = | 5555 Variable* temp = |
5578 scope_->NewTemporary(ast_value_factory()->empty_string()); | 5556 scope_->NewTemporary(ast_value_factory()->empty_string()); |
5579 VariableProxy* obj = factory()->NewVariableProxy(temp); | 5557 VariableProxy* obj = factory()->NewVariableProxy(temp); |
5580 Assignment* assign_obj = factory()->NewAssignment( | 5558 Assignment* assign_obj = factory()->NewAssignment( |
5581 Token::ASSIGN, obj, function->AsProperty()->obj(), | 5559 Token::ASSIGN, obj, function->AsProperty()->obj(), |
5582 RelocInfo::kNoPosition); | 5560 kNoSourcePosition); |
5583 function = factory()->NewProperty( | 5561 function = factory()->NewProperty( |
5584 assign_obj, function->AsProperty()->key(), RelocInfo::kNoPosition); | 5562 assign_obj, function->AsProperty()->key(), kNoSourcePosition); |
5585 args->InsertAt(0, function, zone()); | 5563 args->InsertAt(0, function, zone()); |
5586 obj = factory()->NewVariableProxy(temp); | 5564 obj = factory()->NewVariableProxy(temp); |
5587 args->InsertAt(1, obj, zone()); | 5565 args->InsertAt(1, obj, zone()); |
5588 } | 5566 } |
5589 } else { | 5567 } else { |
5590 // Non-method calls | 5568 // Non-method calls |
5591 args->InsertAt(0, function, zone()); | 5569 args->InsertAt(0, function, zone()); |
5592 args->InsertAt(1, factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | 5570 args->InsertAt(1, factory()->NewUndefinedLiteral(kNoSourcePosition), |
5593 zone()); | 5571 zone()); |
5594 } | 5572 } |
5595 return factory()->NewCallRuntime(Context::REFLECT_APPLY_INDEX, args, pos); | 5573 return factory()->NewCallRuntime(Context::REFLECT_APPLY_INDEX, args, pos); |
5596 } | 5574 } |
5597 } | 5575 } |
5598 | 5576 |
5599 | 5577 |
5600 Expression* Parser::SpreadCallNew(Expression* function, | 5578 Expression* Parser::SpreadCallNew(Expression* function, |
5601 ZoneList<v8::internal::Expression*>* args, | 5579 ZoneList<v8::internal::Expression*>* args, |
5602 int pos) { | 5580 int pos) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5671 Expression* ParserTraits::RewriteAwaitExpression(Expression* value, | 5649 Expression* ParserTraits::RewriteAwaitExpression(Expression* value, |
5672 int await_pos) { | 5650 int await_pos) { |
5673 // yield %AsyncFunctionAwait(.generator_object, <operand>) | 5651 // yield %AsyncFunctionAwait(.generator_object, <operand>) |
5674 Variable* generator_object_variable = | 5652 Variable* generator_object_variable = |
5675 parser_->function_state_->generator_object_variable(); | 5653 parser_->function_state_->generator_object_variable(); |
5676 | 5654 |
5677 // If generator_object_variable is null, | 5655 // If generator_object_variable is null, |
5678 if (!generator_object_variable) return value; | 5656 if (!generator_object_variable) return value; |
5679 | 5657 |
5680 auto factory = parser_->factory(); | 5658 auto factory = parser_->factory(); |
5681 const int nopos = RelocInfo::kNoPosition; | 5659 const int nopos = kNoSourcePosition; |
5682 | 5660 |
5683 Variable* temp_var = parser_->scope_->NewTemporary( | 5661 Variable* temp_var = parser_->scope_->NewTemporary( |
5684 parser_->ast_value_factory()->empty_string()); | 5662 parser_->ast_value_factory()->empty_string()); |
5685 VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var); | 5663 VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var); |
5686 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); | 5664 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); |
5687 | 5665 |
5688 // Wrap value evaluation to provide a break location. | 5666 // Wrap value evaluation to provide a break location. |
5689 Expression* value_assignment = | 5667 Expression* value_assignment = |
5690 factory->NewAssignment(Token::ASSIGN, temp_proxy, value, nopos); | 5668 factory->NewAssignment(Token::ASSIGN, temp_proxy, value, nopos); |
5691 do_block->statements()->Add( | 5669 do_block->statements()->Add( |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5822 args->Add(right, zone()); | 5800 args->Add(right, zone()); |
5823 Expression* call = | 5801 Expression* call = |
5824 factory()->NewCallRuntime(Context::MATH_POW_METHOD_INDEX, args, pos); | 5802 factory()->NewCallRuntime(Context::MATH_POW_METHOD_INDEX, args, pos); |
5825 return factory()->NewAssignment(Token::ASSIGN, result, call, pos); | 5803 return factory()->NewAssignment(Token::ASSIGN, result, call, pos); |
5826 } else if (left->IsProperty()) { | 5804 } else if (left->IsProperty()) { |
5827 Property* prop = left->AsProperty(); | 5805 Property* prop = left->AsProperty(); |
5828 auto temp_obj = scope_->NewTemporary(ast_value_factory()->empty_string()); | 5806 auto temp_obj = scope_->NewTemporary(ast_value_factory()->empty_string()); |
5829 auto temp_key = scope_->NewTemporary(ast_value_factory()->empty_string()); | 5807 auto temp_key = scope_->NewTemporary(ast_value_factory()->empty_string()); |
5830 Expression* assign_obj = factory()->NewAssignment( | 5808 Expression* assign_obj = factory()->NewAssignment( |
5831 Token::ASSIGN, factory()->NewVariableProxy(temp_obj), prop->obj(), | 5809 Token::ASSIGN, factory()->NewVariableProxy(temp_obj), prop->obj(), |
5832 RelocInfo::kNoPosition); | 5810 kNoSourcePosition); |
5833 Expression* assign_key = factory()->NewAssignment( | 5811 Expression* assign_key = factory()->NewAssignment( |
5834 Token::ASSIGN, factory()->NewVariableProxy(temp_key), prop->key(), | 5812 Token::ASSIGN, factory()->NewVariableProxy(temp_key), prop->key(), |
5835 RelocInfo::kNoPosition); | 5813 kNoSourcePosition); |
5836 args->Add(factory()->NewProperty(factory()->NewVariableProxy(temp_obj), | 5814 args->Add(factory()->NewProperty(factory()->NewVariableProxy(temp_obj), |
5837 factory()->NewVariableProxy(temp_key), | 5815 factory()->NewVariableProxy(temp_key), |
5838 left->position()), | 5816 left->position()), |
5839 zone()); | 5817 zone()); |
5840 args->Add(right, zone()); | 5818 args->Add(right, zone()); |
5841 Expression* call = | 5819 Expression* call = |
5842 factory()->NewCallRuntime(Context::MATH_POW_METHOD_INDEX, args, pos); | 5820 factory()->NewCallRuntime(Context::MATH_POW_METHOD_INDEX, args, pos); |
5843 Expression* target = factory()->NewProperty( | 5821 Expression* target = factory()->NewProperty( |
5844 factory()->NewVariableProxy(temp_obj), | 5822 factory()->NewVariableProxy(temp_obj), |
5845 factory()->NewVariableProxy(temp_key), RelocInfo::kNoPosition); | 5823 factory()->NewVariableProxy(temp_key), kNoSourcePosition); |
5846 Expression* assign = | 5824 Expression* assign = |
5847 factory()->NewAssignment(Token::ASSIGN, target, call, pos); | 5825 factory()->NewAssignment(Token::ASSIGN, target, call, pos); |
5848 return factory()->NewBinaryOperation( | 5826 return factory()->NewBinaryOperation( |
5849 Token::COMMA, assign_obj, | 5827 Token::COMMA, assign_obj, |
5850 factory()->NewBinaryOperation(Token::COMMA, assign_key, assign, pos), | 5828 factory()->NewBinaryOperation(Token::COMMA, assign_key, assign, pos), |
5851 pos); | 5829 pos); |
5852 } | 5830 } |
5853 UNREACHABLE(); | 5831 UNREACHABLE(); |
5854 return nullptr; | 5832 return nullptr; |
5855 } | 5833 } |
(...skipping 11 matching lines...) Expand all Loading... |
5867 // $R | 5845 // $R |
5868 // } | 5846 // } |
5869 // where $R, $i and $j are fresh temporary variables. | 5847 // where $R, $i and $j are fresh temporary variables. |
5870 ZoneList<Expression*>::iterator s = lit->FirstSpread(); | 5848 ZoneList<Expression*>::iterator s = lit->FirstSpread(); |
5871 if (s == lit->EndValue()) return nullptr; // no spread, no rewriting... | 5849 if (s == lit->EndValue()) return nullptr; // no spread, no rewriting... |
5872 Variable* result = | 5850 Variable* result = |
5873 scope_->NewTemporary(ast_value_factory()->dot_result_string()); | 5851 scope_->NewTemporary(ast_value_factory()->dot_result_string()); |
5874 // NOTE: The value assigned to R is the whole original array literal, | 5852 // NOTE: The value assigned to R is the whole original array literal, |
5875 // spreads included. This will be fixed before the rewritten AST is returned. | 5853 // spreads included. This will be fixed before the rewritten AST is returned. |
5876 // $R = lit | 5854 // $R = lit |
5877 Expression* init_result = | 5855 Expression* init_result = factory()->NewAssignment( |
5878 factory()->NewAssignment(Token::INIT, factory()->NewVariableProxy(result), | 5856 Token::INIT, factory()->NewVariableProxy(result), lit, kNoSourcePosition); |
5879 lit, RelocInfo::kNoPosition); | 5857 Block* do_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition); |
5880 Block* do_block = | |
5881 factory()->NewBlock(nullptr, 16, false, RelocInfo::kNoPosition); | |
5882 do_block->statements()->Add( | 5858 do_block->statements()->Add( |
5883 factory()->NewExpressionStatement(init_result, RelocInfo::kNoPosition), | 5859 factory()->NewExpressionStatement(init_result, kNoSourcePosition), |
5884 zone()); | 5860 zone()); |
5885 // Traverse the array literal starting from the first spread. | 5861 // Traverse the array literal starting from the first spread. |
5886 while (s != lit->EndValue()) { | 5862 while (s != lit->EndValue()) { |
5887 Expression* value = *s++; | 5863 Expression* value = *s++; |
5888 Spread* spread = value->AsSpread(); | 5864 Spread* spread = value->AsSpread(); |
5889 if (spread == nullptr) { | 5865 if (spread == nullptr) { |
5890 // If the element is not a spread, we're adding a single: | 5866 // If the element is not a spread, we're adding a single: |
5891 // %AppendElement($R, value) | 5867 // %AppendElement($R, value) |
5892 ZoneList<Expression*>* append_element_args = NewExpressionList(2, zone()); | 5868 ZoneList<Expression*>* append_element_args = NewExpressionList(2, zone()); |
5893 append_element_args->Add(factory()->NewVariableProxy(result), zone()); | 5869 append_element_args->Add(factory()->NewVariableProxy(result), zone()); |
5894 append_element_args->Add(value, zone()); | 5870 append_element_args->Add(value, zone()); |
5895 do_block->statements()->Add( | 5871 do_block->statements()->Add( |
5896 factory()->NewExpressionStatement( | 5872 factory()->NewExpressionStatement( |
5897 factory()->NewCallRuntime(Runtime::kAppendElement, | 5873 factory()->NewCallRuntime(Runtime::kAppendElement, |
5898 append_element_args, | 5874 append_element_args, kNoSourcePosition), |
5899 RelocInfo::kNoPosition), | 5875 kNoSourcePosition), |
5900 RelocInfo::kNoPosition), | |
5901 zone()); | 5876 zone()); |
5902 } else { | 5877 } else { |
5903 // If it's a spread, we're adding a for/of loop iterating through it. | 5878 // If it's a spread, we're adding a for/of loop iterating through it. |
5904 Variable* each = | 5879 Variable* each = |
5905 scope_->NewTemporary(ast_value_factory()->dot_for_string()); | 5880 scope_->NewTemporary(ast_value_factory()->dot_for_string()); |
5906 Expression* subject = spread->expression(); | 5881 Expression* subject = spread->expression(); |
5907 // %AppendElement($R, each) | 5882 // %AppendElement($R, each) |
5908 Statement* append_body; | 5883 Statement* append_body; |
5909 { | 5884 { |
5910 ZoneList<Expression*>* append_element_args = | 5885 ZoneList<Expression*>* append_element_args = |
5911 NewExpressionList(2, zone()); | 5886 NewExpressionList(2, zone()); |
5912 append_element_args->Add(factory()->NewVariableProxy(result), zone()); | 5887 append_element_args->Add(factory()->NewVariableProxy(result), zone()); |
5913 append_element_args->Add(factory()->NewVariableProxy(each), zone()); | 5888 append_element_args->Add(factory()->NewVariableProxy(each), zone()); |
5914 append_body = factory()->NewExpressionStatement( | 5889 append_body = factory()->NewExpressionStatement( |
5915 factory()->NewCallRuntime(Runtime::kAppendElement, | 5890 factory()->NewCallRuntime(Runtime::kAppendElement, |
5916 append_element_args, | 5891 append_element_args, kNoSourcePosition), |
5917 RelocInfo::kNoPosition), | 5892 kNoSourcePosition); |
5918 RelocInfo::kNoPosition); | |
5919 } | 5893 } |
5920 // for (each of spread) %AppendElement($R, each) | 5894 // for (each of spread) %AppendElement($R, each) |
5921 ForEachStatement* loop = factory()->NewForEachStatement( | 5895 ForEachStatement* loop = factory()->NewForEachStatement( |
5922 ForEachStatement::ITERATE, nullptr, RelocInfo::kNoPosition); | 5896 ForEachStatement::ITERATE, nullptr, kNoSourcePosition); |
5923 InitializeForOfStatement(loop->AsForOfStatement(), | 5897 InitializeForOfStatement(loop->AsForOfStatement(), |
5924 factory()->NewVariableProxy(each), subject, | 5898 factory()->NewVariableProxy(each), subject, |
5925 append_body); | 5899 append_body); |
5926 do_block->statements()->Add(loop, zone()); | 5900 do_block->statements()->Add(loop, zone()); |
5927 } | 5901 } |
5928 } | 5902 } |
5929 // Now, rewind the original array literal to truncate everything from the | 5903 // Now, rewind the original array literal to truncate everything from the |
5930 // first spread (included) until the end. This fixes $R's initialization. | 5904 // first spread (included) until the end. This fixes $R's initialization. |
5931 lit->RewindSpreads(); | 5905 lit->RewindSpreads(); |
5932 return factory()->NewDoExpression(do_block, result, lit->position()); | 5906 return factory()->NewDoExpression(do_block, result, lit->position()); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6081 // | 6055 // |
6082 // IteratorClose(iterator, input, output) expands to the following: | 6056 // IteratorClose(iterator, input, output) expands to the following: |
6083 // | 6057 // |
6084 // let iteratorReturn = iterator.return; | 6058 // let iteratorReturn = iterator.return; |
6085 // if (IS_NULL_OR_UNDEFINED(iteratorReturn)) return input; | 6059 // if (IS_NULL_OR_UNDEFINED(iteratorReturn)) return input; |
6086 // output = %_Call(iteratorReturn, iterator, input); | 6060 // output = %_Call(iteratorReturn, iterator, input); |
6087 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); | 6061 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); |
6088 | 6062 |
6089 Expression* ParserTraits::RewriteYieldStar( | 6063 Expression* ParserTraits::RewriteYieldStar( |
6090 Expression* generator, Expression* iterable, int pos) { | 6064 Expression* generator, Expression* iterable, int pos) { |
6091 | 6065 const int nopos = kNoSourcePosition; |
6092 const int nopos = RelocInfo::kNoPosition; | |
6093 | 6066 |
6094 auto factory = parser_->factory(); | 6067 auto factory = parser_->factory(); |
6095 auto avfactory = parser_->ast_value_factory(); | 6068 auto avfactory = parser_->ast_value_factory(); |
6096 auto scope = parser_->scope_; | 6069 auto scope = parser_->scope_; |
6097 auto zone = parser_->zone(); | 6070 auto zone = parser_->zone(); |
6098 | 6071 |
6099 | 6072 |
6100 // Forward definition for break/continue statements. | 6073 // Forward definition for break/continue statements. |
6101 WhileStatement* loop = factory->NewWhileStatement(nullptr, nopos); | 6074 WhileStatement* loop = factory->NewWhileStatement(nullptr, nopos); |
6102 | 6075 |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6508 Rewriter::Rewrite(parser_, yield_star, avfactory); | 6481 Rewriter::Rewrite(parser_, yield_star, avfactory); |
6509 } | 6482 } |
6510 | 6483 |
6511 return yield_star; | 6484 return yield_star; |
6512 } | 6485 } |
6513 | 6486 |
6514 Statement* ParserTraits::CheckCallable(Variable* var, Expression* error, | 6487 Statement* ParserTraits::CheckCallable(Variable* var, Expression* error, |
6515 int pos) { | 6488 int pos) { |
6516 auto factory = parser_->factory(); | 6489 auto factory = parser_->factory(); |
6517 auto avfactory = parser_->ast_value_factory(); | 6490 auto avfactory = parser_->ast_value_factory(); |
6518 const int nopos = RelocInfo::kNoPosition; | 6491 const int nopos = kNoSourcePosition; |
6519 Statement* validate_var; | 6492 Statement* validate_var; |
6520 { | 6493 { |
6521 Expression* type_of = factory->NewUnaryOperation( | 6494 Expression* type_of = factory->NewUnaryOperation( |
6522 Token::TYPEOF, factory->NewVariableProxy(var), nopos); | 6495 Token::TYPEOF, factory->NewVariableProxy(var), nopos); |
6523 Expression* function_literal = | 6496 Expression* function_literal = |
6524 factory->NewStringLiteral(avfactory->function_string(), nopos); | 6497 factory->NewStringLiteral(avfactory->function_string(), nopos); |
6525 Expression* condition = factory->NewCompareOperation( | 6498 Expression* condition = factory->NewCompareOperation( |
6526 Token::EQ_STRICT, type_of, function_literal, nopos); | 6499 Token::EQ_STRICT, type_of, function_literal, nopos); |
6527 | 6500 |
6528 Statement* throw_call = factory->NewExpressionStatement(error, pos); | 6501 Statement* throw_call = factory->NewExpressionStatement(error, pos); |
(...skipping 12 matching lines...) Expand all Loading... |
6541 // following code: | 6514 // following code: |
6542 // | 6515 // |
6543 // let iteratorReturn = iterator.return; | 6516 // let iteratorReturn = iterator.return; |
6544 // if (IS_NULL_OR_UNDEFINED(iteratorReturn) { | 6517 // if (IS_NULL_OR_UNDEFINED(iteratorReturn) { |
6545 // return {value: input, done: true}; | 6518 // return {value: input, done: true}; |
6546 // } | 6519 // } |
6547 // output = %_Call(iteratorReturn, iterator, input); | 6520 // output = %_Call(iteratorReturn, iterator, input); |
6548 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); | 6521 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); |
6549 // | 6522 // |
6550 | 6523 |
6551 const int nopos = RelocInfo::kNoPosition; | 6524 const int nopos = kNoSourcePosition; |
6552 auto factory = parser_->factory(); | 6525 auto factory = parser_->factory(); |
6553 auto avfactory = parser_->ast_value_factory(); | 6526 auto avfactory = parser_->ast_value_factory(); |
6554 auto zone = parser_->zone(); | 6527 auto zone = parser_->zone(); |
6555 | 6528 |
6556 // let iteratorReturn = iterator.return; | 6529 // let iteratorReturn = iterator.return; |
6557 Variable* var_return = var_output; // Reusing the output variable. | 6530 Variable* var_return = var_output; // Reusing the output variable. |
6558 Statement* get_return; | 6531 Statement* get_return; |
6559 { | 6532 { |
6560 Expression* iterator_proxy = factory->NewVariableProxy(iterator); | 6533 Expression* iterator_proxy = factory->NewVariableProxy(iterator); |
6561 Expression* literal = | 6534 Expression* literal = |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6647 // if (completion === kAbruptCompletion) completion = kThrowCompletion; | 6620 // if (completion === kAbruptCompletion) completion = kThrowCompletion; |
6648 // %ReThrow(e); | 6621 // %ReThrow(e); |
6649 // } | 6622 // } |
6650 // } finally { | 6623 // } finally { |
6651 // if (condition) { | 6624 // if (condition) { |
6652 // #BuildIteratorCloseForCompletion(iter, completion) | 6625 // #BuildIteratorCloseForCompletion(iter, completion) |
6653 // } | 6626 // } |
6654 // } | 6627 // } |
6655 // | 6628 // |
6656 | 6629 |
6657 const int nopos = RelocInfo::kNoPosition; | 6630 const int nopos = kNoSourcePosition; |
6658 auto factory = parser_->factory(); | 6631 auto factory = parser_->factory(); |
6659 auto avfactory = parser_->ast_value_factory(); | 6632 auto avfactory = parser_->ast_value_factory(); |
6660 auto scope = parser_->scope_; | 6633 auto scope = parser_->scope_; |
6661 auto zone = parser_->zone(); | 6634 auto zone = parser_->zone(); |
6662 | 6635 |
6663 // completion = kNormalCompletion; | 6636 // completion = kNormalCompletion; |
6664 Statement* initialize_completion; | 6637 Statement* initialize_completion; |
6665 { | 6638 { |
6666 Expression* proxy = factory->NewVariableProxy(completion); | 6639 Expression* proxy = factory->NewVariableProxy(completion); |
6667 Expression* assignment = factory->NewAssignment( | 6640 Expression* assignment = factory->NewAssignment( |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6766 // try { %_Call(iteratorReturn, iterator) } catch (_) { } | 6739 // try { %_Call(iteratorReturn, iterator) } catch (_) { } |
6767 // } else { | 6740 // } else { |
6768 // let output = %_Call(iteratorReturn, iterator); | 6741 // let output = %_Call(iteratorReturn, iterator); |
6769 // if (!IS_RECEIVER(output)) { | 6742 // if (!IS_RECEIVER(output)) { |
6770 // %ThrowIterResultNotAnObject(output); | 6743 // %ThrowIterResultNotAnObject(output); |
6771 // } | 6744 // } |
6772 // } | 6745 // } |
6773 // } | 6746 // } |
6774 // | 6747 // |
6775 | 6748 |
6776 const int nopos = RelocInfo::kNoPosition; | 6749 const int nopos = kNoSourcePosition; |
6777 auto factory = parser_->factory(); | 6750 auto factory = parser_->factory(); |
6778 auto avfactory = parser_->ast_value_factory(); | 6751 auto avfactory = parser_->ast_value_factory(); |
6779 auto scope = parser_->scope_; | 6752 auto scope = parser_->scope_; |
6780 auto zone = parser_->zone(); | 6753 auto zone = parser_->zone(); |
6781 | 6754 |
6782 | 6755 |
6783 // let iteratorReturn = iterator.return; | 6756 // let iteratorReturn = iterator.return; |
6784 Variable* var_return = scope->NewTemporary(avfactory->empty_string()); | 6757 Variable* var_return = scope->NewTemporary(avfactory->empty_string()); |
6785 Statement* get_return; | 6758 Statement* get_return; |
6786 { | 6759 { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6943 // } | 6916 // } |
6944 // | 6917 // |
6945 // and the loop's assign_each is wrapped as follows | 6918 // and the loop's assign_each is wrapped as follows |
6946 // | 6919 // |
6947 // do { | 6920 // do { |
6948 // {{completion = kAbruptCompletion;}} | 6921 // {{completion = kAbruptCompletion;}} |
6949 // #assign-each | 6922 // #assign-each |
6950 // } | 6923 // } |
6951 // | 6924 // |
6952 | 6925 |
6953 const int nopos = RelocInfo::kNoPosition; | 6926 const int nopos = kNoSourcePosition; |
6954 auto factory = parser_->factory(); | 6927 auto factory = parser_->factory(); |
6955 auto avfactory = parser_->ast_value_factory(); | 6928 auto avfactory = parser_->ast_value_factory(); |
6956 auto scope = parser_->scope_; | 6929 auto scope = parser_->scope_; |
6957 auto zone = parser_->zone(); | 6930 auto zone = parser_->zone(); |
6958 | 6931 |
6959 Variable* var_completion = scope->NewTemporary(avfactory->empty_string()); | 6932 Variable* var_completion = scope->NewTemporary(avfactory->empty_string()); |
6960 | 6933 |
6961 // let each; | 6934 // let each; |
6962 Variable* var_each = scope->NewTemporary(avfactory->empty_string()); | 6935 Variable* var_each = scope->NewTemporary(avfactory->empty_string()); |
6963 Statement* initialize_each; | 6936 Statement* initialize_each; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7045 try_block, target); | 7018 try_block, target); |
7046 final_loop = target; | 7019 final_loop = target; |
7047 } | 7020 } |
7048 | 7021 |
7049 return final_loop; | 7022 return final_loop; |
7050 } | 7023 } |
7051 | 7024 |
7052 | 7025 |
7053 } // namespace internal | 7026 } // namespace internal |
7054 } // namespace v8 | 7027 } // namespace v8 |
OLD | NEW |