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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 return factory->NewVariableProxy(scope->receiver(), pos); | 678 return factory->NewVariableProxy(scope->receiver(), pos); |
679 } | 679 } |
680 | 680 |
681 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, | 681 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, |
682 int pos) { | 682 int pos) { |
683 return factory->NewSuperReference( | 683 return factory->NewSuperReference( |
684 ThisExpression(scope, factory, pos)->AsVariableProxy(), | 684 ThisExpression(scope, factory, pos)->AsVariableProxy(), |
685 pos); | 685 pos); |
686 } | 686 } |
687 | 687 |
688 Expression* ParserTraits::ClassExpression( | |
689 const AstRawString* name, Expression* extends, Expression* constructor, | |
690 ZoneList<ObjectLiteral::Property*>* properties, int start_position, | |
691 int end_position, AstNodeFactory* factory) { | |
692 return factory->NewClassLiteral(name, extends, constructor, properties, | |
693 start_position, end_position); | |
694 } | |
695 | 688 |
696 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, | 689 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, |
697 int pos, int end_pos) { | 690 int pos, int end_pos) { |
698 return parser_->DefaultConstructor(call_super, scope, pos, end_pos); | 691 return parser_->DefaultConstructor(call_super, scope, pos, end_pos); |
699 } | 692 } |
700 | 693 |
701 | 694 |
702 Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, | 695 Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, |
703 Scanner* scanner, | 696 Scanner* scanner, |
704 AstNodeFactory* factory) { | 697 AstNodeFactory* factory) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 const AstRawString* name, Scanner::Location function_name_location, | 763 const AstRawString* name, Scanner::Location function_name_location, |
771 bool name_is_strict_reserved, FunctionKind kind, | 764 bool name_is_strict_reserved, FunctionKind kind, |
772 int function_token_position, FunctionLiteral::FunctionType type, | 765 int function_token_position, FunctionLiteral::FunctionType type, |
773 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 766 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
774 return parser_->ParseFunctionLiteral( | 767 return parser_->ParseFunctionLiteral( |
775 name, function_name_location, name_is_strict_reserved, kind, | 768 name, function_name_location, name_is_strict_reserved, kind, |
776 function_token_position, type, arity_restriction, ok); | 769 function_token_position, type, arity_restriction, ok); |
777 } | 770 } |
778 | 771 |
779 | 772 |
773 ClassLiteral* ParserTraits::ParseClassLiteral( | |
774 const AstRawString* name, Scanner::Location class_name_location, | |
775 bool name_is_strict_reserved, int pos, bool* ok) { | |
776 return parser_->ParseClassLiteral(name, class_name_location, | |
777 name_is_strict_reserved, pos, ok); | |
778 } | |
779 | |
780 | |
780 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) | 781 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) |
781 : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit, | 782 : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit, |
782 info->extension(), NULL, info->zone(), this), | 783 info->extension(), NULL, info->zone(), this), |
783 scanner_(parse_info->unicode_cache), | 784 scanner_(parse_info->unicode_cache), |
784 reusable_preparser_(NULL), | 785 reusable_preparser_(NULL), |
785 original_scope_(NULL), | 786 original_scope_(NULL), |
786 target_stack_(NULL), | 787 target_stack_(NULL), |
787 cached_parse_data_(NULL), | 788 cached_parse_data_(NULL), |
788 info_(info), | 789 info_(info), |
789 has_pending_error_(false), | 790 has_pending_error_(false), |
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1986 // | 1987 // |
1987 // let C = class C { ... }; | 1988 // let C = class C { ... }; |
1988 // | 1989 // |
1989 // so rewrite it as such. | 1990 // so rewrite it as such. |
1990 | 1991 |
1991 Expect(Token::CLASS, CHECK_OK); | 1992 Expect(Token::CLASS, CHECK_OK); |
1992 int pos = position(); | 1993 int pos = position(); |
1993 bool is_strict_reserved = false; | 1994 bool is_strict_reserved = false; |
1994 const AstRawString* name = | 1995 const AstRawString* name = |
1995 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 1996 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
1996 Expression* value = ParseClassLiteral(name, scanner()->location(), | 1997 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), |
1997 is_strict_reserved, pos, CHECK_OK); | 1998 is_strict_reserved, pos, CHECK_OK); |
1998 | 1999 |
1999 VariableProxy* proxy = NewUnresolved(name, LET, Interface::NewValue()); | 2000 VariableProxy* proxy = NewUnresolved(name, LET, Interface::NewValue()); |
2000 Declaration* declaration = | 2001 Declaration* declaration = |
2001 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); | 2002 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); |
2002 Declare(declaration, true, CHECK_OK); | 2003 Declare(declaration, true, CHECK_OK); |
2003 proxy->var()->set_initializer_position(pos); | 2004 proxy->var()->set_initializer_position(pos); |
2004 | 2005 |
2005 Token::Value init_op = Token::INIT_LET; | 2006 Token::Value init_op = Token::INIT_LET; |
2006 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); | 2007 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); |
2007 Statement* assignment_statement = | 2008 Statement* assignment_statement = |
(...skipping 1878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3886 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3887 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
3887 is_generator(), | 3888 is_generator(), |
3888 logger); | 3889 logger); |
3889 if (pre_parse_timer_ != NULL) { | 3890 if (pre_parse_timer_ != NULL) { |
3890 pre_parse_timer_->Stop(); | 3891 pre_parse_timer_->Stop(); |
3891 } | 3892 } |
3892 return result; | 3893 return result; |
3893 } | 3894 } |
3894 | 3895 |
3895 | 3896 |
3897 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, | |
marja
2015/02/10 11:31:49
Is there a reason why ParseClassLiteral is not in
| |
3898 Scanner::Location class_name_location, | |
3899 bool name_is_strict_reserved, int pos, | |
3900 bool* ok) { | |
3901 // All parts of a ClassDeclaration and ClassExpression are strict code. | |
3902 if (name_is_strict_reserved) { | |
3903 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); | |
3904 *ok = false; | |
3905 return NULL; | |
3906 } | |
3907 if (IsEvalOrArguments(name)) { | |
3908 ReportMessageAt(class_name_location, "strict_eval_arguments"); | |
3909 *ok = false; | |
3910 return NULL; | |
3911 } | |
3912 | |
3913 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | |
3914 BlockState block_state(&scope_, block_scope); | |
3915 scope_->SetStrictMode(STRICT); | |
3916 scope_->SetScopeName(name); | |
3917 | |
3918 VariableProxy* proxy = NULL; | |
3919 if (name != NULL) { | |
3920 proxy = NewUnresolved(name, CONST, Interface::NewConst()); | |
3921 Declaration* declaration = | |
3922 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | |
3923 Declare(declaration, true, CHECK_OK); | |
3924 } | |
3925 | |
3926 Expression* extends = NULL; | |
3927 if (Check(Token::EXTENDS)) { | |
3928 block_scope->set_start_position(scanner()->location().end_pos); | |
3929 extends = ParseLeftHandSideExpression(CHECK_OK); | |
3930 } else { | |
3931 block_scope->set_start_position(scanner()->location().end_pos); | |
3932 } | |
3933 | |
3934 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); | |
3935 Expression* constructor = NULL; | |
3936 bool has_seen_constructor = false; | |
3937 | |
3938 Expect(Token::LBRACE, CHECK_OK); | |
3939 while (peek() != Token::RBRACE) { | |
3940 if (Check(Token::SEMICOLON)) continue; | |
3941 if (fni_ != NULL) fni_->Enter(); | |
3942 const bool in_class = true; | |
3943 const bool is_static = false; | |
3944 ObjectLiteral::Property* property = ParsePropertyDefinition( | |
3945 NULL, in_class, is_static, &has_seen_constructor, CHECK_OK); | |
3946 | |
3947 if (has_seen_constructor && constructor == NULL) { | |
3948 constructor = GetPropertyValue(property); | |
3949 } else { | |
3950 properties->Add(property, zone()); | |
3951 } | |
3952 | |
3953 if (fni_ != NULL) { | |
3954 fni_->Infer(); | |
3955 fni_->Leave(); | |
3956 } | |
3957 } | |
3958 | |
3959 Expect(Token::RBRACE, CHECK_OK); | |
3960 int end_pos = scanner()->location().end_pos; | |
3961 | |
3962 if (constructor == NULL) { | |
3963 constructor = | |
3964 DefaultConstructor(extends != NULL, block_scope, pos, end_pos); | |
3965 } | |
3966 | |
3967 block_scope->set_end_position(end_pos); | |
3968 block_scope = block_scope->FinalizeBlockScope(); | |
3969 | |
3970 if (name != NULL) { | |
3971 DCHECK_NOT_NULL(proxy); | |
3972 DCHECK_NOT_NULL(block_scope); | |
3973 proxy->var()->set_initializer_position(end_pos); | |
3974 } | |
3975 | |
3976 return factory()->NewClassLiteral(name, block_scope, proxy, extends, | |
3977 constructor, properties, pos, end_pos); | |
3978 } | |
3979 | |
3980 | |
3896 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 3981 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
3897 // CallRuntime :: | 3982 // CallRuntime :: |
3898 // '%' Identifier Arguments | 3983 // '%' Identifier Arguments |
3899 | 3984 |
3900 int pos = peek_position(); | 3985 int pos = peek_position(); |
3901 Expect(Token::MOD, CHECK_OK); | 3986 Expect(Token::MOD, CHECK_OK); |
3902 // Allow "eval" or "arguments" for backward compatibility. | 3987 // Allow "eval" or "arguments" for backward compatibility. |
3903 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 3988 const AstRawString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
3904 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); | 3989 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); |
3905 | 3990 |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4993 | 5078 |
4994 // We cannot internalize on a background thread; a foreground task will take | 5079 // We cannot internalize on a background thread; a foreground task will take |
4995 // care of calling Parser::Internalize just before compilation. | 5080 // care of calling Parser::Internalize just before compilation. |
4996 | 5081 |
4997 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 5082 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
4998 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 5083 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
4999 log_ = NULL; | 5084 log_ = NULL; |
5000 } | 5085 } |
5001 } | 5086 } |
5002 } } // namespace v8::internal | 5087 } } // namespace v8::internal |
OLD | NEW |