forked from microsoft/hermes-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HostModel.cpp
121 lines (102 loc) · 3.71 KB
/
HostModel.cpp
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
/*
* 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"
namespace hermes {
namespace vm {
//===----------------------------------------------------------------------===//
// class FinalizableNativeFunction
const 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);
mb.setVTable(&FinalizableNativeFunction::vt.base.base);
}
CallResult<HermesValue> FinalizableNativeFunction::createWithoutPrototype(
Runtime *runtime,
void *context,
NativeFunctionPtr functionPtr,
FinalizeNativeFunctionPtr finalizePtr,
SymbolID name,
unsigned paramCount) {
auto parentHandle = Handle<JSObject>::vmcast(&runtime->functionPrototype);
auto *cell =
runtime->makeAFixed<FinalizableNativeFunction, HasFinalizer::Yes>(
runtime,
parentHandle,
runtime->getHiddenClassForPrototype(
*parentHandle, numOverlapSlots<FinalizableNativeFunction>()),
context,
functionPtr,
finalizePtr);
auto selfHandle = JSObjectInit::initToHandle(runtime, cell);
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() {}
const 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);
mb.setVTable(&HostObject::vt.base);
}
CallResult<HermesValue> HostObject::createWithoutPrototype(
Runtime *runtime,
std::unique_ptr<HostObjectProxy> proxy) {
auto parentHandle = Handle<JSObject>::vmcast(&runtime->objectPrototype);
HostObject *hostObj = runtime->makeAFixed<HostObject, HasFinalizer::Yes>(
runtime,
parentHandle,
runtime->getHiddenClassForPrototype(
*parentHandle, numOverlapSlots<HostObject>()),
std::move(proxy));
hostObj->flags_.hostObject = true;
return JSObjectInit::initToHermesValue(runtime, hostObj);
}
} // namespace vm
} // namespace hermes