1// Copyright 2017 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef V8_OBJECTS_JS_ARRAY_INL_H_ 6#define V8_OBJECTS_JS_ARRAY_INL_H_ 7 8#include "src/objects/js-array.h" 9 10#include "src/objects/objects-inl.h" // Needed for write barriers 11 12// Has to be the last include (doesn't have include guards): 13#include "src/objects/object-macros.h" 14 15namespace v8 { 16namespace internal { 17 18#include "torque-generated/src/objects/js-array-tq-inl.inc" 19 20TQ_OBJECT_CONSTRUCTORS_IMPL(JSArray) 21TQ_OBJECT_CONSTRUCTORS_IMPL(JSArrayIterator) 22 23DEF_GETTER(JSArray, length, Object) { 24 return TaggedField<Object, kLengthOffset>::load(cage_base, *this); 25} 26 27void JSArray::set_length(Object value, WriteBarrierMode mode) { 28 // Note the relaxed atomic store. 29 TaggedField<Object, kLengthOffset>::Relaxed_Store(*this, value); 30 CONDITIONAL_WRITE_BARRIER(*this, kLengthOffset, value, mode); 31} 32 33Object JSArray::length(PtrComprCageBase cage_base, RelaxedLoadTag tag) const { 34 return TaggedField<Object, kLengthOffset>::Relaxed_Load(cage_base, *this); 35} 36 37void JSArray::set_length(Smi length) { 38 // Don't need a write barrier for a Smi. 39 set_length(Object(length.ptr()), SKIP_WRITE_BARRIER); 40} 41 42bool JSArray::SetLengthWouldNormalize(Heap* heap, uint32_t new_length) { 43 return new_length > kMaxFastArrayLength; 44} 45 46void JSArray::SetContent(Handle<JSArray> array, 47 Handle<FixedArrayBase> storage) { 48 EnsureCanContainElements(array, storage, storage->length(), 49 ALLOW_COPIED_DOUBLE_ELEMENTS); 50 51 DCHECK( 52 (storage->map() == array->GetReadOnlyRoots().fixed_double_array_map() && 53 IsDoubleElementsKind(array->GetElementsKind())) || 54 ((storage->map() != array->GetReadOnlyRoots().fixed_double_array_map()) && 55 (IsObjectElementsKind(array->GetElementsKind()) || 56 (IsSmiElementsKind(array->GetElementsKind()) && 57 Handle<FixedArray>::cast(storage)->ContainsOnlySmisOrHoles())))); 58 array->set_elements(*storage); 59 array->set_length(Smi::FromInt(storage->length())); 60} 61 62bool JSArray::HasArrayPrototype(Isolate* isolate) { 63 return map().prototype() == *isolate->initial_array_prototype(); 64} 65 66SMI_ACCESSORS(JSArrayIterator, raw_kind, kKindOffset) 67 68IterationKind JSArrayIterator::kind() const { 69 return static_cast<IterationKind>(raw_kind()); 70} 71 72void JSArrayIterator::set_kind(IterationKind kind) { 73 set_raw_kind(static_cast<int>(kind)); 74} 75 76} // namespace internal 77} // namespace v8 78 79#include "src/objects/object-macros-undef.h" 80 81#endif // V8_OBJECTS_JS_ARRAY_INL_H_ 82