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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 } | 733 } |
734 | 734 |
735 | 735 |
736 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { | 736 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { |
737 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); | 737 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); |
738 } | 738 } |
739 | 739 |
740 | 740 |
741 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, | 741 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, |
742 int pos) { | 742 int pos) { |
743 return factory->NewVariableProxy(scope->receiver(), pos); | 743 return scope->NewUnresolved(factory, |
| 744 parser_->ast_value_factory()->this_string(), |
| 745 Variable::THIS, pos, pos + 4); |
744 } | 746 } |
745 | 747 |
746 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, | 748 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, |
747 int pos) { | 749 int pos) { |
748 return factory->NewSuperReference( | 750 return factory->NewSuperReference( |
749 ThisExpression(scope, factory, pos)->AsVariableProxy(), | 751 ThisExpression(scope, factory, pos)->AsVariableProxy(), |
750 pos); | 752 pos); |
751 } | 753 } |
752 | 754 |
753 | 755 |
(...skipping 27 matching lines...) Expand all Loading... |
781 return NULL; | 783 return NULL; |
782 } | 784 } |
783 | 785 |
784 | 786 |
785 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, | 787 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, |
786 int start_position, | 788 int start_position, |
787 int end_position, | 789 int end_position, |
788 Scope* scope, | 790 Scope* scope, |
789 AstNodeFactory* factory) { | 791 AstNodeFactory* factory) { |
790 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); | 792 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); |
791 return scope->NewUnresolved(factory, name, start_position, end_position); | 793 return scope->NewUnresolved(factory, name, Variable::NORMAL, start_position, |
| 794 end_position); |
792 } | 795 } |
793 | 796 |
794 | 797 |
795 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, | 798 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, |
796 AstNodeFactory* factory) { | 799 AstNodeFactory* factory) { |
797 const AstRawString* symbol = GetSymbol(scanner); | 800 const AstRawString* symbol = GetSymbol(scanner); |
798 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 801 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
799 return factory->NewStringLiteral(symbol, pos); | 802 return factory->NewStringLiteral(symbol, pos); |
800 } | 803 } |
801 | 804 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 // background thread. We should not access anything Isolate / heap dependent | 963 // background thread. We should not access anything Isolate / heap dependent |
961 // via ParseInfo, and also not pass it forward. | 964 // via ParseInfo, and also not pass it forward. |
962 DCHECK(scope_ == NULL); | 965 DCHECK(scope_ == NULL); |
963 DCHECK(target_stack_ == NULL); | 966 DCHECK(target_stack_ == NULL); |
964 | 967 |
965 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; | 968 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; |
966 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; | 969 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; |
967 | 970 |
968 FunctionLiteral* result = NULL; | 971 FunctionLiteral* result = NULL; |
969 { | 972 { |
| 973 // TODO(wingo): Add an outer GLOBAL_SCOPE corresponding to the native |
| 974 // context, which will have the "this" binding for script scopes. |
970 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); | 975 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); |
971 info->set_script_scope(scope); | 976 info->set_script_scope(scope); |
972 if (!info->context().is_null() && !info->context()->IsNativeContext()) { | 977 if (!info->context().is_null() && !info->context()->IsNativeContext()) { |
973 scope = Scope::DeserializeScopeChain(info->isolate(), zone(), | 978 scope = Scope::DeserializeScopeChain(info->isolate(), zone(), |
974 *info->context(), scope); | 979 *info->context(), scope); |
975 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this | 980 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this |
976 // means the Parser cannot operate independent of the V8 heap. Tell the | 981 // means the Parser cannot operate independent of the V8 heap. Tell the |
977 // string table to internalize strings and values right after they're | 982 // string table to internalize strings and values right after they're |
978 // created. This kind of parsing can only be done in the main thread. | 983 // created. This kind of parsing can only be done in the main thread. |
979 DCHECK(parsing_on_main_thread_); | 984 DCHECK(parsing_on_main_thread_); |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1912 } | 1917 } |
1913 | 1918 |
1914 | 1919 |
1915 VariableProxy* Parser::NewUnresolved(const AstRawString* name, | 1920 VariableProxy* Parser::NewUnresolved(const AstRawString* name, |
1916 VariableMode mode) { | 1921 VariableMode mode) { |
1917 // If we are inside a function, a declaration of a var/const variable is a | 1922 // If we are inside a function, a declaration of a var/const variable is a |
1918 // truly local variable, and the scope of the variable is always the function | 1923 // truly local variable, and the scope of the variable is always the function |
1919 // scope. | 1924 // scope. |
1920 // Let/const variables in harmony mode are always added to the immediately | 1925 // Let/const variables in harmony mode are always added to the immediately |
1921 // enclosing scope. | 1926 // enclosing scope. |
1922 return DeclarationScope(mode)->NewUnresolved(factory(), name, | 1927 return DeclarationScope(mode)->NewUnresolved( |
1923 scanner()->location().beg_pos, | 1928 factory(), name, Variable::NORMAL, scanner()->location().beg_pos, |
1924 scanner()->location().end_pos); | 1929 scanner()->location().end_pos); |
1925 } | 1930 } |
1926 | 1931 |
1927 | 1932 |
1928 Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { | 1933 Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { |
1929 VariableProxy* proxy = declaration->proxy(); | 1934 VariableProxy* proxy = declaration->proxy(); |
1930 DCHECK(proxy->raw_name() != NULL); | 1935 DCHECK(proxy->raw_name() != NULL); |
1931 const AstRawString* name = proxy->raw_name(); | 1936 const AstRawString* name = proxy->raw_name(); |
1932 VariableMode mode = declaration->mode(); | 1937 VariableMode mode = declaration->mode(); |
1933 Scope* declaration_scope = DeclarationScope(mode); | 1938 Scope* declaration_scope = DeclarationScope(mode); |
1934 Variable* var = NULL; | 1939 Variable* var = NULL; |
(...skipping 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3578 *ok = false; | 3583 *ok = false; |
3579 return nullptr; | 3584 return nullptr; |
3580 } | 3585 } |
3581 ForEachStatement* loop = | 3586 ForEachStatement* loop = |
3582 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3587 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3583 Target target(&this->target_stack_, loop); | 3588 Target target(&this->target_stack_, loop); |
3584 | 3589 |
3585 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3590 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3586 Expect(Token::RPAREN, CHECK_OK); | 3591 Expect(Token::RPAREN, CHECK_OK); |
3587 | 3592 |
3588 VariableProxy* each = | 3593 VariableProxy* each = scope_->NewUnresolved( |
3589 scope_->NewUnresolved(factory(), name, each_beg_pos, each_end_pos); | 3594 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); |
3590 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3595 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3591 InitializeForEachStatement(loop, each, enumerable, body); | 3596 InitializeForEachStatement(loop, each, enumerable, body); |
3592 Block* result = | 3597 Block* result = |
3593 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); | 3598 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); |
3594 result->AddStatement(variable_statement, zone()); | 3599 result->AddStatement(variable_statement, zone()); |
3595 result->AddStatement(loop, zone()); | 3600 result->AddStatement(loop, zone()); |
3596 scope_ = saved_scope; | 3601 scope_ = saved_scope; |
3597 for_scope->set_end_position(scanner()->location().end_pos); | 3602 for_scope->set_end_position(scanner()->location().end_pos); |
3598 for_scope = for_scope->FinalizeBlockScope(); | 3603 for_scope = for_scope->FinalizeBlockScope(); |
3599 DCHECK(for_scope == NULL); | 3604 DCHECK(for_scope == NULL); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3660 ForEachStatement* loop = | 3665 ForEachStatement* loop = |
3661 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3666 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3662 Target target(&this->target_stack_, loop); | 3667 Target target(&this->target_stack_, loop); |
3663 | 3668 |
3664 // The expression does not see the loop variable. | 3669 // The expression does not see the loop variable. |
3665 scope_ = saved_scope; | 3670 scope_ = saved_scope; |
3666 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3671 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3667 scope_ = for_scope; | 3672 scope_ = for_scope; |
3668 Expect(Token::RPAREN, CHECK_OK); | 3673 Expect(Token::RPAREN, CHECK_OK); |
3669 | 3674 |
3670 VariableProxy* each = | 3675 VariableProxy* each = scope_->NewUnresolved( |
3671 scope_->NewUnresolved(factory(), name, each_beg_pos, each_end_pos); | 3676 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); |
3672 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3677 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3673 Block* body_block = | 3678 Block* body_block = |
3674 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 3679 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
3675 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; | 3680 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; |
3676 Assignment* assignment = factory()->NewAssignment( | 3681 Assignment* assignment = factory()->NewAssignment( |
3677 init_op, each, temp_proxy, RelocInfo::kNoPosition); | 3682 init_op, each, temp_proxy, RelocInfo::kNoPosition); |
3678 Statement* assignment_statement = factory()->NewExpressionStatement( | 3683 Statement* assignment_statement = factory()->NewExpressionStatement( |
3679 assignment, RelocInfo::kNoPosition); | 3684 assignment, RelocInfo::kNoPosition); |
3680 body_block->AddStatement(variable_statement, zone()); | 3685 body_block->AddStatement(variable_statement, zone()); |
3681 body_block->AddStatement(assignment_statement, zone()); | 3686 body_block->AddStatement(assignment_statement, zone()); |
(...skipping 2238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5920 | 5925 |
5921 Expression* Parser::SpreadCallNew(Expression* function, | 5926 Expression* Parser::SpreadCallNew(Expression* function, |
5922 ZoneList<v8::internal::Expression*>* args, | 5927 ZoneList<v8::internal::Expression*>* args, |
5923 int pos) { | 5928 int pos) { |
5924 args->InsertAt(0, function, zone()); | 5929 args->InsertAt(0, function, zone()); |
5925 | 5930 |
5926 return factory()->NewCallRuntime( | 5931 return factory()->NewCallRuntime( |
5927 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5932 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5928 } | 5933 } |
5929 } } // namespace v8::internal | 5934 } } // namespace v8::internal |
OLD | NEW |