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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 function_scope->set_start_position(pos); | 237 function_scope->set_start_position(pos); |
238 function_scope->set_end_position(pos); | 238 function_scope->set_end_position(pos); |
239 ZoneList<Statement*>* body = NULL; | 239 ZoneList<Statement*>* body = NULL; |
240 | 240 |
241 { | 241 { |
242 FunctionState function_state(&function_state_, &scope_state_, | 242 FunctionState function_state(&function_state_, &scope_state_, |
243 function_scope); | 243 function_scope); |
244 | 244 |
245 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); | 245 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); |
246 if (call_super) { | 246 if (call_super) { |
247 // $super_constructor = %_GetSuperConstructor(<this-function>) | 247 // Create a SuperCallReference and handle in BytecodeGenerator. |
248 // %reflect_construct( | |
249 // $super_constructor, InternalArray(...args), new.target) | |
250 auto constructor_args_name = ast_value_factory()->empty_string(); | 248 auto constructor_args_name = ast_value_factory()->empty_string(); |
251 bool is_duplicate; | 249 bool is_duplicate; |
252 bool is_rest = true; | 250 bool is_rest = true; |
253 bool is_optional = false; | 251 bool is_optional = false; |
254 Variable* constructor_args = function_scope->DeclareParameter( | 252 Variable* constructor_args = function_scope->DeclareParameter( |
255 constructor_args_name, TEMPORARY, is_optional, is_rest, &is_duplicate, | 253 constructor_args_name, TEMPORARY, is_optional, is_rest, &is_duplicate, |
256 ast_value_factory()); | 254 ast_value_factory()); |
257 | 255 |
258 ZoneList<Expression*>* args = | 256 ZoneList<Expression*>* args = |
259 new (zone()) ZoneList<Expression*>(2, zone()); | |
260 VariableProxy* this_function_proxy = | |
261 NewUnresolved(ast_value_factory()->this_function_string(), pos); | |
262 ZoneList<Expression*>* tmp = | |
263 new (zone()) ZoneList<Expression*>(1, zone()); | 257 new (zone()) ZoneList<Expression*>(1, zone()); |
264 tmp->Add(this_function_proxy, zone()); | |
265 Expression* super_constructor = factory()->NewCallRuntime( | |
266 Runtime::kInlineGetSuperConstructor, tmp, pos); | |
267 args->Add(super_constructor, zone()); | |
268 Spread* spread_args = factory()->NewSpread( | 258 Spread* spread_args = factory()->NewSpread( |
269 factory()->NewVariableProxy(constructor_args), pos, pos); | 259 factory()->NewVariableProxy(constructor_args), pos, pos); |
270 ZoneList<Expression*>* spread_args_expr = | 260 |
271 new (zone()) ZoneList<Expression*>(1, zone()); | 261 args->Add(spread_args, zone()); |
272 spread_args_expr->Add(spread_args, zone()); | 262 Expression* super_call_ref = NewSuperCallReference(pos); |
273 args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone()); | 263 Expression* call = factory()->NewCall(super_call_ref, args, pos); |
274 VariableProxy* new_target_proxy = | |
275 NewUnresolved(ast_value_factory()->new_target_string(), pos); | |
276 args->Add(new_target_proxy, zone()); | |
277 Expression* call = factory()->NewCallRuntime( | |
278 Context::REFLECT_CONSTRUCT_INDEX, args, pos); | |
279 if (requires_class_field_init) { | |
280 call = CallClassFieldInitializer(scope(), call); | |
281 } | |
282 body->Add(factory()->NewReturnStatement(call, pos), zone()); | 264 body->Add(factory()->NewReturnStatement(call, pos), zone()); |
283 } | 265 } |
284 | 266 |
285 materialized_literal_count = function_state.materialized_literal_count(); | 267 materialized_literal_count = function_state.materialized_literal_count(); |
286 expected_property_count = function_state.expected_property_count(); | 268 expected_property_count = function_state.expected_property_count(); |
287 } | 269 } |
288 | 270 |
289 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 271 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
290 name, function_scope, body, materialized_literal_count, | 272 name, function_scope, body, materialized_literal_count, |
291 expected_property_count, parameter_count, parameter_count, | 273 expected_property_count, parameter_count, parameter_count, |
(...skipping 3777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4069 } | 4051 } |
4070 UNREACHABLE(); | 4052 UNREACHABLE(); |
4071 } | 4053 } |
4072 | 4054 |
4073 Expression* Parser::SpreadCall(Expression* function, | 4055 Expression* Parser::SpreadCall(Expression* function, |
4074 ZoneList<Expression*>* args, int pos) { | 4056 ZoneList<Expression*>* args, int pos) { |
4075 if (function->IsSuperCallReference()) { | 4057 if (function->IsSuperCallReference()) { |
4076 // Super calls | 4058 // Super calls |
4077 // $super_constructor = %_GetSuperConstructor(<this-function>) | 4059 // $super_constructor = %_GetSuperConstructor(<this-function>) |
4078 // %reflect_construct($super_constructor, args, new.target) | 4060 // %reflect_construct($super_constructor, args, new.target) |
| 4061 |
| 4062 bool only_last_arg_is_spread = false; |
| 4063 for (int i = 0; i < args->length(); i++) { |
| 4064 if (args->at(i)->IsSpread()) { |
| 4065 if (i == args->length() - 1) { |
| 4066 only_last_arg_is_spread = true; |
| 4067 } |
| 4068 break; |
| 4069 } |
| 4070 } |
| 4071 |
| 4072 if (only_last_arg_is_spread) { |
| 4073 // Handle in BytecodeGenerator. |
| 4074 Expression* super_call_ref = NewSuperCallReference(pos); |
| 4075 return factory()->NewCall(super_call_ref, args, pos); |
| 4076 } |
| 4077 args = PrepareSpreadArguments(args); |
4079 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone()); | 4078 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone()); |
4080 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone()); | 4079 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone()); |
4081 Expression* super_constructor = factory()->NewCallRuntime( | 4080 Expression* super_constructor = factory()->NewCallRuntime( |
4082 Runtime::kInlineGetSuperConstructor, tmp, pos); | 4081 Runtime::kInlineGetSuperConstructor, tmp, pos); |
4083 args->InsertAt(0, super_constructor, zone()); | 4082 args->InsertAt(0, super_constructor, zone()); |
4084 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); | 4083 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); |
4085 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, | 4084 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, |
4086 pos); | 4085 pos); |
4087 } else { | 4086 } else { |
| 4087 args = PrepareSpreadArguments(args); |
4088 if (function->IsProperty()) { | 4088 if (function->IsProperty()) { |
4089 // Method calls | 4089 // Method calls |
4090 if (function->AsProperty()->IsSuperAccess()) { | 4090 if (function->AsProperty()->IsSuperAccess()) { |
4091 Expression* home = ThisExpression(kNoSourcePosition); | 4091 Expression* home = ThisExpression(kNoSourcePosition); |
4092 args->InsertAt(0, function, zone()); | 4092 args->InsertAt(0, function, zone()); |
4093 args->InsertAt(1, home, zone()); | 4093 args->InsertAt(1, home, zone()); |
4094 } else { | 4094 } else { |
4095 Variable* temp = NewTemporary(ast_value_factory()->empty_string()); | 4095 Variable* temp = NewTemporary(ast_value_factory()->empty_string()); |
4096 VariableProxy* obj = factory()->NewVariableProxy(temp); | 4096 VariableProxy* obj = factory()->NewVariableProxy(temp); |
4097 Assignment* assign_obj = factory()->NewAssignment( | 4097 Assignment* assign_obj = factory()->NewAssignment( |
(...skipping 10 matching lines...) Expand all Loading... |
4108 args->InsertAt(0, function, zone()); | 4108 args->InsertAt(0, function, zone()); |
4109 args->InsertAt(1, factory()->NewUndefinedLiteral(kNoSourcePosition), | 4109 args->InsertAt(1, factory()->NewUndefinedLiteral(kNoSourcePosition), |
4110 zone()); | 4110 zone()); |
4111 } | 4111 } |
4112 return factory()->NewCallRuntime(Context::REFLECT_APPLY_INDEX, args, pos); | 4112 return factory()->NewCallRuntime(Context::REFLECT_APPLY_INDEX, args, pos); |
4113 } | 4113 } |
4114 } | 4114 } |
4115 | 4115 |
4116 Expression* Parser::SpreadCallNew(Expression* function, | 4116 Expression* Parser::SpreadCallNew(Expression* function, |
4117 ZoneList<Expression*>* args, int pos) { | 4117 ZoneList<Expression*>* args, int pos) { |
| 4118 args = PrepareSpreadArguments(args); |
4118 args->InsertAt(0, function, zone()); | 4119 args->InsertAt(0, function, zone()); |
4119 | 4120 |
4120 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 4121 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
4121 } | 4122 } |
4122 | 4123 |
4123 | 4124 |
4124 void Parser::SetLanguageMode(Scope* scope, LanguageMode mode) { | 4125 void Parser::SetLanguageMode(Scope* scope, LanguageMode mode) { |
4125 v8::Isolate::UseCounterFeature feature; | 4126 v8::Isolate::UseCounterFeature feature; |
4126 if (is_sloppy(mode)) | 4127 if (is_sloppy(mode)) |
4127 feature = v8::Isolate::kSloppyMode; | 4128 feature = v8::Isolate::kSloppyMode; |
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5465 | 5466 |
5466 return final_loop; | 5467 return final_loop; |
5467 } | 5468 } |
5468 | 5469 |
5469 #undef CHECK_OK | 5470 #undef CHECK_OK |
5470 #undef CHECK_OK_VOID | 5471 #undef CHECK_OK_VOID |
5471 #undef CHECK_FAILED | 5472 #undef CHECK_FAILED |
5472 | 5473 |
5473 } // namespace internal | 5474 } // namespace internal |
5474 } // namespace v8 | 5475 } // namespace v8 |
OLD | NEW |