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