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 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 } | 734 } |
735 | 735 |
736 | 736 |
737 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { | 737 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { |
738 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); | 738 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); |
739 } | 739 } |
740 | 740 |
741 | 741 |
742 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, | 742 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, |
743 int pos) { | 743 int pos) { |
744 return scope->NewUnresolved(factory, | 744 return factory->NewVariableProxy(scope->receiver(), pos); |
745 parser_->ast_value_factory()->this_string(), | |
746 Variable::THIS, pos, pos + 4); | |
747 } | 745 } |
748 | 746 |
749 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, | 747 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, |
750 int pos) { | 748 int pos) { |
751 return factory->NewSuperReference( | 749 return factory->NewSuperReference( |
752 ThisExpression(scope, factory, pos)->AsVariableProxy(), | 750 ThisExpression(scope, factory, pos)->AsVariableProxy(), |
753 pos); | 751 pos); |
754 } | 752 } |
755 | 753 |
756 | 754 |
(...skipping 27 matching lines...) Expand all Loading... |
784 return NULL; | 782 return NULL; |
785 } | 783 } |
786 | 784 |
787 | 785 |
788 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, | 786 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, |
789 int start_position, | 787 int start_position, |
790 int end_position, | 788 int end_position, |
791 Scope* scope, | 789 Scope* scope, |
792 AstNodeFactory* factory) { | 790 AstNodeFactory* factory) { |
793 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); | 791 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); |
794 return scope->NewUnresolved(factory, name, Variable::NORMAL, start_position, | 792 return scope->NewUnresolved(factory, name, start_position, end_position); |
795 end_position); | |
796 } | 793 } |
797 | 794 |
798 | 795 |
799 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, | 796 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, |
800 AstNodeFactory* factory) { | 797 AstNodeFactory* factory) { |
801 const AstRawString* symbol = GetSymbol(scanner); | 798 const AstRawString* symbol = GetSymbol(scanner); |
802 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 799 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
803 return factory->NewStringLiteral(symbol, pos); | 800 return factory->NewStringLiteral(symbol, pos); |
804 } | 801 } |
805 | 802 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 // background thread. We should not access anything Isolate / heap dependent | 961 // background thread. We should not access anything Isolate / heap dependent |
965 // via ParseInfo, and also not pass it forward. | 962 // via ParseInfo, and also not pass it forward. |
966 DCHECK(scope_ == NULL); | 963 DCHECK(scope_ == NULL); |
967 DCHECK(target_stack_ == NULL); | 964 DCHECK(target_stack_ == NULL); |
968 | 965 |
969 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; | 966 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; |
970 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; | 967 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; |
971 | 968 |
972 FunctionLiteral* result = NULL; | 969 FunctionLiteral* result = NULL; |
973 { | 970 { |
974 // TODO(wingo): Add an outer GLOBAL_SCOPE corresponding to the native | |
975 // context, which will have the "this" binding for script scopes. | |
976 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); | 971 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); |
977 info->set_script_scope(scope); | 972 info->set_script_scope(scope); |
978 if (!info->context().is_null() && !info->context()->IsNativeContext()) { | 973 if (!info->context().is_null() && !info->context()->IsNativeContext()) { |
979 scope = Scope::DeserializeScopeChain(info->isolate(), zone(), | 974 scope = Scope::DeserializeScopeChain(info->isolate(), zone(), |
980 *info->context(), scope); | 975 *info->context(), scope); |
981 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this | 976 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this |
982 // means the Parser cannot operate independent of the V8 heap. Tell the | 977 // means the Parser cannot operate independent of the V8 heap. Tell the |
983 // string table to internalize strings and values right after they're | 978 // string table to internalize strings and values right after they're |
984 // created. This kind of parsing can only be done in the main thread. | 979 // created. This kind of parsing can only be done in the main thread. |
985 DCHECK(parsing_on_main_thread_); | 980 DCHECK(parsing_on_main_thread_); |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1918 } | 1913 } |
1919 | 1914 |
1920 | 1915 |
1921 VariableProxy* Parser::NewUnresolved(const AstRawString* name, | 1916 VariableProxy* Parser::NewUnresolved(const AstRawString* name, |
1922 VariableMode mode) { | 1917 VariableMode mode) { |
1923 // If we are inside a function, a declaration of a var/const variable is a | 1918 // If we are inside a function, a declaration of a var/const variable is a |
1924 // truly local variable, and the scope of the variable is always the function | 1919 // truly local variable, and the scope of the variable is always the function |
1925 // scope. | 1920 // scope. |
1926 // Let/const variables in harmony mode are always added to the immediately | 1921 // Let/const variables in harmony mode are always added to the immediately |
1927 // enclosing scope. | 1922 // enclosing scope. |
1928 return DeclarationScope(mode)->NewUnresolved( | 1923 return DeclarationScope(mode)->NewUnresolved(factory(), name, |
1929 factory(), name, Variable::NORMAL, scanner()->location().beg_pos, | 1924 scanner()->location().beg_pos, |
1930 scanner()->location().end_pos); | 1925 scanner()->location().end_pos); |
1931 } | 1926 } |
1932 | 1927 |
1933 | 1928 |
1934 Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { | 1929 Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { |
1935 VariableProxy* proxy = declaration->proxy(); | 1930 VariableProxy* proxy = declaration->proxy(); |
1936 DCHECK(proxy->raw_name() != NULL); | 1931 DCHECK(proxy->raw_name() != NULL); |
1937 const AstRawString* name = proxy->raw_name(); | 1932 const AstRawString* name = proxy->raw_name(); |
1938 VariableMode mode = declaration->mode(); | 1933 VariableMode mode = declaration->mode(); |
1939 Scope* declaration_scope = DeclarationScope(mode); | 1934 Scope* declaration_scope = DeclarationScope(mode); |
1940 Variable* var = NULL; | 1935 Variable* var = NULL; |
(...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3433 *ok = false; | 3428 *ok = false; |
3434 return nullptr; | 3429 return nullptr; |
3435 } | 3430 } |
3436 ForEachStatement* loop = | 3431 ForEachStatement* loop = |
3437 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3432 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3438 Target target(&this->target_stack_, loop); | 3433 Target target(&this->target_stack_, loop); |
3439 | 3434 |
3440 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3435 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3441 Expect(Token::RPAREN, CHECK_OK); | 3436 Expect(Token::RPAREN, CHECK_OK); |
3442 | 3437 |
3443 VariableProxy* each = scope_->NewUnresolved( | 3438 VariableProxy* each = |
3444 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); | 3439 scope_->NewUnresolved(factory(), name, each_beg_pos, each_end_pos); |
3445 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3440 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3446 InitializeForEachStatement(loop, each, enumerable, body); | 3441 InitializeForEachStatement(loop, each, enumerable, body); |
3447 Block* result = | 3442 Block* result = |
3448 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); | 3443 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); |
3449 result->AddStatement(variable_statement, zone()); | 3444 result->AddStatement(variable_statement, zone()); |
3450 result->AddStatement(loop, zone()); | 3445 result->AddStatement(loop, zone()); |
3451 scope_ = saved_scope; | 3446 scope_ = saved_scope; |
3452 for_scope->set_end_position(scanner()->location().end_pos); | 3447 for_scope->set_end_position(scanner()->location().end_pos); |
3453 for_scope = for_scope->FinalizeBlockScope(); | 3448 for_scope = for_scope->FinalizeBlockScope(); |
3454 DCHECK(for_scope == NULL); | 3449 DCHECK(for_scope == NULL); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3515 ForEachStatement* loop = | 3510 ForEachStatement* loop = |
3516 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3511 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3517 Target target(&this->target_stack_, loop); | 3512 Target target(&this->target_stack_, loop); |
3518 | 3513 |
3519 // The expression does not see the loop variable. | 3514 // The expression does not see the loop variable. |
3520 scope_ = saved_scope; | 3515 scope_ = saved_scope; |
3521 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3516 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3522 scope_ = for_scope; | 3517 scope_ = for_scope; |
3523 Expect(Token::RPAREN, CHECK_OK); | 3518 Expect(Token::RPAREN, CHECK_OK); |
3524 | 3519 |
3525 VariableProxy* each = scope_->NewUnresolved( | 3520 VariableProxy* each = |
3526 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); | 3521 scope_->NewUnresolved(factory(), name, each_beg_pos, each_end_pos); |
3527 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3522 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3528 Block* body_block = | 3523 Block* body_block = |
3529 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 3524 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
3530 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; | 3525 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; |
3531 Assignment* assignment = factory()->NewAssignment( | 3526 Assignment* assignment = factory()->NewAssignment( |
3532 init_op, each, temp_proxy, RelocInfo::kNoPosition); | 3527 init_op, each, temp_proxy, RelocInfo::kNoPosition); |
3533 Statement* assignment_statement = factory()->NewExpressionStatement( | 3528 Statement* assignment_statement = factory()->NewExpressionStatement( |
3534 assignment, RelocInfo::kNoPosition); | 3529 assignment, RelocInfo::kNoPosition); |
3535 body_block->AddStatement(variable_statement, zone()); | 3530 body_block->AddStatement(variable_statement, zone()); |
3536 body_block->AddStatement(assignment_statement, zone()); | 3531 body_block->AddStatement(assignment_statement, zone()); |
(...skipping 2238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5775 | 5770 |
5776 Expression* Parser::SpreadCallNew(Expression* function, | 5771 Expression* Parser::SpreadCallNew(Expression* function, |
5777 ZoneList<v8::internal::Expression*>* args, | 5772 ZoneList<v8::internal::Expression*>* args, |
5778 int pos) { | 5773 int pos) { |
5779 args->InsertAt(0, function, zone()); | 5774 args->InsertAt(0, function, zone()); |
5780 | 5775 |
5781 return factory()->NewCallRuntime( | 5776 return factory()->NewCallRuntime( |
5782 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5777 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5783 } | 5778 } |
5784 } } // namespace v8::internal | 5779 } } // namespace v8::internal |
OLD | NEW |