Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: src/parser.cc

Issue 1146733002: Revert of Reapply "Resolve references to "this" the same way as normal variables"" (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/mips64/lithium-codegen-mips64.cc ('k') | src/ppc/full-codegen-ppc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 } 1910 }
1916 1911
1917 1912
1918 VariableProxy* Parser::NewUnresolved(const AstRawString* name, 1913 VariableProxy* Parser::NewUnresolved(const AstRawString* name,
1919 VariableMode mode) { 1914 VariableMode mode) {
1920 // If we are inside a function, a declaration of a var/const variable is a 1915 // If we are inside a function, a declaration of a var/const variable is a
1921 // truly local variable, and the scope of the variable is always the function 1916 // truly local variable, and the scope of the variable is always the function
1922 // scope. 1917 // scope.
1923 // Let/const variables in harmony mode are always added to the immediately 1918 // Let/const variables in harmony mode are always added to the immediately
1924 // enclosing scope. 1919 // enclosing scope.
1925 return DeclarationScope(mode)->NewUnresolved( 1920 return DeclarationScope(mode)->NewUnresolved(factory(), name,
1926 factory(), name, Variable::NORMAL, scanner()->location().beg_pos, 1921 scanner()->location().beg_pos,
1927 scanner()->location().end_pos); 1922 scanner()->location().end_pos);
1928 } 1923 }
1929 1924
1930 1925
1931 Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { 1926 Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) {
1932 VariableProxy* proxy = declaration->proxy(); 1927 VariableProxy* proxy = declaration->proxy();
1933 DCHECK(proxy->raw_name() != NULL); 1928 DCHECK(proxy->raw_name() != NULL);
1934 const AstRawString* name = proxy->raw_name(); 1929 const AstRawString* name = proxy->raw_name();
1935 VariableMode mode = declaration->mode(); 1930 VariableMode mode = declaration->mode();
1936 Scope* declaration_scope = DeclarationScope(mode); 1931 Scope* declaration_scope = DeclarationScope(mode);
1937 Variable* var = NULL; 1932 Variable* var = NULL;
(...skipping 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after
3436 *ok = false; 3431 *ok = false;
3437 return nullptr; 3432 return nullptr;
3438 } 3433 }
3439 ForEachStatement* loop = 3434 ForEachStatement* loop =
3440 factory()->NewForEachStatement(mode, labels, stmt_pos); 3435 factory()->NewForEachStatement(mode, labels, stmt_pos);
3441 Target target(&this->target_stack_, loop); 3436 Target target(&this->target_stack_, loop);
3442 3437
3443 Expression* enumerable = ParseExpression(true, CHECK_OK); 3438 Expression* enumerable = ParseExpression(true, CHECK_OK);
3444 Expect(Token::RPAREN, CHECK_OK); 3439 Expect(Token::RPAREN, CHECK_OK);
3445 3440
3446 VariableProxy* each = 3441 VariableProxy* each = scope_->NewUnresolved(
3447 scope_->NewUnresolved(factory(), parsing_result.SingleName(), 3442 factory(), parsing_result.SingleName(), each_beg_pos, each_end_pos);
3448 Variable::NORMAL, each_beg_pos, each_end_pos);
3449 Statement* body = ParseSubStatement(NULL, CHECK_OK); 3443 Statement* body = ParseSubStatement(NULL, CHECK_OK);
3450 InitializeForEachStatement(loop, each, enumerable, body); 3444 InitializeForEachStatement(loop, each, enumerable, body);
3451 Block* result = 3445 Block* result =
3452 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); 3446 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
3453 result->AddStatement(variable_statement, zone()); 3447 result->AddStatement(variable_statement, zone());
3454 result->AddStatement(loop, zone()); 3448 result->AddStatement(loop, zone());
3455 scope_ = saved_scope; 3449 scope_ = saved_scope;
3456 for_scope->set_end_position(scanner()->location().end_pos); 3450 for_scope->set_end_position(scanner()->location().end_pos);
3457 for_scope = for_scope->FinalizeBlockScope(); 3451 for_scope = for_scope->FinalizeBlockScope();
3458 DCHECK(for_scope == NULL); 3452 DCHECK(for_scope == NULL);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3521 ForEachStatement* loop = 3515 ForEachStatement* loop =
3522 factory()->NewForEachStatement(mode, labels, stmt_pos); 3516 factory()->NewForEachStatement(mode, labels, stmt_pos);
3523 Target target(&this->target_stack_, loop); 3517 Target target(&this->target_stack_, loop);
3524 3518
3525 // The expression does not see the loop variable. 3519 // The expression does not see the loop variable.
3526 scope_ = saved_scope; 3520 scope_ = saved_scope;
3527 Expression* enumerable = ParseExpression(true, CHECK_OK); 3521 Expression* enumerable = ParseExpression(true, CHECK_OK);
3528 scope_ = for_scope; 3522 scope_ = for_scope;
3529 Expect(Token::RPAREN, CHECK_OK); 3523 Expect(Token::RPAREN, CHECK_OK);
3530 3524
3531 VariableProxy* each = 3525 VariableProxy* each = scope_->NewUnresolved(
3532 scope_->NewUnresolved(factory(), parsing_result.SingleName(), 3526 factory(), parsing_result.SingleName(), each_end_pos);
3533 Variable::NORMAL, each_end_pos);
3534 Statement* body = ParseSubStatement(NULL, CHECK_OK); 3527 Statement* body = ParseSubStatement(NULL, CHECK_OK);
3535 Block* body_block = 3528 Block* body_block =
3536 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); 3529 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition);
3537 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; 3530 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN;
3538 Assignment* assignment = factory()->NewAssignment( 3531 Assignment* assignment = factory()->NewAssignment(
3539 init_op, each, temp_proxy, RelocInfo::kNoPosition); 3532 init_op, each, temp_proxy, RelocInfo::kNoPosition);
3540 Statement* assignment_statement = factory()->NewExpressionStatement( 3533 Statement* assignment_statement = factory()->NewExpressionStatement(
3541 assignment, RelocInfo::kNoPosition); 3534 assignment, RelocInfo::kNoPosition);
3542 body_block->AddStatement(variable_statement, zone()); 3535 body_block->AddStatement(variable_statement, zone());
3543 body_block->AddStatement(assignment_statement, zone()); 3536 body_block->AddStatement(assignment_statement, zone());
(...skipping 2172 matching lines...) Expand 10 before | Expand all | Expand 10 after
5716 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5709 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5717 args = new (zone()) ZoneList<Expression*>(0, zone()); 5710 args = new (zone()) ZoneList<Expression*>(0, zone());
5718 args->Add(result, zone()); 5711 args->Add(result, zone());
5719 return factory()->NewCallRuntime( 5712 return factory()->NewCallRuntime(
5720 ast_value_factory()->empty_string(), 5713 ast_value_factory()->empty_string(),
5721 Runtime::FunctionForId(Runtime::kInlineCallSuperWithSpread), args, pos); 5714 Runtime::FunctionForId(Runtime::kInlineCallSuperWithSpread), args, pos);
5722 } else { 5715 } else {
5723 if (function->IsProperty()) { 5716 if (function->IsProperty()) {
5724 // Method calls 5717 // Method calls
5725 if (function->AsProperty()->IsSuperAccess()) { 5718 if (function->AsProperty()->IsSuperAccess()) {
5726 Expression* home = ThisExpression(scope_, factory(), 5719 VariableProxy* original_home =
5727 RelocInfo::kNoPosition); 5720 function->AsProperty()->obj()->AsSuperReference()->this_var();
5721 VariableProxy* home = factory()->NewVariableProxy(original_home->var());
5728 args->InsertAt(0, function, zone()); 5722 args->InsertAt(0, function, zone());
5729 args->InsertAt(1, home, zone()); 5723 args->InsertAt(1, home, zone());
5730 } else { 5724 } else {
5731 Variable* temp = 5725 Variable* temp =
5732 scope_->NewTemporary(ast_value_factory()->empty_string()); 5726 scope_->NewTemporary(ast_value_factory()->empty_string());
5733 VariableProxy* obj = factory()->NewVariableProxy(temp); 5727 VariableProxy* obj = factory()->NewVariableProxy(temp);
5734 Assignment* assign_obj = factory()->NewAssignment( 5728 Assignment* assign_obj = factory()->NewAssignment(
5735 Token::ASSIGN, obj, function->AsProperty()->obj(), 5729 Token::ASSIGN, obj, function->AsProperty()->obj(),
5736 RelocInfo::kNoPosition); 5730 RelocInfo::kNoPosition);
5737 function = factory()->NewProperty( 5731 function = factory()->NewProperty(
(...skipping 16 matching lines...) Expand all
5754 5748
5755 Expression* Parser::SpreadCallNew(Expression* function, 5749 Expression* Parser::SpreadCallNew(Expression* function,
5756 ZoneList<v8::internal::Expression*>* args, 5750 ZoneList<v8::internal::Expression*>* args,
5757 int pos) { 5751 int pos) {
5758 args->InsertAt(0, function, zone()); 5752 args->InsertAt(0, function, zone());
5759 5753
5760 return factory()->NewCallRuntime( 5754 return factory()->NewCallRuntime(
5761 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5755 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5762 } 5756 }
5763 } } // namespace v8::internal 5757 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/mips64/lithium-codegen-mips64.cc ('k') | src/ppc/full-codegen-ppc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698