Chromium Code Reviews| 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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 return factory->NewVariableProxy(scope->receiver(), pos); | 687 return factory->NewVariableProxy(scope->receiver(), pos); | 
| 688 } | 688 } | 
| 689 | 689 | 
| 690 Expression* ParserTraits::SuperReference( | 690 Expression* ParserTraits::SuperReference( | 
| 691 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) { | 691 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) { | 
| 692 return factory->NewSuperReference( | 692 return factory->NewSuperReference( | 
| 693 ThisExpression(scope, factory, pos)->AsVariableProxy(), | 693 ThisExpression(scope, factory, pos)->AsVariableProxy(), | 
| 694 pos); | 694 pos); | 
| 695 } | 695 } | 
| 696 | 696 | 
| 697 Expression* ParserTraits::ClassExpression( | |
| 698 const AstRawString* name, Expression* extends, Expression* constructor, | |
| 699 ZoneList<ObjectLiteral::Property*>* properties, int start_position, | |
| 700 int end_position, AstNodeFactory<AstConstructionVisitor>* factory) { | |
| 701 return factory->NewClassLiteral(name, extends, constructor, properties, | |
| 702 start_position, end_position); | |
| 703 } | |
| 704 | |
| 705 | 697 | 
| 706 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, | 698 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, | 
| 707 int pos, int end_pos) { | 699 int pos, int end_pos) { | 
| 708 return parser_->DefaultConstructor(call_super, scope, pos, end_pos); | 700 return parser_->DefaultConstructor(call_super, scope, pos, end_pos); | 
| 709 } | 701 } | 
| 710 | 702 | 
| 711 | 703 | 
| 712 Literal* ParserTraits::ExpressionFromLiteral( | 704 Literal* ParserTraits::ExpressionFromLiteral( | 
| 713 Token::Value token, int pos, | 705 Token::Value token, int pos, | 
| 714 Scanner* scanner, | 706 Scanner* scanner, | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 782 const AstRawString* name, Scanner::Location function_name_location, | 774 const AstRawString* name, Scanner::Location function_name_location, | 
| 783 bool name_is_strict_reserved, FunctionKind kind, | 775 bool name_is_strict_reserved, FunctionKind kind, | 
| 784 int function_token_position, FunctionLiteral::FunctionType type, | 776 int function_token_position, FunctionLiteral::FunctionType type, | 
| 785 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 777 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 
| 786 return parser_->ParseFunctionLiteral( | 778 return parser_->ParseFunctionLiteral( | 
| 787 name, function_name_location, name_is_strict_reserved, kind, | 779 name, function_name_location, name_is_strict_reserved, kind, | 
| 788 function_token_position, type, arity_restriction, ok); | 780 function_token_position, type, arity_restriction, ok); | 
| 789 } | 781 } | 
| 790 | 782 | 
| 791 | 783 | 
| 784 ClassLiteral* ParserTraits::ParseClassLiteral( | |
| 785 const AstRawString* name, Scanner::Location class_name_location, | |
| 786 bool name_is_strict_reserved, int pos, bool* ok) { | |
| 787 return parser_->ParseClassLiteral(name, class_name_location, | |
| 788 name_is_strict_reserved, pos, ok); | |
| 789 } | |
| 790 | |
| 791 | |
| 792 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) | 792 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) | 
| 793 : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit, | 793 : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit, | 
| 794 info->extension(), NULL, info->zone(), this), | 794 info->extension(), NULL, info->zone(), this), | 
| 795 scanner_(parse_info->unicode_cache), | 795 scanner_(parse_info->unicode_cache), | 
| 796 reusable_preparser_(NULL), | 796 reusable_preparser_(NULL), | 
| 797 original_scope_(NULL), | 797 original_scope_(NULL), | 
| 798 target_stack_(NULL), | 798 target_stack_(NULL), | 
| 799 cached_parse_data_(NULL), | 799 cached_parse_data_(NULL), | 
| 800 info_(info), | 800 info_(info), | 
| 801 has_pending_error_(false), | 801 has_pending_error_(false), | 
| (...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2004 // | 2004 // | 
| 2005 // let C = class C { ... }; | 2005 // let C = class C { ... }; | 
| 2006 // | 2006 // | 
| 2007 // so rewrite it as such. | 2007 // so rewrite it as such. | 
| 2008 | 2008 | 
| 2009 Expect(Token::CLASS, CHECK_OK); | 2009 Expect(Token::CLASS, CHECK_OK); | 
| 2010 int pos = position(); | 2010 int pos = position(); | 
| 2011 bool is_strict_reserved = false; | 2011 bool is_strict_reserved = false; | 
| 2012 const AstRawString* name = | 2012 const AstRawString* name = | 
| 2013 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 2013 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 
| 2014 Expression* value = ParseClassLiteral(name, scanner()->location(), | 2014 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), | 
| 2015 is_strict_reserved, pos, CHECK_OK); | 2015 is_strict_reserved, pos, CHECK_OK); | 
| 2016 | 2016 | 
| 2017 VariableProxy* proxy = NewUnresolved(name, LET, Interface::NewValue()); | 2017 VariableProxy* proxy = NewUnresolved(name, LET, Interface::NewValue()); | 
| 2018 Declaration* declaration = | 2018 Declaration* declaration = | 
| 2019 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); | 2019 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); | 
| 2020 Declare(declaration, true, CHECK_OK); | 2020 Declare(declaration, true, CHECK_OK); | 
| 2021 proxy->var()->set_initializer_position(pos); | 2021 proxy->var()->set_initializer_position(pos); | 
| 2022 | 2022 | 
| 2023 Token::Value init_op = Token::INIT_LET; | 2023 Token::Value init_op = Token::INIT_LET; | 
| 2024 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); | 2024 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); | 
| 2025 Statement* assignment_statement = | 2025 Statement* assignment_statement = | 
| (...skipping 1886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3912 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3912 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 
| 3913 is_generator(), | 3913 is_generator(), | 
| 3914 logger); | 3914 logger); | 
| 3915 if (pre_parse_timer_ != NULL) { | 3915 if (pre_parse_timer_ != NULL) { | 
| 3916 pre_parse_timer_->Stop(); | 3916 pre_parse_timer_->Stop(); | 
| 3917 } | 3917 } | 
| 3918 return result; | 3918 return result; | 
| 3919 } | 3919 } | 
| 3920 | 3920 | 
| 3921 | 3921 | 
| 3922 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, | |
| 
 
