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

Side by Side Diff: src/parser.cc

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