| 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 8481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8492 ? Smi::cast(JSArray::cast(object)->length())->value() | 8492 ? Smi::cast(JSArray::cast(object)->length())->value() |
| 8493 : object->elements()->length(); | 8493 : object->elements()->length(); |
| 8494 return length > 0; | 8494 return length > 0; |
| 8495 } | 8495 } |
| 8496 case FAST_HOLEY_SMI_ELEMENTS: | 8496 case FAST_HOLEY_SMI_ELEMENTS: |
| 8497 case FAST_HOLEY_ELEMENTS: { | 8497 case FAST_HOLEY_ELEMENTS: { |
| 8498 FixedArray* elements = FixedArray::cast(object->elements()); | 8498 FixedArray* elements = FixedArray::cast(object->elements()); |
| 8499 int length = object->IsJSArray() | 8499 int length = object->IsJSArray() |
| 8500 ? Smi::cast(JSArray::cast(object)->length())->value() | 8500 ? Smi::cast(JSArray::cast(object)->length())->value() |
| 8501 : elements->length(); | 8501 : elements->length(); |
| 8502 Isolate* isolate = GetIsolate(); |
| 8502 for (int i = 0; i < length; i++) { | 8503 for (int i = 0; i < length; i++) { |
| 8503 if (!elements->is_the_hole(i)) return true; | 8504 if (!elements->is_the_hole(isolate, i)) return true; |
| 8504 } | 8505 } |
| 8505 return false; | 8506 return false; |
| 8506 } | 8507 } |
| 8507 case FAST_HOLEY_DOUBLE_ELEMENTS: { | 8508 case FAST_HOLEY_DOUBLE_ELEMENTS: { |
| 8508 int length = object->IsJSArray() | 8509 int length = object->IsJSArray() |
| 8509 ? Smi::cast(JSArray::cast(object)->length())->value() | 8510 ? Smi::cast(JSArray::cast(object)->length())->value() |
| 8510 : object->elements()->length(); | 8511 : object->elements()->length(); |
| 8511 // Zero-length arrays would use the empty FixedArray... | 8512 // Zero-length arrays would use the empty FixedArray... |
| 8512 if (length == 0) return false; | 8513 if (length == 0) return false; |
| 8513 // ...so only cast to FixedDoubleArray otherwise. | 8514 // ...so only cast to FixedDoubleArray otherwise. |
| (...skipping 7549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16063 uint32_t index) { | 16064 uint32_t index) { |
| 16064 uint32_t length = 0; | 16065 uint32_t length = 0; |
| 16065 CHECK(array->length()->ToArrayLength(&length)); | 16066 CHECK(array->length()->ToArrayLength(&length)); |
| 16066 if (length <= index) return HasReadOnlyLength(array); | 16067 if (length <= index) return HasReadOnlyLength(array); |
| 16067 return false; | 16068 return false; |
| 16068 } | 16069 } |
| 16069 | 16070 |
| 16070 | 16071 |
| 16071 template <typename BackingStore> | 16072 template <typename BackingStore> |
| 16072 static int FastHoleyElementsUsage(JSObject* object, BackingStore* store) { | 16073 static int FastHoleyElementsUsage(JSObject* object, BackingStore* store) { |
| 16074 Isolate* isolate = store->GetIsolate(); |
| 16073 int limit = object->IsJSArray() | 16075 int limit = object->IsJSArray() |
| 16074 ? Smi::cast(JSArray::cast(object)->length())->value() | 16076 ? Smi::cast(JSArray::cast(object)->length())->value() |
| 16075 : store->length(); | 16077 : store->length(); |
| 16076 int used = 0; | 16078 int used = 0; |
| 16077 for (int i = 0; i < limit; ++i) { | 16079 for (int i = 0; i < limit; ++i) { |
| 16078 if (!store->is_the_hole(i)) ++used; | 16080 if (!store->is_the_hole(isolate, i)) ++used; |
| 16079 } | 16081 } |
| 16080 return used; | 16082 return used; |
| 16081 } | 16083 } |
| 16082 | 16084 |
| 16083 | 16085 |
| 16084 int JSObject::GetFastElementsUsage() { | 16086 int JSObject::GetFastElementsUsage() { |
| 16085 FixedArrayBase* store = elements(); | 16087 FixedArrayBase* store = elements(); |
| 16086 switch (GetElementsKind()) { | 16088 switch (GetElementsKind()) { |
| 16087 case FAST_SMI_ELEMENTS: | 16089 case FAST_SMI_ELEMENTS: |
| 16088 case FAST_DOUBLE_ELEMENTS: | 16090 case FAST_DOUBLE_ELEMENTS: |
| (...skipping 4251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20340 // Check if the accessor uses a cached property. | 20342 // Check if the accessor uses a cached property. |
| 20341 if (!fti->cached_property_name()->IsTheHole(isolate)) { | 20343 if (!fti->cached_property_name()->IsTheHole(isolate)) { |
| 20342 return handle(Name::cast(fti->cached_property_name())); | 20344 return handle(Name::cast(fti->cached_property_name())); |
| 20343 } | 20345 } |
| 20344 } | 20346 } |
| 20345 return MaybeHandle<Name>(); | 20347 return MaybeHandle<Name>(); |
| 20346 } | 20348 } |
| 20347 | 20349 |
| 20348 } // namespace internal | 20350 } // namespace internal |
| 20349 } // namespace v8 | 20351 } // namespace v8 |
| OLD | NEW |