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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 auto constructor_args_name = ast_value_factory()->empty_string(); | 268 auto constructor_args_name = ast_value_factory()->empty_string(); |
269 bool is_duplicate; | 269 bool is_duplicate; |
270 bool is_rest = true; | 270 bool is_rest = true; |
271 bool is_optional = false; | 271 bool is_optional = false; |
272 Variable* constructor_args = function_scope->DeclareParameter( | 272 Variable* constructor_args = function_scope->DeclareParameter( |
273 constructor_args_name, TEMPORARY, is_optional, is_rest, &is_duplicate, | 273 constructor_args_name, TEMPORARY, is_optional, is_rest, &is_duplicate, |
274 ast_value_factory()); | 274 ast_value_factory()); |
275 | 275 |
276 ZoneList<Expression*>* args = | 276 ZoneList<Expression*>* args = |
277 new (zone()) ZoneList<Expression*>(2, zone()); | 277 new (zone()) ZoneList<Expression*>(2, zone()); |
278 VariableProxy* this_function_proxy = this->scope()->NewUnresolved( | 278 VariableProxy* this_function_proxy = |
279 factory(), ast_value_factory()->this_function_string(), | 279 NewUnresolved(ast_value_factory()->this_function_string(), pos); |
280 Variable::NORMAL, pos); | |
281 ZoneList<Expression*>* tmp = | 280 ZoneList<Expression*>* tmp = |
282 new (zone()) ZoneList<Expression*>(1, zone()); | 281 new (zone()) ZoneList<Expression*>(1, zone()); |
283 tmp->Add(this_function_proxy, zone()); | 282 tmp->Add(this_function_proxy, zone()); |
284 Expression* super_constructor = factory()->NewCallRuntime( | 283 Expression* super_constructor = factory()->NewCallRuntime( |
285 Runtime::kInlineGetSuperConstructor, tmp, pos); | 284 Runtime::kInlineGetSuperConstructor, tmp, pos); |
286 args->Add(super_constructor, zone()); | 285 args->Add(super_constructor, zone()); |
287 Spread* spread_args = factory()->NewSpread( | 286 Spread* spread_args = factory()->NewSpread( |
288 factory()->NewVariableProxy(constructor_args), pos, pos); | 287 factory()->NewVariableProxy(constructor_args), pos, pos); |
289 ZoneList<Expression*>* spread_args_expr = | 288 ZoneList<Expression*>* spread_args_expr = |
290 new (zone()) ZoneList<Expression*>(1, zone()); | 289 new (zone()) ZoneList<Expression*>(1, zone()); |
291 spread_args_expr->Add(spread_args, zone()); | 290 spread_args_expr->Add(spread_args, zone()); |
292 args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone()); | 291 args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone()); |
293 VariableProxy* new_target_proxy = this->scope()->NewUnresolved( | 292 VariableProxy* new_target_proxy = |
294 factory(), ast_value_factory()->new_target_string(), Variable::NORMAL, | 293 NewUnresolved(ast_value_factory()->new_target_string(), pos); |
295 pos); | |
296 args->Add(new_target_proxy, zone()); | 294 args->Add(new_target_proxy, zone()); |
297 CallRuntime* call = factory()->NewCallRuntime( | 295 CallRuntime* call = factory()->NewCallRuntime( |
298 Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 296 Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
299 body->Add(factory()->NewReturnStatement(call, pos), zone()); | 297 body->Add(factory()->NewReturnStatement(call, pos), zone()); |
300 } | 298 } |
301 | 299 |
302 materialized_literal_count = function_state.materialized_literal_count(); | 300 materialized_literal_count = function_state.materialized_literal_count(); |
303 expected_property_count = function_state.expected_property_count(); | 301 expected_property_count = function_state.expected_property_count(); |
304 } | 302 } |
305 | 303 |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 char array[100]; | 681 char array[100]; |
684 const char* string = DoubleToCString(double_value, ArrayVector(array)); | 682 const char* string = DoubleToCString(double_value, ArrayVector(array)); |
685 return parser_->ast_value_factory()->GetOneByteString(string); | 683 return parser_->ast_value_factory()->GetOneByteString(string); |
686 } | 684 } |
687 | 685 |
688 | 686 |
689 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { | 687 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { |
690 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); | 688 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); |
691 } | 689 } |
692 | 690 |
693 Expression* ParserTraits::ThisExpression(AstNodeFactory* factory, int pos) { | 691 Expression* ParserTraits::ThisExpression(int pos) { |
694 return parser_->scope()->NewUnresolved( | 692 return parser_->NewUnresolved(parser_->ast_value_factory()->this_string(), |
695 factory, parser_->ast_value_factory()->this_string(), Variable::THIS, pos, | 693 pos, pos + 4, Variable::THIS); |
696 pos + 4); | |
697 } | 694 } |
698 | 695 |
699 Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory, | 696 Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory, |
700 int pos) { | 697 int pos) { |
701 // this_function[home_object_symbol] | 698 // this_function[home_object_symbol] |
702 VariableProxy* this_function_proxy = parser_->scope()->NewUnresolved( | 699 VariableProxy* this_function_proxy = parser_->NewUnresolved( |
703 factory, parser_->ast_value_factory()->this_function_string(), | 700 parser_->ast_value_factory()->this_function_string(), pos); |
704 Variable::NORMAL, pos); | |
705 Expression* home_object_symbol_literal = | 701 Expression* home_object_symbol_literal = |
706 factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); | 702 factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); |
707 Expression* home_object = factory->NewProperty( | 703 Expression* home_object = factory->NewProperty( |
708 this_function_proxy, home_object_symbol_literal, pos); | 704 this_function_proxy, home_object_symbol_literal, pos); |
709 return factory->NewSuperPropertyReference( | 705 return factory->NewSuperPropertyReference( |
710 ThisExpression(factory, pos)->AsVariableProxy(), home_object, pos); | 706 ThisExpression(pos)->AsVariableProxy(), home_object, pos); |
711 } | 707 } |
712 | 708 |
713 Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory, | 709 Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory, |
714 int pos) { | 710 int pos) { |
715 VariableProxy* new_target_proxy = parser_->scope()->NewUnresolved( | 711 VariableProxy* new_target_proxy = parser_->NewUnresolved( |
716 factory, parser_->ast_value_factory()->new_target_string(), | 712 parser_->ast_value_factory()->new_target_string(), pos); |
717 Variable::NORMAL, pos); | 713 VariableProxy* this_function_proxy = parser_->NewUnresolved( |
718 VariableProxy* this_function_proxy = parser_->scope()->NewUnresolved( | 714 parser_->ast_value_factory()->this_function_string(), pos); |
719 factory, parser_->ast_value_factory()->this_function_string(), | 715 return factory->NewSuperCallReference(ThisExpression(pos)->AsVariableProxy(), |
720 Variable::NORMAL, pos); | 716 new_target_proxy, this_function_proxy, |
721 return factory->NewSuperCallReference( | 717 pos); |
722 ThisExpression(factory, pos)->AsVariableProxy(), new_target_proxy, | |
723 this_function_proxy, pos); | |
724 } | 718 } |
725 | 719 |
726 Expression* ParserTraits::NewTargetExpression(AstNodeFactory* factory, | 720 Expression* ParserTraits::NewTargetExpression(int pos) { |
727 int pos) { | |
728 static const int kNewTargetStringLength = 10; | 721 static const int kNewTargetStringLength = 10; |
729 auto proxy = parser_->scope()->NewUnresolved( | 722 auto proxy = |
730 factory, parser_->ast_value_factory()->new_target_string(), | 723 parser_->NewUnresolved(parser_->ast_value_factory()->new_target_string(), |
731 Variable::NORMAL, pos, pos + kNewTargetStringLength); | 724 pos, pos + kNewTargetStringLength); |
732 proxy->set_is_new_target(); | 725 proxy->set_is_new_target(); |
733 return proxy; | 726 return proxy; |
734 } | 727 } |
735 | 728 |
736 Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory, | 729 Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory, |
737 int pos) { | 730 int pos) { |
738 // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator). | 731 // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator). |
739 Zone* zone = parser_->zone(); | 732 Zone* zone = parser_->zone(); |
740 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone); | 733 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone); |
741 VariableProxy* generator = factory->NewVariableProxy( | 734 VariableProxy* generator = factory->NewVariableProxy( |
(...skipping 22 matching lines...) Expand all Loading... |
764 bool has_dot = scanner->ContainsDot(); | 757 bool has_dot = scanner->ContainsDot(); |
765 double value = scanner->DoubleValue(); | 758 double value = scanner->DoubleValue(); |
766 return factory->NewNumberLiteral(value, pos, has_dot); | 759 return factory->NewNumberLiteral(value, pos, has_dot); |
767 } | 760 } |
768 default: | 761 default: |
769 DCHECK(false); | 762 DCHECK(false); |
770 } | 763 } |
771 return NULL; | 764 return NULL; |
772 } | 765 } |
773 | 766 |
774 | |
775 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, | 767 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, |
776 int start_position, | 768 int start_position, |
777 int end_position, | 769 int end_position) { |
778 AstNodeFactory* factory) { | |
779 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); | 770 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); |
780 return parser_->scope()->NewUnresolved(factory, name, Variable::NORMAL, | 771 return parser_->NewUnresolved(name, start_position, end_position); |
781 start_position, end_position); | |
782 } | 772 } |
783 | 773 |
784 | 774 |
785 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, | 775 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, |
786 AstNodeFactory* factory) { | 776 AstNodeFactory* factory) { |
787 const AstRawString* symbol = GetSymbol(scanner); | 777 const AstRawString* symbol = GetSymbol(scanner); |
788 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 778 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
789 return factory->NewStringLiteral(symbol, pos); | 779 return factory->NewStringLiteral(symbol, pos); |
790 } | 780 } |
791 | 781 |
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1942 | 1932 |
1943 case Token::TRY: | 1933 case Token::TRY: |
1944 return ParseTryStatement(ok); | 1934 return ParseTryStatement(ok); |
1945 | 1935 |
1946 default: | 1936 default: |
1947 UNREACHABLE(); | 1937 UNREACHABLE(); |
1948 return NULL; | 1938 return NULL; |
1949 } | 1939 } |
1950 } | 1940 } |
1951 | 1941 |
| 1942 VariableProxy* Parser::NewUnresolved(const AstRawString* name, int begin_pos, |
| 1943 int end_pos, Variable::Kind kind) { |
| 1944 return scope()->NewUnresolved(factory(), name, begin_pos, end_pos, kind); |
| 1945 } |
1952 | 1946 |
1953 VariableProxy* Parser::NewUnresolved(const AstRawString* name, | 1947 VariableProxy* Parser::NewUnresolved(const AstRawString* name) { |
1954 VariableMode mode) { | 1948 return scope()->NewUnresolved(factory(), name, scanner()->location().beg_pos, |
1955 // If we are inside a function, a declaration of a 'var' variable is a | 1949 scanner()->location().end_pos); |
1956 // truly local variable, and the scope of the variable is always the function | |
1957 // scope. | |
1958 // Let/const variables are always added to the immediately enclosing scope. | |
1959 Scope* scope = | |
1960 IsLexicalVariableMode(mode) ? this->scope() : GetDeclarationScope(); | |
1961 return scope->NewUnresolved(factory(), name, Variable::NORMAL, | |
1962 scanner()->location().beg_pos, | |
1963 scanner()->location().end_pos); | |
1964 } | 1950 } |
1965 | 1951 |
1966 InitializationFlag Parser::DefaultInitializationFlag(VariableMode mode) { | 1952 InitializationFlag Parser::DefaultInitializationFlag(VariableMode mode) { |
1967 DCHECK(IsDeclaredVariableMode(mode)); | 1953 DCHECK(IsDeclaredVariableMode(mode)); |
1968 return mode == VAR ? kCreatedInitialized : kNeedsInitialization; | 1954 return mode == VAR ? kCreatedInitialized : kNeedsInitialization; |
1969 } | 1955 } |
1970 | 1956 |
1971 Declaration* Parser::DeclareVariable(const AstRawString* name, | 1957 Declaration* Parser::DeclareVariable(const AstRawString* name, |
1972 VariableMode mode, int pos, bool* ok) { | 1958 VariableMode mode, int pos, bool* ok) { |
1973 return DeclareVariable(name, mode, DefaultInitializationFlag(mode), pos, ok); | 1959 return DeclareVariable(name, mode, DefaultInitializationFlag(mode), pos, ok); |
1974 } | 1960 } |
1975 | 1961 |
1976 Declaration* Parser::DeclareVariable(const AstRawString* name, | 1962 Declaration* Parser::DeclareVariable(const AstRawString* name, |
1977 VariableMode mode, InitializationFlag init, | 1963 VariableMode mode, InitializationFlag init, |
1978 int pos, bool* ok) { | 1964 int pos, bool* ok) { |
1979 DCHECK_NOT_NULL(name); | 1965 DCHECK_NOT_NULL(name); |
1980 VariableProxy* proxy = NewUnresolved(name, mode); | 1966 Scope* scope = |
| 1967 IsLexicalVariableMode(mode) ? this->scope() : GetDeclarationScope(); |
| 1968 VariableProxy* proxy = |
| 1969 scope->NewUnresolved(factory(), name, scanner()->location().beg_pos, |
| 1970 scanner()->location().end_pos); |
1981 Declaration* declaration = | 1971 Declaration* declaration = |
1982 factory()->NewVariableDeclaration(proxy, scope(), pos); | 1972 factory()->NewVariableDeclaration(proxy, this->scope(), pos); |
1983 Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, CHECK_OK); | 1973 Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, CHECK_OK); |
1984 return declaration; | 1974 return declaration; |
1985 } | 1975 } |
1986 | 1976 |
1987 Variable* Parser::Declare(Declaration* declaration, | 1977 Variable* Parser::Declare(Declaration* declaration, |
1988 DeclarationDescriptor::Kind declaration_kind, | 1978 DeclarationDescriptor::Kind declaration_kind, |
1989 VariableMode mode, InitializationFlag init, bool* ok, | 1979 VariableMode mode, InitializationFlag init, bool* ok, |
1990 Scope* scope) { | 1980 Scope* scope) { |
1991 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY); | 1981 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY); |
1992 | 1982 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2205 is_generator ? FunctionKind::kGeneratorFunction | 2195 is_generator ? FunctionKind::kGeneratorFunction |
2206 : is_async ? FunctionKind::kAsyncFunction | 2196 : is_async ? FunctionKind::kAsyncFunction |
2207 : FunctionKind::kNormalFunction, | 2197 : FunctionKind::kNormalFunction, |
2208 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); | 2198 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); |
2209 | 2199 |
2210 // In ES6, a function behaves as a lexical binding, except in | 2200 // In ES6, a function behaves as a lexical binding, except in |
2211 // a script scope, or the initial scope of eval or another function. | 2201 // a script scope, or the initial scope of eval or another function. |
2212 VariableMode mode = | 2202 VariableMode mode = |
2213 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET | 2203 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET |
2214 : VAR; | 2204 : VAR; |
2215 VariableProxy* proxy = NewUnresolved(variable_name, mode); | 2205 VariableProxy* proxy = NewUnresolved(variable_name); |
2216 Declaration* declaration = | 2206 Declaration* declaration = |
2217 factory()->NewFunctionDeclaration(proxy, fun, scope(), pos); | 2207 factory()->NewFunctionDeclaration(proxy, fun, scope(), pos); |
2218 Declare(declaration, DeclarationDescriptor::NORMAL, mode, kCreatedInitialized, | 2208 Declare(declaration, DeclarationDescriptor::NORMAL, mode, kCreatedInitialized, |
2219 CHECK_OK); | 2209 CHECK_OK); |
2220 if (names) names->Add(variable_name, zone()); | 2210 if (names) names->Add(variable_name, zone()); |
2221 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition); | 2211 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition); |
2222 // Async functions don't undergo sloppy mode block scoped hoisting, and don't | 2212 // Async functions don't undergo sloppy mode block scoped hoisting, and don't |
2223 // allow duplicates in a block. Both are represented by the | 2213 // allow duplicates in a block. Both are represented by the |
2224 // sloppy_block_function_map. Don't add them to the map for async functions. | 2214 // sloppy_block_function_map. Don't add them to the map for async functions. |
2225 // Generators are also supposed to be prohibited; currently doing this behind | 2215 // Generators are also supposed to be prohibited; currently doing this behind |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2713 Scanner::Location loc = scanner()->location(); | 2703 Scanner::Location loc = scanner()->location(); |
2714 | 2704 |
2715 Token::Value tok = peek(); | 2705 Token::Value tok = peek(); |
2716 Statement* result; | 2706 Statement* result; |
2717 Expression* return_value; | 2707 Expression* return_value; |
2718 if (scanner()->HasAnyLineTerminatorBeforeNext() || | 2708 if (scanner()->HasAnyLineTerminatorBeforeNext() || |
2719 tok == Token::SEMICOLON || | 2709 tok == Token::SEMICOLON || |
2720 tok == Token::RBRACE || | 2710 tok == Token::RBRACE || |
2721 tok == Token::EOS) { | 2711 tok == Token::EOS) { |
2722 if (IsSubclassConstructor(function_state_->kind())) { | 2712 if (IsSubclassConstructor(function_state_->kind())) { |
2723 return_value = ThisExpression(factory(), loc.beg_pos); | 2713 return_value = ThisExpression(loc.beg_pos); |
2724 } else { | 2714 } else { |
2725 return_value = GetLiteralUndefined(position()); | 2715 return_value = GetLiteralUndefined(position()); |
2726 } | 2716 } |
2727 } else { | 2717 } else { |
2728 int pos = peek_position(); | 2718 int pos = peek_position(); |
2729 | 2719 |
2730 if (IsSubclassConstructor(function_state_->kind())) { | 2720 if (IsSubclassConstructor(function_state_->kind())) { |
2731 // Because of the return code rewriting that happens in case of a subclass | 2721 // Because of the return code rewriting that happens in case of a subclass |
2732 // constructor we don't want to accept tail calls, therefore we don't set | 2722 // constructor we don't want to accept tail calls, therefore we don't set |
2733 // ReturnExprScope to kInsideValidReturnStatement here. | 2723 // ReturnExprScope to kInsideValidReturnStatement here. |
(...skipping 26 matching lines...) Expand all Loading... |
2760 Expression* is_object_conditional = factory()->NewConditional( | 2750 Expression* is_object_conditional = factory()->NewConditional( |
2761 is_spec_object_call, factory()->NewVariableProxy(temp), | 2751 is_spec_object_call, factory()->NewVariableProxy(temp), |
2762 factory()->NewSmiLiteral(1, pos), pos); | 2752 factory()->NewSmiLiteral(1, pos), pos); |
2763 | 2753 |
2764 // temp === undefined | 2754 // temp === undefined |
2765 Expression* is_undefined = factory()->NewCompareOperation( | 2755 Expression* is_undefined = factory()->NewCompareOperation( |
2766 Token::EQ_STRICT, assign, | 2756 Token::EQ_STRICT, assign, |
2767 factory()->NewUndefinedLiteral(kNoSourcePosition), pos); | 2757 factory()->NewUndefinedLiteral(kNoSourcePosition), pos); |
2768 | 2758 |
2769 // is_undefined ? this : is_object_conditional | 2759 // is_undefined ? this : is_object_conditional |
2770 return_value = factory()->NewConditional(is_undefined, | 2760 return_value = factory()->NewConditional( |
2771 ThisExpression(factory(), pos), | 2761 is_undefined, ThisExpression(pos), is_object_conditional, pos); |
2772 is_object_conditional, pos); | |
2773 } else { | 2762 } else { |
2774 ReturnExprScope maybe_allow_tail_calls( | 2763 ReturnExprScope maybe_allow_tail_calls( |
2775 function_state_, ReturnExprContext::kInsideValidReturnStatement); | 2764 function_state_, ReturnExprContext::kInsideValidReturnStatement); |
2776 return_value = ParseExpression(true, CHECK_OK); | 2765 return_value = ParseExpression(true, CHECK_OK); |
2777 | 2766 |
2778 if (allow_tailcalls() && !is_sloppy(language_mode())) { | 2767 if (allow_tailcalls() && !is_sloppy(language_mode())) { |
2779 // ES6 14.6.1 Static Semantics: IsInTailPosition | 2768 // ES6 14.6.1 Static Semantics: IsInTailPosition |
2780 function_state_->AddImplicitTailCallExpression(return_value); | 2769 function_state_->AddImplicitTailCallExpression(return_value); |
2781 } | 2770 } |
2782 } | 2771 } |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3441 factory()->NewBlock(NULL, names->length() + 4, false, kNoSourcePosition); | 3430 factory()->NewBlock(NULL, names->length() + 4, false, kNoSourcePosition); |
3442 | 3431 |
3443 // Add statement: let/const x = i. | 3432 // Add statement: let/const x = i. |
3444 outer_block->statements()->Add(init, zone()); | 3433 outer_block->statements()->Add(init, zone()); |
3445 | 3434 |
3446 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); | 3435 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); |
3447 | 3436 |
3448 // For each lexical variable x: | 3437 // For each lexical variable x: |
3449 // make statement: temp_x = x. | 3438 // make statement: temp_x = x. |
3450 for (int i = 0; i < names->length(); i++) { | 3439 for (int i = 0; i < names->length(); i++) { |
3451 VariableProxy* proxy = NewUnresolved(names->at(i), LET); | 3440 VariableProxy* proxy = NewUnresolved(names->at(i)); |
3452 Variable* temp = NewTemporary(temp_name); | 3441 Variable* temp = NewTemporary(temp_name); |
3453 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); | 3442 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); |
3454 Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy, | 3443 Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy, |
3455 proxy, kNoSourcePosition); | 3444 proxy, kNoSourcePosition); |
3456 Statement* assignment_statement = | 3445 Statement* assignment_statement = |
3457 factory()->NewExpressionStatement(assignment, kNoSourcePosition); | 3446 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
3458 outer_block->statements()->Add(assignment_statement, zone()); | 3447 outer_block->statements()->Add(assignment_statement, zone()); |
3459 temps.Add(temp, zone()); | 3448 temps.Add(temp, zone()); |
3460 } | 3449 } |
3461 | 3450 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3712 bound_names_are_lexical = | 3701 bound_names_are_lexical = |
3713 IsLexicalVariableMode(parsing_result.descriptor.mode); | 3702 IsLexicalVariableMode(parsing_result.descriptor.mode); |
3714 | 3703 |
3715 // special case for legacy for (var ... = ... in ...) | 3704 // special case for legacy for (var ... = ... in ...) |
3716 if (!bound_names_are_lexical && decl.pattern->IsVariableProxy() && | 3705 if (!bound_names_are_lexical && decl.pattern->IsVariableProxy() && |
3717 decl.initializer != nullptr) { | 3706 decl.initializer != nullptr) { |
3718 DCHECK(!allow_harmony_for_in()); | 3707 DCHECK(!allow_harmony_for_in()); |
3719 ++use_counts_[v8::Isolate::kForInInitializer]; | 3708 ++use_counts_[v8::Isolate::kForInInitializer]; |
3720 const AstRawString* name = | 3709 const AstRawString* name = |
3721 decl.pattern->AsVariableProxy()->raw_name(); | 3710 decl.pattern->AsVariableProxy()->raw_name(); |
3722 VariableProxy* single_var = NewUnresolved(name, VAR); | 3711 VariableProxy* single_var = NewUnresolved(name); |
3723 init_block = factory()->NewBlock( | 3712 init_block = factory()->NewBlock( |
3724 nullptr, 2, true, parsing_result.descriptor.declaration_pos); | 3713 nullptr, 2, true, parsing_result.descriptor.declaration_pos); |
3725 init_block->statements()->Add( | 3714 init_block->statements()->Add( |
3726 factory()->NewExpressionStatement( | 3715 factory()->NewExpressionStatement( |
3727 factory()->NewAssignment(Token::ASSIGN, single_var, | 3716 factory()->NewAssignment(Token::ASSIGN, single_var, |
3728 decl.initializer, kNoSourcePosition), | 3717 decl.initializer, kNoSourcePosition), |
3729 kNoSourcePosition), | 3718 kNoSourcePosition), |
3730 zone()); | 3719 zone()); |
3731 } | 3720 } |
3732 | 3721 |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4755 | 4744 |
4756 block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 4745 block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
4757 block->statements()->Add(try_catch_statement, zone()); | 4746 block->statements()->Add(try_catch_statement, zone()); |
4758 return block; | 4747 return block; |
4759 } | 4748 } |
4760 | 4749 |
4761 Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { | 4750 Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { |
4762 DCHECK_NOT_NULL(function_state_->generator_object_variable()); | 4751 DCHECK_NOT_NULL(function_state_->generator_object_variable()); |
4763 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | 4752 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
4764 args->Add(factory()->NewThisFunction(pos), zone()); | 4753 args->Add(factory()->NewThisFunction(pos), zone()); |
4765 args->Add(IsArrowFunction(kind) | 4754 args->Add(IsArrowFunction(kind) ? GetLiteralUndefined(pos) |
4766 ? GetLiteralUndefined(pos) | 4755 : ThisExpression(kNoSourcePosition), |
4767 : ThisExpression(factory(), kNoSourcePosition), | |
4768 zone()); | 4756 zone()); |
4769 return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, | 4757 return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, |
4770 pos); | 4758 pos); |
4771 } | 4759 } |
4772 | 4760 |
4773 Expression* Parser::BuildPromiseResolve(Expression* value, int pos) { | 4761 Expression* Parser::BuildPromiseResolve(Expression* value, int pos) { |
4774 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); | 4762 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); |
4775 args->Add(value, zone()); | 4763 args->Add(value, zone()); |
4776 return factory()->NewCallRuntime(Context::PROMISE_CREATE_RESOLVED_INDEX, args, | 4764 return factory()->NewCallRuntime(Context::PROMISE_CREATE_RESOLVED_INDEX, args, |
4777 pos); | 4765 pos); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4878 } else if (IsAsyncFunction(kind)) { | 4866 } else if (IsAsyncFunction(kind)) { |
4879 const bool accept_IN = true; | 4867 const bool accept_IN = true; |
4880 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind, | 4868 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind, |
4881 FunctionBody::Normal, accept_IN, pos, CHECK_OK); | 4869 FunctionBody::Normal, accept_IN, pos, CHECK_OK); |
4882 } else { | 4870 } else { |
4883 ParseStatementList(body, Token::RBRACE, CHECK_OK); | 4871 ParseStatementList(body, Token::RBRACE, CHECK_OK); |
4884 } | 4872 } |
4885 | 4873 |
4886 if (IsSubclassConstructor(kind)) { | 4874 if (IsSubclassConstructor(kind)) { |
4887 body->Add(factory()->NewReturnStatement( | 4875 body->Add(factory()->NewReturnStatement( |
4888 this->ThisExpression(factory(), kNoSourcePosition), | 4876 this->ThisExpression(kNoSourcePosition), kNoSourcePosition), |
4889 kNoSourcePosition), | |
4890 zone()); | 4877 zone()); |
4891 } | 4878 } |
4892 } | 4879 } |
4893 | 4880 |
4894 Expect(Token::RBRACE, CHECK_OK); | 4881 Expect(Token::RBRACE, CHECK_OK); |
4895 scope()->set_end_position(scanner()->location().end_pos); | 4882 scope()->set_end_position(scanner()->location().end_pos); |
4896 | 4883 |
4897 if (!parameters.is_simple) { | 4884 if (!parameters.is_simple) { |
4898 DCHECK_NOT_NULL(inner_scope); | 4885 DCHECK_NOT_NULL(inner_scope); |
4899 DCHECK_EQ(function_scope, scope()); | 4886 DCHECK_EQ(function_scope, scope()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5002 } | 4989 } |
5003 | 4990 |
5004 BlockState block_state(&scope_state_); | 4991 BlockState block_state(&scope_state_); |
5005 RaiseLanguageMode(STRICT); | 4992 RaiseLanguageMode(STRICT); |
5006 #ifdef DEBUG | 4993 #ifdef DEBUG |
5007 scope()->SetScopeName(name); | 4994 scope()->SetScopeName(name); |
5008 #endif | 4995 #endif |
5009 | 4996 |
5010 VariableProxy* proxy = nullptr; | 4997 VariableProxy* proxy = nullptr; |
5011 if (name != nullptr) { | 4998 if (name != nullptr) { |
5012 proxy = NewUnresolved(name, CONST); | 4999 proxy = NewUnresolved(name); |
5013 // TODO(verwaest): declare via block_state. | 5000 // TODO(verwaest): declare via block_state. |
5014 Declaration* declaration = | 5001 Declaration* declaration = |
5015 factory()->NewVariableDeclaration(proxy, block_state.scope(), pos); | 5002 factory()->NewVariableDeclaration(proxy, block_state.scope(), pos); |
5016 Declare(declaration, DeclarationDescriptor::NORMAL, CONST, | 5003 Declare(declaration, DeclarationDescriptor::NORMAL, CONST, |
5017 DefaultInitializationFlag(CONST), CHECK_OK); | 5004 DefaultInitializationFlag(CONST), CHECK_OK); |
5018 } | 5005 } |
5019 | 5006 |
5020 Expression* extends = nullptr; | 5007 Expression* extends = nullptr; |
5021 if (Check(Token::EXTENDS)) { | 5008 if (Check(Token::EXTENDS)) { |
5022 block_state.set_start_position(scanner()->location().end_pos); | 5009 block_state.set_start_position(scanner()->location().end_pos); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5206 ZoneList<Declaration*>* decls = inner_scope->declarations(); | 5193 ZoneList<Declaration*>* decls = inner_scope->declarations(); |
5207 BlockState block_state(&scope_state_, inner_scope); | 5194 BlockState block_state(&scope_state_, inner_scope); |
5208 for (int i = 0; i < decls->length(); ++i) { | 5195 for (int i = 0; i < decls->length(); ++i) { |
5209 Declaration* decl = decls->at(i); | 5196 Declaration* decl = decls->at(i); |
5210 if (decl->proxy()->var()->mode() != VAR || !decl->IsVariableDeclaration()) { | 5197 if (decl->proxy()->var()->mode() != VAR || !decl->IsVariableDeclaration()) { |
5211 continue; | 5198 continue; |
5212 } | 5199 } |
5213 const AstRawString* name = decl->proxy()->raw_name(); | 5200 const AstRawString* name = decl->proxy()->raw_name(); |
5214 Variable* parameter = function_scope->LookupLocal(name); | 5201 Variable* parameter = function_scope->LookupLocal(name); |
5215 if (parameter == nullptr) continue; | 5202 if (parameter == nullptr) continue; |
5216 VariableProxy* to = NewUnresolved(name, VAR); | 5203 VariableProxy* to = NewUnresolved(name); |
5217 VariableProxy* from = factory()->NewVariableProxy(parameter); | 5204 VariableProxy* from = factory()->NewVariableProxy(parameter); |
5218 Expression* assignment = | 5205 Expression* assignment = |
5219 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition); | 5206 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition); |
5220 Statement* statement = | 5207 Statement* statement = |
5221 factory()->NewExpressionStatement(assignment, kNoSourcePosition); | 5208 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
5222 inner_block->statements()->InsertAt(0, statement, zone()); | 5209 inner_block->statements()->InsertAt(0, statement, zone()); |
5223 } | 5210 } |
5224 } | 5211 } |
5225 | 5212 |
5226 void Parser::InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope, | 5213 void Parser::InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope, |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5687 Expression* super_constructor = factory()->NewCallRuntime( | 5674 Expression* super_constructor = factory()->NewCallRuntime( |
5688 Runtime::kInlineGetSuperConstructor, tmp, pos); | 5675 Runtime::kInlineGetSuperConstructor, tmp, pos); |
5689 args->InsertAt(0, super_constructor, zone()); | 5676 args->InsertAt(0, super_constructor, zone()); |
5690 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); | 5677 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); |
5691 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, | 5678 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, |
5692 pos); | 5679 pos); |
5693 } else { | 5680 } else { |
5694 if (function->IsProperty()) { | 5681 if (function->IsProperty()) { |
5695 // Method calls | 5682 // Method calls |
5696 if (function->AsProperty()->IsSuperAccess()) { | 5683 if (function->AsProperty()->IsSuperAccess()) { |
5697 Expression* home = ThisExpression(factory(), kNoSourcePosition); | 5684 Expression* home = ThisExpression(kNoSourcePosition); |
5698 args->InsertAt(0, function, zone()); | 5685 args->InsertAt(0, function, zone()); |
5699 args->InsertAt(1, home, zone()); | 5686 args->InsertAt(1, home, zone()); |
5700 } else { | 5687 } else { |
5701 Variable* temp = NewTemporary(ast_value_factory()->empty_string()); | 5688 Variable* temp = NewTemporary(ast_value_factory()->empty_string()); |
5702 VariableProxy* obj = factory()->NewVariableProxy(temp); | 5689 VariableProxy* obj = factory()->NewVariableProxy(temp); |
5703 Assignment* assign_obj = factory()->NewAssignment( | 5690 Assignment* assign_obj = factory()->NewAssignment( |
5704 Token::ASSIGN, obj, function->AsProperty()->obj(), | 5691 Token::ASSIGN, obj, function->AsProperty()->obj(), |
5705 kNoSourcePosition); | 5692 kNoSourcePosition); |
5706 function = factory()->NewProperty( | 5693 function = factory()->NewProperty( |
5707 assign_obj, function->AsProperty()->key(), kNoSourcePosition); | 5694 assign_obj, function->AsProperty()->key(), kNoSourcePosition); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5928 | 5915 |
5929 Expression* Parser::RewriteAssignExponentiation(Expression* left, | 5916 Expression* Parser::RewriteAssignExponentiation(Expression* left, |
5930 Expression* right, int pos) { | 5917 Expression* right, int pos) { |
5931 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | 5918 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
5932 if (left->IsVariableProxy()) { | 5919 if (left->IsVariableProxy()) { |
5933 VariableProxy* lhs = left->AsVariableProxy(); | 5920 VariableProxy* lhs = left->AsVariableProxy(); |
5934 | 5921 |
5935 Expression* result; | 5922 Expression* result; |
5936 DCHECK_NOT_NULL(lhs->raw_name()); | 5923 DCHECK_NOT_NULL(lhs->raw_name()); |
5937 result = this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(), | 5924 result = this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(), |
5938 lhs->end_position(), factory()); | 5925 lhs->end_position()); |
5939 args->Add(left, zone()); | 5926 args->Add(left, zone()); |
5940 args->Add(right, zone()); | 5927 args->Add(right, zone()); |
5941 Expression* call = | 5928 Expression* call = |
5942 factory()->NewCallRuntime(Context::MATH_POW_INDEX, args, pos); | 5929 factory()->NewCallRuntime(Context::MATH_POW_INDEX, args, pos); |
5943 return factory()->NewAssignment(Token::ASSIGN, result, call, pos); | 5930 return factory()->NewAssignment(Token::ASSIGN, result, call, pos); |
5944 } else if (left->IsProperty()) { | 5931 } else if (left->IsProperty()) { |
5945 Property* prop = left->AsProperty(); | 5932 Property* prop = left->AsProperty(); |
5946 auto temp_obj = NewTemporary(ast_value_factory()->empty_string()); | 5933 auto temp_obj = NewTemporary(ast_value_factory()->empty_string()); |
5947 auto temp_key = NewTemporary(ast_value_factory()->empty_string()); | 5934 auto temp_key = NewTemporary(ast_value_factory()->empty_string()); |
5948 Expression* assign_obj = factory()->NewAssignment( | 5935 Expression* assign_obj = factory()->NewAssignment( |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7083 node->Print(Isolate::Current()); | 7070 node->Print(Isolate::Current()); |
7084 } | 7071 } |
7085 #endif // DEBUG | 7072 #endif // DEBUG |
7086 | 7073 |
7087 #undef CHECK_OK | 7074 #undef CHECK_OK |
7088 #undef CHECK_OK_VOID | 7075 #undef CHECK_OK_VOID |
7089 #undef CHECK_FAILED | 7076 #undef CHECK_FAILED |
7090 | 7077 |
7091 } // namespace internal | 7078 } // namespace internal |
7092 } // namespace v8 | 7079 } // namespace v8 |
OLD | NEW |