Commit c911517f authored by petermarshall's avatar petermarshall Committed by Commit bot

Refactor IterationHasObservableEffects to be more readable.

This was kind of hard to read due to the nesting. Refactor it using short-circuit
a bit more and add some comments to each bit.

Review-Url: https://codereview.chromium.org/2573283003
Cr-Commit-Position: refs/heads/master@{#41727}
parent 45d51734
...@@ -2177,32 +2177,37 @@ MaybeHandle<Object> Object::ArraySpeciesConstructor( ...@@ -2177,32 +2177,37 @@ MaybeHandle<Object> Object::ArraySpeciesConstructor(
} }
bool Object::IterationHasObservableEffects() { bool Object::IterationHasObservableEffects() {
if (IsJSArray()) { // Check that this object is an array.
// Check that the spread arg has fast elements if (!IsJSArray()) return true;
JSArray* spread_array = JSArray::cast(this); JSArray* spread_array = JSArray::cast(this);
ElementsKind array_kind = spread_array->GetElementsKind();
Isolate* isolate = spread_array->GetIsolate(); Isolate* isolate = spread_array->GetIsolate();
// And that it has the orignal ArrayPrototype // Check that we have the original ArrayPrototype.
JSObject* array_proto = JSObject::cast(spread_array->map()->prototype()); JSObject* array_proto = JSObject::cast(spread_array->map()->prototype());
Map* iterator_map = isolate->initial_array_iterator_prototype()->map(); if (!isolate->is_initial_array_prototype(array_proto)) return true;
// Check that the iterator acts as expected. // Check that the ArrayPrototype hasn't been modified in a way that would
// If IsArrayIteratorLookupChainIntact(), then we know that the initial // affect iteration.
// ArrayIterator is being used. If the map of the prototype has changed, if (!isolate->IsArrayIteratorLookupChainIntact()) return true;
// then take the slow path.
if (isolate->is_initial_array_prototype(array_proto) && // Check that the map of the initial array iterator hasn't changed.
isolate->IsArrayIteratorLookupChainIntact() && Map* iterator_map = isolate->initial_array_iterator_prototype()->map();
isolate->is_initial_array_iterator_prototype_map(iterator_map)) { if (!isolate->is_initial_array_iterator_prototype_map(iterator_map)) {
if (IsFastPackedElementsKind(array_kind)) { return true;
return false;
} }
// For FastPacked kinds, iteration will have the same effect as simply
// accessing each property in order.
ElementsKind array_kind = spread_array->GetElementsKind();
if (IsFastPackedElementsKind(array_kind)) return false;
// For FastHoley kinds, an element access on a hole would cause a lookup on
// the prototype. This could have different results if the prototype has been
// changed.
if (IsFastHoleyElementsKind(array_kind) && if (IsFastHoleyElementsKind(array_kind) &&
isolate->IsFastArrayConstructorPrototypeChainIntact()) { isolate->IsFastArrayConstructorPrototypeChainIntact()) {
return false; return false;
} }
}
}
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment