| Index: src/runtime/runtime-classes.cc
|
| diff --git a/src/runtime/runtime-classes.cc b/src/runtime/runtime-classes.cc
|
| index aafd7779870f74cbd9bc2e5380b79f4842e8638b..f433edf26dd73c9e24763703ad092a7aa5b0376c 100644
|
| --- a/src/runtime/runtime-classes.cc
|
| +++ b/src/runtime/runtime-classes.cc
|
| @@ -388,5 +388,47 @@ RUNTIME_FUNCTION(Runtime_GetSuperConstructor) {
|
| return active_function->map()->prototype();
|
| }
|
|
|
| +RUNTIME_FUNCTION(Runtime_ConstructWithSpread) {
|
| + HandleScope scope(isolate);
|
| + DCHECK_LE(3, args.length());
|
| + CONVERT_ARG_HANDLE_CHECKED(JSReceiver, constructor, 0);
|
| + CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 1);
|
| +
|
| + int constructor_argc = args.length() - 2;
|
| + CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1);
|
| +
|
| + // Iterate over the spread if we need to.
|
| + if (spread->CanUseElementsInsteadOfIteration()) {
|
| + Handle<JSFunction> spread_iterable_function = isolate->spread_iterable();
|
| + ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
| + isolate, spread,
|
| + Execution::Call(isolate, spread_iterable_function,
|
| + isolate->factory()->undefined_value(), 1, &spread));
|
| + }
|
| +
|
| + uint32_t spread_length;
|
| + Handle<JSArray> spread_array = Handle<JSArray>::cast(spread);
|
| + CHECK(spread_array->length()->ToArrayIndex(&spread_length));
|
| + int result_length = constructor_argc - 1 + spread_length;
|
| + ScopedVector<Handle<Object>> construct_args(result_length);
|
| +
|
| + // Append each of the individual args to the result.
|
| + for (int i = 0; i < constructor_argc - 1; i++) {
|
| + construct_args[i] = args.at<Object>(2 + i);
|
| + }
|
| +
|
| + // Append element of the spread to the result.
|
| + for (uint32_t i = 0; i < spread_length; i++) {
|
| + LookupIterator it(isolate, spread, i);
|
| + Handle<Object> element = spread_array->GetDataProperty(&it);
|
| + construct_args[constructor_argc - 1 + i] = element;
|
| + }
|
| +
|
| + // Call the constructor.
|
| + RETURN_RESULT_OR_FAILURE(
|
| + isolate, Execution::New(isolate, constructor, new_target, result_length,
|
| + construct_args.start()));
|
| +}
|
| +
|
| } // namespace internal
|
| } // namespace v8
|
|
|