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

Side by Side Diff: src/parsing/parser.cc

Issue 2540593003: Move desugaring of super calls with trailing spread to one runtime call. (Closed)
Patch Set: Change some comments and simplify an else Created 4 years 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
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/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
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 3809 matching lines...) Expand 10 before | Expand all | Expand 10 after
4101 } 4083 }
4102 UNREACHABLE(); 4084 UNREACHABLE();
4103 } 4085 }
4104 4086
4105 Expression* Parser::SpreadCall(Expression* function, 4087 Expression* Parser::SpreadCall(Expression* function,
4106 ZoneList<Expression*>* args, int pos) { 4088 ZoneList<Expression*>* args, int pos) {
4107 if (function->IsSuperCallReference()) { 4089 if (function->IsSuperCallReference()) {
4108 // Super calls 4090 // Super calls
4109 // $super_constructor = %_GetSuperConstructor(<this-function>) 4091 // $super_constructor = %_GetSuperConstructor(<this-function>)
4110 // %reflect_construct($super_constructor, args, new.target) 4092 // %reflect_construct($super_constructor, args, new.target)
4093
4094 bool only_last_arg_is_spread = false;
4095 for (int i = 0; i < args->length(); i++) {
4096 if (args->at(i)->IsSpread()) {
4097 if (i == args->length() - 1) {
4098 only_last_arg_is_spread = true;
4099 }
4100 break;
4101 }
4102 }
4103
4104 if (only_last_arg_is_spread) {
4105 // Handle in BytecodeGenerator
4106 Expression* super_call_ref = NewSuperCallReference(pos);
4107 return factory()->NewCall(super_call_ref, args, pos);
4108 }
4109 args = PrepareSpreadArguments(args);
4111 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone()); 4110 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone());
4112 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone()); 4111 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone());
4113 Expression* super_constructor = factory()->NewCallRuntime( 4112 Expression* super_constructor = factory()->NewCallRuntime(
4114 Runtime::kInlineGetSuperConstructor, tmp, pos); 4113 Runtime::kInlineGetSuperConstructor, tmp, pos);
4115 args->InsertAt(0, super_constructor, zone()); 4114 args->InsertAt(0, super_constructor, zone());
4116 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); 4115 args->Add(function->AsSuperCallReference()->new_target_var(), zone());
4117 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, 4116 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args,
4118 pos); 4117 pos);
4119 } else { 4118 } else {
4119 args = PrepareSpreadArguments(args);
4120 if (function->IsProperty()) { 4120 if (function->IsProperty()) {
4121 // Method calls 4121 // Method calls
4122 if (function->AsProperty()->IsSuperAccess()) { 4122 if (function->AsProperty()->IsSuperAccess()) {
4123 Expression* home = ThisExpression(kNoSourcePosition); 4123 Expression* home = ThisExpression(kNoSourcePosition);
4124 args->InsertAt(0, function, zone()); 4124 args->InsertAt(0, function, zone());
4125 args->InsertAt(1, home, zone()); 4125 args->InsertAt(1, home, zone());
4126 } else { 4126 } else {
4127 Variable* temp = NewTemporary(ast_value_factory()->empty_string()); 4127 Variable* temp = NewTemporary(ast_value_factory()->empty_string());
4128 VariableProxy* obj = factory()->NewVariableProxy(temp); 4128 VariableProxy* obj = factory()->NewVariableProxy(temp);
4129 Assignment* assign_obj = factory()->NewAssignment( 4129 Assignment* assign_obj = factory()->NewAssignment(
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after
5502 5502
5503 return final_loop; 5503 return final_loop;
5504 } 5504 }
5505 5505
5506 #undef CHECK_OK 5506 #undef CHECK_OK
5507 #undef CHECK_OK_VOID 5507 #undef CHECK_OK_VOID
5508 #undef CHECK_FAILED 5508 #undef CHECK_FAILED
5509 5509
5510 } // namespace internal 5510 } // namespace internal
5511 } // namespace v8 5511 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698