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