| 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 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 } | 735 } |
| 736 | 736 |
| 737 | 737 |
| 738 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { | 738 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { |
| 739 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); | 739 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); |
| 740 } | 740 } |
| 741 | 741 |
| 742 | 742 |
| 743 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, | 743 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, |
| 744 int pos) { | 744 int pos) { |
| 745 return factory->NewVariableProxy(scope->receiver(), pos); | 745 return scope->NewUnresolved(factory, |
| 746 parser_->ast_value_factory()->this_string(), |
| 747 Variable::THIS, pos, pos + 4); |
| 746 } | 748 } |
| 747 | 749 |
| 748 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, | 750 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, |
| 749 int pos) { | 751 int pos) { |
| 750 return factory->NewSuperReference( | 752 return factory->NewSuperReference( |
| 751 ThisExpression(scope, factory, pos)->AsVariableProxy(), | 753 ThisExpression(scope, factory, pos)->AsVariableProxy(), |
| 752 pos); | 754 pos); |
| 753 } | 755 } |
| 754 | 756 |
| 755 | 757 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 783 return NULL; | 785 return NULL; |
| 784 } | 786 } |
| 785 | 787 |
| 786 | 788 |
| 787 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, | 789 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, |
| 788 int start_position, | 790 int start_position, |
| 789 int end_position, | 791 int end_position, |
| 790 Scope* scope, | 792 Scope* scope, |
| 791 AstNodeFactory* factory) { | 793 AstNodeFactory* factory) { |
| 792 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); | 794 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); |
| 793 return scope->NewUnresolved(factory, name, start_position, end_position); | 795 return scope->NewUnresolved(factory, name, Variable::NORMAL, start_position, |
| 796 end_position); |
| 794 } | 797 } |
| 795 | 798 |
| 796 | 799 |
| 797 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, | 800 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, |
| 798 AstNodeFactory* factory) { | 801 AstNodeFactory* factory) { |
| 799 const AstRawString* symbol = GetSymbol(scanner); | 802 const AstRawString* symbol = GetSymbol(scanner); |
| 800 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 803 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
| 801 return factory->NewStringLiteral(symbol, pos); | 804 return factory->NewStringLiteral(symbol, pos); |
| 802 } | 805 } |
| 803 | 806 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 // background thread. We should not access anything Isolate / heap dependent | 965 // background thread. We should not access anything Isolate / heap dependent |
| 963 // via ParseInfo, and also not pass it forward. | 966 // via ParseInfo, and also not pass it forward. |
| 964 DCHECK(scope_ == NULL); | 967 DCHECK(scope_ == NULL); |
| 965 DCHECK(target_stack_ == NULL); | 968 DCHECK(target_stack_ == NULL); |
| 966 | 969 |
| 967 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; | 970 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; |
| 968 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; | 971 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; |
| 969 | 972 |
| 970 FunctionLiteral* result = NULL; | 973 FunctionLiteral* result = NULL; |
| 971 { | 974 { |
| 975 // TODO(wingo): Add an outer GLOBAL_SCOPE corresponding to the native |
| 976 // context, which will have the "this" binding for script scopes. |
| 972 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); | 977 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); |
| 973 info->set_script_scope(scope); | 978 info->set_script_scope(scope); |
| 974 if (!info->context().is_null() && !info->context()->IsNativeContext()) { | 979 if (!info->context().is_null() && !info->context()->IsNativeContext()) { |
| 975 scope = Scope::DeserializeScopeChain(info->isolate(), zone(), | 980 scope = Scope::DeserializeScopeChain(info->isolate(), zone(), |
| 976 *info->context(), scope); | 981 *info->context(), scope); |
| 977 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this | 982 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this |
| 978 // means the Parser cannot operate independent of the V8 heap. Tell the | 983 // means the Parser cannot operate independent of the V8 heap. Tell the |
| 979 // string table to internalize strings and values right after they're | 984 // string table to internalize strings and values right after they're |
| 980 // created. This kind of parsing can only be done in the main thread. | 985 // created. This kind of parsing can only be done in the main thread. |
| 981 DCHECK(parsing_on_main_thread_); | 986 DCHECK(parsing_on_main_thread_); |
| (...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1916 } | 1921 } |
| 1917 | 1922 |
| 1918 | 1923 |
| 1919 VariableProxy* Parser::NewUnresolved(const AstRawString* name, | 1924 VariableProxy* Parser::NewUnresolved(const AstRawString* name, |
| 1920 VariableMode mode) { | 1925 VariableMode mode) { |
| 1921 // If we are inside a function, a declaration of a var/const variable is a | 1926 // If we are inside a function, a declaration of a var/const variable is a |
| 1922 // truly local variable, and the scope of the variable is always the function | 1927 // truly local variable, and the scope of the variable is always the function |
| 1923 // scope. | 1928 // scope. |
| 1924 // Let/const variables in harmony mode are always added to the immediately | 1929 // Let/const variables in harmony mode are always added to the immediately |
| 1925 // enclosing scope. | 1930 // enclosing scope. |
| 1926 return DeclarationScope(mode)->NewUnresolved(factory(), name, | 1931 return DeclarationScope(mode)->NewUnresolved( |
| 1927 scanner()->location().beg_pos, | 1932 factory(), name, Variable::NORMAL, scanner()->location().beg_pos, |
| 1928 scanner()->location().end_pos); | 1933 scanner()->location().end_pos); |
| 1929 } | 1934 } |
| 1930 | 1935 |
| 1931 | 1936 |
| 1932 Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { | 1937 Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { |
| 1933 VariableProxy* proxy = declaration->proxy(); | 1938 VariableProxy* proxy = declaration->proxy(); |
| 1934 DCHECK(proxy->raw_name() != NULL); | 1939 DCHECK(proxy->raw_name() != NULL); |
| 1935 const AstRawString* name = proxy->raw_name(); | 1940 const AstRawString* name = proxy->raw_name(); |
| 1936 VariableMode mode = declaration->mode(); | 1941 VariableMode mode = declaration->mode(); |
| 1937 Scope* declaration_scope = DeclarationScope(mode); | 1942 Scope* declaration_scope = DeclarationScope(mode); |
| 1938 Variable* var = NULL; | 1943 Variable* var = NULL; |
| (...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3439 *ok = false; | 3444 *ok = false; |
| 3440 return nullptr; | 3445 return nullptr; |
| 3441 } | 3446 } |
| 3442 ForEachStatement* loop = | 3447 ForEachStatement* loop = |
| 3443 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3448 factory()->NewForEachStatement(mode, labels, stmt_pos); |
| 3444 Target target(&this->target_stack_, loop); | 3449 Target target(&this->target_stack_, loop); |
| 3445 | 3450 |
| 3446 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3451 Expression* enumerable = ParseExpression(true, CHECK_OK); |
| 3447 Expect(Token::RPAREN, CHECK_OK); | 3452 Expect(Token::RPAREN, CHECK_OK); |
| 3448 | 3453 |
| 3449 VariableProxy* each = scope_->NewUnresolved( | 3454 VariableProxy* each = |
| 3450 factory(), parsing_result.SingleName(), each_beg_pos, each_end_pos); | 3455 scope_->NewUnresolved(factory(), parsing_result.SingleName(), |
| 3456 Variable::NORMAL, each_beg_pos, each_end_pos); |
| 3451 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3457 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
| 3452 InitializeForEachStatement(loop, each, enumerable, body); | 3458 InitializeForEachStatement(loop, each, enumerable, body); |
| 3453 Block* result = | 3459 Block* result = |
| 3454 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); | 3460 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); |
| 3455 result->AddStatement(variable_statement, zone()); | 3461 result->AddStatement(variable_statement, zone()); |
| 3456 result->AddStatement(loop, zone()); | 3462 result->AddStatement(loop, zone()); |
| 3457 scope_ = saved_scope; | 3463 scope_ = saved_scope; |
| 3458 for_scope->set_end_position(scanner()->location().end_pos); | 3464 for_scope->set_end_position(scanner()->location().end_pos); |
| 3459 for_scope = for_scope->FinalizeBlockScope(); | 3465 for_scope = for_scope->FinalizeBlockScope(); |
| 3460 DCHECK(for_scope == NULL); | 3466 DCHECK(for_scope == NULL); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3523 ForEachStatement* loop = | 3529 ForEachStatement* loop = |
| 3524 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3530 factory()->NewForEachStatement(mode, labels, stmt_pos); |
| 3525 Target target(&this->target_stack_, loop); | 3531 Target target(&this->target_stack_, loop); |
| 3526 | 3532 |
| 3527 // The expression does not see the loop variable. | 3533 // The expression does not see the loop variable. |
| 3528 scope_ = saved_scope; | 3534 scope_ = saved_scope; |
| 3529 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3535 Expression* enumerable = ParseExpression(true, CHECK_OK); |
| 3530 scope_ = for_scope; | 3536 scope_ = for_scope; |
| 3531 Expect(Token::RPAREN, CHECK_OK); | 3537 Expect(Token::RPAREN, CHECK_OK); |
| 3532 | 3538 |
| 3533 VariableProxy* each = scope_->NewUnresolved( | 3539 VariableProxy* each = |
| 3534 factory(), parsing_result.SingleName(), each_end_pos); | 3540 scope_->NewUnresolved(factory(), parsing_result.SingleName(), |
| 3541 Variable::NORMAL, each_end_pos); |
| 3535 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3542 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
| 3536 Block* body_block = | 3543 Block* body_block = |
| 3537 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 3544 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
| 3538 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; | 3545 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; |
| 3539 Assignment* assignment = factory()->NewAssignment( | 3546 Assignment* assignment = factory()->NewAssignment( |
| 3540 init_op, each, temp_proxy, RelocInfo::kNoPosition); | 3547 init_op, each, temp_proxy, RelocInfo::kNoPosition); |
| 3541 Statement* assignment_statement = factory()->NewExpressionStatement( | 3548 Statement* assignment_statement = factory()->NewExpressionStatement( |
| 3542 assignment, RelocInfo::kNoPosition); | 3549 assignment, RelocInfo::kNoPosition); |
| 3543 body_block->AddStatement(variable_statement, zone()); | 3550 body_block->AddStatement(variable_statement, zone()); |
| 3544 body_block->AddStatement(assignment_statement, zone()); | 3551 body_block->AddStatement(assignment_statement, zone()); |
| (...skipping 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5747 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5754 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
| 5748 args = new (zone()) ZoneList<Expression*>(0, zone()); | 5755 args = new (zone()) ZoneList<Expression*>(0, zone()); |
| 5749 args->Add(result, zone()); | 5756 args->Add(result, zone()); |
| 5750 return factory()->NewCallRuntime( | 5757 return factory()->NewCallRuntime( |
| 5751 ast_value_factory()->empty_string(), | 5758 ast_value_factory()->empty_string(), |
| 5752 Runtime::FunctionForId(Runtime::kInlineCallSuperWithSpread), args, pos); | 5759 Runtime::FunctionForId(Runtime::kInlineCallSuperWithSpread), args, pos); |
| 5753 } else { | 5760 } else { |
| 5754 if (function->IsProperty()) { | 5761 if (function->IsProperty()) { |
| 5755 // Method calls | 5762 // Method calls |
| 5756 if (function->AsProperty()->IsSuperAccess()) { | 5763 if (function->AsProperty()->IsSuperAccess()) { |
| 5757 VariableProxy* original_home = | 5764 Expression* home = |
| 5758 function->AsProperty()->obj()->AsSuperReference()->this_var(); | 5765 ThisExpression(scope_, factory(), RelocInfo::kNoPosition); |
| 5759 VariableProxy* home = factory()->NewVariableProxy(original_home->var()); | |
| 5760 args->InsertAt(0, function, zone()); | 5766 args->InsertAt(0, function, zone()); |
| 5761 args->InsertAt(1, home, zone()); | 5767 args->InsertAt(1, home, zone()); |
| 5762 } else { | 5768 } else { |
| 5763 Variable* temp = | 5769 Variable* temp = |
| 5764 scope_->NewTemporary(ast_value_factory()->empty_string()); | 5770 scope_->NewTemporary(ast_value_factory()->empty_string()); |
| 5765 VariableProxy* obj = factory()->NewVariableProxy(temp); | 5771 VariableProxy* obj = factory()->NewVariableProxy(temp); |
| 5766 Assignment* assign_obj = factory()->NewAssignment( | 5772 Assignment* assign_obj = factory()->NewAssignment( |
| 5767 Token::ASSIGN, obj, function->AsProperty()->obj(), | 5773 Token::ASSIGN, obj, function->AsProperty()->obj(), |
| 5768 RelocInfo::kNoPosition); | 5774 RelocInfo::kNoPosition); |
| 5769 function = factory()->NewProperty( | 5775 function = factory()->NewProperty( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 5786 | 5792 |
| 5787 Expression* Parser::SpreadCallNew(Expression* function, | 5793 Expression* Parser::SpreadCallNew(Expression* function, |
| 5788 ZoneList<v8::internal::Expression*>* args, | 5794 ZoneList<v8::internal::Expression*>* args, |
| 5789 int pos) { | 5795 int pos) { |
| 5790 args->InsertAt(0, function, zone()); | 5796 args->InsertAt(0, function, zone()); |
| 5791 | 5797 |
| 5792 return factory()->NewCallRuntime( | 5798 return factory()->NewCallRuntime( |
| 5793 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5799 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
| 5794 } | 5800 } |
| 5795 } } // namespace v8::internal | 5801 } } // namespace v8::internal |
| OLD | NEW |