forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSDataView.cpp
More file actions
81 lines (68 loc) · 2.41 KB
/
JSDataView.cpp
File metadata and controls
81 lines (68 loc) · 2.41 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
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* 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.
*/
#include "hermes/VM/JSDataView.h"
#include "hermes/VM/BuildMetadata.h"
#include "llvh/Support/Debug.h"
#define DEBUG_TYPE "serialize"
namespace hermes {
namespace vm {
ObjectVTable JSDataView::vt{
VTable(CellKind::DataViewKind, cellSize<JSDataView>()),
JSDataView::_getOwnIndexedRangeImpl,
JSDataView::_haveOwnIndexedImpl,
JSDataView::_getOwnIndexedPropertyFlagsImpl,
JSDataView::_getOwnIndexedImpl,
JSDataView::_setOwnIndexedImpl,
JSDataView::_deleteOwnIndexedImpl,
JSDataView::_checkAllOwnIndexedImpl,
};
void DataViewBuildMeta(const GCCell *cell, Metadata::Builder &mb) {
mb.addJSObjectOverlapSlots(JSObject::numOverlapSlots<JSDataView>());
ObjectBuildMeta(cell, mb);
const auto *self = static_cast<const JSDataView *>(cell);
mb.addField("buffer", &self->buffer_);
}
#ifdef HERMESVM_SERIALIZE
JSDataView::JSDataView(Deserializer &d) : JSObject(d, &vt.base) {
d.readRelocation(&buffer_, RelocationKind::GCPointer);
offset_ = d.readInt<size_type>();
length_ = d.readInt<size_type>();
}
void DataViewSerialize(Serializer &s, const GCCell *cell) {
auto *self = vmcast<const JSDataView>(cell);
JSObject::serializeObjectImpl(
s, cell, JSObject::numOverlapSlots<JSDataView>());
s.writeRelocation(self->buffer_.get(s.getRuntime()));
s.writeInt<JSDataView::size_type>(self->offset_);
s.writeInt<JSDataView::size_type>(self->length_);
s.endObject(cell);
}
void DataViewDeserialize(Deserializer &d, CellKind kind) {
assert(kind == CellKind::DataViewKind && "Expected DataView");
void *mem = d.getRuntime()->alloc(cellSize<JSDataView>());
auto *cell = new (mem) JSDataView(d);
d.endObject(cell);
}
#endif
PseudoHandle<JSDataView> JSDataView::create(
Runtime *runtime,
Handle<JSObject> prototype) {
JSObjectAlloc<JSDataView> mem{runtime};
return mem.initToPseudoHandle(new (mem) JSDataView(
runtime,
*prototype,
runtime->getHiddenClassForPrototypeRaw(
*prototype,
numOverlapSlots<JSDataView>() + ANONYMOUS_PROPERTY_SLOTS)));
}
JSDataView::JSDataView(Runtime *runtime, JSObject *parent, HiddenClass *clazz)
: JSObject(runtime, &vt.base, parent, clazz),
buffer_(nullptr),
offset_(0),
length_(0) {}
} // namespace vm
} // namespace hermes