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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 264 |
265 | 265 |
266 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, | 266 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, |
267 int pos, int end_pos) { | 267 int pos, int end_pos) { |
268 int materialized_literal_count = -1; | 268 int materialized_literal_count = -1; |
269 int expected_property_count = -1; | 269 int expected_property_count = -1; |
270 int handler_count = 0; | 270 int handler_count = 0; |
271 int parameter_count = 0; | 271 int parameter_count = 0; |
272 const AstRawString* name = ast_value_factory()->empty_string(); | 272 const AstRawString* name = ast_value_factory()->empty_string(); |
273 | 273 |
274 Scope* function_scope = | 274 |
275 NewScope(scope, FUNCTION_SCOPE, FunctionKind::kDefaultConstructor); | 275 FunctionKind kind = call_super && !FLAG_experimental_classes |
| 276 ? FunctionKind::kDefaultBaseConstructor |
| 277 : FunctionKind::kDefaultSubclassConstructor; |
| 278 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind); |
276 function_scope->SetLanguageMode( | 279 function_scope->SetLanguageMode( |
277 static_cast<LanguageMode>(scope->language_mode() | STRICT_BIT)); | 280 static_cast<LanguageMode>(scope->language_mode() | STRICT_BIT)); |
278 // Set start and end position to the same value | 281 // Set start and end position to the same value |
279 function_scope->set_start_position(pos); | 282 function_scope->set_start_position(pos); |
280 function_scope->set_end_position(pos); | 283 function_scope->set_end_position(pos); |
281 ZoneList<Statement*>* body = NULL; | 284 ZoneList<Statement*>* body = NULL; |
282 | 285 |
283 { | 286 { |
284 AstNodeFactory function_factory(ast_value_factory()); | 287 AstNodeFactory function_factory(ast_value_factory()); |
285 FunctionState function_state(&function_state_, &scope_, function_scope, | 288 FunctionState function_state(&function_state_, &scope_, function_scope, |
286 kDefaultConstructor, &function_factory); | 289 kind, &function_factory); |
287 | 290 |
288 body = new (zone()) ZoneList<Statement*>(1, zone()); | 291 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); |
| 292 AddAssertIsConstruct(body, pos); |
289 if (call_super) { | 293 if (call_super) { |
290 ZoneList<Expression*>* args = | 294 ZoneList<Expression*>* args = |
291 new (zone()) ZoneList<Expression*>(0, zone()); | 295 new (zone()) ZoneList<Expression*>(0, zone()); |
292 CallRuntime* call = factory()->NewCallRuntime( | 296 if (FLAG_experimental_classes) { |
293 ast_value_factory()->empty_string(), | 297 CallRuntime* call = factory()->NewCallRuntime( |
294 Runtime::FunctionForId(Runtime::kDefaultConstructorSuperCall), args, | 298 ast_value_factory()->empty_string(), |
295 pos); | 299 Runtime::FunctionForId(Runtime::kInlineDefaultConstructorCallSuper), |
296 body->Add(factory()->NewExpressionStatement(call, pos), zone()); | 300 args, pos); |
| 301 body->Add(factory()->NewReturnStatement(call, pos), zone()); |
| 302 } else { |
| 303 CallRuntime* call = factory()->NewCallRuntime( |
| 304 ast_value_factory()->empty_string(), |
| 305 Runtime::FunctionForId(Runtime::kDefaultConstructorSuperCall), args, |
| 306 pos); |
| 307 body->Add(factory()->NewExpressionStatement(call, pos), zone()); |
| 308 } |
297 function_scope->RecordSuperConstructorCallUsage(); | 309 function_scope->RecordSuperConstructorCallUsage(); |
298 } | 310 } |
299 | 311 |
300 materialized_literal_count = function_state.materialized_literal_count(); | 312 materialized_literal_count = function_state.materialized_literal_count(); |
301 expected_property_count = function_state.expected_property_count(); | 313 expected_property_count = function_state.expected_property_count(); |
302 handler_count = function_state.handler_count(); | 314 handler_count = function_state.handler_count(); |
303 } | 315 } |
304 | 316 |
305 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 317 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
306 name, ast_value_factory(), function_scope, body, | 318 name, ast_value_factory(), function_scope, body, |
307 materialized_literal_count, expected_property_count, handler_count, | 319 materialized_literal_count, expected_property_count, handler_count, |
308 parameter_count, FunctionLiteral::kNoDuplicateParameters, | 320 parameter_count, FunctionLiteral::kNoDuplicateParameters, |
309 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, | 321 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, |
310 FunctionLiteral::kNotParenthesized, FunctionKind::kDefaultConstructor, | 322 FunctionLiteral::kNotParenthesized, kind, pos); |
311 pos); | |
312 | 323 |
313 return function_literal; | 324 return function_literal; |
314 } | 325 } |
315 | 326 |
316 | 327 |
317 // ---------------------------------------------------------------------------- | 328 // ---------------------------------------------------------------------------- |
318 // Target is a support class to facilitate manipulation of the | 329 // Target is a support class to facilitate manipulation of the |
319 // Parser's target_stack_ (the stack of potential 'break' and | 330 // Parser's target_stack_ (the stack of potential 'break' and |
320 // 'continue' statement targets). Upon construction, a new target is | 331 // 'continue' statement targets). Upon construction, a new target is |
321 // added; it is removed upon destruction. | 332 // added; it is removed upon destruction. |
(...skipping 3565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3887 if (produce_cached_parse_data()) { | 3898 if (produce_cached_parse_data()) { |
3888 DCHECK(log_); | 3899 DCHECK(log_); |
3889 // Position right after terminal '}'. | 3900 // Position right after terminal '}'. |
3890 int body_end = scanner()->location().end_pos; | 3901 int body_end = scanner()->location().end_pos; |
3891 log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, | 3902 log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, |
3892 *expected_property_count, scope_->language_mode()); | 3903 *expected_property_count, scope_->language_mode()); |
3893 } | 3904 } |
3894 } | 3905 } |
3895 | 3906 |
3896 | 3907 |
| 3908 void Parser::AddAssertIsConstruct(ZoneList<Statement*>* body, int pos) { |
| 3909 if (!FLAG_experimental_classes) return; |
| 3910 |
| 3911 ZoneList<Expression*>* arguments = |
| 3912 new (zone()) ZoneList<Expression*>(0, zone()); |
| 3913 CallRuntime* construct_check = factory()->NewCallRuntime( |
| 3914 ast_value_factory()->is_construct_call_string(), |
| 3915 Runtime::FunctionForId(Runtime::kInlineIsConstructCall), arguments, pos); |
| 3916 CallRuntime* non_callable_error = factory()->NewCallRuntime( |
| 3917 ast_value_factory()->empty_string(), |
| 3918 Runtime::FunctionForId(Runtime::kThrowConstructorNonCallableError), |
| 3919 arguments, pos); |
| 3920 IfStatement* if_statement = factory()->NewIfStatement( |
| 3921 factory()->NewUnaryOperation(Token::NOT, construct_check, pos), |
| 3922 factory()->NewReturnStatement(non_callable_error, pos), |
| 3923 factory()->NewEmptyStatement(pos), pos); |
| 3924 body->Add(if_statement, zone()); |
| 3925 } |
| 3926 |
| 3927 |
3897 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 3928 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
3898 const AstRawString* function_name, int pos, Variable* fvar, | 3929 const AstRawString* function_name, int pos, Variable* fvar, |
3899 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 3930 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
3900 // Everything inside an eagerly parsed function will be parsed eagerly | 3931 // Everything inside an eagerly parsed function will be parsed eagerly |
3901 // (see comment above). | 3932 // (see comment above). |
3902 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 3933 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
3903 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone()); | 3934 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone()); |
3904 if (fvar != NULL) { | 3935 if (fvar != NULL) { |
3905 VariableProxy* fproxy = scope_->NewUnresolved( | 3936 VariableProxy* fproxy = scope_->NewUnresolved( |
3906 factory(), function_name, Interface::NewConst()); | 3937 factory(), function_name, Interface::NewConst()); |
3907 fproxy->BindTo(fvar); | 3938 fproxy->BindTo(fvar); |
3908 body->Add(factory()->NewExpressionStatement( | 3939 body->Add(factory()->NewExpressionStatement( |
3909 factory()->NewAssignment(fvar_init_op, | 3940 factory()->NewAssignment(fvar_init_op, |
3910 fproxy, | 3941 fproxy, |
3911 factory()->NewThisFunction(pos), | 3942 factory()->NewThisFunction(pos), |
3912 RelocInfo::kNoPosition), | 3943 RelocInfo::kNoPosition), |
3913 RelocInfo::kNoPosition), zone()); | 3944 RelocInfo::kNoPosition), zone()); |
3914 } | 3945 } |
3915 | 3946 |
3916 | 3947 |
3917 // For concise constructors, check that they are constructed, | 3948 // For concise constructors, check that they are constructed, |
3918 // not called. | 3949 // not called. |
3919 if (FLAG_experimental_classes && i::IsConstructor(kind)) { | 3950 if (i::IsConstructor(kind)) { |
3920 ZoneList<Expression*>* arguments = | 3951 AddAssertIsConstruct(body, pos); |
3921 new (zone()) ZoneList<Expression*>(0, zone()); | |
3922 CallRuntime* construct_check = factory()->NewCallRuntime( | |
3923 ast_value_factory()->is_construct_call_string(), | |
3924 Runtime::FunctionForId(Runtime::kInlineIsConstructCall), arguments, | |
3925 pos); | |
3926 CallRuntime* non_callable_error = factory()->NewCallRuntime( | |
3927 ast_value_factory()->empty_string(), | |
3928 Runtime::FunctionForId(Runtime::kThrowConstructorNonCallableError), | |
3929 arguments, pos); | |
3930 IfStatement* if_statement = factory()->NewIfStatement( | |
3931 factory()->NewUnaryOperation(Token::NOT, construct_check, pos), | |
3932 factory()->NewReturnStatement(non_callable_error, pos), | |
3933 factory()->NewEmptyStatement(pos), pos); | |
3934 body->Add(if_statement, zone()); | |
3935 } | 3952 } |
3936 | 3953 |
3937 // For generators, allocate and yield an iterator on function entry. | 3954 // For generators, allocate and yield an iterator on function entry. |
3938 if (IsGeneratorFunction(kind)) { | 3955 if (IsGeneratorFunction(kind)) { |
3939 ZoneList<Expression*>* arguments = | 3956 ZoneList<Expression*>* arguments = |
3940 new(zone()) ZoneList<Expression*>(0, zone()); | 3957 new(zone()) ZoneList<Expression*>(0, zone()); |
3941 CallRuntime* allocation = factory()->NewCallRuntime( | 3958 CallRuntime* allocation = factory()->NewCallRuntime( |
3942 ast_value_factory()->empty_string(), | 3959 ast_value_factory()->empty_string(), |
3943 Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject), arguments, | 3960 Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject), arguments, |
3944 pos); | 3961 pos); |
(...skipping 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5419 } else { | 5436 } else { |
5420 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5437 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
5421 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5438 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
5422 raw_string->length()); | 5439 raw_string->length()); |
5423 } | 5440 } |
5424 } | 5441 } |
5425 | 5442 |
5426 return running_hash; | 5443 return running_hash; |
5427 } | 5444 } |
5428 } } // namespace v8::internal | 5445 } } // namespace v8::internal |
OLD | NEW |