Chromium Code Reviews| Index: src/runtime/runtime-array.cc |
| diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc |
| index 51b8cb956b171519d16c3d96b941782b9c4a3cd2..b2f578911f5ce202651665481927f80e246e09c8 100644 |
| --- a/src/runtime/runtime-array.cc |
| +++ b/src/runtime/runtime-array.cc |
| @@ -635,11 +635,9 @@ RUNTIME_FUNCTION(Runtime_ArrayIndexOf) { |
| return Smi::FromInt(-1); |
| } |
| -RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) { |
| - HandleScope scope(isolate); |
| - DCHECK_EQ(1, args.length()); |
| - CONVERT_ARG_HANDLE_CHECKED(Object, spread, 0); |
| +namespace { |
| +bool mustIterate(Isolate* isolate, Handle<Object> spread) { |
|
Benedikt Meurer
2016/11/29 13:15:40
Nit: CamlCase.
petermarshall
2016/11/29 13:32:27
Done
|
| if (spread->IsJSArray()) { |
| // Check that the spread arg has fast elements |
| Handle<JSArray> spread_array = Handle<JSArray>::cast(spread); |
| @@ -653,19 +651,31 @@ RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) { |
| // If IsArrayIteratorLookupChainIntact(), then we know that the initial |
| // ArrayIterator is being used. If the map of the prototype has changed, |
| // then take the slow path. |
| - |
| if (isolate->is_initial_array_prototype(array_proto) && |
| isolate->IsArrayIteratorLookupChainIntact() && |
| isolate->is_initial_array_iterator_prototype_map(iterator_map)) { |
| if (IsFastPackedElementsKind(array_kind)) { |
| - return *spread; |
| + return false; |
| } |
| if (IsFastHoleyElementsKind(array_kind) && |
| isolate->IsFastArrayConstructorPrototypeChainIntact()) { |
| - return *spread; |
| + return false; |
| } |
| } |
| } |
| + return true; |
| +} |
| + |
| +} // namespace |
| + |
| +RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) { |
| + HandleScope scope(isolate); |
| + DCHECK_EQ(1, args.length()); |
| + CONVERT_ARG_HANDLE_CHECKED(Object, spread, 0); |
| + |
| + if (!mustIterate(isolate, spread)) { |
| + return *spread; |
| + } |
| Handle<JSFunction> spread_iterable_function = isolate->spread_iterable(); |
| @@ -678,5 +688,36 @@ RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) { |
| return *spreaded; |
| } |
| +RUNTIME_FUNCTION(Runtime_SpreadIterablePrepareVarArgs) { |
| + HandleScope scope(isolate); |
| + DCHECK_LE(2, args.length()); |
| + CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1); |
| + |
| + Handle<FixedArray> result = isolate->factory()->NewFixedArray(args.length()); |
| + for (int i = 0; i < args.length() - 1; i++) { |
| + result->set(i, *args.at<Object>(i)); |
| + } |
| + // Iterate over the spread if we need to. |
| + if (mustIterate(isolate, spread)) { |
| + 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)); |
| + } |
| + JSArray* spread_array = JSArray::cast(*spread); |
| + uint32_t length; |
| + spread_array->length()->ToArrayIndex(&length); |
|
Benedikt Meurer
2016/11/29 13:15:40
Nit: CHECK the result.
petermarshall
2016/11/29 13:32:27
Done
|
| + for (uint32_t i = 0; i < length; i++) { |
| + LookupIterator it(isolate, spread, i); |
| + result = FixedArray::SetAndGrow(result, args.length() - 1 + i, |
| + spread_array->GetDataProperty(&it)); |
| + } |
| + |
| + Handle<JSArray> r = isolate->factory()->NewJSArrayWithElements( |
| + result, FAST_ELEMENTS, args.length() - 1 + length); |
| + return *r; |
| +} |
| + |
| } // namespace internal |
| } // namespace v8 |