Chromium Code Reviews| Index: src/runtime/runtime-array.cc |
| diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc |
| index ef177fec4c193e0fa9e83f63d680353924d68e7a..3013b7e4d6c96f79729e876f0ba170daca602be9 100644 |
| --- a/src/runtime/runtime-array.cc |
| +++ b/src/runtime/runtime-array.cc |
| @@ -628,5 +628,52 @@ RUNTIME_FUNCTION(Runtime_ArrayIndexOf) { |
| return Smi::FromInt(-1); |
| } |
| +namespace { |
| + |
| +bool IteratorProtoMapUnchanged(Isolate* isolate) { |
| + Map* current_map = isolate->initial_array_iterator_prototype()->map(); |
| + Map* original_map = *isolate->initial_array_iterator_prototype_map(); |
| + |
| + return current_map == original_map; |
| +} |
| + |
| +} // namepsace |
| + |
| +RUNTIME_FUNCTION(Runtime_SpreadIterablePrepare) { |
| + HandleScope scope(isolate); |
| + DCHECK_EQ(1, args.length()); |
| + CONVERT_ARG_HANDLE_CHECKED(Object, spread, 0); |
| + |
| + if (spread->IsJSArray()) { |
| + // Check that the spread arg has fast elements |
| + Handle<JSArray> spread_array = Handle<JSArray>::cast(spread); |
| + ElementsKind array_kind = spread_array->GetElementsKind(); |
| + |
| + // And that it has the orignal ArrayPrototype |
| + Object* current_proto = spread_array->map()->prototype(); |
| + Object* original_proto = *isolate->initial_array_prototype(); |
|
Yang
2016/11/14 12:59:01
this unnecessarily wraps the context field into a
petermarshall
2016/11/14 13:37:19
That is much nicer, and we can do it for checking
|
| + |
| + // Check that the iterator acts as expected. |
| + // 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 (IsFastElementsKind(array_kind) && current_proto == original_proto && |
| + isolate->IsArrayIteratorLookupChainIntact() && |
| + IteratorProtoMapUnchanged(isolate)) { |
| + return *spread; |
| + } |
| + } |
| + |
| + Handle<JSFunction> spread_iterable_function = isolate->spread_iterable(); |
| + |
| + Handle<Object> spreaded; |
| + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| + isolate, spreaded, |
| + Execution::Call(isolate, spread_iterable_function, |
| + isolate->factory()->undefined_value(), 1, &spread)); |
| + |
| + return *spreaded; |
| +} |
| + |
| } // namespace internal |
| } // namespace v8 |