OLD | NEW |
---|---|
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 Loading... | |
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 // TODO(petermarshall): We probably need to add a protector to the initial |
2195 isolate->IsArrayIteratorLookupChainIntact() && | 2194 // array iterator just like the array prototype, because there are some |
2196 isolate->is_initial_array_iterator_prototype_map(iterator_map)) { | 2195 // changes that a map check won't recognize. |
Michael Starzinger
2016/12/15 15:05:39
question: Not sure about this TODO, which changes
| |
2197 if (IsFastPackedElementsKind(array_kind)) { | 2196 |
2198 return false; | 2197 // Check that the map of the initial array iterator hasn't changed. |
2199 } | 2198 Map* iterator_map = isolate->initial_array_iterator_prototype()->map(); |
2200 if (IsFastHoleyElementsKind(array_kind) && | 2199 if (!isolate->is_initial_array_iterator_prototype_map(iterator_map)) { |
2201 isolate->IsFastArrayConstructorPrototypeChainIntact()) { | 2200 return true; |
2202 return false; | 2201 } |
2203 } | 2202 |
2204 } | 2203 // For FastPacked kinds, iteration will have the same effect as simply |
2204 // accessing each property in order. | |
2205 ElementsKind array_kind = spread_array->GetElementsKind(); | |
2206 if (IsFastPackedElementsKind(array_kind)) return false; | |
2207 | |
2208 // For FastHoley kinds, an element access on a hole would cause a lookup on | |
2209 // the prototype. This could have different results if the prototype has been | |
2210 // changed. | |
2211 if (IsFastHoleyElementsKind(array_kind) && | |
2212 isolate->IsFastArrayConstructorPrototypeChainIntact()) { | |
2213 return false; | |
2205 } | 2214 } |
2206 return true; | 2215 return true; |
2207 } | 2216 } |
2208 | 2217 |
2209 void Object::ShortPrint(FILE* out) { | 2218 void Object::ShortPrint(FILE* out) { |
2210 OFStream os(out); | 2219 OFStream os(out); |
2211 os << Brief(this); | 2220 os << Brief(this); |
2212 } | 2221 } |
2213 | 2222 |
2214 | 2223 |
(...skipping 18196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20411 // depend on this. | 20420 // depend on this. |
20412 return DICTIONARY_ELEMENTS; | 20421 return DICTIONARY_ELEMENTS; |
20413 } | 20422 } |
20414 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20423 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
20415 return kind; | 20424 return kind; |
20416 } | 20425 } |
20417 } | 20426 } |
20418 | 20427 |
20419 } // namespace internal | 20428 } // namespace internal |
20420 } // namespace v8 | 20429 } // namespace v8 |
OLD | NEW |