11cb0ef41Sopenharmony_ci// Copyright 2017 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_ARRAY_INL_H_ 61cb0ef41Sopenharmony_ci#define V8_OBJECTS_JS_ARRAY_INL_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/objects/js-array.h" 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h" // Needed for write barriers 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards): 131cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h" 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cinamespace v8 { 161cb0ef41Sopenharmony_cinamespace internal { 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/js-array-tq-inl.inc" 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSArray) 211cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSArrayIterator) 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciDEF_GETTER(JSArray, length, Object) { 241cb0ef41Sopenharmony_ci return TaggedField<Object, kLengthOffset>::load(cage_base, *this); 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_civoid JSArray::set_length(Object value, WriteBarrierMode mode) { 281cb0ef41Sopenharmony_ci // Note the relaxed atomic store. 291cb0ef41Sopenharmony_ci TaggedField<Object, kLengthOffset>::Relaxed_Store(*this, value); 301cb0ef41Sopenharmony_ci CONDITIONAL_WRITE_BARRIER(*this, kLengthOffset, value, mode); 311cb0ef41Sopenharmony_ci} 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ciObject JSArray::length(PtrComprCageBase cage_base, RelaxedLoadTag tag) const { 341cb0ef41Sopenharmony_ci return TaggedField<Object, kLengthOffset>::Relaxed_Load(cage_base, *this); 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_civoid JSArray::set_length(Smi length) { 381cb0ef41Sopenharmony_ci // Don't need a write barrier for a Smi. 391cb0ef41Sopenharmony_ci set_length(Object(length.ptr()), SKIP_WRITE_BARRIER); 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_cibool JSArray::SetLengthWouldNormalize(Heap* heap, uint32_t new_length) { 431cb0ef41Sopenharmony_ci return new_length > kMaxFastArrayLength; 441cb0ef41Sopenharmony_ci} 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_civoid JSArray::SetContent(Handle<JSArray> array, 471cb0ef41Sopenharmony_ci Handle<FixedArrayBase> storage) { 481cb0ef41Sopenharmony_ci EnsureCanContainElements(array, storage, storage->length(), 491cb0ef41Sopenharmony_ci ALLOW_COPIED_DOUBLE_ELEMENTS); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci DCHECK( 521cb0ef41Sopenharmony_ci (storage->map() == array->GetReadOnlyRoots().fixed_double_array_map() && 531cb0ef41Sopenharmony_ci IsDoubleElementsKind(array->GetElementsKind())) || 541cb0ef41Sopenharmony_ci ((storage->map() != array->GetReadOnlyRoots().fixed_double_array_map()) && 551cb0ef41Sopenharmony_ci (IsObjectElementsKind(array->GetElementsKind()) || 561cb0ef41Sopenharmony_ci (IsSmiElementsKind(array->GetElementsKind()) && 571cb0ef41Sopenharmony_ci Handle<FixedArray>::cast(storage)->ContainsOnlySmisOrHoles())))); 581cb0ef41Sopenharmony_ci array->set_elements(*storage); 591cb0ef41Sopenharmony_ci array->set_length(Smi::FromInt(storage->length())); 601cb0ef41Sopenharmony_ci} 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_cibool JSArray::HasArrayPrototype(Isolate* isolate) { 631cb0ef41Sopenharmony_ci return map().prototype() == *isolate->initial_array_prototype(); 641cb0ef41Sopenharmony_ci} 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ciSMI_ACCESSORS(JSArrayIterator, raw_kind, kKindOffset) 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ciIterationKind JSArrayIterator::kind() const { 691cb0ef41Sopenharmony_ci return static_cast<IterationKind>(raw_kind()); 701cb0ef41Sopenharmony_ci} 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_civoid JSArrayIterator::set_kind(IterationKind kind) { 731cb0ef41Sopenharmony_ci set_raw_kind(static_cast<int>(kind)); 741cb0ef41Sopenharmony_ci} 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci} // namespace internal 771cb0ef41Sopenharmony_ci} // namespace v8 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h" 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci#endif // V8_OBJECTS_JS_ARRAY_INL_H_ 82