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

Side by Side Diff: src/runtime/runtime-classes.cc

Issue 2541113004: [Ignition/turbo] Add a NewWithSpread bytecode. (Closed)
Patch Set: Move MustIterate to Object 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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <limits> 8 #include <limits>
9 9
10 #include "src/arguments.h" 10 #include "src/arguments.h"
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 381 }
382 382
383 383
384 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { 384 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) {
385 SealHandleScope shs(isolate); 385 SealHandleScope shs(isolate);
386 DCHECK_EQ(1, args.length()); 386 DCHECK_EQ(1, args.length());
387 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); 387 CONVERT_ARG_CHECKED(JSFunction, active_function, 0);
388 return active_function->map()->prototype(); 388 return active_function->map()->prototype();
389 } 389 }
390 390
391 RUNTIME_FUNCTION(Runtime_ConstructWithSpread) {
392 HandleScope scope(isolate);
393 DCHECK_LE(3, args.length());
394 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, constructor, 0);
395 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 1);
396
397 int constructor_argc = args.length() - 2;
398 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1);
399
400 // Iterate over the spread if we need to.
401 if (spread->MustIterate()) {
402 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable();
403 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
404 isolate, spread,
405 Execution::Call(isolate, spread_iterable_function,
406 isolate->factory()->undefined_value(), 1, &spread));
407 }
408
409 Handle<JSArray> spread_array = Handle<JSArray>::cast(spread);
410 if (constructor_argc > 1) {
411 uint32_t spread_length;
412 CHECK(spread_array->length()->ToArrayIndex(&spread_length));
413
414 // Append each of the individual args to the result.
415 int result_length = constructor_argc - 1 + spread_length;
416 Handle<FixedArray> args_array =
417 isolate->factory()->NewFixedArray(result_length);
418 for (int i = 0; i < constructor_argc - 1; i++) {
419 args_array->set(i, *args.at<Object>(2 + i));
420 }
421
422 // Append element of the spread to the result.
423 for (uint32_t i = 0; i < spread_length; i++) {
424 LookupIterator it(isolate, spread, i);
425 Handle<Object> element = spread_array->GetDataProperty(&it);
426 args_array->set(constructor_argc - 1 + i, *element);
427 }
428
429 spread_array = isolate->factory()->NewJSArrayWithElements(
430 args_array, FAST_ELEMENTS, result_length);
431 }
432
433 // Call ReflectConstruct to do the actual super constructor call.
Benedikt Meurer 2016/12/05 11:42:10 It'd be nice to use Execution::New directly here,
petermarshall 2016/12/05 13:30:46 That is nice, I think we avoid allocating that JS
434 Handle<Object> construct_args[] = {constructor, spread_array, new_target};
435 Handle<Object> result;
436 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
437 isolate, result, Execution::Call(isolate, isolate->reflect_construct(),
438 isolate->factory()->undefined_value(), 3,
439 construct_args));
440 return *result;
441 }
442
391 } // namespace internal 443 } // namespace internal
392 } // namespace v8 444 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698