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 1932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 TransitionElementsKind(object, FAST_DOUBLE_ELEMENTS); | 1943 TransitionElementsKind(object, FAST_DOUBLE_ELEMENTS); |
1944 } | 1944 } |
1945 } | 1945 } |
1946 | 1946 |
1947 | 1947 |
1948 void JSObject::SetMapAndElements(Handle<JSObject> object, | 1948 void JSObject::SetMapAndElements(Handle<JSObject> object, |
1949 Handle<Map> new_map, | 1949 Handle<Map> new_map, |
1950 Handle<FixedArrayBase> value) { | 1950 Handle<FixedArrayBase> value) { |
1951 JSObject::MigrateToMap(object, new_map); | 1951 JSObject::MigrateToMap(object, new_map); |
1952 DCHECK((object->map()->has_fast_smi_or_object_elements() || | 1952 DCHECK((object->map()->has_fast_smi_or_object_elements() || |
1953 (*value == object->GetHeap()->empty_fixed_array())) == | 1953 (*value == object->GetHeap()->empty_fixed_array()) || |
| 1954 object->map()->has_fast_string_wrapper_elements()) == |
1954 (value->map() == object->GetHeap()->fixed_array_map() || | 1955 (value->map() == object->GetHeap()->fixed_array_map() || |
1955 value->map() == object->GetHeap()->fixed_cow_array_map())); | 1956 value->map() == object->GetHeap()->fixed_cow_array_map())); |
1956 DCHECK((*value == object->GetHeap()->empty_fixed_array()) || | 1957 DCHECK((*value == object->GetHeap()->empty_fixed_array()) || |
1957 (object->map()->has_fast_double_elements() == | 1958 (object->map()->has_fast_double_elements() == |
1958 value->IsFixedDoubleArray())); | 1959 value->IsFixedDoubleArray())); |
1959 object->set_elements(*value); | 1960 object->set_elements(*value); |
1960 } | 1961 } |
1961 | 1962 |
1962 | 1963 |
1963 void JSObject::set_elements(FixedArrayBase* value, WriteBarrierMode mode) { | 1964 void JSObject::set_elements(FixedArrayBase* value, WriteBarrierMode mode) { |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2325 | 2326 |
2326 | 2327 |
2327 bool Object::ToArrayLength(uint32_t* index) { return Object::ToUint32(index); } | 2328 bool Object::ToArrayLength(uint32_t* index) { return Object::ToUint32(index); } |
2328 | 2329 |
2329 | 2330 |
2330 bool Object::ToArrayIndex(uint32_t* index) { | 2331 bool Object::ToArrayIndex(uint32_t* index) { |
2331 return Object::ToUint32(index) && *index != kMaxUInt32; | 2332 return Object::ToUint32(index) && *index != kMaxUInt32; |
2332 } | 2333 } |
2333 | 2334 |
2334 | 2335 |
2335 bool Object::IsStringObjectWithCharacterAt(uint32_t index) { | |
2336 if (!this->IsJSValue()) return false; | |
2337 | |
2338 JSValue* js_value = JSValue::cast(this); | |
2339 if (!js_value->value()->IsString()) return false; | |
2340 | |
2341 String* str = String::cast(js_value->value()); | |
2342 if (index >= static_cast<uint32_t>(str->length())) return false; | |
2343 | |
2344 return true; | |
2345 } | |
2346 | |
2347 | |
2348 void Object::VerifyApiCallResultType() { | 2336 void Object::VerifyApiCallResultType() { |
2349 #if DEBUG | 2337 #if DEBUG |
2350 if (!(IsSmi() || IsString() || IsSymbol() || IsJSReceiver() || | 2338 if (!(IsSmi() || IsString() || IsSymbol() || IsJSReceiver() || |
2351 IsHeapNumber() || IsSimd128Value() || IsUndefined() || IsTrue() || | 2339 IsHeapNumber() || IsSimd128Value() || IsUndefined() || IsTrue() || |
2352 IsFalse() || IsNull())) { | 2340 IsFalse() || IsNull())) { |
2353 FATAL("API call returned invalid object"); | 2341 FATAL("API call returned invalid object"); |
2354 } | 2342 } |
2355 #endif // DEBUG | 2343 #endif // DEBUG |
2356 } | 2344 } |
2357 | 2345 |
2358 | 2346 |
2359 Object* FixedArray::get(int index) const { | 2347 Object* FixedArray::get(int index) const { |
2360 SLOW_DCHECK(index >= 0 && index < this->length()); | 2348 SLOW_DCHECK(index >= 0 && index < this->length()); |
2361 return READ_FIELD(this, kHeaderSize + index * kPointerSize); | 2349 return READ_FIELD(this, kHeaderSize + index * kPointerSize); |
2362 } | 2350 } |
2363 | 2351 |
2364 | 2352 Handle<Object> FixedArray::get(FixedArray* array, int index, Isolate* isolate) { |
2365 Handle<Object> FixedArray::get(Handle<FixedArray> array, int index) { | 2353 return handle(array->get(index), isolate); |
2366 return handle(array->get(index), array->GetIsolate()); | |
2367 } | 2354 } |
2368 | 2355 |
2369 | 2356 |
2370 bool FixedArray::is_the_hole(int index) { | 2357 bool FixedArray::is_the_hole(int index) { |
2371 return get(index) == GetHeap()->the_hole_value(); | 2358 return get(index) == GetHeap()->the_hole_value(); |
2372 } | 2359 } |
2373 | 2360 |
2374 | 2361 |
2375 void FixedArray::set(int index, Smi* value) { | 2362 void FixedArray::set(int index, Smi* value) { |
2376 DCHECK(map() != GetHeap()->fixed_cow_array_map()); | 2363 DCHECK(map() != GetHeap()->fixed_cow_array_map()); |
(...skipping 24 matching lines...) Expand all Loading... |
2401 | 2388 |
2402 | 2389 |
2403 uint64_t FixedDoubleArray::get_representation(int index) { | 2390 uint64_t FixedDoubleArray::get_representation(int index) { |
2404 DCHECK(map() != GetHeap()->fixed_cow_array_map() && | 2391 DCHECK(map() != GetHeap()->fixed_cow_array_map() && |
2405 map() != GetHeap()->fixed_array_map()); | 2392 map() != GetHeap()->fixed_array_map()); |
2406 DCHECK(index >= 0 && index < this->length()); | 2393 DCHECK(index >= 0 && index < this->length()); |
2407 int offset = kHeaderSize + index * kDoubleSize; | 2394 int offset = kHeaderSize + index * kDoubleSize; |
2408 return READ_UINT64_FIELD(this, offset); | 2395 return READ_UINT64_FIELD(this, offset); |
2409 } | 2396 } |
2410 | 2397 |
2411 | 2398 Handle<Object> FixedDoubleArray::get(FixedDoubleArray* array, int index, |
2412 Handle<Object> FixedDoubleArray::get(Handle<FixedDoubleArray> array, | 2399 Isolate* isolate) { |
2413 int index) { | |
2414 if (array->is_the_hole(index)) { | 2400 if (array->is_the_hole(index)) { |
2415 return array->GetIsolate()->factory()->the_hole_value(); | 2401 return isolate->factory()->the_hole_value(); |
2416 } else { | 2402 } else { |
2417 return array->GetIsolate()->factory()->NewNumber(array->get_scalar(index)); | 2403 return isolate->factory()->NewNumber(array->get_scalar(index)); |
2418 } | 2404 } |
2419 } | 2405 } |
2420 | 2406 |
2421 | 2407 |
2422 void FixedDoubleArray::set(int index, double value) { | 2408 void FixedDoubleArray::set(int index, double value) { |
2423 DCHECK(map() != GetHeap()->fixed_cow_array_map() && | 2409 DCHECK(map() != GetHeap()->fixed_cow_array_map() && |
2424 map() != GetHeap()->fixed_array_map()); | 2410 map() != GetHeap()->fixed_array_map()); |
2425 int offset = kHeaderSize + index * kDoubleSize; | 2411 int offset = kHeaderSize + index * kDoubleSize; |
2426 if (std::isnan(value)) { | 2412 if (std::isnan(value)) { |
2427 WRITE_DOUBLE_FIELD(this, offset, std::numeric_limits<double>::quiet_NaN()); | 2413 WRITE_DOUBLE_FIELD(this, offset, std::numeric_limits<double>::quiet_NaN()); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2864 if (length != kInvalidEnumCacheSentinel) { | 2850 if (length != kInvalidEnumCacheSentinel) { |
2865 DCHECK(length >= 0); | 2851 DCHECK(length >= 0); |
2866 DCHECK(length == 0 || instance_descriptors()->HasEnumCache()); | 2852 DCHECK(length == 0 || instance_descriptors()->HasEnumCache()); |
2867 DCHECK(length <= NumberOfOwnDescriptors()); | 2853 DCHECK(length <= NumberOfOwnDescriptors()); |
2868 } | 2854 } |
2869 set_bit_field3(EnumLengthBits::update(bit_field3(), length)); | 2855 set_bit_field3(EnumLengthBits::update(bit_field3(), length)); |
2870 } | 2856 } |
2871 | 2857 |
2872 | 2858 |
2873 FixedArrayBase* Map::GetInitialElements() { | 2859 FixedArrayBase* Map::GetInitialElements() { |
2874 if (has_fast_smi_or_object_elements() || | 2860 if (has_fast_elements() || has_fast_string_wrapper_elements()) { |
2875 has_fast_double_elements()) { | |
2876 DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); | 2861 DCHECK(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
2877 return GetHeap()->empty_fixed_array(); | 2862 return GetHeap()->empty_fixed_array(); |
2878 } else if (has_fixed_typed_array_elements()) { | 2863 } else if (has_fixed_typed_array_elements()) { |
2879 FixedTypedArrayBase* empty_array = | 2864 FixedTypedArrayBase* empty_array = |
2880 GetHeap()->EmptyFixedTypedArrayForMap(this); | 2865 GetHeap()->EmptyFixedTypedArrayForMap(this); |
2881 DCHECK(!GetHeap()->InNewSpace(empty_array)); | 2866 DCHECK(!GetHeap()->InNewSpace(empty_array)); |
2882 return empty_array; | 2867 return empty_array; |
2883 } else { | 2868 } else { |
2884 UNREACHABLE(); | 2869 UNREACHABLE(); |
2885 } | 2870 } |
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4211 float FixedTypedArray<Float32ArrayTraits>::from_double(double value) { | 4196 float FixedTypedArray<Float32ArrayTraits>::from_double(double value) { |
4212 return static_cast<float>(value); | 4197 return static_cast<float>(value); |
4213 } | 4198 } |
4214 | 4199 |
4215 | 4200 |
4216 template<> inline | 4201 template<> inline |
4217 double FixedTypedArray<Float64ArrayTraits>::from_double(double value) { | 4202 double FixedTypedArray<Float64ArrayTraits>::from_double(double value) { |
4218 return value; | 4203 return value; |
4219 } | 4204 } |
4220 | 4205 |
4221 | |
4222 template <class Traits> | 4206 template <class Traits> |
4223 Handle<Object> FixedTypedArray<Traits>::get( | 4207 Handle<Object> FixedTypedArray<Traits>::get(FixedTypedArray<Traits>* array, |
4224 Handle<FixedTypedArray<Traits> > array, | 4208 int index) { |
4225 int index) { | |
4226 return Traits::ToHandle(array->GetIsolate(), array->get_scalar(index)); | 4209 return Traits::ToHandle(array->GetIsolate(), array->get_scalar(index)); |
4227 } | 4210 } |
4228 | 4211 |
4229 | 4212 |
4230 template <class Traits> | 4213 template <class Traits> |
4231 void FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) { | 4214 void FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) { |
4232 ElementType cast_value = Traits::defaultValue(); | 4215 ElementType cast_value = Traits::defaultValue(); |
4233 if (value->IsSmi()) { | 4216 if (value->IsSmi()) { |
4234 int int_value = Smi::cast(value)->value(); | 4217 int int_value = Smi::cast(value)->value(); |
4235 cast_value = from_int(int_value); | 4218 cast_value = from_int(int_value); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4592 bool Map::has_fast_double_elements() { | 4575 bool Map::has_fast_double_elements() { |
4593 return IsFastDoubleElementsKind(elements_kind()); | 4576 return IsFastDoubleElementsKind(elements_kind()); |
4594 } | 4577 } |
4595 | 4578 |
4596 bool Map::has_fast_elements() { return IsFastElementsKind(elements_kind()); } | 4579 bool Map::has_fast_elements() { return IsFastElementsKind(elements_kind()); } |
4597 | 4580 |
4598 bool Map::has_sloppy_arguments_elements() { | 4581 bool Map::has_sloppy_arguments_elements() { |
4599 return IsSloppyArgumentsElements(elements_kind()); | 4582 return IsSloppyArgumentsElements(elements_kind()); |
4600 } | 4583 } |
4601 | 4584 |
| 4585 bool Map::has_fast_string_wrapper_elements() { |
| 4586 return elements_kind() == FAST_STRING_WRAPPER_ELEMENTS; |
| 4587 } |
| 4588 |
4602 bool Map::has_fixed_typed_array_elements() { | 4589 bool Map::has_fixed_typed_array_elements() { |
4603 return IsFixedTypedArrayElementsKind(elements_kind()); | 4590 return IsFixedTypedArrayElementsKind(elements_kind()); |
4604 } | 4591 } |
4605 | 4592 |
4606 bool Map::has_dictionary_elements() { | 4593 bool Map::has_dictionary_elements() { |
4607 return IsDictionaryElementsKind(elements_kind()); | 4594 return IsDictionaryElementsKind(elements_kind()); |
4608 } | 4595 } |
4609 | 4596 |
4610 | 4597 |
4611 void Map::set_dictionary_map(bool value) { | 4598 void Map::set_dictionary_map(bool value) { |
(...skipping 2103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6715 | 6702 |
6716 bool JSObject::HasSlowArgumentsElements() { | 6703 bool JSObject::HasSlowArgumentsElements() { |
6717 return GetElementsKind() == SLOW_SLOPPY_ARGUMENTS_ELEMENTS; | 6704 return GetElementsKind() == SLOW_SLOPPY_ARGUMENTS_ELEMENTS; |
6718 } | 6705 } |
6719 | 6706 |
6720 | 6707 |
6721 bool JSObject::HasSloppyArgumentsElements() { | 6708 bool JSObject::HasSloppyArgumentsElements() { |
6722 return IsSloppyArgumentsElements(GetElementsKind()); | 6709 return IsSloppyArgumentsElements(GetElementsKind()); |
6723 } | 6710 } |
6724 | 6711 |
| 6712 bool JSObject::HasStringWrapperElements() { |
| 6713 return IsStringWrapperElementsKind(GetElementsKind()); |
| 6714 } |
| 6715 |
| 6716 bool JSObject::HasFastStringWrapperElements() { |
| 6717 return GetElementsKind() == FAST_STRING_WRAPPER_ELEMENTS; |
| 6718 } |
| 6719 |
| 6720 bool JSObject::HasSlowStringWrapperElements() { |
| 6721 return GetElementsKind() == SLOW_STRING_WRAPPER_ELEMENTS; |
| 6722 } |
6725 | 6723 |
6726 bool JSObject::HasFixedTypedArrayElements() { | 6724 bool JSObject::HasFixedTypedArrayElements() { |
6727 HeapObject* array = elements(); | 6725 HeapObject* array = elements(); |
6728 DCHECK(array != NULL); | 6726 DCHECK(array != NULL); |
6729 return array->IsFixedTypedArrayBase(); | 6727 return array->IsFixedTypedArrayBase(); |
6730 } | 6728 } |
6731 | 6729 |
6732 | 6730 |
6733 #define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size) \ | 6731 #define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size) \ |
6734 bool JSObject::HasFixed##Type##Elements() { \ | 6732 bool JSObject::HasFixed##Type##Elements() { \ |
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7812 #undef WRITE_INT64_FIELD | 7810 #undef WRITE_INT64_FIELD |
7813 #undef READ_BYTE_FIELD | 7811 #undef READ_BYTE_FIELD |
7814 #undef WRITE_BYTE_FIELD | 7812 #undef WRITE_BYTE_FIELD |
7815 #undef NOBARRIER_READ_BYTE_FIELD | 7813 #undef NOBARRIER_READ_BYTE_FIELD |
7816 #undef NOBARRIER_WRITE_BYTE_FIELD | 7814 #undef NOBARRIER_WRITE_BYTE_FIELD |
7817 | 7815 |
7818 } // namespace internal | 7816 } // namespace internal |
7819 } // namespace v8 | 7817 } // namespace v8 |
7820 | 7818 |
7821 #endif // V8_OBJECTS_INL_H_ | 7819 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |