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/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); | 452 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); |
453 Object* prototype = active_function->map()->prototype(); | 453 Object* prototype = active_function->map()->prototype(); |
454 if (!prototype->IsConstructor()) { | 454 if (!prototype->IsConstructor()) { |
455 HandleScope scope(isolate); | 455 HandleScope scope(isolate); |
456 return ThrowNotSuperConstructor(isolate, handle(prototype, isolate), | 456 return ThrowNotSuperConstructor(isolate, handle(prototype, isolate), |
457 handle(active_function, isolate)); | 457 handle(active_function, isolate)); |
458 } | 458 } |
459 return prototype; | 459 return prototype; |
460 } | 460 } |
461 | 461 |
| 462 RUNTIME_FUNCTION(Runtime_CallWithSpread) { |
| 463 HandleScope scope(isolate); |
| 464 DCHECK_LE(3, args.length()); |
| 465 CONVERT_ARG_HANDLE_CHECKED(Object, callable, 0); |
| 466 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); |
| 467 |
| 468 int function_argc = args.length() - 2; |
| 469 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1); |
| 470 |
| 471 // Iterate over the spread if we need to. |
| 472 if (spread->IterationHasObservableEffects()) { |
| 473 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable(); |
| 474 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 475 isolate, spread, |
| 476 Execution::Call(isolate, spread_iterable_function, |
| 477 isolate->factory()->undefined_value(), 1, &spread)); |
| 478 } |
| 479 |
| 480 uint32_t spread_length; |
| 481 Handle<JSArray> spread_array = Handle<JSArray>::cast(spread); |
| 482 CHECK(spread_array->length()->ToArrayIndex(&spread_length)); |
| 483 int result_length = function_argc - 1 + spread_length; |
| 484 ScopedVector<Handle<Object>> function_args(result_length); |
| 485 |
| 486 // Append each of the individual args to the result. |
| 487 for (int i = 0; i < function_argc - 1; i++) { |
| 488 function_args[i] = args.at<Object>(2 + i); |
| 489 } |
| 490 |
| 491 // Append element of the spread to the result. |
| 492 ElementsAccessor* accessor = spread_array->GetElementsAccessor(); |
| 493 for (uint32_t i = 0; i < spread_length; i++) { |
| 494 DCHECK(accessor->HasElement(spread_array, i)); |
| 495 Handle<Object> element = accessor->Get(spread_array, i); |
| 496 function_args[function_argc - 1 + i] = element; |
| 497 } |
| 498 |
| 499 // Call the function. |
| 500 RETURN_RESULT_OR_FAILURE( |
| 501 isolate, Execution::Call(isolate, callable, receiver, result_length, |
| 502 function_args.start())); |
| 503 } |
| 504 |
462 } // namespace internal | 505 } // namespace internal |
463 } // namespace v8 | 506 } // namespace v8 |
OLD | NEW |