Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/js/src/vm/ArrayObject.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
 * vim: set ts=8 sts=4 et sw=4 tw=99:
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/. */
6
7
#ifndef vm_ArrayObject_h
8
#define vm_ArrayObject_h
9
10
#include "vm/NativeObject.h"
11
12
namespace js {
13
14
class AutoSetNewObjectMetadata;
15
16
class ArrayObject : public NativeObject
17
{
18
  public:
19
    // Array(x) eagerly allocates dense elements if x <= this value. Without
20
    // the subtraction the max would roll over to the next power-of-two (4096)
21
    // due to the way that growElements() and goodAllocated() work.
22
    static const uint32_t EagerAllocationMaxLength = 2048 - ObjectElements::VALUES_PER_HEADER;
23
24
    static const Class class_;
25
26
104
    bool lengthIsWritable() const {
27
104
        return !getElementsHeader()->hasNonwritableArrayLength();
28
104
    }
29
30
138
    uint32_t length() const {
31
138
        return getElementsHeader()->length;
32
138
    }
33
34
0
    void setNonWritableLength(JSContext* cx) {
35
0
        shrinkCapacityToInitializedLength(cx);
36
0
        getElementsHeader()->setNonwritableArrayLength();
37
0
    }
38
39
    inline void setLength(JSContext* cx, uint32_t length);
40
41
    // Variant of setLength for use on arrays where the length cannot overflow int32_t.
42
9
    void setLengthInt32(uint32_t length) {
43
9
        MOZ_ASSERT(lengthIsWritable());
44
9
        MOZ_ASSERT_IF(length != getElementsHeader()->length, !denseElementsAreFrozen());
45
9
        MOZ_ASSERT(length <= INT32_MAX);
46
9
        getElementsHeader()->length = length;
47
9
    }
48
49
    // Make an array object with the specified initial state.
50
    static inline ArrayObject*
51
    createArray(JSContext* cx,
52
                gc::AllocKind kind,
53
                gc::InitialHeap heap,
54
                HandleShape shape,
55
                HandleObjectGroup group,
56
                uint32_t length,
57
                AutoSetNewObjectMetadata& metadata);
58
59
    // Make a copy-on-write array object which shares the elements of an
60
    // existing object.
61
    static inline ArrayObject*
62
    createCopyOnWriteArray(JSContext* cx,
63
                           gc::InitialHeap heap,
64
                           HandleArrayObject sharedElementsOwner);
65
66
  private:
67
    // Helper for the above methods.
68
    static inline ArrayObject*
69
    createArrayInternal(JSContext* cx,
70
                        gc::AllocKind kind,
71
                        gc::InitialHeap heap,
72
                        HandleShape shape,
73
                        HandleObjectGroup group,
74
                        AutoSetNewObjectMetadata&);
75
76
    static inline ArrayObject*
77
    finishCreateArray(ArrayObject* obj, HandleShape shape, AutoSetNewObjectMetadata& metadata);
78
};
79
80
} // namespace js
81
82
#endif // vm_ArrayObject_h
83