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 "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
10 #include "src/elements.h" | 10 #include "src/elements.h" |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable(); | 641 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable(); |
642 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 642 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
643 isolate, spread, | 643 isolate, spread, |
644 Execution::Call(isolate, spread_iterable_function, | 644 Execution::Call(isolate, spread_iterable_function, |
645 isolate->factory()->undefined_value(), 1, &spread)); | 645 isolate->factory()->undefined_value(), 1, &spread)); |
646 } | 646 } |
647 | 647 |
648 return *spread; | 648 return *spread; |
649 } | 649 } |
650 | 650 |
| 651 RUNTIME_FUNCTION(Runtime_SpreadIterableFixed) { |
| 652 HandleScope scope(isolate); |
| 653 DCHECK_EQ(1, args.length()); |
| 654 CONVERT_ARG_HANDLE_CHECKED(Object, spread, 0); |
| 655 |
| 656 // The caller should check if proper iteration is necessary. |
| 657 Handle<JSFunction> spread_iterable_function = isolate->spread_iterable(); |
| 658 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 659 isolate, spread, |
| 660 Execution::Call(isolate, spread_iterable_function, |
| 661 isolate->factory()->undefined_value(), 1, &spread)); |
| 662 |
| 663 // Create a new FixedArray and put the result of the spread into it. |
| 664 Handle<JSArray> spread_array = Handle<JSArray>::cast(spread); |
| 665 uint32_t spread_length; |
| 666 CHECK(spread_array->length()->ToArrayIndex(&spread_length)); |
| 667 |
| 668 Handle<FixedArray> result = isolate->factory()->NewFixedArray(spread_length); |
| 669 ElementsAccessor* accessor = spread_array->GetElementsAccessor(); |
| 670 for (uint32_t i = 0; i < spread_length; i++) { |
| 671 DCHECK(accessor->HasElement(spread_array, i)); |
| 672 Handle<Object> element = accessor->Get(spread_array, i); |
| 673 result->set(i, *element); |
| 674 } |
| 675 |
| 676 return *result; |
| 677 } |
| 678 |
651 } // namespace internal | 679 } // namespace internal |
652 } // namespace v8 | 680 } // namespace v8 |
OLD | NEW |