11cb0ef41Sopenharmony_ci// Copyright 2018 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#ifndef V8_OBJECTS_JS_OBJECTS_INL_H_ 61cb0ef41Sopenharmony_ci#define V8_OBJECTS_JS_OBJECTS_INL_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/common/globals.h" 91cb0ef41Sopenharmony_ci#include "src/heap/heap-write-barrier.h" 101cb0ef41Sopenharmony_ci#include "src/objects/elements.h" 111cb0ef41Sopenharmony_ci#include "src/objects/embedder-data-slot-inl.h" 121cb0ef41Sopenharmony_ci#include "src/objects/feedback-vector.h" 131cb0ef41Sopenharmony_ci#include "src/objects/field-index-inl.h" 141cb0ef41Sopenharmony_ci#include "src/objects/hash-table-inl.h" 151cb0ef41Sopenharmony_ci#include "src/objects/heap-number-inl.h" 161cb0ef41Sopenharmony_ci#include "src/objects/js-objects.h" 171cb0ef41Sopenharmony_ci#include "src/objects/keys.h" 181cb0ef41Sopenharmony_ci#include "src/objects/lookup-inl.h" 191cb0ef41Sopenharmony_ci#include "src/objects/property-array-inl.h" 201cb0ef41Sopenharmony_ci#include "src/objects/prototype-inl.h" 211cb0ef41Sopenharmony_ci#include "src/objects/shared-function-info.h" 221cb0ef41Sopenharmony_ci#include "src/objects/slots.h" 231cb0ef41Sopenharmony_ci#include "src/objects/smi-inl.h" 241cb0ef41Sopenharmony_ci#include "src/objects/swiss-name-dictionary-inl.h" 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards): 271cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h" 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_cinamespace v8 { 301cb0ef41Sopenharmony_cinamespace internal { 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/js-objects-tq-inl.inc" 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSReceiver) 351cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSObject) 361cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSObjectWithEmbedderSlots) 371cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSCustomElementsObject) 381cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSSpecialObject) 391cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSAsyncFromSyncIterator) 401cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSDate) 411cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSGlobalObject) 421cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSGlobalProxy) 431cb0ef41Sopenharmony_ciJSIteratorResult::JSIteratorResult(Address ptr) : JSObject(ptr) {} 441cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSMessageObject) 451cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSPrimitiveWrapper) 461cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSStringIterator) 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ciNEVER_READ_ONLY_SPACE_IMPL(JSReceiver) 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ciCAST_ACCESSOR(JSIteratorResult) 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, elements, FixedArrayBase) { 531cb0ef41Sopenharmony_ci return TaggedField<FixedArrayBase, kElementsOffset>::load(cage_base, *this); 541cb0ef41Sopenharmony_ci} 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ciFixedArrayBase JSObject::elements(RelaxedLoadTag tag) const { 571cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 581cb0ef41Sopenharmony_ci return elements(cage_base, tag); 591cb0ef41Sopenharmony_ci} 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ciFixedArrayBase JSObject::elements(PtrComprCageBase cage_base, 621cb0ef41Sopenharmony_ci RelaxedLoadTag) const { 631cb0ef41Sopenharmony_ci return TaggedField<FixedArrayBase, kElementsOffset>::Relaxed_Load(cage_base, 641cb0ef41Sopenharmony_ci *this); 651cb0ef41Sopenharmony_ci} 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_civoid JSObject::set_elements(FixedArrayBase value, WriteBarrierMode mode) { 681cb0ef41Sopenharmony_ci // Note the relaxed atomic store. 691cb0ef41Sopenharmony_ci TaggedField<FixedArrayBase, kElementsOffset>::Relaxed_Store(*this, value); 701cb0ef41Sopenharmony_ci CONDITIONAL_WRITE_BARRIER(*this, kElementsOffset, value, mode); 711cb0ef41Sopenharmony_ci} 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ciMaybeHandle<Object> JSReceiver::GetProperty(Isolate* isolate, 741cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver, 751cb0ef41Sopenharmony_ci Handle<Name> name) { 761cb0ef41Sopenharmony_ci LookupIterator it(isolate, receiver, name, receiver); 771cb0ef41Sopenharmony_ci if (!it.IsFound()) return it.factory()->undefined_value(); 781cb0ef41Sopenharmony_ci return Object::GetProperty(&it); 791cb0ef41Sopenharmony_ci} 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ciMaybeHandle<Object> JSReceiver::GetElement(Isolate* isolate, 821cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver, 831cb0ef41Sopenharmony_ci uint32_t index) { 841cb0ef41Sopenharmony_ci LookupIterator it(isolate, receiver, index, receiver); 851cb0ef41Sopenharmony_ci if (!it.IsFound()) return it.factory()->undefined_value(); 861cb0ef41Sopenharmony_ci return Object::GetProperty(&it); 871cb0ef41Sopenharmony_ci} 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ciHandle<Object> JSReceiver::GetDataProperty(Isolate* isolate, 901cb0ef41Sopenharmony_ci Handle<JSReceiver> object, 911cb0ef41Sopenharmony_ci Handle<Name> name) { 921cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, name, object, 931cb0ef41Sopenharmony_ci LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); 941cb0ef41Sopenharmony_ci if (!it.IsFound()) return it.factory()->undefined_value(); 951cb0ef41Sopenharmony_ci return GetDataProperty(&it); 961cb0ef41Sopenharmony_ci} 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_ciMaybeHandle<HeapObject> JSReceiver::GetPrototype(Isolate* isolate, 991cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver) { 1001cb0ef41Sopenharmony_ci // We don't expect access checks to be needed on JSProxy objects. 1011cb0ef41Sopenharmony_ci DCHECK(!receiver->IsAccessCheckNeeded() || receiver->IsJSObject()); 1021cb0ef41Sopenharmony_ci PrototypeIterator iter(isolate, receiver, kStartAtReceiver, 1031cb0ef41Sopenharmony_ci PrototypeIterator::END_AT_NON_HIDDEN); 1041cb0ef41Sopenharmony_ci do { 1051cb0ef41Sopenharmony_ci if (!iter.AdvanceFollowingProxies()) return MaybeHandle<HeapObject>(); 1061cb0ef41Sopenharmony_ci } while (!iter.IsAtEnd()); 1071cb0ef41Sopenharmony_ci return PrototypeIterator::GetCurrent(iter); 1081cb0ef41Sopenharmony_ci} 1091cb0ef41Sopenharmony_ci 1101cb0ef41Sopenharmony_ciMaybeHandle<Object> JSReceiver::GetProperty(Isolate* isolate, 1111cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver, 1121cb0ef41Sopenharmony_ci const char* name) { 1131cb0ef41Sopenharmony_ci Handle<String> str = isolate->factory()->InternalizeUtf8String(name); 1141cb0ef41Sopenharmony_ci return GetProperty(isolate, receiver, str); 1151cb0ef41Sopenharmony_ci} 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_ci// static 1181cb0ef41Sopenharmony_ciV8_WARN_UNUSED_RESULT MaybeHandle<FixedArray> JSReceiver::OwnPropertyKeys( 1191cb0ef41Sopenharmony_ci Handle<JSReceiver> object) { 1201cb0ef41Sopenharmony_ci return KeyAccumulator::GetKeys(object, KeyCollectionMode::kOwnOnly, 1211cb0ef41Sopenharmony_ci ALL_PROPERTIES, 1221cb0ef41Sopenharmony_ci GetKeysConversion::kConvertToString); 1231cb0ef41Sopenharmony_ci} 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_cibool JSObject::PrototypeHasNoElements(Isolate* isolate, JSObject object) { 1261cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 1271cb0ef41Sopenharmony_ci HeapObject prototype = HeapObject::cast(object.map().prototype()); 1281cb0ef41Sopenharmony_ci ReadOnlyRoots roots(isolate); 1291cb0ef41Sopenharmony_ci HeapObject null = roots.null_value(); 1301cb0ef41Sopenharmony_ci FixedArrayBase empty_fixed_array = roots.empty_fixed_array(); 1311cb0ef41Sopenharmony_ci FixedArrayBase empty_slow_element_dictionary = 1321cb0ef41Sopenharmony_ci roots.empty_slow_element_dictionary(); 1331cb0ef41Sopenharmony_ci while (prototype != null) { 1341cb0ef41Sopenharmony_ci Map map = prototype.map(); 1351cb0ef41Sopenharmony_ci if (map.IsCustomElementsReceiverMap()) return false; 1361cb0ef41Sopenharmony_ci FixedArrayBase elements = JSObject::cast(prototype).elements(); 1371cb0ef41Sopenharmony_ci if (elements != empty_fixed_array && 1381cb0ef41Sopenharmony_ci elements != empty_slow_element_dictionary) { 1391cb0ef41Sopenharmony_ci return false; 1401cb0ef41Sopenharmony_ci } 1411cb0ef41Sopenharmony_ci prototype = HeapObject::cast(map.prototype()); 1421cb0ef41Sopenharmony_ci } 1431cb0ef41Sopenharmony_ci return true; 1441cb0ef41Sopenharmony_ci} 1451cb0ef41Sopenharmony_ci 1461cb0ef41Sopenharmony_ciACCESSORS(JSReceiver, raw_properties_or_hash, Object, kPropertiesOrHashOffset) 1471cb0ef41Sopenharmony_ciRELAXED_ACCESSORS(JSReceiver, raw_properties_or_hash, Object, 1481cb0ef41Sopenharmony_ci kPropertiesOrHashOffset) 1491cb0ef41Sopenharmony_ci 1501cb0ef41Sopenharmony_civoid JSObject::EnsureCanContainHeapObjectElements(Handle<JSObject> object) { 1511cb0ef41Sopenharmony_ci JSObject::ValidateElements(*object); 1521cb0ef41Sopenharmony_ci ElementsKind elements_kind = object->map().elements_kind(); 1531cb0ef41Sopenharmony_ci if (!IsObjectElementsKind(elements_kind)) { 1541cb0ef41Sopenharmony_ci if (IsHoleyElementsKind(elements_kind)) { 1551cb0ef41Sopenharmony_ci TransitionElementsKind(object, HOLEY_ELEMENTS); 1561cb0ef41Sopenharmony_ci } else { 1571cb0ef41Sopenharmony_ci TransitionElementsKind(object, PACKED_ELEMENTS); 1581cb0ef41Sopenharmony_ci } 1591cb0ef41Sopenharmony_ci } 1601cb0ef41Sopenharmony_ci} 1611cb0ef41Sopenharmony_ci 1621cb0ef41Sopenharmony_citemplate <typename TSlot> 1631cb0ef41Sopenharmony_civoid JSObject::EnsureCanContainElements(Handle<JSObject> object, TSlot objects, 1641cb0ef41Sopenharmony_ci uint32_t count, 1651cb0ef41Sopenharmony_ci EnsureElementsMode mode) { 1661cb0ef41Sopenharmony_ci static_assert(std::is_same<TSlot, FullObjectSlot>::value || 1671cb0ef41Sopenharmony_ci std::is_same<TSlot, ObjectSlot>::value, 1681cb0ef41Sopenharmony_ci "Only ObjectSlot and FullObjectSlot are expected here"); 1691cb0ef41Sopenharmony_ci ElementsKind current_kind = object->GetElementsKind(); 1701cb0ef41Sopenharmony_ci ElementsKind target_kind = current_kind; 1711cb0ef41Sopenharmony_ci { 1721cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 1731cb0ef41Sopenharmony_ci DCHECK(mode != ALLOW_COPIED_DOUBLE_ELEMENTS); 1741cb0ef41Sopenharmony_ci bool is_holey = IsHoleyElementsKind(current_kind); 1751cb0ef41Sopenharmony_ci if (current_kind == HOLEY_ELEMENTS) return; 1761cb0ef41Sopenharmony_ci Object the_hole = object->GetReadOnlyRoots().the_hole_value(); 1771cb0ef41Sopenharmony_ci for (uint32_t i = 0; i < count; ++i, ++objects) { 1781cb0ef41Sopenharmony_ci Object current = *objects; 1791cb0ef41Sopenharmony_ci if (current == the_hole) { 1801cb0ef41Sopenharmony_ci is_holey = true; 1811cb0ef41Sopenharmony_ci target_kind = GetHoleyElementsKind(target_kind); 1821cb0ef41Sopenharmony_ci } else if (!current.IsSmi()) { 1831cb0ef41Sopenharmony_ci if (mode == ALLOW_CONVERTED_DOUBLE_ELEMENTS && current.IsNumber()) { 1841cb0ef41Sopenharmony_ci if (IsSmiElementsKind(target_kind)) { 1851cb0ef41Sopenharmony_ci if (is_holey) { 1861cb0ef41Sopenharmony_ci target_kind = HOLEY_DOUBLE_ELEMENTS; 1871cb0ef41Sopenharmony_ci } else { 1881cb0ef41Sopenharmony_ci target_kind = PACKED_DOUBLE_ELEMENTS; 1891cb0ef41Sopenharmony_ci } 1901cb0ef41Sopenharmony_ci } 1911cb0ef41Sopenharmony_ci } else if (is_holey) { 1921cb0ef41Sopenharmony_ci target_kind = HOLEY_ELEMENTS; 1931cb0ef41Sopenharmony_ci break; 1941cb0ef41Sopenharmony_ci } else { 1951cb0ef41Sopenharmony_ci target_kind = PACKED_ELEMENTS; 1961cb0ef41Sopenharmony_ci } 1971cb0ef41Sopenharmony_ci } 1981cb0ef41Sopenharmony_ci } 1991cb0ef41Sopenharmony_ci } 2001cb0ef41Sopenharmony_ci if (target_kind != current_kind) { 2011cb0ef41Sopenharmony_ci TransitionElementsKind(object, target_kind); 2021cb0ef41Sopenharmony_ci } 2031cb0ef41Sopenharmony_ci} 2041cb0ef41Sopenharmony_ci 2051cb0ef41Sopenharmony_civoid JSObject::EnsureCanContainElements(Handle<JSObject> object, 2061cb0ef41Sopenharmony_ci Handle<FixedArrayBase> elements, 2071cb0ef41Sopenharmony_ci uint32_t length, 2081cb0ef41Sopenharmony_ci EnsureElementsMode mode) { 2091cb0ef41Sopenharmony_ci ReadOnlyRoots roots = object->GetReadOnlyRoots(); 2101cb0ef41Sopenharmony_ci if (elements->map() != roots.fixed_double_array_map()) { 2111cb0ef41Sopenharmony_ci DCHECK(elements->map() == roots.fixed_array_map() || 2121cb0ef41Sopenharmony_ci elements->map() == roots.fixed_cow_array_map()); 2131cb0ef41Sopenharmony_ci if (mode == ALLOW_COPIED_DOUBLE_ELEMENTS) { 2141cb0ef41Sopenharmony_ci mode = DONT_ALLOW_DOUBLE_ELEMENTS; 2151cb0ef41Sopenharmony_ci } 2161cb0ef41Sopenharmony_ci ObjectSlot objects = 2171cb0ef41Sopenharmony_ci Handle<FixedArray>::cast(elements)->GetFirstElementAddress(); 2181cb0ef41Sopenharmony_ci EnsureCanContainElements(object, objects, length, mode); 2191cb0ef41Sopenharmony_ci return; 2201cb0ef41Sopenharmony_ci } 2211cb0ef41Sopenharmony_ci 2221cb0ef41Sopenharmony_ci DCHECK(mode == ALLOW_COPIED_DOUBLE_ELEMENTS); 2231cb0ef41Sopenharmony_ci if (object->GetElementsKind() == HOLEY_SMI_ELEMENTS) { 2241cb0ef41Sopenharmony_ci TransitionElementsKind(object, HOLEY_DOUBLE_ELEMENTS); 2251cb0ef41Sopenharmony_ci } else if (object->GetElementsKind() == PACKED_SMI_ELEMENTS) { 2261cb0ef41Sopenharmony_ci Handle<FixedDoubleArray> double_array = 2271cb0ef41Sopenharmony_ci Handle<FixedDoubleArray>::cast(elements); 2281cb0ef41Sopenharmony_ci for (uint32_t i = 0; i < length; ++i) { 2291cb0ef41Sopenharmony_ci if (double_array->is_the_hole(i)) { 2301cb0ef41Sopenharmony_ci TransitionElementsKind(object, HOLEY_DOUBLE_ELEMENTS); 2311cb0ef41Sopenharmony_ci return; 2321cb0ef41Sopenharmony_ci } 2331cb0ef41Sopenharmony_ci } 2341cb0ef41Sopenharmony_ci TransitionElementsKind(object, PACKED_DOUBLE_ELEMENTS); 2351cb0ef41Sopenharmony_ci } 2361cb0ef41Sopenharmony_ci} 2371cb0ef41Sopenharmony_ci 2381cb0ef41Sopenharmony_civoid JSObject::SetMapAndElements(Handle<JSObject> object, Handle<Map> new_map, 2391cb0ef41Sopenharmony_ci Handle<FixedArrayBase> value) { 2401cb0ef41Sopenharmony_ci Isolate* isolate = object->GetIsolate(); 2411cb0ef41Sopenharmony_ci JSObject::MigrateToMap(isolate, object, new_map); 2421cb0ef41Sopenharmony_ci DCHECK((object->map().has_fast_smi_or_object_elements() || 2431cb0ef41Sopenharmony_ci (*value == ReadOnlyRoots(isolate).empty_fixed_array()) || 2441cb0ef41Sopenharmony_ci object->map().has_fast_string_wrapper_elements()) == 2451cb0ef41Sopenharmony_ci (value->map() == ReadOnlyRoots(isolate).fixed_array_map() || 2461cb0ef41Sopenharmony_ci value->map() == ReadOnlyRoots(isolate).fixed_cow_array_map())); 2471cb0ef41Sopenharmony_ci DCHECK((*value == ReadOnlyRoots(isolate).empty_fixed_array()) || 2481cb0ef41Sopenharmony_ci (object->map().has_fast_double_elements() == 2491cb0ef41Sopenharmony_ci value->IsFixedDoubleArray())); 2501cb0ef41Sopenharmony_ci object->set_elements(*value); 2511cb0ef41Sopenharmony_ci} 2521cb0ef41Sopenharmony_ci 2531cb0ef41Sopenharmony_civoid JSObject::initialize_elements() { 2541cb0ef41Sopenharmony_ci FixedArrayBase elements = map().GetInitialElements(); 2551cb0ef41Sopenharmony_ci set_elements(elements, SKIP_WRITE_BARRIER); 2561cb0ef41Sopenharmony_ci} 2571cb0ef41Sopenharmony_ci 2581cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, GetIndexedInterceptor, InterceptorInfo) { 2591cb0ef41Sopenharmony_ci return map(cage_base).GetIndexedInterceptor(cage_base); 2601cb0ef41Sopenharmony_ci} 2611cb0ef41Sopenharmony_ci 2621cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, GetNamedInterceptor, InterceptorInfo) { 2631cb0ef41Sopenharmony_ci return map(cage_base).GetNamedInterceptor(cage_base); 2641cb0ef41Sopenharmony_ci} 2651cb0ef41Sopenharmony_ci 2661cb0ef41Sopenharmony_ci// static 2671cb0ef41Sopenharmony_ciint JSObject::GetHeaderSize(Map map) { 2681cb0ef41Sopenharmony_ci // Check for the most common kind of JavaScript object before 2691cb0ef41Sopenharmony_ci // falling into the generic switch. This speeds up the internal 2701cb0ef41Sopenharmony_ci // field operations considerably on average. 2711cb0ef41Sopenharmony_ci InstanceType instance_type = map.instance_type(); 2721cb0ef41Sopenharmony_ci return instance_type == JS_OBJECT_TYPE 2731cb0ef41Sopenharmony_ci ? JSObject::kHeaderSize 2741cb0ef41Sopenharmony_ci : GetHeaderSize(instance_type, map.has_prototype_slot()); 2751cb0ef41Sopenharmony_ci} 2761cb0ef41Sopenharmony_ci 2771cb0ef41Sopenharmony_ci// static 2781cb0ef41Sopenharmony_ciint JSObject::GetEmbedderFieldsStartOffset(Map map) { 2791cb0ef41Sopenharmony_ci // Embedder fields are located after the object header. 2801cb0ef41Sopenharmony_ci return GetHeaderSize(map); 2811cb0ef41Sopenharmony_ci} 2821cb0ef41Sopenharmony_ci 2831cb0ef41Sopenharmony_ciint JSObject::GetEmbedderFieldsStartOffset() { 2841cb0ef41Sopenharmony_ci return GetEmbedderFieldsStartOffset(map()); 2851cb0ef41Sopenharmony_ci} 2861cb0ef41Sopenharmony_ci 2871cb0ef41Sopenharmony_ci// static 2881cb0ef41Sopenharmony_cibool JSObject::MayHaveEmbedderFields(Map map) { 2891cb0ef41Sopenharmony_ci InstanceType instance_type = map.instance_type(); 2901cb0ef41Sopenharmony_ci // TODO(v8) It'd be nice if all objects with embedder data slots inherited 2911cb0ef41Sopenharmony_ci // from JSObjectWithEmbedderSlots, but this is currently not possible due to 2921cb0ef41Sopenharmony_ci // instance_type constraints. 2931cb0ef41Sopenharmony_ci return InstanceTypeChecker::IsJSObjectWithEmbedderSlots(instance_type) || 2941cb0ef41Sopenharmony_ci InstanceTypeChecker::IsJSSpecialObject(instance_type); 2951cb0ef41Sopenharmony_ci} 2961cb0ef41Sopenharmony_ci 2971cb0ef41Sopenharmony_cibool JSObject::MayHaveEmbedderFields() const { 2981cb0ef41Sopenharmony_ci return MayHaveEmbedderFields(map()); 2991cb0ef41Sopenharmony_ci} 3001cb0ef41Sopenharmony_ci 3011cb0ef41Sopenharmony_ci// static 3021cb0ef41Sopenharmony_ciint JSObject::GetEmbedderFieldCount(Map map) { 3031cb0ef41Sopenharmony_ci int instance_size = map.instance_size(); 3041cb0ef41Sopenharmony_ci if (instance_size == kVariableSizeSentinel) return 0; 3051cb0ef41Sopenharmony_ci // Embedder fields are located after the object header, whereas in-object 3061cb0ef41Sopenharmony_ci // properties are located at the end of the object. We don't have to round up 3071cb0ef41Sopenharmony_ci // the header size here because division by kEmbedderDataSlotSizeInTaggedSlots 3081cb0ef41Sopenharmony_ci // will swallow potential padding in case of (kTaggedSize != 3091cb0ef41Sopenharmony_ci // kSystemPointerSize) anyway. 3101cb0ef41Sopenharmony_ci return (((instance_size - GetEmbedderFieldsStartOffset(map)) >> 3111cb0ef41Sopenharmony_ci kTaggedSizeLog2) - 3121cb0ef41Sopenharmony_ci map.GetInObjectProperties()) / 3131cb0ef41Sopenharmony_ci kEmbedderDataSlotSizeInTaggedSlots; 3141cb0ef41Sopenharmony_ci} 3151cb0ef41Sopenharmony_ci 3161cb0ef41Sopenharmony_ciint JSObject::GetEmbedderFieldCount() const { 3171cb0ef41Sopenharmony_ci return GetEmbedderFieldCount(map()); 3181cb0ef41Sopenharmony_ci} 3191cb0ef41Sopenharmony_ci 3201cb0ef41Sopenharmony_ciint JSObject::GetEmbedderFieldOffset(int index) { 3211cb0ef41Sopenharmony_ci DCHECK_LT(static_cast<unsigned>(index), 3221cb0ef41Sopenharmony_ci static_cast<unsigned>(GetEmbedderFieldCount())); 3231cb0ef41Sopenharmony_ci return GetEmbedderFieldsStartOffset() + (kEmbedderDataSlotSize * index); 3241cb0ef41Sopenharmony_ci} 3251cb0ef41Sopenharmony_ci 3261cb0ef41Sopenharmony_ciObject JSObject::GetEmbedderField(int index) { 3271cb0ef41Sopenharmony_ci return EmbedderDataSlot(*this, index).load_tagged(); 3281cb0ef41Sopenharmony_ci} 3291cb0ef41Sopenharmony_ci 3301cb0ef41Sopenharmony_civoid JSObject::SetEmbedderField(int index, Object value) { 3311cb0ef41Sopenharmony_ci EmbedderDataSlot::store_tagged(*this, index, value); 3321cb0ef41Sopenharmony_ci} 3331cb0ef41Sopenharmony_ci 3341cb0ef41Sopenharmony_civoid JSObject::SetEmbedderField(int index, Smi value) { 3351cb0ef41Sopenharmony_ci EmbedderDataSlot(*this, index).store_smi(value); 3361cb0ef41Sopenharmony_ci} 3371cb0ef41Sopenharmony_ci 3381cb0ef41Sopenharmony_cibool JSObject::IsDroppableApiObject() const { 3391cb0ef41Sopenharmony_ci auto instance_type = map().instance_type(); 3401cb0ef41Sopenharmony_ci return InstanceTypeChecker::IsJSApiObject(instance_type) || 3411cb0ef41Sopenharmony_ci instance_type == JS_SPECIAL_API_OBJECT_TYPE; 3421cb0ef41Sopenharmony_ci} 3431cb0ef41Sopenharmony_ci 3441cb0ef41Sopenharmony_ci// Access fast-case object properties at index. The use of these routines 3451cb0ef41Sopenharmony_ci// is needed to correctly distinguish between properties stored in-object and 3461cb0ef41Sopenharmony_ci// properties stored in the properties array. 3471cb0ef41Sopenharmony_ciObject JSObject::RawFastPropertyAt(FieldIndex index) const { 3481cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 3491cb0ef41Sopenharmony_ci return RawFastPropertyAt(cage_base, index); 3501cb0ef41Sopenharmony_ci} 3511cb0ef41Sopenharmony_ci 3521cb0ef41Sopenharmony_ciObject JSObject::RawFastPropertyAt(PtrComprCageBase cage_base, 3531cb0ef41Sopenharmony_ci FieldIndex index) const { 3541cb0ef41Sopenharmony_ci if (index.is_inobject()) { 3551cb0ef41Sopenharmony_ci return TaggedField<Object>::Relaxed_Load(cage_base, *this, index.offset()); 3561cb0ef41Sopenharmony_ci } else { 3571cb0ef41Sopenharmony_ci return property_array(cage_base).get(cage_base, 3581cb0ef41Sopenharmony_ci index.outobject_array_index()); 3591cb0ef41Sopenharmony_ci } 3601cb0ef41Sopenharmony_ci} 3611cb0ef41Sopenharmony_ci 3621cb0ef41Sopenharmony_ci// The SeqCst versions of RawFastPropertyAt are used for atomically accessing 3631cb0ef41Sopenharmony_ci// shared struct fields. 3641cb0ef41Sopenharmony_ciObject JSObject::RawFastPropertyAt(FieldIndex index, 3651cb0ef41Sopenharmony_ci SeqCstAccessTag tag) const { 3661cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 3671cb0ef41Sopenharmony_ci return RawFastPropertyAt(cage_base, index, tag); 3681cb0ef41Sopenharmony_ci} 3691cb0ef41Sopenharmony_ci 3701cb0ef41Sopenharmony_ciObject JSObject::RawFastPropertyAt(PtrComprCageBase cage_base, FieldIndex index, 3711cb0ef41Sopenharmony_ci SeqCstAccessTag tag) const { 3721cb0ef41Sopenharmony_ci if (index.is_inobject()) { 3731cb0ef41Sopenharmony_ci return TaggedField<Object>::SeqCst_Load(cage_base, *this, index.offset()); 3741cb0ef41Sopenharmony_ci } else { 3751cb0ef41Sopenharmony_ci return property_array(cage_base).get(cage_base, 3761cb0ef41Sopenharmony_ci index.outobject_array_index(), tag); 3771cb0ef41Sopenharmony_ci } 3781cb0ef41Sopenharmony_ci} 3791cb0ef41Sopenharmony_ci 3801cb0ef41Sopenharmony_cibase::Optional<Object> JSObject::RawInobjectPropertyAt( 3811cb0ef41Sopenharmony_ci PtrComprCageBase cage_base, Map original_map, FieldIndex index) const { 3821cb0ef41Sopenharmony_ci CHECK(index.is_inobject()); 3831cb0ef41Sopenharmony_ci 3841cb0ef41Sopenharmony_ci // This method implements a "snapshot" protocol to protect against reading out 3851cb0ef41Sopenharmony_ci // of bounds of an object. It's used to access a fast in-object property from 3861cb0ef41Sopenharmony_ci // a background thread with no locking. That caller does have the guarantee 3871cb0ef41Sopenharmony_ci // that a garbage collection cannot happen during its query. However, it must 3881cb0ef41Sopenharmony_ci // contend with the main thread altering the object in heavy ways through 3891cb0ef41Sopenharmony_ci // object migration. Specifically, the object can get smaller. Initially, this 3901cb0ef41Sopenharmony_ci // may seem benign, because object migration fills the freed-up space with 3911cb0ef41Sopenharmony_ci // FillerMap words which, even though they offer wrong values, are at 3921cb0ef41Sopenharmony_ci // least tagged values. 3931cb0ef41Sopenharmony_ci 3941cb0ef41Sopenharmony_ci // However, there is an additional danger. Sweeper threads may discover the 3951cb0ef41Sopenharmony_ci // filler words and offer that space to the main thread for allocation. Should 3961cb0ef41Sopenharmony_ci // a HeapNumber be allocated into that space while we're reading a property at 3971cb0ef41Sopenharmony_ci // that location (from our out-of-date information), we risk interpreting a 3981cb0ef41Sopenharmony_ci // double value as a pointer. This must be prevented. 3991cb0ef41Sopenharmony_ci // 4001cb0ef41Sopenharmony_ci // We do this by: 4011cb0ef41Sopenharmony_ci // 4021cb0ef41Sopenharmony_ci // a) Reading the map first 4031cb0ef41Sopenharmony_ci // b) Reading the property with acquire semantics (but do not inspect it!) 4041cb0ef41Sopenharmony_ci // c) Re-read the map with acquire semantics. 4051cb0ef41Sopenharmony_ci // 4061cb0ef41Sopenharmony_ci // Only if the maps match can the property be inspected. It may have a "wrong" 4071cb0ef41Sopenharmony_ci // value, but it will be within the bounds of the objects instance size as 4081cb0ef41Sopenharmony_ci // given by the map and it will be a valid Smi or object pointer. 4091cb0ef41Sopenharmony_ci Object maybe_tagged_object = 4101cb0ef41Sopenharmony_ci TaggedField<Object>::Acquire_Load(cage_base, *this, index.offset()); 4111cb0ef41Sopenharmony_ci if (original_map != map(cage_base, kAcquireLoad)) return {}; 4121cb0ef41Sopenharmony_ci return maybe_tagged_object; 4131cb0ef41Sopenharmony_ci} 4141cb0ef41Sopenharmony_ci 4151cb0ef41Sopenharmony_civoid JSObject::RawFastInobjectPropertyAtPut(FieldIndex index, Object value, 4161cb0ef41Sopenharmony_ci WriteBarrierMode mode) { 4171cb0ef41Sopenharmony_ci DCHECK(index.is_inobject()); 4181cb0ef41Sopenharmony_ci int offset = index.offset(); 4191cb0ef41Sopenharmony_ci RELAXED_WRITE_FIELD(*this, offset, value); 4201cb0ef41Sopenharmony_ci CONDITIONAL_WRITE_BARRIER(*this, offset, value, mode); 4211cb0ef41Sopenharmony_ci} 4221cb0ef41Sopenharmony_ci 4231cb0ef41Sopenharmony_civoid JSObject::RawFastInobjectPropertyAtPut(FieldIndex index, Object value, 4241cb0ef41Sopenharmony_ci SeqCstAccessTag tag) { 4251cb0ef41Sopenharmony_ci DCHECK(index.is_inobject()); 4261cb0ef41Sopenharmony_ci DCHECK(value.IsShared()); 4271cb0ef41Sopenharmony_ci SEQ_CST_WRITE_FIELD(*this, index.offset(), value); 4281cb0ef41Sopenharmony_ci // JSSharedStructs are allocated in the shared old space, which is currently 4291cb0ef41Sopenharmony_ci // collected by stopping the world, so the incremental write barrier is not 4301cb0ef41Sopenharmony_ci // needed. They can only store Smis and other HeapObjects in the shared old 4311cb0ef41Sopenharmony_ci // space, so the generational write barrier is also not needed. 4321cb0ef41Sopenharmony_ci} 4331cb0ef41Sopenharmony_ci 4341cb0ef41Sopenharmony_civoid JSObject::FastPropertyAtPut(FieldIndex index, Object value, 4351cb0ef41Sopenharmony_ci WriteBarrierMode mode) { 4361cb0ef41Sopenharmony_ci if (index.is_inobject()) { 4371cb0ef41Sopenharmony_ci RawFastInobjectPropertyAtPut(index, value, mode); 4381cb0ef41Sopenharmony_ci } else { 4391cb0ef41Sopenharmony_ci DCHECK_EQ(UPDATE_WRITE_BARRIER, mode); 4401cb0ef41Sopenharmony_ci property_array().set(index.outobject_array_index(), value); 4411cb0ef41Sopenharmony_ci } 4421cb0ef41Sopenharmony_ci} 4431cb0ef41Sopenharmony_ci 4441cb0ef41Sopenharmony_civoid JSObject::FastPropertyAtPut(FieldIndex index, Object value, 4451cb0ef41Sopenharmony_ci SeqCstAccessTag tag) { 4461cb0ef41Sopenharmony_ci if (index.is_inobject()) { 4471cb0ef41Sopenharmony_ci RawFastInobjectPropertyAtPut(index, value, tag); 4481cb0ef41Sopenharmony_ci } else { 4491cb0ef41Sopenharmony_ci property_array().set(index.outobject_array_index(), value, tag); 4501cb0ef41Sopenharmony_ci } 4511cb0ef41Sopenharmony_ci} 4521cb0ef41Sopenharmony_ci 4531cb0ef41Sopenharmony_civoid JSObject::WriteToField(InternalIndex descriptor, PropertyDetails details, 4541cb0ef41Sopenharmony_ci Object value) { 4551cb0ef41Sopenharmony_ci DCHECK_EQ(PropertyLocation::kField, details.location()); 4561cb0ef41Sopenharmony_ci DCHECK_EQ(PropertyKind::kData, details.kind()); 4571cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 4581cb0ef41Sopenharmony_ci FieldIndex index = FieldIndex::ForDescriptor(map(), descriptor); 4591cb0ef41Sopenharmony_ci if (details.representation().IsDouble()) { 4601cb0ef41Sopenharmony_ci // Manipulating the signaling NaN used for the hole and uninitialized 4611cb0ef41Sopenharmony_ci // double field sentinel in C++, e.g. with bit_cast or value()/set_value(), 4621cb0ef41Sopenharmony_ci // will change its value on ia32 (the x87 stack is used to return values 4631cb0ef41Sopenharmony_ci // and stores to the stack silently clear the signalling bit). 4641cb0ef41Sopenharmony_ci uint64_t bits; 4651cb0ef41Sopenharmony_ci if (value.IsSmi()) { 4661cb0ef41Sopenharmony_ci bits = bit_cast<uint64_t>(static_cast<double>(Smi::ToInt(value))); 4671cb0ef41Sopenharmony_ci } else if (value.IsUninitialized()) { 4681cb0ef41Sopenharmony_ci bits = kHoleNanInt64; 4691cb0ef41Sopenharmony_ci } else { 4701cb0ef41Sopenharmony_ci DCHECK(value.IsHeapNumber()); 4711cb0ef41Sopenharmony_ci bits = HeapNumber::cast(value).value_as_bits(kRelaxedLoad); 4721cb0ef41Sopenharmony_ci } 4731cb0ef41Sopenharmony_ci auto box = HeapNumber::cast(RawFastPropertyAt(index)); 4741cb0ef41Sopenharmony_ci box.set_value_as_bits(bits, kRelaxedStore); 4751cb0ef41Sopenharmony_ci } else { 4761cb0ef41Sopenharmony_ci FastPropertyAtPut(index, value); 4771cb0ef41Sopenharmony_ci } 4781cb0ef41Sopenharmony_ci} 4791cb0ef41Sopenharmony_ci 4801cb0ef41Sopenharmony_ciObject JSObject::RawFastPropertyAtSwap(FieldIndex index, Object value, 4811cb0ef41Sopenharmony_ci SeqCstAccessTag tag) { 4821cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 4831cb0ef41Sopenharmony_ci return RawFastPropertyAtSwap(cage_base, index, value, tag); 4841cb0ef41Sopenharmony_ci} 4851cb0ef41Sopenharmony_ci 4861cb0ef41Sopenharmony_ciObject JSObject::RawFastPropertyAtSwap(PtrComprCageBase cage_base, 4871cb0ef41Sopenharmony_ci FieldIndex index, Object value, 4881cb0ef41Sopenharmony_ci SeqCstAccessTag tag) { 4891cb0ef41Sopenharmony_ci if (index.is_inobject()) { 4901cb0ef41Sopenharmony_ci return TaggedField<Object>::SeqCst_Swap(cage_base, *this, index.offset(), 4911cb0ef41Sopenharmony_ci value); 4921cb0ef41Sopenharmony_ci } 4931cb0ef41Sopenharmony_ci return property_array().Swap(cage_base, index.outobject_array_index(), value, 4941cb0ef41Sopenharmony_ci tag); 4951cb0ef41Sopenharmony_ci} 4961cb0ef41Sopenharmony_ci 4971cb0ef41Sopenharmony_ciint JSObject::GetInObjectPropertyOffset(int index) { 4981cb0ef41Sopenharmony_ci return map().GetInObjectPropertyOffset(index); 4991cb0ef41Sopenharmony_ci} 5001cb0ef41Sopenharmony_ci 5011cb0ef41Sopenharmony_ciObject JSObject::InObjectPropertyAt(int index) { 5021cb0ef41Sopenharmony_ci int offset = GetInObjectPropertyOffset(index); 5031cb0ef41Sopenharmony_ci return TaggedField<Object>::load(*this, offset); 5041cb0ef41Sopenharmony_ci} 5051cb0ef41Sopenharmony_ci 5061cb0ef41Sopenharmony_ciObject JSObject::InObjectPropertyAtPut(int index, Object value, 5071cb0ef41Sopenharmony_ci WriteBarrierMode mode) { 5081cb0ef41Sopenharmony_ci // Adjust for the number of properties stored in the object. 5091cb0ef41Sopenharmony_ci int offset = GetInObjectPropertyOffset(index); 5101cb0ef41Sopenharmony_ci WRITE_FIELD(*this, offset, value); 5111cb0ef41Sopenharmony_ci CONDITIONAL_WRITE_BARRIER(*this, offset, value, mode); 5121cb0ef41Sopenharmony_ci return value; 5131cb0ef41Sopenharmony_ci} 5141cb0ef41Sopenharmony_ci 5151cb0ef41Sopenharmony_civoid JSObject::InitializeBody(Map map, int start_offset, 5161cb0ef41Sopenharmony_ci bool is_slack_tracking_in_progress, 5171cb0ef41Sopenharmony_ci MapWord filler_map, Object undefined_filler) { 5181cb0ef41Sopenharmony_ci int size = map.instance_size(); 5191cb0ef41Sopenharmony_ci int offset = start_offset; 5201cb0ef41Sopenharmony_ci 5211cb0ef41Sopenharmony_ci // embedder data slots need to be initialized separately 5221cb0ef41Sopenharmony_ci if (MayHaveEmbedderFields(map)) { 5231cb0ef41Sopenharmony_ci int embedder_field_start = GetEmbedderFieldsStartOffset(map); 5241cb0ef41Sopenharmony_ci int embedder_field_count = GetEmbedderFieldCount(map); 5251cb0ef41Sopenharmony_ci 5261cb0ef41Sopenharmony_ci // fill start with references to the undefined value object 5271cb0ef41Sopenharmony_ci DCHECK_LE(offset, embedder_field_start); 5281cb0ef41Sopenharmony_ci while (offset < embedder_field_start) { 5291cb0ef41Sopenharmony_ci WRITE_FIELD(*this, offset, undefined_filler); 5301cb0ef41Sopenharmony_ci offset += kTaggedSize; 5311cb0ef41Sopenharmony_ci } 5321cb0ef41Sopenharmony_ci 5331cb0ef41Sopenharmony_ci // initialize embedder data slots 5341cb0ef41Sopenharmony_ci DCHECK_EQ(offset, embedder_field_start); 5351cb0ef41Sopenharmony_ci for (int i = 0; i < embedder_field_count; i++) { 5361cb0ef41Sopenharmony_ci // TODO(v8): consider initializing embedded data slots with Smi::zero(). 5371cb0ef41Sopenharmony_ci EmbedderDataSlot(*this, i).Initialize(undefined_filler); 5381cb0ef41Sopenharmony_ci offset += kEmbedderDataSlotSize; 5391cb0ef41Sopenharmony_ci } 5401cb0ef41Sopenharmony_ci } else { 5411cb0ef41Sopenharmony_ci DCHECK_EQ(0, GetEmbedderFieldCount(map)); 5421cb0ef41Sopenharmony_ci } 5431cb0ef41Sopenharmony_ci 5441cb0ef41Sopenharmony_ci DCHECK_LE(offset, size); 5451cb0ef41Sopenharmony_ci if (is_slack_tracking_in_progress) { 5461cb0ef41Sopenharmony_ci int end_of_pre_allocated_offset = 5471cb0ef41Sopenharmony_ci size - (map.UnusedPropertyFields() * kTaggedSize); 5481cb0ef41Sopenharmony_ci DCHECK_LE(kHeaderSize, end_of_pre_allocated_offset); 5491cb0ef41Sopenharmony_ci DCHECK_LE(offset, end_of_pre_allocated_offset); 5501cb0ef41Sopenharmony_ci // fill pre allocated slots with references to the undefined value object 5511cb0ef41Sopenharmony_ci while (offset < end_of_pre_allocated_offset) { 5521cb0ef41Sopenharmony_ci WRITE_FIELD(*this, offset, undefined_filler); 5531cb0ef41Sopenharmony_ci offset += kTaggedSize; 5541cb0ef41Sopenharmony_ci } 5551cb0ef41Sopenharmony_ci // fill the remainder with one word filler objects (ie just a map word) 5561cb0ef41Sopenharmony_ci while (offset < size) { 5571cb0ef41Sopenharmony_ci Object fm = Object(filler_map.ptr()); 5581cb0ef41Sopenharmony_ci WRITE_FIELD(*this, offset, fm); 5591cb0ef41Sopenharmony_ci offset += kTaggedSize; 5601cb0ef41Sopenharmony_ci } 5611cb0ef41Sopenharmony_ci } else { 5621cb0ef41Sopenharmony_ci while (offset < size) { 5631cb0ef41Sopenharmony_ci // fill everything with references to the undefined value object 5641cb0ef41Sopenharmony_ci WRITE_FIELD(*this, offset, undefined_filler); 5651cb0ef41Sopenharmony_ci offset += kTaggedSize; 5661cb0ef41Sopenharmony_ci } 5671cb0ef41Sopenharmony_ci } 5681cb0ef41Sopenharmony_ci} 5691cb0ef41Sopenharmony_ci 5701cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSExternalObject) 5711cb0ef41Sopenharmony_ci 5721cb0ef41Sopenharmony_ciDEF_GETTER(JSExternalObject, value, void*) { 5731cb0ef41Sopenharmony_ci Isolate* isolate = GetIsolateForSandbox(*this); 5741cb0ef41Sopenharmony_ci return reinterpret_cast<void*>( 5751cb0ef41Sopenharmony_ci ReadExternalPointerField(kValueOffset, isolate, kExternalObjectValueTag)); 5761cb0ef41Sopenharmony_ci} 5771cb0ef41Sopenharmony_ci 5781cb0ef41Sopenharmony_civoid JSExternalObject::AllocateExternalPointerEntries(Isolate* isolate) { 5791cb0ef41Sopenharmony_ci InitExternalPointerField(kValueOffset, isolate, kExternalObjectValueTag); 5801cb0ef41Sopenharmony_ci} 5811cb0ef41Sopenharmony_ci 5821cb0ef41Sopenharmony_civoid JSExternalObject::set_value(Isolate* isolate, void* value) { 5831cb0ef41Sopenharmony_ci WriteExternalPointerField(kValueOffset, isolate, 5841cb0ef41Sopenharmony_ci reinterpret_cast<Address>(value), 5851cb0ef41Sopenharmony_ci kExternalObjectValueTag); 5861cb0ef41Sopenharmony_ci} 5871cb0ef41Sopenharmony_ci 5881cb0ef41Sopenharmony_ciDEF_GETTER(JSGlobalObject, native_context_unchecked, Object) { 5891cb0ef41Sopenharmony_ci return TaggedField<Object, kNativeContextOffset>::Relaxed_Load(cage_base, 5901cb0ef41Sopenharmony_ci *this); 5911cb0ef41Sopenharmony_ci} 5921cb0ef41Sopenharmony_ci 5931cb0ef41Sopenharmony_cibool JSMessageObject::DidEnsureSourcePositionsAvailable() const { 5941cb0ef41Sopenharmony_ci return shared_info().IsUndefined(); 5951cb0ef41Sopenharmony_ci} 5961cb0ef41Sopenharmony_ci 5971cb0ef41Sopenharmony_ciint JSMessageObject::GetStartPosition() const { 5981cb0ef41Sopenharmony_ci DCHECK(DidEnsureSourcePositionsAvailable()); 5991cb0ef41Sopenharmony_ci return start_position(); 6001cb0ef41Sopenharmony_ci} 6011cb0ef41Sopenharmony_ci 6021cb0ef41Sopenharmony_ciint JSMessageObject::GetEndPosition() const { 6031cb0ef41Sopenharmony_ci DCHECK(DidEnsureSourcePositionsAvailable()); 6041cb0ef41Sopenharmony_ci return end_position(); 6051cb0ef41Sopenharmony_ci} 6061cb0ef41Sopenharmony_ci 6071cb0ef41Sopenharmony_ciMessageTemplate JSMessageObject::type() const { 6081cb0ef41Sopenharmony_ci return MessageTemplateFromInt(raw_type()); 6091cb0ef41Sopenharmony_ci} 6101cb0ef41Sopenharmony_ci 6111cb0ef41Sopenharmony_civoid JSMessageObject::set_type(MessageTemplate value) { 6121cb0ef41Sopenharmony_ci set_raw_type(static_cast<int>(value)); 6131cb0ef41Sopenharmony_ci} 6141cb0ef41Sopenharmony_ci 6151cb0ef41Sopenharmony_ciACCESSORS(JSMessageObject, shared_info, HeapObject, kSharedInfoOffset) 6161cb0ef41Sopenharmony_ciACCESSORS(JSMessageObject, bytecode_offset, Smi, kBytecodeOffsetOffset) 6171cb0ef41Sopenharmony_ciSMI_ACCESSORS(JSMessageObject, start_position, kStartPositionOffset) 6181cb0ef41Sopenharmony_ciSMI_ACCESSORS(JSMessageObject, end_position, kEndPositionOffset) 6191cb0ef41Sopenharmony_ciSMI_ACCESSORS(JSMessageObject, error_level, kErrorLevelOffset) 6201cb0ef41Sopenharmony_ciSMI_ACCESSORS(JSMessageObject, raw_type, kMessageTypeOffset) 6211cb0ef41Sopenharmony_ci 6221cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, GetElementsKind, ElementsKind) { 6231cb0ef41Sopenharmony_ci ElementsKind kind = map(cage_base).elements_kind(); 6241cb0ef41Sopenharmony_ci#if VERIFY_HEAP && DEBUG 6251cb0ef41Sopenharmony_ci FixedArrayBase fixed_array = FixedArrayBase::unchecked_cast( 6261cb0ef41Sopenharmony_ci TaggedField<HeapObject, kElementsOffset>::load(cage_base, *this)); 6271cb0ef41Sopenharmony_ci 6281cb0ef41Sopenharmony_ci // If a GC was caused while constructing this object, the elements 6291cb0ef41Sopenharmony_ci // pointer may point to a one pointer filler map. 6301cb0ef41Sopenharmony_ci if (ElementsAreSafeToExamine(cage_base)) { 6311cb0ef41Sopenharmony_ci Map map = fixed_array.map(cage_base); 6321cb0ef41Sopenharmony_ci if (IsSmiOrObjectElementsKind(kind)) { 6331cb0ef41Sopenharmony_ci DCHECK(map == GetReadOnlyRoots(cage_base).fixed_array_map() || 6341cb0ef41Sopenharmony_ci map == GetReadOnlyRoots(cage_base).fixed_cow_array_map()); 6351cb0ef41Sopenharmony_ci } else if (IsDoubleElementsKind(kind)) { 6361cb0ef41Sopenharmony_ci DCHECK(fixed_array.IsFixedDoubleArray(cage_base) || 6371cb0ef41Sopenharmony_ci fixed_array == GetReadOnlyRoots(cage_base).empty_fixed_array()); 6381cb0ef41Sopenharmony_ci } else if (kind == DICTIONARY_ELEMENTS) { 6391cb0ef41Sopenharmony_ci DCHECK(fixed_array.IsFixedArray(cage_base)); 6401cb0ef41Sopenharmony_ci DCHECK(fixed_array.IsNumberDictionary(cage_base)); 6411cb0ef41Sopenharmony_ci } else { 6421cb0ef41Sopenharmony_ci DCHECK(kind > DICTIONARY_ELEMENTS || 6431cb0ef41Sopenharmony_ci IsAnyNonextensibleElementsKind(kind)); 6441cb0ef41Sopenharmony_ci } 6451cb0ef41Sopenharmony_ci DCHECK(!IsSloppyArgumentsElementsKind(kind) || 6461cb0ef41Sopenharmony_ci elements(cage_base).IsSloppyArgumentsElements()); 6471cb0ef41Sopenharmony_ci } 6481cb0ef41Sopenharmony_ci#endif 6491cb0ef41Sopenharmony_ci return kind; 6501cb0ef41Sopenharmony_ci} 6511cb0ef41Sopenharmony_ci 6521cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, GetElementsAccessor, ElementsAccessor*) { 6531cb0ef41Sopenharmony_ci return ElementsAccessor::ForKind(GetElementsKind(cage_base)); 6541cb0ef41Sopenharmony_ci} 6551cb0ef41Sopenharmony_ci 6561cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasObjectElements, bool) { 6571cb0ef41Sopenharmony_ci return IsObjectElementsKind(GetElementsKind(cage_base)); 6581cb0ef41Sopenharmony_ci} 6591cb0ef41Sopenharmony_ci 6601cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasSmiElements, bool) { 6611cb0ef41Sopenharmony_ci return IsSmiElementsKind(GetElementsKind(cage_base)); 6621cb0ef41Sopenharmony_ci} 6631cb0ef41Sopenharmony_ci 6641cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasSmiOrObjectElements, bool) { 6651cb0ef41Sopenharmony_ci return IsSmiOrObjectElementsKind(GetElementsKind(cage_base)); 6661cb0ef41Sopenharmony_ci} 6671cb0ef41Sopenharmony_ci 6681cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasDoubleElements, bool) { 6691cb0ef41Sopenharmony_ci return IsDoubleElementsKind(GetElementsKind(cage_base)); 6701cb0ef41Sopenharmony_ci} 6711cb0ef41Sopenharmony_ci 6721cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasHoleyElements, bool) { 6731cb0ef41Sopenharmony_ci return IsHoleyElementsKind(GetElementsKind(cage_base)); 6741cb0ef41Sopenharmony_ci} 6751cb0ef41Sopenharmony_ci 6761cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasFastElements, bool) { 6771cb0ef41Sopenharmony_ci return IsFastElementsKind(GetElementsKind(cage_base)); 6781cb0ef41Sopenharmony_ci} 6791cb0ef41Sopenharmony_ci 6801cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasFastPackedElements, bool) { 6811cb0ef41Sopenharmony_ci return IsFastPackedElementsKind(GetElementsKind(cage_base)); 6821cb0ef41Sopenharmony_ci} 6831cb0ef41Sopenharmony_ci 6841cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasDictionaryElements, bool) { 6851cb0ef41Sopenharmony_ci return IsDictionaryElementsKind(GetElementsKind(cage_base)); 6861cb0ef41Sopenharmony_ci} 6871cb0ef41Sopenharmony_ci 6881cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasPackedElements, bool) { 6891cb0ef41Sopenharmony_ci return GetElementsKind(cage_base) == PACKED_ELEMENTS; 6901cb0ef41Sopenharmony_ci} 6911cb0ef41Sopenharmony_ci 6921cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasAnyNonextensibleElements, bool) { 6931cb0ef41Sopenharmony_ci return IsAnyNonextensibleElementsKind(GetElementsKind(cage_base)); 6941cb0ef41Sopenharmony_ci} 6951cb0ef41Sopenharmony_ci 6961cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasSealedElements, bool) { 6971cb0ef41Sopenharmony_ci return IsSealedElementsKind(GetElementsKind(cage_base)); 6981cb0ef41Sopenharmony_ci} 6991cb0ef41Sopenharmony_ci 7001cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasNonextensibleElements, bool) { 7011cb0ef41Sopenharmony_ci return IsNonextensibleElementsKind(GetElementsKind(cage_base)); 7021cb0ef41Sopenharmony_ci} 7031cb0ef41Sopenharmony_ci 7041cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasFastArgumentsElements, bool) { 7051cb0ef41Sopenharmony_ci return IsFastArgumentsElementsKind(GetElementsKind(cage_base)); 7061cb0ef41Sopenharmony_ci} 7071cb0ef41Sopenharmony_ci 7081cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasSlowArgumentsElements, bool) { 7091cb0ef41Sopenharmony_ci return IsSlowArgumentsElementsKind(GetElementsKind(cage_base)); 7101cb0ef41Sopenharmony_ci} 7111cb0ef41Sopenharmony_ci 7121cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasSloppyArgumentsElements, bool) { 7131cb0ef41Sopenharmony_ci return IsSloppyArgumentsElementsKind(GetElementsKind(cage_base)); 7141cb0ef41Sopenharmony_ci} 7151cb0ef41Sopenharmony_ci 7161cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasStringWrapperElements, bool) { 7171cb0ef41Sopenharmony_ci return IsStringWrapperElementsKind(GetElementsKind(cage_base)); 7181cb0ef41Sopenharmony_ci} 7191cb0ef41Sopenharmony_ci 7201cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasFastStringWrapperElements, bool) { 7211cb0ef41Sopenharmony_ci return GetElementsKind(cage_base) == FAST_STRING_WRAPPER_ELEMENTS; 7221cb0ef41Sopenharmony_ci} 7231cb0ef41Sopenharmony_ci 7241cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasSlowStringWrapperElements, bool) { 7251cb0ef41Sopenharmony_ci return GetElementsKind(cage_base) == SLOW_STRING_WRAPPER_ELEMENTS; 7261cb0ef41Sopenharmony_ci} 7271cb0ef41Sopenharmony_ci 7281cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasTypedArrayOrRabGsabTypedArrayElements, bool) { 7291cb0ef41Sopenharmony_ci DCHECK(!elements(cage_base).is_null()); 7301cb0ef41Sopenharmony_ci return map(cage_base).has_typed_array_or_rab_gsab_typed_array_elements(); 7311cb0ef41Sopenharmony_ci} 7321cb0ef41Sopenharmony_ci 7331cb0ef41Sopenharmony_ci#define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype) \ 7341cb0ef41Sopenharmony_ci DEF_GETTER(JSObject, HasFixed##Type##Elements, bool) { \ 7351cb0ef41Sopenharmony_ci return map(cage_base).elements_kind() == TYPE##_ELEMENTS; \ 7361cb0ef41Sopenharmony_ci } 7371cb0ef41Sopenharmony_ci 7381cb0ef41Sopenharmony_ciTYPED_ARRAYS(FIXED_TYPED_ELEMENTS_CHECK) 7391cb0ef41Sopenharmony_ci 7401cb0ef41Sopenharmony_ci#undef FIXED_TYPED_ELEMENTS_CHECK 7411cb0ef41Sopenharmony_ci 7421cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasNamedInterceptor, bool) { 7431cb0ef41Sopenharmony_ci return map(cage_base).has_named_interceptor(); 7441cb0ef41Sopenharmony_ci} 7451cb0ef41Sopenharmony_ci 7461cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, HasIndexedInterceptor, bool) { 7471cb0ef41Sopenharmony_ci return map(cage_base).has_indexed_interceptor(); 7481cb0ef41Sopenharmony_ci} 7491cb0ef41Sopenharmony_ci 7501cb0ef41Sopenharmony_ciRELEASE_ACQUIRE_ACCESSORS_CHECKED2(JSGlobalObject, global_dictionary, 7511cb0ef41Sopenharmony_ci GlobalDictionary, kPropertiesOrHashOffset, 7521cb0ef41Sopenharmony_ci !HasFastProperties(cage_base), true) 7531cb0ef41Sopenharmony_ci 7541cb0ef41Sopenharmony_ciDEF_GETTER(JSObject, element_dictionary, NumberDictionary) { 7551cb0ef41Sopenharmony_ci DCHECK(HasDictionaryElements(cage_base) || 7561cb0ef41Sopenharmony_ci HasSlowStringWrapperElements(cage_base)); 7571cb0ef41Sopenharmony_ci return NumberDictionary::cast(elements(cage_base)); 7581cb0ef41Sopenharmony_ci} 7591cb0ef41Sopenharmony_ci 7601cb0ef41Sopenharmony_civoid JSReceiver::initialize_properties(Isolate* isolate) { 7611cb0ef41Sopenharmony_ci ReadOnlyRoots roots(isolate); 7621cb0ef41Sopenharmony_ci DCHECK(!ObjectInYoungGeneration(roots.empty_fixed_array())); 7631cb0ef41Sopenharmony_ci DCHECK(!ObjectInYoungGeneration(roots.empty_property_dictionary())); 7641cb0ef41Sopenharmony_ci DCHECK(!ObjectInYoungGeneration(roots.empty_ordered_property_dictionary())); 7651cb0ef41Sopenharmony_ci if (map(isolate).is_dictionary_map()) { 7661cb0ef41Sopenharmony_ci if (V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL) { 7671cb0ef41Sopenharmony_ci WRITE_FIELD(*this, kPropertiesOrHashOffset, 7681cb0ef41Sopenharmony_ci roots.empty_swiss_property_dictionary()); 7691cb0ef41Sopenharmony_ci } else { 7701cb0ef41Sopenharmony_ci WRITE_FIELD(*this, kPropertiesOrHashOffset, 7711cb0ef41Sopenharmony_ci roots.empty_property_dictionary()); 7721cb0ef41Sopenharmony_ci } 7731cb0ef41Sopenharmony_ci } else { 7741cb0ef41Sopenharmony_ci WRITE_FIELD(*this, kPropertiesOrHashOffset, roots.empty_fixed_array()); 7751cb0ef41Sopenharmony_ci } 7761cb0ef41Sopenharmony_ci} 7771cb0ef41Sopenharmony_ci 7781cb0ef41Sopenharmony_ciDEF_GETTER(JSReceiver, HasFastProperties, bool) { 7791cb0ef41Sopenharmony_ci DCHECK(raw_properties_or_hash(cage_base).IsSmi() || 7801cb0ef41Sopenharmony_ci ((raw_properties_or_hash(cage_base).IsGlobalDictionary(cage_base) || 7811cb0ef41Sopenharmony_ci raw_properties_or_hash(cage_base).IsNameDictionary(cage_base) || 7821cb0ef41Sopenharmony_ci raw_properties_or_hash(cage_base).IsSwissNameDictionary( 7831cb0ef41Sopenharmony_ci cage_base)) == map(cage_base).is_dictionary_map())); 7841cb0ef41Sopenharmony_ci return !map(cage_base).is_dictionary_map(); 7851cb0ef41Sopenharmony_ci} 7861cb0ef41Sopenharmony_ci 7871cb0ef41Sopenharmony_ciDEF_GETTER(JSReceiver, property_dictionary, NameDictionary) { 7881cb0ef41Sopenharmony_ci DCHECK(!IsJSGlobalObject(cage_base)); 7891cb0ef41Sopenharmony_ci DCHECK(!HasFastProperties(cage_base)); 7901cb0ef41Sopenharmony_ci DCHECK(!V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL); 7911cb0ef41Sopenharmony_ci 7921cb0ef41Sopenharmony_ci Object prop = raw_properties_or_hash(cage_base); 7931cb0ef41Sopenharmony_ci if (prop.IsSmi()) { 7941cb0ef41Sopenharmony_ci return GetReadOnlyRoots(cage_base).empty_property_dictionary(); 7951cb0ef41Sopenharmony_ci } 7961cb0ef41Sopenharmony_ci return NameDictionary::cast(prop); 7971cb0ef41Sopenharmony_ci} 7981cb0ef41Sopenharmony_ci 7991cb0ef41Sopenharmony_ciDEF_GETTER(JSReceiver, property_dictionary_swiss, SwissNameDictionary) { 8001cb0ef41Sopenharmony_ci DCHECK(!IsJSGlobalObject(cage_base)); 8011cb0ef41Sopenharmony_ci DCHECK(!HasFastProperties(cage_base)); 8021cb0ef41Sopenharmony_ci DCHECK(V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL); 8031cb0ef41Sopenharmony_ci 8041cb0ef41Sopenharmony_ci Object prop = raw_properties_or_hash(cage_base); 8051cb0ef41Sopenharmony_ci if (prop.IsSmi()) { 8061cb0ef41Sopenharmony_ci return GetReadOnlyRoots(cage_base).empty_swiss_property_dictionary(); 8071cb0ef41Sopenharmony_ci } 8081cb0ef41Sopenharmony_ci return SwissNameDictionary::cast(prop); 8091cb0ef41Sopenharmony_ci} 8101cb0ef41Sopenharmony_ci 8111cb0ef41Sopenharmony_ci// TODO(gsathya): Pass isolate directly to this function and access 8121cb0ef41Sopenharmony_ci// the heap from this. 8131cb0ef41Sopenharmony_ciDEF_GETTER(JSReceiver, property_array, PropertyArray) { 8141cb0ef41Sopenharmony_ci DCHECK(HasFastProperties(cage_base)); 8151cb0ef41Sopenharmony_ci Object prop = raw_properties_or_hash(cage_base); 8161cb0ef41Sopenharmony_ci if (prop.IsSmi() || prop == GetReadOnlyRoots(cage_base).empty_fixed_array()) { 8171cb0ef41Sopenharmony_ci return GetReadOnlyRoots(cage_base).empty_property_array(); 8181cb0ef41Sopenharmony_ci } 8191cb0ef41Sopenharmony_ci return PropertyArray::cast(prop); 8201cb0ef41Sopenharmony_ci} 8211cb0ef41Sopenharmony_ci 8221cb0ef41Sopenharmony_ciMaybe<bool> JSReceiver::HasProperty(Isolate* isolate, Handle<JSReceiver> object, 8231cb0ef41Sopenharmony_ci Handle<Name> name) { 8241cb0ef41Sopenharmony_ci PropertyKey key(isolate, name); 8251cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, key, object); 8261cb0ef41Sopenharmony_ci return HasProperty(&it); 8271cb0ef41Sopenharmony_ci} 8281cb0ef41Sopenharmony_ci 8291cb0ef41Sopenharmony_ciMaybe<bool> JSReceiver::HasOwnProperty(Isolate* isolate, 8301cb0ef41Sopenharmony_ci Handle<JSReceiver> object, 8311cb0ef41Sopenharmony_ci uint32_t index) { 8321cb0ef41Sopenharmony_ci if (object->IsJSObject()) { // Shortcut. 8331cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, index, object, LookupIterator::OWN); 8341cb0ef41Sopenharmony_ci return HasProperty(&it); 8351cb0ef41Sopenharmony_ci } 8361cb0ef41Sopenharmony_ci 8371cb0ef41Sopenharmony_ci Maybe<PropertyAttributes> attributes = 8381cb0ef41Sopenharmony_ci JSReceiver::GetOwnPropertyAttributes(object, index); 8391cb0ef41Sopenharmony_ci MAYBE_RETURN(attributes, Nothing<bool>()); 8401cb0ef41Sopenharmony_ci return Just(attributes.FromJust() != ABSENT); 8411cb0ef41Sopenharmony_ci} 8421cb0ef41Sopenharmony_ci 8431cb0ef41Sopenharmony_ciMaybe<PropertyAttributes> JSReceiver::GetPropertyAttributes( 8441cb0ef41Sopenharmony_ci Handle<JSReceiver> object, Handle<Name> name) { 8451cb0ef41Sopenharmony_ci Isolate* isolate = object->GetIsolate(); 8461cb0ef41Sopenharmony_ci PropertyKey key(isolate, name); 8471cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, key, object); 8481cb0ef41Sopenharmony_ci return GetPropertyAttributes(&it); 8491cb0ef41Sopenharmony_ci} 8501cb0ef41Sopenharmony_ci 8511cb0ef41Sopenharmony_ciMaybe<PropertyAttributes> JSReceiver::GetOwnPropertyAttributes( 8521cb0ef41Sopenharmony_ci Handle<JSReceiver> object, Handle<Name> name) { 8531cb0ef41Sopenharmony_ci Isolate* isolate = object->GetIsolate(); 8541cb0ef41Sopenharmony_ci PropertyKey key(isolate, name); 8551cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, key, object, LookupIterator::OWN); 8561cb0ef41Sopenharmony_ci return GetPropertyAttributes(&it); 8571cb0ef41Sopenharmony_ci} 8581cb0ef41Sopenharmony_ci 8591cb0ef41Sopenharmony_ciMaybe<PropertyAttributes> JSReceiver::GetOwnPropertyAttributes( 8601cb0ef41Sopenharmony_ci Handle<JSReceiver> object, uint32_t index) { 8611cb0ef41Sopenharmony_ci LookupIterator it(object->GetIsolate(), object, index, object, 8621cb0ef41Sopenharmony_ci LookupIterator::OWN); 8631cb0ef41Sopenharmony_ci return GetPropertyAttributes(&it); 8641cb0ef41Sopenharmony_ci} 8651cb0ef41Sopenharmony_ci 8661cb0ef41Sopenharmony_ciMaybe<bool> JSReceiver::HasElement(Isolate* isolate, Handle<JSReceiver> object, 8671cb0ef41Sopenharmony_ci uint32_t index) { 8681cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, index, object); 8691cb0ef41Sopenharmony_ci return HasProperty(&it); 8701cb0ef41Sopenharmony_ci} 8711cb0ef41Sopenharmony_ci 8721cb0ef41Sopenharmony_ciMaybe<PropertyAttributes> JSReceiver::GetElementAttributes( 8731cb0ef41Sopenharmony_ci Handle<JSReceiver> object, uint32_t index) { 8741cb0ef41Sopenharmony_ci Isolate* isolate = object->GetIsolate(); 8751cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, index, object); 8761cb0ef41Sopenharmony_ci return GetPropertyAttributes(&it); 8771cb0ef41Sopenharmony_ci} 8781cb0ef41Sopenharmony_ci 8791cb0ef41Sopenharmony_ciMaybe<PropertyAttributes> JSReceiver::GetOwnElementAttributes( 8801cb0ef41Sopenharmony_ci Handle<JSReceiver> object, uint32_t index) { 8811cb0ef41Sopenharmony_ci Isolate* isolate = object->GetIsolate(); 8821cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, index, object, LookupIterator::OWN); 8831cb0ef41Sopenharmony_ci return GetPropertyAttributes(&it); 8841cb0ef41Sopenharmony_ci} 8851cb0ef41Sopenharmony_ci 8861cb0ef41Sopenharmony_cibool JSGlobalObject::IsDetached() { 8871cb0ef41Sopenharmony_ci return global_proxy().IsDetachedFrom(*this); 8881cb0ef41Sopenharmony_ci} 8891cb0ef41Sopenharmony_ci 8901cb0ef41Sopenharmony_cibool JSGlobalProxy::IsDetachedFrom(JSGlobalObject global) const { 8911cb0ef41Sopenharmony_ci const PrototypeIterator iter(this->GetIsolate(), *this); 8921cb0ef41Sopenharmony_ci return iter.GetCurrent() != global; 8931cb0ef41Sopenharmony_ci} 8941cb0ef41Sopenharmony_ci 8951cb0ef41Sopenharmony_ciinline int JSGlobalProxy::SizeWithEmbedderFields(int embedder_field_count) { 8961cb0ef41Sopenharmony_ci DCHECK_GE(embedder_field_count, 0); 8971cb0ef41Sopenharmony_ci return kHeaderSize + embedder_field_count * kEmbedderDataSlotSize; 8981cb0ef41Sopenharmony_ci} 8991cb0ef41Sopenharmony_ci 9001cb0ef41Sopenharmony_ciACCESSORS(JSIteratorResult, value, Object, kValueOffset) 9011cb0ef41Sopenharmony_ciACCESSORS(JSIteratorResult, done, Object, kDoneOffset) 9021cb0ef41Sopenharmony_ci 9031cb0ef41Sopenharmony_ci// If the fast-case backing storage takes up much more memory than a dictionary 9041cb0ef41Sopenharmony_ci// backing storage would, the object should have slow elements. 9051cb0ef41Sopenharmony_ci// static 9061cb0ef41Sopenharmony_cistatic inline bool ShouldConvertToSlowElements(uint32_t used_elements, 9071cb0ef41Sopenharmony_ci uint32_t new_capacity) { 9081cb0ef41Sopenharmony_ci uint32_t size_threshold = NumberDictionary::kPreferFastElementsSizeFactor * 9091cb0ef41Sopenharmony_ci NumberDictionary::ComputeCapacity(used_elements) * 9101cb0ef41Sopenharmony_ci NumberDictionary::kEntrySize; 9111cb0ef41Sopenharmony_ci return size_threshold <= new_capacity; 9121cb0ef41Sopenharmony_ci} 9131cb0ef41Sopenharmony_ci 9141cb0ef41Sopenharmony_cistatic inline bool ShouldConvertToSlowElements(JSObject object, 9151cb0ef41Sopenharmony_ci uint32_t capacity, 9161cb0ef41Sopenharmony_ci uint32_t index, 9171cb0ef41Sopenharmony_ci uint32_t* new_capacity) { 9181cb0ef41Sopenharmony_ci STATIC_ASSERT(JSObject::kMaxUncheckedOldFastElementsLength <= 9191cb0ef41Sopenharmony_ci JSObject::kMaxUncheckedFastElementsLength); 9201cb0ef41Sopenharmony_ci if (index < capacity) { 9211cb0ef41Sopenharmony_ci *new_capacity = capacity; 9221cb0ef41Sopenharmony_ci return false; 9231cb0ef41Sopenharmony_ci } 9241cb0ef41Sopenharmony_ci if (index - capacity >= JSObject::kMaxGap) return true; 9251cb0ef41Sopenharmony_ci *new_capacity = JSObject::NewElementsCapacity(index + 1); 9261cb0ef41Sopenharmony_ci DCHECK_LT(index, *new_capacity); 9271cb0ef41Sopenharmony_ci if (*new_capacity <= JSObject::kMaxUncheckedOldFastElementsLength || 9281cb0ef41Sopenharmony_ci (*new_capacity <= JSObject::kMaxUncheckedFastElementsLength && 9291cb0ef41Sopenharmony_ci ObjectInYoungGeneration(object))) { 9301cb0ef41Sopenharmony_ci return false; 9311cb0ef41Sopenharmony_ci } 9321cb0ef41Sopenharmony_ci return ShouldConvertToSlowElements(object.GetFastElementsUsage(), 9331cb0ef41Sopenharmony_ci *new_capacity); 9341cb0ef41Sopenharmony_ci} 9351cb0ef41Sopenharmony_ci 9361cb0ef41Sopenharmony_ci} // namespace internal 9371cb0ef41Sopenharmony_ci} // namespace v8 9381cb0ef41Sopenharmony_ci 9391cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h" 9401cb0ef41Sopenharmony_ci 9411cb0ef41Sopenharmony_ci#endif // V8_OBJECTS_JS_OBJECTS_INL_H_ 942