arv (Not doing code reviews)
2014/11/12 23:15:41
I had to split the code from ParserBase into Parse
 
 | |
| 3923 Scanner::Location class_name_location, | |
| 3924 bool name_is_strict_reserved, int pos, | |
| 3925 bool* ok) { | |
| 3926 // All parts of a ClassDeclaration and ClassExpression are strict code. | |
| 3927 if (name_is_strict_reserved) { | |
| 3928 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); | |
| 3929 *ok = false; | |
| 3930 return NULL; | |
| 3931 } | |
| 3932 if (this->IsEvalOrArguments(name)) { | |
| 
 
adamk
2014/11/13 01:45:43
I don't think you need these explicit |this| refer
 
arv (Not doing code reviews)
2014/11/13 20:47:50
Done.
 
 | |
| 3933 ReportMessageAt(class_name_location, "strict_eval_arguments"); | |
| 3934 *ok = false; | |
| 3935 return NULL; | |
| 3936 } | |
| 3937 | |
| 3938 Scope* block_scope = this->NewScope(scope_, BLOCK_SCOPE); | |
| 3939 BlockState block_state(&scope_, block_scope); | |
| 3940 scope_->SetStrictMode(STRICT); | |
| 3941 scope_->SetScopeName(name); | |
| 3942 | |
| 3943 VariableProxy* proxy = NULL; | |
| 3944 if (name != NULL) { | |
| 3945 proxy = NewUnresolved(name, CONST, Interface::NewConst()); | |
| 3946 Declaration* declaration = | |
| 3947 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | |
| 3948 Declare(declaration, true, CHECK_OK); | |
| 3949 } | |
| 3950 | |
| 3951 bool has_extends = false; | |
| 3952 Expression* extends = NULL; | |
| 3953 if (Check(Token::EXTENDS)) { | |
| 3954 block_scope->set_start_position(scanner()->location().end_pos); | |
| 3955 extends = this->ParseLeftHandSideExpression(CHECK_OK); | |
| 3956 has_extends = true; | |
| 3957 } else { | |
| 3958 block_scope->set_start_position(scanner()->location().end_pos); | |
| 3959 } | |
| 3960 | |
| 3961 ZoneList<ObjectLiteral::Property*>* properties = | |
| 3962 this->NewPropertyList(4, zone()); | |
| 3963 Expression* constructor = NULL; | |
| 3964 bool has_seen_constructor = false; | |
| 3965 | |
| 3966 Expect(Token::LBRACE, CHECK_OK); | |
| 3967 while (peek() != Token::RBRACE) { | |
| 3968 if (Check(Token::SEMICOLON)) continue; | |
| 3969 if (fni_ != NULL) fni_->Enter(); | |
| 3970 const bool in_class = true; | |
| 3971 const bool is_static = false; | |
| 3972 bool old_has_seen_constructor = has_seen_constructor; | |
| 3973 ObjectLiteral::Property* property = this->ParsePropertyDefinition( | |
| 3974 NULL, in_class, is_static, &has_seen_constructor, CHECK_OK); | |
| 3975 | |
| 3976 if (has_seen_constructor != old_has_seen_constructor) { | |
| 
 
Dmitry Lomov (no reviews)
2014/11/13 11:17:37
Nit: replace this condition with 'constructor == N
 
arv (Not doing code reviews)
2014/11/13 20:47:49
Done.
 
 | |
| 3977 constructor = this->GetPropertyValue(property); | |
| 3978 } else { | |
| 3979 properties->Add(property, zone()); | |
| 3980 } | |
| 3981 | |
| 3982 if (fni_ != NULL) { | |
| 3983 fni_->Infer(); | |
| 3984 fni_->Leave(); | |
| 3985 } | |
| 3986 } | |
| 3987 | |
| 3988 Expect(Token::RBRACE, CHECK_OK); | |
| 3989 int end_pos = scanner()->location().end_pos; | |
| 3990 | |
| 3991 if (!has_seen_constructor) { | |
| 
 
Dmitry Lomov (no reviews)
2014/11/13 11:17:37
Nit: replace this condition with 'constructor == N
 
arv (Not doing code reviews)
2014/11/13 20:47:50
Done.
 
 | |
| 3992 constructor = | |
| 3993 this->DefaultConstructor(has_extends, block_scope, pos, end_pos); | |
| 3994 } | |
| 3995 | |
| 3996 block_scope->set_end_position(end_pos); | |
| 3997 block_scope = block_scope->FinalizeBlockScope(); | |
| 3998 | |
| 3999 if (name != NULL) { | |
| 4000 DCHECK_NOT_NULL(proxy); | |
| 4001 DCHECK_NOT_NULL(block_scope); | |
| 4002 proxy->var()->set_initializer_position(end_pos); | |
| 4003 } | |
| 4004 | |
| 4005 return factory()->NewClassLiteral(name, block_scope, proxy, extends, | |
| 4006 constructor, properties, pos, end_pos); | |
| 4007 } | |
| 4008 | |
| 4009 | |
| 3922 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 4010 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 
| 3923 // CallRuntime :: | 4011 // CallRuntime :: | 
| 3924 // '%' Identifier Arguments | 4012 // '%' Identifier Arguments | 
| 3925 | 4013 | 
| 3926 int pos = peek_position(); | 4014 int pos = peek_position(); | 
| 3927 Expect(Token::MOD, CHECK_OK); | 4015 Expect(Token::MOD, CHECK_OK); | 
| 3928 // Allow "eval" or "arguments" for backward compatibility. | 4016 // Allow "eval" or "arguments" for backward compatibility. | 
| 3929 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 4017 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 
| 3930 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); | 4018 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); | 
| 3931 | 4019 | 
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5019 | 5107 | 
| 5020 // We cannot internalize on a background thread; a foreground task will take | 5108 // We cannot internalize on a background thread; a foreground task will take | 
| 5021 // care of calling Parser::Internalize just before compilation. | 5109 // care of calling Parser::Internalize just before compilation. | 
| 5022 | 5110 | 
| 5023 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 5111 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 
| 5024 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 5112 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 
| 5025 log_ = NULL; | 5113 log_ = NULL; | 
| 5026 } | 5114 } | 
| 5027 } | 5115 } | 
| 5028 } } // namespace v8::internal | 5116 } } // namespace v8::internal | 
| OLD | NEW |