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

Side by Side Diff: src/parser.cc

Issue 1258883002: Version 4.5.103.14 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@4.5
Patch Set: Created 5 years, 4 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/parser.h ('k') | src/preparser.h » ('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/ast-literal-reindexer.h" 9 #include "src/ast-literal-reindexer.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } else { 327 } else {
328 DCHECK(info->cached_data() != NULL); 328 DCHECK(info->cached_data() != NULL);
329 if (compile_options_ == ScriptCompiler::kConsumeParserCache) { 329 if (compile_options_ == ScriptCompiler::kConsumeParserCache) {
330 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); 330 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data());
331 } 331 }
332 } 332 }
333 } 333 }
334 334
335 335
336 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, 336 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope,
337 int pos, int end_pos) { 337 int pos, int end_pos,
338 LanguageMode language_mode) {
338 int materialized_literal_count = -1; 339 int materialized_literal_count = -1;
339 int expected_property_count = -1; 340 int expected_property_count = -1;
340 int parameter_count = 0; 341 int parameter_count = 0;
341 const AstRawString* name = ast_value_factory()->empty_string(); 342 const AstRawString* name = ast_value_factory()->empty_string();
342 343
343 344
344 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor 345 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor
345 : FunctionKind::kDefaultBaseConstructor; 346 : FunctionKind::kDefaultBaseConstructor;
346 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind); 347 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind);
347 function_scope->SetLanguageMode( 348 function_scope->SetLanguageMode(
348 static_cast<LanguageMode>(scope->language_mode() | STRICT_BIT)); 349 static_cast<LanguageMode>(language_mode | STRICT_BIT));
349 // Set start and end position to the same value 350 // Set start and end position to the same value
350 function_scope->set_start_position(pos); 351 function_scope->set_start_position(pos);
351 function_scope->set_end_position(pos); 352 function_scope->set_end_position(pos);
352 ZoneList<Statement*>* body = NULL; 353 ZoneList<Statement*>* body = NULL;
353 354
354 { 355 {
355 AstNodeFactory function_factory(ast_value_factory()); 356 AstNodeFactory function_factory(ast_value_factory());
356 FunctionState function_state(&function_state_, &scope_, function_scope, 357 FunctionState function_state(&function_state_, &scope_, function_scope,
357 kind, &function_factory); 358 kind, &function_factory);
358 359
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 AstNodeFactory* factory, 789 AstNodeFactory* factory,
789 int pos) { 790 int pos) {
790 static const int kNewTargetStringLength = 10; 791 static const int kNewTargetStringLength = 10;
791 return scope->NewUnresolved( 792 return scope->NewUnresolved(
792 factory, parser_->ast_value_factory()->new_target_string(), 793 factory, parser_->ast_value_factory()->new_target_string(),
793 Variable::NORMAL, pos, pos + kNewTargetStringLength); 794 Variable::NORMAL, pos, pos + kNewTargetStringLength);
794 } 795 }
795 796
796 797
797 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, 798 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope,
798 int pos, int end_pos) { 799 int pos, int end_pos,
799 return parser_->DefaultConstructor(call_super, scope, pos, end_pos); 800 LanguageMode mode) {
801 return parser_->DefaultConstructor(call_super, scope, pos, end_pos, mode);
800 } 802 }
801 803
802 804
803 Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, 805 Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos,
804 Scanner* scanner, 806 Scanner* scanner,
805 AstNodeFactory* factory) { 807 AstNodeFactory* factory) {
806 switch (token) { 808 switch (token) {
807 case Token::NULL_LITERAL: 809 case Token::NULL_LITERAL:
808 return factory->NewNullLiteral(pos); 810 return factory->NewNullLiteral(pos);
809 case Token::TRUE_LITERAL: 811 case Token::TRUE_LITERAL:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 868
867 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { 869 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) {
868 return parser_->ParseV8Intrinsic(ok); 870 return parser_->ParseV8Intrinsic(ok);
869 } 871 }
870 872
871 873
872 FunctionLiteral* ParserTraits::ParseFunctionLiteral( 874 FunctionLiteral* ParserTraits::ParseFunctionLiteral(
873 const AstRawString* name, Scanner::Location function_name_location, 875 const AstRawString* name, Scanner::Location function_name_location,
874 bool name_is_strict_reserved, FunctionKind kind, 876 bool name_is_strict_reserved, FunctionKind kind,
875 int function_token_position, FunctionLiteral::FunctionType type, 877 int function_token_position, FunctionLiteral::FunctionType type,
876 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { 878 FunctionLiteral::ArityRestriction arity_restriction,
879 LanguageMode language_mode, bool* ok) {
877 return parser_->ParseFunctionLiteral( 880 return parser_->ParseFunctionLiteral(
878 name, function_name_location, name_is_strict_reserved, kind, 881 name, function_name_location, name_is_strict_reserved, kind,
879 function_token_position, type, arity_restriction, ok); 882 function_token_position, type, arity_restriction, language_mode, ok);
880 } 883 }
881 884
882 885
883 ClassLiteral* ParserTraits::ParseClassLiteral( 886 ClassLiteral* ParserTraits::ParseClassLiteral(
884 const AstRawString* name, Scanner::Location class_name_location, 887 const AstRawString* name, Scanner::Location class_name_location,
885 bool name_is_strict_reserved, int pos, bool* ok) { 888 bool name_is_strict_reserved, int pos, bool* ok) {
886 return parser_->ParseClassLiteral(name, class_name_location, 889 return parser_->ParseClassLiteral(name, class_name_location,
887 name_is_strict_reserved, pos, ok); 890 name_is_strict_reserved, pos, ok);
888 } 891 }
889 892
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 scope = Scope::DeserializeScopeChain(isolate, zone(), 1164 scope = Scope::DeserializeScopeChain(isolate, zone(),
1162 info->closure()->context(), scope); 1165 info->closure()->context(), scope);
1163 } 1166 }
1164 original_scope_ = scope; 1167 original_scope_ = scope;
1165 AstNodeFactory function_factory(ast_value_factory()); 1168 AstNodeFactory function_factory(ast_value_factory());
1166 FunctionState function_state(&function_state_, &scope_, scope, 1169 FunctionState function_state(&function_state_, &scope_, scope,
1167 shared_info->kind(), &function_factory); 1170 shared_info->kind(), &function_factory);
1168 DCHECK(is_sloppy(scope->language_mode()) || 1171 DCHECK(is_sloppy(scope->language_mode()) ||
1169 is_strict(info->language_mode())); 1172 is_strict(info->language_mode()));
1170 DCHECK(info->language_mode() == shared_info->language_mode()); 1173 DCHECK(info->language_mode() == shared_info->language_mode());
1171 scope->SetLanguageMode(shared_info->language_mode());
1172 FunctionLiteral::FunctionType function_type = shared_info->is_expression() 1174 FunctionLiteral::FunctionType function_type = shared_info->is_expression()
1173 ? (shared_info->is_anonymous() 1175 ? (shared_info->is_anonymous()
1174 ? FunctionLiteral::ANONYMOUS_EXPRESSION 1176 ? FunctionLiteral::ANONYMOUS_EXPRESSION
1175 : FunctionLiteral::NAMED_EXPRESSION) 1177 : FunctionLiteral::NAMED_EXPRESSION)
1176 : FunctionLiteral::DECLARATION; 1178 : FunctionLiteral::DECLARATION;
1177 bool ok = true; 1179 bool ok = true;
1178 1180
1179 if (shared_info->is_arrow()) { 1181 if (shared_info->is_arrow()) {
1180 Scope* scope = 1182 Scope* scope =
1181 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); 1183 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
1184 scope->SetLanguageMode(shared_info->language_mode());
1182 scope->set_start_position(shared_info->start_position()); 1185 scope->set_start_position(shared_info->start_position());
1183 ExpressionClassifier formals_classifier; 1186 ExpressionClassifier formals_classifier;
1184 ParserFormalParameterParsingState parsing_state(scope); 1187 ParserFormalParameterParsingState parsing_state(scope);
1185 Checkpoint checkpoint(this); 1188 Checkpoint checkpoint(this);
1186 { 1189 {
1187 // Parsing patterns as variable reference expression creates 1190 // Parsing patterns as variable reference expression creates
1188 // NewUnresolved references in current scope. Entrer arrow function 1191 // NewUnresolved references in current scope. Entrer arrow function
1189 // scope for formal parameter parsing. 1192 // scope for formal parameter parsing.
1190 BlockState block_state(&scope_, scope); 1193 BlockState block_state(&scope_, scope);
1191 if (Check(Token::LPAREN)) { 1194 if (Check(Token::LPAREN)) {
(...skipping 25 matching lines...) Expand all
1217 DCHECK(expression->IsFunctionLiteral()); 1220 DCHECK(expression->IsFunctionLiteral());
1218 result = expression->AsFunctionLiteral(); 1221 result = expression->AsFunctionLiteral();
1219 } else { 1222 } else {
1220 ok = false; 1223 ok = false;
1221 } 1224 }
1222 } 1225 }
1223 } 1226 }
1224 } else if (shared_info->is_default_constructor()) { 1227 } else if (shared_info->is_default_constructor()) {
1225 result = DefaultConstructor(IsSubclassConstructor(shared_info->kind()), 1228 result = DefaultConstructor(IsSubclassConstructor(shared_info->kind()),
1226 scope, shared_info->start_position(), 1229 scope, shared_info->start_position(),
1227 shared_info->end_position()); 1230 shared_info->end_position(),
1231 shared_info->language_mode());
1228 } else { 1232 } else {
1229 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), 1233 result = ParseFunctionLiteral(
1230 false, // Strict mode name already checked. 1234 raw_name, Scanner::Location::invalid(), false, shared_info->kind(),
1231 shared_info->kind(), RelocInfo::kNoPosition, 1235 RelocInfo::kNoPosition, function_type, FunctionLiteral::NORMAL_ARITY,
1232 function_type, 1236 shared_info->language_mode(), &ok);
1233 FunctionLiteral::NORMAL_ARITY, &ok);
1234 } 1237 }
1235 // Make sure the results agree. 1238 // Make sure the results agree.
1236 DCHECK(ok == (result != NULL)); 1239 DCHECK(ok == (result != NULL));
1237 } 1240 }
1238 1241
1239 // Make sure the target stack is empty. 1242 // Make sure the target stack is empty.
1240 DCHECK(target_stack_ == NULL); 1243 DCHECK(target_stack_ == NULL);
1241 1244
1242 if (result != NULL) { 1245 if (result != NULL) {
1243 Handle<String> inferred_name(shared_info->inferred_name()); 1246 Handle<String> inferred_name(shared_info->inferred_name());
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
2186 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 2189 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
2187 // GeneratorDeclaration :: 2190 // GeneratorDeclaration ::
2188 // 'function' '*' Identifier '(' FormalParameterListopt ')' 2191 // 'function' '*' Identifier '(' FormalParameterListopt ')'
2189 // '{' FunctionBody '}' 2192 // '{' FunctionBody '}'
2190 Expect(Token::FUNCTION, CHECK_OK); 2193 Expect(Token::FUNCTION, CHECK_OK);
2191 int pos = position(); 2194 int pos = position();
2192 bool is_generator = Check(Token::MUL); 2195 bool is_generator = Check(Token::MUL);
2193 bool is_strict_reserved = false; 2196 bool is_strict_reserved = false;
2194 const AstRawString* name = ParseIdentifierOrStrictReservedWord( 2197 const AstRawString* name = ParseIdentifierOrStrictReservedWord(
2195 &is_strict_reserved, CHECK_OK); 2198 &is_strict_reserved, CHECK_OK);
2196 FunctionLiteral* fun = 2199 FunctionLiteral* fun = ParseFunctionLiteral(
2197 ParseFunctionLiteral(name, scanner()->location(), is_strict_reserved, 2200 name, scanner()->location(), is_strict_reserved,
2198 is_generator ? FunctionKind::kGeneratorFunction 2201 is_generator ? FunctionKind::kGeneratorFunction
2199 : FunctionKind::kNormalFunction, 2202 : FunctionKind::kNormalFunction,
2200 pos, FunctionLiteral::DECLARATION, 2203 pos, FunctionLiteral::DECLARATION, FunctionLiteral::NORMAL_ARITY,
2201 FunctionLiteral::NORMAL_ARITY, CHECK_OK); 2204 language_mode(), CHECK_OK);
2202 // Even if we're not at the top-level of the global or a function 2205 // Even if we're not at the top-level of the global or a function
2203 // scope, we treat it as such and introduce the function with its 2206 // scope, we treat it as such and introduce the function with its
2204 // initial value upon entering the corresponding scope. 2207 // initial value upon entering the corresponding scope.
2205 // In ES6, a function behaves as a lexical binding, except in 2208 // In ES6, a function behaves as a lexical binding, except in
2206 // a script scope, or the initial scope of eval or another function. 2209 // a script scope, or the initial scope of eval or another function.
2207 VariableMode mode = 2210 VariableMode mode =
2208 is_strong(language_mode()) 2211 is_strong(language_mode())
2209 ? CONST 2212 ? CONST
2210 : is_strict(language_mode()) && 2213 : is_strict(language_mode()) &&
2211 !(scope_->is_script_scope() || scope_->is_eval_scope() || 2214 !(scope_->is_script_scope() || scope_->is_eval_scope() ||
(...skipping 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after
3909 DCHECK(reindexer.count() <= 3912 DCHECK(reindexer.count() <=
3910 parser_->function_state_->materialized_literal_count()); 3913 parser_->function_state_->materialized_literal_count());
3911 } 3914 }
3912 } 3915 }
3913 3916
3914 3917
3915 FunctionLiteral* Parser::ParseFunctionLiteral( 3918 FunctionLiteral* Parser::ParseFunctionLiteral(
3916 const AstRawString* function_name, Scanner::Location function_name_location, 3919 const AstRawString* function_name, Scanner::Location function_name_location,
3917 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, 3920 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos,
3918 FunctionLiteral::FunctionType function_type, 3921 FunctionLiteral::FunctionType function_type,
3919 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { 3922 FunctionLiteral::ArityRestriction arity_restriction,
3923 LanguageMode language_mode, bool* ok) {
3920 // Function :: 3924 // Function ::
3921 // '(' FormalParameterList? ')' '{' FunctionBody '}' 3925 // '(' FormalParameterList? ')' '{' FunctionBody '}'
3922 // 3926 //
3923 // Getter :: 3927 // Getter ::
3924 // '(' ')' '{' FunctionBody '}' 3928 // '(' ')' '{' FunctionBody '}'
3925 // 3929 //
3926 // Setter :: 3930 // Setter ::
3927 // '(' PropertySetParameterList ')' '{' FunctionBody '}' 3931 // '(' PropertySetParameterList ')' '{' FunctionBody '}'
3928 3932
3929 int pos = function_token_pos == RelocInfo::kNoPosition 3933 int pos = function_token_pos == RelocInfo::kNoPosition
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3965 // under which we compile is _not_ a declaration scope. This holds because 3969 // under which we compile is _not_ a declaration scope. This holds because
3966 // in all normal cases, function declarations are fully hoisted to a 3970 // in all normal cases, function declarations are fully hoisted to a
3967 // declaration scope and compiled relative to that. 3971 // declaration scope and compiled relative to that.
3968 // - (2) is the case iff the current declaration scope is still the original 3972 // - (2) is the case iff the current declaration scope is still the original
3969 // one relative to the deserialized scope chain. Otherwise we must be 3973 // one relative to the deserialized scope chain. Otherwise we must be
3970 // compiling a function in an inner declaration scope in the eval, e.g. a 3974 // compiling a function in an inner declaration scope in the eval, e.g. a
3971 // nested function, and hoisting works normally relative to that. 3975 // nested function, and hoisting works normally relative to that.
3972 Scope* declaration_scope = scope_->DeclarationScope(); 3976 Scope* declaration_scope = scope_->DeclarationScope();
3973 Scope* original_declaration_scope = original_scope_->DeclarationScope(); 3977 Scope* original_declaration_scope = original_scope_->DeclarationScope();
3974 Scope* scope = function_type == FunctionLiteral::DECLARATION && 3978 Scope* scope = function_type == FunctionLiteral::DECLARATION &&
3975 is_sloppy(language_mode()) && 3979 is_sloppy(language_mode) &&
3976 (original_scope_ == original_declaration_scope || 3980 (original_scope_ == original_declaration_scope ||
3977 declaration_scope != original_declaration_scope) 3981 declaration_scope != original_declaration_scope)
3978 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind) 3982 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind)
3979 : NewScope(scope_, FUNCTION_SCOPE, kind); 3983 : NewScope(scope_, FUNCTION_SCOPE, kind);
3984 scope->SetLanguageMode(language_mode);
3980 ZoneList<Statement*>* body = NULL; 3985 ZoneList<Statement*>* body = NULL;
3981 int materialized_literal_count = -1; 3986 int materialized_literal_count = -1;
3982 int expected_property_count = -1; 3987 int expected_property_count = -1;
3983 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 3988 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
3984 ExpressionClassifier formals_classifier(&duplicate_finder); 3989 ExpressionClassifier formals_classifier(&duplicate_finder);
3985 FunctionLiteral::EagerCompileHint eager_compile_hint = 3990 FunctionLiteral::EagerCompileHint eager_compile_hint =
3986 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile 3991 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile
3987 : FunctionLiteral::kShouldLazyCompile; 3992 : FunctionLiteral::kShouldLazyCompile;
3988 bool should_be_used_once_hint = false; 3993 bool should_be_used_once_hint = false;
3989 // Parse function body. 3994 // Parse function body.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
4023 4028
4024 // If we have a named function expression, we add a local variable 4029 // If we have a named function expression, we add a local variable
4025 // declaration to the body of the function with the name of the 4030 // declaration to the body of the function with the name of the
4026 // function and let it refer to the function itself (closure). 4031 // function and let it refer to the function itself (closure).
4027 // NOTE: We create a proxy and resolve it here so that in the 4032 // NOTE: We create a proxy and resolve it here so that in the
4028 // future we can change the AST to only refer to VariableProxies 4033 // future we can change the AST to only refer to VariableProxies
4029 // instead of Variables and Proxis as is the case now. 4034 // instead of Variables and Proxis as is the case now.
4030 Variable* fvar = NULL; 4035 Variable* fvar = NULL;
4031 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY; 4036 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY;
4032 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { 4037 if (function_type == FunctionLiteral::NAMED_EXPRESSION) {
4033 if (is_strict(language_mode())) { 4038 if (is_strict(language_mode)) {
4034 fvar_init_op = Token::INIT_CONST; 4039 fvar_init_op = Token::INIT_CONST;
4035 } 4040 }
4036 VariableMode fvar_mode = 4041 VariableMode fvar_mode = is_strict(language_mode) ? CONST : CONST_LEGACY;
4037 is_strict(language_mode()) ? CONST : CONST_LEGACY;
4038 DCHECK(function_name != NULL); 4042 DCHECK(function_name != NULL);
4039 fvar = new (zone()) 4043 fvar = new (zone())
4040 Variable(scope_, function_name, fvar_mode, Variable::NORMAL, 4044 Variable(scope_, function_name, fvar_mode, Variable::NORMAL,
4041 kCreatedInitialized, kNotAssigned); 4045 kCreatedInitialized, kNotAssigned);
4042 VariableProxy* proxy = factory()->NewVariableProxy(fvar); 4046 VariableProxy* proxy = factory()->NewVariableProxy(fvar);
4043 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( 4047 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration(
4044 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); 4048 proxy, fvar_mode, scope_, RelocInfo::kNoPosition);
4045 scope_->DeclareFunctionVar(fvar_declaration); 4049 scope_->DeclareFunctionVar(fvar_declaration);
4046 } 4050 }
4047 4051
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
4105 // used once. 4109 // used once.
4106 eager_compile_hint = FunctionLiteral::kShouldEagerCompile; 4110 eager_compile_hint = FunctionLiteral::kShouldEagerCompile;
4107 should_be_used_once_hint = true; 4111 should_be_used_once_hint = true;
4108 } 4112 }
4109 } 4113 }
4110 if (!is_lazily_parsed) { 4114 if (!is_lazily_parsed) {
4111 body = ParseEagerFunctionBody(function_name, pos, parsing_state, fvar, 4115 body = ParseEagerFunctionBody(function_name, pos, parsing_state, fvar,
4112 fvar_init_op, kind, CHECK_OK); 4116 fvar_init_op, kind, CHECK_OK);
4113 materialized_literal_count = function_state.materialized_literal_count(); 4117 materialized_literal_count = function_state.materialized_literal_count();
4114 expected_property_count = function_state.expected_property_count(); 4118 expected_property_count = function_state.expected_property_count();
4119 }
4115 4120
4116 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { 4121 // Parsing the body may change the language mode in our scope.
4117 if (!function_state.super_location().IsValid()) { 4122 language_mode = scope->language_mode();
4118 ReportMessageAt(function_name_location, 4123
4119 MessageTemplate::kStrongSuperCallMissing, 4124 if (is_strong(language_mode) && IsSubclassConstructor(kind)) {
4120 kReferenceError); 4125 if (!function_state.super_location().IsValid()) {
4121 *ok = false; 4126 ReportMessageAt(function_name_location,
4122 return nullptr; 4127 MessageTemplate::kStrongSuperCallMissing,
4123 } 4128 kReferenceError);
4129 *ok = false;
4130 return nullptr;
4124 } 4131 }
4125 } 4132 }
4126 4133
4127 // Validate name and parameter names. We can do this only after parsing the 4134 // Validate name and parameter names. We can do this only after parsing the
4128 // function, since the function can declare itself strict. 4135 // function, since the function can declare itself strict.
4129 CheckFunctionName(language_mode(), kind, function_name, 4136 CheckFunctionName(language_mode, kind, function_name,
4130 name_is_strict_reserved, function_name_location, 4137 name_is_strict_reserved, function_name_location,
4131 CHECK_OK); 4138 CHECK_OK);
4132 const bool use_strict_params = 4139 const bool use_strict_params =
4133 !parsing_state.is_simple_parameter_list || IsConciseMethod(kind); 4140 !parsing_state.is_simple_parameter_list || IsConciseMethod(kind);
4134 const bool allow_duplicate_parameters = 4141 const bool allow_duplicate_parameters =
4135 is_sloppy(language_mode()) && !use_strict_params; 4142 is_sloppy(language_mode) && !use_strict_params;
4136 ValidateFormalParameters(&formals_classifier, language_mode(), 4143 ValidateFormalParameters(&formals_classifier, language_mode,
4137 allow_duplicate_parameters, CHECK_OK); 4144 allow_duplicate_parameters, CHECK_OK);
4138 4145
4139 if (is_strict(language_mode())) { 4146 if (is_strict(language_mode)) {
4140 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), 4147 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(),
4141 CHECK_OK); 4148 CHECK_OK);
4142 CheckConflictingVarDeclarations(scope, CHECK_OK); 4149 CheckConflictingVarDeclarations(scope, CHECK_OK);
4143 } 4150 }
4144 } 4151 }
4145 4152
4146 bool has_duplicate_parameters = 4153 bool has_duplicate_parameters =
4147 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); 4154 !formals_classifier.is_valid_formal_parameter_list_without_duplicates();
4148 FunctionLiteral::ParameterFlag duplicate_parameters = 4155 FunctionLiteral::ParameterFlag duplicate_parameters =
4149 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters 4156 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
4520 if (fni_ != NULL) { 4527 if (fni_ != NULL) {
4521 fni_->Infer(); 4528 fni_->Infer();
4522 fni_->Leave(); 4529 fni_->Leave();
4523 } 4530 }
4524 } 4531 }
4525 4532
4526 Expect(Token::RBRACE, CHECK_OK); 4533 Expect(Token::RBRACE, CHECK_OK);
4527 int end_pos = scanner()->location().end_pos; 4534 int end_pos = scanner()->location().end_pos;
4528 4535
4529 if (constructor == NULL) { 4536 if (constructor == NULL) {
4530 constructor = 4537 constructor = DefaultConstructor(extends != NULL, block_scope, pos, end_pos,
4531 DefaultConstructor(extends != NULL, block_scope, pos, end_pos); 4538 block_scope->language_mode());
4532 } 4539 }
4533 4540
4534 block_scope->set_end_position(end_pos); 4541 block_scope->set_end_position(end_pos);
4535 4542
4536 if (name != NULL) { 4543 if (name != NULL) {
4537 DCHECK_NOT_NULL(proxy); 4544 DCHECK_NOT_NULL(proxy);
4538 proxy->var()->set_initializer_position(end_pos); 4545 proxy->var()->set_initializer_position(end_pos);
4539 } else { 4546 } else {
4540 // Unnamed classes should not have scopes (the scope will be empty). 4547 // Unnamed classes should not have scopes (the scope will be empty).
4541 DCHECK_EQ(block_scope->num_var_or_const(), 0); 4548 DCHECK_EQ(block_scope->num_var_or_const(), 0);
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after
5942 Expression* Parser::SpreadCallNew(Expression* function, 5949 Expression* Parser::SpreadCallNew(Expression* function,
5943 ZoneList<v8::internal::Expression*>* args, 5950 ZoneList<v8::internal::Expression*>* args,
5944 int pos) { 5951 int pos) {
5945 args->InsertAt(0, function, zone()); 5952 args->InsertAt(0, function, zone());
5946 5953
5947 return factory()->NewCallRuntime( 5954 return factory()->NewCallRuntime(
5948 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5955 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5949 } 5956 }
5950 } // namespace internal 5957 } // namespace internal
5951 } // namespace v8 5958 } // namespace v8
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698