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/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 Loading... |
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 Loading... |
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 Loading... |
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 FunctionNameValidity function_name_validity, FunctionKind kind, | 876 FunctionNameValidity function_name_validity, 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, function_name_validity, kind, | 881 name, function_name_location, function_name_validity, 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 scope = Scope::DeserializeScopeChain(isolate, zone(), | 1167 scope = Scope::DeserializeScopeChain(isolate, zone(), |
1165 info->closure()->context(), scope); | 1168 info->closure()->context(), scope); |
1166 } | 1169 } |
1167 original_scope_ = scope; | 1170 original_scope_ = scope; |
1168 AstNodeFactory function_factory(ast_value_factory()); | 1171 AstNodeFactory function_factory(ast_value_factory()); |
1169 FunctionState function_state(&function_state_, &scope_, scope, | 1172 FunctionState function_state(&function_state_, &scope_, scope, |
1170 shared_info->kind(), &function_factory); | 1173 shared_info->kind(), &function_factory); |
1171 DCHECK(is_sloppy(scope->language_mode()) || | 1174 DCHECK(is_sloppy(scope->language_mode()) || |
1172 is_strict(info->language_mode())); | 1175 is_strict(info->language_mode())); |
1173 DCHECK(info->language_mode() == shared_info->language_mode()); | 1176 DCHECK(info->language_mode() == shared_info->language_mode()); |
1174 scope->SetLanguageMode(shared_info->language_mode()); | |
1175 FunctionLiteral::FunctionType function_type = shared_info->is_expression() | 1177 FunctionLiteral::FunctionType function_type = shared_info->is_expression() |
1176 ? (shared_info->is_anonymous() | 1178 ? (shared_info->is_anonymous() |
1177 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 1179 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
1178 : FunctionLiteral::NAMED_EXPRESSION) | 1180 : FunctionLiteral::NAMED_EXPRESSION) |
1179 : FunctionLiteral::DECLARATION; | 1181 : FunctionLiteral::DECLARATION; |
1180 bool ok = true; | 1182 bool ok = true; |
1181 | 1183 |
1182 if (shared_info->is_arrow()) { | 1184 if (shared_info->is_arrow()) { |
1183 Scope* scope = | 1185 Scope* scope = |
1184 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); | 1186 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| 1187 scope->SetLanguageMode(shared_info->language_mode()); |
1185 scope->set_start_position(shared_info->start_position()); | 1188 scope->set_start_position(shared_info->start_position()); |
1186 ExpressionClassifier formals_classifier; | 1189 ExpressionClassifier formals_classifier; |
1187 ParserFormalParameterParsingState parsing_state(scope); | 1190 ParserFormalParameterParsingState parsing_state(scope); |
1188 Checkpoint checkpoint(this); | 1191 Checkpoint checkpoint(this); |
1189 { | 1192 { |
1190 // Parsing patterns as variable reference expression creates | 1193 // Parsing patterns as variable reference expression creates |
1191 // NewUnresolved references in current scope. Entrer arrow function | 1194 // NewUnresolved references in current scope. Entrer arrow function |
1192 // scope for formal parameter parsing. | 1195 // scope for formal parameter parsing. |
1193 BlockState block_state(&scope_, scope); | 1196 BlockState block_state(&scope_, scope); |
1194 if (Check(Token::LPAREN)) { | 1197 if (Check(Token::LPAREN)) { |
(...skipping 25 matching lines...) Expand all Loading... |
1220 DCHECK(expression->IsFunctionLiteral()); | 1223 DCHECK(expression->IsFunctionLiteral()); |
1221 result = expression->AsFunctionLiteral(); | 1224 result = expression->AsFunctionLiteral(); |
1222 } else { | 1225 } else { |
1223 ok = false; | 1226 ok = false; |
1224 } | 1227 } |
1225 } | 1228 } |
1226 } | 1229 } |
1227 } else if (shared_info->is_default_constructor()) { | 1230 } else if (shared_info->is_default_constructor()) { |
1228 result = DefaultConstructor(IsSubclassConstructor(shared_info->kind()), | 1231 result = DefaultConstructor(IsSubclassConstructor(shared_info->kind()), |
1229 scope, shared_info->start_position(), | 1232 scope, shared_info->start_position(), |
1230 shared_info->end_position()); | 1233 shared_info->end_position(), |
| 1234 shared_info->language_mode()); |
1231 } else { | 1235 } else { |
1232 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), | 1236 result = ParseFunctionLiteral( |
1233 kSkipFunctionNameCheck, shared_info->kind(), | 1237 raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, |
1234 RelocInfo::kNoPosition, function_type, | 1238 shared_info->kind(), RelocInfo::kNoPosition, function_type, |
1235 FunctionLiteral::NORMAL_ARITY, &ok); | 1239 FunctionLiteral::NORMAL_ARITY, shared_info->language_mode(), &ok); |
1236 } | 1240 } |
1237 // Make sure the results agree. | 1241 // Make sure the results agree. |
1238 DCHECK(ok == (result != NULL)); | 1242 DCHECK(ok == (result != NULL)); |
1239 } | 1243 } |
1240 | 1244 |
1241 // Make sure the target stack is empty. | 1245 // Make sure the target stack is empty. |
1242 DCHECK(target_stack_ == NULL); | 1246 DCHECK(target_stack_ == NULL); |
1243 | 1247 |
1244 if (result != NULL) { | 1248 if (result != NULL) { |
1245 Handle<String> inferred_name(shared_info->inferred_name()); | 1249 Handle<String> inferred_name(shared_info->inferred_name()); |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2188 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | 2192 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
2189 // GeneratorDeclaration :: | 2193 // GeneratorDeclaration :: |
2190 // 'function' '*' Identifier '(' FormalParameterListopt ')' | 2194 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
2191 // '{' FunctionBody '}' | 2195 // '{' FunctionBody '}' |
2192 Expect(Token::FUNCTION, CHECK_OK); | 2196 Expect(Token::FUNCTION, CHECK_OK); |
2193 int pos = position(); | 2197 int pos = position(); |
2194 bool is_generator = Check(Token::MUL); | 2198 bool is_generator = Check(Token::MUL); |
2195 bool is_strict_reserved = false; | 2199 bool is_strict_reserved = false; |
2196 const AstRawString* name = ParseIdentifierOrStrictReservedWord( | 2200 const AstRawString* name = ParseIdentifierOrStrictReservedWord( |
2197 &is_strict_reserved, CHECK_OK); | 2201 &is_strict_reserved, CHECK_OK); |
2198 FunctionLiteral* fun = | 2202 FunctionLiteral* fun = ParseFunctionLiteral( |
2199 ParseFunctionLiteral(name, scanner()->location(), | 2203 name, scanner()->location(), |
2200 is_strict_reserved ? kFunctionNameIsStrictReserved | 2204 is_strict_reserved ? kFunctionNameIsStrictReserved |
2201 : kFunctionNameValidityUnknown, | 2205 : kFunctionNameValidityUnknown, |
2202 is_generator ? FunctionKind::kGeneratorFunction | 2206 is_generator ? FunctionKind::kGeneratorFunction |
2203 : FunctionKind::kNormalFunction, | 2207 : FunctionKind::kNormalFunction, |
2204 pos, FunctionLiteral::DECLARATION, | 2208 pos, FunctionLiteral::DECLARATION, FunctionLiteral::NORMAL_ARITY, |
2205 FunctionLiteral::NORMAL_ARITY, CHECK_OK); | 2209 language_mode(), CHECK_OK); |
2206 // Even if we're not at the top-level of the global or a function | 2210 // Even if we're not at the top-level of the global or a function |
2207 // scope, we treat it as such and introduce the function with its | 2211 // scope, we treat it as such and introduce the function with its |
2208 // initial value upon entering the corresponding scope. | 2212 // initial value upon entering the corresponding scope. |
2209 // In ES6, a function behaves as a lexical binding, except in | 2213 // In ES6, a function behaves as a lexical binding, except in |
2210 // a script scope, or the initial scope of eval or another function. | 2214 // a script scope, or the initial scope of eval or another function. |
2211 VariableMode mode = | 2215 VariableMode mode = |
2212 is_strong(language_mode()) | 2216 is_strong(language_mode()) |
2213 ? CONST | 2217 ? CONST |
2214 : (is_strict(language_mode()) || allow_harmony_sloppy()) && | 2218 : (is_strict(language_mode()) || allow_harmony_sloppy()) && |
2215 !(scope_->is_script_scope() || scope_->is_eval_scope() || | 2219 !(scope_->is_script_scope() || scope_->is_eval_scope() || |
(...skipping 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3913 DCHECK(reindexer.count() <= | 3917 DCHECK(reindexer.count() <= |
3914 parser_->function_state_->materialized_literal_count()); | 3918 parser_->function_state_->materialized_literal_count()); |
3915 } | 3919 } |
3916 } | 3920 } |
3917 | 3921 |
3918 | 3922 |
3919 FunctionLiteral* Parser::ParseFunctionLiteral( | 3923 FunctionLiteral* Parser::ParseFunctionLiteral( |
3920 const AstRawString* function_name, Scanner::Location function_name_location, | 3924 const AstRawString* function_name, Scanner::Location function_name_location, |
3921 FunctionNameValidity function_name_validity, FunctionKind kind, | 3925 FunctionNameValidity function_name_validity, FunctionKind kind, |
3922 int function_token_pos, FunctionLiteral::FunctionType function_type, | 3926 int function_token_pos, FunctionLiteral::FunctionType function_type, |
3923 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 3927 FunctionLiteral::ArityRestriction arity_restriction, |
| 3928 LanguageMode language_mode, bool* ok) { |
3924 // Function :: | 3929 // Function :: |
3925 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 3930 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
3926 // | 3931 // |
3927 // Getter :: | 3932 // Getter :: |
3928 // '(' ')' '{' FunctionBody '}' | 3933 // '(' ')' '{' FunctionBody '}' |
3929 // | 3934 // |
3930 // Setter :: | 3935 // Setter :: |
3931 // '(' PropertySetParameterList ')' '{' FunctionBody '}' | 3936 // '(' PropertySetParameterList ')' '{' FunctionBody '}' |
3932 | 3937 |
3933 int pos = function_token_pos == RelocInfo::kNoPosition | 3938 int pos = function_token_pos == RelocInfo::kNoPosition |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3969 // under which we compile is _not_ a declaration scope. This holds because | 3974 // under which we compile is _not_ a declaration scope. This holds because |
3970 // in all normal cases, function declarations are fully hoisted to a | 3975 // in all normal cases, function declarations are fully hoisted to a |
3971 // declaration scope and compiled relative to that. | 3976 // declaration scope and compiled relative to that. |
3972 // - (2) is the case iff the current declaration scope is still the original | 3977 // - (2) is the case iff the current declaration scope is still the original |
3973 // one relative to the deserialized scope chain. Otherwise we must be | 3978 // one relative to the deserialized scope chain. Otherwise we must be |
3974 // compiling a function in an inner declaration scope in the eval, e.g. a | 3979 // compiling a function in an inner declaration scope in the eval, e.g. a |
3975 // nested function, and hoisting works normally relative to that. | 3980 // nested function, and hoisting works normally relative to that. |
3976 Scope* declaration_scope = scope_->DeclarationScope(); | 3981 Scope* declaration_scope = scope_->DeclarationScope(); |
3977 Scope* original_declaration_scope = original_scope_->DeclarationScope(); | 3982 Scope* original_declaration_scope = original_scope_->DeclarationScope(); |
3978 Scope* scope = function_type == FunctionLiteral::DECLARATION && | 3983 Scope* scope = function_type == FunctionLiteral::DECLARATION && |
3979 is_sloppy(language_mode()) && | 3984 is_sloppy(language_mode) && !allow_harmony_sloppy() && |
3980 !allow_harmony_sloppy() && | |
3981 (original_scope_ == original_declaration_scope || | 3985 (original_scope_ == original_declaration_scope || |
3982 declaration_scope != original_declaration_scope) | 3986 declaration_scope != original_declaration_scope) |
3983 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind) | 3987 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind) |
3984 : NewScope(scope_, FUNCTION_SCOPE, kind); | 3988 : NewScope(scope_, FUNCTION_SCOPE, kind); |
| 3989 scope->SetLanguageMode(language_mode); |
3985 ZoneList<Statement*>* body = NULL; | 3990 ZoneList<Statement*>* body = NULL; |
3986 int materialized_literal_count = -1; | 3991 int materialized_literal_count = -1; |
3987 int expected_property_count = -1; | 3992 int expected_property_count = -1; |
3988 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 3993 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
3989 ExpressionClassifier formals_classifier(&duplicate_finder); | 3994 ExpressionClassifier formals_classifier(&duplicate_finder); |
3990 FunctionLiteral::EagerCompileHint eager_compile_hint = | 3995 FunctionLiteral::EagerCompileHint eager_compile_hint = |
3991 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile | 3996 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile |
3992 : FunctionLiteral::kShouldLazyCompile; | 3997 : FunctionLiteral::kShouldLazyCompile; |
3993 bool should_be_used_once_hint = false; | 3998 bool should_be_used_once_hint = false; |
3994 // Parse function body. | 3999 // Parse function body. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4028 | 4033 |
4029 // If we have a named function expression, we add a local variable | 4034 // If we have a named function expression, we add a local variable |
4030 // declaration to the body of the function with the name of the | 4035 // declaration to the body of the function with the name of the |
4031 // function and let it refer to the function itself (closure). | 4036 // function and let it refer to the function itself (closure). |
4032 // NOTE: We create a proxy and resolve it here so that in the | 4037 // NOTE: We create a proxy and resolve it here so that in the |
4033 // future we can change the AST to only refer to VariableProxies | 4038 // future we can change the AST to only refer to VariableProxies |
4034 // instead of Variables and Proxis as is the case now. | 4039 // instead of Variables and Proxis as is the case now. |
4035 Variable* fvar = NULL; | 4040 Variable* fvar = NULL; |
4036 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY; | 4041 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY; |
4037 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { | 4042 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { |
4038 bool use_strict_const = is_strict(language_mode()) || | 4043 bool use_strict_const = is_strict(language_mode) || |
4039 (!allow_legacy_const() && allow_harmony_sloppy()); | 4044 (!allow_legacy_const() && allow_harmony_sloppy()); |
4040 if (use_strict_const) { | 4045 if (use_strict_const) { |
4041 fvar_init_op = Token::INIT_CONST; | 4046 fvar_init_op = Token::INIT_CONST; |
4042 } | 4047 } |
4043 VariableMode fvar_mode = use_strict_const ? CONST : CONST_LEGACY; | 4048 VariableMode fvar_mode = use_strict_const ? CONST : CONST_LEGACY; |
4044 DCHECK(function_name != NULL); | 4049 DCHECK(function_name != NULL); |
4045 fvar = new (zone()) | 4050 fvar = new (zone()) |
4046 Variable(scope_, function_name, fvar_mode, Variable::NORMAL, | 4051 Variable(scope_, function_name, fvar_mode, Variable::NORMAL, |
4047 kCreatedInitialized, kNotAssigned); | 4052 kCreatedInitialized, kNotAssigned); |
4048 VariableProxy* proxy = factory()->NewVariableProxy(fvar); | 4053 VariableProxy* proxy = factory()->NewVariableProxy(fvar); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4111 // used once. | 4116 // used once. |
4112 eager_compile_hint = FunctionLiteral::kShouldEagerCompile; | 4117 eager_compile_hint = FunctionLiteral::kShouldEagerCompile; |
4113 should_be_used_once_hint = true; | 4118 should_be_used_once_hint = true; |
4114 } | 4119 } |
4115 } | 4120 } |
4116 if (!is_lazily_parsed) { | 4121 if (!is_lazily_parsed) { |
4117 body = ParseEagerFunctionBody(function_name, pos, parsing_state, fvar, | 4122 body = ParseEagerFunctionBody(function_name, pos, parsing_state, fvar, |
4118 fvar_init_op, kind, CHECK_OK); | 4123 fvar_init_op, kind, CHECK_OK); |
4119 materialized_literal_count = function_state.materialized_literal_count(); | 4124 materialized_literal_count = function_state.materialized_literal_count(); |
4120 expected_property_count = function_state.expected_property_count(); | 4125 expected_property_count = function_state.expected_property_count(); |
| 4126 } |
4121 | 4127 |
4122 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { | 4128 // Parsing the body may change the language mode in our scope. |
4123 if (!function_state.super_location().IsValid()) { | 4129 language_mode = scope->language_mode(); |
4124 ReportMessageAt(function_name_location, | 4130 |
4125 MessageTemplate::kStrongSuperCallMissing, | 4131 if (is_strong(language_mode) && IsSubclassConstructor(kind)) { |
4126 kReferenceError); | 4132 if (!function_state.super_location().IsValid()) { |
4127 *ok = false; | 4133 ReportMessageAt(function_name_location, |
4128 return nullptr; | 4134 MessageTemplate::kStrongSuperCallMissing, |
4129 } | 4135 kReferenceError); |
| 4136 *ok = false; |
| 4137 return nullptr; |
4130 } | 4138 } |
4131 } | 4139 } |
4132 | 4140 |
4133 // Validate name and parameter names. We can do this only after parsing the | 4141 // Validate name and parameter names. We can do this only after parsing the |
4134 // function, since the function can declare itself strict. | 4142 // function, since the function can declare itself strict. |
4135 CheckFunctionName(language_mode(), function_name, function_name_validity, | 4143 CheckFunctionName(language_mode, function_name, function_name_validity, |
4136 function_name_location, CHECK_OK); | 4144 function_name_location, CHECK_OK); |
4137 const bool use_strict_params = | 4145 const bool use_strict_params = |
4138 !parsing_state.is_simple_parameter_list || IsConciseMethod(kind); | 4146 !parsing_state.is_simple_parameter_list || IsConciseMethod(kind); |
4139 const bool allow_duplicate_parameters = | 4147 const bool allow_duplicate_parameters = |
4140 is_sloppy(language_mode()) && !use_strict_params; | 4148 is_sloppy(language_mode) && !use_strict_params; |
4141 ValidateFormalParameters(&formals_classifier, language_mode(), | 4149 ValidateFormalParameters(&formals_classifier, language_mode, |
4142 allow_duplicate_parameters, CHECK_OK); | 4150 allow_duplicate_parameters, CHECK_OK); |
4143 | 4151 |
4144 if (is_strict(language_mode())) { | 4152 if (is_strict(language_mode)) { |
4145 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), | 4153 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), |
4146 CHECK_OK); | 4154 CHECK_OK); |
4147 } | 4155 } |
4148 if (is_strict(language_mode()) || allow_harmony_sloppy()) { | 4156 if (is_strict(language_mode) || allow_harmony_sloppy()) { |
4149 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4157 CheckConflictingVarDeclarations(scope, CHECK_OK); |
4150 } | 4158 } |
4151 } | 4159 } |
4152 | 4160 |
4153 bool has_duplicate_parameters = | 4161 bool has_duplicate_parameters = |
4154 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); | 4162 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); |
4155 FunctionLiteral::ParameterFlag duplicate_parameters = | 4163 FunctionLiteral::ParameterFlag duplicate_parameters = |
4156 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters | 4164 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters |
4157 : FunctionLiteral::kNoDuplicateParameters; | 4165 : FunctionLiteral::kNoDuplicateParameters; |
4158 | 4166 |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4527 if (fni_ != NULL) { | 4535 if (fni_ != NULL) { |
4528 fni_->Infer(); | 4536 fni_->Infer(); |
4529 fni_->Leave(); | 4537 fni_->Leave(); |
4530 } | 4538 } |
4531 } | 4539 } |
4532 | 4540 |
4533 Expect(Token::RBRACE, CHECK_OK); | 4541 Expect(Token::RBRACE, CHECK_OK); |
4534 int end_pos = scanner()->location().end_pos; | 4542 int end_pos = scanner()->location().end_pos; |
4535 | 4543 |
4536 if (constructor == NULL) { | 4544 if (constructor == NULL) { |
4537 constructor = | 4545 constructor = DefaultConstructor(extends != NULL, block_scope, pos, end_pos, |
4538 DefaultConstructor(extends != NULL, block_scope, pos, end_pos); | 4546 block_scope->language_mode()); |
4539 } | 4547 } |
4540 | 4548 |
4541 block_scope->set_end_position(end_pos); | 4549 block_scope->set_end_position(end_pos); |
4542 | 4550 |
4543 if (name != NULL) { | 4551 if (name != NULL) { |
4544 DCHECK_NOT_NULL(proxy); | 4552 DCHECK_NOT_NULL(proxy); |
4545 proxy->var()->set_initializer_position(end_pos); | 4553 proxy->var()->set_initializer_position(end_pos); |
4546 } else { | 4554 } else { |
4547 // Unnamed classes should not have scopes (the scope will be empty). | 4555 // Unnamed classes should not have scopes (the scope will be empty). |
4548 DCHECK_EQ(block_scope->num_var_or_const(), 0); | 4556 DCHECK_EQ(block_scope->num_var_or_const(), 0); |
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5949 Expression* Parser::SpreadCallNew(Expression* function, | 5957 Expression* Parser::SpreadCallNew(Expression* function, |
5950 ZoneList<v8::internal::Expression*>* args, | 5958 ZoneList<v8::internal::Expression*>* args, |
5951 int pos) { | 5959 int pos) { |
5952 args->InsertAt(0, function, zone()); | 5960 args->InsertAt(0, function, zone()); |
5953 | 5961 |
5954 return factory()->NewCallRuntime( | 5962 return factory()->NewCallRuntime( |
5955 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5963 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5956 } | 5964 } |
5957 } // namespace internal | 5965 } // namespace internal |
5958 } // namespace v8 | 5966 } // namespace v8 |
OLD | NEW |