forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.h
More file actions
68 lines (52 loc) · 1.73 KB
/
Array.h
File metadata and controls
68 lines (52 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef HERMES_UNITTESTS_VMRUNTIME_ARRAY_H
#define HERMES_UNITTESTS_VMRUNTIME_ARRAY_H
#include "TestHelpers.h"
#include "hermes/VM/BuildMetadata.h"
#include "hermes/VM/GC.h"
#include "llvh/Support/TrailingObjects.h"
using namespace hermes::vm;
namespace hermes {
namespace unittest {
/// An Array class suitable for use in unit tests.
class Array final : public VariableSizeRuntimeCell,
private llvh::TrailingObjects<Array, GCHermesValue> {
friend TrailingObjects;
public:
static const VTable vt;
AtomicIfConcurrentGC<uint32_t> length;
Array(GC *gc, uint32_t length)
: VariableSizeRuntimeCell(gc, &vt, allocSize(length)), length(length) {}
static bool classof(const GCCell *cell) {
return cell->getVT() == &vt;
}
GCHermesValue *values() {
return getTrailingObjects<GCHermesValue>();
}
const GCHermesValue *values() const {
return getTrailingObjects<GCHermesValue>();
}
static Array *create(DummyRuntime &runtime, uint32_t length) {
auto *self =
new (runtime.allocWithFinalizer</*fixedSize*/ false>(allocSize(length)))
Array(&runtime.getHeap(), length);
GCHermesValue::fill(
self->values(),
self->values() + length,
HermesValue::encodeEmptyValue(),
&runtime.getHeap());
return self;
}
static uint32_t allocSize(uint32_t length) {
return totalSizeToAlloc<GCHermesValue>(length);
}
};
void ArrayBuildMeta(const GCCell *cell, Metadata::Builder &mb);
} // namespace unittest
} // namespace hermes
#endif // HERMES_UNITTESTS_VMRUNTIME_ARRAY_H