Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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_NewWithSpread) { | |
| 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->IterationHasObservableEffects()) { | |
| 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 uint32_t spread_length; | |
| 410 Handle<JSArray> spread_array = Handle<JSArray>::cast(spread); | |
| 411 CHECK(spread_array->length()->ToArrayIndex(&spread_length)); | |
| 412 int result_length = constructor_argc - 1 + spread_length; | |
| 413 ScopedVector<Handle<Object>> construct_args(result_length); | |
| 414 | |
| 415 // Append each of the individual args to the result. | |
| 416 for (int i = 0; i < constructor_argc - 1; i++) { | |
| 417 construct_args[i] = args.at<Object>(2 + i); | |
| 418 } | |
| 419 | |
| 420 // Append element of the spread to the result. | |
| 421 for (uint32_t i = 0; i < spread_length; i++) { | |
|
Benedikt Meurer
2016/12/07 07:32:40
Can you add a TODO here to eventually use ElementA
| |
| 422 LookupIterator it(isolate, spread, i); | |
| 423 Handle<Object> element = spread_array->GetDataProperty(&it); | |
| 424 construct_args[constructor_argc - 1 + i] = element; | |
| 425 } | |
| 426 | |
| 427 // Call the constructor. | |
| 428 RETURN_RESULT_OR_FAILURE( | |
| 429 isolate, Execution::New(isolate, constructor, new_target, result_length, | |
| 430 construct_args.start())); | |
| 431 } | |
| 432 | |
| 391 } // namespace internal | 433 } // namespace internal |
| 392 } // namespace v8 | 434 } // namespace v8 |
| OLD | NEW |