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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 return factory->NewVariableProxy(scope->receiver(), pos); | 684 return factory->NewVariableProxy(scope->receiver(), pos); |
685 } | 685 } |
686 | 686 |
687 Expression* ParserTraits::SuperReference( | 687 Expression* ParserTraits::SuperReference( |
688 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) { | 688 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) { |
689 return factory->NewSuperReference( | 689 return factory->NewSuperReference( |
690 ThisExpression(scope, factory, pos)->AsVariableProxy(), | 690 ThisExpression(scope, factory, pos)->AsVariableProxy(), |
691 pos); | 691 pos); |
692 } | 692 } |
693 | 693 |
694 Expression* ParserTraits::ClassExpression( | |
695 const AstRawString* name, Expression* extends, Expression* constructor, | |
696 ZoneList<ObjectLiteral::Property*>* properties, int start_position, | |
697 int end_position, AstNodeFactory<AstConstructionVisitor>* factory) { | |
698 return factory->NewClassLiteral(name, extends, constructor, properties, | |
699 start_position, end_position); | |
700 } | |
701 | |
702 | 694 |
703 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, | 695 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, |
704 int pos, int end_pos) { | 696 int pos, int end_pos) { |
705 return parser_->DefaultConstructor(call_super, scope, pos, end_pos); | 697 return parser_->DefaultConstructor(call_super, scope, pos, end_pos); |
706 } | 698 } |
707 | 699 |
708 | 700 |
709 Literal* ParserTraits::ExpressionFromLiteral( | 701 Literal* ParserTraits::ExpressionFromLiteral( |
710 Token::Value token, int pos, | 702 Token::Value token, int pos, |
711 Scanner* scanner, | 703 Scanner* scanner, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 const AstRawString* name, Scanner::Location function_name_location, | 771 const AstRawString* name, Scanner::Location function_name_location, |
780 bool name_is_strict_reserved, FunctionKind kind, | 772 bool name_is_strict_reserved, FunctionKind kind, |
781 int function_token_position, FunctionLiteral::FunctionType type, | 773 int function_token_position, FunctionLiteral::FunctionType type, |
782 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 774 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
783 return parser_->ParseFunctionLiteral( | 775 return parser_->ParseFunctionLiteral( |
784 name, function_name_location, name_is_strict_reserved, kind, | 776 name, function_name_location, name_is_strict_reserved, kind, |
785 function_token_position, type, arity_restriction, ok); | 777 function_token_position, type, arity_restriction, ok); |
786 } | 778 } |
787 | 779 |
788 | 780 |
781 ClassLiteral* ParserTraits::ParseClassLiteral( | |
782 const AstRawString* name, Scanner::Location class_name_location, | |
783 bool name_is_strict_reserved, int pos, bool* ok) { | |
784 return parser_->ParseClassLiteral(name, class_name_location, | |
785 name_is_strict_reserved, pos, ok); | |
786 } | |
787 | |
788 | |
789 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) | 789 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) |
790 : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit, | 790 : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit, |
791 info->extension(), NULL, info->zone(), this), | 791 info->extension(), NULL, info->zone(), this), |
792 scanner_(parse_info->unicode_cache), | 792 scanner_(parse_info->unicode_cache), |
793 reusable_preparser_(NULL), | 793 reusable_preparser_(NULL), |
794 original_scope_(NULL), | 794 original_scope_(NULL), |
795 target_stack_(NULL), | 795 target_stack_(NULL), |
796 cached_parse_data_(NULL), | 796 cached_parse_data_(NULL), |
797 info_(info), | 797 info_(info), |
798 has_pending_error_(false), | 798 has_pending_error_(false), |
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1998 // | 1998 // |
1999 // let C = class C { ... }; | 1999 // let C = class C { ... }; |
2000 // | 2000 // |
2001 // so rewrite it as such. | 2001 // so rewrite it as such. |
2002 | 2002 |
2003 Expect(Token::CLASS, CHECK_OK); | 2003 Expect(Token::CLASS, CHECK_OK); |
2004 int pos = position(); | 2004 int pos = position(); |
2005 bool is_strict_reserved = false; | 2005 bool is_strict_reserved = false; |
2006 const AstRawString* name = | 2006 const AstRawString* name = |
2007 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 2007 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
2008 Expression* value = ParseClassLiteral(name, scanner()->location(), | 2008 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), |
2009 is_strict_reserved, pos, CHECK_OK); | 2009 is_strict_reserved, pos, CHECK_OK); |
2010 | 2010 |
2011 VariableProxy* proxy = NewUnresolved(name, LET, Interface::NewValue()); | 2011 VariableProxy* proxy = NewUnresolved(name, LET, Interface::NewValue()); |
2012 Declaration* declaration = | 2012 Declaration* declaration = |
2013 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); | 2013 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); |
2014 Declare(declaration, true, CHECK_OK); | 2014 Declare(declaration, true, CHECK_OK); |
2015 proxy->var()->set_initializer_position(pos); | 2015 proxy->var()->set_initializer_position(pos); |
2016 | 2016 |
2017 Token::Value init_op = Token::INIT_LET; | 2017 Token::Value init_op = Token::INIT_LET; |
2018 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); | 2018 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); |
2019 Statement* assignment_statement = | 2019 Statement* assignment_statement = |
(...skipping 1883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3903 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3903 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
3904 is_generator(), | 3904 is_generator(), |
3905 logger); | 3905 logger); |
3906 if (pre_parse_timer_ != NULL) { | 3906 if (pre_parse_timer_ != NULL) { |
3907 pre_parse_timer_->Stop(); | 3907 pre_parse_timer_->Stop(); |
3908 } | 3908 } |
3909 return result; | 3909 return result; |
3910 } | 3910 } |
3911 | 3911 |
3912 | 3912 |
3913 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, | |
3914 Scanner::Location class_name_location, | |
3915 bool name_is_strict_reserved, int pos, | |
3916 bool* ok) { | |
3917 // All parts of a ClassDeclaration and ClassExpression are strict code. | |
3918 if (name_is_strict_reserved) { | |
3919 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); | |
3920 *ok = false; | |
3921 return NULL; | |
3922 } | |
3923 if (IsEvalOrArguments(name)) { | |
3924 ReportMessageAt(class_name_location, "strict_eval_arguments"); | |
3925 *ok = false; | |
3926 return NULL; | |
3927 } | |
3928 | |
3929 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | |
3930 BlockState block_state(&scope_, block_scope); | |
3931 scope_->SetStrictMode(STRICT); | |
3932 scope_->SetScopeName(name); | |
3933 | |
3934 VariableProxy* proxy = NULL; | |
3935 if (name != NULL) { | |
3936 proxy = NewUnresolved(name, CONST, Interface::NewConst()); | |
3937 Declaration* declaration = | |
3938 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | |
3939 Declare(declaration, true, CHECK_OK); | |
3940 } | |
3941 | |
3942 Expression* extends = NULL; | |
3943 if (Check(Token::EXTENDS)) { | |
3944 block_scope->set_start_position(scanner()->location().end_pos); | |
3945 extends = ParseLeftHandSideExpression(CHECK_OK); | |
3946 } else { | |
3947 block_scope->set_start_position(scanner()->location().end_pos); | |
3948 } | |
3949 | |
3950 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); | |
3951 Expression* constructor = NULL; | |
3952 bool has_seen_constructor = false; | |
3953 | |
3954 Expect(Token::LBRACE, CHECK_OK); | |
3955 while (peek() != Token::RBRACE) { | |
3956 if (Check(Token::SEMICOLON)) continue; | |
3957 if (fni_ != NULL) fni_->Enter(); | |
3958 const bool in_class = true; | |
3959 const bool is_static = false; | |
3960 ObjectLiteral::Property* property = ParsePropertyDefinition( | |
Dmitry Lomov (no reviews)
2014/11/13 21:10:37
Nit: move has_seen_constructor variable here (it i
arv (Not doing code reviews)
2014/11/13 21:56:29
It needs to be done outside the loop since ParsePr
| |
3961 NULL, in_class, is_static, &has_seen_constructor, CHECK_OK); | |
3962 | |
3963 if (has_seen_constructor && constructor == NULL) { | |
3964 constructor = GetPropertyValue(property); | |
3965 } else { | |
3966 properties->Add(property, zone()); | |
3967 } | |
3968 | |
3969 if (fni_ != NULL) { | |
3970 fni_->Infer(); | |
3971 fni_->Leave(); | |
3972 } | |
3973 } | |
3974 | |
3975 Expect(Token::RBRACE, CHECK_OK); | |
3976 int end_pos = scanner()->location().end_pos; | |
3977 | |
3978 if (constructor == NULL) { | |
3979 constructor = | |
3980 this->DefaultConstructor(extends != NULL, block_scope, pos, end_pos); | |
Dmitry Lomov (no reviews)
2014/11/13 21:10:37
Nit: remove 'this->'
arv (Not doing code reviews)
2014/11/13 21:56:29
Done.
| |
3981 } | |
3982 | |
3983 block_scope->set_end_position(end_pos); | |
3984 block_scope = block_scope->FinalizeBlockScope(); | |
3985 | |
3986 if (name != NULL) { | |
3987 DCHECK_NOT_NULL(proxy); | |
3988 DCHECK_NOT_NULL(block_scope); | |
3989 proxy->var()->set_initializer_position(end_pos); | |
3990 } | |
3991 | |
3992 return factory()->NewClassLiteral(name, block_scope, proxy, extends, | |
3993 constructor, properties, pos, end_pos); | |
3994 } | |
3995 | |
3996 | |
3913 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 3997 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
3914 // CallRuntime :: | 3998 // CallRuntime :: |
3915 // '%' Identifier Arguments | 3999 // '%' Identifier Arguments |
3916 | 4000 |
3917 int pos = peek_position(); | 4001 int pos = peek_position(); |
3918 Expect(Token::MOD, CHECK_OK); | 4002 Expect(Token::MOD, CHECK_OK); |
3919 // Allow "eval" or "arguments" for backward compatibility. | 4003 // Allow "eval" or "arguments" for backward compatibility. |
3920 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 4004 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
3921 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); | 4005 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); |
3922 | 4006 |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5010 | 5094 |
5011 // We cannot internalize on a background thread; a foreground task will take | 5095 // We cannot internalize on a background thread; a foreground task will take |
5012 // care of calling Parser::Internalize just before compilation. | 5096 // care of calling Parser::Internalize just before compilation. |
5013 | 5097 |
5014 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 5098 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
5015 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 5099 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
5016 log_ = NULL; | 5100 log_ = NULL; |
5017 } | 5101 } |
5018 } | 5102 } |
5019 } } // namespace v8::internal | 5103 } } // namespace v8::internal |
OLD | NEW |