forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHostModel.cpp
More file actions
149 lines (125 loc) · 4.48 KB
/
HostModel.cpp
File metadata and controls
149 lines (125 loc) · 4.48 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* 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/HostModel.h"
#include "hermes/VM/BuildMetadata.h"
#include "llvh/Support/Debug.h"
#define DEBUG_TYPE "serialize"
namespace hermes {
namespace vm {
//===----------------------------------------------------------------------===//
// class FinalizableNativeFunction
CallableVTable FinalizableNativeFunction::vt{
{
VTable(
CellKind::FinalizableNativeFunctionKind,
cellSize<FinalizableNativeFunction>(),
FinalizableNativeFunction::_finalizeImpl),
FinalizableNativeFunction::_getOwnIndexedRangeImpl,
FinalizableNativeFunction::_haveOwnIndexedImpl,
FinalizableNativeFunction::_getOwnIndexedPropertyFlagsImpl,
FinalizableNativeFunction::_getOwnIndexedImpl,
FinalizableNativeFunction::_setOwnIndexedImpl,
FinalizableNativeFunction::_deleteOwnIndexedImpl,
FinalizableNativeFunction::_checkAllOwnIndexedImpl,
},
FinalizableNativeFunction::_newObjectImpl,
FinalizableNativeFunction::_callImpl};
void FinalizableNativeFunctionBuildMeta(
const GCCell *cell,
Metadata::Builder &mb) {
mb.addJSObjectOverlapSlots(
JSObject::numOverlapSlots<FinalizableNativeFunction>());
NativeFunctionBuildMeta(cell, mb);
}
#ifdef HERMESVM_SERIALIZE
void FinalizableNativeFunctionSerialize(Serializer &s, const GCCell *cell) {
llvh::outs()
<< "Serialize function not implemented for FinalizableNativeFunction\n";
}
void FinalizableNativeFunctionDeserialize(Deserializer &d, CellKind kind) {
llvh::outs()
<< "Deserialize function not implemented for FinalizableNativeFunction\n";
}
#endif
CallResult<HermesValue> FinalizableNativeFunction::createWithoutPrototype(
Runtime *runtime,
void *context,
NativeFunctionPtr functionPtr,
FinalizeNativeFunctionPtr finalizePtr,
SymbolID name,
unsigned paramCount) {
auto parentHandle = Handle<JSObject>::vmcast(&runtime->functionPrototype);
JSObjectAlloc<FinalizableNativeFunction, HasFinalizer::Yes> mem{runtime};
auto selfHandle = mem.initToHandle(new (mem) FinalizableNativeFunction(
runtime,
parentHandle,
createPseudoHandle(runtime->getHiddenClassForPrototypeRaw(
*parentHandle,
numOverlapSlots<FinalizableNativeFunction>() +
ANONYMOUS_PROPERTY_SLOTS)),
context,
functionPtr,
finalizePtr));
auto prototypeObjectHandle = Handle<JSObject>(runtime);
auto st = defineNameLengthAndPrototype(
selfHandle,
runtime,
name,
paramCount,
prototypeObjectHandle,
Callable::WritablePrototype::Yes,
false);
(void)st;
assert(
st != ExecutionStatus::EXCEPTION && "defineLengthAndPrototype() failed");
return selfHandle.getHermesValue();
}
HostObjectProxy::~HostObjectProxy() {}
ObjectVTable HostObject::vt{
VTable(
CellKind::HostObjectKind,
cellSize<HostObject>(),
HostObject::_finalizeImpl),
HostObject::_getOwnIndexedRangeImpl,
HostObject::_haveOwnIndexedImpl,
HostObject::_getOwnIndexedPropertyFlagsImpl,
HostObject::_getOwnIndexedImpl,
HostObject::_setOwnIndexedImpl,
HostObject::_deleteOwnIndexedImpl,
HostObject::_checkAllOwnIndexedImpl,
};
void HostObjectBuildMeta(const GCCell *cell, Metadata::Builder &mb) {
mb.addJSObjectOverlapSlots(JSObject::numOverlapSlots<HostObject>());
ObjectBuildMeta(cell, mb);
}
#ifdef HERMESVM_SERIALIZE
void HostObjectSerialize(Serializer &s, const GCCell *cell) {
LLVM_DEBUG(
llvh::dbgs() << "Serialize function not implemented for HostObject\n");
}
void HostObjectDeserialize(Deserializer &d, CellKind kind) {
LLVM_DEBUG(
llvh::dbgs() << "Deserialize function not implemented for HostObject\n");
}
#endif
CallResult<HermesValue> HostObject::createWithoutPrototype(
Runtime *runtime,
std::unique_ptr<HostObjectProxy> proxy) {
auto parentHandle = Handle<JSObject>::vmcast(&runtime->objectPrototype);
JSObjectAlloc<HostObject, HasFinalizer::Yes> mem{runtime};
HostObject *hostObj = new (mem) HostObject(
runtime,
*parentHandle,
runtime->getHiddenClassForPrototypeRaw(
*parentHandle,
numOverlapSlots<HostObject>() + ANONYMOUS_PROPERTY_SLOTS),
std::move(proxy));
hostObj->flags_.hostObject = true;
return mem.initToHermesValue(hostObj);
}
} // namespace vm
} // namespace hermes