Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / js / src / vm / ArrayObject.h
blob8a10710dd82cdce7854e3590cb091874b9e44e35
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef vm_ArrayObject_h
8 #define vm_ArrayObject_h
10 #include "vm/NativeObject.h"
12 namespace js {
14 class AutoSetNewObjectMetadata;
16 class ArrayObject : public NativeObject {
17 public:
18 // Array(x) eagerly allocates dense elements if x <= this value. Without
19 // the subtraction the max would roll over to the next power-of-two (4096)
20 // due to the way that growElements() and goodAllocated() work.
21 static const uint32_t EagerAllocationMaxLength =
22 2048 - ObjectElements::VALUES_PER_HEADER;
24 static const JSClass class_;
26 bool lengthIsWritable() const {
27 return !getElementsHeader()->hasNonwritableArrayLength();
30 uint32_t length() const { return getElementsHeader()->length; }
32 void setNonWritableLength(JSContext* cx) {
33 shrinkCapacityToInitializedLength(cx);
34 getElementsHeader()->setNonwritableArrayLength();
37 void setLength(uint32_t length) {
38 MOZ_ASSERT(lengthIsWritable());
39 MOZ_ASSERT_IF(length != getElementsHeader()->length,
40 !denseElementsAreFrozen());
41 getElementsHeader()->length = length;
44 // Try to add a new dense element to this array. The array must be extensible.
46 // Returns DenseElementResult::Incomplete if `index >= length`, if the array
47 // has sparse elements, if we're adding a sparse element, or if the array
48 // already contains a dense element at this index.
49 inline DenseElementResult addDenseElementNoLengthChange(JSContext* cx,
50 uint32_t index,
51 const Value& val);
53 // Make an array object with the specified initial state.
54 static MOZ_ALWAYS_INLINE ArrayObject* create(
55 JSContext* cx, gc::AllocKind kind, gc::Heap heap,
56 Handle<SharedShape*> shape, uint32_t length, uint32_t slotSpan,
57 AutoSetNewObjectMetadata& metadata, gc::AllocSite* site = nullptr);
60 } // namespace js
62 #endif // vm_ArrayObject_h