Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: src/objects.cc

Issue 2573283003: Refactor IterationHasObservableEffects to be more readable. (Closed)
Patch Set: remove potentially confusing todo Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 2159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2170 if (!constructor->IsConstructor()) { 2170 if (!constructor->IsConstructor()) {
2171 THROW_NEW_ERROR(isolate, 2171 THROW_NEW_ERROR(isolate,
2172 NewTypeError(MessageTemplate::kSpeciesNotConstructor), 2172 NewTypeError(MessageTemplate::kSpeciesNotConstructor),
2173 Object); 2173 Object);
2174 } 2174 }
2175 return constructor; 2175 return constructor;
2176 } 2176 }
2177 } 2177 }
2178 2178
2179 bool Object::IterationHasObservableEffects() { 2179 bool Object::IterationHasObservableEffects() {
2180 if (IsJSArray()) { 2180 // Check that this object is an array.
2181 // Check that the spread arg has fast elements 2181 if (!IsJSArray()) return true;
2182 JSArray* spread_array = JSArray::cast(this); 2182 JSArray* spread_array = JSArray::cast(this);
2183 ElementsKind array_kind = spread_array->GetElementsKind(); 2183 Isolate* isolate = spread_array->GetIsolate();
2184 Isolate* isolate = spread_array->GetIsolate();
2185 2184
2186 // And that it has the orignal ArrayPrototype 2185 // Check that we have the original ArrayPrototype.
2187 JSObject* array_proto = JSObject::cast(spread_array->map()->prototype()); 2186 JSObject* array_proto = JSObject::cast(spread_array->map()->prototype());
2188 Map* iterator_map = isolate->initial_array_iterator_prototype()->map(); 2187 if (!isolate->is_initial_array_prototype(array_proto)) return true;
2189 2188
2190 // Check that the iterator acts as expected. 2189 // Check that the ArrayPrototype hasn't been modified in a way that would
2191 // If IsArrayIteratorLookupChainIntact(), then we know that the initial 2190 // affect iteration.
2192 // ArrayIterator is being used. If the map of the prototype has changed, 2191 if (!isolate->IsArrayIteratorLookupChainIntact()) return true;
2193 // then take the slow path. 2192
2194 if (isolate->is_initial_array_prototype(array_proto) && 2193 // Check that the map of the initial array iterator hasn't changed.
2195 isolate->IsArrayIteratorLookupChainIntact() && 2194 Map* iterator_map = isolate->initial_array_iterator_prototype()->map();
2196 isolate->is_initial_array_iterator_prototype_map(iterator_map)) { 2195 if (!isolate->is_initial_array_iterator_prototype_map(iterator_map)) {
2197 if (IsFastPackedElementsKind(array_kind)) { 2196 return true;
2198 return false; 2197 }
2199 } 2198
2200 if (IsFastHoleyElementsKind(array_kind) && 2199 // For FastPacked kinds, iteration will have the same effect as simply
2201 isolate->IsFastArrayConstructorPrototypeChainIntact()) { 2200 // accessing each property in order.
2202 return false; 2201 ElementsKind array_kind = spread_array->GetElementsKind();
2203 } 2202 if (IsFastPackedElementsKind(array_kind)) return false;
2204 } 2203
2204 // For FastHoley kinds, an element access on a hole would cause a lookup on
2205 // the prototype. This could have different results if the prototype has been
2206 // changed.
2207 if (IsFastHoleyElementsKind(array_kind) &&
2208 isolate->IsFastArrayConstructorPrototypeChainIntact()) {
2209 return false;
2205 } 2210 }
2206 return true; 2211 return true;
2207 } 2212 }
2208 2213
2209 void Object::ShortPrint(FILE* out) { 2214 void Object::ShortPrint(FILE* out) {
2210 OFStream os(out); 2215 OFStream os(out);
2211 os << Brief(this); 2216 os << Brief(this);
2212 } 2217 }
2213 2218
2214 2219
(...skipping 18196 matching lines...) Expand 10 before | Expand all | Expand 10 after
20411 // depend on this. 20416 // depend on this.
20412 return DICTIONARY_ELEMENTS; 20417 return DICTIONARY_ELEMENTS;
20413 } 20418 }
20414 DCHECK_LE(kind, LAST_ELEMENTS_KIND); 20419 DCHECK_LE(kind, LAST_ELEMENTS_KIND);
20415 return kind; 20420 return kind;
20416 } 20421 }
20417 } 20422 }
20418 20423
20419 } // namespace internal 20424 } // namespace internal
20420 } // namespace v8 20425 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698