11cb0ef41Sopenharmony_ci// Copyright 2012 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci// 51cb0ef41Sopenharmony_ci// Review notes: 61cb0ef41Sopenharmony_ci// 71cb0ef41Sopenharmony_ci// - The use of macros in these inline functions may seem superfluous 81cb0ef41Sopenharmony_ci// but it is absolutely needed to make sure gcc generates optimal 91cb0ef41Sopenharmony_ci// code. gcc is not happy when attempting to inline too deep. 101cb0ef41Sopenharmony_ci// 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_OBJECTS_INL_H_ 131cb0ef41Sopenharmony_ci#define V8_OBJECTS_OBJECTS_INL_H_ 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci#include "src/base/bits.h" 161cb0ef41Sopenharmony_ci#include "src/base/memory.h" 171cb0ef41Sopenharmony_ci#include "src/base/numbers/double.h" 181cb0ef41Sopenharmony_ci#include "src/builtins/builtins.h" 191cb0ef41Sopenharmony_ci#include "src/common/globals.h" 201cb0ef41Sopenharmony_ci#include "src/common/ptr-compr-inl.h" 211cb0ef41Sopenharmony_ci#include "src/handles/handles-inl.h" 221cb0ef41Sopenharmony_ci#include "src/heap/factory.h" 231cb0ef41Sopenharmony_ci#include "src/heap/heap-write-barrier-inl.h" 241cb0ef41Sopenharmony_ci#include "src/heap/read-only-heap-inl.h" 251cb0ef41Sopenharmony_ci#include "src/numbers/conversions-inl.h" 261cb0ef41Sopenharmony_ci#include "src/objects/bigint.h" 271cb0ef41Sopenharmony_ci#include "src/objects/heap-number-inl.h" 281cb0ef41Sopenharmony_ci#include "src/objects/heap-object.h" 291cb0ef41Sopenharmony_ci#include "src/objects/js-proxy-inl.h" // TODO(jkummerow): Drop. 301cb0ef41Sopenharmony_ci#include "src/objects/keys.h" 311cb0ef41Sopenharmony_ci#include "src/objects/literal-objects.h" 321cb0ef41Sopenharmony_ci#include "src/objects/lookup-inl.h" // TODO(jkummerow): Drop. 331cb0ef41Sopenharmony_ci#include "src/objects/objects.h" 341cb0ef41Sopenharmony_ci#include "src/objects/oddball-inl.h" 351cb0ef41Sopenharmony_ci#include "src/objects/property-details.h" 361cb0ef41Sopenharmony_ci#include "src/objects/property.h" 371cb0ef41Sopenharmony_ci#include "src/objects/regexp-match-info-inl.h" 381cb0ef41Sopenharmony_ci#include "src/objects/shared-function-info.h" 391cb0ef41Sopenharmony_ci#include "src/objects/slots-inl.h" 401cb0ef41Sopenharmony_ci#include "src/objects/smi-inl.h" 411cb0ef41Sopenharmony_ci#include "src/objects/tagged-field-inl.h" 421cb0ef41Sopenharmony_ci#include "src/objects/tagged-impl-inl.h" 431cb0ef41Sopenharmony_ci#include "src/objects/tagged-index.h" 441cb0ef41Sopenharmony_ci#include "src/objects/templates.h" 451cb0ef41Sopenharmony_ci#include "src/sandbox/external-pointer-inl.h" 461cb0ef41Sopenharmony_ci#include "src/sandbox/sandboxed-pointer-inl.h" 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards): 491cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h" 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_cinamespace v8 { 521cb0ef41Sopenharmony_cinamespace internal { 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ciPropertyDetails::PropertyDetails(Smi smi) { value_ = smi.value(); } 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ciSmi PropertyDetails::AsSmi() const { 571cb0ef41Sopenharmony_ci // Ensure the upper 2 bits have the same value by sign extending it. This is 581cb0ef41Sopenharmony_ci // necessary to be able to use the 31st bit of the property details. 591cb0ef41Sopenharmony_ci int value = value_ << 1; 601cb0ef41Sopenharmony_ci return Smi::FromInt(value >> 1); 611cb0ef41Sopenharmony_ci} 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ciint PropertyDetails::field_width_in_words() const { 641cb0ef41Sopenharmony_ci DCHECK_EQ(location(), PropertyLocation::kField); 651cb0ef41Sopenharmony_ci return 1; 661cb0ef41Sopenharmony_ci} 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsClassBoilerplate, bool) { 691cb0ef41Sopenharmony_ci return IsFixedArrayExact(cage_base); 701cb0ef41Sopenharmony_ci} 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_cibool Object::IsTaggedIndex() const { 731cb0ef41Sopenharmony_ci return IsSmi() && TaggedIndex::IsValid(TaggedIndex(ptr()).value()); 741cb0ef41Sopenharmony_ci} 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_cibool Object::InSharedHeap() const { 771cb0ef41Sopenharmony_ci return IsHeapObject() && HeapObject::cast(*this).InSharedHeap(); 781cb0ef41Sopenharmony_ci} 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_cibool Object::InSharedWritableHeap() const { 811cb0ef41Sopenharmony_ci return IsHeapObject() && HeapObject::cast(*this).InSharedWritableHeap(); 821cb0ef41Sopenharmony_ci} 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_ci#define IS_TYPE_FUNCTION_DEF(type_) \ 851cb0ef41Sopenharmony_ci bool Object::Is##type_() const { \ 861cb0ef41Sopenharmony_ci return IsHeapObject() && HeapObject::cast(*this).Is##type_(); \ 871cb0ef41Sopenharmony_ci } \ 881cb0ef41Sopenharmony_ci bool Object::Is##type_(PtrComprCageBase cage_base) const { \ 891cb0ef41Sopenharmony_ci return IsHeapObject() && HeapObject::cast(*this).Is##type_(cage_base); \ 901cb0ef41Sopenharmony_ci } 911cb0ef41Sopenharmony_ciHEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DEF) 921cb0ef41Sopenharmony_ciIS_TYPE_FUNCTION_DEF(HashTableBase) 931cb0ef41Sopenharmony_ciIS_TYPE_FUNCTION_DEF(SmallOrderedHashTable) 941cb0ef41Sopenharmony_ciIS_TYPE_FUNCTION_DEF(CodeT) 951cb0ef41Sopenharmony_ci#undef IS_TYPE_FUNCTION_DEF 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci#define IS_TYPE_FUNCTION_DEF(Type, Value) \ 981cb0ef41Sopenharmony_ci bool Object::Is##Type(Isolate* isolate) const { \ 991cb0ef41Sopenharmony_ci return Is##Type(ReadOnlyRoots(isolate)); \ 1001cb0ef41Sopenharmony_ci } \ 1011cb0ef41Sopenharmony_ci bool Object::Is##Type(LocalIsolate* isolate) const { \ 1021cb0ef41Sopenharmony_ci return Is##Type(ReadOnlyRoots(isolate)); \ 1031cb0ef41Sopenharmony_ci } \ 1041cb0ef41Sopenharmony_ci bool Object::Is##Type(ReadOnlyRoots roots) const { \ 1051cb0ef41Sopenharmony_ci return *this == roots.Value(); \ 1061cb0ef41Sopenharmony_ci } \ 1071cb0ef41Sopenharmony_ci bool Object::Is##Type() const { \ 1081cb0ef41Sopenharmony_ci return IsHeapObject() && HeapObject::cast(*this).Is##Type(); \ 1091cb0ef41Sopenharmony_ci } \ 1101cb0ef41Sopenharmony_ci bool HeapObject::Is##Type(Isolate* isolate) const { \ 1111cb0ef41Sopenharmony_ci return Object::Is##Type(isolate); \ 1121cb0ef41Sopenharmony_ci } \ 1131cb0ef41Sopenharmony_ci bool HeapObject::Is##Type(LocalIsolate* isolate) const { \ 1141cb0ef41Sopenharmony_ci return Object::Is##Type(isolate); \ 1151cb0ef41Sopenharmony_ci } \ 1161cb0ef41Sopenharmony_ci bool HeapObject::Is##Type(ReadOnlyRoots roots) const { \ 1171cb0ef41Sopenharmony_ci return Object::Is##Type(roots); \ 1181cb0ef41Sopenharmony_ci } \ 1191cb0ef41Sopenharmony_ci bool HeapObject::Is##Type() const { return Is##Type(GetReadOnlyRoots()); } 1201cb0ef41Sopenharmony_ciODDBALL_LIST(IS_TYPE_FUNCTION_DEF) 1211cb0ef41Sopenharmony_ci#undef IS_TYPE_FUNCTION_DEF 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_cibool Object::IsNullOrUndefined(Isolate* isolate) const { 1241cb0ef41Sopenharmony_ci return IsNullOrUndefined(ReadOnlyRoots(isolate)); 1251cb0ef41Sopenharmony_ci} 1261cb0ef41Sopenharmony_ci 1271cb0ef41Sopenharmony_cibool Object::IsNullOrUndefined(ReadOnlyRoots roots) const { 1281cb0ef41Sopenharmony_ci return IsNull(roots) || IsUndefined(roots); 1291cb0ef41Sopenharmony_ci} 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_cibool Object::IsNullOrUndefined() const { 1321cb0ef41Sopenharmony_ci return IsHeapObject() && HeapObject::cast(*this).IsNullOrUndefined(); 1331cb0ef41Sopenharmony_ci} 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_cibool Object::IsZero() const { return *this == Smi::zero(); } 1361cb0ef41Sopenharmony_ci 1371cb0ef41Sopenharmony_cibool Object::IsPublicSymbol() const { 1381cb0ef41Sopenharmony_ci return IsSymbol() && !Symbol::cast(*this).is_private(); 1391cb0ef41Sopenharmony_ci} 1401cb0ef41Sopenharmony_cibool Object::IsPrivateSymbol() const { 1411cb0ef41Sopenharmony_ci return IsSymbol() && Symbol::cast(*this).is_private(); 1421cb0ef41Sopenharmony_ci} 1431cb0ef41Sopenharmony_ci 1441cb0ef41Sopenharmony_cibool Object::IsNoSharedNameSentinel() const { 1451cb0ef41Sopenharmony_ci return *this == SharedFunctionInfo::kNoSharedNameSentinel; 1461cb0ef41Sopenharmony_ci} 1471cb0ef41Sopenharmony_ci 1481cb0ef41Sopenharmony_citemplate <class T, 1491cb0ef41Sopenharmony_ci typename std::enable_if<(std::is_arithmetic<T>::value || 1501cb0ef41Sopenharmony_ci std::is_enum<T>::value) && 1511cb0ef41Sopenharmony_ci !std::is_floating_point<T>::value, 1521cb0ef41Sopenharmony_ci int>::type> 1531cb0ef41Sopenharmony_ciT Object::Relaxed_ReadField(size_t offset) const { 1541cb0ef41Sopenharmony_ci // Pointer compression causes types larger than kTaggedSize to be 1551cb0ef41Sopenharmony_ci // unaligned. Atomic loads must be aligned. 1561cb0ef41Sopenharmony_ci DCHECK_IMPLIES(COMPRESS_POINTERS_BOOL, sizeof(T) <= kTaggedSize); 1571cb0ef41Sopenharmony_ci using AtomicT = typename base::AtomicTypeFromByteWidth<sizeof(T)>::type; 1581cb0ef41Sopenharmony_ci return static_cast<T>(base::AsAtomicImpl<AtomicT>::Relaxed_Load( 1591cb0ef41Sopenharmony_ci reinterpret_cast<AtomicT*>(field_address(offset)))); 1601cb0ef41Sopenharmony_ci} 1611cb0ef41Sopenharmony_ci 1621cb0ef41Sopenharmony_citemplate <class T, 1631cb0ef41Sopenharmony_ci typename std::enable_if<(std::is_arithmetic<T>::value || 1641cb0ef41Sopenharmony_ci std::is_enum<T>::value) && 1651cb0ef41Sopenharmony_ci !std::is_floating_point<T>::value, 1661cb0ef41Sopenharmony_ci int>::type> 1671cb0ef41Sopenharmony_civoid Object::Relaxed_WriteField(size_t offset, T value) { 1681cb0ef41Sopenharmony_ci // Pointer compression causes types larger than kTaggedSize to be 1691cb0ef41Sopenharmony_ci // unaligned. Atomic stores must be aligned. 1701cb0ef41Sopenharmony_ci DCHECK_IMPLIES(COMPRESS_POINTERS_BOOL, sizeof(T) <= kTaggedSize); 1711cb0ef41Sopenharmony_ci using AtomicT = typename base::AtomicTypeFromByteWidth<sizeof(T)>::type; 1721cb0ef41Sopenharmony_ci base::AsAtomicImpl<AtomicT>::Relaxed_Store( 1731cb0ef41Sopenharmony_ci reinterpret_cast<AtomicT*>(field_address(offset)), 1741cb0ef41Sopenharmony_ci static_cast<AtomicT>(value)); 1751cb0ef41Sopenharmony_ci} 1761cb0ef41Sopenharmony_ci 1771cb0ef41Sopenharmony_cibool HeapObject::InSharedHeap() const { 1781cb0ef41Sopenharmony_ci if (IsReadOnlyHeapObject(*this)) return V8_SHARED_RO_HEAP_BOOL; 1791cb0ef41Sopenharmony_ci return InSharedWritableHeap(); 1801cb0ef41Sopenharmony_ci} 1811cb0ef41Sopenharmony_ci 1821cb0ef41Sopenharmony_cibool HeapObject::InSharedWritableHeap() const { 1831cb0ef41Sopenharmony_ci return BasicMemoryChunk::FromHeapObject(*this)->InSharedHeap(); 1841cb0ef41Sopenharmony_ci} 1851cb0ef41Sopenharmony_ci 1861cb0ef41Sopenharmony_cibool HeapObject::IsNullOrUndefined(Isolate* isolate) const { 1871cb0ef41Sopenharmony_ci return IsNullOrUndefined(ReadOnlyRoots(isolate)); 1881cb0ef41Sopenharmony_ci} 1891cb0ef41Sopenharmony_ci 1901cb0ef41Sopenharmony_cibool HeapObject::IsNullOrUndefined(ReadOnlyRoots roots) const { 1911cb0ef41Sopenharmony_ci return Object::IsNullOrUndefined(roots); 1921cb0ef41Sopenharmony_ci} 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_cibool HeapObject::IsNullOrUndefined() const { 1951cb0ef41Sopenharmony_ci return IsNullOrUndefined(GetReadOnlyRoots()); 1961cb0ef41Sopenharmony_ci} 1971cb0ef41Sopenharmony_ci 1981cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsCodeT, bool) { 1991cb0ef41Sopenharmony_ci return V8_EXTERNAL_CODE_SPACE_BOOL ? IsCodeDataContainer(cage_base) 2001cb0ef41Sopenharmony_ci : IsCode(cage_base); 2011cb0ef41Sopenharmony_ci} 2021cb0ef41Sopenharmony_ci 2031cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsUniqueName, bool) { 2041cb0ef41Sopenharmony_ci return IsInternalizedString(cage_base) || IsSymbol(cage_base); 2051cb0ef41Sopenharmony_ci} 2061cb0ef41Sopenharmony_ci 2071cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsFunction, bool) { 2081cb0ef41Sopenharmony_ci return IsJSFunctionOrBoundFunctionOrWrappedFunction(); 2091cb0ef41Sopenharmony_ci} 2101cb0ef41Sopenharmony_ci 2111cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsCallable, bool) { 2121cb0ef41Sopenharmony_ci return map(cage_base).is_callable(); 2131cb0ef41Sopenharmony_ci} 2141cb0ef41Sopenharmony_ci 2151cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsCallableJSProxy, bool) { 2161cb0ef41Sopenharmony_ci return IsCallable(cage_base) && IsJSProxy(cage_base); 2171cb0ef41Sopenharmony_ci} 2181cb0ef41Sopenharmony_ci 2191cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsCallableApiObject, bool) { 2201cb0ef41Sopenharmony_ci InstanceType type = map(cage_base).instance_type(); 2211cb0ef41Sopenharmony_ci return IsCallable(cage_base) && 2221cb0ef41Sopenharmony_ci (type == JS_API_OBJECT_TYPE || type == JS_SPECIAL_API_OBJECT_TYPE); 2231cb0ef41Sopenharmony_ci} 2241cb0ef41Sopenharmony_ci 2251cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsNonNullForeign, bool) { 2261cb0ef41Sopenharmony_ci return IsForeign(cage_base) && 2271cb0ef41Sopenharmony_ci Foreign::cast(*this).foreign_address() != kNullAddress; 2281cb0ef41Sopenharmony_ci} 2291cb0ef41Sopenharmony_ci 2301cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsConstructor, bool) { 2311cb0ef41Sopenharmony_ci return map(cage_base).is_constructor(); 2321cb0ef41Sopenharmony_ci} 2331cb0ef41Sopenharmony_ci 2341cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsSourceTextModuleInfo, bool) { 2351cb0ef41Sopenharmony_ci return map(cage_base) == GetReadOnlyRoots(cage_base).module_info_map(); 2361cb0ef41Sopenharmony_ci} 2371cb0ef41Sopenharmony_ci 2381cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsConsString, bool) { 2391cb0ef41Sopenharmony_ci if (!IsString(cage_base)) return false; 2401cb0ef41Sopenharmony_ci return StringShape(String::cast(*this).map(cage_base)).IsCons(); 2411cb0ef41Sopenharmony_ci} 2421cb0ef41Sopenharmony_ci 2431cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsThinString, bool) { 2441cb0ef41Sopenharmony_ci if (!IsString(cage_base)) return false; 2451cb0ef41Sopenharmony_ci return StringShape(String::cast(*this).map(cage_base)).IsThin(); 2461cb0ef41Sopenharmony_ci} 2471cb0ef41Sopenharmony_ci 2481cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsSlicedString, bool) { 2491cb0ef41Sopenharmony_ci if (!IsString(cage_base)) return false; 2501cb0ef41Sopenharmony_ci return StringShape(String::cast(*this).map(cage_base)).IsSliced(); 2511cb0ef41Sopenharmony_ci} 2521cb0ef41Sopenharmony_ci 2531cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsSeqString, bool) { 2541cb0ef41Sopenharmony_ci if (!IsString(cage_base)) return false; 2551cb0ef41Sopenharmony_ci return StringShape(String::cast(*this).map(cage_base)).IsSequential(); 2561cb0ef41Sopenharmony_ci} 2571cb0ef41Sopenharmony_ci 2581cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsSeqOneByteString, bool) { 2591cb0ef41Sopenharmony_ci if (!IsString(cage_base)) return false; 2601cb0ef41Sopenharmony_ci return StringShape(String::cast(*this).map(cage_base)).IsSequential() && 2611cb0ef41Sopenharmony_ci String::cast(*this).IsOneByteRepresentation(cage_base); 2621cb0ef41Sopenharmony_ci} 2631cb0ef41Sopenharmony_ci 2641cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsSeqTwoByteString, bool) { 2651cb0ef41Sopenharmony_ci if (!IsString(cage_base)) return false; 2661cb0ef41Sopenharmony_ci return StringShape(String::cast(*this).map(cage_base)).IsSequential() && 2671cb0ef41Sopenharmony_ci String::cast(*this).IsTwoByteRepresentation(cage_base); 2681cb0ef41Sopenharmony_ci} 2691cb0ef41Sopenharmony_ci 2701cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsExternalOneByteString, bool) { 2711cb0ef41Sopenharmony_ci if (!IsString(cage_base)) return false; 2721cb0ef41Sopenharmony_ci return StringShape(String::cast(*this).map(cage_base)).IsExternal() && 2731cb0ef41Sopenharmony_ci String::cast(*this).IsOneByteRepresentation(cage_base); 2741cb0ef41Sopenharmony_ci} 2751cb0ef41Sopenharmony_ci 2761cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsExternalTwoByteString, bool) { 2771cb0ef41Sopenharmony_ci if (!IsString(cage_base)) return false; 2781cb0ef41Sopenharmony_ci return StringShape(String::cast(*this).map(cage_base)).IsExternal() && 2791cb0ef41Sopenharmony_ci String::cast(*this).IsTwoByteRepresentation(cage_base); 2801cb0ef41Sopenharmony_ci} 2811cb0ef41Sopenharmony_ci 2821cb0ef41Sopenharmony_cibool Object::IsNumber() const { 2831cb0ef41Sopenharmony_ci if (IsSmi()) return true; 2841cb0ef41Sopenharmony_ci HeapObject this_heap_object = HeapObject::cast(*this); 2851cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(this_heap_object); 2861cb0ef41Sopenharmony_ci return this_heap_object.IsHeapNumber(cage_base); 2871cb0ef41Sopenharmony_ci} 2881cb0ef41Sopenharmony_ci 2891cb0ef41Sopenharmony_cibool Object::IsNumber(PtrComprCageBase cage_base) const { 2901cb0ef41Sopenharmony_ci return IsSmi() || IsHeapNumber(cage_base); 2911cb0ef41Sopenharmony_ci} 2921cb0ef41Sopenharmony_ci 2931cb0ef41Sopenharmony_cibool Object::IsNumeric() const { 2941cb0ef41Sopenharmony_ci if (IsSmi()) return true; 2951cb0ef41Sopenharmony_ci HeapObject this_heap_object = HeapObject::cast(*this); 2961cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(this_heap_object); 2971cb0ef41Sopenharmony_ci return this_heap_object.IsHeapNumber(cage_base) || 2981cb0ef41Sopenharmony_ci this_heap_object.IsBigInt(cage_base); 2991cb0ef41Sopenharmony_ci} 3001cb0ef41Sopenharmony_ci 3011cb0ef41Sopenharmony_cibool Object::IsNumeric(PtrComprCageBase cage_base) const { 3021cb0ef41Sopenharmony_ci return IsNumber(cage_base) || IsBigInt(cage_base); 3031cb0ef41Sopenharmony_ci} 3041cb0ef41Sopenharmony_ci 3051cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsArrayList, bool) { 3061cb0ef41Sopenharmony_ci return map(cage_base) == 3071cb0ef41Sopenharmony_ci GetReadOnlyRoots(cage_base).unchecked_array_list_map(); 3081cb0ef41Sopenharmony_ci} 3091cb0ef41Sopenharmony_ci 3101cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsRegExpMatchInfo, bool) { 3111cb0ef41Sopenharmony_ci return IsFixedArrayExact(cage_base); 3121cb0ef41Sopenharmony_ci} 3131cb0ef41Sopenharmony_ci 3141cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsDeoptimizationData, bool) { 3151cb0ef41Sopenharmony_ci // Must be a fixed array. 3161cb0ef41Sopenharmony_ci if (!IsFixedArrayExact(cage_base)) return false; 3171cb0ef41Sopenharmony_ci 3181cb0ef41Sopenharmony_ci // There's no sure way to detect the difference between a fixed array and 3191cb0ef41Sopenharmony_ci // a deoptimization data array. Since this is used for asserts we can 3201cb0ef41Sopenharmony_ci // check that the length is zero or else the fixed size plus a multiple of 3211cb0ef41Sopenharmony_ci // the entry size. 3221cb0ef41Sopenharmony_ci int length = FixedArray::cast(*this).length(); 3231cb0ef41Sopenharmony_ci if (length == 0) return true; 3241cb0ef41Sopenharmony_ci 3251cb0ef41Sopenharmony_ci length -= DeoptimizationData::kFirstDeoptEntryIndex; 3261cb0ef41Sopenharmony_ci return length >= 0 && length % DeoptimizationData::kDeoptEntrySize == 0; 3271cb0ef41Sopenharmony_ci} 3281cb0ef41Sopenharmony_ci 3291cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsHandlerTable, bool) { 3301cb0ef41Sopenharmony_ci return IsFixedArrayExact(cage_base); 3311cb0ef41Sopenharmony_ci} 3321cb0ef41Sopenharmony_ci 3331cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsTemplateList, bool) { 3341cb0ef41Sopenharmony_ci if (!IsFixedArrayExact(cage_base)) return false; 3351cb0ef41Sopenharmony_ci if (FixedArray::cast(*this).length() < 1) return false; 3361cb0ef41Sopenharmony_ci return true; 3371cb0ef41Sopenharmony_ci} 3381cb0ef41Sopenharmony_ci 3391cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsDependentCode, bool) { 3401cb0ef41Sopenharmony_ci return IsWeakArrayList(cage_base); 3411cb0ef41Sopenharmony_ci} 3421cb0ef41Sopenharmony_ci 3431cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsOSROptimizedCodeCache, bool) { 3441cb0ef41Sopenharmony_ci return IsWeakFixedArray(cage_base); 3451cb0ef41Sopenharmony_ci} 3461cb0ef41Sopenharmony_ci 3471cb0ef41Sopenharmony_cibool HeapObject::IsAbstractCode() const { 3481cb0ef41Sopenharmony_ci // TODO(v8:11880): Either make AbstractCode be ByteArray|CodeT or 3491cb0ef41Sopenharmony_ci // ensure this version is not called for hot code. 3501cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBaseSlow(*this); 3511cb0ef41Sopenharmony_ci return HeapObject::IsAbstractCode(cage_base); 3521cb0ef41Sopenharmony_ci} 3531cb0ef41Sopenharmony_cibool HeapObject::IsAbstractCode(PtrComprCageBase cage_base) const { 3541cb0ef41Sopenharmony_ci return IsBytecodeArray(cage_base) || IsCode(cage_base); 3551cb0ef41Sopenharmony_ci} 3561cb0ef41Sopenharmony_ci 3571cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsStringWrapper, bool) { 3581cb0ef41Sopenharmony_ci return IsJSPrimitiveWrapper(cage_base) && 3591cb0ef41Sopenharmony_ci JSPrimitiveWrapper::cast(*this).value().IsString(cage_base); 3601cb0ef41Sopenharmony_ci} 3611cb0ef41Sopenharmony_ci 3621cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsBooleanWrapper, bool) { 3631cb0ef41Sopenharmony_ci return IsJSPrimitiveWrapper(cage_base) && 3641cb0ef41Sopenharmony_ci JSPrimitiveWrapper::cast(*this).value().IsBoolean(cage_base); 3651cb0ef41Sopenharmony_ci} 3661cb0ef41Sopenharmony_ci 3671cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsScriptWrapper, bool) { 3681cb0ef41Sopenharmony_ci return IsJSPrimitiveWrapper(cage_base) && 3691cb0ef41Sopenharmony_ci JSPrimitiveWrapper::cast(*this).value().IsScript(cage_base); 3701cb0ef41Sopenharmony_ci} 3711cb0ef41Sopenharmony_ci 3721cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsNumberWrapper, bool) { 3731cb0ef41Sopenharmony_ci return IsJSPrimitiveWrapper(cage_base) && 3741cb0ef41Sopenharmony_ci JSPrimitiveWrapper::cast(*this).value().IsNumber(cage_base); 3751cb0ef41Sopenharmony_ci} 3761cb0ef41Sopenharmony_ci 3771cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsBigIntWrapper, bool) { 3781cb0ef41Sopenharmony_ci return IsJSPrimitiveWrapper(cage_base) && 3791cb0ef41Sopenharmony_ci JSPrimitiveWrapper::cast(*this).value().IsBigInt(cage_base); 3801cb0ef41Sopenharmony_ci} 3811cb0ef41Sopenharmony_ci 3821cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsSymbolWrapper, bool) { 3831cb0ef41Sopenharmony_ci return IsJSPrimitiveWrapper(cage_base) && 3841cb0ef41Sopenharmony_ci JSPrimitiveWrapper::cast(*this).value().IsSymbol(cage_base); 3851cb0ef41Sopenharmony_ci} 3861cb0ef41Sopenharmony_ci 3871cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsStringSet, bool) { return IsHashTable(cage_base); } 3881cb0ef41Sopenharmony_ci 3891cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsObjectHashSet, bool) { return IsHashTable(cage_base); } 3901cb0ef41Sopenharmony_ci 3911cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsCompilationCacheTable, bool) { 3921cb0ef41Sopenharmony_ci return IsHashTable(cage_base); 3931cb0ef41Sopenharmony_ci} 3941cb0ef41Sopenharmony_ci 3951cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsMapCache, bool) { return IsHashTable(cage_base); } 3961cb0ef41Sopenharmony_ci 3971cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsObjectHashTable, bool) { 3981cb0ef41Sopenharmony_ci return IsHashTable(cage_base); 3991cb0ef41Sopenharmony_ci} 4001cb0ef41Sopenharmony_ci 4011cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsHashTableBase, bool) { return IsHashTable(cage_base); } 4021cb0ef41Sopenharmony_ci 4031cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY 4041cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsWasmExceptionPackage, bool) { 4051cb0ef41Sopenharmony_ci // It is not possible to check for the existence of certain properties on the 4061cb0ef41Sopenharmony_ci // underlying {JSReceiver} here because that requires calling handlified code. 4071cb0ef41Sopenharmony_ci return IsJSReceiver(cage_base); 4081cb0ef41Sopenharmony_ci} 4091cb0ef41Sopenharmony_ci#endif // V8_ENABLE_WEBASSEMBLY 4101cb0ef41Sopenharmony_ci 4111cb0ef41Sopenharmony_cibool Object::IsPrimitive() const { 4121cb0ef41Sopenharmony_ci if (IsSmi()) return true; 4131cb0ef41Sopenharmony_ci HeapObject this_heap_object = HeapObject::cast(*this); 4141cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(this_heap_object); 4151cb0ef41Sopenharmony_ci return this_heap_object.map(cage_base).IsPrimitiveMap(); 4161cb0ef41Sopenharmony_ci} 4171cb0ef41Sopenharmony_ci 4181cb0ef41Sopenharmony_cibool Object::IsPrimitive(PtrComprCageBase cage_base) const { 4191cb0ef41Sopenharmony_ci return IsSmi() || HeapObject::cast(*this).map(cage_base).IsPrimitiveMap(); 4201cb0ef41Sopenharmony_ci} 4211cb0ef41Sopenharmony_ci 4221cb0ef41Sopenharmony_ci// static 4231cb0ef41Sopenharmony_ciMaybe<bool> Object::IsArray(Handle<Object> object) { 4241cb0ef41Sopenharmony_ci if (object->IsSmi()) return Just(false); 4251cb0ef41Sopenharmony_ci Handle<HeapObject> heap_object = Handle<HeapObject>::cast(object); 4261cb0ef41Sopenharmony_ci if (heap_object->IsJSArray()) return Just(true); 4271cb0ef41Sopenharmony_ci if (!heap_object->IsJSProxy()) return Just(false); 4281cb0ef41Sopenharmony_ci return JSProxy::IsArray(Handle<JSProxy>::cast(object)); 4291cb0ef41Sopenharmony_ci} 4301cb0ef41Sopenharmony_ci 4311cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsUndetectable, bool) { 4321cb0ef41Sopenharmony_ci return map(cage_base).is_undetectable(); 4331cb0ef41Sopenharmony_ci} 4341cb0ef41Sopenharmony_ci 4351cb0ef41Sopenharmony_ciDEF_GETTER(HeapObject, IsAccessCheckNeeded, bool) { 4361cb0ef41Sopenharmony_ci if (IsJSGlobalProxy(cage_base)) { 4371cb0ef41Sopenharmony_ci const JSGlobalProxy proxy = JSGlobalProxy::cast(*this); 4381cb0ef41Sopenharmony_ci JSGlobalObject global = proxy.GetIsolate()->context().global_object(); 4391cb0ef41Sopenharmony_ci return proxy.IsDetachedFrom(global); 4401cb0ef41Sopenharmony_ci } 4411cb0ef41Sopenharmony_ci return map(cage_base).is_access_check_needed(); 4421cb0ef41Sopenharmony_ci} 4431cb0ef41Sopenharmony_ci 4441cb0ef41Sopenharmony_ci#define MAKE_STRUCT_PREDICATE(NAME, Name, name) \ 4451cb0ef41Sopenharmony_ci bool Object::Is##Name() const { \ 4461cb0ef41Sopenharmony_ci return IsHeapObject() && HeapObject::cast(*this).Is##Name(); \ 4471cb0ef41Sopenharmony_ci } \ 4481cb0ef41Sopenharmony_ci bool Object::Is##Name(PtrComprCageBase cage_base) const { \ 4491cb0ef41Sopenharmony_ci return IsHeapObject() && HeapObject::cast(*this).Is##Name(cage_base); \ 4501cb0ef41Sopenharmony_ci } 4511cb0ef41Sopenharmony_ciSTRUCT_LIST(MAKE_STRUCT_PREDICATE) 4521cb0ef41Sopenharmony_ci#undef MAKE_STRUCT_PREDICATE 4531cb0ef41Sopenharmony_ci 4541cb0ef41Sopenharmony_cidouble Object::Number() const { 4551cb0ef41Sopenharmony_ci DCHECK(IsNumber()); 4561cb0ef41Sopenharmony_ci return IsSmi() ? static_cast<double>(Smi(this->ptr()).value()) 4571cb0ef41Sopenharmony_ci : HeapNumber::unchecked_cast(*this).value(); 4581cb0ef41Sopenharmony_ci} 4591cb0ef41Sopenharmony_ci 4601cb0ef41Sopenharmony_ci// static 4611cb0ef41Sopenharmony_cibool Object::SameNumberValue(double value1, double value2) { 4621cb0ef41Sopenharmony_ci // SameNumberValue(NaN, NaN) is true. 4631cb0ef41Sopenharmony_ci if (value1 != value2) { 4641cb0ef41Sopenharmony_ci return std::isnan(value1) && std::isnan(value2); 4651cb0ef41Sopenharmony_ci } 4661cb0ef41Sopenharmony_ci // SameNumberValue(0.0, -0.0) is false. 4671cb0ef41Sopenharmony_ci return (std::signbit(value1) == std::signbit(value2)); 4681cb0ef41Sopenharmony_ci} 4691cb0ef41Sopenharmony_ci 4701cb0ef41Sopenharmony_cibool Object::IsNaN() const { 4711cb0ef41Sopenharmony_ci return this->IsHeapNumber() && std::isnan(HeapNumber::cast(*this).value()); 4721cb0ef41Sopenharmony_ci} 4731cb0ef41Sopenharmony_ci 4741cb0ef41Sopenharmony_cibool Object::IsMinusZero() const { 4751cb0ef41Sopenharmony_ci return this->IsHeapNumber() && 4761cb0ef41Sopenharmony_ci i::IsMinusZero(HeapNumber::cast(*this).value()); 4771cb0ef41Sopenharmony_ci} 4781cb0ef41Sopenharmony_ci 4791cb0ef41Sopenharmony_ciOBJECT_CONSTRUCTORS_IMPL(BigIntBase, PrimitiveHeapObject) 4801cb0ef41Sopenharmony_ciOBJECT_CONSTRUCTORS_IMPL(BigInt, BigIntBase) 4811cb0ef41Sopenharmony_ciOBJECT_CONSTRUCTORS_IMPL(FreshlyAllocatedBigInt, BigIntBase) 4821cb0ef41Sopenharmony_ci 4831cb0ef41Sopenharmony_ci// ------------------------------------ 4841cb0ef41Sopenharmony_ci// Cast operations 4851cb0ef41Sopenharmony_ci 4861cb0ef41Sopenharmony_ciCAST_ACCESSOR(BigIntBase) 4871cb0ef41Sopenharmony_ciCAST_ACCESSOR(BigInt) 4881cb0ef41Sopenharmony_ci 4891cb0ef41Sopenharmony_cibool Object::HasValidElements() { 4901cb0ef41Sopenharmony_ci // Dictionary is covered under FixedArray. ByteArray is used 4911cb0ef41Sopenharmony_ci // for the JSTypedArray backing stores. 4921cb0ef41Sopenharmony_ci return IsFixedArray() || IsFixedDoubleArray() || IsByteArray(); 4931cb0ef41Sopenharmony_ci} 4941cb0ef41Sopenharmony_ci 4951cb0ef41Sopenharmony_cibool Object::FilterKey(PropertyFilter filter) { 4961cb0ef41Sopenharmony_ci DCHECK(!IsPropertyCell()); 4971cb0ef41Sopenharmony_ci if (filter == PRIVATE_NAMES_ONLY) { 4981cb0ef41Sopenharmony_ci if (!IsSymbol()) return true; 4991cb0ef41Sopenharmony_ci return !Symbol::cast(*this).is_private_name(); 5001cb0ef41Sopenharmony_ci } else if (IsSymbol()) { 5011cb0ef41Sopenharmony_ci if (filter & SKIP_SYMBOLS) return true; 5021cb0ef41Sopenharmony_ci 5031cb0ef41Sopenharmony_ci if (Symbol::cast(*this).is_private()) return true; 5041cb0ef41Sopenharmony_ci } else { 5051cb0ef41Sopenharmony_ci if (filter & SKIP_STRINGS) return true; 5061cb0ef41Sopenharmony_ci } 5071cb0ef41Sopenharmony_ci return false; 5081cb0ef41Sopenharmony_ci} 5091cb0ef41Sopenharmony_ci 5101cb0ef41Sopenharmony_ciRepresentation Object::OptimalRepresentation(PtrComprCageBase cage_base) const { 5111cb0ef41Sopenharmony_ci if (IsSmi()) { 5121cb0ef41Sopenharmony_ci return Representation::Smi(); 5131cb0ef41Sopenharmony_ci } 5141cb0ef41Sopenharmony_ci HeapObject heap_object = HeapObject::cast(*this); 5151cb0ef41Sopenharmony_ci if (heap_object.IsHeapNumber(cage_base)) { 5161cb0ef41Sopenharmony_ci return Representation::Double(); 5171cb0ef41Sopenharmony_ci } else if (heap_object.IsUninitialized( 5181cb0ef41Sopenharmony_ci heap_object.GetReadOnlyRoots(cage_base))) { 5191cb0ef41Sopenharmony_ci return Representation::None(); 5201cb0ef41Sopenharmony_ci } 5211cb0ef41Sopenharmony_ci return Representation::HeapObject(); 5221cb0ef41Sopenharmony_ci} 5231cb0ef41Sopenharmony_ci 5241cb0ef41Sopenharmony_ciElementsKind Object::OptimalElementsKind(PtrComprCageBase cage_base) const { 5251cb0ef41Sopenharmony_ci if (IsSmi()) return PACKED_SMI_ELEMENTS; 5261cb0ef41Sopenharmony_ci if (IsNumber(cage_base)) return PACKED_DOUBLE_ELEMENTS; 5271cb0ef41Sopenharmony_ci return PACKED_ELEMENTS; 5281cb0ef41Sopenharmony_ci} 5291cb0ef41Sopenharmony_ci 5301cb0ef41Sopenharmony_cibool Object::FitsRepresentation(Representation representation, 5311cb0ef41Sopenharmony_ci bool allow_coercion) const { 5321cb0ef41Sopenharmony_ci if (representation.IsSmi()) { 5331cb0ef41Sopenharmony_ci return IsSmi(); 5341cb0ef41Sopenharmony_ci } else if (representation.IsDouble()) { 5351cb0ef41Sopenharmony_ci return allow_coercion ? IsNumber() : IsHeapNumber(); 5361cb0ef41Sopenharmony_ci } else if (representation.IsHeapObject()) { 5371cb0ef41Sopenharmony_ci return IsHeapObject(); 5381cb0ef41Sopenharmony_ci } else if (representation.IsNone()) { 5391cb0ef41Sopenharmony_ci return false; 5401cb0ef41Sopenharmony_ci } 5411cb0ef41Sopenharmony_ci return true; 5421cb0ef41Sopenharmony_ci} 5431cb0ef41Sopenharmony_ci 5441cb0ef41Sopenharmony_cibool Object::ToUint32(uint32_t* value) const { 5451cb0ef41Sopenharmony_ci if (IsSmi()) { 5461cb0ef41Sopenharmony_ci int num = Smi::ToInt(*this); 5471cb0ef41Sopenharmony_ci if (num < 0) return false; 5481cb0ef41Sopenharmony_ci *value = static_cast<uint32_t>(num); 5491cb0ef41Sopenharmony_ci return true; 5501cb0ef41Sopenharmony_ci } 5511cb0ef41Sopenharmony_ci if (IsHeapNumber()) { 5521cb0ef41Sopenharmony_ci double num = HeapNumber::cast(*this).value(); 5531cb0ef41Sopenharmony_ci return DoubleToUint32IfEqualToSelf(num, value); 5541cb0ef41Sopenharmony_ci } 5551cb0ef41Sopenharmony_ci return false; 5561cb0ef41Sopenharmony_ci} 5571cb0ef41Sopenharmony_ci 5581cb0ef41Sopenharmony_ci// static 5591cb0ef41Sopenharmony_ciMaybeHandle<JSReceiver> Object::ToObject(Isolate* isolate, 5601cb0ef41Sopenharmony_ci Handle<Object> object, 5611cb0ef41Sopenharmony_ci const char* method_name) { 5621cb0ef41Sopenharmony_ci if (object->IsJSReceiver()) return Handle<JSReceiver>::cast(object); 5631cb0ef41Sopenharmony_ci return ToObjectImpl(isolate, object, method_name); 5641cb0ef41Sopenharmony_ci} 5651cb0ef41Sopenharmony_ci 5661cb0ef41Sopenharmony_ci// static 5671cb0ef41Sopenharmony_ciMaybeHandle<Name> Object::ToName(Isolate* isolate, Handle<Object> input) { 5681cb0ef41Sopenharmony_ci if (input->IsName()) return Handle<Name>::cast(input); 5691cb0ef41Sopenharmony_ci return ConvertToName(isolate, input); 5701cb0ef41Sopenharmony_ci} 5711cb0ef41Sopenharmony_ci 5721cb0ef41Sopenharmony_ci// static 5731cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::ToPropertyKey(Isolate* isolate, 5741cb0ef41Sopenharmony_ci Handle<Object> value) { 5751cb0ef41Sopenharmony_ci if (value->IsSmi() || HeapObject::cast(*value).IsName()) return value; 5761cb0ef41Sopenharmony_ci return ConvertToPropertyKey(isolate, value); 5771cb0ef41Sopenharmony_ci} 5781cb0ef41Sopenharmony_ci 5791cb0ef41Sopenharmony_ci// static 5801cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::ToPrimitive(Isolate* isolate, Handle<Object> input, 5811cb0ef41Sopenharmony_ci ToPrimitiveHint hint) { 5821cb0ef41Sopenharmony_ci if (input->IsPrimitive()) return input; 5831cb0ef41Sopenharmony_ci return JSReceiver::ToPrimitive(isolate, Handle<JSReceiver>::cast(input), 5841cb0ef41Sopenharmony_ci hint); 5851cb0ef41Sopenharmony_ci} 5861cb0ef41Sopenharmony_ci 5871cb0ef41Sopenharmony_ci// static 5881cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::ToNumber(Isolate* isolate, Handle<Object> input) { 5891cb0ef41Sopenharmony_ci if (input->IsNumber()) return input; // Shortcut. 5901cb0ef41Sopenharmony_ci return ConvertToNumberOrNumeric(isolate, input, Conversion::kToNumber); 5911cb0ef41Sopenharmony_ci} 5921cb0ef41Sopenharmony_ci 5931cb0ef41Sopenharmony_ci// static 5941cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::ToNumeric(Isolate* isolate, Handle<Object> input) { 5951cb0ef41Sopenharmony_ci if (input->IsNumber() || input->IsBigInt()) return input; // Shortcut. 5961cb0ef41Sopenharmony_ci return ConvertToNumberOrNumeric(isolate, input, Conversion::kToNumeric); 5971cb0ef41Sopenharmony_ci} 5981cb0ef41Sopenharmony_ci 5991cb0ef41Sopenharmony_ci// static 6001cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::ToInteger(Isolate* isolate, Handle<Object> input) { 6011cb0ef41Sopenharmony_ci if (input->IsSmi()) return input; 6021cb0ef41Sopenharmony_ci return ConvertToInteger(isolate, input); 6031cb0ef41Sopenharmony_ci} 6041cb0ef41Sopenharmony_ci 6051cb0ef41Sopenharmony_ci// static 6061cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::ToInt32(Isolate* isolate, Handle<Object> input) { 6071cb0ef41Sopenharmony_ci if (input->IsSmi()) return input; 6081cb0ef41Sopenharmony_ci return ConvertToInt32(isolate, input); 6091cb0ef41Sopenharmony_ci} 6101cb0ef41Sopenharmony_ci 6111cb0ef41Sopenharmony_ci// static 6121cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::ToUint32(Isolate* isolate, Handle<Object> input) { 6131cb0ef41Sopenharmony_ci if (input->IsSmi()) return handle(Smi::cast(*input).ToUint32Smi(), isolate); 6141cb0ef41Sopenharmony_ci return ConvertToUint32(isolate, input); 6151cb0ef41Sopenharmony_ci} 6161cb0ef41Sopenharmony_ci 6171cb0ef41Sopenharmony_ci// static 6181cb0ef41Sopenharmony_ciMaybeHandle<String> Object::ToString(Isolate* isolate, Handle<Object> input) { 6191cb0ef41Sopenharmony_ci if (input->IsString()) return Handle<String>::cast(input); 6201cb0ef41Sopenharmony_ci return ConvertToString(isolate, input); 6211cb0ef41Sopenharmony_ci} 6221cb0ef41Sopenharmony_ci 6231cb0ef41Sopenharmony_ci// static 6241cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::ToLength(Isolate* isolate, Handle<Object> input) { 6251cb0ef41Sopenharmony_ci if (input->IsSmi()) { 6261cb0ef41Sopenharmony_ci int value = std::max(Smi::ToInt(*input), 0); 6271cb0ef41Sopenharmony_ci return handle(Smi::FromInt(value), isolate); 6281cb0ef41Sopenharmony_ci } 6291cb0ef41Sopenharmony_ci return ConvertToLength(isolate, input); 6301cb0ef41Sopenharmony_ci} 6311cb0ef41Sopenharmony_ci 6321cb0ef41Sopenharmony_ci// static 6331cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::ToIndex(Isolate* isolate, Handle<Object> input, 6341cb0ef41Sopenharmony_ci MessageTemplate error_index) { 6351cb0ef41Sopenharmony_ci if (input->IsSmi() && Smi::ToInt(*input) >= 0) return input; 6361cb0ef41Sopenharmony_ci return ConvertToIndex(isolate, input, error_index); 6371cb0ef41Sopenharmony_ci} 6381cb0ef41Sopenharmony_ci 6391cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::GetProperty(Isolate* isolate, Handle<Object> object, 6401cb0ef41Sopenharmony_ci Handle<Name> name) { 6411cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, name); 6421cb0ef41Sopenharmony_ci if (!it.IsFound()) return it.factory()->undefined_value(); 6431cb0ef41Sopenharmony_ci return GetProperty(&it); 6441cb0ef41Sopenharmony_ci} 6451cb0ef41Sopenharmony_ci 6461cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::GetElement(Isolate* isolate, Handle<Object> object, 6471cb0ef41Sopenharmony_ci uint32_t index) { 6481cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, index); 6491cb0ef41Sopenharmony_ci if (!it.IsFound()) return it.factory()->undefined_value(); 6501cb0ef41Sopenharmony_ci return GetProperty(&it); 6511cb0ef41Sopenharmony_ci} 6521cb0ef41Sopenharmony_ci 6531cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::SetElement(Isolate* isolate, Handle<Object> object, 6541cb0ef41Sopenharmony_ci uint32_t index, Handle<Object> value, 6551cb0ef41Sopenharmony_ci ShouldThrow should_throw) { 6561cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, index); 6571cb0ef41Sopenharmony_ci MAYBE_RETURN_NULL( 6581cb0ef41Sopenharmony_ci SetProperty(&it, value, StoreOrigin::kMaybeKeyed, Just(should_throw))); 6591cb0ef41Sopenharmony_ci return value; 6601cb0ef41Sopenharmony_ci} 6611cb0ef41Sopenharmony_ci 6621cb0ef41Sopenharmony_ciAddress Object::ReadSandboxedPointerField(size_t offset, 6631cb0ef41Sopenharmony_ci PtrComprCageBase cage_base) const { 6641cb0ef41Sopenharmony_ci return i::ReadSandboxedPointerField(field_address(offset), cage_base); 6651cb0ef41Sopenharmony_ci} 6661cb0ef41Sopenharmony_ci 6671cb0ef41Sopenharmony_civoid Object::WriteSandboxedPointerField(size_t offset, 6681cb0ef41Sopenharmony_ci PtrComprCageBase cage_base, 6691cb0ef41Sopenharmony_ci Address value) { 6701cb0ef41Sopenharmony_ci i::WriteSandboxedPointerField(field_address(offset), cage_base, value); 6711cb0ef41Sopenharmony_ci} 6721cb0ef41Sopenharmony_ci 6731cb0ef41Sopenharmony_civoid Object::WriteSandboxedPointerField(size_t offset, Isolate* isolate, 6741cb0ef41Sopenharmony_ci Address value) { 6751cb0ef41Sopenharmony_ci i::WriteSandboxedPointerField(field_address(offset), 6761cb0ef41Sopenharmony_ci PtrComprCageBase(isolate), value); 6771cb0ef41Sopenharmony_ci} 6781cb0ef41Sopenharmony_ci 6791cb0ef41Sopenharmony_civoid Object::InitExternalPointerField(size_t offset, Isolate* isolate, 6801cb0ef41Sopenharmony_ci ExternalPointerTag tag) { 6811cb0ef41Sopenharmony_ci i::InitExternalPointerField(field_address(offset), isolate, tag); 6821cb0ef41Sopenharmony_ci} 6831cb0ef41Sopenharmony_ci 6841cb0ef41Sopenharmony_civoid Object::InitExternalPointerField(size_t offset, Isolate* isolate, 6851cb0ef41Sopenharmony_ci Address value, ExternalPointerTag tag) { 6861cb0ef41Sopenharmony_ci i::InitExternalPointerField(field_address(offset), isolate, value, tag); 6871cb0ef41Sopenharmony_ci} 6881cb0ef41Sopenharmony_ci 6891cb0ef41Sopenharmony_ciAddress Object::ReadExternalPointerField(size_t offset, Isolate* isolate, 6901cb0ef41Sopenharmony_ci ExternalPointerTag tag) const { 6911cb0ef41Sopenharmony_ci return i::ReadExternalPointerField(field_address(offset), isolate, tag); 6921cb0ef41Sopenharmony_ci} 6931cb0ef41Sopenharmony_ci 6941cb0ef41Sopenharmony_civoid Object::WriteExternalPointerField(size_t offset, Isolate* isolate, 6951cb0ef41Sopenharmony_ci Address value, ExternalPointerTag tag) { 6961cb0ef41Sopenharmony_ci i::WriteExternalPointerField(field_address(offset), isolate, value, tag); 6971cb0ef41Sopenharmony_ci} 6981cb0ef41Sopenharmony_ci 6991cb0ef41Sopenharmony_ciObjectSlot HeapObject::RawField(int byte_offset) const { 7001cb0ef41Sopenharmony_ci return ObjectSlot(field_address(byte_offset)); 7011cb0ef41Sopenharmony_ci} 7021cb0ef41Sopenharmony_ci 7031cb0ef41Sopenharmony_ciMaybeObjectSlot HeapObject::RawMaybeWeakField(int byte_offset) const { 7041cb0ef41Sopenharmony_ci return MaybeObjectSlot(field_address(byte_offset)); 7051cb0ef41Sopenharmony_ci} 7061cb0ef41Sopenharmony_ci 7071cb0ef41Sopenharmony_ciCodeObjectSlot HeapObject::RawCodeField(int byte_offset) const { 7081cb0ef41Sopenharmony_ci return CodeObjectSlot(field_address(byte_offset)); 7091cb0ef41Sopenharmony_ci} 7101cb0ef41Sopenharmony_ci 7111cb0ef41Sopenharmony_ciExternalPointer_t HeapObject::RawExternalPointerField(int byte_offset) const { 7121cb0ef41Sopenharmony_ci return ReadRawExternalPointerField(field_address(byte_offset)); 7131cb0ef41Sopenharmony_ci} 7141cb0ef41Sopenharmony_ci 7151cb0ef41Sopenharmony_ciMapWord MapWord::FromMap(const Map map) { 7161cb0ef41Sopenharmony_ci DCHECK(map.is_null() || !MapWord::IsPacked(map.ptr())); 7171cb0ef41Sopenharmony_ci#ifdef V8_MAP_PACKING 7181cb0ef41Sopenharmony_ci return MapWord(Pack(map.ptr())); 7191cb0ef41Sopenharmony_ci#else 7201cb0ef41Sopenharmony_ci return MapWord(map.ptr()); 7211cb0ef41Sopenharmony_ci#endif 7221cb0ef41Sopenharmony_ci} 7231cb0ef41Sopenharmony_ci 7241cb0ef41Sopenharmony_ciMap MapWord::ToMap() const { 7251cb0ef41Sopenharmony_ci#ifdef V8_MAP_PACKING 7261cb0ef41Sopenharmony_ci return Map::unchecked_cast(Object(Unpack(value_))); 7271cb0ef41Sopenharmony_ci#else 7281cb0ef41Sopenharmony_ci return Map::unchecked_cast(Object(value_)); 7291cb0ef41Sopenharmony_ci#endif 7301cb0ef41Sopenharmony_ci} 7311cb0ef41Sopenharmony_ci 7321cb0ef41Sopenharmony_cibool MapWord::IsForwardingAddress() const { 7331cb0ef41Sopenharmony_ci return (value_ & kForwardingTagMask) == kForwardingTag; 7341cb0ef41Sopenharmony_ci} 7351cb0ef41Sopenharmony_ci 7361cb0ef41Sopenharmony_ciMapWord MapWord::FromForwardingAddress(HeapObject object) { 7371cb0ef41Sopenharmony_ci return MapWord(object.ptr() - kHeapObjectTag); 7381cb0ef41Sopenharmony_ci} 7391cb0ef41Sopenharmony_ci 7401cb0ef41Sopenharmony_ciHeapObject MapWord::ToForwardingAddress() { 7411cb0ef41Sopenharmony_ci DCHECK(IsForwardingAddress()); 7421cb0ef41Sopenharmony_ci HeapObject obj = HeapObject::FromAddress(value_); 7431cb0ef41Sopenharmony_ci // For objects allocated outside of the main pointer compression cage the 7441cb0ef41Sopenharmony_ci // variant with explicit cage base must be used. 7451cb0ef41Sopenharmony_ci DCHECK_IMPLIES(V8_EXTERNAL_CODE_SPACE_BOOL, !IsCodeSpaceObject(obj)); 7461cb0ef41Sopenharmony_ci return obj; 7471cb0ef41Sopenharmony_ci} 7481cb0ef41Sopenharmony_ci 7491cb0ef41Sopenharmony_ciHeapObject MapWord::ToForwardingAddress(PtrComprCageBase host_cage_base) { 7501cb0ef41Sopenharmony_ci DCHECK(IsForwardingAddress()); 7511cb0ef41Sopenharmony_ci if (V8_EXTERNAL_CODE_SPACE_BOOL) { 7521cb0ef41Sopenharmony_ci // Recompress value_ using proper host_cage_base since the map word 7531cb0ef41Sopenharmony_ci // has the upper 32 bits that correspond to the main cage base value. 7541cb0ef41Sopenharmony_ci Address value = 7551cb0ef41Sopenharmony_ci DecompressTaggedPointer(host_cage_base, CompressTagged(value_)); 7561cb0ef41Sopenharmony_ci return HeapObject::FromAddress(value); 7571cb0ef41Sopenharmony_ci } 7581cb0ef41Sopenharmony_ci return HeapObject::FromAddress(value_); 7591cb0ef41Sopenharmony_ci} 7601cb0ef41Sopenharmony_ci 7611cb0ef41Sopenharmony_ci#ifdef VERIFY_HEAP 7621cb0ef41Sopenharmony_civoid HeapObject::VerifyObjectField(Isolate* isolate, int offset) { 7631cb0ef41Sopenharmony_ci VerifyPointer(isolate, TaggedField<Object>::load(isolate, *this, offset)); 7641cb0ef41Sopenharmony_ci STATIC_ASSERT(!COMPRESS_POINTERS_BOOL || kTaggedSize == kInt32Size); 7651cb0ef41Sopenharmony_ci} 7661cb0ef41Sopenharmony_ci 7671cb0ef41Sopenharmony_civoid HeapObject::VerifyMaybeObjectField(Isolate* isolate, int offset) { 7681cb0ef41Sopenharmony_ci MaybeObject::VerifyMaybeObjectPointer( 7691cb0ef41Sopenharmony_ci isolate, TaggedField<MaybeObject>::load(isolate, *this, offset)); 7701cb0ef41Sopenharmony_ci STATIC_ASSERT(!COMPRESS_POINTERS_BOOL || kTaggedSize == kInt32Size); 7711cb0ef41Sopenharmony_ci} 7721cb0ef41Sopenharmony_ci 7731cb0ef41Sopenharmony_civoid HeapObject::VerifySmiField(int offset) { 7741cb0ef41Sopenharmony_ci CHECK(TaggedField<Object>::load(*this, offset).IsSmi()); 7751cb0ef41Sopenharmony_ci STATIC_ASSERT(!COMPRESS_POINTERS_BOOL || kTaggedSize == kInt32Size); 7761cb0ef41Sopenharmony_ci} 7771cb0ef41Sopenharmony_ci 7781cb0ef41Sopenharmony_ci#endif 7791cb0ef41Sopenharmony_ci 7801cb0ef41Sopenharmony_ciReadOnlyRoots HeapObject::GetReadOnlyRoots() const { 7811cb0ef41Sopenharmony_ci return ReadOnlyHeap::GetReadOnlyRoots(*this); 7821cb0ef41Sopenharmony_ci} 7831cb0ef41Sopenharmony_ci 7841cb0ef41Sopenharmony_ciReadOnlyRoots HeapObject::GetReadOnlyRoots(PtrComprCageBase cage_base) const { 7851cb0ef41Sopenharmony_ci#ifdef V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE 7861cb0ef41Sopenharmony_ci DCHECK_NE(cage_base.address(), 0); 7871cb0ef41Sopenharmony_ci return ReadOnlyRoots(Isolate::FromRootAddress(cage_base.address())); 7881cb0ef41Sopenharmony_ci#else 7891cb0ef41Sopenharmony_ci return GetReadOnlyRoots(); 7901cb0ef41Sopenharmony_ci#endif 7911cb0ef41Sopenharmony_ci} 7921cb0ef41Sopenharmony_ci 7931cb0ef41Sopenharmony_ciMap HeapObject::map() const { 7941cb0ef41Sopenharmony_ci // This method is never used for objects located in code space (Code and 7951cb0ef41Sopenharmony_ci // free space fillers) and thus it is fine to use auto-computed cage base 7961cb0ef41Sopenharmony_ci // value. 7971cb0ef41Sopenharmony_ci DCHECK_IMPLIES(V8_EXTERNAL_CODE_SPACE_BOOL, !IsCodeSpaceObject(*this)); 7981cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 7991cb0ef41Sopenharmony_ci return HeapObject::map(cage_base); 8001cb0ef41Sopenharmony_ci} 8011cb0ef41Sopenharmony_ciMap HeapObject::map(PtrComprCageBase cage_base) const { 8021cb0ef41Sopenharmony_ci return map_word(cage_base, kRelaxedLoad).ToMap(); 8031cb0ef41Sopenharmony_ci} 8041cb0ef41Sopenharmony_ci 8051cb0ef41Sopenharmony_civoid HeapObject::set_map(Map value) { 8061cb0ef41Sopenharmony_ci set_map<EmitWriteBarrier::kYes>(value, kRelaxedStore, 8071cb0ef41Sopenharmony_ci VerificationMode::kPotentialLayoutChange); 8081cb0ef41Sopenharmony_ci} 8091cb0ef41Sopenharmony_ci 8101cb0ef41Sopenharmony_civoid HeapObject::set_map(Map value, ReleaseStoreTag tag) { 8111cb0ef41Sopenharmony_ci set_map<EmitWriteBarrier::kYes>(value, kReleaseStore, 8121cb0ef41Sopenharmony_ci VerificationMode::kPotentialLayoutChange); 8131cb0ef41Sopenharmony_ci} 8141cb0ef41Sopenharmony_ci 8151cb0ef41Sopenharmony_civoid HeapObject::set_map_safe_transition(Map value) { 8161cb0ef41Sopenharmony_ci set_map<EmitWriteBarrier::kYes>(value, kRelaxedStore, 8171cb0ef41Sopenharmony_ci VerificationMode::kSafeMapTransition); 8181cb0ef41Sopenharmony_ci} 8191cb0ef41Sopenharmony_ci 8201cb0ef41Sopenharmony_civoid HeapObject::set_map_safe_transition(Map value, ReleaseStoreTag tag) { 8211cb0ef41Sopenharmony_ci set_map<EmitWriteBarrier::kYes>(value, kReleaseStore, 8221cb0ef41Sopenharmony_ci VerificationMode::kSafeMapTransition); 8231cb0ef41Sopenharmony_ci} 8241cb0ef41Sopenharmony_ci 8251cb0ef41Sopenharmony_ci// Unsafe accessor omitting write barrier. 8261cb0ef41Sopenharmony_civoid HeapObject::set_map_no_write_barrier(Map value, RelaxedStoreTag tag) { 8271cb0ef41Sopenharmony_ci set_map<EmitWriteBarrier::kNo>(value, kRelaxedStore, 8281cb0ef41Sopenharmony_ci VerificationMode::kPotentialLayoutChange); 8291cb0ef41Sopenharmony_ci} 8301cb0ef41Sopenharmony_ci 8311cb0ef41Sopenharmony_civoid HeapObject::set_map_no_write_barrier(Map value, ReleaseStoreTag tag) { 8321cb0ef41Sopenharmony_ci set_map<EmitWriteBarrier::kNo>(value, kReleaseStore, 8331cb0ef41Sopenharmony_ci VerificationMode::kPotentialLayoutChange); 8341cb0ef41Sopenharmony_ci} 8351cb0ef41Sopenharmony_ci 8361cb0ef41Sopenharmony_citemplate <HeapObject::EmitWriteBarrier emit_write_barrier, typename MemoryOrder> 8371cb0ef41Sopenharmony_civoid HeapObject::set_map(Map value, MemoryOrder order, VerificationMode mode) { 8381cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY 8391cb0ef41Sopenharmony_ci // In {WasmGraphBuilder::SetMap} and {WasmGraphBuilder::LoadMap}, we treat 8401cb0ef41Sopenharmony_ci // maps as immutable. Therefore we are not allowed to mutate them here. 8411cb0ef41Sopenharmony_ci DCHECK(!value.IsWasmStructMap() && !value.IsWasmArrayMap()); 8421cb0ef41Sopenharmony_ci#endif 8431cb0ef41Sopenharmony_ci // Object layout changes are currently not supported on background threads. 8441cb0ef41Sopenharmony_ci // This method might change object layout and therefore can't be used on 8451cb0ef41Sopenharmony_ci // background threads. 8461cb0ef41Sopenharmony_ci DCHECK_IMPLIES(mode != VerificationMode::kSafeMapTransition, 8471cb0ef41Sopenharmony_ci !LocalHeap::Current()); 8481cb0ef41Sopenharmony_ci#ifdef VERIFY_HEAP 8491cb0ef41Sopenharmony_ci if (FLAG_verify_heap && !value.is_null()) { 8501cb0ef41Sopenharmony_ci Heap* heap = GetHeapFromWritableObject(*this); 8511cb0ef41Sopenharmony_ci if (mode == VerificationMode::kSafeMapTransition) { 8521cb0ef41Sopenharmony_ci heap->VerifySafeMapTransition(*this, value); 8531cb0ef41Sopenharmony_ci } else { 8541cb0ef41Sopenharmony_ci DCHECK_EQ(mode, VerificationMode::kPotentialLayoutChange); 8551cb0ef41Sopenharmony_ci heap->VerifyObjectLayoutChange(*this, value); 8561cb0ef41Sopenharmony_ci } 8571cb0ef41Sopenharmony_ci } 8581cb0ef41Sopenharmony_ci#endif 8591cb0ef41Sopenharmony_ci set_map_word(MapWord::FromMap(value), order); 8601cb0ef41Sopenharmony_ci#ifndef V8_DISABLE_WRITE_BARRIERS 8611cb0ef41Sopenharmony_ci if (!value.is_null()) { 8621cb0ef41Sopenharmony_ci if (emit_write_barrier == EmitWriteBarrier::kYes) { 8631cb0ef41Sopenharmony_ci WriteBarrier::Marking(*this, map_slot(), value); 8641cb0ef41Sopenharmony_ci } else { 8651cb0ef41Sopenharmony_ci DCHECK_EQ(emit_write_barrier, EmitWriteBarrier::kNo); 8661cb0ef41Sopenharmony_ci SLOW_DCHECK(!WriteBarrier::IsRequired(*this, value)); 8671cb0ef41Sopenharmony_ci } 8681cb0ef41Sopenharmony_ci } 8691cb0ef41Sopenharmony_ci#endif 8701cb0ef41Sopenharmony_ci} 8711cb0ef41Sopenharmony_ci 8721cb0ef41Sopenharmony_civoid HeapObject::set_map_after_allocation(Map value, WriteBarrierMode mode) { 8731cb0ef41Sopenharmony_ci MapWord mapword = MapWord::FromMap(value); 8741cb0ef41Sopenharmony_ci set_map_word(mapword, kRelaxedStore); 8751cb0ef41Sopenharmony_ci#ifndef V8_DISABLE_WRITE_BARRIERS 8761cb0ef41Sopenharmony_ci if (mode != SKIP_WRITE_BARRIER) { 8771cb0ef41Sopenharmony_ci DCHECK(!value.is_null()); 8781cb0ef41Sopenharmony_ci WriteBarrier::Marking(*this, map_slot(), value); 8791cb0ef41Sopenharmony_ci } else { 8801cb0ef41Sopenharmony_ci SLOW_DCHECK(!WriteBarrier::IsRequired(*this, value)); 8811cb0ef41Sopenharmony_ci } 8821cb0ef41Sopenharmony_ci#endif 8831cb0ef41Sopenharmony_ci} 8841cb0ef41Sopenharmony_ci 8851cb0ef41Sopenharmony_ciDEF_ACQUIRE_GETTER(HeapObject, map, Map) { 8861cb0ef41Sopenharmony_ci return map_word(cage_base, kAcquireLoad).ToMap(); 8871cb0ef41Sopenharmony_ci} 8881cb0ef41Sopenharmony_ci 8891cb0ef41Sopenharmony_ciObjectSlot HeapObject::map_slot() const { 8901cb0ef41Sopenharmony_ci return ObjectSlot(MapField::address(*this)); 8911cb0ef41Sopenharmony_ci} 8921cb0ef41Sopenharmony_ci 8931cb0ef41Sopenharmony_ciMapWord HeapObject::map_word(RelaxedLoadTag tag) const { 8941cb0ef41Sopenharmony_ci // This method is never used for objects located in code space (Code and 8951cb0ef41Sopenharmony_ci // free space fillers) and thus it is fine to use auto-computed cage base 8961cb0ef41Sopenharmony_ci // value. 8971cb0ef41Sopenharmony_ci DCHECK_IMPLIES(V8_EXTERNAL_CODE_SPACE_BOOL, !IsCodeSpaceObject(*this)); 8981cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 8991cb0ef41Sopenharmony_ci return HeapObject::map_word(cage_base, tag); 9001cb0ef41Sopenharmony_ci} 9011cb0ef41Sopenharmony_ciMapWord HeapObject::map_word(PtrComprCageBase cage_base, 9021cb0ef41Sopenharmony_ci RelaxedLoadTag tag) const { 9031cb0ef41Sopenharmony_ci return MapField::Relaxed_Load_Map_Word(cage_base, *this); 9041cb0ef41Sopenharmony_ci} 9051cb0ef41Sopenharmony_ci 9061cb0ef41Sopenharmony_civoid HeapObject::set_map_word(MapWord map_word, RelaxedStoreTag) { 9071cb0ef41Sopenharmony_ci MapField::Relaxed_Store_Map_Word(*this, map_word); 9081cb0ef41Sopenharmony_ci} 9091cb0ef41Sopenharmony_ci 9101cb0ef41Sopenharmony_ciMapWord HeapObject::map_word(AcquireLoadTag tag) const { 9111cb0ef41Sopenharmony_ci // This method is never used for objects located in code space (Code and 9121cb0ef41Sopenharmony_ci // free space fillers) and thus it is fine to use auto-computed cage base 9131cb0ef41Sopenharmony_ci // value. 9141cb0ef41Sopenharmony_ci DCHECK_IMPLIES(V8_EXTERNAL_CODE_SPACE_BOOL, !IsCodeSpaceObject(*this)); 9151cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 9161cb0ef41Sopenharmony_ci return HeapObject::map_word(cage_base, tag); 9171cb0ef41Sopenharmony_ci} 9181cb0ef41Sopenharmony_ciMapWord HeapObject::map_word(PtrComprCageBase cage_base, 9191cb0ef41Sopenharmony_ci AcquireLoadTag tag) const { 9201cb0ef41Sopenharmony_ci return MapField::Acquire_Load_No_Unpack(cage_base, *this); 9211cb0ef41Sopenharmony_ci} 9221cb0ef41Sopenharmony_ci 9231cb0ef41Sopenharmony_civoid HeapObject::set_map_word(MapWord map_word, ReleaseStoreTag) { 9241cb0ef41Sopenharmony_ci MapField::Release_Store_Map_Word(*this, map_word); 9251cb0ef41Sopenharmony_ci} 9261cb0ef41Sopenharmony_ci 9271cb0ef41Sopenharmony_cibool HeapObject::release_compare_and_swap_map_word(MapWord old_map_word, 9281cb0ef41Sopenharmony_ci MapWord new_map_word) { 9291cb0ef41Sopenharmony_ci Tagged_t result = 9301cb0ef41Sopenharmony_ci MapField::Release_CompareAndSwap(*this, old_map_word, new_map_word); 9311cb0ef41Sopenharmony_ci return result == static_cast<Tagged_t>(old_map_word.ptr()); 9321cb0ef41Sopenharmony_ci} 9331cb0ef41Sopenharmony_ci 9341cb0ef41Sopenharmony_ci// TODO(v8:11880): consider dropping parameterless version. 9351cb0ef41Sopenharmony_ciint HeapObject::Size() const { 9361cb0ef41Sopenharmony_ci DCHECK_IMPLIES(V8_EXTERNAL_CODE_SPACE_BOOL, !IsCodeSpaceObject(*this)); 9371cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 9381cb0ef41Sopenharmony_ci return HeapObject::Size(cage_base); 9391cb0ef41Sopenharmony_ci} 9401cb0ef41Sopenharmony_ciint HeapObject::Size(PtrComprCageBase cage_base) const { 9411cb0ef41Sopenharmony_ci return SizeFromMap(map(cage_base)); 9421cb0ef41Sopenharmony_ci} 9431cb0ef41Sopenharmony_ci 9441cb0ef41Sopenharmony_ciinline bool IsSpecialReceiverInstanceType(InstanceType instance_type) { 9451cb0ef41Sopenharmony_ci return instance_type <= LAST_SPECIAL_RECEIVER_TYPE; 9461cb0ef41Sopenharmony_ci} 9471cb0ef41Sopenharmony_ci 9481cb0ef41Sopenharmony_ci// This should be in objects/map-inl.h, but can't, because of a cyclic 9491cb0ef41Sopenharmony_ci// dependency. 9501cb0ef41Sopenharmony_cibool Map::IsSpecialReceiverMap() const { 9511cb0ef41Sopenharmony_ci bool result = IsSpecialReceiverInstanceType(instance_type()); 9521cb0ef41Sopenharmony_ci DCHECK_IMPLIES(!result, 9531cb0ef41Sopenharmony_ci !has_named_interceptor() && !is_access_check_needed()); 9541cb0ef41Sopenharmony_ci return result; 9551cb0ef41Sopenharmony_ci} 9561cb0ef41Sopenharmony_ci 9571cb0ef41Sopenharmony_ciinline bool IsCustomElementsReceiverInstanceType(InstanceType instance_type) { 9581cb0ef41Sopenharmony_ci return instance_type <= LAST_CUSTOM_ELEMENTS_RECEIVER; 9591cb0ef41Sopenharmony_ci} 9601cb0ef41Sopenharmony_ci 9611cb0ef41Sopenharmony_ci// This should be in objects/map-inl.h, but can't, because of a cyclic 9621cb0ef41Sopenharmony_ci// dependency. 9631cb0ef41Sopenharmony_cibool Map::IsCustomElementsReceiverMap() const { 9641cb0ef41Sopenharmony_ci return IsCustomElementsReceiverInstanceType(instance_type()); 9651cb0ef41Sopenharmony_ci} 9661cb0ef41Sopenharmony_ci 9671cb0ef41Sopenharmony_cibool Object::ToArrayLength(uint32_t* index) const { 9681cb0ef41Sopenharmony_ci return Object::ToUint32(index); 9691cb0ef41Sopenharmony_ci} 9701cb0ef41Sopenharmony_ci 9711cb0ef41Sopenharmony_cibool Object::ToArrayIndex(uint32_t* index) const { 9721cb0ef41Sopenharmony_ci return Object::ToUint32(index) && *index != kMaxUInt32; 9731cb0ef41Sopenharmony_ci} 9741cb0ef41Sopenharmony_ci 9751cb0ef41Sopenharmony_cibool Object::ToIntegerIndex(size_t* index) const { 9761cb0ef41Sopenharmony_ci if (IsSmi()) { 9771cb0ef41Sopenharmony_ci int num = Smi::ToInt(*this); 9781cb0ef41Sopenharmony_ci if (num < 0) return false; 9791cb0ef41Sopenharmony_ci *index = static_cast<size_t>(num); 9801cb0ef41Sopenharmony_ci return true; 9811cb0ef41Sopenharmony_ci } 9821cb0ef41Sopenharmony_ci if (IsHeapNumber()) { 9831cb0ef41Sopenharmony_ci double num = HeapNumber::cast(*this).value(); 9841cb0ef41Sopenharmony_ci if (!(num >= 0)) return false; // Negation to catch NaNs. 9851cb0ef41Sopenharmony_ci constexpr double max = 9861cb0ef41Sopenharmony_ci std::min(kMaxSafeInteger, 9871cb0ef41Sopenharmony_ci // The maximum size_t is reserved as "invalid" sentinel. 9881cb0ef41Sopenharmony_ci static_cast<double>(std::numeric_limits<size_t>::max() - 1)); 9891cb0ef41Sopenharmony_ci if (num > max) return false; 9901cb0ef41Sopenharmony_ci size_t result = static_cast<size_t>(num); 9911cb0ef41Sopenharmony_ci if (num != result) return false; // Conversion lost fractional precision. 9921cb0ef41Sopenharmony_ci *index = result; 9931cb0ef41Sopenharmony_ci return true; 9941cb0ef41Sopenharmony_ci } 9951cb0ef41Sopenharmony_ci return false; 9961cb0ef41Sopenharmony_ci} 9971cb0ef41Sopenharmony_ci 9981cb0ef41Sopenharmony_ciWriteBarrierMode HeapObject::GetWriteBarrierMode( 9991cb0ef41Sopenharmony_ci const DisallowGarbageCollection& promise) { 10001cb0ef41Sopenharmony_ci return GetWriteBarrierModeForObject(*this, &promise); 10011cb0ef41Sopenharmony_ci} 10021cb0ef41Sopenharmony_ci 10031cb0ef41Sopenharmony_ci// static 10041cb0ef41Sopenharmony_ciAllocationAlignment HeapObject::RequiredAlignment(Map map) { 10051cb0ef41Sopenharmony_ci // TODO(v8:4153): We should think about requiring double alignment 10061cb0ef41Sopenharmony_ci // in general for ByteArray, since they are used as backing store for typed 10071cb0ef41Sopenharmony_ci // arrays now. 10081cb0ef41Sopenharmony_ci // TODO(ishell, v8:8875): Consider using aligned allocations for BigInt. 10091cb0ef41Sopenharmony_ci if (USE_ALLOCATION_ALIGNMENT_BOOL) { 10101cb0ef41Sopenharmony_ci int instance_type = map.instance_type(); 10111cb0ef41Sopenharmony_ci if (instance_type == FIXED_DOUBLE_ARRAY_TYPE) return kDoubleAligned; 10121cb0ef41Sopenharmony_ci if (instance_type == HEAP_NUMBER_TYPE) return kDoubleUnaligned; 10131cb0ef41Sopenharmony_ci } 10141cb0ef41Sopenharmony_ci return kTaggedAligned; 10151cb0ef41Sopenharmony_ci} 10161cb0ef41Sopenharmony_ci 10171cb0ef41Sopenharmony_ciAddress HeapObject::GetFieldAddress(int field_offset) const { 10181cb0ef41Sopenharmony_ci return field_address(field_offset); 10191cb0ef41Sopenharmony_ci} 10201cb0ef41Sopenharmony_ci 10211cb0ef41Sopenharmony_ci// static 10221cb0ef41Sopenharmony_ciMaybe<bool> Object::GreaterThan(Isolate* isolate, Handle<Object> x, 10231cb0ef41Sopenharmony_ci Handle<Object> y) { 10241cb0ef41Sopenharmony_ci Maybe<ComparisonResult> result = Compare(isolate, x, y); 10251cb0ef41Sopenharmony_ci if (result.IsJust()) { 10261cb0ef41Sopenharmony_ci switch (result.FromJust()) { 10271cb0ef41Sopenharmony_ci case ComparisonResult::kGreaterThan: 10281cb0ef41Sopenharmony_ci return Just(true); 10291cb0ef41Sopenharmony_ci case ComparisonResult::kLessThan: 10301cb0ef41Sopenharmony_ci case ComparisonResult::kEqual: 10311cb0ef41Sopenharmony_ci case ComparisonResult::kUndefined: 10321cb0ef41Sopenharmony_ci return Just(false); 10331cb0ef41Sopenharmony_ci } 10341cb0ef41Sopenharmony_ci } 10351cb0ef41Sopenharmony_ci return Nothing<bool>(); 10361cb0ef41Sopenharmony_ci} 10371cb0ef41Sopenharmony_ci 10381cb0ef41Sopenharmony_ci// static 10391cb0ef41Sopenharmony_ciMaybe<bool> Object::GreaterThanOrEqual(Isolate* isolate, Handle<Object> x, 10401cb0ef41Sopenharmony_ci Handle<Object> y) { 10411cb0ef41Sopenharmony_ci Maybe<ComparisonResult> result = Compare(isolate, x, y); 10421cb0ef41Sopenharmony_ci if (result.IsJust()) { 10431cb0ef41Sopenharmony_ci switch (result.FromJust()) { 10441cb0ef41Sopenharmony_ci case ComparisonResult::kEqual: 10451cb0ef41Sopenharmony_ci case ComparisonResult::kGreaterThan: 10461cb0ef41Sopenharmony_ci return Just(true); 10471cb0ef41Sopenharmony_ci case ComparisonResult::kLessThan: 10481cb0ef41Sopenharmony_ci case ComparisonResult::kUndefined: 10491cb0ef41Sopenharmony_ci return Just(false); 10501cb0ef41Sopenharmony_ci } 10511cb0ef41Sopenharmony_ci } 10521cb0ef41Sopenharmony_ci return Nothing<bool>(); 10531cb0ef41Sopenharmony_ci} 10541cb0ef41Sopenharmony_ci 10551cb0ef41Sopenharmony_ci// static 10561cb0ef41Sopenharmony_ciMaybe<bool> Object::LessThan(Isolate* isolate, Handle<Object> x, 10571cb0ef41Sopenharmony_ci Handle<Object> y) { 10581cb0ef41Sopenharmony_ci Maybe<ComparisonResult> result = Compare(isolate, x, y); 10591cb0ef41Sopenharmony_ci if (result.IsJust()) { 10601cb0ef41Sopenharmony_ci switch (result.FromJust()) { 10611cb0ef41Sopenharmony_ci case ComparisonResult::kLessThan: 10621cb0ef41Sopenharmony_ci return Just(true); 10631cb0ef41Sopenharmony_ci case ComparisonResult::kEqual: 10641cb0ef41Sopenharmony_ci case ComparisonResult::kGreaterThan: 10651cb0ef41Sopenharmony_ci case ComparisonResult::kUndefined: 10661cb0ef41Sopenharmony_ci return Just(false); 10671cb0ef41Sopenharmony_ci } 10681cb0ef41Sopenharmony_ci } 10691cb0ef41Sopenharmony_ci return Nothing<bool>(); 10701cb0ef41Sopenharmony_ci} 10711cb0ef41Sopenharmony_ci 10721cb0ef41Sopenharmony_ci// static 10731cb0ef41Sopenharmony_ciMaybe<bool> Object::LessThanOrEqual(Isolate* isolate, Handle<Object> x, 10741cb0ef41Sopenharmony_ci Handle<Object> y) { 10751cb0ef41Sopenharmony_ci Maybe<ComparisonResult> result = Compare(isolate, x, y); 10761cb0ef41Sopenharmony_ci if (result.IsJust()) { 10771cb0ef41Sopenharmony_ci switch (result.FromJust()) { 10781cb0ef41Sopenharmony_ci case ComparisonResult::kEqual: 10791cb0ef41Sopenharmony_ci case ComparisonResult::kLessThan: 10801cb0ef41Sopenharmony_ci return Just(true); 10811cb0ef41Sopenharmony_ci case ComparisonResult::kGreaterThan: 10821cb0ef41Sopenharmony_ci case ComparisonResult::kUndefined: 10831cb0ef41Sopenharmony_ci return Just(false); 10841cb0ef41Sopenharmony_ci } 10851cb0ef41Sopenharmony_ci } 10861cb0ef41Sopenharmony_ci return Nothing<bool>(); 10871cb0ef41Sopenharmony_ci} 10881cb0ef41Sopenharmony_ci 10891cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::GetPropertyOrElement(Isolate* isolate, 10901cb0ef41Sopenharmony_ci Handle<Object> object, 10911cb0ef41Sopenharmony_ci Handle<Name> name) { 10921cb0ef41Sopenharmony_ci PropertyKey key(isolate, name); 10931cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, key); 10941cb0ef41Sopenharmony_ci return GetProperty(&it); 10951cb0ef41Sopenharmony_ci} 10961cb0ef41Sopenharmony_ci 10971cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::SetPropertyOrElement( 10981cb0ef41Sopenharmony_ci Isolate* isolate, Handle<Object> object, Handle<Name> name, 10991cb0ef41Sopenharmony_ci Handle<Object> value, Maybe<ShouldThrow> should_throw, 11001cb0ef41Sopenharmony_ci StoreOrigin store_origin) { 11011cb0ef41Sopenharmony_ci PropertyKey key(isolate, name); 11021cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, key); 11031cb0ef41Sopenharmony_ci MAYBE_RETURN_NULL(SetProperty(&it, value, store_origin, should_throw)); 11041cb0ef41Sopenharmony_ci return value; 11051cb0ef41Sopenharmony_ci} 11061cb0ef41Sopenharmony_ci 11071cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::GetPropertyOrElement(Handle<Object> receiver, 11081cb0ef41Sopenharmony_ci Handle<Name> name, 11091cb0ef41Sopenharmony_ci Handle<JSReceiver> holder) { 11101cb0ef41Sopenharmony_ci Isolate* isolate = holder->GetIsolate(); 11111cb0ef41Sopenharmony_ci PropertyKey key(isolate, name); 11121cb0ef41Sopenharmony_ci LookupIterator it(isolate, receiver, key, holder); 11131cb0ef41Sopenharmony_ci return GetProperty(&it); 11141cb0ef41Sopenharmony_ci} 11151cb0ef41Sopenharmony_ci 11161cb0ef41Sopenharmony_ci// static 11171cb0ef41Sopenharmony_ciObject Object::GetSimpleHash(Object object) { 11181cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 11191cb0ef41Sopenharmony_ci if (object.IsSmi()) { 11201cb0ef41Sopenharmony_ci uint32_t hash = ComputeUnseededHash(Smi::ToInt(object)); 11211cb0ef41Sopenharmony_ci return Smi::FromInt(hash & Smi::kMaxValue); 11221cb0ef41Sopenharmony_ci } 11231cb0ef41Sopenharmony_ci auto instance_type = HeapObject::cast(object).map().instance_type(); 11241cb0ef41Sopenharmony_ci if (InstanceTypeChecker::IsHeapNumber(instance_type)) { 11251cb0ef41Sopenharmony_ci double num = HeapNumber::cast(object).value(); 11261cb0ef41Sopenharmony_ci if (std::isnan(num)) return Smi::FromInt(Smi::kMaxValue); 11271cb0ef41Sopenharmony_ci // Use ComputeUnseededHash for all values in Signed32 range, including -0, 11281cb0ef41Sopenharmony_ci // which is considered equal to 0 because collections use SameValueZero. 11291cb0ef41Sopenharmony_ci uint32_t hash; 11301cb0ef41Sopenharmony_ci // Check range before conversion to avoid undefined behavior. 11311cb0ef41Sopenharmony_ci if (num >= kMinInt && num <= kMaxInt && FastI2D(FastD2I(num)) == num) { 11321cb0ef41Sopenharmony_ci hash = ComputeUnseededHash(FastD2I(num)); 11331cb0ef41Sopenharmony_ci } else { 11341cb0ef41Sopenharmony_ci hash = ComputeLongHash(base::double_to_uint64(num)); 11351cb0ef41Sopenharmony_ci } 11361cb0ef41Sopenharmony_ci return Smi::FromInt(hash & Smi::kMaxValue); 11371cb0ef41Sopenharmony_ci } else if (InstanceTypeChecker::IsName(instance_type)) { 11381cb0ef41Sopenharmony_ci uint32_t hash = Name::cast(object).EnsureHash(); 11391cb0ef41Sopenharmony_ci return Smi::FromInt(hash); 11401cb0ef41Sopenharmony_ci } else if (InstanceTypeChecker::IsOddball(instance_type)) { 11411cb0ef41Sopenharmony_ci uint32_t hash = Oddball::cast(object).to_string().EnsureHash(); 11421cb0ef41Sopenharmony_ci return Smi::FromInt(hash); 11431cb0ef41Sopenharmony_ci } else if (InstanceTypeChecker::IsBigInt(instance_type)) { 11441cb0ef41Sopenharmony_ci uint32_t hash = BigInt::cast(object).Hash(); 11451cb0ef41Sopenharmony_ci return Smi::FromInt(hash & Smi::kMaxValue); 11461cb0ef41Sopenharmony_ci } else if (InstanceTypeChecker::IsSharedFunctionInfo(instance_type)) { 11471cb0ef41Sopenharmony_ci uint32_t hash = SharedFunctionInfo::cast(object).Hash(); 11481cb0ef41Sopenharmony_ci return Smi::FromInt(hash & Smi::kMaxValue); 11491cb0ef41Sopenharmony_ci } 11501cb0ef41Sopenharmony_ci DCHECK(object.IsJSReceiver()); 11511cb0ef41Sopenharmony_ci return object; 11521cb0ef41Sopenharmony_ci} 11531cb0ef41Sopenharmony_ci 11541cb0ef41Sopenharmony_ciObject Object::GetHash() { 11551cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 11561cb0ef41Sopenharmony_ci Object hash = GetSimpleHash(*this); 11571cb0ef41Sopenharmony_ci if (hash.IsSmi()) return hash; 11581cb0ef41Sopenharmony_ci 11591cb0ef41Sopenharmony_ci DCHECK(IsJSReceiver()); 11601cb0ef41Sopenharmony_ci JSReceiver receiver = JSReceiver::cast(*this); 11611cb0ef41Sopenharmony_ci return receiver.GetIdentityHash(); 11621cb0ef41Sopenharmony_ci} 11631cb0ef41Sopenharmony_ci 11641cb0ef41Sopenharmony_cibool Object::IsShared() const { 11651cb0ef41Sopenharmony_ci // This logic should be kept in sync with fast paths in 11661cb0ef41Sopenharmony_ci // CodeStubAssembler::SharedValueBarrier. 11671cb0ef41Sopenharmony_ci 11681cb0ef41Sopenharmony_ci // Smis are trivially shared. 11691cb0ef41Sopenharmony_ci if (IsSmi()) return true; 11701cb0ef41Sopenharmony_ci 11711cb0ef41Sopenharmony_ci HeapObject object = HeapObject::cast(*this); 11721cb0ef41Sopenharmony_ci 11731cb0ef41Sopenharmony_ci // RO objects are shared when the RO space is shared. 11741cb0ef41Sopenharmony_ci if (IsReadOnlyHeapObject(object)) { 11751cb0ef41Sopenharmony_ci return ReadOnlyHeap::IsReadOnlySpaceShared(); 11761cb0ef41Sopenharmony_ci } 11771cb0ef41Sopenharmony_ci 11781cb0ef41Sopenharmony_ci // Check if this object is already shared. 11791cb0ef41Sopenharmony_ci switch (object.map().instance_type()) { 11801cb0ef41Sopenharmony_ci case SHARED_STRING_TYPE: 11811cb0ef41Sopenharmony_ci case SHARED_ONE_BYTE_STRING_TYPE: 11821cb0ef41Sopenharmony_ci case JS_SHARED_STRUCT_TYPE: 11831cb0ef41Sopenharmony_ci DCHECK(object.InSharedHeap()); 11841cb0ef41Sopenharmony_ci return true; 11851cb0ef41Sopenharmony_ci case INTERNALIZED_STRING_TYPE: 11861cb0ef41Sopenharmony_ci case ONE_BYTE_INTERNALIZED_STRING_TYPE: 11871cb0ef41Sopenharmony_ci if (FLAG_shared_string_table) { 11881cb0ef41Sopenharmony_ci DCHECK(object.InSharedHeap()); 11891cb0ef41Sopenharmony_ci return true; 11901cb0ef41Sopenharmony_ci } 11911cb0ef41Sopenharmony_ci return false; 11921cb0ef41Sopenharmony_ci case HEAP_NUMBER_TYPE: 11931cb0ef41Sopenharmony_ci return object.InSharedWritableHeap(); 11941cb0ef41Sopenharmony_ci default: 11951cb0ef41Sopenharmony_ci return false; 11961cb0ef41Sopenharmony_ci } 11971cb0ef41Sopenharmony_ci} 11981cb0ef41Sopenharmony_ci 11991cb0ef41Sopenharmony_ci// static 12001cb0ef41Sopenharmony_ciMaybeHandle<Object> Object::Share(Isolate* isolate, Handle<Object> value, 12011cb0ef41Sopenharmony_ci ShouldThrow throw_if_cannot_be_shared) { 12021cb0ef41Sopenharmony_ci // Sharing values requires the RO space be shared. 12031cb0ef41Sopenharmony_ci DCHECK(ReadOnlyHeap::IsReadOnlySpaceShared()); 12041cb0ef41Sopenharmony_ci if (value->IsShared()) return value; 12051cb0ef41Sopenharmony_ci return ShareSlow(isolate, Handle<HeapObject>::cast(value), 12061cb0ef41Sopenharmony_ci throw_if_cannot_be_shared); 12071cb0ef41Sopenharmony_ci} 12081cb0ef41Sopenharmony_ci 12091cb0ef41Sopenharmony_ci// https://tc39.es/ecma262/#sec-canbeheldweakly 12101cb0ef41Sopenharmony_cibool Object::CanBeHeldWeakly() const { 12111cb0ef41Sopenharmony_ci if (IsJSReceiver()) { 12121cb0ef41Sopenharmony_ci // TODO(v8:12547) Shared structs and arrays should only be able to point 12131cb0ef41Sopenharmony_ci // to shared values in weak collections. For now, disallow them as weak 12141cb0ef41Sopenharmony_ci // collection keys. 12151cb0ef41Sopenharmony_ci if (FLAG_harmony_struct) { 12161cb0ef41Sopenharmony_ci return !IsJSSharedStruct(); 12171cb0ef41Sopenharmony_ci } 12181cb0ef41Sopenharmony_ci return true; 12191cb0ef41Sopenharmony_ci } 12201cb0ef41Sopenharmony_ci return IsSymbol() && !Symbol::cast(*this).is_in_public_symbol_table(); 12211cb0ef41Sopenharmony_ci} 12221cb0ef41Sopenharmony_ci 12231cb0ef41Sopenharmony_ciHandle<Object> ObjectHashTableShape::AsHandle(Handle<Object> key) { 12241cb0ef41Sopenharmony_ci return key; 12251cb0ef41Sopenharmony_ci} 12261cb0ef41Sopenharmony_ci 12271cb0ef41Sopenharmony_ciRelocatable::Relocatable(Isolate* isolate) { 12281cb0ef41Sopenharmony_ci isolate_ = isolate; 12291cb0ef41Sopenharmony_ci prev_ = isolate->relocatable_top(); 12301cb0ef41Sopenharmony_ci isolate->set_relocatable_top(this); 12311cb0ef41Sopenharmony_ci} 12321cb0ef41Sopenharmony_ci 12331cb0ef41Sopenharmony_ciRelocatable::~Relocatable() { 12341cb0ef41Sopenharmony_ci DCHECK_EQ(isolate_->relocatable_top(), this); 12351cb0ef41Sopenharmony_ci isolate_->set_relocatable_top(prev_); 12361cb0ef41Sopenharmony_ci} 12371cb0ef41Sopenharmony_ci 12381cb0ef41Sopenharmony_ci// Predictably converts HeapObject or Address to uint32 by calculating 12391cb0ef41Sopenharmony_ci// offset of the address in respective MemoryChunk. 12401cb0ef41Sopenharmony_cistatic inline uint32_t ObjectAddressForHashing(Address object) { 12411cb0ef41Sopenharmony_ci uint32_t value = static_cast<uint32_t>(object); 12421cb0ef41Sopenharmony_ci return value & kPageAlignmentMask; 12431cb0ef41Sopenharmony_ci} 12441cb0ef41Sopenharmony_ci 12451cb0ef41Sopenharmony_cistatic inline Handle<Object> MakeEntryPair(Isolate* isolate, size_t index, 12461cb0ef41Sopenharmony_ci Handle<Object> value) { 12471cb0ef41Sopenharmony_ci Handle<Object> key = isolate->factory()->SizeToString(index); 12481cb0ef41Sopenharmony_ci Handle<FixedArray> entry_storage = isolate->factory()->NewFixedArray(2); 12491cb0ef41Sopenharmony_ci { 12501cb0ef41Sopenharmony_ci entry_storage->set(0, *key, SKIP_WRITE_BARRIER); 12511cb0ef41Sopenharmony_ci entry_storage->set(1, *value, SKIP_WRITE_BARRIER); 12521cb0ef41Sopenharmony_ci } 12531cb0ef41Sopenharmony_ci return isolate->factory()->NewJSArrayWithElements(entry_storage, 12541cb0ef41Sopenharmony_ci PACKED_ELEMENTS, 2); 12551cb0ef41Sopenharmony_ci} 12561cb0ef41Sopenharmony_ci 12571cb0ef41Sopenharmony_cistatic inline Handle<Object> MakeEntryPair(Isolate* isolate, Handle<Object> key, 12581cb0ef41Sopenharmony_ci Handle<Object> value) { 12591cb0ef41Sopenharmony_ci Handle<FixedArray> entry_storage = isolate->factory()->NewFixedArray(2); 12601cb0ef41Sopenharmony_ci { 12611cb0ef41Sopenharmony_ci entry_storage->set(0, *key, SKIP_WRITE_BARRIER); 12621cb0ef41Sopenharmony_ci entry_storage->set(1, *value, SKIP_WRITE_BARRIER); 12631cb0ef41Sopenharmony_ci } 12641cb0ef41Sopenharmony_ci return isolate->factory()->NewJSArrayWithElements(entry_storage, 12651cb0ef41Sopenharmony_ci PACKED_ELEMENTS, 2); 12661cb0ef41Sopenharmony_ci} 12671cb0ef41Sopenharmony_ci 12681cb0ef41Sopenharmony_ciFreshlyAllocatedBigInt FreshlyAllocatedBigInt::cast(Object object) { 12691cb0ef41Sopenharmony_ci SLOW_DCHECK(object.IsBigInt()); 12701cb0ef41Sopenharmony_ci return FreshlyAllocatedBigInt(object.ptr()); 12711cb0ef41Sopenharmony_ci} 12721cb0ef41Sopenharmony_ci 12731cb0ef41Sopenharmony_ci} // namespace internal 12741cb0ef41Sopenharmony_ci} // namespace v8 12751cb0ef41Sopenharmony_ci 12761cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h" 12771cb0ef41Sopenharmony_ci 12781cb0ef41Sopenharmony_ci#endif // V8_OBJECTS_OBJECTS_INL_H_ 1279