forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxedDouble.cpp
More file actions
45 lines (38 loc) · 1.2 KB
/
BoxedDouble.cpp
File metadata and controls
45 lines (38 loc) · 1.2 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
/*
* 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/BoxedDouble.h"
#include "hermes/VM/Deserializer.h"
#include "hermes/VM/Runtime.h"
#include "hermes/VM/Serializer.h"
namespace hermes {
namespace vm {
const VTable BoxedDouble::vt{
CellKind::BoxedDoubleKind,
cellSize<BoxedDouble>()};
void BoxedDoubleBuildMeta(const GCCell *cell, Metadata::Builder &mb) {
mb.setVTable(&BoxedDouble::vt);
}
#ifdef HERMESVM_SERIALIZE
void BoxedDoubleSerialize(Serializer &s, const GCCell *cell) {
auto *self = vmcast<const BoxedDouble>(cell);
s.writeHermesValue(HermesValue::encodeNumberValue(self->value_));
s.endObject(cell);
}
void BoxedDoubleDeserialize(Deserializer &d, CellKind kind) {
assert(kind == CellKind::BoxedDoubleKind && "Expected BoxedDouble");
auto *cell = d.getRuntime()->makeAFixed<BoxedDouble>(d);
d.endObject(cell);
}
BoxedDouble::BoxedDouble(Deserializer &d)
: GCCell(&d.getRuntime()->getHeap(), &BoxedDouble::vt) {
HermesValue hv;
d.readHermesValue(&hv);
value_ = hv.getNumber();
}
#endif
} // namespace vm
} // namespace hermes