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

Side by Side Diff: src/parser.cc

Issue 883823002: Implement proper scoping for "this" in arrow functions Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: mjsunit/debug-scopes: Skip "this" the same as "arguments" Created 5 years, 10 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
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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 } 668 }
669 669
670 670
671 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { 671 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) {
672 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); 672 return parser_->scanner()->NextSymbol(parser_->ast_value_factory());
673 } 673 }
674 674
675 675
676 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, 676 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory,
677 int pos) { 677 int pos) {
678 return factory->NewVariableProxy(scope->receiver(), pos); 678 return scope->NewUnresolved(factory,
679 ast_value_factory()->this_string(),
wingo 2015/02/06 17:31:19 here probably we will have to pass in Variable::TH
aperez 2015/02/09 16:08:14 Acknowledged.
680 Interface::NewValue(),
681 RelocInfo::kNoPosition);
679 } 682 }
680 683
681 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, 684 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory,
682 int pos) { 685 int pos) {
683 return factory->NewSuperReference( 686 return factory->NewSuperReference(
684 ThisExpression(scope, factory, pos)->AsVariableProxy(), 687 ThisExpression(scope, factory, pos)->AsVariableProxy(),
685 pos); 688 pos);
686 } 689 }
687 690
688 691
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 if (FLAG_print_interface_details) 725 if (FLAG_print_interface_details)
723 PrintF("# Variable %.*s ", name->length(), name->raw_data()); 726 PrintF("# Variable %.*s ", name->length(), name->raw_data());
724 #endif 727 #endif
725 Interface* interface = Interface::NewUnknown(parser_->zone()); 728 Interface* interface = Interface::NewUnknown(parser_->zone());
726 729
727 // Arrow function parameters are parsed as an expression. When 730 // Arrow function parameters are parsed as an expression. When
728 // parsing lazily, it is enough to create a VariableProxy in order 731 // parsing lazily, it is enough to create a VariableProxy in order
729 // for Traits::DeclareArrowParametersFromExpression() to be able to 732 // for Traits::DeclareArrowParametersFromExpression() to be able to
730 // pick the names of the parameters. 733 // pick the names of the parameters.
731 return parser_->parsing_lazy_arrow_parameters_ 734 return parser_->parsing_lazy_arrow_parameters_
732 ? factory->NewVariableProxy(name, false, interface, pos) 735 ? factory->NewVariableProxy(name, interface, pos)
wingo 2015/02/06 17:31:19 instead of removing false, replace with Variable::
aperez 2015/02/09 16:08:14 Acknowledged.
733 : scope->NewUnresolved(factory, name, interface, pos); 736 : scope->NewUnresolved(factory, name, interface, pos);
734 } 737 }
735 738
736 739
737 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, 740 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner,
738 AstNodeFactory* factory) { 741 AstNodeFactory* factory) {
739 const AstRawString* symbol = GetSymbol(scanner); 742 const AstRawString* symbol = GetSymbol(scanner);
740 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); 743 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol);
741 return factory->NewStringLiteral(symbol, pos); 744 return factory->NewStringLiteral(symbol, pos);
742 } 745 }
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 // semantic issue as long as we keep the source order, but it may be 1848 // semantic issue as long as we keep the source order, but it may be
1846 // a performance issue since it may lead to repeated 1849 // a performance issue since it may lead to repeated
1847 // RuntimeHidden_DeclareLookupSlot calls. 1850 // RuntimeHidden_DeclareLookupSlot calls.
1848 declaration_scope->AddDeclaration(declaration); 1851 declaration_scope->AddDeclaration(declaration);
1849 1852
1850 if (mode == CONST_LEGACY && declaration_scope->is_script_scope()) { 1853 if (mode == CONST_LEGACY && declaration_scope->is_script_scope()) {
1851 // For global const variables we bind the proxy to a variable. 1854 // For global const variables we bind the proxy to a variable.
1852 DCHECK(resolve); // should be set by all callers 1855 DCHECK(resolve); // should be set by all callers
1853 Variable::Kind kind = Variable::NORMAL; 1856 Variable::Kind kind = Variable::NORMAL;
1854 var = new (zone()) 1857 var = new (zone())
1855 Variable(declaration_scope, name, mode, true, kind, 1858 Variable(declaration_scope, name, mode, kind,
1856 kNeedsInitialization, kNotAssigned, proxy->interface()); 1859 kNeedsInitialization, kNotAssigned, proxy->interface());
1857 } else if (declaration_scope->is_eval_scope() && 1860 } else if (declaration_scope->is_eval_scope() &&
1858 declaration_scope->strict_mode() == SLOPPY) { 1861 declaration_scope->strict_mode() == SLOPPY) {
1859 // For variable declarations in a sloppy eval scope the proxy is bound 1862 // For variable declarations in a sloppy eval scope the proxy is bound
1860 // to a lookup variable to force a dynamic declaration using the 1863 // to a lookup variable to force a dynamic declaration using the
1861 // DeclareLookupSlot runtime function. 1864 // DeclareLookupSlot runtime function.
1862 Variable::Kind kind = Variable::NORMAL; 1865 Variable::Kind kind = Variable::NORMAL;
1863 // TODO(sigurds) figure out if kNotAssigned is OK here 1866 // TODO(sigurds) figure out if kNotAssigned is OK here
1864 var = new (zone()) Variable(declaration_scope, name, mode, true, kind, 1867 var = new (zone()) Variable(declaration_scope, name, mode, kind,
1865 declaration->initialization(), kNotAssigned, 1868 declaration->initialization(), kNotAssigned,
1866 proxy->interface()); 1869 proxy->interface());
1867 var->AllocateTo(Variable::LOOKUP, -1); 1870 var->AllocateTo(Variable::LOOKUP, -1);
1868 resolve = true; 1871 resolve = true;
1869 } 1872 }
1870 1873
1871 // If requested and we have a local variable, bind the proxy to the variable 1874 // If requested and we have a local variable, bind the proxy to the variable
1872 // at parse-time. This is used for functions (and consts) declared inside 1875 // at parse-time. This is used for functions (and consts) declared inside
1873 // statements: the corresponding function (or const) variable must be in the 1876 // statements: the corresponding function (or const) variable must be in the
1874 // function scope and not a statement-local scope, e.g. as provided with a 1877 // function scope and not a statement-local scope, e.g. as provided with a
(...skipping 1866 matching lines...) Expand 10 before | Expand all | Expand 10 after
3741 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY; 3744 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY;
3742 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { 3745 if (function_type == FunctionLiteral::NAMED_EXPRESSION) {
3743 if (allow_harmony_scoping() && strict_mode() == STRICT) { 3746 if (allow_harmony_scoping() && strict_mode() == STRICT) {
3744 fvar_init_op = Token::INIT_CONST; 3747 fvar_init_op = Token::INIT_CONST;
3745 } 3748 }
3746 VariableMode fvar_mode = 3749 VariableMode fvar_mode =
3747 allow_harmony_scoping() && strict_mode() == STRICT 3750 allow_harmony_scoping() && strict_mode() == STRICT
3748 ? CONST : CONST_LEGACY; 3751 ? CONST : CONST_LEGACY;
3749 DCHECK(function_name != NULL); 3752 DCHECK(function_name != NULL);
3750 fvar = new (zone()) 3753 fvar = new (zone())
3751 Variable(scope_, function_name, fvar_mode, true /* is valid LHS */, 3754 Variable(scope_, function_name, fvar_mode, Variable::NORMAL,
3752 Variable::NORMAL, kCreatedInitialized, kNotAssigned, 3755 kCreatedInitialized, kNotAssigned, Interface::NewConst());
3753 Interface::NewConst());
3754 VariableProxy* proxy = factory()->NewVariableProxy(fvar); 3756 VariableProxy* proxy = factory()->NewVariableProxy(fvar);
3755 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( 3757 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration(
3756 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); 3758 proxy, fvar_mode, scope_, RelocInfo::kNoPosition);
3757 scope_->DeclareFunctionVar(fvar_declaration); 3759 scope_->DeclareFunctionVar(fvar_declaration);
3758 } 3760 }
3759 3761
3760 // Determine if the function can be parsed lazily. Lazy parsing is different 3762 // Determine if the function can be parsed lazily. Lazy parsing is different
3761 // from lazy compilation; we need to parse more eagerly than we compile. 3763 // from lazy compilation; we need to parse more eagerly than we compile.
3762 3764
3763 // We can only parse lazily if we also compile lazily. The heuristics for 3765 // We can only parse lazily if we also compile lazily. The heuristics for
(...skipping 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after
5383 } else { 5385 } else {
5384 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5386 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5385 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5387 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5386 raw_string->length()); 5388 raw_string->length());
5387 } 5389 }
5388 } 5390 }
5389 5391
5390 return running_hash; 5392 return running_hash;
5391 } 5393 }
5392 } } // namespace v8::internal 5394 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698