| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 // Review notes: | 5 // Review notes: |
| 6 // | 6 // |
| 7 // - The use of macros in these inline functions may seem superfluous | 7 // - The use of macros in these inline functions may seem superfluous |
| 8 // but it is absolutely needed to make sure gcc generates optimal | 8 // but it is absolutely needed to make sure gcc generates optimal |
| 9 // code. gcc is not happy when attempting to inline too deep. | 9 // code. gcc is not happy when attempting to inline too deep. |
| 10 // | 10 // |
| (...skipping 1936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1947 TransitionElementsKind(object, FAST_DOUBLE_ELEMENTS); | 1947 TransitionElementsKind(object, FAST_DOUBLE_ELEMENTS); |
| 1948 } | 1948 } |
| 1949 } | 1949 } |
| 1950 | 1950 |
| 1951 | 1951 |
| 1952 void JSObject::SetMapAndElements(Handle<JSObject> object, | 1952 void JSObject::SetMapAndElements(Handle<JSObject> object, |
| 1953 Handle<Map> new_map, | 1953 Handle<Map> new_map, |
| 1954 Handle<FixedArrayBase> value) { | 1954 Handle<FixedArrayBase> value) { |
| 1955 JSObject::MigrateToMap(object, new_map); | 1955 JSObject::MigrateToMap(object, new_map); |
| 1956 DCHECK((object->map()->has_fast_smi_or_object_elements() || | 1956 DCHECK((object->map()->has_fast_smi_or_object_elements() || |
| 1957 (*value == object->GetHeap()->empty_fixed_array())) == | 1957 (*value == object->GetHeap()->empty_fixed_array()) || |
| 1958 object->map()->has_fast_string_wrapper_elements()) == |
| 1958 (value->map() == object->GetHeap()->fixed_array_map() || | 1959 (value->map() == object->GetHeap()->fixed_array_map() || |
| 1959 value->map() == object->GetHeap()->fixed_cow_array_map())); | 1960 value->map() == object->GetHeap()->fixed_cow_array_map())); |
| 1960 DCHECK((*value == object->GetHeap()->empty_fixed_array()) || | 1961 DCHECK((*value == object->GetHeap()->empty_fixed_array()) || |
| 1961 (object->map()->has_fast_double_elements() == | 1962 (object->map()->has_fast_double_elements() == |
| 1962 value->IsFixedDoubleArray())); | 1963 value->IsFixedDoubleArray())); |
| 1963 object->set_elements(*value); | 1964 object->set_elements(*value); |
| 1964 } | 1965 } |
| 1965 | 1966 |
| 1966 | 1967 |
| 1967 void JSObject::set_elements(FixedArrayBase* value, WriteBarrierMode mode) { | 1968 void JSObject::set_elements(FixedArrayBase* value, WriteBarrierMode mode) { |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2329 | 2330 |
| 2330 | 2331 |
| 2331 bool Object::ToArrayLength(uint32_t* index) { return Object::ToUint32(index); } | 2332 bool Object::ToArrayLength(uint32_t* index) { return Object::ToUint32(index); } |
| 2332 | 2333 |
| 2333 | 2334 |
| 2334 bool Object::ToArrayIndex(uint32_t* index) { | 2335 bool Object::ToArrayIndex(uint32_t* index) { |
| 2335 return Object::ToUint32(index) && *index != kMaxUInt32; | 2336 return Object::ToUint32(index) && *index != kMaxUInt32; |
| 2336 } | 2337 } |
| 2337 | 2338 |
| 2338 | 2339 |
| 2339 bool Object::IsStringObjectWithCharacterAt(uint32_t index) { | |
| 2340 if (!this->IsJSValue()) return false; | |
| 2341 | |
| 2342 JSValue* js_value = JSValue::cast(this); | |
| 2343 if (!js_value->value()->IsString()) return false; | |
| 2344 | |
| 2345 String* str = String::cast(js_value->value()); | |
| 2346 if (index >= static_cast<uint32_t>(str->length())) return false; | |
| 2347 | |
| 2348 return true; | |
| 2349 } | |
| 2350 | |
| 2351 | |
| 2352 void Object::VerifyApiCallResultType() { | 2340 void Object::VerifyApiCallResultType() { |
| 2353 #if DEBUG | 2341 #if DEBUG |
| 2354 if (!(IsSmi() || IsString() || IsSymbol() || IsJSReceiver() || | 2342 if (!(IsSmi() || IsString() || IsSymbol() || IsJSReceiver() || |
| 2355 IsHeapNumber() || IsSimd128Value() || IsUndefined() || IsTrue() || | 2343 IsHeapNumber() || IsSimd128Value() || IsUndefined() || IsTrue() || |
| 2356 IsFalse() || IsNull())) { | 2344 IsFalse() || IsNull())) { |
| 2357 FATAL("API call returned invalid object"); | 2345 FATAL("API call returned invalid object"); |
| 2358 } | 2346 } |
| 2359 #endif // DEBUG | 2347 #endif // DEBUG |
| 2360 } | 2348 } |
| 2361 | 2349 |
| 2362 | 2350 |
| 2363 Object* FixedArray::get(int index) const { | 2351 Object* FixedArray::get(int index) const { |
| 2364 SLOW_DCHECK(index >= 0 && index < this->length()); | 2352 SLOW_DCHECK(index >= 0 && index < this->length()); |
| 2365 return READ_FIELD(this, kHeaderSize + index * kPointerSize); | 2353 return READ_FIELD(this, kHeaderSize + index * kPointerSize); |
| 2366 } | 2354 } |
| 2367 | 2355 |
| 2368 | 2356 Handle<Object> FixedArray::get(FixedArray* array, int index, Isolate* isolate) { |
| 2369 Handle<Object> FixedArray::get(Handle<FixedArray> array, int index) { | 2357 return handle(array->get(index), isolate); |
| 2370 return handle(array->get(index), array->GetIsolate()); | |
| 2371 } | 2358 } |
| 2372 | 2359 |
| 2373 | 2360 |
| 2374 bool FixedArray::is_the_hole(int index) { | 2361 bool FixedArray::is_the_hole(int index) { |
| 2375 return get(index) == GetHeap()->the_hole_value(); | 2362 return get(index) == GetHeap()->the_hole_value(); |
| 2376 } | 2363 } |
| 2377 | 2364 |
| 2378 | 2365 |
| 2379 void FixedArray::set(int index, Smi* value) { | 2366 void FixedArray::set(int index, Smi* value) { |
| 2380 DCHECK(map() != GetHeap()->fixed_cow_array_map()); | 2367 DCHECK(map() != GetHeap()->fixed_cow_array_map()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2405 | 2392 |
| 2406 | 2393 |
| 2407 uint64_t FixedDoubleArray::get_representation(int index) { | 2394 uint64_t FixedDoubleArray::get_representation(int index) { |
| 2408 DCHECK(map() != GetHeap()->fixed_cow_array_map() && | 2395 DCHECK(map() != GetHeap()->fixed_cow_array_map() && |
| 2409 map() != GetHeap()->fixed_array_map()); | 2396 map() != GetHeap()->fixed_array_map()); |
| 2410 DCHECK(index >= 0 && index < this->length()); | 2397 DCHECK(index >= 0 && index < this->length()); |
| 2411 int offset = kHeaderSize + index * kDoubleSize; | 2398 int offset = kHeaderSize + index * kDoubleSize; |
| 2412 return READ_UINT64_FIELD(this, offset); | 2399 return READ_UINT64_FIELD(this, offset); |
| 2413 } | 2400 } |
| 2414 | 2401 |
| 2415 | 2402 Handle<Object> FixedDoubleArray::get(FixedDoubleArray* array, int index, |
| 2416 Handle<Object> FixedDoubleArray::get(Handle<FixedDoubleArray> array, | 2403 Isolate* isolate) { |
| 2417 int index) { | |
| 2418 if (array->is_the_hole(index)) { | 2404 if (array->is_the_hole(index)) { |
| 2419 return array->GetIsolate()->factory()->the_hole_value(); | 2405 return isolate->factory()->the_hole_value(); |
| 2420 } else { | 2406 } else { |
| 2421 return array->GetIsolate()->factory()->NewNumber(array->get_scalar(index)); | 2407 return isolate->factory()->NewNumber(array->get_scalar(index)); |
| 2422 } | 2408 } |
| 2423 } | 2409 } |
| 2424 | 2410 |
| 2425 | 2411 |
| 2426 void FixedDoubleArray::set(int index, double value) { | 2412 void FixedDoubleArray::set(int index, double value) { |
| 2427 DCHECK(map() != GetHeap()->fixed_cow_array_map() && | 2413 DCHECK(map() != GetHeap()->fixed_cow_array_map() && |
| 2428 map() != GetHeap()->fixed_array_map()); | 2414 map() != GetHeap()->fixed_array_map()); |
| 2429 int offset = kHeaderSize + index * kDoubleSize; | 2415 int offset = kHeaderSize + index * kDoubleSize; |
| 2430 if (std::isnan(value)) { | 2416 if (std::isnan(value)) { |
| 2431 WRITE_DOUBLE_FIELD(this, offset, std::numeric_limits<double>::quiet_NaN()); | 2417 WRITE_DOUBLE_FIELD(this, offset, std::numeric_limits<double>::quiet_NaN()); |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2868 if (length != kInvalidEnumCacheSentinel) { | 2854 if (length != kInvalidEnumCacheSentinel) { |
| 2869 DCHECK(length >= 0); | 2855 DCHECK(length >= 0); |
| 2870 DCHECK(length == 0 || instance_descriptors()->HasEnumCache()); | 2856 DCHECK(length == 0 || instance_descriptors()->HasEnumCache()); |
| 2871 DCHECK(length <= NumberOfOwnDescriptors()); | 2857 DCHECK(length <= NumberOfOwnDescriptors()); |
| 2872 } | 2858 } |
| 2873 set_bit_field3(EnumLengthBits::update(bit_field3(), length)); | 2859 set_bit_field3(EnumLengthBits::update(bit_field3(), length)); |
| 2874 } | 2860 } |
| 2875 | 2861 |
| 2876 | 2862 |
| 2877 FixedArrayBase* Map::GetInitialElements() { | 2863 FixedArrayBase* Map::GetInitialElements() { |
| 2878 if (has_fast_smi_or_object_elements() || | 2864 if (has_fast_elements() || has_fast_string_wrapper_elements()) { |
| 2879 has_fast_double_elements()) { | |
| 2880 DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); | 2865 DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
| 2881 return GetHeap()->empty_fixed_array(); | 2866 return GetHeap()->empty_fixed_array(); |
| 2882 } else if (has_fixed_typed_array_elements()) { | 2867 } else if (has_fixed_typed_array_elements()) { |
| 2883 FixedTypedArrayBase* empty_array = | 2868 FixedTypedArrayBase* empty_array = |
| 2884 GetHeap()->EmptyFixedTypedArrayForMap(this); | 2869 GetHeap()->EmptyFixedTypedArrayForMap(this); |
| 2885 DCHECK(!GetHeap()->InNewSpace(empty_array)); | 2870 DCHECK(!GetHeap()->InNewSpace(empty_array)); |
| 2886 return empty_array; | 2871 return empty_array; |
| 2887 } else { | 2872 } else { |
| 2888 UNREACHABLE(); | 2873 UNREACHABLE(); |
| 2889 } | 2874 } |
| (...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4229 float FixedTypedArray<Float32ArrayTraits>::from_double(double value) { | 4214 float FixedTypedArray<Float32ArrayTraits>::from_double(double value) { |
| 4230 return static_cast<float>(value); | 4215 return static_cast<float>(value); |
| 4231 } | 4216 } |
| 4232 | 4217 |
| 4233 | 4218 |
| 4234 template<> inline | 4219 template<> inline |
| 4235 double FixedTypedArray<Float64ArrayTraits>::from_double(double value) { | 4220 double FixedTypedArray<Float64ArrayTraits>::from_double(double value) { |
| 4236 return value; | 4221 return value; |
| 4237 } | 4222 } |
| 4238 | 4223 |
| 4239 | |
| 4240 template <class Traits> | 4224 template <class Traits> |
| 4241 Handle<Object> FixedTypedArray<Traits>::get( | 4225 Handle<Object> FixedTypedArray<Traits>::get(FixedTypedArray<Traits>* array, |
| 4242 Handle<FixedTypedArray<Traits> > array, | 4226 int index) { |
| 4243 int index) { | |
| 4244 return Traits::ToHandle(array->GetIsolate(), array->get_scalar(index)); | 4227 return Traits::ToHandle(array->GetIsolate(), array->get_scalar(index)); |
| 4245 } | 4228 } |
| 4246 | 4229 |
| 4247 | 4230 |
| 4248 template <class Traits> | 4231 template <class Traits> |
| 4249 void FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) { | 4232 void FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) { |
| 4250 ElementType cast_value = Traits::defaultValue(); | 4233 ElementType cast_value = Traits::defaultValue(); |
| 4251 if (value->IsSmi()) { | 4234 if (value->IsSmi()) { |
| 4252 int int_value = Smi::cast(value)->value(); | 4235 int int_value = Smi::cast(value)->value(); |
| 4253 cast_value = from_int(int_value); | 4236 cast_value = from_int(int_value); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4610 bool Map::has_fast_double_elements() { | 4593 bool Map::has_fast_double_elements() { |
| 4611 return IsFastDoubleElementsKind(elements_kind()); | 4594 return IsFastDoubleElementsKind(elements_kind()); |
| 4612 } | 4595 } |
| 4613 | 4596 |
| 4614 bool Map::has_fast_elements() { return IsFastElementsKind(elements_kind()); } | 4597 bool Map::has_fast_elements() { return IsFastElementsKind(elements_kind()); } |
| 4615 | 4598 |
| 4616 bool Map::has_sloppy_arguments_elements() { | 4599 bool Map::has_sloppy_arguments_elements() { |
| 4617 return IsSloppyArgumentsElements(elements_kind()); | 4600 return IsSloppyArgumentsElements(elements_kind()); |
| 4618 } | 4601 } |
| 4619 | 4602 |
| 4603 bool Map::has_fast_string_wrapper_elements() { |
| 4604 return elements_kind() == FAST_STRING_WRAPPER_ELEMENTS; |
| 4605 } |
| 4606 |
| 4620 bool Map::has_fixed_typed_array_elements() { | 4607 bool Map::has_fixed_typed_array_elements() { |
| 4621 return IsFixedTypedArrayElementsKind(elements_kind()); | 4608 return IsFixedTypedArrayElementsKind(elements_kind()); |
| 4622 } | 4609 } |
| 4623 | 4610 |
| 4624 bool Map::has_dictionary_elements() { | 4611 bool Map::has_dictionary_elements() { |
| 4625 return IsDictionaryElementsKind(elements_kind()); | 4612 return IsDictionaryElementsKind(elements_kind()); |
| 4626 } | 4613 } |
| 4627 | 4614 |
| 4628 | 4615 |
| 4629 void Map::set_dictionary_map(bool value) { | 4616 void Map::set_dictionary_map(bool value) { |
| (...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6745 | 6732 |
| 6746 bool JSObject::HasSlowArgumentsElements() { | 6733 bool JSObject::HasSlowArgumentsElements() { |
| 6747 return GetElementsKind() == SLOW_SLOPPY_ARGUMENTS_ELEMENTS; | 6734 return GetElementsKind() == SLOW_SLOPPY_ARGUMENTS_ELEMENTS; |
| 6748 } | 6735 } |
| 6749 | 6736 |
| 6750 | 6737 |
| 6751 bool JSObject::HasSloppyArgumentsElements() { | 6738 bool JSObject::HasSloppyArgumentsElements() { |
| 6752 return IsSloppyArgumentsElements(GetElementsKind()); | 6739 return IsSloppyArgumentsElements(GetElementsKind()); |
| 6753 } | 6740 } |
| 6754 | 6741 |
| 6742 bool JSObject::HasStringWrapperElements() { |
| 6743 return IsStringWrapperElementsKind(GetElementsKind()); |
| 6744 } |
| 6745 |
| 6746 bool JSObject::HasFastStringWrapperElements() { |
| 6747 return GetElementsKind() == FAST_STRING_WRAPPER_ELEMENTS; |
| 6748 } |
| 6749 |
| 6750 bool JSObject::HasSlowStringWrapperElements() { |
| 6751 return GetElementsKind() == SLOW_STRING_WRAPPER_ELEMENTS; |
| 6752 } |
| 6755 | 6753 |
| 6756 bool JSObject::HasFixedTypedArrayElements() { | 6754 bool JSObject::HasFixedTypedArrayElements() { |
| 6757 HeapObject* array = elements(); | 6755 HeapObject* array = elements(); |
| 6758 DCHECK(array != NULL); | 6756 DCHECK(array != NULL); |
| 6759 return array->IsFixedTypedArrayBase(); | 6757 return array->IsFixedTypedArrayBase(); |
| 6760 } | 6758 } |
| 6761 | 6759 |
| 6762 | 6760 |
| 6763 #define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size) \ | 6761 #define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size) \ |
| 6764 bool JSObject::HasFixed##Type##Elements() { \ | 6762 bool JSObject::HasFixed##Type##Elements() { \ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6785 | 6783 |
| 6786 | 6784 |
| 6787 GlobalDictionary* JSObject::global_dictionary() { | 6785 GlobalDictionary* JSObject::global_dictionary() { |
| 6788 DCHECK(!HasFastProperties()); | 6786 DCHECK(!HasFastProperties()); |
| 6789 DCHECK(IsJSGlobalObject()); | 6787 DCHECK(IsJSGlobalObject()); |
| 6790 return GlobalDictionary::cast(properties()); | 6788 return GlobalDictionary::cast(properties()); |
| 6791 } | 6789 } |
| 6792 | 6790 |
| 6793 | 6791 |
| 6794 SeededNumberDictionary* JSObject::element_dictionary() { | 6792 SeededNumberDictionary* JSObject::element_dictionary() { |
| 6795 DCHECK(HasDictionaryElements()); | 6793 DCHECK(HasDictionaryElements() || HasSlowStringWrapperElements()); |
| 6796 return SeededNumberDictionary::cast(elements()); | 6794 return SeededNumberDictionary::cast(elements()); |
| 6797 } | 6795 } |
| 6798 | 6796 |
| 6799 | 6797 |
| 6800 bool Name::IsHashFieldComputed(uint32_t field) { | 6798 bool Name::IsHashFieldComputed(uint32_t field) { |
| 6801 return (field & kHashNotComputedMask) == 0; | 6799 return (field & kHashNotComputedMask) == 0; |
| 6802 } | 6800 } |
| 6803 | 6801 |
| 6804 | 6802 |
| 6805 bool Name::HasHashCode() { | 6803 bool Name::HasHashCode() { |
| (...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7842 #undef WRITE_INT64_FIELD | 7840 #undef WRITE_INT64_FIELD |
| 7843 #undef READ_BYTE_FIELD | 7841 #undef READ_BYTE_FIELD |
| 7844 #undef WRITE_BYTE_FIELD | 7842 #undef WRITE_BYTE_FIELD |
| 7845 #undef NOBARRIER_READ_BYTE_FIELD | 7843 #undef NOBARRIER_READ_BYTE_FIELD |
| 7846 #undef NOBARRIER_WRITE_BYTE_FIELD | 7844 #undef NOBARRIER_WRITE_BYTE_FIELD |
| 7847 | 7845 |
| 7848 } // namespace internal | 7846 } // namespace internal |
| 7849 } // namespace v8 | 7847 } // namespace v8 |
| 7850 | 7848 |
| 7851 #endif // V8_OBJECTS_INL_H_ | 7849 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |