@crossbind/core-embind-jsi 2.0.0-beta.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +16 -0
- package/cpp/CMakeLists.txt +16 -0
- package/cpp/src/emscripten/bind.cpp +1158 -0
- package/cpp/src/emscripten/bind.h +2880 -0
- package/cpp/src/emscripten/em_macros.h +43 -0
- package/cpp/src/emscripten/val.h +708 -0
- package/cpp/src/emscripten/wire.h +610 -0
- package/crossbind.config.mjs +5 -0
- package/js/embind.js +4908 -0
- package/package.json +27 -0
|
@@ -0,0 +1,1158 @@
|
|
|
1
|
+
// Copyright 2012 The Emscripten Authors. All rights reserved.
|
|
2
|
+
// Emscripten is available under two separate licenses, the MIT license and the
|
|
3
|
+
// University of Illinois/NCSA Open Source License. Both these licenses can be
|
|
4
|
+
// found in the LICENSE file.
|
|
5
|
+
|
|
6
|
+
#include "./bind.h"
|
|
7
|
+
#ifdef USE_CXA_DEMANGLE
|
|
8
|
+
#include <../lib/libcxxabi/include/cxxabi.h>
|
|
9
|
+
#endif
|
|
10
|
+
#include <algorithm>
|
|
11
|
+
#include <climits>
|
|
12
|
+
// #include <emscripten/emscripten.h>
|
|
13
|
+
#include "./wire.h"
|
|
14
|
+
#include <limits>
|
|
15
|
+
#include <list>
|
|
16
|
+
#include <typeinfo>
|
|
17
|
+
#include <vector>
|
|
18
|
+
#include <string.h>
|
|
19
|
+
|
|
20
|
+
#include <any>
|
|
21
|
+
#include <unordered_map>
|
|
22
|
+
#include <stdlib.h>
|
|
23
|
+
|
|
24
|
+
#ifdef __ANDROID__
|
|
25
|
+
#include <unistd.h>
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
using namespace emscripten;
|
|
29
|
+
using namespace internal;
|
|
30
|
+
using namespace facebook;
|
|
31
|
+
|
|
32
|
+
std::string CROSSBIND_DATA_PATH = "";
|
|
33
|
+
|
|
34
|
+
namespace emscripten {
|
|
35
|
+
facebook::jsi::Runtime* jsRuntime = nullptr;
|
|
36
|
+
namespace internal {
|
|
37
|
+
|
|
38
|
+
// Dynamic heap window registration. JS side keeps multiple ArrayBuffer
|
|
39
|
+
// windows over native memory; this ensures every pointer we hand to JS
|
|
40
|
+
// is covered by at least one window before being read/written there.
|
|
41
|
+
void ensureWindowFor(uint64_t ptr);
|
|
42
|
+
void registerHeapWindow(uint64_t offset);
|
|
43
|
+
|
|
44
|
+
template<typename T>
|
|
45
|
+
struct Bugra {
|
|
46
|
+
static jsi::Value toValue(T rawValue);
|
|
47
|
+
static jsi::Value toValue(T* rawValue);
|
|
48
|
+
static jsi::Value toValue(T** rawValue);
|
|
49
|
+
static jsi::Array toArrayValue(std::vector<T> rawValue);
|
|
50
|
+
|
|
51
|
+
static T fromValue(jsi::Value& rawValue);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
template<typename T>
|
|
55
|
+
jsi::Value Bugra<T>::toValue(T rawValue) {
|
|
56
|
+
return jsi::Value(rawValue);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
template<typename T>
|
|
60
|
+
jsi::Value Bugra<T>::toValue(T* rawValue) {
|
|
61
|
+
uint64_t ptr = reinterpret_cast<uint64_t>(rawValue);
|
|
62
|
+
ensureWindowFor(ptr);
|
|
63
|
+
return jsi::BigInt::fromUint64(*jsRuntime, ptr);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
template<typename T>
|
|
67
|
+
jsi::Value Bugra<T>::toValue(T** rawValue) {
|
|
68
|
+
uint64_t ptr = reinterpret_cast<uint64_t>(rawValue);
|
|
69
|
+
ensureWindowFor(ptr);
|
|
70
|
+
return jsi::BigInt::fromUint64(*jsRuntime, ptr);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
template<typename T>
|
|
74
|
+
T Bugra<T>::fromValue(jsi::Value& rawValue) {
|
|
75
|
+
return reinterpret_cast<T>(rawValue.asBigInt(*jsRuntime).asUint64(*jsRuntime));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
template<> inline jsi::Value Bugra<bool>::toValue(bool rawValue) {
|
|
79
|
+
return jsi::Value(rawValue);
|
|
80
|
+
}
|
|
81
|
+
template<> inline bool Bugra<bool>::fromValue(jsi::Value& rawValue) {
|
|
82
|
+
return rawValue.asBool();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
template<> inline jsi::Value Bugra<double>::toValue(double rawValue) {
|
|
86
|
+
return jsi::Value(rawValue);
|
|
87
|
+
}
|
|
88
|
+
template<> inline double Bugra<double>::fromValue(jsi::Value& rawValue) {
|
|
89
|
+
return rawValue.getNumber();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
template<> inline jsi::Value Bugra<int32_t>::toValue(int32_t rawValue) {
|
|
93
|
+
return jsi::Value(rawValue);
|
|
94
|
+
}
|
|
95
|
+
template<> inline jsi::Value Bugra<uint32_t>::toValue(uint32_t rawValue) {
|
|
96
|
+
return jsi::BigInt::fromUint64(*jsRuntime, rawValue);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
template<> inline jsi::Value Bugra<int64_t>::toValue(int64_t rawValue) {
|
|
100
|
+
return jsi::BigInt::fromInt64(*jsRuntime, rawValue);
|
|
101
|
+
}
|
|
102
|
+
template<> inline int64_t Bugra<int64_t>::fromValue(jsi::Value& rawValue) {
|
|
103
|
+
return rawValue.getBigInt(*jsRuntime).asInt64(*jsRuntime);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
template<> inline jsi::Value Bugra<uint64_t>::toValue(uint64_t rawValue) {
|
|
107
|
+
return jsi::BigInt::fromUint64(*jsRuntime, rawValue);
|
|
108
|
+
}
|
|
109
|
+
template<> inline uint64_t Bugra<uint64_t>::fromValue(jsi::Value& rawValue) {
|
|
110
|
+
return rawValue.getBigInt(*jsRuntime).asUint64(*jsRuntime);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
template<> inline jsi::Value Bugra<std::string>::toValue(std::string rawValue) {
|
|
114
|
+
return jsi::String::createFromUtf8(*jsRuntime, rawValue);
|
|
115
|
+
}
|
|
116
|
+
template<> inline jsi::Value Bugra<const char*>::toValue(const char* rawValue) {
|
|
117
|
+
return jsi::String::createFromUtf8(*jsRuntime, std::string(rawValue));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
template<> inline jsi::Value Bugra<TYPEID>::toValue(TYPEID rawValue) {
|
|
121
|
+
return jsi::BigInt::fromUint64(*jsRuntime, reinterpret_cast<uint64_t>(rawValue));
|
|
122
|
+
}
|
|
123
|
+
template<> inline jsi::Array Bugra<TYPEID>::toArrayValue(std::vector<TYPEID> rawValue) {
|
|
124
|
+
std::vector<jsi::Value> input;
|
|
125
|
+
for (TYPEID t : rawValue) {
|
|
126
|
+
input.push_back(Bugra<TYPEID>::toValue(t));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
jsi::Array result(*jsRuntime, input.size());
|
|
130
|
+
size_t index = 0;
|
|
131
|
+
for (const auto& element : input) {
|
|
132
|
+
result.setValueAtIndex(*jsRuntime, index++, element);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
template<> inline jsi::Value Bugra<GenericFunction>::toValue(GenericFunction rawValue) {
|
|
138
|
+
return jsi::BigInt::fromUint64(*jsRuntime, reinterpret_cast<uint64_t>(rawValue));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
template<> inline jsi::Value Bugra<EM_VAL>::toValue(EM_VAL rawValue) {
|
|
142
|
+
return jsi::BigInt::fromUint64(*jsRuntime, reinterpret_cast<uint64_t>(rawValue));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
template<> inline EM_VAL Bugra<EM_VAL>::fromValue(jsi::Value& rawValue) {
|
|
146
|
+
return reinterpret_cast<EM_VAL>(rawValue.asBigInt(*jsRuntime).asUint64(*jsRuntime));
|
|
147
|
+
// return reinterpret_cast<EM_VAL>((uint32_t) rawValue.getNumber());
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
template<> inline jsi::Value Bugra<EM_METHOD_CALLER>::toValue(EM_METHOD_CALLER rawValue) {
|
|
151
|
+
return jsi::BigInt::fromUint64(*jsRuntime, reinterpret_cast<uint64_t>(rawValue));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
template<> inline jsi::Value Bugra<EM_DESTRUCTORS>::toValue(EM_DESTRUCTORS rawValue) {
|
|
155
|
+
return jsi::BigInt::fromUint64(*jsRuntime, reinterpret_cast<uint64_t>(rawValue));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
template<> inline jsi::Value Bugra<EM_DESTRUCTORS*>::toValue(EM_DESTRUCTORS* rawValue) {
|
|
159
|
+
uint64_t ptr = reinterpret_cast<uint64_t>(rawValue);
|
|
160
|
+
ensureWindowFor(ptr);
|
|
161
|
+
return jsi::BigInt::fromUint64(*jsRuntime, ptr);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
void _emval_register_symbol(const char* value) {
|
|
167
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_register_symbol").call(
|
|
168
|
+
*jsRuntime,
|
|
169
|
+
Bugra<const char*>::toValue(value)
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
void _emval_incref(EM_VAL value) {
|
|
174
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_incref").call(
|
|
175
|
+
*jsRuntime,
|
|
176
|
+
Bugra<EM_VAL>::toValue(value)
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
void _emval_decref(EM_VAL value) {
|
|
180
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_decref").call(
|
|
181
|
+
*jsRuntime,
|
|
182
|
+
Bugra<EM_VAL>::toValue(value)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
void _emval_run_destructors(EM_DESTRUCTORS handle) {
|
|
186
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_run_destructors").call(
|
|
187
|
+
*jsRuntime,
|
|
188
|
+
Bugra<EM_DESTRUCTORS>::toValue(handle)
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
EM_VAL _emval_new_array() {
|
|
192
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_new_array").call(
|
|
193
|
+
*jsRuntime
|
|
194
|
+
);
|
|
195
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
196
|
+
}
|
|
197
|
+
EM_VAL _emval_new_array_from_memory_view(EM_VAL mv) {
|
|
198
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_new_array_from_memory_view").call(
|
|
199
|
+
*jsRuntime,
|
|
200
|
+
Bugra<EM_VAL>::toValue(mv)
|
|
201
|
+
);
|
|
202
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
203
|
+
}
|
|
204
|
+
EM_VAL _emval_new_object() {
|
|
205
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_new_object").call(
|
|
206
|
+
*jsRuntime
|
|
207
|
+
);
|
|
208
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
209
|
+
}
|
|
210
|
+
EM_VAL _emval_new_cstring(const char* value) {
|
|
211
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_new_cstring").call(
|
|
212
|
+
*jsRuntime,
|
|
213
|
+
Bugra<const char*>::toValue(value)
|
|
214
|
+
);
|
|
215
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
216
|
+
}
|
|
217
|
+
EM_VAL _emval_new_u8string(const char* value) {
|
|
218
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_new_u8string").call(
|
|
219
|
+
*jsRuntime,
|
|
220
|
+
Bugra<const char*>::toValue(value)
|
|
221
|
+
);
|
|
222
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
223
|
+
}
|
|
224
|
+
// EM_VAL _emval_new_u16string(const char16_t*) {}
|
|
225
|
+
EM_VAL _emval_take_value(TYPEID type, EM_VAR_ARGS argv) {
|
|
226
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_take_value").call(
|
|
227
|
+
*jsRuntime,
|
|
228
|
+
Bugra<TYPEID>::toValue(type),
|
|
229
|
+
Bugra<EM_VAR_ARGS>::toValue(argv)
|
|
230
|
+
);
|
|
231
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
232
|
+
}
|
|
233
|
+
EM_VAL _emval_new(EM_VAL value, unsigned argCount, const TYPEID argTypes[], EM_VAR_ARGS argv) {
|
|
234
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_new").call(
|
|
235
|
+
*jsRuntime,
|
|
236
|
+
Bugra<EM_VAL>::toValue(value),
|
|
237
|
+
Bugra<unsigned>::toValue(argCount),
|
|
238
|
+
Bugra<TYPEID>::toArrayValue(std::vector<TYPEID>(argTypes, argTypes + argCount)),
|
|
239
|
+
Bugra<EM_VAR_ARGS>::toValue(argv)
|
|
240
|
+
);
|
|
241
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
242
|
+
}
|
|
243
|
+
EM_VAL _emval_get_global(const char* name) {
|
|
244
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_get_global").call(
|
|
245
|
+
*jsRuntime,
|
|
246
|
+
Bugra<const char*>::toValue(name)
|
|
247
|
+
);
|
|
248
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
249
|
+
}
|
|
250
|
+
EM_VAL _emval_get_module_property(const char* name) {
|
|
251
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_get_module_property").call(
|
|
252
|
+
*jsRuntime,
|
|
253
|
+
Bugra<const char*>::toValue(name)
|
|
254
|
+
);
|
|
255
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
256
|
+
}
|
|
257
|
+
EM_VAL _emval_get_property(EM_VAL object, EM_VAL key) {
|
|
258
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_get_property").call(
|
|
259
|
+
*jsRuntime,
|
|
260
|
+
Bugra<EM_VAL>::toValue(object),
|
|
261
|
+
Bugra<EM_VAL>::toValue(key)
|
|
262
|
+
);
|
|
263
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
264
|
+
}
|
|
265
|
+
void _emval_set_property(EM_VAL object, EM_VAL key, EM_VAL value) {
|
|
266
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_set_property").call(
|
|
267
|
+
*jsRuntime,
|
|
268
|
+
Bugra<EM_VAL>::toValue(object),
|
|
269
|
+
Bugra<EM_VAL>::toValue(key),
|
|
270
|
+
Bugra<EM_VAL>::toValue(value)
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
EM_GENERIC_WIRE_TYPE _emval_as(EM_VAL value, TYPEID returnType, EM_DESTRUCTORS* destructors) {
|
|
274
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_as").call(
|
|
275
|
+
*jsRuntime,
|
|
276
|
+
Bugra<EM_VAL>::toValue(value),
|
|
277
|
+
Bugra<TYPEID>::toValue(returnType),
|
|
278
|
+
Bugra<EM_DESTRUCTORS*>::toValue(destructors)
|
|
279
|
+
);
|
|
280
|
+
return response;
|
|
281
|
+
}
|
|
282
|
+
int64_t _emval_as_int64(EM_VAL value, TYPEID returnType) {
|
|
283
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_as_int64").call(
|
|
284
|
+
*jsRuntime,
|
|
285
|
+
Bugra<EM_VAL>::toValue(value),
|
|
286
|
+
Bugra<TYPEID>::toValue(returnType)
|
|
287
|
+
);
|
|
288
|
+
return Bugra<int64_t>::fromValue(response);
|
|
289
|
+
}
|
|
290
|
+
uint64_t _emval_as_uint64(EM_VAL value, TYPEID returnType) {
|
|
291
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_as_uint64").call(
|
|
292
|
+
*jsRuntime,
|
|
293
|
+
Bugra<EM_VAL>::toValue(value),
|
|
294
|
+
Bugra<TYPEID>::toValue(returnType)
|
|
295
|
+
);
|
|
296
|
+
return Bugra<uint64_t>::fromValue(response);
|
|
297
|
+
}
|
|
298
|
+
bool _emval_equals(EM_VAL first, EM_VAL second) {
|
|
299
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_equals").call(
|
|
300
|
+
*jsRuntime,
|
|
301
|
+
Bugra<EM_VAL>::toValue(first),
|
|
302
|
+
Bugra<EM_VAL>::toValue(second)
|
|
303
|
+
);
|
|
304
|
+
return Bugra<bool>::fromValue(response);
|
|
305
|
+
}
|
|
306
|
+
bool _emval_strictly_equals(EM_VAL first, EM_VAL second) {
|
|
307
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_strictly_equals").call(
|
|
308
|
+
*jsRuntime,
|
|
309
|
+
Bugra<EM_VAL>::toValue(first),
|
|
310
|
+
Bugra<EM_VAL>::toValue(second)
|
|
311
|
+
);
|
|
312
|
+
return Bugra<bool>::fromValue(response);
|
|
313
|
+
}
|
|
314
|
+
bool _emval_greater_than(EM_VAL first, EM_VAL second) {
|
|
315
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_greater_than").call(
|
|
316
|
+
*jsRuntime,
|
|
317
|
+
Bugra<EM_VAL>::toValue(first),
|
|
318
|
+
Bugra<EM_VAL>::toValue(second)
|
|
319
|
+
);
|
|
320
|
+
return Bugra<bool>::fromValue(response);
|
|
321
|
+
}
|
|
322
|
+
bool _emval_less_than(EM_VAL first, EM_VAL second) {
|
|
323
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_less_than").call(
|
|
324
|
+
*jsRuntime,
|
|
325
|
+
Bugra<EM_VAL>::toValue(first),
|
|
326
|
+
Bugra<EM_VAL>::toValue(second)
|
|
327
|
+
);
|
|
328
|
+
return Bugra<bool>::fromValue(response);
|
|
329
|
+
}
|
|
330
|
+
bool _emval_not(EM_VAL object) {
|
|
331
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_not").call(
|
|
332
|
+
*jsRuntime,
|
|
333
|
+
Bugra<EM_VAL>::toValue(object)
|
|
334
|
+
);
|
|
335
|
+
return Bugra<bool>::fromValue(response);
|
|
336
|
+
}
|
|
337
|
+
EM_VAL _emval_call(EM_VAL value, unsigned argCount, const TYPEID argTypes[], EM_VAR_ARGS argv) {
|
|
338
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_call").call(
|
|
339
|
+
*jsRuntime,
|
|
340
|
+
Bugra<EM_VAL>::toValue(value),
|
|
341
|
+
Bugra<unsigned>::toValue(argCount),
|
|
342
|
+
Bugra<TYPEID>::toArrayValue(std::vector<TYPEID>(argTypes, argTypes + argCount)),
|
|
343
|
+
Bugra<EM_VAR_ARGS>::toValue(argv)
|
|
344
|
+
);
|
|
345
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
346
|
+
}
|
|
347
|
+
EM_METHOD_CALLER _emval_get_method_caller(unsigned argCount, const TYPEID argTypes[]) {
|
|
348
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_get_method_caller").call(
|
|
349
|
+
*jsRuntime,
|
|
350
|
+
Bugra<unsigned>::toValue(argCount),
|
|
351
|
+
Bugra<TYPEID>::toArrayValue(std::vector<TYPEID>(argTypes, argTypes + argCount))
|
|
352
|
+
);
|
|
353
|
+
return Bugra<EM_METHOD_CALLER>::fromValue(response);
|
|
354
|
+
}
|
|
355
|
+
EM_GENERIC_WIRE_TYPE _emval_call_method(EM_METHOD_CALLER caller, EM_VAL handle, const char* methodName, EM_DESTRUCTORS* destructors, EM_VAR_ARGS argv) {
|
|
356
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_call_method").call(
|
|
357
|
+
*jsRuntime,
|
|
358
|
+
Bugra<EM_METHOD_CALLER>::toValue(caller),
|
|
359
|
+
Bugra<EM_VAL>::toValue(handle),
|
|
360
|
+
Bugra<const char*>::toValue(methodName),
|
|
361
|
+
Bugra<EM_DESTRUCTORS*>::toValue(destructors),
|
|
362
|
+
Bugra<EM_VAR_ARGS>::toValue(argv)
|
|
363
|
+
);
|
|
364
|
+
return response;
|
|
365
|
+
}
|
|
366
|
+
void _emval_call_void_method(EM_METHOD_CALLER caller, EM_VAL handle, const char* methodName, EM_VAR_ARGS argv) {
|
|
367
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_call_void_method").call(
|
|
368
|
+
*jsRuntime,
|
|
369
|
+
Bugra<EM_METHOD_CALLER>::toValue(caller),
|
|
370
|
+
Bugra<EM_VAL>::toValue(handle),
|
|
371
|
+
Bugra<const char*>::toValue(methodName),
|
|
372
|
+
Bugra<EM_VAR_ARGS>::toValue(argv)
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
EM_VAL _emval_typeof(EM_VAL value) {
|
|
376
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_typeof").call(
|
|
377
|
+
*jsRuntime,
|
|
378
|
+
Bugra<EM_VAL>::toValue(value)
|
|
379
|
+
);
|
|
380
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
381
|
+
}
|
|
382
|
+
bool _emval_instanceof(EM_VAL object, EM_VAL constructor) {
|
|
383
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_instanceof").call(
|
|
384
|
+
*jsRuntime,
|
|
385
|
+
Bugra<EM_VAL>::toValue(object),
|
|
386
|
+
Bugra<EM_VAL>::toValue(constructor)
|
|
387
|
+
);
|
|
388
|
+
return Bugra<bool>::fromValue(response);
|
|
389
|
+
}
|
|
390
|
+
bool _emval_is_number(EM_VAL object) {
|
|
391
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_is_number").call(
|
|
392
|
+
*jsRuntime,
|
|
393
|
+
Bugra<EM_VAL>::toValue(object)
|
|
394
|
+
);
|
|
395
|
+
return Bugra<bool>::fromValue(response);
|
|
396
|
+
}
|
|
397
|
+
bool _emval_is_string(EM_VAL object) {
|
|
398
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_is_string").call(
|
|
399
|
+
*jsRuntime,
|
|
400
|
+
Bugra<EM_VAL>::toValue(object)
|
|
401
|
+
);
|
|
402
|
+
return Bugra<bool>::fromValue(response);
|
|
403
|
+
}
|
|
404
|
+
bool _emval_in(EM_VAL item, EM_VAL object) {
|
|
405
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_in").call(
|
|
406
|
+
*jsRuntime,
|
|
407
|
+
Bugra<EM_VAL>::toValue(item),
|
|
408
|
+
Bugra<EM_VAL>::toValue(object)
|
|
409
|
+
);
|
|
410
|
+
return Bugra<bool>::fromValue(response);
|
|
411
|
+
}
|
|
412
|
+
bool _emval_delete(EM_VAL object, EM_VAL property) {
|
|
413
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_delete").call(
|
|
414
|
+
*jsRuntime,
|
|
415
|
+
Bugra<EM_VAL>::toValue(object),
|
|
416
|
+
Bugra<EM_VAL>::toValue(property)
|
|
417
|
+
);
|
|
418
|
+
return Bugra<bool>::fromValue(response);
|
|
419
|
+
}
|
|
420
|
+
bool _emval_throw(EM_VAL object) {
|
|
421
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__emval_throw").call(
|
|
422
|
+
*jsRuntime,
|
|
423
|
+
Bugra<EM_VAL>::toValue(object)
|
|
424
|
+
);
|
|
425
|
+
// __emval_throw always throws in JS, so control never returns here; tell the
|
|
426
|
+
// compiler so this [[noreturn]] bool function has no fall-through return path.
|
|
427
|
+
__builtin_unreachable();
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
void _embind_register_void(TYPEID voidType, const char *name) {
|
|
432
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_void").call(
|
|
433
|
+
*jsRuntime,
|
|
434
|
+
Bugra<TYPEID>::toValue(voidType),
|
|
435
|
+
Bugra<const char*>::toValue(name)
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
void _embind_register_jsiValue(TYPEID jsiValueType, const char *name) {
|
|
440
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_jsiValue").call(
|
|
441
|
+
*jsRuntime,
|
|
442
|
+
Bugra<TYPEID>::toValue(jsiValueType),
|
|
443
|
+
Bugra<const char*>::toValue(name)
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
void _embind_register_bool(TYPEID boolType, const char *name, size_t size, bool trueValue,
|
|
448
|
+
bool falseValue) {
|
|
449
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_bool").call(
|
|
450
|
+
*jsRuntime,
|
|
451
|
+
Bugra<TYPEID>::toValue(boolType),
|
|
452
|
+
Bugra<const char*>::toValue(name),
|
|
453
|
+
Bugra<int32_t>::toValue((int32_t) size),
|
|
454
|
+
Bugra<bool>::toValue(trueValue),
|
|
455
|
+
Bugra<bool>::toValue(falseValue)
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/* template <typename... Things>
|
|
460
|
+
void printVariadic(Things... things) {
|
|
461
|
+
for(const auto p : {things...}) {
|
|
462
|
+
uint64_t a = reinterpret_cast<uint64_t>(&p.type());
|
|
463
|
+
int z = std::any_cast<int>(p);
|
|
464
|
+
int r = 2;
|
|
465
|
+
|
|
466
|
+
}
|
|
467
|
+
} */
|
|
468
|
+
|
|
469
|
+
void _embind_register_integer(TYPEID integerType, const char *name, size_t size,
|
|
470
|
+
int32_t minRange, uint32_t maxRange) {
|
|
471
|
+
// uint64_t z = reinterpret_cast<uint64_t>(integerType);
|
|
472
|
+
// printVariadic(std::any(integerType), std::any(name), std::any(size), std::any(minRange), std::any(maxRange));
|
|
473
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_integer").call(
|
|
474
|
+
*jsRuntime,
|
|
475
|
+
Bugra<TYPEID>::toValue(integerType),
|
|
476
|
+
Bugra<const char*>::toValue(name),
|
|
477
|
+
Bugra<int32_t>::toValue((int32_t) size),
|
|
478
|
+
Bugra<int32_t>::toValue(minRange),
|
|
479
|
+
Bugra<uint32_t>::toValue(maxRange)
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
void
|
|
484
|
+
_embind_register_bigint(TYPEID integerType, const char *name, size_t size, int64_t minRange,
|
|
485
|
+
uint64_t maxRange) {
|
|
486
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_bigint").call(
|
|
487
|
+
*jsRuntime,
|
|
488
|
+
Bugra<TYPEID>::toValue(integerType),
|
|
489
|
+
Bugra<const char*>::toValue(name),
|
|
490
|
+
Bugra<uint64_t>::toValue((uint64_t) size),
|
|
491
|
+
Bugra<int64_t>::toValue(minRange),
|
|
492
|
+
Bugra<uint64_t>::toValue(maxRange)
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
void _embind_register_float(TYPEID floatType, const char *name, size_t size) {
|
|
497
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_float").call(
|
|
498
|
+
*jsRuntime,
|
|
499
|
+
Bugra<TYPEID>::toValue(floatType),
|
|
500
|
+
Bugra<const char*>::toValue(name),
|
|
501
|
+
Bugra<int32_t>::toValue((int32_t) size)
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
void _embind_register_std_string(TYPEID stringType, const char *name) {
|
|
506
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_std_string").call(
|
|
507
|
+
*jsRuntime,
|
|
508
|
+
Bugra<TYPEID>::toValue(stringType),
|
|
509
|
+
Bugra<const char*>::toValue(name)
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
void _embind_register_std_wstring(TYPEID stringType, size_t charSize, const char *name) {
|
|
514
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_std_wstring").call(
|
|
515
|
+
*jsRuntime,
|
|
516
|
+
Bugra<TYPEID>::toValue(stringType),
|
|
517
|
+
Bugra<int32_t>::toValue((int32_t) charSize),
|
|
518
|
+
Bugra<const char*>::toValue(name)
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
void _embind_register_emval(TYPEID emvalType, const char *name) {
|
|
523
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_emval").call(
|
|
524
|
+
*jsRuntime,
|
|
525
|
+
Bugra<TYPEID>::toValue(emvalType),
|
|
526
|
+
Bugra<const char*>::toValue(name)
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
void _embind_register_memory_view(TYPEID memoryViewType, unsigned int typedArrayIndex,
|
|
531
|
+
const char *name) {
|
|
532
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_memory_view").call(
|
|
533
|
+
*jsRuntime,
|
|
534
|
+
Bugra<TYPEID>::toValue(memoryViewType),
|
|
535
|
+
Bugra<uint32_t>::toValue(typedArrayIndex),
|
|
536
|
+
Bugra<const char*>::toValue(name)
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
void _embind_register_function(
|
|
541
|
+
const char *name,
|
|
542
|
+
unsigned argCount,
|
|
543
|
+
const TYPEID argTypes[],
|
|
544
|
+
const char *signature,
|
|
545
|
+
facebook::jsi::Function& invoker,
|
|
546
|
+
GenericFunction function,
|
|
547
|
+
bool isAsync) {
|
|
548
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_function").call(
|
|
549
|
+
*jsRuntime,
|
|
550
|
+
Bugra<const char*>::toValue(name),
|
|
551
|
+
Bugra<int32_t>::toValue(argCount),
|
|
552
|
+
Bugra<TYPEID>::toArrayValue(std::vector<TYPEID>(argTypes, argTypes + argCount)),
|
|
553
|
+
Bugra<const char*>::toValue(signature),
|
|
554
|
+
invoker,
|
|
555
|
+
Bugra<GenericFunction>::toValue(function),
|
|
556
|
+
Bugra<bool>::toValue(isAsync)
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
void _embind_register_optional(TYPEID optionalType, TYPEID type) {
|
|
561
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_optional").call(
|
|
562
|
+
*jsRuntime,
|
|
563
|
+
Bugra<TYPEID>::toValue(optionalType),
|
|
564
|
+
Bugra<TYPEID>::toValue(type)
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
void _embind_register_value_array(
|
|
569
|
+
TYPEID tupleType,
|
|
570
|
+
const char *name,
|
|
571
|
+
const char *constructorSignature,
|
|
572
|
+
facebook::jsi::Function& constructor,
|
|
573
|
+
const char *destructorSignature,
|
|
574
|
+
facebook::jsi::Function& destructor) {
|
|
575
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_value_array").call(
|
|
576
|
+
*jsRuntime,
|
|
577
|
+
Bugra<TYPEID>::toValue(tupleType),
|
|
578
|
+
Bugra<const char*>::toValue(name),
|
|
579
|
+
Bugra<const char*>::toValue(constructorSignature),
|
|
580
|
+
constructor,
|
|
581
|
+
Bugra<const char*>::toValue(destructorSignature),
|
|
582
|
+
destructor
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
void _embind_register_value_array_element(
|
|
587
|
+
TYPEID tupleType,
|
|
588
|
+
TYPEID getterReturnType,
|
|
589
|
+
const char *getterSignature,
|
|
590
|
+
facebook::jsi::Function& getter,
|
|
591
|
+
void *getterContext,
|
|
592
|
+
TYPEID setterArgumentType,
|
|
593
|
+
const char *setterSignature,
|
|
594
|
+
facebook::jsi::Function& setter,
|
|
595
|
+
void *setterContext) {
|
|
596
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_value_array_element").call(
|
|
597
|
+
*jsRuntime,
|
|
598
|
+
Bugra<TYPEID>::toValue(tupleType),
|
|
599
|
+
Bugra<TYPEID>::toValue(getterReturnType),
|
|
600
|
+
Bugra<const char*>::toValue(getterSignature),
|
|
601
|
+
getter,
|
|
602
|
+
Bugra<GenericFunction>::toValue(getterContext),
|
|
603
|
+
Bugra<TYPEID>::toValue(setterArgumentType),
|
|
604
|
+
Bugra<const char*>::toValue(setterSignature),
|
|
605
|
+
setter,
|
|
606
|
+
Bugra<GenericFunction>::toValue(setterContext)
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
void _embind_finalize_value_array(TYPEID tupleType) {
|
|
611
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_finalize_value_array").call(
|
|
612
|
+
*jsRuntime,
|
|
613
|
+
Bugra<TYPEID>::toValue(tupleType)
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
void _embind_register_value_object(
|
|
618
|
+
TYPEID structType,
|
|
619
|
+
const char *fieldName,
|
|
620
|
+
const char *constructorSignature,
|
|
621
|
+
facebook::jsi::Function& constructor,
|
|
622
|
+
const char *destructorSignature,
|
|
623
|
+
facebook::jsi::Function& destructor) {
|
|
624
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_value_object").call(
|
|
625
|
+
*jsRuntime,
|
|
626
|
+
Bugra<TYPEID>::toValue(structType),
|
|
627
|
+
Bugra<const char*>::toValue(fieldName),
|
|
628
|
+
Bugra<const char*>::toValue(constructorSignature),
|
|
629
|
+
constructor,
|
|
630
|
+
Bugra<const char*>::toValue(destructorSignature),
|
|
631
|
+
destructor
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
void _embind_register_value_object_field(
|
|
636
|
+
TYPEID structType,
|
|
637
|
+
const char *fieldName,
|
|
638
|
+
TYPEID getterReturnType,
|
|
639
|
+
const char *getterSignature,
|
|
640
|
+
facebook::jsi::Function& getter,
|
|
641
|
+
void *getterContext,
|
|
642
|
+
TYPEID setterArgumentType,
|
|
643
|
+
const char *setterSignature,
|
|
644
|
+
facebook::jsi::Function& setter,
|
|
645
|
+
void *setterContext) {
|
|
646
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_value_object_field").call(
|
|
647
|
+
*jsRuntime,
|
|
648
|
+
Bugra<TYPEID>::toValue(structType),
|
|
649
|
+
Bugra<const char*>::toValue(fieldName),
|
|
650
|
+
Bugra<TYPEID>::toValue(getterReturnType),
|
|
651
|
+
Bugra<const char*>::toValue(getterSignature),
|
|
652
|
+
getter,
|
|
653
|
+
Bugra<GenericFunction>::toValue(getterContext),
|
|
654
|
+
Bugra<TYPEID>::toValue(setterArgumentType),
|
|
655
|
+
Bugra<const char*>::toValue(setterSignature),
|
|
656
|
+
setter,
|
|
657
|
+
Bugra<GenericFunction>::toValue(setterContext)
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
void _embind_finalize_value_object(TYPEID structType) {
|
|
662
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_finalize_value_object").call(
|
|
663
|
+
*jsRuntime,
|
|
664
|
+
Bugra<TYPEID>::toValue(structType)
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
void _embind_register_class(
|
|
669
|
+
TYPEID classType,
|
|
670
|
+
TYPEID pointerType,
|
|
671
|
+
TYPEID constPointerType,
|
|
672
|
+
TYPEID baseClassType,
|
|
673
|
+
const char *getActualTypeSignature,
|
|
674
|
+
facebook::jsi::Function& getActualType,
|
|
675
|
+
const char *upcastSignature,
|
|
676
|
+
facebook::jsi::Function& upcast,
|
|
677
|
+
const char *downcastSignature,
|
|
678
|
+
facebook::jsi::Function& downcast,
|
|
679
|
+
const char *className,
|
|
680
|
+
const char *destructorSignature,
|
|
681
|
+
facebook::jsi::Function& destructor) {
|
|
682
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_class").call(
|
|
683
|
+
*jsRuntime,
|
|
684
|
+
Bugra<TYPEID>::toValue(classType),
|
|
685
|
+
Bugra<TYPEID>::toValue(pointerType),
|
|
686
|
+
Bugra<TYPEID>::toValue(constPointerType),
|
|
687
|
+
Bugra<TYPEID>::toValue(baseClassType),
|
|
688
|
+
Bugra<const char*>::toValue(getActualTypeSignature),
|
|
689
|
+
getActualType,
|
|
690
|
+
Bugra<const char*>::toValue(upcastSignature),
|
|
691
|
+
upcast,
|
|
692
|
+
Bugra<const char*>::toValue(downcastSignature),
|
|
693
|
+
downcast,
|
|
694
|
+
Bugra<const char*>::toValue(className),
|
|
695
|
+
Bugra<const char*>::toValue(destructorSignature),
|
|
696
|
+
destructor
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
void _embind_register_class_constructor(
|
|
701
|
+
TYPEID classType,
|
|
702
|
+
unsigned argCount,
|
|
703
|
+
const TYPEID argTypes[],
|
|
704
|
+
const char *invokerSignature,
|
|
705
|
+
facebook::jsi::Function& invoker,
|
|
706
|
+
GenericFunction constructor) {
|
|
707
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_class_constructor").call(
|
|
708
|
+
*jsRuntime,
|
|
709
|
+
Bugra<TYPEID>::toValue(classType),
|
|
710
|
+
Bugra<int32_t>::toValue(argCount),
|
|
711
|
+
Bugra<TYPEID>::toArrayValue(std::vector<TYPEID>(argTypes, argTypes + argCount)),
|
|
712
|
+
Bugra<const char*>::toValue(invokerSignature),
|
|
713
|
+
invoker,
|
|
714
|
+
Bugra<GenericFunction>::toValue(constructor)
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
void _embind_register_class_function(
|
|
719
|
+
TYPEID classType,
|
|
720
|
+
const char *methodName,
|
|
721
|
+
unsigned argCount,
|
|
722
|
+
const TYPEID argTypes[],
|
|
723
|
+
const char *invokerSignature,
|
|
724
|
+
facebook::jsi::Function& invoker,
|
|
725
|
+
void *context,
|
|
726
|
+
unsigned isPureVirtual,
|
|
727
|
+
bool isAsync) {
|
|
728
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_class_function").call(
|
|
729
|
+
*jsRuntime,
|
|
730
|
+
Bugra<TYPEID>::toValue(classType),
|
|
731
|
+
Bugra<const char*>::toValue(methodName),
|
|
732
|
+
Bugra<int32_t>::toValue(argCount),
|
|
733
|
+
Bugra<TYPEID>::toArrayValue(std::vector<TYPEID>(argTypes, argTypes + argCount)),
|
|
734
|
+
Bugra<const char*>::toValue(invokerSignature),
|
|
735
|
+
invoker,
|
|
736
|
+
Bugra<GenericFunction>::toValue(context),
|
|
737
|
+
Bugra<int32_t>::toValue(isPureVirtual),
|
|
738
|
+
Bugra<bool>::toValue(isAsync)
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
void _embind_register_class_property(
|
|
743
|
+
TYPEID classType,
|
|
744
|
+
const char *fieldName,
|
|
745
|
+
TYPEID getterReturnType,
|
|
746
|
+
const char *getterSignature,
|
|
747
|
+
facebook::jsi::Function& getter,
|
|
748
|
+
void *getterContext,
|
|
749
|
+
TYPEID setterArgumentType,
|
|
750
|
+
const char *setterSignature,
|
|
751
|
+
facebook::jsi::Function& setter,
|
|
752
|
+
void *setterContext) {
|
|
753
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_class_property").call(
|
|
754
|
+
*jsRuntime,
|
|
755
|
+
Bugra<TYPEID>::toValue(classType),
|
|
756
|
+
Bugra<const char*>::toValue(fieldName),
|
|
757
|
+
Bugra<TYPEID>::toValue(getterReturnType),
|
|
758
|
+
Bugra<const char*>::toValue(getterSignature),
|
|
759
|
+
getter,
|
|
760
|
+
Bugra<GenericFunction>::toValue(getterContext),
|
|
761
|
+
Bugra<TYPEID>::toValue(setterArgumentType),
|
|
762
|
+
Bugra<const char*>::toValue(setterSignature),
|
|
763
|
+
setter,
|
|
764
|
+
Bugra<GenericFunction>::toValue(setterContext)
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
void _embind_register_class_class_function(
|
|
769
|
+
TYPEID classType,
|
|
770
|
+
const char *methodName,
|
|
771
|
+
unsigned argCount,
|
|
772
|
+
const TYPEID argTypes[],
|
|
773
|
+
const char *invokerSignature,
|
|
774
|
+
facebook::jsi::Function& invoker,
|
|
775
|
+
GenericFunction method,
|
|
776
|
+
bool isAsync) {
|
|
777
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_class_class_function").call(
|
|
778
|
+
*jsRuntime,
|
|
779
|
+
Bugra<TYPEID>::toValue(classType),
|
|
780
|
+
Bugra<const char*>::toValue(methodName),
|
|
781
|
+
Bugra<int32_t>::toValue(argCount),
|
|
782
|
+
Bugra<TYPEID>::toArrayValue(std::vector<TYPEID>(argTypes, argTypes + argCount)),
|
|
783
|
+
Bugra<const char*>::toValue(invokerSignature),
|
|
784
|
+
invoker,
|
|
785
|
+
Bugra<GenericFunction>::toValue(method),
|
|
786
|
+
Bugra<bool>::toValue(isAsync)
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
void _embind_register_class_class_property(
|
|
791
|
+
TYPEID classType,
|
|
792
|
+
const char *fieldName,
|
|
793
|
+
TYPEID fieldType,
|
|
794
|
+
void *fieldContext,
|
|
795
|
+
const char *getterSignature,
|
|
796
|
+
facebook::jsi::Function& getter,
|
|
797
|
+
const char *setterSignature,
|
|
798
|
+
facebook::jsi::Function& setter) {
|
|
799
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_class_class_property").call(
|
|
800
|
+
*jsRuntime,
|
|
801
|
+
Bugra<TYPEID>::toValue(classType),
|
|
802
|
+
Bugra<const char*>::toValue(fieldName),
|
|
803
|
+
Bugra<TYPEID>::toValue(fieldType),
|
|
804
|
+
Bugra<GenericFunction>::toValue(fieldContext),
|
|
805
|
+
Bugra<const char*>::toValue(getterSignature),
|
|
806
|
+
getter,
|
|
807
|
+
Bugra<const char*>::toValue(setterSignature),
|
|
808
|
+
setter
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
EM_VAL _embind_create_inheriting_constructor(
|
|
813
|
+
const char *constructorName,
|
|
814
|
+
TYPEID wrapperType,
|
|
815
|
+
EM_VAL properties) {
|
|
816
|
+
auto response = jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_create_inheriting_constructor").call(
|
|
817
|
+
*jsRuntime,
|
|
818
|
+
Bugra<const char*>::toValue(constructorName),
|
|
819
|
+
Bugra<TYPEID>::toValue(wrapperType),
|
|
820
|
+
Bugra<EM_VAL>::toValue(properties)
|
|
821
|
+
);
|
|
822
|
+
return Bugra<EM_VAL>::fromValue(response);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
void _embind_register_enum(
|
|
826
|
+
TYPEID enumType,
|
|
827
|
+
const char *name,
|
|
828
|
+
size_t size,
|
|
829
|
+
bool isSigned) {
|
|
830
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_enum").call(
|
|
831
|
+
*jsRuntime,
|
|
832
|
+
Bugra<TYPEID>::toValue(enumType),
|
|
833
|
+
Bugra<const char*>::toValue(name),
|
|
834
|
+
Bugra<int32_t>::toValue((int32_t) size),
|
|
835
|
+
Bugra<bool>::toValue(isSigned)
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
void _embind_register_smart_ptr(
|
|
840
|
+
TYPEID pointerType,
|
|
841
|
+
TYPEID pointeeType,
|
|
842
|
+
const char *pointerName,
|
|
843
|
+
sharing_policy sharingPolicy,
|
|
844
|
+
const char *getPointeeSignature,
|
|
845
|
+
facebook::jsi::Function& getPointee,
|
|
846
|
+
const char *constructorSignature,
|
|
847
|
+
facebook::jsi::Function& constructor,
|
|
848
|
+
const char *shareSignature,
|
|
849
|
+
facebook::jsi::Function& share,
|
|
850
|
+
const char *destructorSignature,
|
|
851
|
+
facebook::jsi::Function& destructor) {
|
|
852
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_smart_ptr").call(
|
|
853
|
+
*jsRuntime,
|
|
854
|
+
Bugra<TYPEID>::toValue(pointerType),
|
|
855
|
+
Bugra<TYPEID>::toValue(pointeeType),
|
|
856
|
+
Bugra<const char*>::toValue(pointerName),
|
|
857
|
+
Bugra<uint32_t>::toValue((uint32_t) sharingPolicy),
|
|
858
|
+
Bugra<const char*>::toValue(getPointeeSignature),
|
|
859
|
+
getPointee,
|
|
860
|
+
Bugra<const char*>::toValue(constructorSignature),
|
|
861
|
+
constructor,
|
|
862
|
+
Bugra<const char*>::toValue(shareSignature),
|
|
863
|
+
share,
|
|
864
|
+
Bugra<const char*>::toValue(destructorSignature),
|
|
865
|
+
destructor);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
void _embind_register_enum_value(
|
|
869
|
+
TYPEID enumType,
|
|
870
|
+
const char *valueName,
|
|
871
|
+
GenericEnumValue value) {
|
|
872
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_enum_value").call(
|
|
873
|
+
*jsRuntime,
|
|
874
|
+
Bugra<TYPEID>::toValue(enumType),
|
|
875
|
+
Bugra<const char*>::toValue(valueName),
|
|
876
|
+
Bugra<GenericEnumValue>::toValue(value)
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
void _embind_register_constant(
|
|
881
|
+
const char *name,
|
|
882
|
+
TYPEID constantType,
|
|
883
|
+
const facebook::jsi::Value value) {
|
|
884
|
+
jsRuntime->global().getPropertyAsFunction(*jsRuntime, "__embind_register_constant").call(
|
|
885
|
+
*jsRuntime,
|
|
886
|
+
Bugra<const char*>::toValue(name),
|
|
887
|
+
Bugra<TYPEID>::toValue(constantType),
|
|
888
|
+
value
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
const char *EMSCRIPTEN_KEEPALIVE __getTypeName(const std::type_info *ti) {
|
|
893
|
+
if (has_unbound_type_names) {
|
|
894
|
+
#ifdef USE_CXA_DEMANGLE
|
|
895
|
+
int stat;
|
|
896
|
+
char* demangled = abi::__cxa_demangle(ti->name(), NULL, NULL, &stat);
|
|
897
|
+
if (stat == 0 && demangled) {
|
|
898
|
+
return demangled;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
switch (stat) {
|
|
902
|
+
case -1:
|
|
903
|
+
return strdup("<allocation failure>");
|
|
904
|
+
case -2:
|
|
905
|
+
return strdup("<invalid C++ symbol>");
|
|
906
|
+
case -3:
|
|
907
|
+
return strdup("<invalid argument>");
|
|
908
|
+
default:
|
|
909
|
+
return strdup("<unknown error>");
|
|
910
|
+
}
|
|
911
|
+
#else
|
|
912
|
+
return strdup(ti->name());
|
|
913
|
+
#endif
|
|
914
|
+
} else {
|
|
915
|
+
char str[80];
|
|
916
|
+
sprintf(str, "%p", reinterpret_cast<const void *>(ti));
|
|
917
|
+
return strdup(str);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
static InitFunc *init_funcs = nullptr;
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
struct FixedBuffer : facebook::jsi::MutableBuffer {
|
|
925
|
+
FixedBuffer(uint64_t offset) : offset(offset) {}
|
|
926
|
+
|
|
927
|
+
size_t size() const override {
|
|
928
|
+
return UINT32_MAX;
|
|
929
|
+
}
|
|
930
|
+
uint8_t *data() override {
|
|
931
|
+
return reinterpret_cast<uint8_t *>(offset);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
int r = 3;
|
|
935
|
+
uint64_t offset;
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
// Tracks every heap window currently exposed to JS. Single-threaded
|
|
939
|
+
// access assumed (all JSI traffic flows through the JS thread today).
|
|
940
|
+
static std::vector<uint64_t> registeredOffsets;
|
|
941
|
+
|
|
942
|
+
void registerHeapWindow(uint64_t offset) {
|
|
943
|
+
auto buf = std::make_shared<FixedBuffer>(offset);
|
|
944
|
+
auto arrayBuffer = facebook::jsi::ArrayBuffer(*jsRuntime, buf);
|
|
945
|
+
jsRuntime->global()
|
|
946
|
+
.getPropertyAsFunction(*jsRuntime, "__crossbind_register_heap_window")
|
|
947
|
+
.call(*jsRuntime,
|
|
948
|
+
jsi::BigInt::fromUint64(*jsRuntime, offset),
|
|
949
|
+
arrayBuffer);
|
|
950
|
+
registeredOffsets.push_back(offset);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
void ensureWindowFor(uint64_t ptr) {
|
|
954
|
+
for (uint64_t offset : registeredOffsets) {
|
|
955
|
+
if (ptr >= offset && (ptr - offset) < UINT32_MAX) return;
|
|
956
|
+
}
|
|
957
|
+
// Center the new window on `ptr` so nearby allocations also land in it.
|
|
958
|
+
uint64_t newOffset = (ptr > UINT32_MAX / 2)
|
|
959
|
+
? (ptr - UINT32_MAX / 2)
|
|
960
|
+
: 0;
|
|
961
|
+
registerHeapWindow(newOffset);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
EMSCRIPTEN_KEEPALIVE void _embind_initialize_bindings(jsi::Runtime& rt, std::string path) {
|
|
966
|
+
CROSSBIND_DATA_PATH = path;
|
|
967
|
+
Crossbind::setEnv("CROSSBIND_DATA_PATH", path, false);
|
|
968
|
+
jsRuntime = &rt;
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
// Initial seed windows: anchored around .rodata (string literals)
|
|
972
|
+
// and the C++ heap. Additional windows are registered on demand
|
|
973
|
+
// by ensureWindowFor() as new pointer regions are exposed to JS.
|
|
974
|
+
const char* name = "M";
|
|
975
|
+
uint64_t namePtrNumber = reinterpret_cast<uint64_t>(name);
|
|
976
|
+
|
|
977
|
+
// Reference allocation to discover the heap region.
|
|
978
|
+
auto heapProbe = std::make_shared<FixedBuffer>(0);
|
|
979
|
+
uint64_t heapPtrNumber = reinterpret_cast<uint64_t>(heapProbe.get());
|
|
980
|
+
|
|
981
|
+
uint64_t offsetRodataLow = (namePtrNumber > UINT32_MAX)
|
|
982
|
+
? (namePtrNumber - UINT32_MAX) : 0;
|
|
983
|
+
uint64_t offsetHeapLow = (heapPtrNumber > UINT32_MAX)
|
|
984
|
+
? (heapPtrNumber - UINT32_MAX) : 0;
|
|
985
|
+
uint64_t offsetRodataLowest = (offsetRodataLow > UINT32_MAX)
|
|
986
|
+
? (offsetRodataLow - UINT32_MAX) : 0;
|
|
987
|
+
uint64_t offsetRodataHigh = namePtrNumber;
|
|
988
|
+
|
|
989
|
+
registerHeapWindow(offsetRodataLow);
|
|
990
|
+
registerHeapWindow(offsetHeapLow);
|
|
991
|
+
registerHeapWindow(offsetRodataLowest);
|
|
992
|
+
registerHeapWindow(offsetRodataHigh);
|
|
993
|
+
|
|
994
|
+
// Self-healing fallback: when a JS-side heap read misses every window, JS calls
|
|
995
|
+
// this to open one centered on the pointer. Unconditional on purpose - JS is the
|
|
996
|
+
// source of truth about its own windows, so no native covered-check here.
|
|
997
|
+
auto ensureFn = facebook::jsi::Function::createFromHostFunction(
|
|
998
|
+
rt,
|
|
999
|
+
facebook::jsi::PropNameID::forAscii(rt, "__crossbind_ensure_heap_window"),
|
|
1000
|
+
1,
|
|
1001
|
+
[](facebook::jsi::Runtime& rt2, const facebook::jsi::Value&,
|
|
1002
|
+
const facebook::jsi::Value* args, size_t) -> facebook::jsi::Value {
|
|
1003
|
+
uint64_t p = args[0].asBigInt(rt2).asUint64(rt2);
|
|
1004
|
+
uint64_t newOffset = (p > UINT32_MAX / 2) ? (p - UINT32_MAX / 2) : 0;
|
|
1005
|
+
registerHeapWindow(newOffset);
|
|
1006
|
+
return facebook::jsi::Value::undefined();
|
|
1007
|
+
});
|
|
1008
|
+
rt.global().setProperty(rt, "__crossbind_ensure_heap_window", ensureFn);
|
|
1009
|
+
|
|
1010
|
+
for (auto *f = init_funcs; f; f = f->next) {
|
|
1011
|
+
f->init_func();
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
void _embind_register_bindings(InitFunc *f) {
|
|
1016
|
+
f->next = init_funcs;
|
|
1017
|
+
init_funcs = f;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
namespace {
|
|
1024
|
+
template <typename T> static void register_integer(const char* name) {
|
|
1025
|
+
using namespace internal;
|
|
1026
|
+
_embind_register_integer(TypeID<T>::get(), name, sizeof(T), std::numeric_limits<T>::min(),
|
|
1027
|
+
std::numeric_limits<T>::max());
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
template <typename T> static void register_bigint(const char* name) {
|
|
1031
|
+
using namespace internal;
|
|
1032
|
+
_embind_register_bigint(TypeID<T>::get(), name, sizeof(T), std::numeric_limits<T>::min(),
|
|
1033
|
+
std::numeric_limits<T>::max());
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
template <typename T> static void register_float(const char* name) {
|
|
1037
|
+
using namespace internal;
|
|
1038
|
+
_embind_register_float(TypeID<T>::get(), name, sizeof(T));
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
// matches typeMapping in embind.js
|
|
1042
|
+
enum TypedArrayIndex {
|
|
1043
|
+
Int8Array,
|
|
1044
|
+
Uint8Array,
|
|
1045
|
+
Int16Array,
|
|
1046
|
+
Uint16Array,
|
|
1047
|
+
Int32Array,
|
|
1048
|
+
Uint32Array,
|
|
1049
|
+
Float32Array,
|
|
1050
|
+
Float64Array,
|
|
1051
|
+
// Only available if WASM_BIGINT
|
|
1052
|
+
Int64Array,
|
|
1053
|
+
Uint64Array,
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
template <typename T> constexpr TypedArrayIndex getTypedArrayIndex() {
|
|
1057
|
+
static_assert(internal::typeSupportsMemoryView<T>(), "type does not map to a typed array");
|
|
1058
|
+
return std::is_floating_point<T>::value
|
|
1059
|
+
? (sizeof(T) == 4 ? Float32Array : Float64Array)
|
|
1060
|
+
: (sizeof(T) == 1
|
|
1061
|
+
? (std::is_signed<T>::value ? Int8Array : Uint8Array)
|
|
1062
|
+
: (sizeof(T) == 2 ? (std::is_signed<T>::value ? Int16Array : Uint16Array)
|
|
1063
|
+
: (sizeof(T) == 4 ? (std::is_signed<T>::value ? Int32Array : Uint32Array)
|
|
1064
|
+
: (std::is_signed<T>::value ? Int64Array : Uint64Array))));
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
template <typename T> static void register_memory_view(const char* name) {
|
|
1068
|
+
using namespace internal;
|
|
1069
|
+
_embind_register_memory_view(TypeID<memory_view<T>>::get(), getTypedArrayIndex<T>(), name);
|
|
1070
|
+
}
|
|
1071
|
+
} // namespace
|
|
1072
|
+
|
|
1073
|
+
int Crossbind::setEnv(std::string key, std::string value, bool overwrite) {
|
|
1074
|
+
return setenv(key.c_str(), value.c_str(), overwrite);
|
|
1075
|
+
}
|
|
1076
|
+
std::string Crossbind::getEnv(std::string key) {
|
|
1077
|
+
const char* value = getenv(key.c_str());
|
|
1078
|
+
// getenv returns nullptr for an unset key; constructing std::string(nullptr) is UB.
|
|
1079
|
+
return value ? std::string(value) : std::string();
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
EMSCRIPTEN_BINDINGS(builtin) {
|
|
1083
|
+
using namespace emscripten::internal;
|
|
1084
|
+
|
|
1085
|
+
_embind_register_void(TypeID<void>::get(), "void");
|
|
1086
|
+
_embind_register_jsiValue(TypeID<facebook::jsi::Value>::get(), "jsiValue");
|
|
1087
|
+
|
|
1088
|
+
_embind_register_bool(TypeID<bool>::get(), "bool", sizeof(bool), true, false);
|
|
1089
|
+
|
|
1090
|
+
register_integer<char>("char");
|
|
1091
|
+
register_integer<signed char>("signed char");
|
|
1092
|
+
register_integer<unsigned char>("unsigned char");
|
|
1093
|
+
register_integer<signed short>("short");
|
|
1094
|
+
register_integer<unsigned short>("unsigned short");
|
|
1095
|
+
register_integer<signed int>("int");
|
|
1096
|
+
register_integer<unsigned int>("unsigned int");
|
|
1097
|
+
|
|
1098
|
+
// register_bigint<signed long>("long");
|
|
1099
|
+
// register_bigint<unsigned long>("unsigned long");
|
|
1100
|
+
|
|
1101
|
+
register_bigint<int64_t>("int64_t");
|
|
1102
|
+
register_bigint<uint64_t>("uint64_t");
|
|
1103
|
+
|
|
1104
|
+
register_float<float>("float");
|
|
1105
|
+
register_float<double>("double");
|
|
1106
|
+
|
|
1107
|
+
_embind_register_std_string(TypeID<std::string>::get(), "std::string");
|
|
1108
|
+
_embind_register_std_string(
|
|
1109
|
+
TypeID<std::basic_string<unsigned char>>::get(), "std::basic_string<unsigned char>");
|
|
1110
|
+
_embind_register_std_wstring(TypeID<std::wstring>::get(), sizeof(wchar_t), "std::wstring");
|
|
1111
|
+
_embind_register_std_wstring(TypeID<std::u16string>::get(), sizeof(char16_t), "std::u16string");
|
|
1112
|
+
_embind_register_std_wstring(TypeID<std::u32string>::get(), sizeof(char32_t), "std::u32string");
|
|
1113
|
+
_embind_register_emval(TypeID<val>::get(), "emscripten::val");
|
|
1114
|
+
|
|
1115
|
+
// Some of these types are aliases for each other. Luckily,
|
|
1116
|
+
// embind.js's _embind_register_memory_view ignores duplicate
|
|
1117
|
+
// registrations rather than asserting, so the first
|
|
1118
|
+
// register_memory_view call for a particular type will take
|
|
1119
|
+
// precedence.
|
|
1120
|
+
|
|
1121
|
+
register_memory_view<char>("emscripten::memory_view<char>");
|
|
1122
|
+
register_memory_view<signed char>("emscripten::memory_view<signed char>");
|
|
1123
|
+
register_memory_view<unsigned char>("emscripten::memory_view<unsigned char>");
|
|
1124
|
+
|
|
1125
|
+
register_memory_view<short>("emscripten::memory_view<short>");
|
|
1126
|
+
register_memory_view<unsigned short>("emscripten::memory_view<unsigned short>");
|
|
1127
|
+
register_memory_view<int>("emscripten::memory_view<int>");
|
|
1128
|
+
register_memory_view<unsigned int>("emscripten::memory_view<unsigned int>");
|
|
1129
|
+
register_memory_view<long>("emscripten::memory_view<long>");
|
|
1130
|
+
register_memory_view<unsigned long>("emscripten::memory_view<unsigned long>");
|
|
1131
|
+
|
|
1132
|
+
register_memory_view<int8_t>("emscripten::memory_view<int8_t>");
|
|
1133
|
+
register_memory_view<uint8_t>("emscripten::memory_view<uint8_t>");
|
|
1134
|
+
register_memory_view<int16_t>("emscripten::memory_view<int16_t>");
|
|
1135
|
+
register_memory_view<uint16_t>("emscripten::memory_view<uint16_t>");
|
|
1136
|
+
register_memory_view<int32_t>("emscripten::memory_view<int32_t>");
|
|
1137
|
+
register_memory_view<uint32_t>("emscripten::memory_view<uint32_t>");
|
|
1138
|
+
register_memory_view<int64_t>("emscripten::memory_view<int64_t>");
|
|
1139
|
+
register_memory_view<uint64_t>("emscripten::memory_view<uint64_t>");
|
|
1140
|
+
|
|
1141
|
+
register_memory_view<float>("emscripten::memory_view<float>");
|
|
1142
|
+
register_memory_view<double>("emscripten::memory_view<double>");
|
|
1143
|
+
|
|
1144
|
+
// register_vector<bool>("BoolVector");
|
|
1145
|
+
/* register_vector<char>("CharVector");
|
|
1146
|
+
register_vector<short>("ShortVector");
|
|
1147
|
+
register_vector<int>("IntVector");
|
|
1148
|
+
register_vector<int64_t>("Int64_tVector");
|
|
1149
|
+
register_vector<float>("FloatVector");
|
|
1150
|
+
register_vector<double>("DoubleVector");
|
|
1151
|
+
register_vector<std::string>("StringVector"); */
|
|
1152
|
+
|
|
1153
|
+
class_<Crossbind>("Crossbind")
|
|
1154
|
+
.class_function("setEnv", &Crossbind::setEnv)
|
|
1155
|
+
.class_function("getEnv", &Crossbind::getEnv)
|
|
1156
|
+
;
|
|
1157
|
+
constant("CROSSBIND_DATA_PATH", CROSSBIND_DATA_PATH);
|
|
1158
|
+
}
|