@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
package/js/embind.js
ADDED
|
@@ -0,0 +1,4908 @@
|
|
|
1
|
+
function warnOnce(msg) {
|
|
2
|
+
console.warn(msg);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function callRuntimeCallbacks() { }
|
|
6
|
+
|
|
7
|
+
// include: shell.js
|
|
8
|
+
/**
|
|
9
|
+
* @license
|
|
10
|
+
* Copyright 2010 The Emscripten Authors
|
|
11
|
+
* SPDX-License-Identifier: MIT
|
|
12
|
+
*/
|
|
13
|
+
// The Module object: Our interface to the outside world. We import
|
|
14
|
+
// and export values on it. There are various ways Module can be used:
|
|
15
|
+
// 1. Not defined. We create it here
|
|
16
|
+
// 2. A function parameter, function(Module) { ..generated code.. }
|
|
17
|
+
// 3. pre-run appended it, var Module = {}; ..generated code..
|
|
18
|
+
// 4. External script tag defines var Module.
|
|
19
|
+
// We need to check if Module already exists (e.g. case 3 above).
|
|
20
|
+
// Substitution will be replaced with actual code on later stage of the build,
|
|
21
|
+
// this way Closure Compiler will not mangle it (e.g. case 4. above).
|
|
22
|
+
// Note that if you want to run closure, and also to use Module
|
|
23
|
+
// after the generated code, you will need to define var Module = {};
|
|
24
|
+
// before the code. Then that object will be used in the code, and you
|
|
25
|
+
// can continue to use Module afterwards as well.
|
|
26
|
+
globalThis.Module = typeof globalThis.Module != 'undefined' ? globalThis.Module : {};
|
|
27
|
+
|
|
28
|
+
// See https://caniuse.com/mdn-javascript_builtins_bigint64array
|
|
29
|
+
// include: polyfill/bigint64array.js
|
|
30
|
+
|
|
31
|
+
if (typeof globalThis.BigInt64Array === "undefined") {
|
|
32
|
+
// BigInt64Array polyfill for Safari versions between v14.0 and v15.0.
|
|
33
|
+
// All browsers other than Safari added BigInt and BigInt64Array at the same
|
|
34
|
+
// time, but Safari introduced BigInt in v14.0 and introduced BigInt64Array in
|
|
35
|
+
// v15.0
|
|
36
|
+
|
|
37
|
+
function partsToBigIntSigned(lower, upper) {
|
|
38
|
+
return BigInt(lower) | (BigInt(upper + 2 * (upper & 0x80000000)) << 32n);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function partsToBigIntUnsigned(lower, upper) {
|
|
42
|
+
return BigInt(lower) | (BigInt(upper) << 32n);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function bigIntToParts(value) {
|
|
46
|
+
var lower = Number(BigInt(value) & BigInt(0xffffffff)) | 0;
|
|
47
|
+
var upper = Number(BigInt(value) >> 32n) | 0;
|
|
48
|
+
return [lower, upper];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createBigIntArrayShim(partsToBigInt) {
|
|
52
|
+
function createBigInt64Array(array) {
|
|
53
|
+
if (typeof array === "number") {
|
|
54
|
+
array = new Uint32Array(2 * array);
|
|
55
|
+
}
|
|
56
|
+
var orig_array;
|
|
57
|
+
if (!ArrayBuffer.isView(array)) {
|
|
58
|
+
if (array.constructor && array.constructor.name === "ArrayBuffer") {
|
|
59
|
+
array = new Uint32Array(array);
|
|
60
|
+
} else {
|
|
61
|
+
orig_array = array;
|
|
62
|
+
array = new Uint32Array(array.length * 2);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
var proxy = new Proxy(
|
|
66
|
+
{
|
|
67
|
+
slice: function (min, max) {
|
|
68
|
+
if (max === undefined) {
|
|
69
|
+
max = array.length;
|
|
70
|
+
}
|
|
71
|
+
var new_buf = array.slice(min * 2, max * 2);
|
|
72
|
+
return createBigInt64Array(new_buf);
|
|
73
|
+
},
|
|
74
|
+
subarray: function (min, max) {
|
|
75
|
+
var new_buf = array.subarray(min * 2, max * 2);
|
|
76
|
+
return createBigInt64Array(new_buf);
|
|
77
|
+
},
|
|
78
|
+
[Symbol.iterator]: function* () {
|
|
79
|
+
for (var i = 0; i < array.length / 2; i++) {
|
|
80
|
+
yield partsToBigInt(array[2 * i], array[2 * i + 1]);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
BYTES_PER_ELEMENT: 2 * array.BYTES_PER_ELEMENT,
|
|
84
|
+
buffer: array.buffer,
|
|
85
|
+
byteLength: array.byteLength,
|
|
86
|
+
byteOffset: array.byteOffset,
|
|
87
|
+
length: array.length / 2,
|
|
88
|
+
copyWithin: function (target, start, end) {
|
|
89
|
+
array.copyWithin(target * 2, start * 2, end * 2);
|
|
90
|
+
return proxy;
|
|
91
|
+
},
|
|
92
|
+
set: function (source, targetOffset) {
|
|
93
|
+
if (targetOffset === undefined) {
|
|
94
|
+
targetOffset = 0;
|
|
95
|
+
}
|
|
96
|
+
if (2 * (source.length + targetOffset) > array.length) {
|
|
97
|
+
// This is the Chrome error message
|
|
98
|
+
// Firefox: "invalid or out-of-range index"
|
|
99
|
+
throw new RangeError("offset is out of bounds");
|
|
100
|
+
}
|
|
101
|
+
for (var i = 0; i < source.length; i++) {
|
|
102
|
+
var value = source[i];
|
|
103
|
+
var pair = bigIntToParts(value);
|
|
104
|
+
array.set(pair, 2 * (targetOffset + i));
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
get: function (target, idx, receiver) {
|
|
110
|
+
if (typeof idx !== "string" || !/^\d+$/.test(idx)) {
|
|
111
|
+
return Reflect.get(target, idx, receiver);
|
|
112
|
+
}
|
|
113
|
+
var lower = array[idx * 2];
|
|
114
|
+
var upper = array[idx * 2 + 1];
|
|
115
|
+
return partsToBigInt(lower, upper);
|
|
116
|
+
},
|
|
117
|
+
set: function (target, idx, value, receiver) {
|
|
118
|
+
if (typeof idx !== "string" || !/^\d+$/.test(idx)) {
|
|
119
|
+
return Reflect.set(target, idx, value, receiver);
|
|
120
|
+
}
|
|
121
|
+
if (typeof value !== "bigint") {
|
|
122
|
+
// Chrome error message, Firefox has no "a" in front if "BigInt".
|
|
123
|
+
throw new TypeError(`Cannot convert ${value} to a BigInt`);
|
|
124
|
+
}
|
|
125
|
+
var pair = bigIntToParts(value);
|
|
126
|
+
array.set(pair, 2 * idx);
|
|
127
|
+
return true;
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
if (orig_array) {
|
|
132
|
+
proxy.set(orig_array);
|
|
133
|
+
}
|
|
134
|
+
return proxy;
|
|
135
|
+
}
|
|
136
|
+
return createBigInt64Array;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
globalThis.BigUint64Array = createBigIntArrayShim(partsToBigIntUnsigned);
|
|
140
|
+
globalThis.BigInt64Array = createBigIntArrayShim(partsToBigIntSigned);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// end include: polyfill/bigint64array.js
|
|
144
|
+
|
|
145
|
+
// --pre-jses are emitted after the Module integration code, so that they can
|
|
146
|
+
// refer to Module (if they choose; they can also define Module)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
// Sometimes an existing Module object exists with properties
|
|
150
|
+
// meant to overwrite the default module functionality. Here
|
|
151
|
+
// we collect those properties and reapply _after_ we configure
|
|
152
|
+
// the current environment's defaults to avoid having to be so
|
|
153
|
+
// defensive during initialization.
|
|
154
|
+
var moduleOverrides = Object.assign({}, Module);
|
|
155
|
+
|
|
156
|
+
var arguments_ = [];
|
|
157
|
+
var thisProgram = './this.program';
|
|
158
|
+
var quit_ = (status, toThrow) => {
|
|
159
|
+
throw toThrow;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// Determine the runtime environment we are in. You can customize this by
|
|
163
|
+
// setting the ENVIRONMENT setting at compile time (see settings.js).
|
|
164
|
+
|
|
165
|
+
// Attempt to auto-detect the environment
|
|
166
|
+
var ENVIRONMENT_IS_WEB = typeof window == 'object';
|
|
167
|
+
var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function';
|
|
168
|
+
// N.b. Electron.js environment is simultaneously a NODE-environment, but
|
|
169
|
+
// also a web environment.
|
|
170
|
+
var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string';
|
|
171
|
+
var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
|
|
172
|
+
|
|
173
|
+
if (Module['ENVIRONMENT']) {
|
|
174
|
+
throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// `/` should be present at the end if `scriptDirectory` is not empty
|
|
178
|
+
var scriptDirectory = '';
|
|
179
|
+
function locateFile(path) {
|
|
180
|
+
return scriptDirectory + path;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Hooks that are implemented differently in different runtime environments.
|
|
184
|
+
var read_,
|
|
185
|
+
readAsync,
|
|
186
|
+
readBinary,
|
|
187
|
+
setWindowTitle;
|
|
188
|
+
|
|
189
|
+
if (ENVIRONMENT_IS_SHELL) {
|
|
190
|
+
|
|
191
|
+
if ((typeof process == 'object' && typeof require === 'function') || typeof window == 'object' || typeof importScripts == 'function') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
|
|
192
|
+
|
|
193
|
+
if (typeof read != 'undefined') {
|
|
194
|
+
read_ = (f) => {
|
|
195
|
+
return read(f);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
readBinary = (f) => {
|
|
200
|
+
let data;
|
|
201
|
+
if (typeof readbuffer == 'function') {
|
|
202
|
+
return new Uint8Array(readbuffer(f));
|
|
203
|
+
}
|
|
204
|
+
data = read(f, 'binary');
|
|
205
|
+
assert(typeof data == 'object');
|
|
206
|
+
return data;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
readAsync = (f, onload, onerror) => {
|
|
210
|
+
setTimeout(() => onload(readBinary(f)), 0);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
if (typeof clearTimeout == 'undefined') {
|
|
214
|
+
globalThis.clearTimeout = (id) => { };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (typeof scriptArgs != 'undefined') {
|
|
218
|
+
arguments_ = scriptArgs;
|
|
219
|
+
} else if (typeof arguments != 'undefined') {
|
|
220
|
+
arguments_ = arguments;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (typeof quit == 'function') {
|
|
224
|
+
quit_ = (status, toThrow) => {
|
|
225
|
+
// Unlike node which has process.exitCode, d8 has no such mechanism. So we
|
|
226
|
+
// have no way to set the exit code and then let the program exit with
|
|
227
|
+
// that code when it naturally stops running (say, when all setTimeouts
|
|
228
|
+
// have completed). For that reason, we must call `quit` - the only way to
|
|
229
|
+
// set the exit code - but quit also halts immediately. To increase
|
|
230
|
+
// consistency with node (and the web) we schedule the actual quit call
|
|
231
|
+
// using a setTimeout to give the current stack and any exception handlers
|
|
232
|
+
// a chance to run. This enables features such as addOnPostRun (which
|
|
233
|
+
// expected to be able to run code after main returns).
|
|
234
|
+
setTimeout(() => {
|
|
235
|
+
if (!(toThrow instanceof ExitStatus)) {
|
|
236
|
+
let toLog = toThrow;
|
|
237
|
+
if (toThrow && typeof toThrow == 'object' && toThrow.stack) {
|
|
238
|
+
toLog = [toThrow, toThrow.stack];
|
|
239
|
+
}
|
|
240
|
+
err('exiting due to exception: ' + toLog);
|
|
241
|
+
}
|
|
242
|
+
quit(status);
|
|
243
|
+
});
|
|
244
|
+
throw toThrow;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (typeof print != 'undefined') {
|
|
249
|
+
// Prefer to use print/printErr where they exist, as they usually work better.
|
|
250
|
+
if (typeof console == 'undefined') console = /** @type{!Console} */({});
|
|
251
|
+
console.log = /** @type{!function(this:Console, ...*): undefined} */ (print);
|
|
252
|
+
console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (typeof printErr != 'undefined' ? printErr : print);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
} else
|
|
256
|
+
|
|
257
|
+
// Note that this includes Node.js workers when relevant (pthreads is enabled).
|
|
258
|
+
// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
|
|
259
|
+
// ENVIRONMENT_IS_NODE.
|
|
260
|
+
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
|
|
261
|
+
if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
|
|
262
|
+
scriptDirectory = self.location.href;
|
|
263
|
+
} else if (typeof document != 'undefined' && document.currentScript) { // web
|
|
264
|
+
scriptDirectory = document.currentScript.src;
|
|
265
|
+
}
|
|
266
|
+
// blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
|
|
267
|
+
// otherwise, slice off the final part of the url to find the script directory.
|
|
268
|
+
// if scriptDirectory does not contain a slash, lastIndexOf will return -1,
|
|
269
|
+
// and scriptDirectory will correctly be replaced with an empty string.
|
|
270
|
+
// If scriptDirectory contains a query (starting with ?) or a fragment (starting with #),
|
|
271
|
+
// they are removed because they could contain a slash.
|
|
272
|
+
if (scriptDirectory.indexOf('blob:') !== 0) {
|
|
273
|
+
scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf('/') + 1);
|
|
274
|
+
} else {
|
|
275
|
+
scriptDirectory = '';
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (!(typeof window == 'object' || typeof importScripts == 'function')) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
|
|
279
|
+
|
|
280
|
+
// Differentiate the Web Worker from the Node Worker case, as reading must
|
|
281
|
+
// be done differently.
|
|
282
|
+
{
|
|
283
|
+
// include: web_or_worker_shell_read.js
|
|
284
|
+
/**
|
|
285
|
+
* @license
|
|
286
|
+
* Copyright 2019 The Emscripten Authors
|
|
287
|
+
* SPDX-License-Identifier: MIT
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
read_ = (url) => {
|
|
291
|
+
var xhr = new XMLHttpRequest();
|
|
292
|
+
xhr.open('GET', url, false);
|
|
293
|
+
xhr.send(null);
|
|
294
|
+
return xhr.responseText;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (ENVIRONMENT_IS_WORKER) {
|
|
298
|
+
readBinary = (url) => {
|
|
299
|
+
var xhr = new XMLHttpRequest();
|
|
300
|
+
xhr.open('GET', url, false);
|
|
301
|
+
xhr.responseType = 'arraybuffer';
|
|
302
|
+
xhr.send(null);
|
|
303
|
+
return new Uint8Array(/** @type{!ArrayBuffer} */(xhr.response));
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
readAsync = (url, onload, onerror) => {
|
|
308
|
+
var xhr = new XMLHttpRequest();
|
|
309
|
+
xhr.open('GET', url, true);
|
|
310
|
+
xhr.responseType = 'arraybuffer';
|
|
311
|
+
xhr.onload = () => {
|
|
312
|
+
if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
|
|
313
|
+
onload(xhr.response);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
onerror();
|
|
317
|
+
};
|
|
318
|
+
xhr.onerror = onerror;
|
|
319
|
+
xhr.send(null);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// end include: web_or_worker_shell_read.js
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
setWindowTitle = (title) => document.title = title;
|
|
326
|
+
} else {
|
|
327
|
+
throw new Error('environment detection error');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
var out = console.log.bind(console);
|
|
331
|
+
var err = console.warn.bind(console);
|
|
332
|
+
|
|
333
|
+
// Merge back in the overrides
|
|
334
|
+
Object.assign(Module, moduleOverrides);
|
|
335
|
+
// Free the object hierarchy contained in the overrides, this lets the GC
|
|
336
|
+
// reclaim data used e.g. in memoryInitializerRequest, which is a large typed array.
|
|
337
|
+
moduleOverrides = null;
|
|
338
|
+
// checkIncomingModuleAPI();
|
|
339
|
+
|
|
340
|
+
// Emit code to handle expected values on the Module object. This applies Module.x
|
|
341
|
+
// to the proper local x. This has two benefits: first, we only emit it if it is
|
|
342
|
+
// expected to arrive, and second, by using a local everywhere else that can be
|
|
343
|
+
// minified.
|
|
344
|
+
legacyModuleProp('arguments', 'arguments_');
|
|
345
|
+
legacyModuleProp('thisProgram', 'thisProgram');
|
|
346
|
+
legacyModuleProp('quit', 'quit_');
|
|
347
|
+
|
|
348
|
+
// perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
|
|
349
|
+
// Assertions on removed incoming Module JS APIs.
|
|
350
|
+
assert(typeof Module['memoryInitializerPrefixURL'] == 'undefined', 'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead');
|
|
351
|
+
assert(typeof Module['pthreadMainPrefixURL'] == 'undefined', 'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead');
|
|
352
|
+
assert(typeof Module['cdInitializerPrefixURL'] == 'undefined', 'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead');
|
|
353
|
+
assert(typeof Module['filePackagePrefixURL'] == 'undefined', 'Module.filePackagePrefixURL option was removed, use Module.locateFile instead');
|
|
354
|
+
assert(typeof Module['read'] == 'undefined', 'Module.read option was removed (modify read_ in JS)');
|
|
355
|
+
assert(typeof Module['readAsync'] == 'undefined', 'Module.readAsync option was removed (modify readAsync in JS)');
|
|
356
|
+
assert(typeof Module['readBinary'] == 'undefined', 'Module.readBinary option was removed (modify readBinary in JS)');
|
|
357
|
+
assert(typeof Module['setWindowTitle'] == 'undefined', 'Module.setWindowTitle option was removed (modify setWindowTitle in JS)');
|
|
358
|
+
assert(typeof Module['TOTAL_MEMORY'] == 'undefined', 'Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY');
|
|
359
|
+
legacyModuleProp('read', 'read_');
|
|
360
|
+
legacyModuleProp('readAsync', 'readAsync');
|
|
361
|
+
legacyModuleProp('readBinary', 'readBinary');
|
|
362
|
+
legacyModuleProp('setWindowTitle', 'setWindowTitle');
|
|
363
|
+
var IDBFS = 'IDBFS is no longer included by default; build with -lidbfs.js';
|
|
364
|
+
var PROXYFS = 'PROXYFS is no longer included by default; build with -lproxyfs.js';
|
|
365
|
+
var WORKERFS = 'WORKERFS is no longer included by default; build with -lworkerfs.js';
|
|
366
|
+
var NODEFS = 'NODEFS is no longer included by default; build with -lnodefs.js';
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
// end include: shell.js
|
|
370
|
+
// include: preamble.js
|
|
371
|
+
/**
|
|
372
|
+
* @license
|
|
373
|
+
* Copyright 2010 The Emscripten Authors
|
|
374
|
+
* SPDX-License-Identifier: MIT
|
|
375
|
+
*/
|
|
376
|
+
|
|
377
|
+
// === Preamble library stuff ===
|
|
378
|
+
|
|
379
|
+
// Documentation for the public APIs defined in this file must be updated in:
|
|
380
|
+
// site/source/docs/api_reference/preamble.js.rst
|
|
381
|
+
// A prebuilt local version of the documentation is available at:
|
|
382
|
+
// site/build/text/docs/api_reference/preamble.js.txt
|
|
383
|
+
// You can also build docs locally as HTML or other formats in site/
|
|
384
|
+
// An online HTML version (which may be of a different version of Emscripten)
|
|
385
|
+
// is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
|
|
386
|
+
|
|
387
|
+
var wasmBinary; legacyModuleProp('wasmBinary', 'wasmBinary');
|
|
388
|
+
var noExitRuntime = true; legacyModuleProp('noExitRuntime', 'noExitRuntime');
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
// Wasm globals
|
|
392
|
+
|
|
393
|
+
var wasmMemory;
|
|
394
|
+
|
|
395
|
+
//========================================
|
|
396
|
+
// Runtime essentials
|
|
397
|
+
//========================================
|
|
398
|
+
|
|
399
|
+
// whether we are quitting the application. no code should run after this.
|
|
400
|
+
// set in exit() and abort()
|
|
401
|
+
var ABORT = false;
|
|
402
|
+
|
|
403
|
+
// set by exit() and abort(). Passed to 'onExit' handler.
|
|
404
|
+
// NOTE: This is also used as the process return code code in shell environments
|
|
405
|
+
// but only when noExitRuntime is false.
|
|
406
|
+
var EXITSTATUS;
|
|
407
|
+
|
|
408
|
+
/** @type {function(*, string=)} */
|
|
409
|
+
function assert(condition, text) {
|
|
410
|
+
if (!condition) {
|
|
411
|
+
abort('Assertion failed' + (text ? ': ' + text : ''));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// We used to include malloc/free by default in the past. Show a helpful error in
|
|
416
|
+
// builds with assertions.
|
|
417
|
+
function _malloc() {
|
|
418
|
+
abort("malloc() called but not included in the build - add '_malloc' to EXPORTED_FUNCTIONS");
|
|
419
|
+
}
|
|
420
|
+
function _free() {
|
|
421
|
+
// Show a helpful error since we used to include free by default in the past.
|
|
422
|
+
// console.warn("free() called but not included in the build - add '_free' to EXPORTED_FUNCTIONS");
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Memory management
|
|
426
|
+
|
|
427
|
+
var HEAP = [],
|
|
428
|
+
/** @type {!Int8Array} */
|
|
429
|
+
HEAP8 = [],
|
|
430
|
+
/** @type {!Uint8Array} */
|
|
431
|
+
HEAPU8 = [],
|
|
432
|
+
/** @type {!Int16Array} */
|
|
433
|
+
HEAP16 = [],
|
|
434
|
+
/** @type {!Uint16Array} */
|
|
435
|
+
HEAPU16 = [],
|
|
436
|
+
/** @type {!Int32Array} */
|
|
437
|
+
HEAP32 = [],
|
|
438
|
+
/** @type {!Uint32Array} */
|
|
439
|
+
HEAPU32 = [],
|
|
440
|
+
/** @type {!Float32Array} */
|
|
441
|
+
HEAPF32 = [],
|
|
442
|
+
/* BigInt64Array type is not correctly defined in closure
|
|
443
|
+
/** not-@type {!BigInt64Array} */
|
|
444
|
+
HEAP64 = [],
|
|
445
|
+
/* BigUInt64Array type is not correctly defined in closure
|
|
446
|
+
/** not-t@type {!BigUint64Array} */
|
|
447
|
+
HEAPU64 = [],
|
|
448
|
+
/** @type {!Float64Array} */
|
|
449
|
+
HEAPF64 = [],
|
|
450
|
+
|
|
451
|
+
DATA_VIEW = [];
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
var HEAP_OFFSET = [];
|
|
455
|
+
|
|
456
|
+
function updateMemoryViews(offset, offset2, offset3, offset4) {
|
|
457
|
+
// var b = wasmMemory.buffer;
|
|
458
|
+
var b = globalThis.jsiArrayBuffer;
|
|
459
|
+
var b2 = globalThis.jsiArrayBuffer2;
|
|
460
|
+
var b3 = globalThis.jsiArrayBuffer3;
|
|
461
|
+
var b4 = globalThis.jsiArrayBuffer4;
|
|
462
|
+
|
|
463
|
+
// console.log('length: ' + b.byteLength + ', offset 1: ' + offset + ', offset 2: ' + offset2 + ', offset 3: ' + offset3 + ', offset 4: ' + offset4);
|
|
464
|
+
|
|
465
|
+
HEAP_OFFSET = [offset, offset2, offset3, offset4];
|
|
466
|
+
|
|
467
|
+
HEAP8.push(new Int8Array(b));
|
|
468
|
+
HEAP8.push(new Int8Array(b2));
|
|
469
|
+
HEAP8.push(new Int8Array(b3));
|
|
470
|
+
HEAP8.push(new Int8Array(b4));
|
|
471
|
+
|
|
472
|
+
HEAPU8.push(new Uint8Array(b));
|
|
473
|
+
HEAPU8.push(new Uint8Array(b2));
|
|
474
|
+
HEAPU8.push(new Uint8Array(b3));
|
|
475
|
+
HEAPU8.push(new Uint8Array(b4));
|
|
476
|
+
|
|
477
|
+
DATA_VIEW.push(new DataView(b));
|
|
478
|
+
DATA_VIEW.push(new DataView(b2));
|
|
479
|
+
DATA_VIEW.push(new DataView(b3));
|
|
480
|
+
DATA_VIEW.push(new DataView(b4));
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function __crossbind_register_heap_window(offset, arrayBuffer) {
|
|
484
|
+
for (let i = 0; i < HEAP_OFFSET.length; i++) {
|
|
485
|
+
if (HEAP_OFFSET[i] === offset) return;
|
|
486
|
+
}
|
|
487
|
+
HEAP_OFFSET.push(offset);
|
|
488
|
+
HEAP8.push(new Int8Array(arrayBuffer));
|
|
489
|
+
HEAPU8.push(new Uint8Array(arrayBuffer));
|
|
490
|
+
DATA_VIEW.push(new DataView(arrayBuffer));
|
|
491
|
+
}
|
|
492
|
+
globalThis.__crossbind_register_heap_window = __crossbind_register_heap_window;
|
|
493
|
+
|
|
494
|
+
const UINT32_MAX_BIGINT = 4294967295n;
|
|
495
|
+
|
|
496
|
+
function findHeapIndex(ptr) {
|
|
497
|
+
let bestIdx = -1;
|
|
498
|
+
let bestDelta = UINT32_MAX_BIGINT;
|
|
499
|
+
for (let i = 0; i < HEAP_OFFSET.length; i++) {
|
|
500
|
+
const offset = HEAP_OFFSET[i];
|
|
501
|
+
if (ptr >= offset) {
|
|
502
|
+
const delta = ptr - offset;
|
|
503
|
+
if (delta < bestDelta) {
|
|
504
|
+
bestDelta = delta;
|
|
505
|
+
bestIdx = i;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return bestIdx;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function getHeapIndex(ptr) {
|
|
513
|
+
let bestIdx = findHeapIndex(ptr);
|
|
514
|
+
|
|
515
|
+
// Self-healing: a pointer can land outside every window (fresh heap regions from
|
|
516
|
+
// by-value returns, allocator arenas, ...). Ask native to register a covering
|
|
517
|
+
// window and retry once before giving up.
|
|
518
|
+
if (bestIdx === -1 && typeof globalThis.__crossbind_ensure_heap_window === 'function') {
|
|
519
|
+
globalThis.__crossbind_ensure_heap_window(ptr);
|
|
520
|
+
bestIdx = findHeapIndex(ptr);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (bestIdx === -1) {
|
|
524
|
+
throw (`Heap error !!! pointer: ${ptr}, no covering window in: ${HEAP_OFFSET}`);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
return bestIdx;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function writeToMemoryUsingShift(pointer, signed, shift, value) {
|
|
531
|
+
// console.log(`writeToMemory, pointer: ${pointer}`);
|
|
532
|
+
const pi = getHeapIndex(pointer);
|
|
533
|
+
const offset = Number(pointer - HEAP_OFFSET[pi]);
|
|
534
|
+
const shiftAsInt = Number(shift);
|
|
535
|
+
// console.log(`writeToMemory, pi: ${pi}, shift: ${shiftAsInt}, signed: ${signed}, value: ${value}, pointer: ${pointer}`);
|
|
536
|
+
|
|
537
|
+
switch (shiftAsInt) {
|
|
538
|
+
case 0: result = signed ? DATA_VIEW[pi].setInt8(offset, value, true) : DATA_VIEW[pi].setUint8(offset, value, true);
|
|
539
|
+
break;
|
|
540
|
+
case 1: result = signed ? DATA_VIEW[pi].setInt16(offset, value, true) : DATA_VIEW[pi].setUint16(offset, value, true);
|
|
541
|
+
break;
|
|
542
|
+
case 2: result = signed ? DATA_VIEW[pi].setInt32(offset, value, true) : DATA_VIEW[pi].setUint32(offset, value, true);
|
|
543
|
+
break;
|
|
544
|
+
case 3: result = signed ? DATA_VIEW[pi].setBigInt64(offset, value, true) : DATA_VIEW[pi].setBigUint64(offset, value, true);
|
|
545
|
+
break;
|
|
546
|
+
default:
|
|
547
|
+
throw new TypeError("Unknown heap type");
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function readFromMemoryUsingShift(pointer, signed, shift, isFloat = false) {
|
|
552
|
+
// console.log(`readFromMemory, pointer: ${pointer}`);
|
|
553
|
+
const pi = getHeapIndex(pointer);
|
|
554
|
+
const offset = Number(pointer - HEAP_OFFSET[pi]);
|
|
555
|
+
// console.log(`readFromMemory, pi: ${pi}, shift: ${shift}, signed: ${signed}, pointer: ${pointer}, offset: ${offset}`);
|
|
556
|
+
const shiftAsInt = Number(shift);
|
|
557
|
+
|
|
558
|
+
let result = null;
|
|
559
|
+
if (isFloat) {
|
|
560
|
+
switch (shiftAsInt) {
|
|
561
|
+
case 2: result = DATA_VIEW[pi].getFloat32(offset, true);
|
|
562
|
+
break;
|
|
563
|
+
case 3: result = DATA_VIEW[pi].getFloat64(offset, true);
|
|
564
|
+
break;
|
|
565
|
+
default:
|
|
566
|
+
throw new TypeError("Unknown heap type");
|
|
567
|
+
}
|
|
568
|
+
} else {
|
|
569
|
+
switch (shiftAsInt) {
|
|
570
|
+
case 0: result = signed ? DATA_VIEW[pi].getInt8(offset, true) : DATA_VIEW[pi].getUint8(offset, true);
|
|
571
|
+
break;
|
|
572
|
+
case 1: result = signed ? DATA_VIEW[pi].getInt16(offset, true) : DATA_VIEW[pi].getUint16(offset, true);
|
|
573
|
+
break;
|
|
574
|
+
case 2: result = signed ? DATA_VIEW[pi].getInt32(offset, true) : DATA_VIEW[pi].getUint32(offset, true);
|
|
575
|
+
break;
|
|
576
|
+
case 3: result = signed ? DATA_VIEW[pi].getBigInt64(offset, true) : DATA_VIEW[pi].getBigUint64(offset, true);
|
|
577
|
+
break;
|
|
578
|
+
default:
|
|
579
|
+
throw new TypeError("Unknown heap type");
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// console.log(`readFromMemory, result 1: ${result}`);
|
|
584
|
+
|
|
585
|
+
return result;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function readFromMemoryUsingBit(pointer, signed, bit) {
|
|
589
|
+
let shift = 0;
|
|
590
|
+
switch (bit) {
|
|
591
|
+
case 8: shift = 0;
|
|
592
|
+
break;
|
|
593
|
+
case 16: shift = 1;
|
|
594
|
+
break;
|
|
595
|
+
case 32: shift = 2;
|
|
596
|
+
break;
|
|
597
|
+
case 64: shift = 3;
|
|
598
|
+
break;
|
|
599
|
+
default:
|
|
600
|
+
throw new TypeError("Unknown bit");
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
return readFromMemoryUsingShift(pointer, signed, shift);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function readFromMemoryUsingSize(pointer, signed, bit) {
|
|
607
|
+
let shift = 0;
|
|
608
|
+
switch (bit) {
|
|
609
|
+
case 1: shift = 0;
|
|
610
|
+
break;
|
|
611
|
+
case 2: shift = 1;
|
|
612
|
+
break;
|
|
613
|
+
case 4: shift = 2;
|
|
614
|
+
break;
|
|
615
|
+
default:
|
|
616
|
+
throw new TypeError("Unknown size");
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
return readFromMemoryUsingShift(pointer, signed, shift);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
globalThis.updateMemoryViews = updateMemoryViews;
|
|
623
|
+
|
|
624
|
+
assert(!Module['STACK_SIZE'], 'STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time')
|
|
625
|
+
|
|
626
|
+
assert(typeof Int32Array != 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray != undefined && Int32Array.prototype.set != undefined,
|
|
627
|
+
'JS engine does not provide full typed array support');
|
|
628
|
+
|
|
629
|
+
// If memory is defined in wasm, the user can't provide it, or set INITIAL_MEMORY
|
|
630
|
+
assert(!Module['wasmMemory'], 'Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally');
|
|
631
|
+
assert(!Module['INITIAL_MEMORY'], 'Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically');
|
|
632
|
+
|
|
633
|
+
// include: runtime_init_table.js
|
|
634
|
+
// In regular non-RELOCATABLE mode the table is exported
|
|
635
|
+
// from the wasm module and this will be assigned once
|
|
636
|
+
// the exports are available.
|
|
637
|
+
var wasmTable;
|
|
638
|
+
|
|
639
|
+
// end include: runtime_init_table.js
|
|
640
|
+
// include: runtime_stack_check.js
|
|
641
|
+
/**
|
|
642
|
+
* @license
|
|
643
|
+
* Copyright 2019 The Emscripten Authors
|
|
644
|
+
* SPDX-License-Identifier: MIT
|
|
645
|
+
*/
|
|
646
|
+
|
|
647
|
+
// end include: runtime_stack_check.js
|
|
648
|
+
// include: runtime_assertions.js
|
|
649
|
+
/**
|
|
650
|
+
* @license
|
|
651
|
+
* Copyright 2019 The Emscripten Authors
|
|
652
|
+
* SPDX-License-Identifier: MIT
|
|
653
|
+
*/
|
|
654
|
+
|
|
655
|
+
// Endianness check
|
|
656
|
+
(function () {
|
|
657
|
+
var h16 = new Int16Array(1);
|
|
658
|
+
var h8 = new Int8Array(h16.buffer);
|
|
659
|
+
h16[0] = 0x6373;
|
|
660
|
+
if (h8[0] !== 0x73 || h8[1] !== 0x63) throw 'Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)';
|
|
661
|
+
})();
|
|
662
|
+
|
|
663
|
+
// end include: runtime_assertions.js
|
|
664
|
+
var __ATPRERUN__ = []; // functions called before the runtime is initialized
|
|
665
|
+
var __ATINIT__ = []; // functions called during startup
|
|
666
|
+
var __ATEXIT__ = []; // functions called during shutdown
|
|
667
|
+
var __ATPOSTRUN__ = []; // functions called after the main() is called
|
|
668
|
+
|
|
669
|
+
var runtimeInitialized = false;
|
|
670
|
+
|
|
671
|
+
var runtimeKeepaliveCounter = 0;
|
|
672
|
+
|
|
673
|
+
function keepRuntimeAlive() {
|
|
674
|
+
return noExitRuntime || runtimeKeepaliveCounter > 0;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function preRun() {
|
|
678
|
+
callRuntimeCallbacks(__ATPRERUN__);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function initRuntime() {
|
|
682
|
+
assert(!runtimeInitialized);
|
|
683
|
+
runtimeInitialized = true;
|
|
684
|
+
|
|
685
|
+
callRuntimeCallbacks(__ATINIT__);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function postRun() {
|
|
689
|
+
|
|
690
|
+
callRuntimeCallbacks(__ATPOSTRUN__);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
function addOnPreRun(cb) {
|
|
694
|
+
__ATPRERUN__.unshift(cb);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function addOnInit(cb) {
|
|
698
|
+
__ATINIT__.unshift(cb);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
function addOnExit(cb) {
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function addOnPostRun(cb) {
|
|
705
|
+
__ATPOSTRUN__.unshift(cb);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// include: runtime_math.js
|
|
709
|
+
/**
|
|
710
|
+
* @license
|
|
711
|
+
* Copyright 2019 The Emscripten Authors
|
|
712
|
+
* SPDX-License-Identifier: MIT
|
|
713
|
+
*/
|
|
714
|
+
|
|
715
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
|
|
716
|
+
|
|
717
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
|
|
718
|
+
|
|
719
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
|
|
720
|
+
|
|
721
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
|
|
722
|
+
|
|
723
|
+
assert(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
|
|
724
|
+
assert(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
|
|
725
|
+
assert(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
|
|
726
|
+
assert(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
|
|
727
|
+
|
|
728
|
+
// end include: runtime_math.js
|
|
729
|
+
// A counter of dependencies for calling run(). If we need to
|
|
730
|
+
// do asynchronous work before running, increment this and
|
|
731
|
+
// decrement it. Incrementing must happen in a place like
|
|
732
|
+
// Module.preRun (used by emcc to add file preloading).
|
|
733
|
+
// Note that you can add dependencies in preRun, even though
|
|
734
|
+
// it happens right before run - run will be postponed until
|
|
735
|
+
// the dependencies are met.
|
|
736
|
+
var runDependencies = 0;
|
|
737
|
+
var runDependencyWatcher = null;
|
|
738
|
+
var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
|
|
739
|
+
var runDependencyTracking = {};
|
|
740
|
+
|
|
741
|
+
function getUniqueRunDependency(id) {
|
|
742
|
+
var orig = id;
|
|
743
|
+
while (1) {
|
|
744
|
+
if (!runDependencyTracking[id]) return id;
|
|
745
|
+
id = orig + Math.random();
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
function addRunDependency(id) {
|
|
750
|
+
runDependencies++;
|
|
751
|
+
|
|
752
|
+
if (id) {
|
|
753
|
+
assert(!runDependencyTracking[id]);
|
|
754
|
+
runDependencyTracking[id] = 1;
|
|
755
|
+
if (runDependencyWatcher === null && typeof setInterval != 'undefined') {
|
|
756
|
+
// Check for missing dependencies every few seconds
|
|
757
|
+
runDependencyWatcher = setInterval(() => {
|
|
758
|
+
if (ABORT) {
|
|
759
|
+
clearInterval(runDependencyWatcher);
|
|
760
|
+
runDependencyWatcher = null;
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
var shown = false;
|
|
764
|
+
for (var dep in runDependencyTracking) {
|
|
765
|
+
if (!shown) {
|
|
766
|
+
shown = true;
|
|
767
|
+
err('still waiting on run dependencies:');
|
|
768
|
+
}
|
|
769
|
+
err('dependency: ' + dep);
|
|
770
|
+
}
|
|
771
|
+
if (shown) {
|
|
772
|
+
err('(end of list)');
|
|
773
|
+
}
|
|
774
|
+
}, 10000);
|
|
775
|
+
}
|
|
776
|
+
} else {
|
|
777
|
+
err('warning: run dependency added without ID');
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function removeRunDependency(id) {
|
|
782
|
+
runDependencies--;
|
|
783
|
+
|
|
784
|
+
if (id) {
|
|
785
|
+
assert(runDependencyTracking[id]);
|
|
786
|
+
delete runDependencyTracking[id];
|
|
787
|
+
} else {
|
|
788
|
+
err('warning: run dependency removed without ID');
|
|
789
|
+
}
|
|
790
|
+
if (runDependencies == 0) {
|
|
791
|
+
if (runDependencyWatcher !== null) {
|
|
792
|
+
clearInterval(runDependencyWatcher);
|
|
793
|
+
runDependencyWatcher = null;
|
|
794
|
+
}
|
|
795
|
+
if (dependenciesFulfilled) {
|
|
796
|
+
var callback = dependenciesFulfilled;
|
|
797
|
+
dependenciesFulfilled = null;
|
|
798
|
+
callback(); // can add another dependenciesFulfilled
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/** @param {string|number=} what */
|
|
804
|
+
function abort(what) {
|
|
805
|
+
|
|
806
|
+
what = 'Aborted(' + what + ')';
|
|
807
|
+
// TODO(sbc): Should we remove printing and leave it up to whoever
|
|
808
|
+
// catches the exception?
|
|
809
|
+
err(what);
|
|
810
|
+
|
|
811
|
+
ABORT = true;
|
|
812
|
+
EXITSTATUS = 1;
|
|
813
|
+
|
|
814
|
+
// Use a wasm runtime error, because a JS error might be seen as a foreign
|
|
815
|
+
// exception, which means we'd run destructors on it. We need the error to
|
|
816
|
+
// simply make the program stop.
|
|
817
|
+
// FIXME This approach does not work in Wasm EH because it currently does not assume
|
|
818
|
+
// all RuntimeErrors are from traps; it decides whether a RuntimeError is from
|
|
819
|
+
// a trap or not based on a hidden field within the object. So at the moment
|
|
820
|
+
// we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that
|
|
821
|
+
// allows this in the wasm spec.
|
|
822
|
+
|
|
823
|
+
// Suppress closure compiler warning here. Closure compiler's builtin extern
|
|
824
|
+
// defintion for WebAssembly.RuntimeError claims it takes no arguments even
|
|
825
|
+
// though it can.
|
|
826
|
+
// TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
|
|
827
|
+
/** @suppress {checkTypes} */
|
|
828
|
+
var e = new WebAssembly.RuntimeError(what);
|
|
829
|
+
|
|
830
|
+
// Throw the error whether or not MODULARIZE is set because abort is used
|
|
831
|
+
// in code paths apart from instantiation where an exception is expected
|
|
832
|
+
// to be thrown when abort is called.
|
|
833
|
+
throw e;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
// include: memoryprofiler.js
|
|
837
|
+
/**
|
|
838
|
+
* @license
|
|
839
|
+
* Copyright 2015 The Emscripten Authors
|
|
840
|
+
* SPDX-License-Identifier: MIT
|
|
841
|
+
*/
|
|
842
|
+
|
|
843
|
+
// end include: memoryprofiler.js
|
|
844
|
+
// show errors on likely calls to FS when it was not included
|
|
845
|
+
var FS = {
|
|
846
|
+
error: function () {
|
|
847
|
+
abort('Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM');
|
|
848
|
+
},
|
|
849
|
+
init: function () { FS.error() },
|
|
850
|
+
createDataFile: function () { FS.error() },
|
|
851
|
+
createPreloadedFile: function () { FS.error() },
|
|
852
|
+
createLazyFile: function () { FS.error() },
|
|
853
|
+
open: function () { FS.error() },
|
|
854
|
+
mkdev: function () { FS.error() },
|
|
855
|
+
registerDevice: function () { FS.error() },
|
|
856
|
+
analyzePath: function () { FS.error() },
|
|
857
|
+
|
|
858
|
+
ErrnoError: function ErrnoError() { FS.error() },
|
|
859
|
+
};
|
|
860
|
+
Module['FS_createDataFile'] = FS.createDataFile;
|
|
861
|
+
Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
|
|
862
|
+
|
|
863
|
+
// include: URIUtils.js
|
|
864
|
+
/**
|
|
865
|
+
* @license
|
|
866
|
+
* Copyright 2017 The Emscripten Authors
|
|
867
|
+
* SPDX-License-Identifier: MIT
|
|
868
|
+
*/
|
|
869
|
+
|
|
870
|
+
// Prefix of data URIs emitted by SINGLE_FILE and related options.
|
|
871
|
+
var dataURIPrefix = 'data:application/octet-stream;base64,';
|
|
872
|
+
|
|
873
|
+
// Indicates whether filename is a base64 data URI.
|
|
874
|
+
function isDataURI(filename) {
|
|
875
|
+
// Prefix of data URIs emitted by SINGLE_FILE and related options.
|
|
876
|
+
return filename.startsWith(dataURIPrefix);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
// Indicates whether filename is delivered via file protocol (as opposed to http/https)
|
|
880
|
+
function isFileURI(filename) {
|
|
881
|
+
return filename.startsWith('file://');
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
// end include: URIUtils.js
|
|
885
|
+
/** @param {boolean=} fixedasm */
|
|
886
|
+
function createExportWrapper(name, fixedasm) {
|
|
887
|
+
return function () {
|
|
888
|
+
var displayName = name;
|
|
889
|
+
var asm = fixedasm;
|
|
890
|
+
if (!fixedasm) {
|
|
891
|
+
asm = Module['asm'];
|
|
892
|
+
}
|
|
893
|
+
assert(runtimeInitialized, 'native function `' + displayName + '` called before runtime initialization');
|
|
894
|
+
if (!asm[name]) {
|
|
895
|
+
assert(asm[name], 'exported native function `' + displayName + '` not found');
|
|
896
|
+
}
|
|
897
|
+
return asm[name].apply(null, arguments);
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// include: runtime_exceptions.js
|
|
902
|
+
/**
|
|
903
|
+
* @license
|
|
904
|
+
* Copyright 2023 The Emscripten Authors
|
|
905
|
+
* SPDX-License-Identifier: MIT
|
|
906
|
+
*/
|
|
907
|
+
|
|
908
|
+
// end include: runtime_exceptions.js
|
|
909
|
+
var wasmBinaryFile;
|
|
910
|
+
wasmBinaryFile = '';
|
|
911
|
+
if (!isDataURI(wasmBinaryFile)) {
|
|
912
|
+
wasmBinaryFile = locateFile(wasmBinaryFile);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
function getBinary(file) {
|
|
916
|
+
try {
|
|
917
|
+
if (file == wasmBinaryFile && wasmBinary) {
|
|
918
|
+
return new Uint8Array(wasmBinary);
|
|
919
|
+
}
|
|
920
|
+
if (readBinary) {
|
|
921
|
+
return readBinary(file);
|
|
922
|
+
}
|
|
923
|
+
throw "both async and sync fetching of the wasm failed";
|
|
924
|
+
}
|
|
925
|
+
catch (err) {
|
|
926
|
+
abort(err);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
function getBinaryPromise(binaryFile) {
|
|
931
|
+
// If we don't have the binary yet, try to load it asynchronously.
|
|
932
|
+
// Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
|
|
933
|
+
// See https://github.com/github/fetch/pull/92#issuecomment-140665932
|
|
934
|
+
// Cordova or Electron apps are typically loaded from a file:// url.
|
|
935
|
+
// So use fetch if it is available and the url is not a file, otherwise fall back to XHR.
|
|
936
|
+
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
|
|
937
|
+
if (typeof fetch == 'function'
|
|
938
|
+
&& !isFileURI(binaryFile)
|
|
939
|
+
) {
|
|
940
|
+
return fetch(binaryFile, { credentials: 'same-origin' }).then((response) => {
|
|
941
|
+
if (!response['ok']) {
|
|
942
|
+
throw "failed to load wasm binary file at '" + binaryFile + "'";
|
|
943
|
+
}
|
|
944
|
+
return response['arrayBuffer']();
|
|
945
|
+
}).catch(() => getBinary(binaryFile));
|
|
946
|
+
}
|
|
947
|
+
else {
|
|
948
|
+
if (readAsync) {
|
|
949
|
+
// fetch is not available or url is file => try XHR (readAsync uses XHR internally)
|
|
950
|
+
return new Promise((resolve, reject) => {
|
|
951
|
+
readAsync(binaryFile, (response) => resolve(new Uint8Array(/** @type{!ArrayBuffer} */(response))), reject)
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// Otherwise, getBinary should be able to get it synchronously
|
|
958
|
+
return Promise.resolve().then(() => getBinary(binaryFile));
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function instantiateArrayBuffer(binaryFile, imports, receiver) {
|
|
962
|
+
return getBinaryPromise(binaryFile).then((binary) => {
|
|
963
|
+
return WebAssembly.instantiate(binary, imports);
|
|
964
|
+
}).then((instance) => {
|
|
965
|
+
return instance;
|
|
966
|
+
}).then(receiver, (reason) => {
|
|
967
|
+
err('failed to asynchronously prepare wasm: ' + reason);
|
|
968
|
+
|
|
969
|
+
// Warn on some common problems.
|
|
970
|
+
if (isFileURI(wasmBinaryFile)) {
|
|
971
|
+
err('warning: Loading from a file URI (' + wasmBinaryFile + ') is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing');
|
|
972
|
+
}
|
|
973
|
+
abort(reason);
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
function instantiateAsync(binary, binaryFile, imports, callback) {
|
|
978
|
+
if (!binary &&
|
|
979
|
+
typeof WebAssembly.instantiateStreaming == 'function' &&
|
|
980
|
+
!isDataURI(binaryFile) &&
|
|
981
|
+
// Don't use streaming for file:// delivered objects in a webview, fetch them synchronously.
|
|
982
|
+
!isFileURI(binaryFile) &&
|
|
983
|
+
// Avoid instantiateStreaming() on Node.js environment for now, as while
|
|
984
|
+
// Node.js v18.1.0 implements it, it does not have a full fetch()
|
|
985
|
+
// implementation yet.
|
|
986
|
+
//
|
|
987
|
+
// Reference:
|
|
988
|
+
// https://github.com/emscripten-core/emscripten/pull/16917
|
|
989
|
+
!ENVIRONMENT_IS_NODE &&
|
|
990
|
+
typeof fetch == 'function') {
|
|
991
|
+
return fetch(binaryFile, { credentials: 'same-origin' }).then((response) => {
|
|
992
|
+
// Suppress closure warning here since the upstream definition for
|
|
993
|
+
// instantiateStreaming only allows Promise<Repsponse> rather than
|
|
994
|
+
// an actual Response.
|
|
995
|
+
// TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure is fixed.
|
|
996
|
+
/** @suppress {checkTypes} */
|
|
997
|
+
var result = WebAssembly.instantiateStreaming(response, imports);
|
|
998
|
+
|
|
999
|
+
return result.then(
|
|
1000
|
+
callback,
|
|
1001
|
+
function (reason) {
|
|
1002
|
+
// We expect the most common failure cause to be a bad MIME type for the binary,
|
|
1003
|
+
// in which case falling back to ArrayBuffer instantiation should work.
|
|
1004
|
+
err('wasm streaming compile failed: ' + reason);
|
|
1005
|
+
err('falling back to ArrayBuffer instantiation');
|
|
1006
|
+
return instantiateArrayBuffer(binaryFile, imports, callback);
|
|
1007
|
+
});
|
|
1008
|
+
});
|
|
1009
|
+
} else {
|
|
1010
|
+
return instantiateArrayBuffer(binaryFile, imports, callback);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
// Create the wasm instance.
|
|
1015
|
+
// Receives the wasm imports, returns the exports.
|
|
1016
|
+
function createWasm() {
|
|
1017
|
+
// prepare imports
|
|
1018
|
+
var info = {
|
|
1019
|
+
'env': wasmImports,
|
|
1020
|
+
'wasi_snapshot_preview1': wasmImports,
|
|
1021
|
+
};
|
|
1022
|
+
// Load the wasm module and create an instance of using native support in the JS engine.
|
|
1023
|
+
// handle a generated wasm instance, receiving its exports and
|
|
1024
|
+
// performing other necessary setup
|
|
1025
|
+
/** @param {WebAssembly.Module=} module*/
|
|
1026
|
+
function receiveInstance(instance, module) {
|
|
1027
|
+
var exports = instance.exports;
|
|
1028
|
+
|
|
1029
|
+
exports = instrumentWasmExportsForMemory64(exports);
|
|
1030
|
+
|
|
1031
|
+
Module['asm'] = exports;
|
|
1032
|
+
|
|
1033
|
+
wasmMemory = Module['asm']['memory'];
|
|
1034
|
+
assert(wasmMemory, "memory not found in wasm exports");
|
|
1035
|
+
// This assertion doesn't hold when emscripten is run in --post-link
|
|
1036
|
+
// mode.
|
|
1037
|
+
// TODO(sbc): Read INITIAL_MEMORY out of the wasm file in post-link mode.
|
|
1038
|
+
//assert(wasmMemory.buffer.byteLength === 16777216);
|
|
1039
|
+
updateMemoryViews();
|
|
1040
|
+
|
|
1041
|
+
wasmTable = Module['asm']['__indirect_function_table'];
|
|
1042
|
+
assert(wasmTable, "table not found in wasm exports");
|
|
1043
|
+
|
|
1044
|
+
removeRunDependency('wasm-instantiate');
|
|
1045
|
+
|
|
1046
|
+
return exports;
|
|
1047
|
+
}
|
|
1048
|
+
// wait for the pthread pool (if any)
|
|
1049
|
+
addRunDependency('wasm-instantiate');
|
|
1050
|
+
|
|
1051
|
+
// Prefer streaming instantiation if available.
|
|
1052
|
+
// Async compilation can be confusing when an error on the page overwrites Module
|
|
1053
|
+
// (for example, if the order of elements is wrong, and the one defining Module is
|
|
1054
|
+
// later), so we save Module and check it later.
|
|
1055
|
+
var trueModule = Module;
|
|
1056
|
+
function receiveInstantiationResult(result) {
|
|
1057
|
+
// 'result' is a ResultObject object which has both the module and instance.
|
|
1058
|
+
// receiveInstance() will swap in the exports (to Module.asm) so they can be called
|
|
1059
|
+
assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
|
|
1060
|
+
trueModule = null;
|
|
1061
|
+
// TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
|
|
1062
|
+
// When the regression is fixed, can restore the above PTHREADS-enabled path.
|
|
1063
|
+
receiveInstance(result['instance']);
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult);
|
|
1067
|
+
return {}; // no exports yet; we'll fill them in later
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
// include: runtime_debug.js
|
|
1071
|
+
/**
|
|
1072
|
+
* @license
|
|
1073
|
+
* Copyright 2020 The Emscripten Authors
|
|
1074
|
+
* SPDX-License-Identifier: MIT
|
|
1075
|
+
*/
|
|
1076
|
+
|
|
1077
|
+
function legacyModuleProp(prop, newName) {
|
|
1078
|
+
if (!Object.getOwnPropertyDescriptor(Module, prop)) {
|
|
1079
|
+
Object.defineProperty(Module, prop, {
|
|
1080
|
+
configurable: true,
|
|
1081
|
+
get: function () {
|
|
1082
|
+
abort('Module.' + prop + ' has been replaced with plain ' + newName + ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)');
|
|
1083
|
+
}
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
function ignoredModuleProp(prop) {
|
|
1089
|
+
if (Object.getOwnPropertyDescriptor(Module, prop)) {
|
|
1090
|
+
abort('`Module.' + prop + '` was supplied but `' + prop + '` not included in INCOMING_MODULE_JS_API');
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// forcing the filesystem exports a few things by default
|
|
1095
|
+
function isExportedByForceFilesystem(name) {
|
|
1096
|
+
return name === 'FS_createPath' ||
|
|
1097
|
+
name === 'FS_createDataFile' ||
|
|
1098
|
+
name === 'FS_createPreloadedFile' ||
|
|
1099
|
+
name === 'FS_unlink' ||
|
|
1100
|
+
name === 'addRunDependency' ||
|
|
1101
|
+
// The old FS has some functionality that WasmFS lacks.
|
|
1102
|
+
name === 'FS_createLazyFile' ||
|
|
1103
|
+
name === 'FS_createDevice' ||
|
|
1104
|
+
name === 'removeRunDependency';
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
function missingGlobal(sym, msg) {
|
|
1108
|
+
if (typeof globalThis !== 'undefined') {
|
|
1109
|
+
Object.defineProperty(globalThis, sym, {
|
|
1110
|
+
configurable: true,
|
|
1111
|
+
get: function () {
|
|
1112
|
+
warnOnce('`' + sym + '` is not longer defined by emscripten. ' + msg);
|
|
1113
|
+
return undefined;
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
missingGlobal('buffer', 'Please use HEAP8.buffer or wasmMemory.buffer');
|
|
1120
|
+
|
|
1121
|
+
function missingLibrarySymbol(sym) {
|
|
1122
|
+
if (typeof globalThis !== 'undefined' && !Object.getOwnPropertyDescriptor(globalThis, sym)) {
|
|
1123
|
+
Object.defineProperty(globalThis, sym, {
|
|
1124
|
+
configurable: true,
|
|
1125
|
+
get: function () {
|
|
1126
|
+
// Can't `abort()` here because it would break code that does runtime
|
|
1127
|
+
// checks. e.g. `if (typeof SDL === 'undefined')`.
|
|
1128
|
+
var msg = '`' + sym + '` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line';
|
|
1129
|
+
// DEFAULT_LIBRARY_FUNCS_TO_INCLUDE requires the name as it appears in
|
|
1130
|
+
// library.js, which means $name for a JS name with no prefix, or name
|
|
1131
|
+
// for a JS name like _name.
|
|
1132
|
+
var librarySymbol = sym;
|
|
1133
|
+
if (!librarySymbol.startsWith('_')) {
|
|
1134
|
+
librarySymbol = '$' + sym;
|
|
1135
|
+
}
|
|
1136
|
+
msg += " (e.g. -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=" + librarySymbol + ")";
|
|
1137
|
+
if (isExportedByForceFilesystem(sym)) {
|
|
1138
|
+
msg += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you';
|
|
1139
|
+
}
|
|
1140
|
+
warnOnce(msg);
|
|
1141
|
+
return undefined;
|
|
1142
|
+
}
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
// Any symbol that is not included from the JS libary is also (by definition)
|
|
1146
|
+
// not exported on the Module object.
|
|
1147
|
+
unexportedRuntimeSymbol(sym);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
function unexportedRuntimeSymbol(sym) {
|
|
1151
|
+
if (!Object.getOwnPropertyDescriptor(Module, sym)) {
|
|
1152
|
+
Object.defineProperty(Module, sym, {
|
|
1153
|
+
configurable: true,
|
|
1154
|
+
get: function () {
|
|
1155
|
+
var msg = "'" + sym + "' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the FAQ)";
|
|
1156
|
+
if (isExportedByForceFilesystem(sym)) {
|
|
1157
|
+
msg += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you';
|
|
1158
|
+
}
|
|
1159
|
+
abort(msg);
|
|
1160
|
+
}
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
// Used by XXXXX_DEBUG settings to output debug messages.
|
|
1166
|
+
function dbg(text) {
|
|
1167
|
+
// TODO(sbc): Make this configurable somehow. Its not always convenient for
|
|
1168
|
+
// logging to show up as errors.
|
|
1169
|
+
console.error.apply(console, arguments);
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
// end include: runtime_debug.js
|
|
1173
|
+
// === Body ===
|
|
1174
|
+
|
|
1175
|
+
|
|
1176
|
+
// end include: preamble.js
|
|
1177
|
+
|
|
1178
|
+
function embind_init_charCodes() {
|
|
1179
|
+
var codes = new Array(256);
|
|
1180
|
+
for (var i = 0; i < 256; ++i) {
|
|
1181
|
+
codes[i] = String.fromCharCode(i);
|
|
1182
|
+
}
|
|
1183
|
+
embind_charCodes = codes;
|
|
1184
|
+
}
|
|
1185
|
+
var embind_charCodes = undefined;
|
|
1186
|
+
function readLatin1String(ptr) {
|
|
1187
|
+
return ptr;
|
|
1188
|
+
/* var ret = "";
|
|
1189
|
+
var c = ptr;
|
|
1190
|
+
while (HEAPU8[c]) {
|
|
1191
|
+
ret += embind_charCodes[HEAPU8[c++]];
|
|
1192
|
+
}
|
|
1193
|
+
return ret; */
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
var awaitingDependencies = {};
|
|
1197
|
+
|
|
1198
|
+
var registeredTypes = {};
|
|
1199
|
+
|
|
1200
|
+
var typeDependencies = {};
|
|
1201
|
+
|
|
1202
|
+
var char_0 = 48;
|
|
1203
|
+
|
|
1204
|
+
var char_9 = 57;
|
|
1205
|
+
function makeLegalFunctionName(name) {
|
|
1206
|
+
if (undefined === name) {
|
|
1207
|
+
return '_unknown';
|
|
1208
|
+
}
|
|
1209
|
+
name = name.replace(/[^a-zA-Z0-9_]/g, '$');
|
|
1210
|
+
var f = name.charCodeAt(0);
|
|
1211
|
+
if (f >= char_0 && f <= char_9) {
|
|
1212
|
+
return '_' + name;
|
|
1213
|
+
}
|
|
1214
|
+
return name;
|
|
1215
|
+
}
|
|
1216
|
+
function createNamedFunction(name, body) {
|
|
1217
|
+
name = makeLegalFunctionName(name);
|
|
1218
|
+
// Use an abject with a computed property name to create a new function with
|
|
1219
|
+
// a name specified at runtime, but without using `new Function` or `eval`.
|
|
1220
|
+
return {
|
|
1221
|
+
[name]: function () {
|
|
1222
|
+
return body.apply(this, arguments);
|
|
1223
|
+
}
|
|
1224
|
+
}[name];
|
|
1225
|
+
}
|
|
1226
|
+
function extendError(baseErrorType, errorName) {
|
|
1227
|
+
var errorClass = createNamedFunction(errorName, function (message) {
|
|
1228
|
+
this.name = errorName;
|
|
1229
|
+
this.message = message;
|
|
1230
|
+
|
|
1231
|
+
var stack = (new Error(message)).stack;
|
|
1232
|
+
if (stack !== undefined) {
|
|
1233
|
+
this.stack = this.toString() + '\n' +
|
|
1234
|
+
stack.replace(/^Error(:[^\n]*)?\n/, '');
|
|
1235
|
+
}
|
|
1236
|
+
});
|
|
1237
|
+
errorClass.prototype = Object.create(baseErrorType.prototype);
|
|
1238
|
+
errorClass.prototype.constructor = errorClass;
|
|
1239
|
+
errorClass.prototype.toString = function () {
|
|
1240
|
+
if (this.message === undefined) {
|
|
1241
|
+
return this.name;
|
|
1242
|
+
} else {
|
|
1243
|
+
return this.name + ': ' + this.message;
|
|
1244
|
+
}
|
|
1245
|
+
};
|
|
1246
|
+
|
|
1247
|
+
return errorClass;
|
|
1248
|
+
}
|
|
1249
|
+
var BindingError = undefined;
|
|
1250
|
+
function throwBindingError(message) {
|
|
1251
|
+
console.log(message);
|
|
1252
|
+
throw new BindingError(message);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
var InternalError = undefined;
|
|
1259
|
+
function throwInternalError(message) {
|
|
1260
|
+
throw new InternalError(message);
|
|
1261
|
+
}
|
|
1262
|
+
function whenDependentTypesAreResolved(myTypes, dependentTypes, getTypeConverters) {
|
|
1263
|
+
myTypes.forEach(function (type) {
|
|
1264
|
+
typeDependencies[type] = dependentTypes;
|
|
1265
|
+
});
|
|
1266
|
+
|
|
1267
|
+
function onComplete(typeConverters) {
|
|
1268
|
+
var myTypeConverters = getTypeConverters(typeConverters);
|
|
1269
|
+
if (myTypeConverters.length !== myTypes.length) {
|
|
1270
|
+
throwInternalError('Mismatched type converter count');
|
|
1271
|
+
}
|
|
1272
|
+
for (var i = 0; i < myTypes.length; ++i) {
|
|
1273
|
+
registerType(myTypes[i], myTypeConverters[i]);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
var typeConverters = new Array(dependentTypes.length);
|
|
1278
|
+
var unregisteredTypes = [];
|
|
1279
|
+
var registered = 0;
|
|
1280
|
+
dependentTypes.forEach((dt, i) => {
|
|
1281
|
+
if (registeredTypes.hasOwnProperty(dt)) {
|
|
1282
|
+
typeConverters[i] = registeredTypes[dt];
|
|
1283
|
+
} else {
|
|
1284
|
+
unregisteredTypes.push(dt);
|
|
1285
|
+
if (!awaitingDependencies.hasOwnProperty(dt)) {
|
|
1286
|
+
awaitingDependencies[dt] = [];
|
|
1287
|
+
}
|
|
1288
|
+
awaitingDependencies[dt].push(() => {
|
|
1289
|
+
typeConverters[i] = registeredTypes[dt];
|
|
1290
|
+
++registered;
|
|
1291
|
+
if (registered === unregisteredTypes.length) {
|
|
1292
|
+
onComplete(typeConverters);
|
|
1293
|
+
}
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
});
|
|
1297
|
+
if (0 === unregisteredTypes.length) {
|
|
1298
|
+
onComplete(typeConverters);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
/** @param {Object=} options */
|
|
1302
|
+
function registerType(rawType, registeredInstance, options = {}) {
|
|
1303
|
+
// console.log('1', rawType);
|
|
1304
|
+
if (!('argPackAdvance' in registeredInstance)) {
|
|
1305
|
+
throw new TypeError('registerType registeredInstance requires argPackAdvance');
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
// console.log('2', rawType);
|
|
1309
|
+
var name = registeredInstance.name;
|
|
1310
|
+
if (!rawType) {
|
|
1311
|
+
throwBindingError(`type "${name}" must have a positive integer typeid pointer`);
|
|
1312
|
+
}
|
|
1313
|
+
// console.log('3', rawType);
|
|
1314
|
+
if (registeredTypes.hasOwnProperty(rawType)) {
|
|
1315
|
+
if (options.ignoreDuplicateRegistrations) {
|
|
1316
|
+
return;
|
|
1317
|
+
} else {
|
|
1318
|
+
throwBindingError(`Cannot register type '${name}' twice`);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
// console.log('4', rawType);
|
|
1322
|
+
registeredTypes[rawType] = registeredInstance;
|
|
1323
|
+
delete typeDependencies[rawType];
|
|
1324
|
+
// console.log('5', rawType);
|
|
1325
|
+
if (awaitingDependencies.hasOwnProperty(rawType)) {
|
|
1326
|
+
var callbacks = awaitingDependencies[rawType];
|
|
1327
|
+
delete awaitingDependencies[rawType];
|
|
1328
|
+
callbacks.forEach((cb) => cb());
|
|
1329
|
+
}
|
|
1330
|
+
// console.log('6', rawType);
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
function __embind_register_void(rawType, name) {
|
|
1334
|
+
name = readLatin1String(name);
|
|
1335
|
+
// console.log('__embind_register_void', name, rawType);
|
|
1336
|
+
registerType(rawType, {
|
|
1337
|
+
isVoid: true, // void return values can be optimized out sometimes
|
|
1338
|
+
name: name,
|
|
1339
|
+
'argPackAdvance': 0n,
|
|
1340
|
+
'fromWireType': function () {
|
|
1341
|
+
return undefined;
|
|
1342
|
+
},
|
|
1343
|
+
'toWireType': function (destructors, o) {
|
|
1344
|
+
// TODO: assert if anything else is given?
|
|
1345
|
+
return undefined;
|
|
1346
|
+
},
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
globalThis.__embind_register_void = __embind_register_void;
|
|
1350
|
+
|
|
1351
|
+
function __embind_register_jsiValue(rawType, name) {
|
|
1352
|
+
name = readLatin1String(name);
|
|
1353
|
+
// console.log('__embind_register_jsiValue', name, rawType);
|
|
1354
|
+
registerType(rawType, {
|
|
1355
|
+
isVoid: false, // void return values can be optimized out sometimes
|
|
1356
|
+
name: name,
|
|
1357
|
+
'argPackAdvance': 0n,
|
|
1358
|
+
'fromWireType': function (v) {
|
|
1359
|
+
return v;
|
|
1360
|
+
},
|
|
1361
|
+
'toWireType': function (destructors, o) {
|
|
1362
|
+
return o;
|
|
1363
|
+
},
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
globalThis.__embind_register_jsiValue = __embind_register_jsiValue;
|
|
1367
|
+
|
|
1368
|
+
function getShiftFromSize(size) {
|
|
1369
|
+
switch (size) {
|
|
1370
|
+
case 1: return 0;
|
|
1371
|
+
case 2: return 1;
|
|
1372
|
+
case 4: return 2;
|
|
1373
|
+
case 8: return 3;
|
|
1374
|
+
case 1n: return 0;
|
|
1375
|
+
case 2n: return 1;
|
|
1376
|
+
case 4n: return 2;
|
|
1377
|
+
case 8n: return 3;
|
|
1378
|
+
default:
|
|
1379
|
+
throw new TypeError('Unknown type size: ' + size);
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
function __embind_register_bool(rawType, name, size, trueValue, falseValue) {
|
|
1385
|
+
// console.log('bool', name, rawType, size, trueValue, falseValue);
|
|
1386
|
+
var shift = getShiftFromSize(size);
|
|
1387
|
+
|
|
1388
|
+
name = readLatin1String(name);
|
|
1389
|
+
registerType(rawType, {
|
|
1390
|
+
name: name,
|
|
1391
|
+
'fromWireType': function (wt) {
|
|
1392
|
+
// ambiguous emscripten ABI: sometimes return values are
|
|
1393
|
+
// true or false, and sometimes integers (0 or 1)
|
|
1394
|
+
return !!wt;
|
|
1395
|
+
},
|
|
1396
|
+
'toWireType': function (destructors, o) {
|
|
1397
|
+
return o ? trueValue : falseValue;
|
|
1398
|
+
},
|
|
1399
|
+
'argPackAdvance': 8n,
|
|
1400
|
+
'readValueFromPointer': function (pointer) {
|
|
1401
|
+
// console.log('__embind_register_bool readValueFromPointer', pointer);
|
|
1402
|
+
return this['fromWireType'](readFromMemoryUsingSize(pointer, true, size));
|
|
1403
|
+
},
|
|
1404
|
+
destructorFunction: null, // This type does not need a destructor
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
globalThis.__embind_register_bool = __embind_register_bool;
|
|
1408
|
+
|
|
1409
|
+
function __embind_register_optional(rawOptionalType, rawInnerType) {
|
|
1410
|
+
whenDependentTypesAreResolved([rawOptionalType], [rawInnerType], function (innerTypes) {
|
|
1411
|
+
var inner = innerTypes[0];
|
|
1412
|
+
return [{
|
|
1413
|
+
name: `std::optional<${inner.name}>`,
|
|
1414
|
+
// No value crosses as undefined (JS may also hand back null); a present value
|
|
1415
|
+
// rides the inner type's own converters unchanged.
|
|
1416
|
+
'fromWireType': function (wt) {
|
|
1417
|
+
if (wt === undefined || wt === null) return undefined;
|
|
1418
|
+
return inner['fromWireType'](wt);
|
|
1419
|
+
},
|
|
1420
|
+
'toWireType': function (destructors, o) {
|
|
1421
|
+
if (o === undefined || o === null) return undefined;
|
|
1422
|
+
return inner['toWireType'](destructors, o);
|
|
1423
|
+
},
|
|
1424
|
+
'argPackAdvance': 8n,
|
|
1425
|
+
'readValueFromPointer': function (pointer) {
|
|
1426
|
+
throw new Error(`std::optional<${inner.name}> cannot be read from raw memory`);
|
|
1427
|
+
},
|
|
1428
|
+
destructorFunction: null,
|
|
1429
|
+
}];
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
globalThis.__embind_register_optional = __embind_register_optional;
|
|
1433
|
+
|
|
1434
|
+
function embindRepr(v) {
|
|
1435
|
+
if (v === null) {
|
|
1436
|
+
return 'null';
|
|
1437
|
+
}
|
|
1438
|
+
var t = typeof v;
|
|
1439
|
+
if (t === 'object' || t === 'array' || t === 'function') {
|
|
1440
|
+
return v.toString();
|
|
1441
|
+
} else {
|
|
1442
|
+
return '' + v;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
function integerReadValueFromPointer(name, shift, signed) {
|
|
1448
|
+
// integers are quite common, so generate very specialized functions
|
|
1449
|
+
switch (shift) {
|
|
1450
|
+
case 0:
|
|
1451
|
+
case 0n: return signed ?
|
|
1452
|
+
function readS8FromPointer(pointer) { return readFromMemoryUsingShift(pointer, true, 0); } :
|
|
1453
|
+
function readU8FromPointer(pointer) { return readFromMemoryUsingShift(pointer, false, 0); };
|
|
1454
|
+
case 1:
|
|
1455
|
+
case 1n: return signed ?
|
|
1456
|
+
function readS16FromPointer(pointer) { return readFromMemoryUsingShift(pointer, true, 1); } :
|
|
1457
|
+
function readU16FromPointer(pointer) { return readFromMemoryUsingShift(pointer, false, 1); };
|
|
1458
|
+
case 2:
|
|
1459
|
+
case 2n: return signed ?
|
|
1460
|
+
function readS32FromPointer(pointer) { return readFromMemoryUsingShift(pointer, true, 2); } :
|
|
1461
|
+
function readU32FromPointer(pointer) { return readFromMemoryUsingShift(pointer, false, 2); };
|
|
1462
|
+
case 3:
|
|
1463
|
+
case 3n: return signed ?
|
|
1464
|
+
function readS64FromPointer(pointer) { return readFromMemoryUsingShift(pointer, true, 3); } :
|
|
1465
|
+
function readU64FromPointer(pointer) { return readFromMemoryUsingShift(pointer, false, 3); };
|
|
1466
|
+
default:
|
|
1467
|
+
throw new TypeError("Unknown integer type: " + name);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
|
|
1472
|
+
function __embind_register_integer(primitiveType, name, size, minRange, maxRange) {
|
|
1473
|
+
// console.log('integer', name, primitiveType, size, minRange, maxRange);
|
|
1474
|
+
name = readLatin1String(name);
|
|
1475
|
+
// LLVM doesn't have signed and unsigned 32-bit types, so u32 literals come
|
|
1476
|
+
// out as 'i32 -1'. Always treat those as max u32.
|
|
1477
|
+
/* if (maxRange === -1) {
|
|
1478
|
+
maxRange = 4294967295;
|
|
1479
|
+
} */
|
|
1480
|
+
|
|
1481
|
+
var shift = getShiftFromSize(size);
|
|
1482
|
+
|
|
1483
|
+
var fromWireType = (value) => value;
|
|
1484
|
+
|
|
1485
|
+
if (minRange === 0) {
|
|
1486
|
+
var bitshift = 32 - 8 * size;
|
|
1487
|
+
fromWireType = (value) => (value << bitshift) >>> bitshift;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
var isUnsignedType = (name.includes('unsigned'));
|
|
1491
|
+
var checkAssertions = (value, toTypeName) => {
|
|
1492
|
+
if (typeof value != "number" && typeof value != "boolean" && typeof value != "bigint") {
|
|
1493
|
+
throw new TypeError(`Cannot convert "${embindRepr(value)}" to ${toTypeName}`);
|
|
1494
|
+
}
|
|
1495
|
+
if (value < minRange || (maxRange !== -1 && shift !== 2 && shift !== 3 && value > maxRange)) {
|
|
1496
|
+
throw new TypeError(`Passing a number "${embindRepr(value)}" from JS side to C/C++ side to an argument of type "${name}", which is outside the valid range [${minRange}, ${maxRange}]!`);
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
var toWireType;
|
|
1500
|
+
if (isUnsignedType) {
|
|
1501
|
+
toWireType = function (destructors, value) {
|
|
1502
|
+
checkAssertions(value, this.name);
|
|
1503
|
+
return value >>> 0;
|
|
1504
|
+
}
|
|
1505
|
+
} else {
|
|
1506
|
+
toWireType = function (destructors, value) {
|
|
1507
|
+
checkAssertions(value, this.name);
|
|
1508
|
+
// The VM will perform JS to Wasm value conversion, according to the spec:
|
|
1509
|
+
// https://www.w3.org/TR/wasm-js-api-1/#towebassemblyvalue
|
|
1510
|
+
return value;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
registerType(primitiveType, {
|
|
1514
|
+
name: name,
|
|
1515
|
+
'fromWireType': fromWireType,
|
|
1516
|
+
'toWireType': toWireType,
|
|
1517
|
+
'argPackAdvance': 8n,
|
|
1518
|
+
'readValueFromPointer': integerReadValueFromPointer(name, shift, minRange !== 0),
|
|
1519
|
+
destructorFunction: null, // This type does not need a destructor
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
globalThis.__embind_register_integer = __embind_register_integer;
|
|
1524
|
+
|
|
1525
|
+
|
|
1526
|
+
|
|
1527
|
+
function __embind_register_bigint(primitiveType, name, size, minRange, maxRange) {
|
|
1528
|
+
// console.log('bigint', name, primitiveType, size, minRange, maxRange);
|
|
1529
|
+
name = readLatin1String(name);
|
|
1530
|
+
|
|
1531
|
+
var shift = getShiftFromSize(size);
|
|
1532
|
+
|
|
1533
|
+
var isUnsignedType = (name.indexOf('u') != -1);
|
|
1534
|
+
|
|
1535
|
+
// maxRange comes through as -1 for uint64_t (see issue 13902). Work around that temporarily
|
|
1536
|
+
if (isUnsignedType) {
|
|
1537
|
+
maxRange = (1n << 64n) - 1n;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
registerType(primitiveType, {
|
|
1541
|
+
name: name,
|
|
1542
|
+
'fromWireType': function (value) {
|
|
1543
|
+
return value;
|
|
1544
|
+
},
|
|
1545
|
+
'toWireType': function (destructors, value) {
|
|
1546
|
+
// console.log('__embind_register_bigint - toWireType');
|
|
1547
|
+
if (typeof value != "bigint" && typeof value != "number") {
|
|
1548
|
+
throw new TypeError(`Cannot convert "${embindRepr(value)}" to ${this.name}`);
|
|
1549
|
+
}
|
|
1550
|
+
if (value < minRange || value > maxRange) {
|
|
1551
|
+
throw new TypeError(`Passing a number "${embindRepr(value)}" from JS side to C/C++ side to an argument of type "${name}", which is outside the valid range [${minRange}, ${maxRange}]!`);
|
|
1552
|
+
}
|
|
1553
|
+
return BigInt(value);
|
|
1554
|
+
},
|
|
1555
|
+
'argPackAdvance': 8n,
|
|
1556
|
+
'readValueFromPointer': integerReadValueFromPointer(name, shift, !isUnsignedType),
|
|
1557
|
+
destructorFunction: null, // This type does not need a destructor
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
globalThis.__embind_register_bigint = __embind_register_bigint;
|
|
1562
|
+
|
|
1563
|
+
|
|
1564
|
+
function floatReadValueFromPointer(name, shift) {
|
|
1565
|
+
switch (shift) {
|
|
1566
|
+
case 2:
|
|
1567
|
+
case 2n:
|
|
1568
|
+
return function (pointer) {
|
|
1569
|
+
return readFromMemoryUsingShift(pointer, true, 2, true);
|
|
1570
|
+
};
|
|
1571
|
+
case 3:
|
|
1572
|
+
case 3n:
|
|
1573
|
+
return function (pointer) {
|
|
1574
|
+
return readFromMemoryUsingShift(pointer, true, 3, true);
|
|
1575
|
+
};
|
|
1576
|
+
default:
|
|
1577
|
+
throw new TypeError("Unknown float type: " + name);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
|
|
1582
|
+
|
|
1583
|
+
function __embind_register_float(rawType, name, size) {
|
|
1584
|
+
// console.log('float', name, rawType, size);
|
|
1585
|
+
var shift = getShiftFromSize(size);
|
|
1586
|
+
name = readLatin1String(name);
|
|
1587
|
+
registerType(rawType, {
|
|
1588
|
+
name: name,
|
|
1589
|
+
'fromWireType': function (value) {
|
|
1590
|
+
return value;
|
|
1591
|
+
},
|
|
1592
|
+
'toWireType': function (destructors, value) {
|
|
1593
|
+
if (typeof value != "number" && typeof value != "boolean") {
|
|
1594
|
+
throw new TypeError(`Cannot convert ${embindRepr(value)} to ${this.name}`);
|
|
1595
|
+
}
|
|
1596
|
+
// The VM will perform JS to Wasm value conversion, according to the spec:
|
|
1597
|
+
// https://www.w3.org/TR/wasm-js-api-1/#towebassemblyvalue
|
|
1598
|
+
return value;
|
|
1599
|
+
},
|
|
1600
|
+
'argPackAdvance': 8n,
|
|
1601
|
+
'readValueFromPointer': floatReadValueFromPointer(name, shift),
|
|
1602
|
+
destructorFunction: null, // This type does not need a destructor
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
globalThis.__embind_register_float = __embind_register_float;
|
|
1607
|
+
|
|
1608
|
+
|
|
1609
|
+
function simpleReadValueFromPointer(pointer) {
|
|
1610
|
+
/* console.log(
|
|
1611
|
+
'simpleReadValueFromPointer :',
|
|
1612
|
+
this.name, JSON.stringify(pointer, null, 2),
|
|
1613
|
+
readFromMemoryUsingShift(pointer, true, 2)
|
|
1614
|
+
); */
|
|
1615
|
+
return this['fromWireType'](readFromMemoryUsingShift(pointer, true, 2));
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
function simpleReadValueFromPointer64(pointer) {
|
|
1619
|
+
/* console.log(
|
|
1620
|
+
'simpleReadValueFromPointer :',
|
|
1621
|
+
this.name, JSON.stringify(pointer, null, 3),
|
|
1622
|
+
readFromMemoryUsingShift(pointer, true, 3)
|
|
1623
|
+
); */
|
|
1624
|
+
return this['fromWireType'](readFromMemoryUsingShift(pointer, false, 3));
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
|
|
1628
|
+
function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
|
|
1629
|
+
// console.log('stringToUTF8Array');
|
|
1630
|
+
assert(typeof str === 'string');
|
|
1631
|
+
// Parameter maxBytesToWrite is not optional. Negative values, 0, null,
|
|
1632
|
+
// undefined and false each don't write out any bytes.
|
|
1633
|
+
if (!(maxBytesToWrite > 0))
|
|
1634
|
+
return 0;
|
|
1635
|
+
|
|
1636
|
+
var startIdx = outIdx;
|
|
1637
|
+
var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
|
|
1638
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1639
|
+
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
|
|
1640
|
+
// unit, not a Unicode code point of the character! So decode
|
|
1641
|
+
// UTF16->UTF32->UTF8.
|
|
1642
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
1643
|
+
// For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description
|
|
1644
|
+
// and https://www.ietf.org/rfc/rfc2279.txt
|
|
1645
|
+
// and https://tools.ietf.org/html/rfc3629
|
|
1646
|
+
var u = str.charCodeAt(i); // possibly a lead surrogate
|
|
1647
|
+
if (u >= 0xD800 && u <= 0xDFFF) {
|
|
1648
|
+
var u1 = str.charCodeAt(++i);
|
|
1649
|
+
u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF);
|
|
1650
|
+
}
|
|
1651
|
+
if (u <= 0x7F) {
|
|
1652
|
+
if (outIdx >= endIdx) break;
|
|
1653
|
+
heap[outIdx++] = u;
|
|
1654
|
+
} else if (u <= 0x7FF) {
|
|
1655
|
+
if (outIdx + 1 >= endIdx) break;
|
|
1656
|
+
heap[outIdx++] = 0xC0 | (u >> 6);
|
|
1657
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
1658
|
+
} else if (u <= 0xFFFF) {
|
|
1659
|
+
if (outIdx + 2 >= endIdx) break;
|
|
1660
|
+
heap[outIdx++] = 0xE0 | (u >> 12);
|
|
1661
|
+
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
1662
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
1663
|
+
} else {
|
|
1664
|
+
if (outIdx + 3 >= endIdx) break;
|
|
1665
|
+
if (u > 0x10FFFF) warnOnce('Invalid Unicode code point ' + ptrToString(u) + ' encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).');
|
|
1666
|
+
heap[outIdx++] = 0xF0 | (u >> 18);
|
|
1667
|
+
heap[outIdx++] = 0x80 | ((u >> 12) & 63);
|
|
1668
|
+
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
1669
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
// Null-terminate the pointer to the buffer.
|
|
1673
|
+
heap[outIdx] = 0;
|
|
1674
|
+
return outIdx - startIdx;
|
|
1675
|
+
}
|
|
1676
|
+
function stringToUTF8(str, outPtr, maxBytesToWrite) {
|
|
1677
|
+
assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
|
|
1678
|
+
|
|
1679
|
+
const index = getHeapIndex(outPtr);
|
|
1680
|
+
return stringToUTF8Array(str, HEAPU8[index], outPtr - HEAP_OFFSET[index], maxBytesToWrite);
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
function lengthBytesUTF8(str) {
|
|
1684
|
+
var len = 0;
|
|
1685
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1686
|
+
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
|
|
1687
|
+
// unit, not a Unicode code point of the character! So decode
|
|
1688
|
+
// UTF16->UTF32->UTF8.
|
|
1689
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
1690
|
+
var c = str.charCodeAt(i); // possibly a lead surrogate
|
|
1691
|
+
if (c <= 0x7F) {
|
|
1692
|
+
len++;
|
|
1693
|
+
} else if (c <= 0x7FF) {
|
|
1694
|
+
len += 2;
|
|
1695
|
+
} else if (c >= 0xD800 && c <= 0xDFFF) {
|
|
1696
|
+
len += 4; ++i;
|
|
1697
|
+
} else {
|
|
1698
|
+
len += 3;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
return len;
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
var UTF8Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder('utf8') : undefined;
|
|
1705
|
+
|
|
1706
|
+
/**
|
|
1707
|
+
* Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
|
|
1708
|
+
* array that contains uint8 values, returns a copy of that string as a
|
|
1709
|
+
* Javascript String object.
|
|
1710
|
+
* heapOrArray is either a regular array, or a JavaScript typed array view.
|
|
1711
|
+
* @param {number} idx
|
|
1712
|
+
* @param {number=} maxBytesToRead
|
|
1713
|
+
* @return {string}
|
|
1714
|
+
*/
|
|
1715
|
+
function UTF8ArrayToString(heapOrArray, idx, maxBytesToRead) {
|
|
1716
|
+
var endIdx = idx + maxBytesToRead;
|
|
1717
|
+
var endPtr = idx;
|
|
1718
|
+
// TextDecoder needs to know the byte length in advance, it doesn't stop on
|
|
1719
|
+
// null terminator by itself. Also, use the length info to avoid running tiny
|
|
1720
|
+
// strings through TextDecoder, since .subarray() allocates garbage.
|
|
1721
|
+
// (As a tiny code save trick, compare endPtr against endIdx using a negation,
|
|
1722
|
+
// so that undefined means Infinity)
|
|
1723
|
+
while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
|
|
1724
|
+
|
|
1725
|
+
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
|
|
1726
|
+
return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
|
|
1727
|
+
}
|
|
1728
|
+
var str = '';
|
|
1729
|
+
// If building with TextDecoder, we have already computed the string length
|
|
1730
|
+
// above, so test loop end condition against that
|
|
1731
|
+
while (idx < endPtr) {
|
|
1732
|
+
// For UTF8 byte structure, see:
|
|
1733
|
+
// http://en.wikipedia.org/wiki/UTF-8#Description
|
|
1734
|
+
// https://www.ietf.org/rfc/rfc2279.txt
|
|
1735
|
+
// https://tools.ietf.org/html/rfc3629
|
|
1736
|
+
var u0 = heapOrArray[idx++];
|
|
1737
|
+
if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
|
|
1738
|
+
var u1 = heapOrArray[idx++] & 63;
|
|
1739
|
+
if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
|
|
1740
|
+
var u2 = heapOrArray[idx++] & 63;
|
|
1741
|
+
if ((u0 & 0xF0) == 0xE0) {
|
|
1742
|
+
u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
|
|
1743
|
+
} else {
|
|
1744
|
+
if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte ' + ptrToString(u0) + ' encountered when deserializing a UTF-8 string in wasm memory to a JS string!');
|
|
1745
|
+
u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
if (u0 < 0x10000) {
|
|
1749
|
+
str += String.fromCharCode(u0);
|
|
1750
|
+
} else {
|
|
1751
|
+
var ch = u0 - 0x10000;
|
|
1752
|
+
str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
return str;
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
|
|
1759
|
+
/**
|
|
1760
|
+
* Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
|
|
1761
|
+
* emscripten HEAP, returns a copy of that string as a Javascript String object.
|
|
1762
|
+
*
|
|
1763
|
+
* @param {number} ptr
|
|
1764
|
+
* @param {number=} maxBytesToRead - An optional length that specifies the
|
|
1765
|
+
* maximum number of bytes to read. You can omit this parameter to scan the
|
|
1766
|
+
* string until the first 0 byte. If maxBytesToRead is passed, and the string
|
|
1767
|
+
* at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
|
|
1768
|
+
* string will cut short at that byte index (i.e. maxBytesToRead will not
|
|
1769
|
+
* produce a string of exact length [ptr, ptr+maxBytesToRead[) N.B. mixing
|
|
1770
|
+
* frequent uses of UTF8ToString() with and without maxBytesToRead may throw
|
|
1771
|
+
* JS JIT optimizations off, so it is worth to consider consistently using one
|
|
1772
|
+
* @return {string}
|
|
1773
|
+
*/
|
|
1774
|
+
function UTF8ToString(ptr, maxBytesToRead) {
|
|
1775
|
+
assert(typeof ptr === 'bigint' || typeof ptr === 'number');
|
|
1776
|
+
const index = getHeapIndex(ptr);
|
|
1777
|
+
|
|
1778
|
+
return ptr ? UTF8ArrayToString(HEAPU8[index], ptr - HEAP_OFFSET[index], maxBytesToRead) : '';
|
|
1779
|
+
}
|
|
1780
|
+
function __embind_register_std_string(rawType, name) {
|
|
1781
|
+
name = readLatin1String(name);
|
|
1782
|
+
var stdStringIsUTF8
|
|
1783
|
+
//process only std::string bindings with UTF8 support, in contrast to e.g. std::basic_string<unsigned char>
|
|
1784
|
+
= (name === "std::string");
|
|
1785
|
+
|
|
1786
|
+
registerType(rawType, {
|
|
1787
|
+
name: name,
|
|
1788
|
+
'fromWireType': function (value) {
|
|
1789
|
+
if (typeof value !== 'bigint') {
|
|
1790
|
+
return value;
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
var length = readFromMemoryUsingShift(value, false, 2) //HEAPU32[value >> 2];
|
|
1794
|
+
var payload = value + 8n;
|
|
1795
|
+
var str;
|
|
1796
|
+
if (stdStringIsUTF8) {
|
|
1797
|
+
var decodeStartPtr = payload;
|
|
1798
|
+
for (var i = 0n; i <= length; ++i) {
|
|
1799
|
+
var currentBytePtr = payload + i;
|
|
1800
|
+
const heapIndex = getHeapIndex(currentBytePtr);
|
|
1801
|
+
if (i == length || HEAPU8[heapIndex][currentBytePtr - HEAP_OFFSET[heapIndex]] == 0) {
|
|
1802
|
+
var maxRead = currentBytePtr - decodeStartPtr;
|
|
1803
|
+
var stringSegment = UTF8ToString(decodeStartPtr, maxRead);
|
|
1804
|
+
if (str === undefined) {
|
|
1805
|
+
str = stringSegment
|
|
1806
|
+
} else {
|
|
1807
|
+
str += String.fromCharCode(0);
|
|
1808
|
+
str += stringSegment
|
|
1809
|
+
}
|
|
1810
|
+
decodeStartPtr = currentBytePtr + 1n
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
} else {
|
|
1814
|
+
/* var a = new Array(length);
|
|
1815
|
+
for (var i = 0; i < length; ++i) {
|
|
1816
|
+
a[i] = String.fromCharCode(HEAPU8[payload + i])
|
|
1817
|
+
}
|
|
1818
|
+
str = a.join("") */
|
|
1819
|
+
}
|
|
1820
|
+
_free(value);
|
|
1821
|
+
return str;
|
|
1822
|
+
},
|
|
1823
|
+
'toWireType': function (destructors, value, usePointer = false) {
|
|
1824
|
+
return value;
|
|
1825
|
+
/* if (!usePointer) {
|
|
1826
|
+
return value;
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
if (value instanceof ArrayBuffer) {
|
|
1830
|
+
value = new Uint8Array(value)
|
|
1831
|
+
}
|
|
1832
|
+
var length;
|
|
1833
|
+
var valueIsOfTypeString = typeof value == "string";
|
|
1834
|
+
if (!(valueIsOfTypeString || value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int8Array)) {
|
|
1835
|
+
throwBindingError("Cannot pass non-string to std::string")
|
|
1836
|
+
}
|
|
1837
|
+
if (stdStringIsUTF8 && valueIsOfTypeString) {
|
|
1838
|
+
length = lengthBytesUTF8(value)
|
|
1839
|
+
} else {
|
|
1840
|
+
length = value.length
|
|
1841
|
+
}
|
|
1842
|
+
var base = _malloc(4 + length + 1);
|
|
1843
|
+
var ptr = base + 4;
|
|
1844
|
+
|
|
1845
|
+
writeToMemoryUsingShift(base, false, 2, length); // HEAPU32[base >> 2] = length;
|
|
1846
|
+
if (stdStringIsUTF8 && valueIsOfTypeString) {
|
|
1847
|
+
stringToUTF8(value, ptr, length + 1)
|
|
1848
|
+
} else {
|
|
1849
|
+
if (valueIsOfTypeString) {
|
|
1850
|
+
for (var i = 0; i < length; ++i) {
|
|
1851
|
+
var charCode = value.charCodeAt(i);
|
|
1852
|
+
if (charCode > 255) {
|
|
1853
|
+
_free(ptr);
|
|
1854
|
+
throwBindingError("String has UTF-16 code units that do not fit in 8 bits")
|
|
1855
|
+
}
|
|
1856
|
+
writeToMemoryUsingShift(ptr + i, false, 0, charCode); // HEAPU8[ptr + i] = charCode
|
|
1857
|
+
}
|
|
1858
|
+
} else {
|
|
1859
|
+
for (var i = 0; i < length; ++i) {
|
|
1860
|
+
writeToMemoryUsingShift(ptr + i, false, 0, value[i]); //HEAPU8[ptr + i] = value[i]
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
if (destructors !== null) {
|
|
1865
|
+
destructors.push(_free, base)
|
|
1866
|
+
}
|
|
1867
|
+
return base; */
|
|
1868
|
+
},
|
|
1869
|
+
'argPackAdvance': 8n,
|
|
1870
|
+
'readValueFromPointer': simpleReadValueFromPointer64,
|
|
1871
|
+
destructorFunction: function (ptr) { _free(ptr); },
|
|
1872
|
+
});
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
globalThis.__embind_register_std_string = __embind_register_std_string;
|
|
1876
|
+
|
|
1877
|
+
|
|
1878
|
+
var UTF16Decoder = (function () {
|
|
1879
|
+
try {
|
|
1880
|
+
return typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-16le') : undefined;
|
|
1881
|
+
} catch (e) {
|
|
1882
|
+
return undefined;
|
|
1883
|
+
}
|
|
1884
|
+
})();
|
|
1885
|
+
function UTF16ToString(ptr, maxBytesToRead) {
|
|
1886
|
+
assert(ptr % 2 == 0, 'Pointer passed to UTF16ToString must be aligned to two bytes!');
|
|
1887
|
+
var endPtr = ptr;
|
|
1888
|
+
// TextDecoder needs to know the byte length in advance, it doesn't stop on
|
|
1889
|
+
// null terminator by itself.
|
|
1890
|
+
// Also, use the length info to avoid running tiny strings through
|
|
1891
|
+
// TextDecoder, since .subarray() allocates garbage.
|
|
1892
|
+
var idx = endPtr >> 1;
|
|
1893
|
+
var maxIdx = idx + maxBytesToRead / 2;
|
|
1894
|
+
// If maxBytesToRead is not passed explicitly, it will be undefined, and this
|
|
1895
|
+
// will always evaluate to true. This saves on code size.
|
|
1896
|
+
while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx;
|
|
1897
|
+
endPtr = idx << 1;
|
|
1898
|
+
|
|
1899
|
+
if (endPtr - ptr > 32 && UTF16Decoder)
|
|
1900
|
+
return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr));
|
|
1901
|
+
|
|
1902
|
+
// Fallback: decode without UTF16Decoder
|
|
1903
|
+
var str = '';
|
|
1904
|
+
|
|
1905
|
+
// If maxBytesToRead is not passed explicitly, it will be undefined, and the
|
|
1906
|
+
// for-loop's condition will always evaluate to true. The loop is then
|
|
1907
|
+
// terminated on the first null char.
|
|
1908
|
+
for (var i = 0; !(i >= maxBytesToRead / 2); ++i) {
|
|
1909
|
+
var codeUnit = HEAP16[(((ptr) + (i * 2)) >> 1)];
|
|
1910
|
+
if (codeUnit == 0) break;
|
|
1911
|
+
// fromCharCode constructs a character from a UTF-16 code unit, so we can
|
|
1912
|
+
// pass the UTF16 string right through.
|
|
1913
|
+
str += String.fromCharCode(codeUnit);
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
return str;
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
function stringToUTF16(str, outPtr, maxBytesToWrite) {
|
|
1920
|
+
assert(outPtr % 2 == 0, 'Pointer passed to stringToUTF16 must be aligned to two bytes!');
|
|
1921
|
+
assert(typeof maxBytesToWrite == 'number', 'stringToUTF16(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
|
|
1922
|
+
// Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
|
|
1923
|
+
if (maxBytesToWrite === undefined) {
|
|
1924
|
+
maxBytesToWrite = 0x7FFFFFFF;
|
|
1925
|
+
}
|
|
1926
|
+
if (maxBytesToWrite < 2) return 0;
|
|
1927
|
+
maxBytesToWrite -= 2; // Null terminator.
|
|
1928
|
+
var startPtr = outPtr;
|
|
1929
|
+
var numCharsToWrite = (maxBytesToWrite < str.length * 2) ? (maxBytesToWrite / 2) : str.length;
|
|
1930
|
+
for (var i = 0; i < numCharsToWrite; ++i) {
|
|
1931
|
+
// charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP.
|
|
1932
|
+
var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
|
|
1933
|
+
HEAP16[((outPtr) >> 1)] = codeUnit;
|
|
1934
|
+
outPtr += 2;
|
|
1935
|
+
}
|
|
1936
|
+
// Null-terminate the pointer to the HEAP.
|
|
1937
|
+
HEAP16[((outPtr) >> 1)] = 0;
|
|
1938
|
+
return outPtr - startPtr;
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
function lengthBytesUTF16(str) {
|
|
1942
|
+
return str.length * 2;
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
function UTF32ToString(ptr, maxBytesToRead) {
|
|
1946
|
+
assert(ptr % 4 == 0, 'Pointer passed to UTF32ToString must be aligned to four bytes!');
|
|
1947
|
+
var i = 0;
|
|
1948
|
+
|
|
1949
|
+
var str = '';
|
|
1950
|
+
// If maxBytesToRead is not passed explicitly, it will be undefined, and this
|
|
1951
|
+
// will always evaluate to true. This saves on code size.
|
|
1952
|
+
while (!(i >= maxBytesToRead / 4)) {
|
|
1953
|
+
var utf32 = HEAP32[(((ptr) + (i * 4)) >> 2)];
|
|
1954
|
+
if (utf32 == 0) break;
|
|
1955
|
+
++i;
|
|
1956
|
+
// Gotcha: fromCharCode constructs a character from a UTF-16 encoded code (pair), not from a Unicode code point! So encode the code point to UTF-16 for constructing.
|
|
1957
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
1958
|
+
if (utf32 >= 0x10000) {
|
|
1959
|
+
var ch = utf32 - 0x10000;
|
|
1960
|
+
str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
|
|
1961
|
+
} else {
|
|
1962
|
+
str += String.fromCharCode(utf32);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
return str;
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
function stringToUTF32(str, outPtr, maxBytesToWrite) {
|
|
1969
|
+
assert(outPtr % 4 == 0, 'Pointer passed to stringToUTF32 must be aligned to four bytes!');
|
|
1970
|
+
assert(typeof maxBytesToWrite == 'number', 'stringToUTF32(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
|
|
1971
|
+
// Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
|
|
1972
|
+
if (maxBytesToWrite === undefined) {
|
|
1973
|
+
maxBytesToWrite = 0x7FFFFFFF;
|
|
1974
|
+
}
|
|
1975
|
+
if (maxBytesToWrite < 4) return 0;
|
|
1976
|
+
var startPtr = outPtr;
|
|
1977
|
+
var endPtr = startPtr + maxBytesToWrite - 4;
|
|
1978
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1979
|
+
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
|
|
1980
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
1981
|
+
var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
|
|
1982
|
+
if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {
|
|
1983
|
+
var trailSurrogate = str.charCodeAt(++i);
|
|
1984
|
+
codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF);
|
|
1985
|
+
}
|
|
1986
|
+
HEAP32[((outPtr) >> 2)] = codeUnit;
|
|
1987
|
+
outPtr += 4;
|
|
1988
|
+
if (outPtr + 4 > endPtr) break;
|
|
1989
|
+
}
|
|
1990
|
+
// Null-terminate the pointer to the HEAP.
|
|
1991
|
+
HEAP32[((outPtr) >> 2)] = 0;
|
|
1992
|
+
return outPtr - startPtr;
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
function lengthBytesUTF32(str) {
|
|
1996
|
+
var len = 0;
|
|
1997
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1998
|
+
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
|
|
1999
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
2000
|
+
var codeUnit = str.charCodeAt(i);
|
|
2001
|
+
if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) ++i; // possibly a lead surrogate, so skip over the tail surrogate.
|
|
2002
|
+
len += 4;
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
return len;
|
|
2006
|
+
}
|
|
2007
|
+
function __embind_register_std_wstring(rawType, charSize, name) {
|
|
2008
|
+
name = readLatin1String(name);
|
|
2009
|
+
var decodeString, encodeString, getHeap, lengthBytesUTF, shift;
|
|
2010
|
+
if (charSize === 2) {
|
|
2011
|
+
decodeString = UTF16ToString;
|
|
2012
|
+
encodeString = stringToUTF16;
|
|
2013
|
+
lengthBytesUTF = lengthBytesUTF16;
|
|
2014
|
+
getHeap = () => HEAPU16;
|
|
2015
|
+
shift = 1;
|
|
2016
|
+
} else if (charSize === 4) {
|
|
2017
|
+
decodeString = UTF32ToString;
|
|
2018
|
+
encodeString = stringToUTF32;
|
|
2019
|
+
lengthBytesUTF = lengthBytesUTF32;
|
|
2020
|
+
getHeap = () => HEAPU32;
|
|
2021
|
+
shift = 2;
|
|
2022
|
+
}
|
|
2023
|
+
registerType(rawType, {
|
|
2024
|
+
name: name,
|
|
2025
|
+
'fromWireType': function (value) {
|
|
2026
|
+
// Code mostly taken from _embind_register_std_string fromWireType
|
|
2027
|
+
var length = HEAPU32[value >> 2];
|
|
2028
|
+
var HEAP = getHeap();
|
|
2029
|
+
var str;
|
|
2030
|
+
|
|
2031
|
+
var decodeStartPtr = value + 4;
|
|
2032
|
+
// Looping here to support possible embedded '0' bytes
|
|
2033
|
+
for (var i = 0; i <= length; ++i) {
|
|
2034
|
+
var currentBytePtr = value + 4 + i * charSize;
|
|
2035
|
+
if (i == length || HEAP[currentBytePtr >> shift] == 0) {
|
|
2036
|
+
var maxReadBytes = currentBytePtr - decodeStartPtr;
|
|
2037
|
+
var stringSegment = decodeString(decodeStartPtr, maxReadBytes);
|
|
2038
|
+
if (str === undefined) {
|
|
2039
|
+
str = stringSegment;
|
|
2040
|
+
} else {
|
|
2041
|
+
str += String.fromCharCode(0);
|
|
2042
|
+
str += stringSegment;
|
|
2043
|
+
}
|
|
2044
|
+
decodeStartPtr = currentBytePtr + charSize;
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
_free(value);
|
|
2049
|
+
|
|
2050
|
+
return str;
|
|
2051
|
+
},
|
|
2052
|
+
'toWireType': function (destructors, value) {
|
|
2053
|
+
if (!(typeof value == 'string')) {
|
|
2054
|
+
throwBindingError('Cannot pass non-string to C++ string type ' + name);
|
|
2055
|
+
}
|
|
2056
|
+
// console.log('registerType toWireType');
|
|
2057
|
+
|
|
2058
|
+
// assumes 4-byte alignment
|
|
2059
|
+
var length = lengthBytesUTF(value);
|
|
2060
|
+
var ptr = _malloc(4 + length + charSize);
|
|
2061
|
+
HEAPU32[ptr >> 2] = length >> shift;
|
|
2062
|
+
|
|
2063
|
+
encodeString(value, ptr + 4, length + charSize);
|
|
2064
|
+
|
|
2065
|
+
if (destructors !== null) {
|
|
2066
|
+
destructors.push(_free, ptr);
|
|
2067
|
+
}
|
|
2068
|
+
return ptr;
|
|
2069
|
+
},
|
|
2070
|
+
'argPackAdvance': 8n,
|
|
2071
|
+
'readValueFromPointer': simpleReadValueFromPointer,
|
|
2072
|
+
destructorFunction: function (ptr) { _free(ptr); },
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
globalThis.__embind_register_std_wstring = __embind_register_std_wstring;
|
|
2077
|
+
|
|
2078
|
+
function HandleAllocator() {
|
|
2079
|
+
this.allocated = [undefined];
|
|
2080
|
+
this.freelist = [];
|
|
2081
|
+
this.get = function (id) {
|
|
2082
|
+
// console.log('HandleAllocator get', id);
|
|
2083
|
+
return this.allocated[Number(id)];
|
|
2084
|
+
};
|
|
2085
|
+
this.allocate = function (handle) {
|
|
2086
|
+
var id = this.freelist.pop() || this.allocated.length;
|
|
2087
|
+
// console.log('HandleAllocator allocate', id, JSON.stringify(handle));
|
|
2088
|
+
this.allocated[id] = handle;
|
|
2089
|
+
return BigInt(id);
|
|
2090
|
+
};
|
|
2091
|
+
this.free = function (id) {
|
|
2092
|
+
const id2 = Number(id);
|
|
2093
|
+
// console.log('HandleAllocator free', id);
|
|
2094
|
+
// Set the slot to `undefined` rather than using `delete` here since
|
|
2095
|
+
// apparently arrays with holes in them can be less efficient.
|
|
2096
|
+
if (typeof id2 === 'number' && isFinite(id2)) {
|
|
2097
|
+
this.allocated[id2] = undefined;
|
|
2098
|
+
this.freelist.push(id2);
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
}
|
|
2102
|
+
var emval_handles = new HandleAllocator();;
|
|
2103
|
+
function __emval_decref(handle) {
|
|
2104
|
+
// console.log('__emval_decref');
|
|
2105
|
+
if (handle >= emval_handles.reserved && 0 === --emval_handles.get(handle).refcount) {
|
|
2106
|
+
emval_handles.free(handle);
|
|
2107
|
+
}
|
|
2108
|
+
// console.log('__emval_decref2');
|
|
2109
|
+
}
|
|
2110
|
+
globalThis.__emval_decref = __emval_decref;
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
|
|
2114
|
+
function count_emval_handles() {
|
|
2115
|
+
var count = 0;
|
|
2116
|
+
for (var i = emval_handles.reserved; i < emval_handles.allocated.length; ++i) {
|
|
2117
|
+
if (emval_handles.allocated[i] !== undefined) {
|
|
2118
|
+
++count;
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
return count;
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
function init_emval() {
|
|
2125
|
+
// reserve some special values. These never get de-allocated.
|
|
2126
|
+
// The HandleAllocator takes care of reserving zero.
|
|
2127
|
+
emval_handles.allocated.push(
|
|
2128
|
+
{ value: undefined },
|
|
2129
|
+
{ value: null },
|
|
2130
|
+
{ value: true },
|
|
2131
|
+
{ value: false },
|
|
2132
|
+
);
|
|
2133
|
+
emval_handles.reserved = emval_handles.allocated.length
|
|
2134
|
+
Module['count_emval_handles'] = count_emval_handles;
|
|
2135
|
+
}
|
|
2136
|
+
var Emval = {
|
|
2137
|
+
toValue: (handle) => {
|
|
2138
|
+
if (!handle || !emval_handles.get(handle)) {
|
|
2139
|
+
throwBindingError('Cannot use deleted val. handle = ' + handle);
|
|
2140
|
+
}
|
|
2141
|
+
return emval_handles.get(handle).value;
|
|
2142
|
+
}, toHandle: (value) => {
|
|
2143
|
+
// console.log('Emval toHandle', value);
|
|
2144
|
+
switch (value) {
|
|
2145
|
+
case undefined: return 1n;
|
|
2146
|
+
case null: return 2n;
|
|
2147
|
+
case true: return 3n;
|
|
2148
|
+
case false: return 4n;
|
|
2149
|
+
default: {
|
|
2150
|
+
const r = emval_handles.allocate({ refcount: 1, value: value });
|
|
2151
|
+
// console.log('Emval toHandle default: ', r);
|
|
2152
|
+
return r;
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
};
|
|
2157
|
+
|
|
2158
|
+
|
|
2159
|
+
|
|
2160
|
+
function __embind_register_emval(rawType, name) {
|
|
2161
|
+
name = readLatin1String(name);
|
|
2162
|
+
registerType(rawType, {
|
|
2163
|
+
name: name,
|
|
2164
|
+
'fromWireType': function (handle) {
|
|
2165
|
+
// console.log('emval fromWireType1', registeredTypes[rawType], this.name, handle);
|
|
2166
|
+
var rv = Emval.toValue(handle);
|
|
2167
|
+
// console.log('emval fromWireType2', rv);
|
|
2168
|
+
__emval_decref(handle);
|
|
2169
|
+
// console.log('emval fromWireType 2');
|
|
2170
|
+
return rv;
|
|
2171
|
+
},
|
|
2172
|
+
'toWireType': function (destructors, value) {
|
|
2173
|
+
// console.log('emval toWireType');
|
|
2174
|
+
return Emval.toHandle(value);
|
|
2175
|
+
},
|
|
2176
|
+
'argPackAdvance': 8n,
|
|
2177
|
+
'readValueFromPointer': simpleReadValueFromPointer,
|
|
2178
|
+
destructorFunction: null, // This type does not need a destructor
|
|
2179
|
+
|
|
2180
|
+
// TODO: do we need a deleteObject here? write a test where
|
|
2181
|
+
// emval is passed into JS via an interface
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
globalThis.__embind_register_emval = __embind_register_emval;
|
|
2186
|
+
|
|
2187
|
+
// crossbind JSON-value hooks (embind-rust serde_json::Value): handle-based on purpose - the
|
|
2188
|
+
// emval string plumbing reads wasm-heap pointers, which the native runtime has none of.
|
|
2189
|
+
function __crossbind_json_to_handle(text) {
|
|
2190
|
+
return Emval.toHandle(JSON.parse(text));
|
|
2191
|
+
}
|
|
2192
|
+
globalThis.__crossbind_json_to_handle = __crossbind_json_to_handle;
|
|
2193
|
+
|
|
2194
|
+
function __crossbind_handle_to_json(handle) {
|
|
2195
|
+
const s = JSON.stringify(Emval.toValue(handle));
|
|
2196
|
+
__emval_decref(handle);
|
|
2197
|
+
return s === undefined ? 'null' : s;
|
|
2198
|
+
}
|
|
2199
|
+
globalThis.__crossbind_handle_to_json = __crossbind_handle_to_json;
|
|
2200
|
+
|
|
2201
|
+
// crossbind live-value hooks (embind-rust JsValue/JsFunction): handle-based like the JSON pair;
|
|
2202
|
+
// strings travel as jsi strings, handles as the table's BigInts.
|
|
2203
|
+
function __crossbind_v_get(h, key) {
|
|
2204
|
+
return Emval.toHandle(Emval.toValue(h)[key]);
|
|
2205
|
+
}
|
|
2206
|
+
globalThis.__crossbind_v_get = __crossbind_v_get;
|
|
2207
|
+
|
|
2208
|
+
function __crossbind_v_set(h, key, v) {
|
|
2209
|
+
Emval.toValue(h)[key] = Emval.toValue(v);
|
|
2210
|
+
}
|
|
2211
|
+
globalThis.__crossbind_v_set = __crossbind_v_set;
|
|
2212
|
+
|
|
2213
|
+
function __crossbind_v_from_num(v) {
|
|
2214
|
+
return Emval.toHandle(v);
|
|
2215
|
+
}
|
|
2216
|
+
globalThis.__crossbind_v_from_num = __crossbind_v_from_num;
|
|
2217
|
+
|
|
2218
|
+
function __crossbind_v_from_bool(v) {
|
|
2219
|
+
return Emval.toHandle(!!v);
|
|
2220
|
+
}
|
|
2221
|
+
globalThis.__crossbind_v_from_bool = __crossbind_v_from_bool;
|
|
2222
|
+
|
|
2223
|
+
function __crossbind_v_from_str(s) {
|
|
2224
|
+
return Emval.toHandle(s);
|
|
2225
|
+
}
|
|
2226
|
+
globalThis.__crossbind_v_from_str = __crossbind_v_from_str;
|
|
2227
|
+
|
|
2228
|
+
function __crossbind_v_kind(h) {
|
|
2229
|
+
const v = Emval.toValue(h);
|
|
2230
|
+
if (v === null || v === undefined) return 0;
|
|
2231
|
+
const t = typeof v;
|
|
2232
|
+
if (t === 'boolean') return 1;
|
|
2233
|
+
if (t === 'number') return 2;
|
|
2234
|
+
if (t === 'string') return 3;
|
|
2235
|
+
if (t === 'function') return 4;
|
|
2236
|
+
return 5;
|
|
2237
|
+
}
|
|
2238
|
+
globalThis.__crossbind_v_kind = __crossbind_v_kind;
|
|
2239
|
+
|
|
2240
|
+
function __crossbind_v_as_num(h) {
|
|
2241
|
+
return Number(Emval.toValue(h));
|
|
2242
|
+
}
|
|
2243
|
+
globalThis.__crossbind_v_as_num = __crossbind_v_as_num;
|
|
2244
|
+
|
|
2245
|
+
function __crossbind_v_as_bool(h) {
|
|
2246
|
+
return Emval.toValue(h) ? 1 : 0;
|
|
2247
|
+
}
|
|
2248
|
+
globalThis.__crossbind_v_as_bool = __crossbind_v_as_bool;
|
|
2249
|
+
|
|
2250
|
+
function __crossbind_v_as_str(h) {
|
|
2251
|
+
return String(Emval.toValue(h));
|
|
2252
|
+
}
|
|
2253
|
+
globalThis.__crossbind_v_as_str = __crossbind_v_as_str;
|
|
2254
|
+
|
|
2255
|
+
function __crossbind_v_call(f, args) {
|
|
2256
|
+
const fn = Emval.toValue(f);
|
|
2257
|
+
return Emval.toHandle(fn(...args.map((a) => Emval.toValue(a))));
|
|
2258
|
+
}
|
|
2259
|
+
globalThis.__crossbind_v_call = __crossbind_v_call;
|
|
2260
|
+
|
|
2261
|
+
function __embind_register_memory_view(rawType, dataTypeIndex, name) {
|
|
2262
|
+
var typeMapping = [
|
|
2263
|
+
Int8Array,
|
|
2264
|
+
Uint8Array,
|
|
2265
|
+
Int16Array,
|
|
2266
|
+
Uint16Array,
|
|
2267
|
+
Int32Array,
|
|
2268
|
+
Uint32Array,
|
|
2269
|
+
Float32Array,
|
|
2270
|
+
Float64Array,
|
|
2271
|
+
BigInt64Array,
|
|
2272
|
+
BigUint64Array,
|
|
2273
|
+
];
|
|
2274
|
+
|
|
2275
|
+
var TA = typeMapping[dataTypeIndex];
|
|
2276
|
+
|
|
2277
|
+
function decodeMemoryView(handle) {
|
|
2278
|
+
handle = handle >>> 2;
|
|
2279
|
+
var heap = HEAPU32;
|
|
2280
|
+
var size = heap[handle]; // in elements
|
|
2281
|
+
var data = heap[handle + 1]; // byte offset into emscripten heap
|
|
2282
|
+
return new TA(heap.buffer, data, size);
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
name = readLatin1String(name);
|
|
2286
|
+
registerType(rawType, {
|
|
2287
|
+
name: name,
|
|
2288
|
+
'fromWireType': decodeMemoryView,
|
|
2289
|
+
'argPackAdvance': 8n,
|
|
2290
|
+
'readValueFromPointer': decodeMemoryView,
|
|
2291
|
+
}, {
|
|
2292
|
+
ignoreDuplicateRegistrations: true,
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
globalThis.__embind_register_memory_view = __embind_register_memory_view;
|
|
2296
|
+
|
|
2297
|
+
function runDestructors(destructors) {
|
|
2298
|
+
while (destructors.length) {
|
|
2299
|
+
var ptr = destructors.pop();
|
|
2300
|
+
var del = destructors.pop();
|
|
2301
|
+
del(ptr);
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
|
|
2306
|
+
function newFunc(constructor, argumentList) {
|
|
2307
|
+
if (!(constructor instanceof Function)) {
|
|
2308
|
+
throw new TypeError(`new_ called with constructor type ${typeof (constructor)} which is not a function`);
|
|
2309
|
+
}
|
|
2310
|
+
/*
|
|
2311
|
+
* Previously, the following line was just:
|
|
2312
|
+
* function dummy() {};
|
|
2313
|
+
* Unfortunately, Chrome was preserving 'dummy' as the object's name, even
|
|
2314
|
+
* though at creation, the 'dummy' has the correct constructor name. Thus,
|
|
2315
|
+
* objects created with IMVU.new would show up in the debugger as 'dummy',
|
|
2316
|
+
* which isn't very helpful. Using IMVU.createNamedFunction addresses the
|
|
2317
|
+
* issue. Doublely-unfortunately, there's no way to write a test for this
|
|
2318
|
+
* behavior. -NRD 2013.02.22
|
|
2319
|
+
*/
|
|
2320
|
+
var dummy = createNamedFunction(constructor.name || 'unknownFunctionName', function () { });
|
|
2321
|
+
dummy.prototype = constructor.prototype;
|
|
2322
|
+
var obj = new dummy;
|
|
2323
|
+
|
|
2324
|
+
var r = constructor.apply(obj, argumentList);
|
|
2325
|
+
return (r instanceof Object) ? r : obj;
|
|
2326
|
+
}
|
|
2327
|
+
function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cppTargetFunc, /** boolean= */ isAsync) {
|
|
2328
|
+
// console.log('craftInvokerFunction', humanName, argTypes);
|
|
2329
|
+
// humanName: a human-readable string name for the function to be generated.
|
|
2330
|
+
// argTypes: An array that contains the embind type objects for all types in the function signature.
|
|
2331
|
+
// argTypes[0] is the type object for the function return value.
|
|
2332
|
+
// argTypes[1] is the type object for function this object/class type, or null if not crafting an invoker for a class method.
|
|
2333
|
+
// argTypes[2...] are the actual function parameters.
|
|
2334
|
+
// classType: The embind type object for the class to be bound, or null if this is not a method of a class.
|
|
2335
|
+
// cppInvokerFunc: JS Function object to the C++-side function that interops into C++ code.
|
|
2336
|
+
// cppTargetFunc: Function pointer (an integer to FUNCTION_TABLE) to the target C++ function the cppInvokerFunc will end up calling.
|
|
2337
|
+
// isAsync: Optional. If true, returns an async function. Async bindings are only supported with JSPI.
|
|
2338
|
+
var argCount = argTypes.length;
|
|
2339
|
+
|
|
2340
|
+
if (argCount < 2) {
|
|
2341
|
+
throwBindingError("argTypes array size mismatch! Must at least get return value and 'this' types!");
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
assert(!isAsync, 'Async bindings are only supported with JSPI.');
|
|
2345
|
+
|
|
2346
|
+
var isClassMethodFunc = (argTypes[1] !== null && classType !== null);
|
|
2347
|
+
|
|
2348
|
+
// Free functions with signature "void function()" do not need an invoker that marshalls between wire types.
|
|
2349
|
+
// TODO: This omits argument count check - enable only at -O3 or similar.
|
|
2350
|
+
// if (ENABLE_UNSAFE_OPTS && argCount == 2 && argTypes[0].name == "void" && !isClassMethodFunc) {
|
|
2351
|
+
// return FUNCTION_TABLE[fn];
|
|
2352
|
+
// }
|
|
2353
|
+
|
|
2354
|
+
// Determine if we need to use a dynamic stack to store the destructors for the function parameters.
|
|
2355
|
+
// TODO: Remove this completely once all function invokers are being dynamically generated.
|
|
2356
|
+
var needsDestructorStack = false;
|
|
2357
|
+
|
|
2358
|
+
for (var i = 1; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here.
|
|
2359
|
+
if (argTypes[i] !== null && argTypes[i].destructorFunction === undefined) { // The type does not define a destructor function - must use dynamic stack
|
|
2360
|
+
needsDestructorStack = true;
|
|
2361
|
+
break;
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
var returns = (argTypes[0].name !== "void");
|
|
2366
|
+
|
|
2367
|
+
var argsList = "";
|
|
2368
|
+
var argsListWired = "";
|
|
2369
|
+
for (var i = 0; i < argCount - 2; ++i) {
|
|
2370
|
+
argsList += (i !== 0 ? ", " : "") + "arg" + i;
|
|
2371
|
+
argsListWired += (i !== 0 ? ", " : "") + "arg" + i + "Wired";
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2374
|
+
var invokerFnBody =
|
|
2375
|
+
"return function " + makeLegalFunctionName(humanName) + "(" + argsList + ") {\n" +
|
|
2376
|
+
"if (arguments.length !== " + (argCount - 2) + ") {\n" +
|
|
2377
|
+
"throwBindingError('function " + humanName + " called with ' + arguments.length + ' arguments, expected " + (argCount - 2) + " args!');\n" +
|
|
2378
|
+
"}\n";
|
|
2379
|
+
|
|
2380
|
+
if (needsDestructorStack) {
|
|
2381
|
+
invokerFnBody += "var destructors = [];\n";
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
var dtorStack = needsDestructorStack ? "destructors" : "null";
|
|
2385
|
+
var args1 = ["throwBindingError", "invoker", "fn", "runDestructors", "retType", "classParam"];
|
|
2386
|
+
var args2 = [throwBindingError, cppInvokerFunc, cppTargetFunc, runDestructors, argTypes[0], argTypes[1]];
|
|
2387
|
+
|
|
2388
|
+
if (isClassMethodFunc) {
|
|
2389
|
+
invokerFnBody += "var thisWired = classParam.toWireType(" + dtorStack + ", this);\n";
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
for (var i = 0; i < argCount - 2; ++i) {
|
|
2393
|
+
invokerFnBody += "var arg" + i + "Wired = argType" + i + ".toWireType(" + dtorStack + ", arg" + i + "); // " + argTypes[i + 2].name + "\n";
|
|
2394
|
+
args1.push("argType" + i);
|
|
2395
|
+
args2.push(argTypes[i + 2]);
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
if (isClassMethodFunc) {
|
|
2399
|
+
argsListWired = "thisWired" + (argsListWired.length > 0 ? ", " : "") + argsListWired;
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
invokerFnBody +=
|
|
2403
|
+
(returns || isAsync ? "var rv = " : "") + "invoker(fn" + (argsListWired.length > 0 ? ", " : "") + argsListWired + ");\n";
|
|
2404
|
+
|
|
2405
|
+
if (needsDestructorStack) {
|
|
2406
|
+
invokerFnBody += "runDestructors(destructors);\n";
|
|
2407
|
+
} else {
|
|
2408
|
+
for (var i = isClassMethodFunc ? 1 : 2; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here. Also skip class type if not a method.
|
|
2409
|
+
var paramName = (i === 1 ? "thisWired" : ("arg" + (i - 2) + "Wired"));
|
|
2410
|
+
if (argTypes[i].destructorFunction !== null) {
|
|
2411
|
+
invokerFnBody += paramName + "_dtor(" + paramName + "); // " + argTypes[i].name + "\n";
|
|
2412
|
+
args1.push(paramName + "_dtor");
|
|
2413
|
+
args2.push(argTypes[i].destructorFunction);
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
if (returns) {
|
|
2419
|
+
invokerFnBody += "var ret = retType.fromWireType(rv);\n" +
|
|
2420
|
+
"return ret;\n";
|
|
2421
|
+
} else {
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
invokerFnBody += "}\n";
|
|
2425
|
+
|
|
2426
|
+
args1.push(invokerFnBody);
|
|
2427
|
+
//console.log('newFunc 1', args1);
|
|
2428
|
+
//console.log('newFunc 2', args2);
|
|
2429
|
+
|
|
2430
|
+
return newFunc(Function, args1).apply(null, args2);
|
|
2431
|
+
/* return (...az) => {
|
|
2432
|
+
console.log('craftInvokerFunction2', humanName, az);
|
|
2433
|
+
const y = newFunc(Function, args1).apply(null, args2);
|
|
2434
|
+
const k = y(...az);
|
|
2435
|
+
console.log('craftInvokerFunction21', humanName, k, az);
|
|
2436
|
+
return k;
|
|
2437
|
+
} */
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
function ensureOverloadTable(proto, methodName, humanName) {
|
|
2441
|
+
if (undefined === proto[methodName].overloadTable) {
|
|
2442
|
+
var prevFunc = proto[methodName];
|
|
2443
|
+
// Inject an overload resolver function that routes to the appropriate overload based on the number of arguments.
|
|
2444
|
+
proto[methodName] = function () {
|
|
2445
|
+
// TODO This check can be removed in -O3 level "unsafe" optimizations.
|
|
2446
|
+
if (!proto[methodName].overloadTable.hasOwnProperty(arguments.length)) {
|
|
2447
|
+
throwBindingError(`Function '${humanName}' called with an invalid number of arguments (${arguments.length}) - expects one of (${proto[methodName].overloadTable})!`);
|
|
2448
|
+
}
|
|
2449
|
+
return proto[methodName].overloadTable[arguments.length].apply(this, arguments);
|
|
2450
|
+
};
|
|
2451
|
+
// Move the previous function into the overload table.
|
|
2452
|
+
proto[methodName].overloadTable = [];
|
|
2453
|
+
proto[methodName].overloadTable[prevFunc.argCount] = prevFunc;
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
/** @param {number=} numArguments */
|
|
2458
|
+
function exposePublicSymbol(name, value, numArguments) {
|
|
2459
|
+
if (Module.hasOwnProperty(name)) {
|
|
2460
|
+
if (undefined === numArguments || (undefined !== Module[name].overloadTable && undefined !== Module[name].overloadTable[numArguments])) {
|
|
2461
|
+
throwBindingError(`Cannot register public name '${name}' twice`);
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
// We are exposing a function with the same name as an existing function. Create an overload table and a function selector
|
|
2465
|
+
// that routes between the two.
|
|
2466
|
+
ensureOverloadTable(Module, name, name);
|
|
2467
|
+
if (Module.hasOwnProperty(numArguments)) {
|
|
2468
|
+
throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`);
|
|
2469
|
+
}
|
|
2470
|
+
// Add the new function into the overload table.
|
|
2471
|
+
Module[name].overloadTable[numArguments] = value;
|
|
2472
|
+
}
|
|
2473
|
+
else {
|
|
2474
|
+
Module[name] = value;
|
|
2475
|
+
if (undefined !== numArguments) {
|
|
2476
|
+
Module[name].numArguments = numArguments;
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
function heap32VectorToArray(count, firstElement) {
|
|
2482
|
+
return firstElement;
|
|
2483
|
+
/* var array = [];
|
|
2484
|
+
for (var i = 0; i < count; i++) {
|
|
2485
|
+
// TODO(https://github.com/emscripten-core/emscripten/issues/17310):
|
|
2486
|
+
// Find a way to hoist the `>> 2` or `>> 3` out of this loop.
|
|
2487
|
+
array.push(Number(HEAPU64[(((firstElement)+(i * 8))>>3)]));
|
|
2488
|
+
}
|
|
2489
|
+
return array; */
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
|
|
2493
|
+
/** @param {number=} numArguments */
|
|
2494
|
+
function replacePublicSymbol(name, value, numArguments) {
|
|
2495
|
+
if (!Module.hasOwnProperty(name)) {
|
|
2496
|
+
throwInternalError('Replacing nonexistant public symbol');
|
|
2497
|
+
}
|
|
2498
|
+
// If there's an overload table for this symbol, replace the symbol in the overload table instead.
|
|
2499
|
+
if (undefined !== Module[name].overloadTable && undefined !== numArguments) {
|
|
2500
|
+
Module[name].overloadTable[numArguments] = value;
|
|
2501
|
+
}
|
|
2502
|
+
else {
|
|
2503
|
+
Module[name] = value;
|
|
2504
|
+
Module[name].argCount = numArguments;
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
|
|
2509
|
+
|
|
2510
|
+
function getDynCaller(signature, rawFunction, slice) {
|
|
2511
|
+
return (...args) => {
|
|
2512
|
+
//console.log('getDynCallerReturn', signature, rawFunction, args.length, ...args);
|
|
2513
|
+
if (slice) {
|
|
2514
|
+
args = args.slice(1);
|
|
2515
|
+
}
|
|
2516
|
+
return rawFunction(...args);
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
function getWasmTableEntry(rawFunction) { return (a, b, c) => { console.log('getWasmTableEntry', rawFunction, a, b, c); }; }
|
|
2521
|
+
|
|
2522
|
+
function embind__requireFunction(signature, rawFunction, slice = false) {
|
|
2523
|
+
signature = readLatin1String(signature);
|
|
2524
|
+
|
|
2525
|
+
function makeDynCaller() {
|
|
2526
|
+
if (true) {
|
|
2527
|
+
return getDynCaller(signature, rawFunction, slice);
|
|
2528
|
+
}
|
|
2529
|
+
return getWasmTableEntry(rawFunction);
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
var fp = makeDynCaller();
|
|
2533
|
+
if (typeof fp != "function") {
|
|
2534
|
+
throwBindingError(`unknown function pointer with signature ${signature}: ${rawFunction}`);
|
|
2535
|
+
}
|
|
2536
|
+
return fp;
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2539
|
+
|
|
2540
|
+
|
|
2541
|
+
var UnboundTypeError = undefined;
|
|
2542
|
+
|
|
2543
|
+
|
|
2544
|
+
function ___getTypeName() { }
|
|
2545
|
+
|
|
2546
|
+
function getTypeName(type) {
|
|
2547
|
+
var ptr = ___getTypeName(type);
|
|
2548
|
+
var rv = readLatin1String(ptr);
|
|
2549
|
+
_free(ptr);
|
|
2550
|
+
return rv;
|
|
2551
|
+
}
|
|
2552
|
+
function throwUnboundTypeError(message, types) {
|
|
2553
|
+
var unboundTypes = [];
|
|
2554
|
+
var seen = {};
|
|
2555
|
+
function visit(type) {
|
|
2556
|
+
if (seen[type]) {
|
|
2557
|
+
return;
|
|
2558
|
+
}
|
|
2559
|
+
if (registeredTypes[type]) {
|
|
2560
|
+
return;
|
|
2561
|
+
}
|
|
2562
|
+
if (typeDependencies[type]) {
|
|
2563
|
+
typeDependencies[type].forEach(visit);
|
|
2564
|
+
return;
|
|
2565
|
+
}
|
|
2566
|
+
unboundTypes.push(type);
|
|
2567
|
+
seen[type] = true;
|
|
2568
|
+
}
|
|
2569
|
+
types.forEach(visit);
|
|
2570
|
+
|
|
2571
|
+
throw new UnboundTypeError(message + ': ' + unboundTypes.map(getTypeName).join([', ']));
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
function __embind_register_function(name, argCount, rawArgTypesAddr, signature, rawInvoker, fn, isAsync) {
|
|
2575
|
+
// const argCount = Number(argCount);
|
|
2576
|
+
// console.log('function', name, argCount, rawArgTypesAddr, signature, rawInvoker, fn, isAsync);
|
|
2577
|
+
var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
|
|
2578
|
+
name = readLatin1String(name);
|
|
2579
|
+
// console.log('a1');
|
|
2580
|
+
rawInvoker = embind__requireFunction(signature, rawInvoker, true);
|
|
2581
|
+
// console.log('a2');
|
|
2582
|
+
exposePublicSymbol(name, function () {
|
|
2583
|
+
throwUnboundTypeError(`Cannot call ${name} due to unbound types`, argTypes);
|
|
2584
|
+
}, argCount - 1);
|
|
2585
|
+
// console.log('a3');
|
|
2586
|
+
whenDependentTypesAreResolved([], argTypes, function (argTypes) {
|
|
2587
|
+
// console.log('a4', argTypes);
|
|
2588
|
+
var invokerArgsArray = [argTypes[0] /* return value */, null /* no class 'this'*/].concat(argTypes.slice(1) /* actual params */);
|
|
2589
|
+
// console.log('a5');
|
|
2590
|
+
replacePublicSymbol(name, craftInvokerFunction(name, invokerArgsArray, null /* no class 'this'*/, rawInvoker, fn, isAsync), argCount - 1);
|
|
2591
|
+
// console.log('a6');
|
|
2592
|
+
return [];
|
|
2593
|
+
});
|
|
2594
|
+
// console.log('a7');
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2597
|
+
globalThis.__embind_register_function = __embind_register_function;
|
|
2598
|
+
|
|
2599
|
+
var tupleRegistrations = {};
|
|
2600
|
+
|
|
2601
|
+
|
|
2602
|
+
function __embind_register_value_array(
|
|
2603
|
+
rawType,
|
|
2604
|
+
name,
|
|
2605
|
+
constructorSignature,
|
|
2606
|
+
rawConstructor,
|
|
2607
|
+
destructorSignature,
|
|
2608
|
+
rawDestructor
|
|
2609
|
+
) {
|
|
2610
|
+
tupleRegistrations[rawType] = {
|
|
2611
|
+
name: readLatin1String(name),
|
|
2612
|
+
rawConstructor: embind__requireFunction(constructorSignature, rawConstructor),
|
|
2613
|
+
rawDestructor: embind__requireFunction(destructorSignature, rawDestructor),
|
|
2614
|
+
elements: [],
|
|
2615
|
+
};
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
globalThis.__embind_register_value_array = __embind_register_value_array;
|
|
2619
|
+
|
|
2620
|
+
function __embind_register_value_array_element(
|
|
2621
|
+
rawTupleType,
|
|
2622
|
+
getterReturnType,
|
|
2623
|
+
getterSignature,
|
|
2624
|
+
getter,
|
|
2625
|
+
getterContext,
|
|
2626
|
+
setterArgumentType,
|
|
2627
|
+
setterSignature,
|
|
2628
|
+
setter,
|
|
2629
|
+
setterContext
|
|
2630
|
+
) {
|
|
2631
|
+
tupleRegistrations[rawTupleType].elements.push({
|
|
2632
|
+
getterReturnType: getterReturnType,
|
|
2633
|
+
getter: embind__requireFunction(getterSignature, getter),
|
|
2634
|
+
getterContext: getterContext,
|
|
2635
|
+
setterArgumentType: setterArgumentType,
|
|
2636
|
+
setter: embind__requireFunction(setterSignature, setter),
|
|
2637
|
+
setterContext: setterContext,
|
|
2638
|
+
});
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
globalThis.__embind_register_value_array_element = __embind_register_value_array_element;
|
|
2642
|
+
|
|
2643
|
+
|
|
2644
|
+
function __embind_finalize_value_array(rawTupleType) {
|
|
2645
|
+
var reg = tupleRegistrations[rawTupleType];
|
|
2646
|
+
delete tupleRegistrations[rawTupleType];
|
|
2647
|
+
var elements = reg.elements;
|
|
2648
|
+
var elementsLength = elements.length;
|
|
2649
|
+
var elementTypes = elements.map(function (elt) { return elt.getterReturnType; }).
|
|
2650
|
+
concat(elements.map(function (elt) { return elt.setterArgumentType; }));
|
|
2651
|
+
|
|
2652
|
+
var rawConstructor = reg.rawConstructor;
|
|
2653
|
+
var rawDestructor = reg.rawDestructor;
|
|
2654
|
+
|
|
2655
|
+
whenDependentTypesAreResolved([rawTupleType], elementTypes, function (elementTypes) {
|
|
2656
|
+
elements.forEach((elt, i) => {
|
|
2657
|
+
var getterReturnType = elementTypes[i];
|
|
2658
|
+
var getter = elt.getter;
|
|
2659
|
+
var getterContext = elt.getterContext;
|
|
2660
|
+
var setterArgumentType = elementTypes[i + elementsLength];
|
|
2661
|
+
var setter = elt.setter;
|
|
2662
|
+
var setterContext = elt.setterContext;
|
|
2663
|
+
elt.read = (ptr) => {
|
|
2664
|
+
//console.log('elt.read ', ptr);
|
|
2665
|
+
const a = getter(getterContext, ptr);
|
|
2666
|
+
//console.log('elt.read2 ', ptr, a);
|
|
2667
|
+
//console.log('elt.read3 ', ptr, a, getterReturnType['fromWireType'](a));
|
|
2668
|
+
return getterReturnType['fromWireType'](a);
|
|
2669
|
+
};
|
|
2670
|
+
elt.write = (ptr, o) => {
|
|
2671
|
+
//console.log('elt.write ', ptr, o);
|
|
2672
|
+
var destructors = [];
|
|
2673
|
+
setter(setterContext, ptr, setterArgumentType['toWireType'](destructors, o));
|
|
2674
|
+
runDestructors(destructors);
|
|
2675
|
+
};
|
|
2676
|
+
});
|
|
2677
|
+
|
|
2678
|
+
return [{
|
|
2679
|
+
name: reg.name,
|
|
2680
|
+
'fromWireType': function (ptr) {
|
|
2681
|
+
//console.log('__embind_finalize_value_array fromWireType', reg.name, ptr);
|
|
2682
|
+
var rv = new Array(elementsLength);
|
|
2683
|
+
for (var i = 0; i < elementsLength; ++i) {
|
|
2684
|
+
rv[i] = elements[i].read(ptr);
|
|
2685
|
+
}
|
|
2686
|
+
rawDestructor(ptr);
|
|
2687
|
+
return rv;
|
|
2688
|
+
},
|
|
2689
|
+
'toWireType': function (destructors, o) {
|
|
2690
|
+
if (elementsLength !== o.length) {
|
|
2691
|
+
throw new TypeError(`Incorrect number of tuple elements for ${reg.name}: expected=${elementsLength}, actual=${o.length}`);
|
|
2692
|
+
}
|
|
2693
|
+
var ptr = rawConstructor();
|
|
2694
|
+
//console.log('__embind_finalize_value_array toWireType', reg.name, ptr);
|
|
2695
|
+
for (var i = 0; i < elementsLength; ++i) {
|
|
2696
|
+
elements[i].write(ptr, o[i]);
|
|
2697
|
+
}
|
|
2698
|
+
if (destructors !== null) {
|
|
2699
|
+
destructors.push(rawDestructor, ptr);
|
|
2700
|
+
}
|
|
2701
|
+
return ptr;
|
|
2702
|
+
},
|
|
2703
|
+
'argPackAdvance': 8n,
|
|
2704
|
+
'readValueFromPointer': simpleReadValueFromPointer,
|
|
2705
|
+
destructorFunction: rawDestructor,
|
|
2706
|
+
}];
|
|
2707
|
+
});
|
|
2708
|
+
}
|
|
2709
|
+
|
|
2710
|
+
globalThis.__embind_finalize_value_array = __embind_finalize_value_array;
|
|
2711
|
+
|
|
2712
|
+
var structRegistrations = {};
|
|
2713
|
+
|
|
2714
|
+
|
|
2715
|
+
function __embind_register_value_object(
|
|
2716
|
+
rawType,
|
|
2717
|
+
name,
|
|
2718
|
+
constructorSignature,
|
|
2719
|
+
rawConstructor,
|
|
2720
|
+
destructorSignature,
|
|
2721
|
+
rawDestructor
|
|
2722
|
+
) {
|
|
2723
|
+
structRegistrations[rawType] = {
|
|
2724
|
+
name: readLatin1String(name),
|
|
2725
|
+
rawConstructor: embind__requireFunction(constructorSignature, rawConstructor),
|
|
2726
|
+
rawDestructor: embind__requireFunction(destructorSignature, rawDestructor),
|
|
2727
|
+
fields: [],
|
|
2728
|
+
};
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
globalThis.__embind_register_value_object = __embind_register_value_object;
|
|
2732
|
+
|
|
2733
|
+
|
|
2734
|
+
function __embind_register_value_object_field(
|
|
2735
|
+
structType,
|
|
2736
|
+
fieldName,
|
|
2737
|
+
getterReturnType,
|
|
2738
|
+
getterSignature,
|
|
2739
|
+
getter,
|
|
2740
|
+
getterContext,
|
|
2741
|
+
setterArgumentType,
|
|
2742
|
+
setterSignature,
|
|
2743
|
+
setter,
|
|
2744
|
+
setterContext
|
|
2745
|
+
) {
|
|
2746
|
+
structRegistrations[structType].fields.push({
|
|
2747
|
+
fieldName: readLatin1String(fieldName),
|
|
2748
|
+
getterReturnType: getterReturnType,
|
|
2749
|
+
getter: embind__requireFunction(getterSignature, getter),
|
|
2750
|
+
getterContext: getterContext,
|
|
2751
|
+
setterArgumentType: setterArgumentType,
|
|
2752
|
+
setter: embind__requireFunction(setterSignature, setter),
|
|
2753
|
+
setterContext: setterContext,
|
|
2754
|
+
});
|
|
2755
|
+
}
|
|
2756
|
+
|
|
2757
|
+
globalThis.__embind_register_value_object_field = __embind_register_value_object_field;
|
|
2758
|
+
|
|
2759
|
+
|
|
2760
|
+
function __embind_finalize_value_object(structType) {
|
|
2761
|
+
var reg = structRegistrations[structType];
|
|
2762
|
+
delete structRegistrations[structType];
|
|
2763
|
+
|
|
2764
|
+
var rawConstructor = reg.rawConstructor;
|
|
2765
|
+
var rawDestructor = reg.rawDestructor;
|
|
2766
|
+
var fieldRecords = reg.fields;
|
|
2767
|
+
var fieldTypes = fieldRecords.map((field) => field.getterReturnType).
|
|
2768
|
+
concat(fieldRecords.map((field) => field.setterArgumentType));
|
|
2769
|
+
whenDependentTypesAreResolved([structType], fieldTypes, (fieldTypes) => {
|
|
2770
|
+
var fields = {};
|
|
2771
|
+
fieldRecords.forEach((field, i) => {
|
|
2772
|
+
var fieldName = field.fieldName;
|
|
2773
|
+
var getterReturnType = fieldTypes[i];
|
|
2774
|
+
var getter = field.getter;
|
|
2775
|
+
var getterContext = field.getterContext;
|
|
2776
|
+
var setterArgumentType = fieldTypes[i + fieldRecords.length];
|
|
2777
|
+
var setter = field.setter;
|
|
2778
|
+
var setterContext = field.setterContext;
|
|
2779
|
+
fields[fieldName] = {
|
|
2780
|
+
read: (ptr) => {
|
|
2781
|
+
return getterReturnType['fromWireType'](
|
|
2782
|
+
getter(getterContext, ptr));
|
|
2783
|
+
},
|
|
2784
|
+
write: (ptr, o) => {
|
|
2785
|
+
var destructors = [];
|
|
2786
|
+
setter(setterContext, ptr, setterArgumentType['toWireType'](destructors, o));
|
|
2787
|
+
runDestructors(destructors);
|
|
2788
|
+
}
|
|
2789
|
+
};
|
|
2790
|
+
});
|
|
2791
|
+
|
|
2792
|
+
return [{
|
|
2793
|
+
name: reg.name,
|
|
2794
|
+
'fromWireType': function (ptr) {
|
|
2795
|
+
//console.log('fromWireType __embind_finalize_value_object');
|
|
2796
|
+
var rv = {};
|
|
2797
|
+
for (var i in fields) {
|
|
2798
|
+
rv[i] = fields[i].read(ptr);
|
|
2799
|
+
}
|
|
2800
|
+
rawDestructor(ptr);
|
|
2801
|
+
return rv;
|
|
2802
|
+
},
|
|
2803
|
+
'toWireType': function (destructors, o) {
|
|
2804
|
+
//console.log('toWireType __embind_finalize_value_object');
|
|
2805
|
+
// todo: Here we have an opportunity for -O3 level "unsafe" optimizations:
|
|
2806
|
+
// assume all fields are present without checking.
|
|
2807
|
+
for (var fieldName in fields) {
|
|
2808
|
+
if (!(fieldName in o)) {
|
|
2809
|
+
throw new TypeError(`Missing field: "${fieldName}"`);
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
var ptr = rawConstructor();
|
|
2813
|
+
for (fieldName in fields) {
|
|
2814
|
+
fields[fieldName].write(ptr, o[fieldName]);
|
|
2815
|
+
}
|
|
2816
|
+
if (destructors !== null) {
|
|
2817
|
+
destructors.push(rawDestructor, ptr);
|
|
2818
|
+
}
|
|
2819
|
+
return ptr;
|
|
2820
|
+
},
|
|
2821
|
+
'argPackAdvance': 8n,
|
|
2822
|
+
'readValueFromPointer': simpleReadValueFromPointer,
|
|
2823
|
+
destructorFunction: rawDestructor,
|
|
2824
|
+
}];
|
|
2825
|
+
});
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
globalThis.__embind_finalize_value_object = __embind_finalize_value_object;
|
|
2829
|
+
|
|
2830
|
+
|
|
2831
|
+
function ClassHandle_isAliasOf(other) {
|
|
2832
|
+
// console.log('ClassHandle_isAliasOf');
|
|
2833
|
+
if (!(this instanceof ClassHandle)) {
|
|
2834
|
+
return false;
|
|
2835
|
+
}
|
|
2836
|
+
if (!(other instanceof ClassHandle)) {
|
|
2837
|
+
return false;
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
var leftClass = this.$$.ptrType.registeredClass;
|
|
2841
|
+
var left = this.$$.ptr;
|
|
2842
|
+
var rightClass = other.$$.ptrType.registeredClass;
|
|
2843
|
+
var right = other.$$.ptr;
|
|
2844
|
+
|
|
2845
|
+
while (leftClass.baseClass) {
|
|
2846
|
+
left = leftClass.upcast(left);
|
|
2847
|
+
leftClass = leftClass.baseClass;
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2850
|
+
while (rightClass.baseClass) {
|
|
2851
|
+
right = rightClass.upcast(right);
|
|
2852
|
+
rightClass = rightClass.baseClass;
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2855
|
+
return leftClass === rightClass && left === right;
|
|
2856
|
+
}
|
|
2857
|
+
|
|
2858
|
+
function shallowCopyInternalPointer(o) {
|
|
2859
|
+
return {
|
|
2860
|
+
count: o.count,
|
|
2861
|
+
deleteScheduled: o.deleteScheduled,
|
|
2862
|
+
preservePointerOnDelete: o.preservePointerOnDelete,
|
|
2863
|
+
ptr: o.ptr,
|
|
2864
|
+
ptrType: o.ptrType,
|
|
2865
|
+
smartPtr: o.smartPtr,
|
|
2866
|
+
smartPtrType: o.smartPtrType,
|
|
2867
|
+
};
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
function throwInstanceAlreadyDeleted(obj) {
|
|
2871
|
+
function getInstanceTypeName(handle) {
|
|
2872
|
+
return handle.$$.ptrType.registeredClass.name;
|
|
2873
|
+
}
|
|
2874
|
+
throwBindingError(getInstanceTypeName(obj) + ' instance already deleted');
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
var finalizationRegistry = false;
|
|
2878
|
+
|
|
2879
|
+
function detachFinalizer(handle) { }
|
|
2880
|
+
|
|
2881
|
+
function runDestructor($$) {
|
|
2882
|
+
if ($$.smartPtr) {
|
|
2883
|
+
$$.smartPtrType.rawDestructor($$.smartPtr);
|
|
2884
|
+
} else {
|
|
2885
|
+
$$.ptrType.registeredClass.rawDestructor($$.ptr);
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
function releaseClassHandle($$) {
|
|
2889
|
+
$$.count.value -= 1;
|
|
2890
|
+
var toDelete = 0 === $$.count.value;
|
|
2891
|
+
if (toDelete) {
|
|
2892
|
+
runDestructor($$);
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
function downcastPointer(ptr, ptrClass, desiredClass) {
|
|
2897
|
+
if (ptrClass === desiredClass) {
|
|
2898
|
+
return ptr;
|
|
2899
|
+
}
|
|
2900
|
+
if (undefined === desiredClass.baseClass) {
|
|
2901
|
+
return null; // no conversion
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
var rv = downcastPointer(ptr, ptrClass, desiredClass.baseClass);
|
|
2905
|
+
if (rv === null) {
|
|
2906
|
+
return null;
|
|
2907
|
+
}
|
|
2908
|
+
return desiredClass.downcast(rv);
|
|
2909
|
+
}
|
|
2910
|
+
|
|
2911
|
+
var registeredPointers = {};
|
|
2912
|
+
|
|
2913
|
+
function getInheritedInstanceCount() {
|
|
2914
|
+
return Object.keys(registeredInstances).length;
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
function getLiveInheritedInstances() {
|
|
2918
|
+
var rv = [];
|
|
2919
|
+
for (var k in registeredInstances) {
|
|
2920
|
+
if (registeredInstances.hasOwnProperty(k)) {
|
|
2921
|
+
rv.push(registeredInstances[k]);
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
return rv;
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
var deletionQueue = [];
|
|
2928
|
+
function flushPendingDeletes() {
|
|
2929
|
+
while (deletionQueue.length) {
|
|
2930
|
+
var obj = deletionQueue.pop();
|
|
2931
|
+
obj.$$.deleteScheduled = false;
|
|
2932
|
+
obj['delete']();
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2936
|
+
var delayFunction = undefined;
|
|
2937
|
+
|
|
2938
|
+
|
|
2939
|
+
function setDelayFunction(fn) {
|
|
2940
|
+
delayFunction = fn;
|
|
2941
|
+
if (deletionQueue.length && delayFunction) {
|
|
2942
|
+
delayFunction(flushPendingDeletes);
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
function init_embind() {
|
|
2946
|
+
Module['getInheritedInstanceCount'] = getInheritedInstanceCount;
|
|
2947
|
+
Module['getLiveInheritedInstances'] = getLiveInheritedInstances;
|
|
2948
|
+
Module['flushPendingDeletes'] = flushPendingDeletes;
|
|
2949
|
+
Module['setDelayFunction'] = setDelayFunction;
|
|
2950
|
+
}
|
|
2951
|
+
var registeredInstances = {};
|
|
2952
|
+
|
|
2953
|
+
function getBasestPointer(class_, ptr) {
|
|
2954
|
+
// console.log('getBasestPointer');
|
|
2955
|
+
if (ptr === undefined) {
|
|
2956
|
+
throwBindingError('ptr should not be undefined');
|
|
2957
|
+
}
|
|
2958
|
+
while (class_.baseClass) {
|
|
2959
|
+
ptr = class_.upcast(ptr);
|
|
2960
|
+
class_ = class_.baseClass;
|
|
2961
|
+
}
|
|
2962
|
+
return ptr;
|
|
2963
|
+
}
|
|
2964
|
+
function getInheritedInstance(class_, ptr) {
|
|
2965
|
+
ptr = getBasestPointer(class_, ptr);
|
|
2966
|
+
return registeredInstances[ptr];
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2969
|
+
|
|
2970
|
+
function makeClassHandle(prototype, record) {
|
|
2971
|
+
//console.log('makeClassHandle', prototype, record);
|
|
2972
|
+
if (!record.ptrType || !record.ptr) {
|
|
2973
|
+
throwInternalError('makeClassHandle requires ptr and ptrType');
|
|
2974
|
+
}
|
|
2975
|
+
var hasSmartPtrType = !!record.smartPtrType;
|
|
2976
|
+
var hasSmartPtr = !!record.smartPtr;
|
|
2977
|
+
if (hasSmartPtrType !== hasSmartPtr) {
|
|
2978
|
+
throwInternalError('Both smartPtrType and smartPtr must be specified');
|
|
2979
|
+
}
|
|
2980
|
+
record.count = { value: 1 };
|
|
2981
|
+
return attachFinalizer(Object.create(prototype, {
|
|
2982
|
+
$$: {
|
|
2983
|
+
value: record,
|
|
2984
|
+
},
|
|
2985
|
+
}));
|
|
2986
|
+
}
|
|
2987
|
+
|
|
2988
|
+
var MAX_INT53 = 9007199254740992;
|
|
2989
|
+
|
|
2990
|
+
var MIN_INT53 = -9007199254740992;
|
|
2991
|
+
function bigintToI53Checked(num) {
|
|
2992
|
+
return (num < MIN_INT53 || num > MAX_INT53) ? NaN : Number(num);
|
|
2993
|
+
}
|
|
2994
|
+
function RegisteredPointer_fromWireType(ptr) {
|
|
2995
|
+
//console.log('RegisteredPointer_fromWireType', ptr);
|
|
2996
|
+
// ptr is a raw pointer (or a raw smartpointer)
|
|
2997
|
+
// ptr = bigintToI53Checked(ptr);
|
|
2998
|
+
// console.log('RegisteredPointer_fromWireType 2', ptr);
|
|
2999
|
+
// assert(Number.isSafeInteger(ptr));
|
|
3000
|
+
|
|
3001
|
+
// rawPointer is a maybe-null raw pointer
|
|
3002
|
+
var rawPointer = this.getPointee(ptr);
|
|
3003
|
+
//console.log('RegisteredPointer_fromWireType - rawPointer: ', rawPointer);
|
|
3004
|
+
|
|
3005
|
+
if (!rawPointer) {
|
|
3006
|
+
this.destructor(ptr);
|
|
3007
|
+
return null;
|
|
3008
|
+
}
|
|
3009
|
+
|
|
3010
|
+
var registeredInstance = getInheritedInstance(this.registeredClass, rawPointer);
|
|
3011
|
+
//console.log('RegisteredPointer_fromWireType - registeredInstance: ', registeredInstance);
|
|
3012
|
+
if (undefined !== registeredInstance) {
|
|
3013
|
+
// JS object has been neutered, time to repopulate it
|
|
3014
|
+
if (0 === registeredInstance.$$.count.value) {
|
|
3015
|
+
registeredInstance.$$.ptr = rawPointer;
|
|
3016
|
+
registeredInstance.$$.smartPtr = ptr;
|
|
3017
|
+
return registeredInstance['clone']();
|
|
3018
|
+
} else {
|
|
3019
|
+
// else, just increment reference count on existing object
|
|
3020
|
+
// it already has a reference to the smart pointer
|
|
3021
|
+
var rv = registeredInstance['clone']();
|
|
3022
|
+
this.destructor(ptr);
|
|
3023
|
+
return rv;
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
|
|
3027
|
+
function makeDefaultHandle() {
|
|
3028
|
+
if (this.isSmartPointer) {
|
|
3029
|
+
return makeClassHandle(this.registeredClass.instancePrototype, {
|
|
3030
|
+
ptrType: this.pointeeType,
|
|
3031
|
+
ptr: rawPointer,
|
|
3032
|
+
smartPtrType: this,
|
|
3033
|
+
smartPtr: ptr,
|
|
3034
|
+
});
|
|
3035
|
+
} else {
|
|
3036
|
+
return makeClassHandle(this.registeredClass.instancePrototype, {
|
|
3037
|
+
ptrType: this,
|
|
3038
|
+
ptr: ptr,
|
|
3039
|
+
});
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
|
|
3043
|
+
var actualType = this.registeredClass.getActualType(rawPointer);
|
|
3044
|
+
var registeredPointerRecord = registeredPointers[actualType];
|
|
3045
|
+
//console.log('RegisteredPointer_fromWireType - actualType: ', actualType);
|
|
3046
|
+
//console.log('RegisteredPointer_fromWireType - registeredPointerRecord: ', registeredPointerRecord);
|
|
3047
|
+
if (!registeredPointerRecord) {
|
|
3048
|
+
return makeDefaultHandle.call(this);
|
|
3049
|
+
}
|
|
3050
|
+
|
|
3051
|
+
var toType;
|
|
3052
|
+
if (this.isConst) {
|
|
3053
|
+
toType = registeredPointerRecord.constPointerType;
|
|
3054
|
+
} else {
|
|
3055
|
+
toType = registeredPointerRecord.pointerType;
|
|
3056
|
+
}
|
|
3057
|
+
//console.log('RegisteredPointer_fromWireType - toType: ', toType, this.isConst);
|
|
3058
|
+
var dp = downcastPointer(
|
|
3059
|
+
rawPointer,
|
|
3060
|
+
this.registeredClass,
|
|
3061
|
+
toType.registeredClass);
|
|
3062
|
+
//console.log('RegisteredPointer_fromWireType - downcastPointer: ', dp);
|
|
3063
|
+
//console.log('RegisteredPointer_fromWireType - isSmartPointer: ', this.isSmartPointer);
|
|
3064
|
+
if (dp === null) {
|
|
3065
|
+
return makeDefaultHandle.call(this);
|
|
3066
|
+
}
|
|
3067
|
+
if (this.isSmartPointer) {
|
|
3068
|
+
return makeClassHandle(toType.registeredClass.instancePrototype, {
|
|
3069
|
+
ptrType: toType,
|
|
3070
|
+
ptr: dp,
|
|
3071
|
+
smartPtrType: this,
|
|
3072
|
+
smartPtr: ptr,
|
|
3073
|
+
});
|
|
3074
|
+
} else {
|
|
3075
|
+
return makeClassHandle(toType.registeredClass.instancePrototype, {
|
|
3076
|
+
ptrType: toType,
|
|
3077
|
+
ptr: dp,
|
|
3078
|
+
});
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
function attachFinalizer(handle) {
|
|
3082
|
+
//console.log('attachFinalizer', handle);
|
|
3083
|
+
if ('undefined' === typeof FinalizationRegistry) {
|
|
3084
|
+
attachFinalizer = (handle) => handle;
|
|
3085
|
+
return handle;
|
|
3086
|
+
}
|
|
3087
|
+
// If the running environment has a FinalizationRegistry (see
|
|
3088
|
+
// https://github.com/tc39/proposal-weakrefs), then attach finalizers
|
|
3089
|
+
// for class handles. We check for the presence of FinalizationRegistry
|
|
3090
|
+
// at run-time, not build-time.
|
|
3091
|
+
finalizationRegistry = new FinalizationRegistry((info) => {
|
|
3092
|
+
console.warn(info.leakWarning.stack.replace(/^Error: /, ''));
|
|
3093
|
+
releaseClassHandle(info.$$);
|
|
3094
|
+
});
|
|
3095
|
+
attachFinalizer = (handle) => {
|
|
3096
|
+
var $$ = handle.$$;
|
|
3097
|
+
var hasSmartPtr = !!$$.smartPtr;
|
|
3098
|
+
if (hasSmartPtr) {
|
|
3099
|
+
// We should not call the destructor on raw pointers in case other code expects the pointee to live
|
|
3100
|
+
var info = { $$: $$ };
|
|
3101
|
+
// Create a warning as an Error instance in advance so that we can store
|
|
3102
|
+
// the current stacktrace and point to it when / if a leak is detected.
|
|
3103
|
+
// This is more useful than the empty stacktrace of `FinalizationRegistry`
|
|
3104
|
+
// callback.
|
|
3105
|
+
var cls = $$.ptrType.registeredClass;
|
|
3106
|
+
info.leakWarning = new Error(`Embind found a leaked C++ instance ${cls.name} <${ptrToString($$.ptr)}>.\n` +
|
|
3107
|
+
"We'll free it automatically in this case, but this functionality is not reliable across various environments.\n" +
|
|
3108
|
+
"Make sure to invoke .delete() manually once you're done with the instance instead.\n" +
|
|
3109
|
+
"Originally allocated"); // `.stack` will add "at ..." after this sentence
|
|
3110
|
+
if ('captureStackTrace' in Error) {
|
|
3111
|
+
Error.captureStackTrace(info.leakWarning, RegisteredPointer_fromWireType);
|
|
3112
|
+
}
|
|
3113
|
+
finalizationRegistry.register(handle, info, handle);
|
|
3114
|
+
}
|
|
3115
|
+
return handle;
|
|
3116
|
+
};
|
|
3117
|
+
detachFinalizer = (handle) => finalizationRegistry.unregister(handle);
|
|
3118
|
+
return attachFinalizer(handle);
|
|
3119
|
+
}
|
|
3120
|
+
function ClassHandle_clone() {
|
|
3121
|
+
if (!this.$$.ptr) {
|
|
3122
|
+
throwInstanceAlreadyDeleted(this);
|
|
3123
|
+
}
|
|
3124
|
+
|
|
3125
|
+
if (this.$$.preservePointerOnDelete) {
|
|
3126
|
+
this.$$.count.value += 1;
|
|
3127
|
+
return this;
|
|
3128
|
+
} else {
|
|
3129
|
+
var clone = attachFinalizer(Object.create(Object.getPrototypeOf(this), {
|
|
3130
|
+
$$: {
|
|
3131
|
+
value: shallowCopyInternalPointer(this.$$),
|
|
3132
|
+
}
|
|
3133
|
+
}));
|
|
3134
|
+
|
|
3135
|
+
clone.$$.count.value += 1;
|
|
3136
|
+
clone.$$.deleteScheduled = false;
|
|
3137
|
+
return clone;
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
|
|
3141
|
+
|
|
3142
|
+
|
|
3143
|
+
|
|
3144
|
+
function ClassHandle_delete() {
|
|
3145
|
+
if (!this.$$.ptr) {
|
|
3146
|
+
throwInstanceAlreadyDeleted(this);
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
if (this.$$.deleteScheduled && !this.$$.preservePointerOnDelete) {
|
|
3150
|
+
throwBindingError('Object already scheduled for deletion');
|
|
3151
|
+
}
|
|
3152
|
+
|
|
3153
|
+
detachFinalizer(this);
|
|
3154
|
+
releaseClassHandle(this.$$);
|
|
3155
|
+
|
|
3156
|
+
if (!this.$$.preservePointerOnDelete) {
|
|
3157
|
+
this.$$.smartPtr = undefined;
|
|
3158
|
+
this.$$.ptr = undefined;
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
|
|
3162
|
+
function ClassHandle_isDeleted() {
|
|
3163
|
+
return !this.$$.ptr;
|
|
3164
|
+
}
|
|
3165
|
+
|
|
3166
|
+
|
|
3167
|
+
|
|
3168
|
+
function ClassHandle_deleteLater() {
|
|
3169
|
+
if (!this.$$.ptr) {
|
|
3170
|
+
throwInstanceAlreadyDeleted(this);
|
|
3171
|
+
}
|
|
3172
|
+
if (this.$$.deleteScheduled && !this.$$.preservePointerOnDelete) {
|
|
3173
|
+
throwBindingError('Object already scheduled for deletion');
|
|
3174
|
+
}
|
|
3175
|
+
deletionQueue.push(this);
|
|
3176
|
+
if (deletionQueue.length === 1 && delayFunction) {
|
|
3177
|
+
delayFunction(flushPendingDeletes);
|
|
3178
|
+
}
|
|
3179
|
+
this.$$.deleteScheduled = true;
|
|
3180
|
+
return this;
|
|
3181
|
+
}
|
|
3182
|
+
function init_ClassHandle() {
|
|
3183
|
+
ClassHandle.prototype['isAliasOf'] = ClassHandle_isAliasOf;
|
|
3184
|
+
ClassHandle.prototype['clone'] = ClassHandle_clone;
|
|
3185
|
+
ClassHandle.prototype['delete'] = ClassHandle_delete;
|
|
3186
|
+
ClassHandle.prototype['isDeleted'] = ClassHandle_isDeleted;
|
|
3187
|
+
ClassHandle.prototype['deleteLater'] = ClassHandle_deleteLater;
|
|
3188
|
+
}
|
|
3189
|
+
function ClassHandle() {
|
|
3190
|
+
}
|
|
3191
|
+
|
|
3192
|
+
|
|
3193
|
+
|
|
3194
|
+
|
|
3195
|
+
|
|
3196
|
+
|
|
3197
|
+
/** @constructor */
|
|
3198
|
+
function RegisteredClass(name,
|
|
3199
|
+
constructor,
|
|
3200
|
+
instancePrototype,
|
|
3201
|
+
rawDestructor,
|
|
3202
|
+
baseClass,
|
|
3203
|
+
getActualType,
|
|
3204
|
+
upcast,
|
|
3205
|
+
downcast) {
|
|
3206
|
+
this.name = name;
|
|
3207
|
+
this.constructor = constructor;
|
|
3208
|
+
this.instancePrototype = instancePrototype;
|
|
3209
|
+
this.rawDestructor = rawDestructor;
|
|
3210
|
+
this.baseClass = baseClass;
|
|
3211
|
+
this.getActualType = getActualType;
|
|
3212
|
+
this.upcast = upcast;
|
|
3213
|
+
this.downcast = downcast;
|
|
3214
|
+
this.pureVirtualFunctions = [];
|
|
3215
|
+
}
|
|
3216
|
+
|
|
3217
|
+
|
|
3218
|
+
function upcastPointer(ptr, ptrClass, desiredClass) {
|
|
3219
|
+
// console.log('upcastPointer');
|
|
3220
|
+
while (ptrClass !== desiredClass) {
|
|
3221
|
+
if (!ptrClass.upcast) {
|
|
3222
|
+
throwBindingError(`Expected null or instance of ${desiredClass.name}, got an instance of ${ptrClass.name}`);
|
|
3223
|
+
}
|
|
3224
|
+
ptr = ptrClass.upcast(ptr);
|
|
3225
|
+
ptrClass = ptrClass.baseClass;
|
|
3226
|
+
}
|
|
3227
|
+
return ptr;
|
|
3228
|
+
}
|
|
3229
|
+
function constNoSmartPtrRawPointerToWireType(destructors, handle) {
|
|
3230
|
+
// console.log('constNoSmartPtrRawPointerToWireType');
|
|
3231
|
+
if (handle === null) {
|
|
3232
|
+
if (this.isReference) {
|
|
3233
|
+
throwBindingError('null is not a valid ' + this.name);
|
|
3234
|
+
}
|
|
3235
|
+
return 0;
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
if (!handle.$$) {
|
|
3239
|
+
throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`);
|
|
3240
|
+
}
|
|
3241
|
+
if (!handle.$$.ptr) {
|
|
3242
|
+
throwBindingError('Cannot pass deleted object as a pointer of type ' + this.name);
|
|
3243
|
+
}
|
|
3244
|
+
var handleClass = handle.$$.ptrType.registeredClass;
|
|
3245
|
+
var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
|
|
3246
|
+
return ptr;
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
|
|
3250
|
+
function genericPointerToWireType(destructors, handle) {
|
|
3251
|
+
// console.log('genericPointerToWireType');
|
|
3252
|
+
var ptr;
|
|
3253
|
+
if (handle === null) {
|
|
3254
|
+
if (this.isReference) {
|
|
3255
|
+
throwBindingError('null is not a valid ' + this.name);
|
|
3256
|
+
}
|
|
3257
|
+
|
|
3258
|
+
if (this.isSmartPointer) {
|
|
3259
|
+
ptr = this.rawConstructor();
|
|
3260
|
+
if (destructors !== null) {
|
|
3261
|
+
destructors.push(this.rawDestructor, ptr);
|
|
3262
|
+
}
|
|
3263
|
+
return ptr;
|
|
3264
|
+
} else {
|
|
3265
|
+
return 0;
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
|
|
3269
|
+
if (!handle.$$) {
|
|
3270
|
+
throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`);
|
|
3271
|
+
}
|
|
3272
|
+
if (!handle.$$.ptr) {
|
|
3273
|
+
throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`);
|
|
3274
|
+
}
|
|
3275
|
+
if (!this.isConst && handle.$$.ptrType.isConst) {
|
|
3276
|
+
throwBindingError(`Cannot convert argument of type ${(handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name)} to parameter type ${this.name}`);
|
|
3277
|
+
}
|
|
3278
|
+
var handleClass = handle.$$.ptrType.registeredClass;
|
|
3279
|
+
ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
|
|
3280
|
+
|
|
3281
|
+
if (this.isSmartPointer) {
|
|
3282
|
+
// TODO: this is not strictly true
|
|
3283
|
+
// We could support BY_EMVAL conversions from raw pointers to smart pointers
|
|
3284
|
+
// because the smart pointer can hold a reference to the handle
|
|
3285
|
+
if (undefined === handle.$$.smartPtr) {
|
|
3286
|
+
throwBindingError('Passing raw pointer to smart pointer is illegal');
|
|
3287
|
+
}
|
|
3288
|
+
|
|
3289
|
+
switch (this.sharingPolicy) {
|
|
3290
|
+
case 0: // NONE
|
|
3291
|
+
case 0n:
|
|
3292
|
+
// no upcasting
|
|
3293
|
+
if (handle.$$.smartPtrType === this) {
|
|
3294
|
+
ptr = handle.$$.smartPtr;
|
|
3295
|
+
} else {
|
|
3296
|
+
throwBindingError(`Cannot convert argument of type ${(handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name)} to parameter type ${this.name}`);
|
|
3297
|
+
}
|
|
3298
|
+
break;
|
|
3299
|
+
|
|
3300
|
+
case 1: // INTRUSIVE
|
|
3301
|
+
case 1n:
|
|
3302
|
+
ptr = handle.$$.smartPtr;
|
|
3303
|
+
break;
|
|
3304
|
+
|
|
3305
|
+
case 2: // BY_EMVAL
|
|
3306
|
+
case 2n:
|
|
3307
|
+
if (handle.$$.smartPtrType === this) {
|
|
3308
|
+
ptr = handle.$$.smartPtr;
|
|
3309
|
+
} else {
|
|
3310
|
+
var clonedHandle = handle['clone']();
|
|
3311
|
+
const tt = Emval.toHandle(function () {
|
|
3312
|
+
clonedHandle['delete']();
|
|
3313
|
+
});
|
|
3314
|
+
//console.log('this.rawShare(', ptr, tt);
|
|
3315
|
+
ptr = this.rawShare(
|
|
3316
|
+
ptr,
|
|
3317
|
+
tt
|
|
3318
|
+
);
|
|
3319
|
+
//console.log('this.rawShare = ', ptr);
|
|
3320
|
+
if (destructors !== null) {
|
|
3321
|
+
destructors.push(this.rawDestructor, ptr);
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
break;
|
|
3325
|
+
|
|
3326
|
+
default:
|
|
3327
|
+
throwBindingError('Unsupporting sharing policy');
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
return ptr;
|
|
3331
|
+
}
|
|
3332
|
+
|
|
3333
|
+
|
|
3334
|
+
function nonConstNoSmartPtrRawPointerToWireType(destructors, handle) {
|
|
3335
|
+
// console.log('nonConstNoSmartPtrRawPointerToWireType');
|
|
3336
|
+
if (handle === null) {
|
|
3337
|
+
if (this.isReference) {
|
|
3338
|
+
throwBindingError('null is not a valid ' + this.name);
|
|
3339
|
+
}
|
|
3340
|
+
return 0;
|
|
3341
|
+
}
|
|
3342
|
+
//console.log('nonConstNoSmartPtrRawPointerToWireType 1', handle.$$, handle.smartPtr);
|
|
3343
|
+
|
|
3344
|
+
if (!handle.$$) {
|
|
3345
|
+
throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`);
|
|
3346
|
+
}
|
|
3347
|
+
//console.log('nonConstNoSmartPtrRawPointerToWireType 2');
|
|
3348
|
+
if (!handle.$$.ptr) {
|
|
3349
|
+
throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`);
|
|
3350
|
+
}
|
|
3351
|
+
//console.log('nonConstNoSmartPtrRawPointerToWireType 3');
|
|
3352
|
+
if (handle.$$.ptrType.isConst) {
|
|
3353
|
+
throwBindingError(`Cannot convert argument of type ${handle.$$.ptrType.name} to parameter type ${this.name}`);
|
|
3354
|
+
}
|
|
3355
|
+
//console.log('nonConstNoSmartPtrRawPointerToWireType 4');
|
|
3356
|
+
var handleClass = handle.$$.ptrType.registeredClass;
|
|
3357
|
+
var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
|
|
3358
|
+
//console.log('nonConstNoSmartPtrRawPointerToWireType 5');
|
|
3359
|
+
return ptr;
|
|
3360
|
+
}
|
|
3361
|
+
|
|
3362
|
+
|
|
3363
|
+
function RegisteredPointer_getPointee(ptr) {
|
|
3364
|
+
//console.log('RegisteredPointer_getPointee', ptr, this.rawGetPointee);
|
|
3365
|
+
if (this.rawGetPointee) {
|
|
3366
|
+
ptr = this.rawGetPointee(ptr);
|
|
3367
|
+
}
|
|
3368
|
+
return ptr;
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3371
|
+
function RegisteredPointer_destructor(ptr) {
|
|
3372
|
+
if (this.rawDestructor) {
|
|
3373
|
+
this.rawDestructor(ptr);
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
|
|
3377
|
+
function RegisteredPointer_deleteObject(handle) {
|
|
3378
|
+
if (handle !== null) {
|
|
3379
|
+
handle['delete']();
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
|
|
3383
|
+
function init_RegisteredPointer() {
|
|
3384
|
+
RegisteredPointer.prototype.getPointee = RegisteredPointer_getPointee;
|
|
3385
|
+
RegisteredPointer.prototype.destructor = RegisteredPointer_destructor;
|
|
3386
|
+
RegisteredPointer.prototype['argPackAdvance'] = 8n;
|
|
3387
|
+
RegisteredPointer.prototype['readValueFromPointer'] = simpleReadValueFromPointer64;
|
|
3388
|
+
RegisteredPointer.prototype['deleteObject'] = RegisteredPointer_deleteObject;
|
|
3389
|
+
RegisteredPointer.prototype['fromWireType'] = RegisteredPointer_fromWireType;
|
|
3390
|
+
}
|
|
3391
|
+
/** @constructor
|
|
3392
|
+
@param {*=} pointeeType,
|
|
3393
|
+
@param {*=} sharingPolicy,
|
|
3394
|
+
@param {*=} rawGetPointee,
|
|
3395
|
+
@param {*=} rawConstructor,
|
|
3396
|
+
@param {*=} rawShare,
|
|
3397
|
+
@param {*=} rawDestructor,
|
|
3398
|
+
*/
|
|
3399
|
+
function RegisteredPointer(
|
|
3400
|
+
name,
|
|
3401
|
+
registeredClass,
|
|
3402
|
+
isReference,
|
|
3403
|
+
isConst,
|
|
3404
|
+
|
|
3405
|
+
// smart pointer properties
|
|
3406
|
+
isSmartPointer,
|
|
3407
|
+
pointeeType,
|
|
3408
|
+
sharingPolicy,
|
|
3409
|
+
rawGetPointee,
|
|
3410
|
+
rawConstructor,
|
|
3411
|
+
rawShare,
|
|
3412
|
+
rawDestructor
|
|
3413
|
+
) {
|
|
3414
|
+
this.name = name;
|
|
3415
|
+
this.registeredClass = registeredClass;
|
|
3416
|
+
this.isReference = isReference;
|
|
3417
|
+
this.isConst = isConst;
|
|
3418
|
+
|
|
3419
|
+
// smart pointer properties
|
|
3420
|
+
this.isSmartPointer = isSmartPointer;
|
|
3421
|
+
this.pointeeType = pointeeType;
|
|
3422
|
+
this.sharingPolicy = sharingPolicy;
|
|
3423
|
+
this.rawGetPointee = rawGetPointee;
|
|
3424
|
+
this.rawConstructor = rawConstructor;
|
|
3425
|
+
this.rawShare = rawShare;
|
|
3426
|
+
this.rawDestructor = rawDestructor;
|
|
3427
|
+
|
|
3428
|
+
if (!isSmartPointer && registeredClass.baseClass === undefined) {
|
|
3429
|
+
if (isConst) {
|
|
3430
|
+
this['toWireType'] = constNoSmartPtrRawPointerToWireType;
|
|
3431
|
+
this.destructorFunction = null;
|
|
3432
|
+
} else {
|
|
3433
|
+
this['toWireType'] = nonConstNoSmartPtrRawPointerToWireType;
|
|
3434
|
+
this.destructorFunction = null;
|
|
3435
|
+
}
|
|
3436
|
+
} else {
|
|
3437
|
+
this['toWireType'] = genericPointerToWireType;
|
|
3438
|
+
// Here we must leave this.destructorFunction undefined, since whether genericPointerToWireType returns
|
|
3439
|
+
// a pointer that needs to be freed up is runtime-dependent, and cannot be evaluated at registration time.
|
|
3440
|
+
// TODO: Create an alternative mechanism that allows removing the use of var destructors = []; array in
|
|
3441
|
+
// craftInvokerFunction altogether.
|
|
3442
|
+
}
|
|
3443
|
+
}
|
|
3444
|
+
|
|
3445
|
+
|
|
3446
|
+
|
|
3447
|
+
|
|
3448
|
+
function __embind_register_class(rawType,
|
|
3449
|
+
rawPointerType,
|
|
3450
|
+
rawConstPointerType,
|
|
3451
|
+
baseClassRawType,
|
|
3452
|
+
getActualTypeSignature,
|
|
3453
|
+
getActualType,
|
|
3454
|
+
upcastSignature,
|
|
3455
|
+
upcast,
|
|
3456
|
+
downcastSignature,
|
|
3457
|
+
downcast,
|
|
3458
|
+
name,
|
|
3459
|
+
destructorSignature,
|
|
3460
|
+
rawDestructor) {
|
|
3461
|
+
/* console.log('__embind_register_class', rawType,
|
|
3462
|
+
rawPointerType,
|
|
3463
|
+
rawConstPointerType,
|
|
3464
|
+
baseClassRawType,
|
|
3465
|
+
getActualTypeSignature,
|
|
3466
|
+
getActualType,
|
|
3467
|
+
upcastSignature,
|
|
3468
|
+
upcast,
|
|
3469
|
+
downcastSignature,
|
|
3470
|
+
downcast,
|
|
3471
|
+
name,
|
|
3472
|
+
destructorSignature,
|
|
3473
|
+
rawDestructor); */
|
|
3474
|
+
name = readLatin1String(name);
|
|
3475
|
+
getActualType = embind__requireFunction(getActualTypeSignature, getActualType);
|
|
3476
|
+
if (upcast) {
|
|
3477
|
+
upcast = embind__requireFunction(upcastSignature, upcast);
|
|
3478
|
+
// upcast = (...a) => {console.log('----------------------------->', a); };
|
|
3479
|
+
}
|
|
3480
|
+
if (downcast) {
|
|
3481
|
+
downcast = embind__requireFunction(downcastSignature, downcast);
|
|
3482
|
+
}
|
|
3483
|
+
rawDestructor = embind__requireFunction(destructorSignature, rawDestructor);
|
|
3484
|
+
var legalFunctionName = makeLegalFunctionName(name);
|
|
3485
|
+
|
|
3486
|
+
exposePublicSymbol(legalFunctionName, function () {
|
|
3487
|
+
// this code cannot run if baseClassRawType is zero
|
|
3488
|
+
throwUnboundTypeError(`Cannot construct ${name} due to unbound types`, [baseClassRawType]);
|
|
3489
|
+
});
|
|
3490
|
+
|
|
3491
|
+
whenDependentTypesAreResolved(
|
|
3492
|
+
[rawType, rawPointerType, rawConstPointerType],
|
|
3493
|
+
baseClassRawType ? [baseClassRawType] : [],
|
|
3494
|
+
function (base) {
|
|
3495
|
+
base = base[0];
|
|
3496
|
+
|
|
3497
|
+
var baseClass;
|
|
3498
|
+
var basePrototype;
|
|
3499
|
+
if (baseClassRawType) {
|
|
3500
|
+
baseClass = base.registeredClass;
|
|
3501
|
+
basePrototype = baseClass.instancePrototype;
|
|
3502
|
+
} else {
|
|
3503
|
+
basePrototype = ClassHandle.prototype;
|
|
3504
|
+
}
|
|
3505
|
+
//console.log('__embind_register_class -> ', name, baseClassRawType, baseClass, basePrototype, ClassHandle);
|
|
3506
|
+
|
|
3507
|
+
var constructor = createNamedFunction(legalFunctionName, function () {
|
|
3508
|
+
if (Object.getPrototypeOf(this) !== instancePrototype) {
|
|
3509
|
+
throw new BindingError("Use 'new' to construct " + name);
|
|
3510
|
+
}
|
|
3511
|
+
if (undefined === registeredClass.constructor_body) {
|
|
3512
|
+
throw new BindingError(name + " has no accessible constructor");
|
|
3513
|
+
}
|
|
3514
|
+
var body = registeredClass.constructor_body[arguments.length];
|
|
3515
|
+
if (undefined === body) {
|
|
3516
|
+
throw new BindingError(`Tried to invoke ctor of ${name} with invalid number of parameters (${arguments.length}) - expected (${Object.keys(registeredClass.constructor_body).toString()}) parameters instead!`);
|
|
3517
|
+
}
|
|
3518
|
+
return body.apply(this, arguments);
|
|
3519
|
+
});
|
|
3520
|
+
|
|
3521
|
+
var instancePrototype = Object.create(basePrototype, {
|
|
3522
|
+
constructor: { value: constructor },
|
|
3523
|
+
});
|
|
3524
|
+
|
|
3525
|
+
//console.log('__embind_register_class -> instancePrototype: ', name, Object.keys(basePrototype), instancePrototype.constructor);
|
|
3526
|
+
|
|
3527
|
+
constructor.prototype = instancePrototype;
|
|
3528
|
+
|
|
3529
|
+
var registeredClass = new RegisteredClass(name,
|
|
3530
|
+
constructor,
|
|
3531
|
+
instancePrototype,
|
|
3532
|
+
rawDestructor,
|
|
3533
|
+
baseClass,
|
|
3534
|
+
getActualType,
|
|
3535
|
+
upcast,
|
|
3536
|
+
downcast);
|
|
3537
|
+
|
|
3538
|
+
if (registeredClass.baseClass) {
|
|
3539
|
+
// Keep track of class hierarchy. Used to allow sub-classes to inherit class functions.
|
|
3540
|
+
if (registeredClass.baseClass.__derivedClasses === undefined) {
|
|
3541
|
+
registeredClass.baseClass.__derivedClasses = [];
|
|
3542
|
+
}
|
|
3543
|
+
|
|
3544
|
+
registeredClass.baseClass.__derivedClasses.push(registeredClass);
|
|
3545
|
+
}
|
|
3546
|
+
|
|
3547
|
+
var referenceConverter = new RegisteredPointer(name,
|
|
3548
|
+
registeredClass,
|
|
3549
|
+
true,
|
|
3550
|
+
false,
|
|
3551
|
+
false);
|
|
3552
|
+
|
|
3553
|
+
var pointerConverter = new RegisteredPointer(name + '*',
|
|
3554
|
+
registeredClass,
|
|
3555
|
+
false,
|
|
3556
|
+
false,
|
|
3557
|
+
false);
|
|
3558
|
+
|
|
3559
|
+
var constPointerConverter = new RegisteredPointer(name + ' const*',
|
|
3560
|
+
registeredClass,
|
|
3561
|
+
false,
|
|
3562
|
+
true,
|
|
3563
|
+
false);
|
|
3564
|
+
|
|
3565
|
+
registeredPointers[rawType] = {
|
|
3566
|
+
pointerType: pointerConverter,
|
|
3567
|
+
constPointerType: constPointerConverter
|
|
3568
|
+
};
|
|
3569
|
+
|
|
3570
|
+
replacePublicSymbol(legalFunctionName, constructor);
|
|
3571
|
+
|
|
3572
|
+
return [referenceConverter, pointerConverter, constPointerConverter];
|
|
3573
|
+
}
|
|
3574
|
+
);
|
|
3575
|
+
}
|
|
3576
|
+
|
|
3577
|
+
globalThis.__embind_register_class = __embind_register_class;
|
|
3578
|
+
|
|
3579
|
+
|
|
3580
|
+
|
|
3581
|
+
|
|
3582
|
+
|
|
3583
|
+
function __embind_register_class_constructor(
|
|
3584
|
+
rawClassType,
|
|
3585
|
+
argCount,
|
|
3586
|
+
rawArgTypesAddr,
|
|
3587
|
+
invokerSignature,
|
|
3588
|
+
invoker,
|
|
3589
|
+
rawConstructor
|
|
3590
|
+
) {
|
|
3591
|
+
/* console.log('__embind_register_class_constructor', rawClassType,
|
|
3592
|
+
argCount,
|
|
3593
|
+
rawArgTypesAddr,
|
|
3594
|
+
invokerSignature,
|
|
3595
|
+
invoker,
|
|
3596
|
+
rawConstructor); */
|
|
3597
|
+
assert(argCount > 0);
|
|
3598
|
+
var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
|
|
3599
|
+
invoker = embind__requireFunction(invokerSignature, invoker, true);
|
|
3600
|
+
var args = [rawConstructor];
|
|
3601
|
+
var destructors = [];
|
|
3602
|
+
|
|
3603
|
+
whenDependentTypesAreResolved([], [rawClassType], function (classType) {
|
|
3604
|
+
classType = classType[0];
|
|
3605
|
+
var humanName = 'constructor ' + classType.name;
|
|
3606
|
+
|
|
3607
|
+
if (undefined === classType.registeredClass.constructor_body) {
|
|
3608
|
+
classType.registeredClass.constructor_body = [];
|
|
3609
|
+
}
|
|
3610
|
+
if (undefined !== classType.registeredClass.constructor_body[argCount - 1]) {
|
|
3611
|
+
throw new BindingError(`Cannot register multiple constructors with identical number of parameters (${argCount - 1}) for class '${classType.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);
|
|
3612
|
+
}
|
|
3613
|
+
classType.registeredClass.constructor_body[argCount - 1] = () => {
|
|
3614
|
+
throwUnboundTypeError(`Cannot construct ${classType.name} due to unbound types`, rawArgTypes);
|
|
3615
|
+
};
|
|
3616
|
+
|
|
3617
|
+
whenDependentTypesAreResolved([], rawArgTypes, function (argTypes) {
|
|
3618
|
+
// Insert empty slot for context type (argTypes[1]).
|
|
3619
|
+
argTypes.splice(1, 0, null);
|
|
3620
|
+
classType.registeredClass.constructor_body[argCount - 1] = craftInvokerFunction(humanName, argTypes, null, invoker, rawConstructor);
|
|
3621
|
+
return [];
|
|
3622
|
+
});
|
|
3623
|
+
return [];
|
|
3624
|
+
});
|
|
3625
|
+
}
|
|
3626
|
+
|
|
3627
|
+
globalThis.__embind_register_class_constructor = __embind_register_class_constructor;
|
|
3628
|
+
|
|
3629
|
+
|
|
3630
|
+
|
|
3631
|
+
|
|
3632
|
+
|
|
3633
|
+
function __embind_register_class_function(rawClassType,
|
|
3634
|
+
methodName,
|
|
3635
|
+
argCount,
|
|
3636
|
+
rawArgTypesAddr, // [ReturnType, ThisType, Args...]
|
|
3637
|
+
invokerSignature,
|
|
3638
|
+
rawInvoker,
|
|
3639
|
+
context,
|
|
3640
|
+
isPureVirtual,
|
|
3641
|
+
isAsync) {
|
|
3642
|
+
// console.log('__embind_register_class_function', methodName, argCount);
|
|
3643
|
+
var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
|
|
3644
|
+
methodName = readLatin1String(methodName);
|
|
3645
|
+
rawInvoker = embind__requireFunction(invokerSignature, rawInvoker, true);
|
|
3646
|
+
|
|
3647
|
+
whenDependentTypesAreResolved([], [rawClassType], function (classType) {
|
|
3648
|
+
//console.log(methodName, argCount);
|
|
3649
|
+
classType = classType[0];
|
|
3650
|
+
var humanName = classType.name + '.' + methodName;
|
|
3651
|
+
|
|
3652
|
+
if (methodName.startsWith("@@")) {
|
|
3653
|
+
methodName = Symbol[methodName.substring(2)];
|
|
3654
|
+
}
|
|
3655
|
+
|
|
3656
|
+
if (isPureVirtual) {
|
|
3657
|
+
classType.registeredClass.pureVirtualFunctions.push(methodName);
|
|
3658
|
+
}
|
|
3659
|
+
|
|
3660
|
+
function unboundTypesHandler() {
|
|
3661
|
+
//console.log(`Cannot call2 ${humanName} due to unbound types`, rawArgTypes, rawArgTypes.map(a => registeredTypes[a]));
|
|
3662
|
+
throwUnboundTypeError(`Cannot call2 ${humanName} due to unbound types`, rawArgTypes);
|
|
3663
|
+
}
|
|
3664
|
+
|
|
3665
|
+
var proto = classType.registeredClass.instancePrototype;
|
|
3666
|
+
var method = proto[methodName];
|
|
3667
|
+
if (undefined === method || (undefined === method.overloadTable && method.className !== classType.name && method.argCount === argCount - 2)) {
|
|
3668
|
+
// This is the first overload to be registered, OR we are replacing a
|
|
3669
|
+
// function in the base class with a function in the derived class.
|
|
3670
|
+
unboundTypesHandler.argCount = argCount - 2;
|
|
3671
|
+
unboundTypesHandler.className = classType.name;
|
|
3672
|
+
proto[methodName] = unboundTypesHandler;
|
|
3673
|
+
} else {
|
|
3674
|
+
// There was an existing function with the same name registered. Set up
|
|
3675
|
+
// a function overload routing table.
|
|
3676
|
+
ensureOverloadTable(proto, methodName, humanName);
|
|
3677
|
+
proto[methodName].overloadTable[argCount - 2] = unboundTypesHandler;
|
|
3678
|
+
}
|
|
3679
|
+
|
|
3680
|
+
whenDependentTypesAreResolved([], rawArgTypes, function (argTypes) {
|
|
3681
|
+
//console.log(methodName);
|
|
3682
|
+
var memberFunction = craftInvokerFunction(humanName, argTypes, classType, rawInvoker, context, isAsync);
|
|
3683
|
+
|
|
3684
|
+
// Replace the initial unbound-handler-stub function with the appropriate member function, now that all types
|
|
3685
|
+
// are resolved. If multiple overloads are registered for this function, the function goes into an overload table.
|
|
3686
|
+
if (undefined === proto[methodName].overloadTable) {
|
|
3687
|
+
// Set argCount in case an overload is registered later
|
|
3688
|
+
memberFunction.argCount = argCount - 2;
|
|
3689
|
+
proto[methodName] = memberFunction;
|
|
3690
|
+
} else {
|
|
3691
|
+
proto[methodName].overloadTable[argCount - 2] = memberFunction;
|
|
3692
|
+
}
|
|
3693
|
+
|
|
3694
|
+
return [];
|
|
3695
|
+
});
|
|
3696
|
+
return [];
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3699
|
+
|
|
3700
|
+
globalThis.__embind_register_class_function = __embind_register_class_function;
|
|
3701
|
+
|
|
3702
|
+
|
|
3703
|
+
|
|
3704
|
+
|
|
3705
|
+
|
|
3706
|
+
|
|
3707
|
+
function validateThis(this_, classType, humanName) {
|
|
3708
|
+
if (!(this_ instanceof Object)) {
|
|
3709
|
+
throwBindingError(humanName + ' with invalid "this": ' + this_);
|
|
3710
|
+
}
|
|
3711
|
+
if (!(this_ instanceof classType.registeredClass.constructor)) {
|
|
3712
|
+
throwBindingError(humanName + ' incompatible with "this" of type ' + this_.constructor.name);
|
|
3713
|
+
}
|
|
3714
|
+
if (!this_.$$.ptr) {
|
|
3715
|
+
throwBindingError(`cannot call emscripten binding method ${humanName} on deleted object`);
|
|
3716
|
+
}
|
|
3717
|
+
// console.log('validateThis');
|
|
3718
|
+
|
|
3719
|
+
// todo: kill this
|
|
3720
|
+
return upcastPointer(this_.$$.ptr,
|
|
3721
|
+
this_.$$.ptrType.registeredClass,
|
|
3722
|
+
classType.registeredClass);
|
|
3723
|
+
}
|
|
3724
|
+
function __embind_register_class_property(classType,
|
|
3725
|
+
fieldName,
|
|
3726
|
+
getterReturnType,
|
|
3727
|
+
getterSignature,
|
|
3728
|
+
getter,
|
|
3729
|
+
getterContext,
|
|
3730
|
+
setterArgumentType,
|
|
3731
|
+
setterSignature,
|
|
3732
|
+
setter,
|
|
3733
|
+
setterContext) {
|
|
3734
|
+
fieldName = readLatin1String(fieldName);
|
|
3735
|
+
getter = embind__requireFunction(getterSignature, getter);
|
|
3736
|
+
|
|
3737
|
+
whenDependentTypesAreResolved([], [classType], function (classType) {
|
|
3738
|
+
classType = classType[0];
|
|
3739
|
+
var humanName = classType.name + '.' + fieldName;
|
|
3740
|
+
var desc = {
|
|
3741
|
+
get: function () {
|
|
3742
|
+
throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [getterReturnType, setterArgumentType]);
|
|
3743
|
+
},
|
|
3744
|
+
enumerable: true,
|
|
3745
|
+
configurable: true
|
|
3746
|
+
};
|
|
3747
|
+
if (setter && setterContext) {
|
|
3748
|
+
desc.set = () => {
|
|
3749
|
+
throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [getterReturnType, setterArgumentType]);
|
|
3750
|
+
};
|
|
3751
|
+
} else {
|
|
3752
|
+
desc.set = (v) => {
|
|
3753
|
+
throwBindingError(humanName + ' is a read-only property');
|
|
3754
|
+
};
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
Object.defineProperty(classType.registeredClass.instancePrototype, fieldName, desc);
|
|
3758
|
+
|
|
3759
|
+
whenDependentTypesAreResolved(
|
|
3760
|
+
[],
|
|
3761
|
+
(setter && setterContext ? [getterReturnType, setterArgumentType] : [getterReturnType]),
|
|
3762
|
+
function (types) {
|
|
3763
|
+
var getterReturnType = types[0];
|
|
3764
|
+
var desc = {
|
|
3765
|
+
get: function () {
|
|
3766
|
+
// console.log('get -> ', this.$$.ptr);
|
|
3767
|
+
var ptr = validateThis(this, classType, humanName + ' getter');
|
|
3768
|
+
return getterReturnType['fromWireType'](getter(getterContext, ptr));
|
|
3769
|
+
},
|
|
3770
|
+
enumerable: true
|
|
3771
|
+
};
|
|
3772
|
+
|
|
3773
|
+
if (setter && setterContext) {
|
|
3774
|
+
setter = embind__requireFunction(setterSignature, setter);
|
|
3775
|
+
var setterArgumentType = types[1];
|
|
3776
|
+
desc.set = function (v) {
|
|
3777
|
+
// console.log('set -> ', this.$$.ptr);
|
|
3778
|
+
var ptr = validateThis(this, classType, humanName + ' setter');
|
|
3779
|
+
var destructors = [];
|
|
3780
|
+
setter(setterContext, ptr, setterArgumentType['toWireType'](destructors, v));
|
|
3781
|
+
runDestructors(destructors);
|
|
3782
|
+
};
|
|
3783
|
+
}
|
|
3784
|
+
|
|
3785
|
+
// console.log('__embind_register_class_property', fieldName, desc);
|
|
3786
|
+
|
|
3787
|
+
Object.defineProperty(classType.registeredClass.instancePrototype, fieldName, desc);
|
|
3788
|
+
return [];
|
|
3789
|
+
});
|
|
3790
|
+
|
|
3791
|
+
return [];
|
|
3792
|
+
});
|
|
3793
|
+
}
|
|
3794
|
+
|
|
3795
|
+
globalThis.__embind_register_class_property = __embind_register_class_property;
|
|
3796
|
+
|
|
3797
|
+
|
|
3798
|
+
|
|
3799
|
+
|
|
3800
|
+
|
|
3801
|
+
function __embind_register_class_class_function(rawClassType,
|
|
3802
|
+
methodName,
|
|
3803
|
+
argCount,
|
|
3804
|
+
rawArgTypesAddr,
|
|
3805
|
+
invokerSignature,
|
|
3806
|
+
rawInvoker,
|
|
3807
|
+
fn,
|
|
3808
|
+
isAsync) {
|
|
3809
|
+
var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
|
|
3810
|
+
methodName = readLatin1String(methodName);
|
|
3811
|
+
rawInvoker = embind__requireFunction(invokerSignature, rawInvoker, true);
|
|
3812
|
+
whenDependentTypesAreResolved([], [rawClassType], function (classType) {
|
|
3813
|
+
classType = classType[0];
|
|
3814
|
+
var humanName = classType.name + '.' + methodName;
|
|
3815
|
+
|
|
3816
|
+
function unboundTypesHandler() {
|
|
3817
|
+
throwUnboundTypeError(`Cannot call ${humanName} due to unbound types`, rawArgTypes);
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3820
|
+
if (methodName.startsWith("@@")) {
|
|
3821
|
+
methodName = Symbol[methodName.substring(2)];
|
|
3822
|
+
}
|
|
3823
|
+
|
|
3824
|
+
var proto = classType.registeredClass.constructor;
|
|
3825
|
+
if (undefined === proto[methodName]) {
|
|
3826
|
+
// This is the first function to be registered with this name.
|
|
3827
|
+
unboundTypesHandler.argCount = argCount - 1;
|
|
3828
|
+
proto[methodName] = unboundTypesHandler;
|
|
3829
|
+
} else {
|
|
3830
|
+
// There was an existing function with the same name registered. Set up
|
|
3831
|
+
// a function overload routing table.
|
|
3832
|
+
ensureOverloadTable(proto, methodName, humanName);
|
|
3833
|
+
proto[methodName].overloadTable[argCount - 1] = unboundTypesHandler;
|
|
3834
|
+
}
|
|
3835
|
+
|
|
3836
|
+
whenDependentTypesAreResolved([], rawArgTypes, function (argTypes) {
|
|
3837
|
+
// Replace the initial unbound-types-handler stub with the proper
|
|
3838
|
+
// function. If multiple overloads are registered, the function handlers
|
|
3839
|
+
// go into an overload table.
|
|
3840
|
+
var invokerArgsArray = [argTypes[0] /* return value */, null /* no class 'this'*/].concat(argTypes.slice(1) /* actual params */);
|
|
3841
|
+
var func = craftInvokerFunction(humanName, invokerArgsArray, null /* no class 'this'*/, rawInvoker, fn, isAsync);
|
|
3842
|
+
if (undefined === proto[methodName].overloadTable) {
|
|
3843
|
+
func.argCount = argCount - 1;
|
|
3844
|
+
proto[methodName] = func;
|
|
3845
|
+
} else {
|
|
3846
|
+
proto[methodName].overloadTable[argCount - 1] = func;
|
|
3847
|
+
}
|
|
3848
|
+
|
|
3849
|
+
if (classType.registeredClass.__derivedClasses) {
|
|
3850
|
+
for (const derivedClass of classType.registeredClass.__derivedClasses) {
|
|
3851
|
+
if (!derivedClass.constructor.hasOwnProperty(methodName)) {
|
|
3852
|
+
// TODO: Add support for overloads
|
|
3853
|
+
derivedClass.constructor[methodName] = func;
|
|
3854
|
+
}
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
|
|
3858
|
+
return [];
|
|
3859
|
+
});
|
|
3860
|
+
return [];
|
|
3861
|
+
});
|
|
3862
|
+
}
|
|
3863
|
+
|
|
3864
|
+
globalThis.__embind_register_class_class_function = __embind_register_class_class_function;
|
|
3865
|
+
|
|
3866
|
+
|
|
3867
|
+
|
|
3868
|
+
|
|
3869
|
+
|
|
3870
|
+
function __embind_register_class_class_property(rawClassType,
|
|
3871
|
+
fieldName,
|
|
3872
|
+
rawFieldType,
|
|
3873
|
+
rawFieldPtr,
|
|
3874
|
+
getterSignature,
|
|
3875
|
+
getter,
|
|
3876
|
+
setterSignature,
|
|
3877
|
+
setter) {
|
|
3878
|
+
fieldName = readLatin1String(fieldName);
|
|
3879
|
+
getter = embind__requireFunction(getterSignature, getter);
|
|
3880
|
+
|
|
3881
|
+
whenDependentTypesAreResolved([], [rawClassType], function (classType) {
|
|
3882
|
+
classType = classType[0];
|
|
3883
|
+
var humanName = classType.name + '.' + fieldName;
|
|
3884
|
+
var desc = {
|
|
3885
|
+
get: function () {
|
|
3886
|
+
throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [rawFieldType]);
|
|
3887
|
+
},
|
|
3888
|
+
enumerable: true,
|
|
3889
|
+
configurable: true
|
|
3890
|
+
};
|
|
3891
|
+
if (setter && setterSignature !== "") {
|
|
3892
|
+
desc.set = () => {
|
|
3893
|
+
throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [rawFieldType]);
|
|
3894
|
+
};
|
|
3895
|
+
} else {
|
|
3896
|
+
desc.set = (v) => {
|
|
3897
|
+
throwBindingError(`${humanName} is a read-only property`);
|
|
3898
|
+
};
|
|
3899
|
+
}
|
|
3900
|
+
|
|
3901
|
+
Object.defineProperty(classType.registeredClass.constructor, fieldName, desc);
|
|
3902
|
+
|
|
3903
|
+
whenDependentTypesAreResolved([], [rawFieldType], function (fieldType) {
|
|
3904
|
+
fieldType = fieldType[0];
|
|
3905
|
+
var desc = {
|
|
3906
|
+
get: function () {
|
|
3907
|
+
return fieldType['fromWireType'](getter(rawFieldPtr));
|
|
3908
|
+
},
|
|
3909
|
+
enumerable: true
|
|
3910
|
+
};
|
|
3911
|
+
|
|
3912
|
+
if (setter && setterSignature !== "") {
|
|
3913
|
+
setter = embind__requireFunction(setterSignature, setter);
|
|
3914
|
+
desc.set = (v) => {
|
|
3915
|
+
var destructors = [];
|
|
3916
|
+
setter(rawFieldPtr, fieldType['toWireType'](destructors, v));
|
|
3917
|
+
runDestructors(destructors);
|
|
3918
|
+
};
|
|
3919
|
+
}
|
|
3920
|
+
|
|
3921
|
+
Object.defineProperty(classType.registeredClass.constructor, fieldName, desc);
|
|
3922
|
+
return [];
|
|
3923
|
+
});
|
|
3924
|
+
|
|
3925
|
+
return [];
|
|
3926
|
+
});
|
|
3927
|
+
}
|
|
3928
|
+
|
|
3929
|
+
globalThis.__embind_register_class_class_property = __embind_register_class_class_property;
|
|
3930
|
+
|
|
3931
|
+
var PureVirtualError = undefined;
|
|
3932
|
+
|
|
3933
|
+
|
|
3934
|
+
|
|
3935
|
+
|
|
3936
|
+
function registerInheritedInstance(class_, ptr, instance) {
|
|
3937
|
+
ptr = getBasestPointer(class_, ptr);
|
|
3938
|
+
if (registeredInstances.hasOwnProperty(ptr)) {
|
|
3939
|
+
throwBindingError('Tried to register registered instance: ' + ptr);
|
|
3940
|
+
} else {
|
|
3941
|
+
registeredInstances[ptr] = instance;
|
|
3942
|
+
}
|
|
3943
|
+
}
|
|
3944
|
+
|
|
3945
|
+
|
|
3946
|
+
|
|
3947
|
+
function requireRegisteredType(rawType, humanName) {
|
|
3948
|
+
//console.log('requireRegisteredType', rawType, humanName);
|
|
3949
|
+
var impl = registeredTypes[rawType];
|
|
3950
|
+
//console.log('requireRegisteredType value: ', impl);
|
|
3951
|
+
if (undefined === impl) {
|
|
3952
|
+
throwBindingError(humanName + " has unknown type " + getTypeName(rawType));
|
|
3953
|
+
}
|
|
3954
|
+
return impl;
|
|
3955
|
+
}
|
|
3956
|
+
|
|
3957
|
+
|
|
3958
|
+
|
|
3959
|
+
|
|
3960
|
+
function unregisterInheritedInstance(class_, ptr) {
|
|
3961
|
+
ptr = getBasestPointer(class_, ptr);
|
|
3962
|
+
if (registeredInstances.hasOwnProperty(ptr)) {
|
|
3963
|
+
delete registeredInstances[ptr];
|
|
3964
|
+
} else {
|
|
3965
|
+
throwBindingError('Tried to unregister unregistered instance: ' + ptr);
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
|
|
3969
|
+
|
|
3970
|
+
function __embind_create_inheriting_constructor(constructorName, wrapperType, properties) {
|
|
3971
|
+
constructorName = readLatin1String(constructorName);
|
|
3972
|
+
wrapperType = requireRegisteredType(wrapperType, 'wrapper');
|
|
3973
|
+
properties = Emval.toValue(properties);
|
|
3974
|
+
|
|
3975
|
+
var arraySlice = [].slice;
|
|
3976
|
+
|
|
3977
|
+
var registeredClass = wrapperType.registeredClass;
|
|
3978
|
+
var wrapperPrototype = registeredClass.instancePrototype;
|
|
3979
|
+
var baseClass = registeredClass.baseClass;
|
|
3980
|
+
var baseClassPrototype = baseClass.instancePrototype;
|
|
3981
|
+
var baseConstructor = registeredClass.baseClass.constructor;
|
|
3982
|
+
var ctor = createNamedFunction(constructorName, function () {
|
|
3983
|
+
registeredClass.baseClass.pureVirtualFunctions.forEach(function (name) {
|
|
3984
|
+
if (this[name] === baseClassPrototype[name]) {
|
|
3985
|
+
throw new PureVirtualError(`Pure virtual function ${name} must be implemented in JavaScript`);
|
|
3986
|
+
}
|
|
3987
|
+
}.bind(this));
|
|
3988
|
+
|
|
3989
|
+
Object.defineProperty(this, '__parent', {
|
|
3990
|
+
value: wrapperPrototype
|
|
3991
|
+
});
|
|
3992
|
+
this["__construct"].apply(this, arraySlice.call(arguments));
|
|
3993
|
+
});
|
|
3994
|
+
|
|
3995
|
+
// It's a little nasty that we're modifying the wrapper prototype here.
|
|
3996
|
+
|
|
3997
|
+
wrapperPrototype["__construct"] = function __construct() {
|
|
3998
|
+
if (this === wrapperPrototype) {
|
|
3999
|
+
throwBindingError("Pass correct 'this' to __construct");
|
|
4000
|
+
}
|
|
4001
|
+
|
|
4002
|
+
var inner = baseConstructor["implement"].apply(
|
|
4003
|
+
undefined,
|
|
4004
|
+
[this].concat(arraySlice.call(arguments)));
|
|
4005
|
+
detachFinalizer(inner);
|
|
4006
|
+
var $$ = inner.$$;
|
|
4007
|
+
inner["notifyOnDestruction"]();
|
|
4008
|
+
$$.preservePointerOnDelete = true;
|
|
4009
|
+
Object.defineProperties(this, {
|
|
4010
|
+
$$: {
|
|
4011
|
+
value: $$
|
|
4012
|
+
}
|
|
4013
|
+
});
|
|
4014
|
+
attachFinalizer(this);
|
|
4015
|
+
registerInheritedInstance(registeredClass, $$.ptr, this);
|
|
4016
|
+
};
|
|
4017
|
+
|
|
4018
|
+
wrapperPrototype["__destruct"] = function __destruct() {
|
|
4019
|
+
if (this === wrapperPrototype) {
|
|
4020
|
+
throwBindingError("Pass correct 'this' to __destruct");
|
|
4021
|
+
}
|
|
4022
|
+
|
|
4023
|
+
detachFinalizer(this);
|
|
4024
|
+
unregisterInheritedInstance(registeredClass, this.$$.ptr);
|
|
4025
|
+
};
|
|
4026
|
+
|
|
4027
|
+
ctor.prototype = Object.create(wrapperPrototype);
|
|
4028
|
+
for (var p in properties) {
|
|
4029
|
+
ctor.prototype[p] = properties[p];
|
|
4030
|
+
}
|
|
4031
|
+
return Emval.toHandle(ctor);
|
|
4032
|
+
}
|
|
4033
|
+
|
|
4034
|
+
globalThis.__embind_create_inheriting_constructor = __embind_create_inheriting_constructor;
|
|
4035
|
+
|
|
4036
|
+
|
|
4037
|
+
function __embind_register_smart_ptr(rawType,
|
|
4038
|
+
rawPointeeType,
|
|
4039
|
+
name,
|
|
4040
|
+
sharingPolicy,
|
|
4041
|
+
getPointeeSignature,
|
|
4042
|
+
rawGetPointee,
|
|
4043
|
+
constructorSignature,
|
|
4044
|
+
rawConstructor,
|
|
4045
|
+
shareSignature,
|
|
4046
|
+
rawShare,
|
|
4047
|
+
destructorSignature,
|
|
4048
|
+
rawDestructor) {
|
|
4049
|
+
/* console.log('__embind_register_smart_ptr', rawType,
|
|
4050
|
+
rawPointeeType,
|
|
4051
|
+
name,
|
|
4052
|
+
sharingPolicy,
|
|
4053
|
+
getPointeeSignature,
|
|
4054
|
+
rawGetPointee,
|
|
4055
|
+
constructorSignature,
|
|
4056
|
+
rawConstructor,
|
|
4057
|
+
shareSignature,
|
|
4058
|
+
rawShare,
|
|
4059
|
+
destructorSignature,
|
|
4060
|
+
rawDestructor); */
|
|
4061
|
+
name = readLatin1String(name);
|
|
4062
|
+
rawGetPointee = embind__requireFunction(getPointeeSignature, rawGetPointee);
|
|
4063
|
+
rawConstructor = embind__requireFunction(constructorSignature, rawConstructor);
|
|
4064
|
+
rawShare = embind__requireFunction(shareSignature, rawShare);
|
|
4065
|
+
rawDestructor = embind__requireFunction(destructorSignature, rawDestructor);
|
|
4066
|
+
|
|
4067
|
+
whenDependentTypesAreResolved([rawType], [rawPointeeType], function (pointeeType) {
|
|
4068
|
+
pointeeType = pointeeType[0];
|
|
4069
|
+
|
|
4070
|
+
var registeredPointer = new RegisteredPointer(name,
|
|
4071
|
+
pointeeType.registeredClass,
|
|
4072
|
+
false,
|
|
4073
|
+
false,
|
|
4074
|
+
// smart pointer properties
|
|
4075
|
+
true,
|
|
4076
|
+
pointeeType,
|
|
4077
|
+
sharingPolicy,
|
|
4078
|
+
rawGetPointee,
|
|
4079
|
+
rawConstructor,
|
|
4080
|
+
rawShare,
|
|
4081
|
+
rawDestructor);
|
|
4082
|
+
return [registeredPointer];
|
|
4083
|
+
});
|
|
4084
|
+
}
|
|
4085
|
+
|
|
4086
|
+
globalThis.__embind_register_smart_ptr = __embind_register_smart_ptr;
|
|
4087
|
+
|
|
4088
|
+
|
|
4089
|
+
|
|
4090
|
+
function enumReadValueFromPointer(name, shift, signed) {
|
|
4091
|
+
//console.log('enumReadValueFromPointer');
|
|
4092
|
+
return (pointer) => {
|
|
4093
|
+
return this['fromWireType'](readFromMemoryUsingShift(pointer, signed, shift));
|
|
4094
|
+
}
|
|
4095
|
+
}
|
|
4096
|
+
|
|
4097
|
+
|
|
4098
|
+
function __embind_register_enum(rawType, name, size, isSigned) {
|
|
4099
|
+
var shift = getShiftFromSize(size);
|
|
4100
|
+
name = readLatin1String(name);
|
|
4101
|
+
|
|
4102
|
+
function ctor() { }
|
|
4103
|
+
ctor.values = {};
|
|
4104
|
+
|
|
4105
|
+
registerType(rawType, {
|
|
4106
|
+
name: name,
|
|
4107
|
+
constructor: ctor,
|
|
4108
|
+
'fromWireType': function (c) {
|
|
4109
|
+
//console.log('__embind_register_enum, fromWireType', ctor, c);
|
|
4110
|
+
return this.constructor.values[c];
|
|
4111
|
+
},
|
|
4112
|
+
'toWireType': function (destructors, c) {
|
|
4113
|
+
//console.log('__embind_register_enum, toWireType', ctor, c.value);
|
|
4114
|
+
return c.value;
|
|
4115
|
+
},
|
|
4116
|
+
'argPackAdvance': 8n,
|
|
4117
|
+
'readValueFromPointer': enumReadValueFromPointer(name, shift, isSigned),
|
|
4118
|
+
destructorFunction: null,
|
|
4119
|
+
});
|
|
4120
|
+
exposePublicSymbol(name, ctor);
|
|
4121
|
+
}
|
|
4122
|
+
|
|
4123
|
+
globalThis.__embind_register_enum = __embind_register_enum;
|
|
4124
|
+
|
|
4125
|
+
function __embind_register_enum_value(rawEnumType, name, enumValue) {
|
|
4126
|
+
var enumType = requireRegisteredType(rawEnumType, 'enum');
|
|
4127
|
+
name = readLatin1String(name);
|
|
4128
|
+
|
|
4129
|
+
var Enum = enumType.constructor;
|
|
4130
|
+
|
|
4131
|
+
var Value = Object.create(enumType.constructor.prototype, {
|
|
4132
|
+
value: { value: enumValue },
|
|
4133
|
+
constructor: { value: createNamedFunction(enumType.name + '_' + name, function () { }) },
|
|
4134
|
+
});
|
|
4135
|
+
Enum.values[enumValue] = Value;
|
|
4136
|
+
Enum[name] = Value;
|
|
4137
|
+
}
|
|
4138
|
+
globalThis.__embind_register_enum_value = __embind_register_enum_value;
|
|
4139
|
+
|
|
4140
|
+
function __embind_register_constant(name, type, value) {
|
|
4141
|
+
name = readLatin1String(name);
|
|
4142
|
+
//console.log('-------------- const ---------', name, type, value);
|
|
4143
|
+
whenDependentTypesAreResolved([], [type], function (type) {
|
|
4144
|
+
type = type[0];
|
|
4145
|
+
//console.log('-------------- const ---------', name, type, value);
|
|
4146
|
+
Module[name] = type['fromWireType'](value);
|
|
4147
|
+
return [];
|
|
4148
|
+
});
|
|
4149
|
+
}
|
|
4150
|
+
|
|
4151
|
+
globalThis.__embind_register_constant = __embind_register_constant;
|
|
4152
|
+
|
|
4153
|
+
var emval_symbols = {};
|
|
4154
|
+
|
|
4155
|
+
function __emval_register_symbol(address) {
|
|
4156
|
+
emval_symbols[address] = readLatin1String(address);
|
|
4157
|
+
}
|
|
4158
|
+
globalThis.__emval_register_symbol = __emval_register_symbol;
|
|
4159
|
+
|
|
4160
|
+
function __emval_incref(handle) {
|
|
4161
|
+
// console.log('__emval_incref');
|
|
4162
|
+
if (handle > 4) {
|
|
4163
|
+
emval_handles.get(handle).refcount += 1;
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
4166
|
+
globalThis.__emval_incref = __emval_incref;
|
|
4167
|
+
|
|
4168
|
+
|
|
4169
|
+
|
|
4170
|
+
|
|
4171
|
+
function __emval_run_destructors(handle) {
|
|
4172
|
+
// console.log('__emval_run_destructors');
|
|
4173
|
+
var destructors = Emval.toValue(handle);
|
|
4174
|
+
runDestructors(destructors);
|
|
4175
|
+
__emval_decref(handle);
|
|
4176
|
+
}
|
|
4177
|
+
globalThis.__emval_run_destructors = __emval_run_destructors;
|
|
4178
|
+
|
|
4179
|
+
|
|
4180
|
+
function __emval_new_array() {
|
|
4181
|
+
// console.log('__emval_new_array');
|
|
4182
|
+
return Emval.toHandle([]);
|
|
4183
|
+
}
|
|
4184
|
+
globalThis.__emval_new_array = __emval_new_array;
|
|
4185
|
+
|
|
4186
|
+
function __emval_new_array_from_memory_view(view) {
|
|
4187
|
+
// console.log('__emval_new_array_from_memory_view');
|
|
4188
|
+
view = Emval.toValue(view);
|
|
4189
|
+
// using for..loop is faster than Array.from
|
|
4190
|
+
var a = new Array(view.length);
|
|
4191
|
+
for (var i = 0; i < view.length; i++) a[i] = view[i];
|
|
4192
|
+
return Emval.toHandle(a);
|
|
4193
|
+
}
|
|
4194
|
+
globalThis.__emval_new_array_from_memory_view = __emval_new_array_from_memory_view;
|
|
4195
|
+
|
|
4196
|
+
function __emval_new_object() {
|
|
4197
|
+
// console.log('__emval_new_object');
|
|
4198
|
+
return Emval.toHandle({});
|
|
4199
|
+
}
|
|
4200
|
+
globalThis.__emval_new_object = __emval_new_object;
|
|
4201
|
+
|
|
4202
|
+
|
|
4203
|
+
function getStringOrSymbol(address) {
|
|
4204
|
+
var symbol = emval_symbols[address];
|
|
4205
|
+
if (symbol === undefined) {
|
|
4206
|
+
return readLatin1String(address);
|
|
4207
|
+
}
|
|
4208
|
+
return symbol;
|
|
4209
|
+
}
|
|
4210
|
+
|
|
4211
|
+
function __emval_new_cstring(v) {
|
|
4212
|
+
// console.log('__emval_new_cstring');
|
|
4213
|
+
return Emval.toHandle(getStringOrSymbol(v));
|
|
4214
|
+
}
|
|
4215
|
+
globalThis.__emval_new_cstring = __emval_new_cstring;
|
|
4216
|
+
|
|
4217
|
+
|
|
4218
|
+
function __emval_new_u8string(v) {
|
|
4219
|
+
// console.log('__emval_new_u8string');
|
|
4220
|
+
return Emval.toHandle(UTF8ToString(v));
|
|
4221
|
+
}
|
|
4222
|
+
globalThis.__emval_new_u8string = __emval_new_u8string;
|
|
4223
|
+
|
|
4224
|
+
function __emval_new_u16string(v) {
|
|
4225
|
+
// console.log('__emval_new_u16string');
|
|
4226
|
+
return Emval.toHandle(UTF16ToString(v));
|
|
4227
|
+
}
|
|
4228
|
+
globalThis.__emval_new_u16string = __emval_new_u16string;
|
|
4229
|
+
|
|
4230
|
+
BigInt.prototype.toJSON = function () { return this.toString() }
|
|
4231
|
+
function __emval_take_value(type, arg) {
|
|
4232
|
+
//console.log('__emval_take_value', JSON.stringify({type, arg}, null, 2));
|
|
4233
|
+
type = requireRegisteredType(type, '_emval_take_value');
|
|
4234
|
+
//console.log('************** 2:', JSON.stringify({type, arg}, null, 2));
|
|
4235
|
+
//console.log('************** 2.5:', type['readValueFromPointer']);
|
|
4236
|
+
var v = type['readValueFromPointer'](arg);
|
|
4237
|
+
//console.log('************** 3:', v);
|
|
4238
|
+
const f = Emval.toHandle(v);
|
|
4239
|
+
//console.log('************** 4:', f);
|
|
4240
|
+
return f;
|
|
4241
|
+
}
|
|
4242
|
+
globalThis.__emval_take_value = __emval_take_value;
|
|
4243
|
+
|
|
4244
|
+
|
|
4245
|
+
function craftEmvalAllocator(argCount) {
|
|
4246
|
+
/*This function returns a new function that looks like this:
|
|
4247
|
+
function emval_allocator_3(constructor, argTypes, args) {
|
|
4248
|
+
var argType0 = requireRegisteredType(HEAP32[(argTypes >> 2)], "parameter 0");
|
|
4249
|
+
var arg0 = argType0['readValueFromPointer'](args);
|
|
4250
|
+
var argType1 = requireRegisteredType(HEAP32[(argTypes >> 2) + 1], "parameter 1");
|
|
4251
|
+
var arg1 = argType1['readValueFromPointer'](args + 8);
|
|
4252
|
+
var argType2 = requireRegisteredType(HEAP32[(argTypes >> 2) + 2], "parameter 2");
|
|
4253
|
+
var arg2 = argType2['readValueFromPointer'](args + 16);
|
|
4254
|
+
var obj = new constructor(arg0, arg1, arg2);
|
|
4255
|
+
return Emval.toHandle(obj);
|
|
4256
|
+
} */
|
|
4257
|
+
var argsList = "";
|
|
4258
|
+
for (var i = 0; i < argCount; ++i) {
|
|
4259
|
+
argsList += (i !== 0 ? ", " : "") + "arg" + i; // 'arg0, arg1, ..., argn'
|
|
4260
|
+
}
|
|
4261
|
+
|
|
4262
|
+
var functionBody =
|
|
4263
|
+
"return function emval_allocator_" + argCount + "(constructor, argTypes, args) {\n";
|
|
4264
|
+
|
|
4265
|
+
for (var i = 0; i < argCount; ++i) {
|
|
4266
|
+
functionBody +=
|
|
4267
|
+
"var argType" + i + " = requireRegisteredType(argTypes[" + i + "], 'parameter " + i + "');\n" +
|
|
4268
|
+
"var arg" + i + " = argType" + i + ".readValueFromPointer(args);\n" +
|
|
4269
|
+
"args += argType" + i + "['argPackAdvance'];\n";
|
|
4270
|
+
}
|
|
4271
|
+
functionBody +=
|
|
4272
|
+
"var obj = new constructor(" + argsList + ");\n" +
|
|
4273
|
+
"return valueToHandle(obj);\n" +
|
|
4274
|
+
"}\n";
|
|
4275
|
+
|
|
4276
|
+
/*jshint evil:true*/
|
|
4277
|
+
return (new Function("requireRegisteredType", "Module", "valueToHandle", "readFromMemoryUsingShift", functionBody))(
|
|
4278
|
+
requireRegisteredType, Module, Emval.toHandle, readFromMemoryUsingShift);
|
|
4279
|
+
}
|
|
4280
|
+
|
|
4281
|
+
var emval_newers = {};
|
|
4282
|
+
|
|
4283
|
+
function __emval_new(handle, argCount, argTypes, args) {
|
|
4284
|
+
argCount = Number(argCount);
|
|
4285
|
+
//console.log('__emval_new', handle, argCount, argTypes.length, argTypes, args);
|
|
4286
|
+
handle = Emval.toValue(handle);
|
|
4287
|
+
|
|
4288
|
+
var newer = emval_newers[argCount];
|
|
4289
|
+
if (!newer) {
|
|
4290
|
+
newer = craftEmvalAllocator(argCount);
|
|
4291
|
+
emval_newers[argCount] = newer;
|
|
4292
|
+
}
|
|
4293
|
+
|
|
4294
|
+
//console.log('__emval_new response2');
|
|
4295
|
+
const a = newer(handle, argTypes, args);;
|
|
4296
|
+
//console.log('__emval_new response: ', a);
|
|
4297
|
+
return a;
|
|
4298
|
+
}
|
|
4299
|
+
globalThis.__emval_new = __emval_new;
|
|
4300
|
+
|
|
4301
|
+
|
|
4302
|
+
const globalIgnoreList = [
|
|
4303
|
+
'jsiArrayBuffer',
|
|
4304
|
+
'jsiArrayBuffer2',
|
|
4305
|
+
'jsiArrayBuffer3',
|
|
4306
|
+
'jsiArrayBuffer4',
|
|
4307
|
+
'window',
|
|
4308
|
+
'self',
|
|
4309
|
+
'DATA_VIEW',
|
|
4310
|
+
'Module',
|
|
4311
|
+
'nativeRuntimeScheduler',
|
|
4312
|
+
];
|
|
4313
|
+
|
|
4314
|
+
function emval_get_global() {
|
|
4315
|
+
if (typeof globalThis == 'object') {
|
|
4316
|
+
const global = {};
|
|
4317
|
+
Object.keys(globalThis).filter(key => !key.startsWith('_') && !globalIgnoreList.includes(key)).forEach(key => {
|
|
4318
|
+
global[key] = globalThis[key];
|
|
4319
|
+
});
|
|
4320
|
+
|
|
4321
|
+
return global;
|
|
4322
|
+
}
|
|
4323
|
+
return (function () {
|
|
4324
|
+
return Function;
|
|
4325
|
+
})()('return this')();
|
|
4326
|
+
}
|
|
4327
|
+
function __emval_get_global(name) {
|
|
4328
|
+
if (name === '') {
|
|
4329
|
+
return Emval.toHandle(emval_get_global());
|
|
4330
|
+
} else {
|
|
4331
|
+
//console.log(`1__emval_get_global(${name})`, globalThis[name]);
|
|
4332
|
+
name = getStringOrSymbol(name);
|
|
4333
|
+
return Emval.toHandle(globalThis[name]);
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
globalThis.__emval_get_global = __emval_get_global;
|
|
4337
|
+
|
|
4338
|
+
|
|
4339
|
+
function __emval_get_module_property(name) {
|
|
4340
|
+
// console.log('__emval_get_module_property');
|
|
4341
|
+
name = getStringOrSymbol(name);
|
|
4342
|
+
return Emval.toHandle(Module[name]);
|
|
4343
|
+
}
|
|
4344
|
+
globalThis.__emval_get_module_property = __emval_get_module_property;
|
|
4345
|
+
|
|
4346
|
+
function __emval_get_property(handle, key) {
|
|
4347
|
+
//console.log('__emval_get_property', handle, key);
|
|
4348
|
+
handle = Emval.toValue(handle);
|
|
4349
|
+
key = Emval.toValue(key);
|
|
4350
|
+
//console.log('__emval_get_property2', handle, key, handle[key]);
|
|
4351
|
+
return Emval.toHandle(handle[key]);
|
|
4352
|
+
}
|
|
4353
|
+
globalThis.__emval_get_property = __emval_get_property;
|
|
4354
|
+
|
|
4355
|
+
function __emval_set_property(handle, key, value) {
|
|
4356
|
+
// console.log('__emval_set_property');
|
|
4357
|
+
handle = Emval.toValue(handle);
|
|
4358
|
+
key = Emval.toValue(key);
|
|
4359
|
+
value = Emval.toValue(value);
|
|
4360
|
+
handle[key] = value;
|
|
4361
|
+
}
|
|
4362
|
+
globalThis.__emval_set_property = __emval_set_property;
|
|
4363
|
+
|
|
4364
|
+
|
|
4365
|
+
function __emval_as(handle, returnType, destructorsRef) {
|
|
4366
|
+
//console.log('__emval_as');
|
|
4367
|
+
handle = Emval.toValue(handle);
|
|
4368
|
+
//console.log('__emval_as 2');
|
|
4369
|
+
returnType = requireRegisteredType(returnType, 'emval::as');
|
|
4370
|
+
//console.log('__emval_as 3');
|
|
4371
|
+
var destructors = [];
|
|
4372
|
+
var rd = Emval.toHandle(destructors);
|
|
4373
|
+
//console.log('__emval_as 4', Number(rd));
|
|
4374
|
+
writeToMemoryUsingShift(destructorsRef, false, 3, rd);
|
|
4375
|
+
const output = returnType['toWireType'](destructors, handle);
|
|
4376
|
+
//console.log('__emval_as 5', Number(output));
|
|
4377
|
+
return output;
|
|
4378
|
+
}
|
|
4379
|
+
globalThis.__emval_as = __emval_as;
|
|
4380
|
+
|
|
4381
|
+
|
|
4382
|
+
function __emval_as_int64(handle, returnType) {
|
|
4383
|
+
// console.log('__emval_as_int64');
|
|
4384
|
+
handle = Emval.toValue(handle);
|
|
4385
|
+
returnType = requireRegisteredType(returnType, 'emval::as');
|
|
4386
|
+
return returnType['toWireType'](null, handle);
|
|
4387
|
+
}
|
|
4388
|
+
globalThis.__emval_as_int64 = __emval_as_int64;
|
|
4389
|
+
|
|
4390
|
+
|
|
4391
|
+
function __emval_as_uint64(handle, returnType) {
|
|
4392
|
+
// console.log('__emval_as_uint64');
|
|
4393
|
+
handle = Emval.toValue(handle);
|
|
4394
|
+
returnType = requireRegisteredType(returnType, 'emval::as');
|
|
4395
|
+
return returnType['toWireType'](null, handle);
|
|
4396
|
+
}
|
|
4397
|
+
globalThis.__emval_as_uint64 = __emval_as_uint64;
|
|
4398
|
+
|
|
4399
|
+
function __emval_equals(first, second) {
|
|
4400
|
+
// console.log('__emval_equals');
|
|
4401
|
+
first = Emval.toValue(first);
|
|
4402
|
+
second = Emval.toValue(second);
|
|
4403
|
+
return first == second;
|
|
4404
|
+
}
|
|
4405
|
+
globalThis.__emval_equals = __emval_equals;
|
|
4406
|
+
|
|
4407
|
+
function __emval_strictly_equals(first, second) {
|
|
4408
|
+
// console.log('__emval_strictly_equals');
|
|
4409
|
+
first = Emval.toValue(first);
|
|
4410
|
+
second = Emval.toValue(second);
|
|
4411
|
+
return first === second;
|
|
4412
|
+
}
|
|
4413
|
+
globalThis.__emval_strictly_equals = __emval_strictly_equals;
|
|
4414
|
+
|
|
4415
|
+
function __emval_greater_than(first, second) {
|
|
4416
|
+
// console.log('__emval_greater_than');
|
|
4417
|
+
first = Emval.toValue(first);
|
|
4418
|
+
second = Emval.toValue(second);
|
|
4419
|
+
return first > second;
|
|
4420
|
+
}
|
|
4421
|
+
globalThis.__emval_greater_than = __emval_greater_than;
|
|
4422
|
+
|
|
4423
|
+
function __emval_less_than(first, second) {
|
|
4424
|
+
// console.log('__emval_less_than');
|
|
4425
|
+
first = Emval.toValue(first);
|
|
4426
|
+
second = Emval.toValue(second);
|
|
4427
|
+
return first < second;
|
|
4428
|
+
}
|
|
4429
|
+
globalThis.__emval_less_than = __emval_less_than;
|
|
4430
|
+
|
|
4431
|
+
function __emval_not(object) {
|
|
4432
|
+
// console.log('__emval_not');
|
|
4433
|
+
object = Emval.toValue(object);
|
|
4434
|
+
return !object;
|
|
4435
|
+
}
|
|
4436
|
+
globalThis.__emval_not = __emval_not;
|
|
4437
|
+
|
|
4438
|
+
function emval_lookupTypes(argCount, argTypes) {
|
|
4439
|
+
//console.log('emval_lookupTypes', argCount, argTypes);
|
|
4440
|
+
var a = new Array(argCount);
|
|
4441
|
+
for (var i = 0; i < argCount; ++i) {
|
|
4442
|
+
const memValue = argTypes[i];
|
|
4443
|
+
a[i] = requireRegisteredType(memValue, "parameter " + i);
|
|
4444
|
+
}
|
|
4445
|
+
return a;
|
|
4446
|
+
}
|
|
4447
|
+
|
|
4448
|
+
function __emval_call(handle, argCount, argTypes, argv) {
|
|
4449
|
+
//console.log('__emval_call', handle, argCount, argTypes, argv);
|
|
4450
|
+
handle = Emval.toValue(handle);
|
|
4451
|
+
var types = emval_lookupTypes(argCount, argTypes);
|
|
4452
|
+
//console.log('ooooo', types);
|
|
4453
|
+
var args = new Array(argCount);
|
|
4454
|
+
for (var i = 0; i < argCount; ++i) {
|
|
4455
|
+
var type = types[i];
|
|
4456
|
+
args[i] = type['readValueFromPointer'](argv);
|
|
4457
|
+
//console.log(args[i]);
|
|
4458
|
+
argv += type['argPackAdvance'];
|
|
4459
|
+
}
|
|
4460
|
+
//console.log('ooooo3');
|
|
4461
|
+
var rv = handle.apply(undefined, args);
|
|
4462
|
+
//console.log('ooooo2');
|
|
4463
|
+
return Emval.toHandle(rv);
|
|
4464
|
+
}
|
|
4465
|
+
globalThis.__emval_call = __emval_call;
|
|
4466
|
+
|
|
4467
|
+
var emval_methodCallers = [];
|
|
4468
|
+
function emval_addMethodCaller(caller) {
|
|
4469
|
+
var id = emval_methodCallers.length;
|
|
4470
|
+
emval_methodCallers.push(caller);
|
|
4471
|
+
return BigInt(id);
|
|
4472
|
+
}
|
|
4473
|
+
|
|
4474
|
+
|
|
4475
|
+
|
|
4476
|
+
var emval_registeredMethods = [];
|
|
4477
|
+
|
|
4478
|
+
function __emval_get_method_caller(argCount, argTypes) {
|
|
4479
|
+
argCount = Number(argCount);
|
|
4480
|
+
//console.log('__emval_get_method_caller', argCount, argTypes);
|
|
4481
|
+
var types = emval_lookupTypes(argCount, argTypes);
|
|
4482
|
+
var retType = types[0];
|
|
4483
|
+
var signatureName = retType.name + "_$" + types.slice(1).map(function (t) { return t.name; }).join("_") + "$";
|
|
4484
|
+
var returnId = emval_registeredMethods[signatureName];
|
|
4485
|
+
if (returnId !== undefined) {
|
|
4486
|
+
return returnId;
|
|
4487
|
+
}
|
|
4488
|
+
|
|
4489
|
+
var params = ["retType"];
|
|
4490
|
+
var args = [retType];
|
|
4491
|
+
|
|
4492
|
+
var argsList = ""; // 'arg0, arg1, arg2, ... , argN'
|
|
4493
|
+
for (var i = 0; i < argCount - 1; ++i) {
|
|
4494
|
+
argsList += (i !== 0 ? ", " : "") + "arg" + i;
|
|
4495
|
+
params.push("argType" + i);
|
|
4496
|
+
args.push(types[1 + i]);
|
|
4497
|
+
}
|
|
4498
|
+
var functionName = makeLegalFunctionName("methodCaller_" + signatureName);
|
|
4499
|
+
var functionBody =
|
|
4500
|
+
"return function " + functionName + "(handle, name, destructors, args) {\n";
|
|
4501
|
+
var offset = 0n;
|
|
4502
|
+
for (var i = 0; i < argCount - 1; ++i) {
|
|
4503
|
+
functionBody +=
|
|
4504
|
+
" var arg" + i + " = argType" + i + ".readValueFromPointer(args" + (offset ? ("+" + offset + "n") : "") + ");\n";
|
|
4505
|
+
offset += types[i + 1]['argPackAdvance'];
|
|
4506
|
+
}
|
|
4507
|
+
functionBody +=
|
|
4508
|
+
" var rv = handle[name](" + argsList + ");\n";
|
|
4509
|
+
for (var i = 0; i < argCount - 1; ++i) {
|
|
4510
|
+
if (types[i + 1]['deleteObject']) {
|
|
4511
|
+
functionBody +=
|
|
4512
|
+
" argType" + i + ".deleteObject(arg" + i + ");\n";
|
|
4513
|
+
}
|
|
4514
|
+
}
|
|
4515
|
+
if (!retType.isVoid) {
|
|
4516
|
+
functionBody +=
|
|
4517
|
+
" return retType.toWireType(destructors, rv, true);\n";
|
|
4518
|
+
}
|
|
4519
|
+
functionBody +=
|
|
4520
|
+
"};\n";
|
|
4521
|
+
params.push(functionBody);
|
|
4522
|
+
var invokerFunction = newFunc(Function, params).apply(null, args);
|
|
4523
|
+
returnId = emval_addMethodCaller(invokerFunction);
|
|
4524
|
+
emval_registeredMethods[signatureName] = returnId;
|
|
4525
|
+
return returnId;
|
|
4526
|
+
}
|
|
4527
|
+
globalThis.__emval_get_method_caller = __emval_get_method_caller;
|
|
4528
|
+
|
|
4529
|
+
function emval_allocateDestructors(destructorsRef) {
|
|
4530
|
+
//console.log('emval_allocateDestructors');
|
|
4531
|
+
var destructors = [];
|
|
4532
|
+
writeToMemoryUsingShift(destructorsRef, false, 3, Emval.toHandle(destructors));
|
|
4533
|
+
//console.log('emval_allocateDestructors 2');
|
|
4534
|
+
return destructors;
|
|
4535
|
+
}
|
|
4536
|
+
|
|
4537
|
+
|
|
4538
|
+
|
|
4539
|
+
function __emval_call_method(caller, handle, methodName, destructorsRef, args) {
|
|
4540
|
+
//console.log('__emval_call_method');
|
|
4541
|
+
caller = emval_methodCallers[caller];
|
|
4542
|
+
handle = Emval.toValue(handle);
|
|
4543
|
+
methodName = getStringOrSymbol(methodName);
|
|
4544
|
+
return caller(handle, methodName, emval_allocateDestructors(destructorsRef), args);
|
|
4545
|
+
}
|
|
4546
|
+
globalThis.__emval_call_method = __emval_call_method;
|
|
4547
|
+
|
|
4548
|
+
|
|
4549
|
+
|
|
4550
|
+
|
|
4551
|
+
function __emval_call_void_method(caller, handle, methodName, args) {
|
|
4552
|
+
//console.log('__emval_call_void_method');
|
|
4553
|
+
caller = emval_methodCallers[caller];
|
|
4554
|
+
handle = Emval.toValue(handle);
|
|
4555
|
+
methodName = getStringOrSymbol(methodName);
|
|
4556
|
+
caller(handle, methodName, null, args);
|
|
4557
|
+
}
|
|
4558
|
+
globalThis.__emval_call_void_method = __emval_call_void_method;
|
|
4559
|
+
|
|
4560
|
+
function __emval_typeof(handle) {
|
|
4561
|
+
// console.log('__emval_typeof');
|
|
4562
|
+
handle = Emval.toValue(handle);
|
|
4563
|
+
return Emval.toHandle(typeof handle);
|
|
4564
|
+
}
|
|
4565
|
+
globalThis.__emval_typeof = __emval_typeof;
|
|
4566
|
+
|
|
4567
|
+
function __emval_instanceof(object, constructor) {
|
|
4568
|
+
// console.log('__emval_instanceof');
|
|
4569
|
+
object = Emval.toValue(object);
|
|
4570
|
+
constructor = Emval.toValue(constructor);
|
|
4571
|
+
return object instanceof constructor;
|
|
4572
|
+
}
|
|
4573
|
+
globalThis.__emval_instanceof = __emval_instanceof;
|
|
4574
|
+
|
|
4575
|
+
function __emval_is_number(handle) {
|
|
4576
|
+
// console.log('__emval_is_number');
|
|
4577
|
+
handle = Emval.toValue(handle);
|
|
4578
|
+
return typeof handle == 'number';
|
|
4579
|
+
}
|
|
4580
|
+
globalThis.__emval_is_number = __emval_is_number;
|
|
4581
|
+
|
|
4582
|
+
function __emval_is_string(handle) {
|
|
4583
|
+
// console.log('__emval_is_string');
|
|
4584
|
+
handle = Emval.toValue(handle);
|
|
4585
|
+
return typeof handle == 'string';
|
|
4586
|
+
}
|
|
4587
|
+
globalThis.__emval_is_string = __emval_is_string;
|
|
4588
|
+
|
|
4589
|
+
function __emval_in(item, object) {
|
|
4590
|
+
// console.log('__emval_in');
|
|
4591
|
+
item = Emval.toValue(item);
|
|
4592
|
+
object = Emval.toValue(object);
|
|
4593
|
+
return item in object;
|
|
4594
|
+
}
|
|
4595
|
+
globalThis.__emval_in = __emval_in;
|
|
4596
|
+
|
|
4597
|
+
function __emval_delete(object, property) {
|
|
4598
|
+
// console.log('__emval_delete');
|
|
4599
|
+
object = Emval.toValue(object);
|
|
4600
|
+
property = Emval.toValue(property);
|
|
4601
|
+
return delete object[property];
|
|
4602
|
+
}
|
|
4603
|
+
globalThis.__emval_delete = __emval_delete;
|
|
4604
|
+
|
|
4605
|
+
function __emval_throw(object) {
|
|
4606
|
+
// console.log('__emval_throw');
|
|
4607
|
+
object = Emval.toValue(object);
|
|
4608
|
+
throw object;
|
|
4609
|
+
}
|
|
4610
|
+
globalThis.__emval_throw = __emval_throw;
|
|
4611
|
+
|
|
4612
|
+
function _callRuntimeCallbacks(callbacks) {
|
|
4613
|
+
while (callbacks.length > 0) {
|
|
4614
|
+
// Pass the module as the first argument.
|
|
4615
|
+
callbacks.shift()(Module);
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
embind_init_charCodes();
|
|
4619
|
+
BindingError = Module['BindingError'] = extendError(Error, 'BindingError');;
|
|
4620
|
+
InternalError = Module['InternalError'] = extendError(Error, 'InternalError');;
|
|
4621
|
+
init_emval();;
|
|
4622
|
+
UnboundTypeError = Module['UnboundTypeError'] = extendError(Error, 'UnboundTypeError');;
|
|
4623
|
+
init_ClassHandle();
|
|
4624
|
+
init_embind();;
|
|
4625
|
+
init_RegisteredPointer();
|
|
4626
|
+
|
|
4627
|
+
PureVirtualError = Module['PureVirtualError'] = extendError(Error, 'PureVirtualError');;
|
|
4628
|
+
// EMSCRIPTEN_END_FUNCS
|
|
4629
|
+
|
|
4630
|
+
// include: postamble.js
|
|
4631
|
+
/**
|
|
4632
|
+
* @license
|
|
4633
|
+
* Copyright 2010 The Emscripten Authors
|
|
4634
|
+
* SPDX-License-Identifier: MIT
|
|
4635
|
+
*/
|
|
4636
|
+
|
|
4637
|
+
// === Auto-generated postamble setup entry stuff ===
|
|
4638
|
+
|
|
4639
|
+
var missingLibrarySymbols = [
|
|
4640
|
+
'callRuntimeCallbacks',
|
|
4641
|
+
'ExitStatus',
|
|
4642
|
+
'exitJS',
|
|
4643
|
+
'handleException',
|
|
4644
|
+
'reallyNegative',
|
|
4645
|
+
'unSign',
|
|
4646
|
+
'strLen',
|
|
4647
|
+
'reSign',
|
|
4648
|
+
'formatString',
|
|
4649
|
+
'intArrayFromString',
|
|
4650
|
+
'intArrayToString',
|
|
4651
|
+
'AsciiToString',
|
|
4652
|
+
'stringToAscii',
|
|
4653
|
+
'stringToNewUTF8',
|
|
4654
|
+
'stringToUTF8OnStack',
|
|
4655
|
+
'writeArrayToMemory',
|
|
4656
|
+
'writeI53ToI64',
|
|
4657
|
+
'writeI53ToI64Clamped',
|
|
4658
|
+
'writeI53ToI64Signaling',
|
|
4659
|
+
'writeI53ToU64Clamped',
|
|
4660
|
+
'writeI53ToU64Signaling',
|
|
4661
|
+
'readI53FromI64',
|
|
4662
|
+
'readI53FromU64',
|
|
4663
|
+
'convertI32PairToI53',
|
|
4664
|
+
'convertI32PairToI53Checked',
|
|
4665
|
+
'convertU32PairToI53'
|
|
4666
|
+
];
|
|
4667
|
+
missingLibrarySymbols.forEach(missingLibrarySymbol)
|
|
4668
|
+
|
|
4669
|
+
var unexportedSymbols = [
|
|
4670
|
+
'run',
|
|
4671
|
+
'addOnPreRun',
|
|
4672
|
+
'addOnInit',
|
|
4673
|
+
'addOnPreMain',
|
|
4674
|
+
'addOnExit',
|
|
4675
|
+
'addOnPostRun',
|
|
4676
|
+
'addRunDependency',
|
|
4677
|
+
'removeRunDependency',
|
|
4678
|
+
'FS_createFolder',
|
|
4679
|
+
'FS_createPath',
|
|
4680
|
+
'FS_createDataFile',
|
|
4681
|
+
'FS_createLazyFile',
|
|
4682
|
+
'FS_createLink',
|
|
4683
|
+
'FS_createDevice',
|
|
4684
|
+
'FS_unlink',
|
|
4685
|
+
'out',
|
|
4686
|
+
'err',
|
|
4687
|
+
'callMain',
|
|
4688
|
+
'abort',
|
|
4689
|
+
'keepRuntimeAlive',
|
|
4690
|
+
'wasmMemory',
|
|
4691
|
+
'stackAlloc',
|
|
4692
|
+
'stackSave',
|
|
4693
|
+
'stackRestore',
|
|
4694
|
+
'getTempRet0',
|
|
4695
|
+
'setTempRet0',
|
|
4696
|
+
'UTF8Decoder',
|
|
4697
|
+
'UTF8ArrayToString',
|
|
4698
|
+
'UTF8ToString',
|
|
4699
|
+
'stringToUTF8Array',
|
|
4700
|
+
'stringToUTF8',
|
|
4701
|
+
'lengthBytesUTF8',
|
|
4702
|
+
'UTF16Decoder',
|
|
4703
|
+
'UTF16ToString',
|
|
4704
|
+
'stringToUTF16',
|
|
4705
|
+
'lengthBytesUTF16',
|
|
4706
|
+
'UTF32ToString',
|
|
4707
|
+
'stringToUTF32',
|
|
4708
|
+
'lengthBytesUTF32',
|
|
4709
|
+
'MAX_INT53',
|
|
4710
|
+
'MIN_INT53',
|
|
4711
|
+
'bigintToI53Checked',
|
|
4712
|
+
'getDynCaller',
|
|
4713
|
+
'getWasmTableEntry',
|
|
4714
|
+
'HandleAllocator',
|
|
4715
|
+
'InternalError',
|
|
4716
|
+
'BindingError',
|
|
4717
|
+
'UnboundTypeError',
|
|
4718
|
+
'PureVirtualError',
|
|
4719
|
+
'init_embind',
|
|
4720
|
+
'throwInternalError',
|
|
4721
|
+
'throwBindingError',
|
|
4722
|
+
'throwUnboundTypeError',
|
|
4723
|
+
'ensureOverloadTable',
|
|
4724
|
+
'exposePublicSymbol',
|
|
4725
|
+
'replacePublicSymbol',
|
|
4726
|
+
'extendError',
|
|
4727
|
+
'createNamedFunction',
|
|
4728
|
+
'embindRepr',
|
|
4729
|
+
'registeredInstances',
|
|
4730
|
+
'getBasestPointer',
|
|
4731
|
+
'registerInheritedInstance',
|
|
4732
|
+
'unregisterInheritedInstance',
|
|
4733
|
+
'getInheritedInstance',
|
|
4734
|
+
'getInheritedInstanceCount',
|
|
4735
|
+
'getLiveInheritedInstances',
|
|
4736
|
+
'registeredTypes',
|
|
4737
|
+
'awaitingDependencies',
|
|
4738
|
+
'typeDependencies',
|
|
4739
|
+
'registeredPointers',
|
|
4740
|
+
'registerType',
|
|
4741
|
+
'whenDependentTypesAreResolved',
|
|
4742
|
+
'embind_charCodes',
|
|
4743
|
+
'embind_init_charCodes',
|
|
4744
|
+
'readLatin1String',
|
|
4745
|
+
'getTypeName',
|
|
4746
|
+
'heap32VectorToArray',
|
|
4747
|
+
'requireRegisteredType',
|
|
4748
|
+
'getShiftFromSize',
|
|
4749
|
+
'integerReadValueFromPointer',
|
|
4750
|
+
'enumReadValueFromPointer',
|
|
4751
|
+
'floatReadValueFromPointer',
|
|
4752
|
+
'simpleReadValueFromPointer',
|
|
4753
|
+
'runDestructors',
|
|
4754
|
+
'newFunc',
|
|
4755
|
+
'craftInvokerFunction',
|
|
4756
|
+
'embind__requireFunction',
|
|
4757
|
+
'tupleRegistrations',
|
|
4758
|
+
'structRegistrations',
|
|
4759
|
+
'genericPointerToWireType',
|
|
4760
|
+
'constNoSmartPtrRawPointerToWireType',
|
|
4761
|
+
'nonConstNoSmartPtrRawPointerToWireType',
|
|
4762
|
+
'init_RegisteredPointer',
|
|
4763
|
+
'RegisteredPointer',
|
|
4764
|
+
'RegisteredPointer_getPointee',
|
|
4765
|
+
'RegisteredPointer_destructor',
|
|
4766
|
+
'RegisteredPointer_deleteObject',
|
|
4767
|
+
'RegisteredPointer_fromWireType',
|
|
4768
|
+
'runDestructor',
|
|
4769
|
+
'releaseClassHandle',
|
|
4770
|
+
'finalizationRegistry',
|
|
4771
|
+
'detachFinalizer_deps',
|
|
4772
|
+
'detachFinalizer',
|
|
4773
|
+
'attachFinalizer',
|
|
4774
|
+
'makeClassHandle',
|
|
4775
|
+
'init_ClassHandle',
|
|
4776
|
+
'ClassHandle',
|
|
4777
|
+
'ClassHandle_isAliasOf',
|
|
4778
|
+
'throwInstanceAlreadyDeleted',
|
|
4779
|
+
'ClassHandle_clone',
|
|
4780
|
+
'ClassHandle_delete',
|
|
4781
|
+
'deletionQueue',
|
|
4782
|
+
'ClassHandle_isDeleted',
|
|
4783
|
+
'ClassHandle_deleteLater',
|
|
4784
|
+
'flushPendingDeletes',
|
|
4785
|
+
'delayFunction',
|
|
4786
|
+
'setDelayFunction',
|
|
4787
|
+
'RegisteredClass',
|
|
4788
|
+
'shallowCopyInternalPointer',
|
|
4789
|
+
'downcastPointer',
|
|
4790
|
+
'upcastPointer',
|
|
4791
|
+
'validateThis',
|
|
4792
|
+
'char_0',
|
|
4793
|
+
'char_9',
|
|
4794
|
+
'makeLegalFunctionName',
|
|
4795
|
+
'emval_handles',
|
|
4796
|
+
'emval_symbols',
|
|
4797
|
+
'init_emval',
|
|
4798
|
+
'count_emval_handles',
|
|
4799
|
+
'getStringOrSymbol',
|
|
4800
|
+
'Emval',
|
|
4801
|
+
'emval_newers',
|
|
4802
|
+
'craftEmvalAllocator',
|
|
4803
|
+
'emval_get_global',
|
|
4804
|
+
'emval_lookupTypes',
|
|
4805
|
+
'emval_allocateDestructors',
|
|
4806
|
+
'emval_methodCallers',
|
|
4807
|
+
'emval_addMethodCaller',
|
|
4808
|
+
'emval_registeredMethods',
|
|
4809
|
+
];
|
|
4810
|
+
unexportedSymbols.forEach(unexportedRuntimeSymbol);
|
|
4811
|
+
|
|
4812
|
+
|
|
4813
|
+
|
|
4814
|
+
var calledRun;
|
|
4815
|
+
|
|
4816
|
+
dependenciesFulfilled = function runCaller() {
|
|
4817
|
+
// If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
|
|
4818
|
+
if (!calledRun) run();
|
|
4819
|
+
if (!calledRun) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
|
|
4820
|
+
};
|
|
4821
|
+
|
|
4822
|
+
function run(args = arguments_) {
|
|
4823
|
+
|
|
4824
|
+
if (runDependencies > 0) {
|
|
4825
|
+
return;
|
|
4826
|
+
}
|
|
4827
|
+
|
|
4828
|
+
preRun();
|
|
4829
|
+
|
|
4830
|
+
// a preRun added a dependency, run will be called later
|
|
4831
|
+
if (runDependencies > 0) {
|
|
4832
|
+
return;
|
|
4833
|
+
}
|
|
4834
|
+
|
|
4835
|
+
function doRun() {
|
|
4836
|
+
// run may have just been called through dependencies being fulfilled just in this very frame,
|
|
4837
|
+
// or while the async setStatus time below was happening
|
|
4838
|
+
if (calledRun) return;
|
|
4839
|
+
calledRun = true;
|
|
4840
|
+
Module['calledRun'] = true;
|
|
4841
|
+
|
|
4842
|
+
if (ABORT) return;
|
|
4843
|
+
|
|
4844
|
+
initRuntime();
|
|
4845
|
+
|
|
4846
|
+
assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
|
|
4847
|
+
|
|
4848
|
+
postRun();
|
|
4849
|
+
}
|
|
4850
|
+
|
|
4851
|
+
{
|
|
4852
|
+
doRun();
|
|
4853
|
+
}
|
|
4854
|
+
}
|
|
4855
|
+
|
|
4856
|
+
function checkUnflushedContent() {
|
|
4857
|
+
// Compiler settings do not allow exiting the runtime, so flushing
|
|
4858
|
+
// the streams is not possible. but in ASSERTIONS mode we check
|
|
4859
|
+
// if there was something to flush, and if so tell the user they
|
|
4860
|
+
// should request that the runtime be exitable.
|
|
4861
|
+
// Normally we would not even include flush() at all, but in ASSERTIONS
|
|
4862
|
+
// builds we do so just for this check, and here we see if there is any
|
|
4863
|
+
// content to flush, that is, we check if there would have been
|
|
4864
|
+
// something a non-ASSERTIONS build would have not seen.
|
|
4865
|
+
// How we flush the streams depends on whether we are in SYSCALLS_REQUIRE_FILESYSTEM=0
|
|
4866
|
+
// mode (which has its own special function for this; otherwise, all
|
|
4867
|
+
// the code is inside libc)
|
|
4868
|
+
var oldOut = out;
|
|
4869
|
+
var oldErr = err;
|
|
4870
|
+
var has = false;
|
|
4871
|
+
out = err = (x) => {
|
|
4872
|
+
has = true;
|
|
4873
|
+
}
|
|
4874
|
+
try { // it doesn't matter if it fails
|
|
4875
|
+
} catch (e) { }
|
|
4876
|
+
out = oldOut;
|
|
4877
|
+
err = oldErr;
|
|
4878
|
+
if (has) {
|
|
4879
|
+
warnOnce('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline when you printf etc.');
|
|
4880
|
+
}
|
|
4881
|
+
}
|
|
4882
|
+
|
|
4883
|
+
run();
|
|
4884
|
+
|
|
4885
|
+
// end include: postamble.js
|
|
4886
|
+
//FORWARDED_DATA:{"librarySymbols":["__embind_register_void","readLatin1String","embind_charCodes","embind_init_charCodes","registerType","awaitingDependencies","registeredTypes","typeDependencies","throwBindingError","BindingError","extendError","createNamedFunction","makeLegalFunctionName","char_0","char_9","whenDependentTypesAreResolved","throwInternalError","InternalError","__embind_register_bool","getShiftFromSize","__embind_register_integer","embindRepr","integerReadValueFromPointer","__embind_register_bigint","__embind_register_float","floatReadValueFromPointer","__embind_register_std_string","simpleReadValueFromPointer","stringToUTF8","stringToUTF8Array","lengthBytesUTF8","_malloc","_free","UTF8ToString","UTF8ArrayToString","UTF8Decoder","__embind_register_std_wstring","UTF16ToString","UTF16Decoder","stringToUTF16","lengthBytesUTF16","UTF32ToString","stringToUTF32","lengthBytesUTF32","__embind_register_emval","__emval_decref","emval_handles","HandleAllocator","Emval","init_emval","count_emval_handles","__embind_register_memory_view","__embind_register_function","craftInvokerFunction","runDestructors","newFunc","exposePublicSymbol","ensureOverloadTable","heap32VectorToArray","replacePublicSymbol","embind__requireFunction","getDynCaller","getWasmTableEntry","throwUnboundTypeError","UnboundTypeError","getTypeName","___getTypeName","__embind_register_value_array","tupleRegistrations","__embind_register_value_array_element","__embind_finalize_value_array","__embind_register_value_object","structRegistrations","__embind_register_value_object_field","__embind_finalize_value_object","__embind_register_class","ClassHandle","init_ClassHandle","ClassHandle_isAliasOf","ClassHandle_clone","shallowCopyInternalPointer","throwInstanceAlreadyDeleted","attachFinalizer","finalizationRegistry","detachFinalizer","releaseClassHandle","runDestructor","RegisteredPointer_fromWireType","downcastPointer","registeredPointers","getInheritedInstance","registeredInstances","init_embind","getInheritedInstanceCount","getLiveInheritedInstances","flushPendingDeletes","deletionQueue","setDelayFunction","delayFunction","getBasestPointer","makeClassHandle","bigintToI53Checked","MAX_INT53","MIN_INT53","ClassHandle_delete","ClassHandle_isDeleted","ClassHandle_deleteLater","RegisteredClass","RegisteredPointer","constNoSmartPtrRawPointerToWireType","upcastPointer","genericPointerToWireType","nonConstNoSmartPtrRawPointerToWireType","init_RegisteredPointer","RegisteredPointer_getPointee","RegisteredPointer_destructor","RegisteredPointer_deleteObject","__embind_register_class_constructor","__embind_register_class_function","__embind_register_class_property","validateThis","__embind_register_class_class_function","__embind_register_class_class_property","__embind_create_inheriting_constructor","PureVirtualError","registerInheritedInstance","requireRegisteredType","unregisterInheritedInstance","__embind_register_smart_ptr","__embind_register_enum","enumReadValueFromPointer","__embind_register_enum_value","__embind_register_constant","__emval_register_symbol","emval_symbols","__emval_incref","__emval_run_destructors","__emval_new_array","__emval_new_array_from_memory_view","__emval_new_object","__emval_new_cstring","getStringOrSymbol","__emval_new_u8string","__emval_new_u16string","__emval_take_value","__emval_new","craftEmvalAllocator","emval_newers","__emval_get_global","emval_get_global","__emval_get_module_property","__emval_get_property","__emval_set_property","__emval_as","__emval_as_int64","__emval_as_uint64","__emval_equals","__emval_strictly_equals","__emval_greater_than","__emval_less_than","__emval_not","__emval_call","emval_lookupTypes","__emval_get_method_caller","emval_addMethodCaller","emval_methodCallers","emval_registeredMethods","__emval_call_method","emval_allocateDestructors","__emval_call_void_method","__emval_typeof","__emval_instanceof","__emval_is_number","__emval_is_string","__emval_in","__emval_delete","__emval_throw"],"warnings":false,"asyncFuncs":[],"ATINITS":"","ATMAINS":"","ATEXITS":""}
|
|
4887
|
+
|
|
4888
|
+
globalThis.Module['ASSERTIONS'] = true;
|
|
4889
|
+
export default globalThis.Module;
|
|
4890
|
+
|
|
4891
|
+
function toArray(vector) {
|
|
4892
|
+
const output = [];
|
|
4893
|
+
for (let i = 0; i < vector.size(); i += 1) {
|
|
4894
|
+
output.push(vector.get(i));
|
|
4895
|
+
}
|
|
4896
|
+
return output;
|
|
4897
|
+
}
|
|
4898
|
+
|
|
4899
|
+
function toVector(VectorClass, array = []) {
|
|
4900
|
+
const vector = new VectorClass();
|
|
4901
|
+
array.forEach((item) => {
|
|
4902
|
+
vector.push_back(item);
|
|
4903
|
+
});
|
|
4904
|
+
return vector;
|
|
4905
|
+
}
|
|
4906
|
+
|
|
4907
|
+
globalThis.Module.toArray = toArray;
|
|
4908
|
+
globalThis.Module.toVector = toVector;
|