@ylink-sdk/mobile-web 0.1.6 → 0.1.9-beta.1
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/dist/e30037b8/VERSION +6 -0
- package/dist/e30037b8/libipvp-simd.d.ts +474 -0
- package/dist/e30037b8/libipvp-simd.js +3267 -0
- package/dist/e30037b8/libipvp-simd.prod.d.ts +474 -0
- package/dist/e30037b8/libipvp-simd.prod.js +184 -0
- package/dist/e30037b8/libipvp-simd.prod.wasm +0 -0
- package/dist/e30037b8/libipvp-simd.wasm +0 -0
- package/dist/e30037b8/libipvp.d.ts +474 -0
- package/dist/e30037b8/libipvp.js +3267 -0
- package/dist/e30037b8/libipvp.prod.d.ts +474 -0
- package/dist/e30037b8/libipvp.prod.js +184 -0
- package/dist/e30037b8/libipvp.prod.wasm +0 -0
- package/dist/e30037b8/libipvp.wasm +0 -0
- package/dist/e30037b8/librtc.d.ts +438 -0
- package/dist/e30037b8/librtc.global.js +5863 -0
- package/dist/e30037b8/librtc.global.prod.js +15 -0
- package/dist/e30037b8/libsfu-simd.d.ts +767 -0
- package/dist/e30037b8/libsfu-simd.js +4822 -0
- package/dist/e30037b8/libsfu-simd.prod.d.ts +767 -0
- package/dist/e30037b8/libsfu-simd.prod.js +209 -0
- package/dist/e30037b8/libsfu-simd.prod.wasm +0 -0
- package/dist/e30037b8/libsfu-simd.wasm +0 -0
- package/dist/e30037b8/libsfu.d.ts +767 -0
- package/dist/e30037b8/libsfu.js +4822 -0
- package/dist/e30037b8/libsfu.prod.d.ts +767 -0
- package/dist/e30037b8/libsfu.prod.js +209 -0
- package/dist/e30037b8/libsfu.prod.wasm +0 -0
- package/dist/e30037b8/libsfu.wasm +0 -0
- package/dist/e30037b8/libsvc-simd-m1.d.ts +767 -0
- package/dist/e30037b8/libsvc-simd-m1.js +4921 -0
- package/dist/e30037b8/libsvc-simd-m1.prod.d.ts +767 -0
- package/dist/e30037b8/libsvc-simd-m1.prod.js +209 -0
- package/dist/e30037b8/libsvc-simd-m1.prod.wasm +0 -0
- package/dist/e30037b8/libsvc-simd-m1.wasm +0 -0
- package/dist/e30037b8/libsvc-simd.d.ts +767 -0
- package/dist/e30037b8/libsvc-simd.js +4857 -0
- package/dist/e30037b8/libsvc-simd.prod.d.ts +767 -0
- package/dist/e30037b8/libsvc-simd.prod.js +209 -0
- package/dist/e30037b8/libsvc-simd.prod.wasm +0 -0
- package/dist/e30037b8/libsvc-simd.wasm +0 -0
- package/dist/e30037b8/libsvc.d.ts +767 -0
- package/dist/e30037b8/libsvc.js +4857 -0
- package/dist/e30037b8/libsvc.prod.d.ts +767 -0
- package/dist/e30037b8/libsvc.prod.js +209 -0
- package/dist/e30037b8/libsvc.prod.wasm +0 -0
- package/dist/e30037b8/libsvc.wasm +0 -0
- package/dist/e30037b8/native-audio-worker.global.js +1583 -0
- package/dist/e30037b8/native-audio-worker.global.prod.js +15 -0
- package/dist/e30037b8/native-video-worker.global.js +1960 -0
- package/dist/e30037b8/native-video-worker.global.prod.js +15 -0
- package/dist/e30037b8/worklet-audio-worker.global.js +900 -0
- package/dist/e30037b8/worklet-audio-worker.global.prod.js +15 -0
- package/dist/style.css +1 -1
- package/dist/ylink-sdk-mobile.umd.js +70 -70
- package/package.json +1 -1
|
@@ -0,0 +1,4857 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
if (typeof WXWebAssembly !== 'undefined') {
|
|
3
|
+
var WebAssembly = WXWebAssembly;
|
|
4
|
+
WebAssembly.RuntimeError = Error;
|
|
5
|
+
WebAssembly.validate = () => false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var LIBSVC = (function() {
|
|
10
|
+
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
|
|
11
|
+
if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;
|
|
12
|
+
return (
|
|
13
|
+
function(LIBSVC) {
|
|
14
|
+
LIBSVC = LIBSVC || {};
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// The Module object: Our interface to the outside world. We import
|
|
19
|
+
// and export values on it. There are various ways Module can be used:
|
|
20
|
+
// 1. Not defined. We create it here
|
|
21
|
+
// 2. A function parameter, function(Module) { ..generated code.. }
|
|
22
|
+
// 3. pre-run appended it, var Module = {}; ..generated code..
|
|
23
|
+
// 4. External script tag defines var Module.
|
|
24
|
+
// We need to check if Module already exists (e.g. case 3 above).
|
|
25
|
+
// Substitution will be replaced with actual code on later stage of the build,
|
|
26
|
+
// this way Closure Compiler will not mangle it (e.g. case 4. above).
|
|
27
|
+
// Note that if you want to run closure, and also to use Module
|
|
28
|
+
// after the generated code, you will need to define var Module = {};
|
|
29
|
+
// before the code. Then that object will be used in the code, and you
|
|
30
|
+
// can continue to use Module afterwards as well.
|
|
31
|
+
var Module = typeof LIBSVC !== 'undefined' ? LIBSVC : {};
|
|
32
|
+
|
|
33
|
+
// Set up the promise that indicates the Module is initialized
|
|
34
|
+
var readyPromiseResolve, readyPromiseReject;
|
|
35
|
+
Module['ready'] = new Promise(function(resolve, reject) {
|
|
36
|
+
readyPromiseResolve = resolve;
|
|
37
|
+
readyPromiseReject = reject;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// --pre-jses are emitted after the Module integration code, so that they can
|
|
41
|
+
// refer to Module (if they choose; they can also define Module)
|
|
42
|
+
// {{PRE_JSES}}
|
|
43
|
+
|
|
44
|
+
// Sometimes an existing Module object exists with properties
|
|
45
|
+
// meant to overwrite the default module functionality. Here
|
|
46
|
+
// we collect those properties and reapply _after_ we configure
|
|
47
|
+
// the current environment's defaults to avoid having to be so
|
|
48
|
+
// defensive during initialization.
|
|
49
|
+
var moduleOverrides = {};
|
|
50
|
+
var key;
|
|
51
|
+
for (key in Module) {
|
|
52
|
+
if (Module.hasOwnProperty(key)) {
|
|
53
|
+
moduleOverrides[key] = Module[key];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
var arguments_ = [];
|
|
58
|
+
var thisProgram = './this.program';
|
|
59
|
+
var quit_ = function(status, toThrow) {
|
|
60
|
+
throw toThrow;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Determine the runtime environment we are in. You can customize this by
|
|
64
|
+
// setting the ENVIRONMENT setting at compile time (see settings.js).
|
|
65
|
+
|
|
66
|
+
var ENVIRONMENT_IS_WEB = false;
|
|
67
|
+
var ENVIRONMENT_IS_WORKER = false;
|
|
68
|
+
var ENVIRONMENT_IS_NODE = false;
|
|
69
|
+
var ENVIRONMENT_IS_SHELL = false;
|
|
70
|
+
ENVIRONMENT_IS_WEB = typeof window === 'object';
|
|
71
|
+
ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
|
|
72
|
+
// N.b. Electron.js environment is simultaneously a NODE-environment, but
|
|
73
|
+
// also a web environment.
|
|
74
|
+
ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';
|
|
75
|
+
ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
|
|
76
|
+
|
|
77
|
+
// `/` should be present at the end if `scriptDirectory` is not empty
|
|
78
|
+
var scriptDirectory = '';
|
|
79
|
+
function locateFile(path) {
|
|
80
|
+
if (Module['locateFile']) {
|
|
81
|
+
return Module['locateFile'](path, scriptDirectory);
|
|
82
|
+
}
|
|
83
|
+
return scriptDirectory + path;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Hooks that are implemented differently in different runtime environments.
|
|
87
|
+
var read_,
|
|
88
|
+
readAsync,
|
|
89
|
+
readBinary,
|
|
90
|
+
setWindowTitle;
|
|
91
|
+
|
|
92
|
+
var nodeFS;
|
|
93
|
+
var nodePath;
|
|
94
|
+
|
|
95
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
96
|
+
if (ENVIRONMENT_IS_WORKER) {
|
|
97
|
+
scriptDirectory = require('path').dirname(scriptDirectory) + '/';
|
|
98
|
+
} else {
|
|
99
|
+
scriptDirectory = __dirname + '/';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// include: node_shell_read.js
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
read_ = function shell_read(filename, binary) {
|
|
106
|
+
if (!nodeFS) nodeFS = require('fs');
|
|
107
|
+
if (!nodePath) nodePath = require('path');
|
|
108
|
+
filename = nodePath['normalize'](filename);
|
|
109
|
+
return nodeFS['readFileSync'](filename, binary ? null : 'utf8');
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
readBinary = function readBinary(filename) {
|
|
113
|
+
var ret = read_(filename, true);
|
|
114
|
+
if (!ret.buffer) {
|
|
115
|
+
ret = new Uint8Array(ret);
|
|
116
|
+
}
|
|
117
|
+
assert(ret.buffer);
|
|
118
|
+
return ret;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// end include: node_shell_read.js
|
|
122
|
+
if (process['argv'].length > 1) {
|
|
123
|
+
thisProgram = process['argv'][1].replace(/\\/g, '/');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
arguments_ = process['argv'].slice(2);
|
|
127
|
+
|
|
128
|
+
// MODULARIZE will export the module in the proper place outside, we don't need to export here
|
|
129
|
+
|
|
130
|
+
process['on']('uncaughtException', function(ex) {
|
|
131
|
+
// suppress ExitStatus exceptions from showing an error
|
|
132
|
+
if (!(ex instanceof ExitStatus)) {
|
|
133
|
+
throw ex;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
process['on']('unhandledRejection', abort);
|
|
138
|
+
|
|
139
|
+
quit_ = function(status) {
|
|
140
|
+
process['exit'](status);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
Module['inspect'] = function () { return '[Emscripten Module object]'; };
|
|
144
|
+
|
|
145
|
+
} else
|
|
146
|
+
if (ENVIRONMENT_IS_SHELL) {
|
|
147
|
+
|
|
148
|
+
if (typeof read != 'undefined') {
|
|
149
|
+
read_ = function shell_read(f) {
|
|
150
|
+
return read(f);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
readBinary = function readBinary(f) {
|
|
155
|
+
var data;
|
|
156
|
+
if (typeof readbuffer === 'function') {
|
|
157
|
+
return new Uint8Array(readbuffer(f));
|
|
158
|
+
}
|
|
159
|
+
data = read(f, 'binary');
|
|
160
|
+
assert(typeof data === 'object');
|
|
161
|
+
return data;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
if (typeof scriptArgs != 'undefined') {
|
|
165
|
+
arguments_ = scriptArgs;
|
|
166
|
+
} else if (typeof arguments != 'undefined') {
|
|
167
|
+
arguments_ = arguments;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (typeof quit === 'function') {
|
|
171
|
+
quit_ = function(status) {
|
|
172
|
+
quit(status);
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (typeof print !== 'undefined') {
|
|
177
|
+
// Prefer to use print/printErr where they exist, as they usually work better.
|
|
178
|
+
if (typeof console === 'undefined') console = /** @type{!Console} */({});
|
|
179
|
+
console.log = /** @type{!function(this:Console, ...*): undefined} */ (print);
|
|
180
|
+
console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (typeof printErr !== 'undefined' ? printErr : print);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
} else
|
|
184
|
+
|
|
185
|
+
// Note that this includes Node.js workers when relevant (pthreads is enabled).
|
|
186
|
+
// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
|
|
187
|
+
// ENVIRONMENT_IS_NODE.
|
|
188
|
+
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
|
|
189
|
+
if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
|
|
190
|
+
scriptDirectory = typeof self !== 'undefined' ? self.location.href : '';
|
|
191
|
+
} else if (typeof document !== 'undefined' && document.currentScript) { // web
|
|
192
|
+
scriptDirectory = document.currentScript.src;
|
|
193
|
+
}
|
|
194
|
+
// When MODULARIZE, this JS may be executed later, after document.currentScript
|
|
195
|
+
// is gone, so we saved it, and we use it here instead of any other info.
|
|
196
|
+
if (_scriptDir) {
|
|
197
|
+
scriptDirectory = _scriptDir;
|
|
198
|
+
}
|
|
199
|
+
// blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
|
|
200
|
+
// otherwise, slice off the final part of the url to find the script directory.
|
|
201
|
+
// if scriptDirectory does not contain a slash, lastIndexOf will return -1,
|
|
202
|
+
// and scriptDirectory will correctly be replaced with an empty string.
|
|
203
|
+
if (scriptDirectory.indexOf('blob:') !== 0) {
|
|
204
|
+
scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf('/')+1);
|
|
205
|
+
} else {
|
|
206
|
+
scriptDirectory = '';
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Differentiate the Web Worker from the Node Worker case, as reading must
|
|
210
|
+
// be done differently.
|
|
211
|
+
{
|
|
212
|
+
|
|
213
|
+
// include: web_or_worker_shell_read.js
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
read_ = function(url) {
|
|
217
|
+
var xhr = new XMLHttpRequest();
|
|
218
|
+
xhr.open('GET', url, false);
|
|
219
|
+
xhr.send(null);
|
|
220
|
+
return xhr.responseText;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
if (ENVIRONMENT_IS_WORKER) {
|
|
224
|
+
readBinary = function(url) {
|
|
225
|
+
var xhr = new XMLHttpRequest();
|
|
226
|
+
xhr.open('GET', url, false);
|
|
227
|
+
xhr.responseType = 'arraybuffer';
|
|
228
|
+
xhr.send(null);
|
|
229
|
+
return new Uint8Array(/** @type{!ArrayBuffer} */(xhr.response));
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
readAsync = function(url, onload, onerror) {
|
|
234
|
+
var xhr = new XMLHttpRequest();
|
|
235
|
+
xhr.open('GET', url, true);
|
|
236
|
+
xhr.responseType = 'arraybuffer';
|
|
237
|
+
xhr.onload = function() {
|
|
238
|
+
if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
|
|
239
|
+
onload(xhr.response);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
onerror();
|
|
243
|
+
};
|
|
244
|
+
xhr.onerror = onerror;
|
|
245
|
+
xhr.send(null);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// end include: web_or_worker_shell_read.js
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
setWindowTitle = function(title) { document.title = title };
|
|
252
|
+
} else
|
|
253
|
+
{
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Set up the out() and err() hooks, which are how we can print to stdout or
|
|
257
|
+
// stderr, respectively.
|
|
258
|
+
var out = Module['print'] || console.log.bind(console);
|
|
259
|
+
var err = Module['printErr'] || console.warn.bind(console);
|
|
260
|
+
|
|
261
|
+
// Merge back in the overrides
|
|
262
|
+
for (key in moduleOverrides) {
|
|
263
|
+
if (moduleOverrides.hasOwnProperty(key)) {
|
|
264
|
+
Module[key] = moduleOverrides[key];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// Free the object hierarchy contained in the overrides, this lets the GC
|
|
268
|
+
// reclaim data used e.g. in memoryInitializerRequest, which is a large typed array.
|
|
269
|
+
moduleOverrides = null;
|
|
270
|
+
|
|
271
|
+
// Emit code to handle expected values on the Module object. This applies Module.x
|
|
272
|
+
// to the proper local x. This has two benefits: first, we only emit it if it is
|
|
273
|
+
// expected to arrive, and second, by using a local everywhere else that can be
|
|
274
|
+
// minified.
|
|
275
|
+
if (Module['arguments']) arguments_ = Module['arguments'];
|
|
276
|
+
if (Module['thisProgram']) thisProgram = Module['thisProgram'];
|
|
277
|
+
if (Module['quit']) quit_ = Module['quit'];
|
|
278
|
+
|
|
279
|
+
// perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
var STACK_ALIGN = 16;
|
|
285
|
+
|
|
286
|
+
function alignMemory(size, factor) {
|
|
287
|
+
if (!factor) factor = STACK_ALIGN; // stack alignment (16-byte) by default
|
|
288
|
+
return Math.ceil(size / factor) * factor;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function getNativeTypeSize(type) {
|
|
292
|
+
switch (type) {
|
|
293
|
+
case 'i1': case 'i8': return 1;
|
|
294
|
+
case 'i16': return 2;
|
|
295
|
+
case 'i32': return 4;
|
|
296
|
+
case 'i64': return 8;
|
|
297
|
+
case 'float': return 4;
|
|
298
|
+
case 'double': return 8;
|
|
299
|
+
default: {
|
|
300
|
+
if (type[type.length-1] === '*') {
|
|
301
|
+
return 4; // A pointer
|
|
302
|
+
} else if (type[0] === 'i') {
|
|
303
|
+
var bits = Number(type.substr(1));
|
|
304
|
+
assert(bits % 8 === 0, 'getNativeTypeSize invalid bits ' + bits + ', type ' + type);
|
|
305
|
+
return bits / 8;
|
|
306
|
+
} else {
|
|
307
|
+
return 0;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function warnOnce(text) {
|
|
314
|
+
if (!warnOnce.shown) warnOnce.shown = {};
|
|
315
|
+
if (!warnOnce.shown[text]) {
|
|
316
|
+
warnOnce.shown[text] = 1;
|
|
317
|
+
err(text);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// include: runtime_functions.js
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
// Wraps a JS function as a wasm function with a given signature.
|
|
325
|
+
function convertJsFunctionToWasm(func, sig) {
|
|
326
|
+
|
|
327
|
+
// If the type reflection proposal is available, use the new
|
|
328
|
+
// "WebAssembly.Function" constructor.
|
|
329
|
+
// Otherwise, construct a minimal wasm module importing the JS function and
|
|
330
|
+
// re-exporting it.
|
|
331
|
+
if (typeof WebAssembly.Function === "function") {
|
|
332
|
+
var typeNames = {
|
|
333
|
+
'i': 'i32',
|
|
334
|
+
'j': 'i64',
|
|
335
|
+
'f': 'f32',
|
|
336
|
+
'd': 'f64'
|
|
337
|
+
};
|
|
338
|
+
var type = {
|
|
339
|
+
parameters: [],
|
|
340
|
+
results: sig[0] == 'v' ? [] : [typeNames[sig[0]]]
|
|
341
|
+
};
|
|
342
|
+
for (var i = 1; i < sig.length; ++i) {
|
|
343
|
+
type.parameters.push(typeNames[sig[i]]);
|
|
344
|
+
}
|
|
345
|
+
return new WebAssembly.Function(type, func);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// The module is static, with the exception of the type section, which is
|
|
349
|
+
// generated based on the signature passed in.
|
|
350
|
+
var typeSection = [
|
|
351
|
+
0x01, // id: section,
|
|
352
|
+
0x00, // length: 0 (placeholder)
|
|
353
|
+
0x01, // count: 1
|
|
354
|
+
0x60, // form: func
|
|
355
|
+
];
|
|
356
|
+
var sigRet = sig.slice(0, 1);
|
|
357
|
+
var sigParam = sig.slice(1);
|
|
358
|
+
var typeCodes = {
|
|
359
|
+
'i': 0x7f, // i32
|
|
360
|
+
'j': 0x7e, // i64
|
|
361
|
+
'f': 0x7d, // f32
|
|
362
|
+
'd': 0x7c, // f64
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// Parameters, length + signatures
|
|
366
|
+
typeSection.push(sigParam.length);
|
|
367
|
+
for (var i = 0; i < sigParam.length; ++i) {
|
|
368
|
+
typeSection.push(typeCodes[sigParam[i]]);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Return values, length + signatures
|
|
372
|
+
// With no multi-return in MVP, either 0 (void) or 1 (anything else)
|
|
373
|
+
if (sigRet == 'v') {
|
|
374
|
+
typeSection.push(0x00);
|
|
375
|
+
} else {
|
|
376
|
+
typeSection = typeSection.concat([0x01, typeCodes[sigRet]]);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Write the overall length of the type section back into the section header
|
|
380
|
+
// (excepting the 2 bytes for the section id and length)
|
|
381
|
+
typeSection[1] = typeSection.length - 2;
|
|
382
|
+
|
|
383
|
+
// Rest of the module is static
|
|
384
|
+
var bytes = new Uint8Array([
|
|
385
|
+
0x00, 0x61, 0x73, 0x6d, // magic ("\0asm")
|
|
386
|
+
0x01, 0x00, 0x00, 0x00, // version: 1
|
|
387
|
+
].concat(typeSection, [
|
|
388
|
+
0x02, 0x07, // import section
|
|
389
|
+
// (import "e" "f" (func 0 (type 0)))
|
|
390
|
+
0x01, 0x01, 0x65, 0x01, 0x66, 0x00, 0x00,
|
|
391
|
+
0x07, 0x05, // export section
|
|
392
|
+
// (export "f" (func 0 (type 0)))
|
|
393
|
+
0x01, 0x01, 0x66, 0x00, 0x00,
|
|
394
|
+
]));
|
|
395
|
+
|
|
396
|
+
// We can compile this wasm module synchronously because it is very small.
|
|
397
|
+
// This accepts an import (at "e.f"), that it reroutes to an export (at "f")
|
|
398
|
+
var module = new WebAssembly.Module(bytes);
|
|
399
|
+
var instance = new WebAssembly.Instance(module, {
|
|
400
|
+
'e': {
|
|
401
|
+
'f': func
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
var wrappedFunc = instance.exports['f'];
|
|
405
|
+
return wrappedFunc;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
var freeTableIndexes = [];
|
|
409
|
+
|
|
410
|
+
// Weak map of functions in the table to their indexes, created on first use.
|
|
411
|
+
var functionsInTableMap;
|
|
412
|
+
|
|
413
|
+
function getEmptyTableSlot() {
|
|
414
|
+
// Reuse a free index if there is one, otherwise grow.
|
|
415
|
+
if (freeTableIndexes.length) {
|
|
416
|
+
return freeTableIndexes.pop();
|
|
417
|
+
}
|
|
418
|
+
// Grow the table
|
|
419
|
+
try {
|
|
420
|
+
wasmTable.grow(1);
|
|
421
|
+
} catch (err) {
|
|
422
|
+
if (!(err instanceof RangeError)) {
|
|
423
|
+
throw err;
|
|
424
|
+
}
|
|
425
|
+
throw 'Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.';
|
|
426
|
+
}
|
|
427
|
+
return wasmTable.length - 1;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Add a wasm function to the table.
|
|
431
|
+
function addFunctionWasm(func, sig) {
|
|
432
|
+
// Check if the function is already in the table, to ensure each function
|
|
433
|
+
// gets a unique index. First, create the map if this is the first use.
|
|
434
|
+
if (!functionsInTableMap) {
|
|
435
|
+
functionsInTableMap = new WeakMap();
|
|
436
|
+
for (var i = 0; i < wasmTable.length; i++) {
|
|
437
|
+
var item = wasmTable.get(i);
|
|
438
|
+
// Ignore null values.
|
|
439
|
+
if (item) {
|
|
440
|
+
functionsInTableMap.set(item, i);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (functionsInTableMap.has(func)) {
|
|
445
|
+
return functionsInTableMap.get(func);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// It's not in the table, add it now.
|
|
449
|
+
|
|
450
|
+
var ret = getEmptyTableSlot();
|
|
451
|
+
|
|
452
|
+
// Set the new value.
|
|
453
|
+
try {
|
|
454
|
+
// Attempting to call this with JS function will cause of table.set() to fail
|
|
455
|
+
wasmTable.set(ret, func);
|
|
456
|
+
} catch (err) {
|
|
457
|
+
if (!(err instanceof TypeError)) {
|
|
458
|
+
throw err;
|
|
459
|
+
}
|
|
460
|
+
var wrapped = convertJsFunctionToWasm(func, sig);
|
|
461
|
+
wasmTable.set(ret, wrapped);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
functionsInTableMap.set(func, ret);
|
|
465
|
+
|
|
466
|
+
return ret;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function removeFunction(index) {
|
|
470
|
+
functionsInTableMap.delete(wasmTable.get(index));
|
|
471
|
+
freeTableIndexes.push(index);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// 'sig' parameter is required for the llvm backend but only when func is not
|
|
475
|
+
// already a WebAssembly function.
|
|
476
|
+
function addFunction(func, sig) {
|
|
477
|
+
|
|
478
|
+
return addFunctionWasm(func, sig);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// end include: runtime_functions.js
|
|
482
|
+
// include: runtime_debug.js
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
// end include: runtime_debug.js
|
|
486
|
+
function makeBigInt(low, high, unsigned) {
|
|
487
|
+
return unsigned ? ((+((low>>>0)))+((+((high>>>0)))*4294967296.0)) : ((+((low>>>0)))+((+((high|0)))*4294967296.0));
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
var tempRet0 = 0;
|
|
491
|
+
|
|
492
|
+
var setTempRet0 = function(value) {
|
|
493
|
+
tempRet0 = value;
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
var getTempRet0 = function() {
|
|
497
|
+
return tempRet0;
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
// === Preamble library stuff ===
|
|
503
|
+
|
|
504
|
+
// Documentation for the public APIs defined in this file must be updated in:
|
|
505
|
+
// site/source/docs/api_reference/preamble.js.rst
|
|
506
|
+
// A prebuilt local version of the documentation is available at:
|
|
507
|
+
// site/build/text/docs/api_reference/preamble.js.txt
|
|
508
|
+
// You can also build docs locally as HTML or other formats in site/
|
|
509
|
+
// An online HTML version (which may be of a different version of Emscripten)
|
|
510
|
+
// is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
|
|
511
|
+
|
|
512
|
+
var wasmBinary;if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
|
|
513
|
+
var noExitRuntime;if (Module['noExitRuntime']) noExitRuntime = Module['noExitRuntime'];
|
|
514
|
+
|
|
515
|
+
if (typeof WebAssembly !== 'object') {
|
|
516
|
+
abort('no native wasm support detected');
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// include: runtime_safe_heap.js
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
// In MINIMAL_RUNTIME, setValue() and getValue() are only available when building with safe heap enabled, for heap safety checking.
|
|
523
|
+
// In traditional runtime, setValue() and getValue() are always available (although their use is highly discouraged due to perf penalties)
|
|
524
|
+
|
|
525
|
+
/** @param {number} ptr
|
|
526
|
+
@param {number} value
|
|
527
|
+
@param {string} type
|
|
528
|
+
@param {number|boolean=} noSafe */
|
|
529
|
+
function setValue(ptr, value, type, noSafe) {
|
|
530
|
+
type = type || 'i8';
|
|
531
|
+
if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
|
|
532
|
+
switch(type) {
|
|
533
|
+
case 'i1': HEAP8[((ptr)>>0)]=value; break;
|
|
534
|
+
case 'i8': HEAP8[((ptr)>>0)]=value; break;
|
|
535
|
+
case 'i16': HEAP16[((ptr)>>1)]=value; break;
|
|
536
|
+
case 'i32': HEAP32[((ptr)>>2)]=value; break;
|
|
537
|
+
case 'i64': (tempI64 = [value>>>0,(tempDouble=value,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math.min((+(Math.floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[((ptr)>>2)]=tempI64[0],HEAP32[(((ptr)+(4))>>2)]=tempI64[1]); break;
|
|
538
|
+
case 'float': HEAPF32[((ptr)>>2)]=value; break;
|
|
539
|
+
case 'double': HEAPF64[((ptr)>>3)]=value; break;
|
|
540
|
+
default: abort('invalid type for setValue: ' + type);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** @param {number} ptr
|
|
545
|
+
@param {string} type
|
|
546
|
+
@param {number|boolean=} noSafe */
|
|
547
|
+
function getValue(ptr, type, noSafe) {
|
|
548
|
+
type = type || 'i8';
|
|
549
|
+
if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
|
|
550
|
+
switch(type) {
|
|
551
|
+
case 'i1': return HEAP8[((ptr)>>0)];
|
|
552
|
+
case 'i8': return HEAP8[((ptr)>>0)];
|
|
553
|
+
case 'i16': return HEAP16[((ptr)>>1)];
|
|
554
|
+
case 'i32': return HEAP32[((ptr)>>2)];
|
|
555
|
+
case 'i64': return HEAP32[((ptr)>>2)];
|
|
556
|
+
case 'float': return HEAPF32[((ptr)>>2)];
|
|
557
|
+
case 'double': return HEAPF64[((ptr)>>3)];
|
|
558
|
+
default: abort('invalid type for getValue: ' + type);
|
|
559
|
+
}
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// end include: runtime_safe_heap.js
|
|
564
|
+
// Wasm globals
|
|
565
|
+
|
|
566
|
+
var wasmMemory;
|
|
567
|
+
|
|
568
|
+
//========================================
|
|
569
|
+
// Runtime essentials
|
|
570
|
+
//========================================
|
|
571
|
+
|
|
572
|
+
// whether we are quitting the application. no code should run after this.
|
|
573
|
+
// set in exit() and abort()
|
|
574
|
+
var ABORT = false;
|
|
575
|
+
|
|
576
|
+
// set by exit() and abort(). Passed to 'onExit' handler.
|
|
577
|
+
// NOTE: This is also used as the process return code code in shell environments
|
|
578
|
+
// but only when noExitRuntime is false.
|
|
579
|
+
var EXITSTATUS;
|
|
580
|
+
|
|
581
|
+
/** @type {function(*, string=)} */
|
|
582
|
+
function assert(condition, text) {
|
|
583
|
+
if (!condition) {
|
|
584
|
+
abort('Assertion failed: ' + text);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
|
|
589
|
+
function getCFunc(ident) {
|
|
590
|
+
var func = Module['_' + ident]; // closure exported function
|
|
591
|
+
assert(func, 'Cannot call unknown function ' + ident + ', make sure it is exported');
|
|
592
|
+
return func;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// C calling interface.
|
|
596
|
+
/** @param {string|null=} returnType
|
|
597
|
+
@param {Array=} argTypes
|
|
598
|
+
@param {Arguments|Array=} args
|
|
599
|
+
@param {Object=} opts */
|
|
600
|
+
function ccall(ident, returnType, argTypes, args, opts) {
|
|
601
|
+
// For fast lookup of conversion functions
|
|
602
|
+
var toC = {
|
|
603
|
+
'string': function(str) {
|
|
604
|
+
var ret = 0;
|
|
605
|
+
if (str !== null && str !== undefined && str !== 0) { // null string
|
|
606
|
+
// at most 4 bytes per UTF-8 code point, +1 for the trailing '\0'
|
|
607
|
+
var len = (str.length << 2) + 1;
|
|
608
|
+
ret = stackAlloc(len);
|
|
609
|
+
stringToUTF8(str, ret, len);
|
|
610
|
+
}
|
|
611
|
+
return ret;
|
|
612
|
+
},
|
|
613
|
+
'array': function(arr) {
|
|
614
|
+
var ret = stackAlloc(arr.length);
|
|
615
|
+
writeArrayToMemory(arr, ret);
|
|
616
|
+
return ret;
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
function convertReturnValue(ret) {
|
|
621
|
+
if (returnType === 'string') return UTF8ToString(ret);
|
|
622
|
+
if (returnType === 'boolean') return Boolean(ret);
|
|
623
|
+
return ret;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
var func = getCFunc(ident);
|
|
627
|
+
var cArgs = [];
|
|
628
|
+
var stack = 0;
|
|
629
|
+
if (args) {
|
|
630
|
+
for (var i = 0; i < args.length; i++) {
|
|
631
|
+
var converter = toC[argTypes[i]];
|
|
632
|
+
if (converter) {
|
|
633
|
+
if (stack === 0) stack = stackSave();
|
|
634
|
+
cArgs[i] = converter(args[i]);
|
|
635
|
+
} else {
|
|
636
|
+
cArgs[i] = args[i];
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
var ret = func.apply(null, cArgs);
|
|
641
|
+
|
|
642
|
+
ret = convertReturnValue(ret);
|
|
643
|
+
if (stack !== 0) stackRestore(stack);
|
|
644
|
+
return ret;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/** @param {string=} returnType
|
|
648
|
+
@param {Array=} argTypes
|
|
649
|
+
@param {Object=} opts */
|
|
650
|
+
function cwrap(ident, returnType, argTypes, opts) {
|
|
651
|
+
argTypes = argTypes || [];
|
|
652
|
+
// When the function takes numbers and returns a number, we can just return
|
|
653
|
+
// the original function
|
|
654
|
+
var numericArgs = argTypes.every(function(type){ return type === 'number'});
|
|
655
|
+
var numericRet = returnType !== 'string';
|
|
656
|
+
if (numericRet && numericArgs && !opts) {
|
|
657
|
+
return getCFunc(ident);
|
|
658
|
+
}
|
|
659
|
+
return function() {
|
|
660
|
+
return ccall(ident, returnType, argTypes, arguments, opts);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
var ALLOC_NORMAL = 0; // Tries to use _malloc()
|
|
665
|
+
var ALLOC_STACK = 1; // Lives for the duration of the current function call
|
|
666
|
+
|
|
667
|
+
// allocate(): This is for internal use. You can use it yourself as well, but the interface
|
|
668
|
+
// is a little tricky (see docs right below). The reason is that it is optimized
|
|
669
|
+
// for multiple syntaxes to save space in generated code. So you should
|
|
670
|
+
// normally not use allocate(), and instead allocate memory using _malloc(),
|
|
671
|
+
// initialize it with setValue(), and so forth.
|
|
672
|
+
// @slab: An array of data.
|
|
673
|
+
// @allocator: How to allocate memory, see ALLOC_*
|
|
674
|
+
/** @type {function((Uint8Array|Array<number>), number)} */
|
|
675
|
+
function allocate(slab, allocator) {
|
|
676
|
+
var ret;
|
|
677
|
+
|
|
678
|
+
if (allocator == ALLOC_STACK) {
|
|
679
|
+
ret = stackAlloc(slab.length);
|
|
680
|
+
} else {
|
|
681
|
+
ret = _malloc(slab.length);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
if (slab.subarray || slab.slice) {
|
|
685
|
+
HEAPU8.set(/** @type {!Uint8Array} */(slab), ret);
|
|
686
|
+
} else {
|
|
687
|
+
HEAPU8.set(new Uint8Array(slab), ret);
|
|
688
|
+
}
|
|
689
|
+
return ret;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// include: runtime_strings.js
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
// runtime_strings.js: Strings related runtime functions that are part of both MINIMAL_RUNTIME and regular runtime.
|
|
696
|
+
|
|
697
|
+
// Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the given array that contains uint8 values, returns
|
|
698
|
+
// a copy of that string as a Javascript String object.
|
|
699
|
+
|
|
700
|
+
var UTF8Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf8') : undefined;
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* @param {number} idx
|
|
704
|
+
* @param {number=} maxBytesToRead
|
|
705
|
+
* @return {string}
|
|
706
|
+
*/
|
|
707
|
+
function UTF8ArrayToString(heap, idx, maxBytesToRead) {
|
|
708
|
+
var endIdx = idx + maxBytesToRead;
|
|
709
|
+
var endPtr = idx;
|
|
710
|
+
// TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
|
|
711
|
+
// Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
|
|
712
|
+
// (As a tiny code save trick, compare endPtr against endIdx using a negation, so that undefined means Infinity)
|
|
713
|
+
while (heap[endPtr] && !(endPtr >= endIdx)) ++endPtr;
|
|
714
|
+
|
|
715
|
+
if (endPtr - idx > 16 && heap.subarray && UTF8Decoder) {
|
|
716
|
+
return UTF8Decoder.decode(heap.subarray(idx, endPtr));
|
|
717
|
+
} else {
|
|
718
|
+
var str = '';
|
|
719
|
+
// If building with TextDecoder, we have already computed the string length above, so test loop end condition against that
|
|
720
|
+
while (idx < endPtr) {
|
|
721
|
+
// For UTF8 byte structure, see:
|
|
722
|
+
// http://en.wikipedia.org/wiki/UTF-8#Description
|
|
723
|
+
// https://www.ietf.org/rfc/rfc2279.txt
|
|
724
|
+
// https://tools.ietf.org/html/rfc3629
|
|
725
|
+
var u0 = heap[idx++];
|
|
726
|
+
if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
|
|
727
|
+
var u1 = heap[idx++] & 63;
|
|
728
|
+
if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
|
|
729
|
+
var u2 = heap[idx++] & 63;
|
|
730
|
+
if ((u0 & 0xF0) == 0xE0) {
|
|
731
|
+
u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
|
|
732
|
+
} else {
|
|
733
|
+
u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heap[idx++] & 63);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
if (u0 < 0x10000) {
|
|
737
|
+
str += String.fromCharCode(u0);
|
|
738
|
+
} else {
|
|
739
|
+
var ch = u0 - 0x10000;
|
|
740
|
+
str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
return str;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the emscripten HEAP, returns a
|
|
748
|
+
// copy of that string as a Javascript String object.
|
|
749
|
+
// maxBytesToRead: an optional length that specifies the maximum number of bytes to read. You can omit
|
|
750
|
+
// this parameter to scan the string until the first \0 byte. If maxBytesToRead is
|
|
751
|
+
// passed, and the string at [ptr, ptr+maxBytesToReadr[ contains a null byte in the
|
|
752
|
+
// middle, then the string will cut short at that byte index (i.e. maxBytesToRead will
|
|
753
|
+
// not produce a string of exact length [ptr, ptr+maxBytesToRead[)
|
|
754
|
+
// N.B. mixing frequent uses of UTF8ToString() with and without maxBytesToRead may
|
|
755
|
+
// throw JS JIT optimizations off, so it is worth to consider consistently using one
|
|
756
|
+
// style or the other.
|
|
757
|
+
/**
|
|
758
|
+
* @param {number} ptr
|
|
759
|
+
* @param {number=} maxBytesToRead
|
|
760
|
+
* @return {string}
|
|
761
|
+
*/
|
|
762
|
+
function UTF8ToString(ptr, maxBytesToRead) {
|
|
763
|
+
return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// Copies the given Javascript String object 'str' to the given byte array at address 'outIdx',
|
|
767
|
+
// encoded in UTF8 form and null-terminated. The copy will require at most str.length*4+1 bytes of space in the HEAP.
|
|
768
|
+
// Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
|
|
769
|
+
// Parameters:
|
|
770
|
+
// str: the Javascript string to copy.
|
|
771
|
+
// heap: the array to copy to. Each index in this array is assumed to be one 8-byte element.
|
|
772
|
+
// outIdx: The starting offset in the array to begin the copying.
|
|
773
|
+
// maxBytesToWrite: The maximum number of bytes this function can write to the array.
|
|
774
|
+
// This count should include the null terminator,
|
|
775
|
+
// i.e. if maxBytesToWrite=1, only the null terminator will be written and nothing else.
|
|
776
|
+
// maxBytesToWrite=0 does not write any bytes to the output, not even the null terminator.
|
|
777
|
+
// Returns the number of bytes written, EXCLUDING the null terminator.
|
|
778
|
+
|
|
779
|
+
function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
|
|
780
|
+
if (!(maxBytesToWrite > 0)) // Parameter maxBytesToWrite is not optional. Negative values, 0, null, undefined and false each don't write out any bytes.
|
|
781
|
+
return 0;
|
|
782
|
+
|
|
783
|
+
var startIdx = outIdx;
|
|
784
|
+
var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
|
|
785
|
+
for (var i = 0; i < str.length; ++i) {
|
|
786
|
+
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
|
|
787
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
788
|
+
// For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629
|
|
789
|
+
var u = str.charCodeAt(i); // possibly a lead surrogate
|
|
790
|
+
if (u >= 0xD800 && u <= 0xDFFF) {
|
|
791
|
+
var u1 = str.charCodeAt(++i);
|
|
792
|
+
u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF);
|
|
793
|
+
}
|
|
794
|
+
if (u <= 0x7F) {
|
|
795
|
+
if (outIdx >= endIdx) break;
|
|
796
|
+
heap[outIdx++] = u;
|
|
797
|
+
} else if (u <= 0x7FF) {
|
|
798
|
+
if (outIdx + 1 >= endIdx) break;
|
|
799
|
+
heap[outIdx++] = 0xC0 | (u >> 6);
|
|
800
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
801
|
+
} else if (u <= 0xFFFF) {
|
|
802
|
+
if (outIdx + 2 >= endIdx) break;
|
|
803
|
+
heap[outIdx++] = 0xE0 | (u >> 12);
|
|
804
|
+
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
805
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
806
|
+
} else {
|
|
807
|
+
if (outIdx + 3 >= endIdx) break;
|
|
808
|
+
heap[outIdx++] = 0xF0 | (u >> 18);
|
|
809
|
+
heap[outIdx++] = 0x80 | ((u >> 12) & 63);
|
|
810
|
+
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
811
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
// Null-terminate the pointer to the buffer.
|
|
815
|
+
heap[outIdx] = 0;
|
|
816
|
+
return outIdx - startIdx;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
|
|
820
|
+
// null-terminated and encoded in UTF8 form. The copy will require at most str.length*4+1 bytes of space in the HEAP.
|
|
821
|
+
// Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
|
|
822
|
+
// Returns the number of bytes written, EXCLUDING the null terminator.
|
|
823
|
+
|
|
824
|
+
function stringToUTF8(str, outPtr, maxBytesToWrite) {
|
|
825
|
+
return stringToUTF8Array(str, HEAPU8,outPtr, maxBytesToWrite);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// Returns the number of bytes the given Javascript string takes if encoded as a UTF8 byte array, EXCLUDING the null terminator byte.
|
|
829
|
+
function lengthBytesUTF8(str) {
|
|
830
|
+
var len = 0;
|
|
831
|
+
for (var i = 0; i < str.length; ++i) {
|
|
832
|
+
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
|
|
833
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
834
|
+
var u = str.charCodeAt(i); // possibly a lead surrogate
|
|
835
|
+
if (u >= 0xD800 && u <= 0xDFFF) u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF);
|
|
836
|
+
if (u <= 0x7F) ++len;
|
|
837
|
+
else if (u <= 0x7FF) len += 2;
|
|
838
|
+
else if (u <= 0xFFFF) len += 3;
|
|
839
|
+
else len += 4;
|
|
840
|
+
}
|
|
841
|
+
return len;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// end include: runtime_strings.js
|
|
845
|
+
// include: runtime_strings_extra.js
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
// runtime_strings_extra.js: Strings related runtime functions that are available only in regular runtime.
|
|
849
|
+
|
|
850
|
+
// Given a pointer 'ptr' to a null-terminated ASCII-encoded string in the emscripten HEAP, returns
|
|
851
|
+
// a copy of that string as a Javascript String object.
|
|
852
|
+
|
|
853
|
+
function AsciiToString(ptr) {
|
|
854
|
+
var str = '';
|
|
855
|
+
while (1) {
|
|
856
|
+
var ch = HEAPU8[((ptr++)>>0)];
|
|
857
|
+
if (!ch) return str;
|
|
858
|
+
str += String.fromCharCode(ch);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
|
|
863
|
+
// null-terminated and encoded in ASCII form. The copy will require at most str.length+1 bytes of space in the HEAP.
|
|
864
|
+
|
|
865
|
+
function stringToAscii(str, outPtr) {
|
|
866
|
+
return writeAsciiToMemory(str, outPtr, false);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns
|
|
870
|
+
// a copy of that string as a Javascript String object.
|
|
871
|
+
|
|
872
|
+
var UTF16Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-16le') : undefined;
|
|
873
|
+
|
|
874
|
+
function UTF16ToString(ptr, maxBytesToRead) {
|
|
875
|
+
var endPtr = ptr;
|
|
876
|
+
// TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
|
|
877
|
+
// Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
|
|
878
|
+
var idx = endPtr >> 1;
|
|
879
|
+
var maxIdx = idx + maxBytesToRead / 2;
|
|
880
|
+
// If maxBytesToRead is not passed explicitly, it will be undefined, and this
|
|
881
|
+
// will always evaluate to true. This saves on code size.
|
|
882
|
+
while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx;
|
|
883
|
+
endPtr = idx << 1;
|
|
884
|
+
|
|
885
|
+
if (endPtr - ptr > 32 && UTF16Decoder) {
|
|
886
|
+
return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr));
|
|
887
|
+
} else {
|
|
888
|
+
var str = '';
|
|
889
|
+
|
|
890
|
+
// If maxBytesToRead is not passed explicitly, it will be undefined, and the for-loop's condition
|
|
891
|
+
// will always evaluate to true. The loop is then terminated on the first null char.
|
|
892
|
+
for (var i = 0; !(i >= maxBytesToRead / 2); ++i) {
|
|
893
|
+
var codeUnit = HEAP16[(((ptr)+(i*2))>>1)];
|
|
894
|
+
if (codeUnit == 0) break;
|
|
895
|
+
// fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
|
|
896
|
+
str += String.fromCharCode(codeUnit);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
return str;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
|
|
904
|
+
// null-terminated and encoded in UTF16 form. The copy will require at most str.length*4+2 bytes of space in the HEAP.
|
|
905
|
+
// Use the function lengthBytesUTF16() to compute the exact number of bytes (excluding null terminator) that this function will write.
|
|
906
|
+
// Parameters:
|
|
907
|
+
// str: the Javascript string to copy.
|
|
908
|
+
// outPtr: Byte address in Emscripten HEAP where to write the string to.
|
|
909
|
+
// maxBytesToWrite: The maximum number of bytes this function can write to the array. This count should include the null
|
|
910
|
+
// terminator, i.e. if maxBytesToWrite=2, only the null terminator will be written and nothing else.
|
|
911
|
+
// maxBytesToWrite<2 does not write any bytes to the output, not even the null terminator.
|
|
912
|
+
// Returns the number of bytes written, EXCLUDING the null terminator.
|
|
913
|
+
|
|
914
|
+
function stringToUTF16(str, outPtr, maxBytesToWrite) {
|
|
915
|
+
// Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
|
|
916
|
+
if (maxBytesToWrite === undefined) {
|
|
917
|
+
maxBytesToWrite = 0x7FFFFFFF;
|
|
918
|
+
}
|
|
919
|
+
if (maxBytesToWrite < 2) return 0;
|
|
920
|
+
maxBytesToWrite -= 2; // Null terminator.
|
|
921
|
+
var startPtr = outPtr;
|
|
922
|
+
var numCharsToWrite = (maxBytesToWrite < str.length*2) ? (maxBytesToWrite / 2) : str.length;
|
|
923
|
+
for (var i = 0; i < numCharsToWrite; ++i) {
|
|
924
|
+
// charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP.
|
|
925
|
+
var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
|
|
926
|
+
HEAP16[((outPtr)>>1)]=codeUnit;
|
|
927
|
+
outPtr += 2;
|
|
928
|
+
}
|
|
929
|
+
// Null-terminate the pointer to the HEAP.
|
|
930
|
+
HEAP16[((outPtr)>>1)]=0;
|
|
931
|
+
return outPtr - startPtr;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte.
|
|
935
|
+
|
|
936
|
+
function lengthBytesUTF16(str) {
|
|
937
|
+
return str.length*2;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
function UTF32ToString(ptr, maxBytesToRead) {
|
|
941
|
+
var i = 0;
|
|
942
|
+
|
|
943
|
+
var str = '';
|
|
944
|
+
// If maxBytesToRead is not passed explicitly, it will be undefined, and this
|
|
945
|
+
// will always evaluate to true. This saves on code size.
|
|
946
|
+
while (!(i >= maxBytesToRead / 4)) {
|
|
947
|
+
var utf32 = HEAP32[(((ptr)+(i*4))>>2)];
|
|
948
|
+
if (utf32 == 0) break;
|
|
949
|
+
++i;
|
|
950
|
+
// 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.
|
|
951
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
952
|
+
if (utf32 >= 0x10000) {
|
|
953
|
+
var ch = utf32 - 0x10000;
|
|
954
|
+
str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
|
|
955
|
+
} else {
|
|
956
|
+
str += String.fromCharCode(utf32);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
return str;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
|
|
963
|
+
// null-terminated and encoded in UTF32 form. The copy will require at most str.length*4+4 bytes of space in the HEAP.
|
|
964
|
+
// Use the function lengthBytesUTF32() to compute the exact number of bytes (excluding null terminator) that this function will write.
|
|
965
|
+
// Parameters:
|
|
966
|
+
// str: the Javascript string to copy.
|
|
967
|
+
// outPtr: Byte address in Emscripten HEAP where to write the string to.
|
|
968
|
+
// maxBytesToWrite: The maximum number of bytes this function can write to the array. This count should include the null
|
|
969
|
+
// terminator, i.e. if maxBytesToWrite=4, only the null terminator will be written and nothing else.
|
|
970
|
+
// maxBytesToWrite<4 does not write any bytes to the output, not even the null terminator.
|
|
971
|
+
// Returns the number of bytes written, EXCLUDING the null terminator.
|
|
972
|
+
|
|
973
|
+
function stringToUTF32(str, outPtr, maxBytesToWrite) {
|
|
974
|
+
// Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
|
|
975
|
+
if (maxBytesToWrite === undefined) {
|
|
976
|
+
maxBytesToWrite = 0x7FFFFFFF;
|
|
977
|
+
}
|
|
978
|
+
if (maxBytesToWrite < 4) return 0;
|
|
979
|
+
var startPtr = outPtr;
|
|
980
|
+
var endPtr = startPtr + maxBytesToWrite - 4;
|
|
981
|
+
for (var i = 0; i < str.length; ++i) {
|
|
982
|
+
// 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.
|
|
983
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
984
|
+
var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
|
|
985
|
+
if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {
|
|
986
|
+
var trailSurrogate = str.charCodeAt(++i);
|
|
987
|
+
codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF);
|
|
988
|
+
}
|
|
989
|
+
HEAP32[((outPtr)>>2)]=codeUnit;
|
|
990
|
+
outPtr += 4;
|
|
991
|
+
if (outPtr + 4 > endPtr) break;
|
|
992
|
+
}
|
|
993
|
+
// Null-terminate the pointer to the HEAP.
|
|
994
|
+
HEAP32[((outPtr)>>2)]=0;
|
|
995
|
+
return outPtr - startPtr;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte.
|
|
999
|
+
|
|
1000
|
+
function lengthBytesUTF32(str) {
|
|
1001
|
+
var len = 0;
|
|
1002
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1003
|
+
// 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.
|
|
1004
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
1005
|
+
var codeUnit = str.charCodeAt(i);
|
|
1006
|
+
if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) ++i; // possibly a lead surrogate, so skip over the tail surrogate.
|
|
1007
|
+
len += 4;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
return len;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
// Allocate heap space for a JS string, and write it there.
|
|
1014
|
+
// It is the responsibility of the caller to free() that memory.
|
|
1015
|
+
function allocateUTF8(str) {
|
|
1016
|
+
var size = lengthBytesUTF8(str) + 1;
|
|
1017
|
+
var ret = _malloc(size);
|
|
1018
|
+
if (ret) stringToUTF8Array(str, HEAP8, ret, size);
|
|
1019
|
+
return ret;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
// Allocate stack space for a JS string, and write it there.
|
|
1023
|
+
function allocateUTF8OnStack(str) {
|
|
1024
|
+
var size = lengthBytesUTF8(str) + 1;
|
|
1025
|
+
var ret = stackAlloc(size);
|
|
1026
|
+
stringToUTF8Array(str, HEAP8, ret, size);
|
|
1027
|
+
return ret;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// Deprecated: This function should not be called because it is unsafe and does not provide
|
|
1031
|
+
// a maximum length limit of how many bytes it is allowed to write. Prefer calling the
|
|
1032
|
+
// function stringToUTF8Array() instead, which takes in a maximum length that can be used
|
|
1033
|
+
// to be secure from out of bounds writes.
|
|
1034
|
+
/** @deprecated
|
|
1035
|
+
@param {boolean=} dontAddNull */
|
|
1036
|
+
function writeStringToMemory(string, buffer, dontAddNull) {
|
|
1037
|
+
warnOnce('writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!');
|
|
1038
|
+
|
|
1039
|
+
var /** @type {number} */ lastChar, /** @type {number} */ end;
|
|
1040
|
+
if (dontAddNull) {
|
|
1041
|
+
// stringToUTF8Array always appends null. If we don't want to do that, remember the
|
|
1042
|
+
// character that existed at the location where the null will be placed, and restore
|
|
1043
|
+
// that after the write (below).
|
|
1044
|
+
end = buffer + lengthBytesUTF8(string);
|
|
1045
|
+
lastChar = HEAP8[end];
|
|
1046
|
+
}
|
|
1047
|
+
stringToUTF8(string, buffer, Infinity);
|
|
1048
|
+
if (dontAddNull) HEAP8[end] = lastChar; // Restore the value under the null character.
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
function writeArrayToMemory(array, buffer) {
|
|
1052
|
+
HEAP8.set(array, buffer);
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/** @param {boolean=} dontAddNull */
|
|
1056
|
+
function writeAsciiToMemory(str, buffer, dontAddNull) {
|
|
1057
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1058
|
+
HEAP8[((buffer++)>>0)]=str.charCodeAt(i);
|
|
1059
|
+
}
|
|
1060
|
+
// Null-terminate the pointer to the HEAP.
|
|
1061
|
+
if (!dontAddNull) HEAP8[((buffer)>>0)]=0;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
// end include: runtime_strings_extra.js
|
|
1065
|
+
// Memory management
|
|
1066
|
+
|
|
1067
|
+
function alignUp(x, multiple) {
|
|
1068
|
+
if (x % multiple > 0) {
|
|
1069
|
+
x += multiple - (x % multiple);
|
|
1070
|
+
}
|
|
1071
|
+
return x;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
var HEAP,
|
|
1075
|
+
/** @type {ArrayBuffer} */
|
|
1076
|
+
buffer,
|
|
1077
|
+
/** @type {Int8Array} */
|
|
1078
|
+
HEAP8,
|
|
1079
|
+
/** @type {Uint8Array} */
|
|
1080
|
+
HEAPU8,
|
|
1081
|
+
/** @type {Int16Array} */
|
|
1082
|
+
HEAP16,
|
|
1083
|
+
/** @type {Uint16Array} */
|
|
1084
|
+
HEAPU16,
|
|
1085
|
+
/** @type {Int32Array} */
|
|
1086
|
+
HEAP32,
|
|
1087
|
+
/** @type {Uint32Array} */
|
|
1088
|
+
HEAPU32,
|
|
1089
|
+
/** @type {Float32Array} */
|
|
1090
|
+
HEAPF32,
|
|
1091
|
+
/** @type {Float64Array} */
|
|
1092
|
+
HEAPF64;
|
|
1093
|
+
|
|
1094
|
+
function updateGlobalBufferAndViews(buf) {
|
|
1095
|
+
buffer = buf;
|
|
1096
|
+
Module['HEAP8'] = HEAP8 = new Int8Array(buf);
|
|
1097
|
+
Module['HEAP16'] = HEAP16 = new Int16Array(buf);
|
|
1098
|
+
Module['HEAP32'] = HEAP32 = new Int32Array(buf);
|
|
1099
|
+
Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf);
|
|
1100
|
+
Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf);
|
|
1101
|
+
Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf);
|
|
1102
|
+
Module['HEAPF32'] = HEAPF32 = new Float32Array(buf);
|
|
1103
|
+
Module['HEAPF64'] = HEAPF64 = new Float64Array(buf);
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
var TOTAL_STACK = 5242880;
|
|
1107
|
+
|
|
1108
|
+
var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 67108864;
|
|
1109
|
+
|
|
1110
|
+
// include: runtime_init_table.js
|
|
1111
|
+
// In regular non-RELOCATABLE mode the table is exported
|
|
1112
|
+
// from the wasm module and this will be assigned once
|
|
1113
|
+
// the exports are available.
|
|
1114
|
+
var wasmTable;
|
|
1115
|
+
|
|
1116
|
+
// end include: runtime_init_table.js
|
|
1117
|
+
// include: runtime_stack_check.js
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
// end include: runtime_stack_check.js
|
|
1121
|
+
// include: runtime_assertions.js
|
|
1122
|
+
|
|
1123
|
+
|
|
1124
|
+
// end include: runtime_assertions.js
|
|
1125
|
+
var __ATPRERUN__ = []; // functions called before the runtime is initialized
|
|
1126
|
+
var __ATINIT__ = []; // functions called during startup
|
|
1127
|
+
var __ATMAIN__ = []; // functions called when main() is to be run
|
|
1128
|
+
var __ATEXIT__ = []; // functions called during shutdown
|
|
1129
|
+
var __ATPOSTRUN__ = []; // functions called after the main() is called
|
|
1130
|
+
|
|
1131
|
+
var runtimeInitialized = false;
|
|
1132
|
+
var runtimeExited = false;
|
|
1133
|
+
|
|
1134
|
+
__ATINIT__.push({ func: function() { ___wasm_call_ctors() } });
|
|
1135
|
+
|
|
1136
|
+
function preRun() {
|
|
1137
|
+
|
|
1138
|
+
if (Module['preRun']) {
|
|
1139
|
+
if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
|
|
1140
|
+
while (Module['preRun'].length) {
|
|
1141
|
+
addOnPreRun(Module['preRun'].shift());
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
callRuntimeCallbacks(__ATPRERUN__);
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
function initRuntime() {
|
|
1149
|
+
runtimeInitialized = true;
|
|
1150
|
+
|
|
1151
|
+
callRuntimeCallbacks(__ATINIT__);
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
function preMain() {
|
|
1155
|
+
|
|
1156
|
+
callRuntimeCallbacks(__ATMAIN__);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
function exitRuntime() {
|
|
1160
|
+
runtimeExited = true;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
function postRun() {
|
|
1164
|
+
|
|
1165
|
+
if (Module['postRun']) {
|
|
1166
|
+
if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
|
|
1167
|
+
while (Module['postRun'].length) {
|
|
1168
|
+
addOnPostRun(Module['postRun'].shift());
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
callRuntimeCallbacks(__ATPOSTRUN__);
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
function addOnPreRun(cb) {
|
|
1176
|
+
__ATPRERUN__.unshift(cb);
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
function addOnInit(cb) {
|
|
1180
|
+
__ATINIT__.unshift(cb);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
function addOnPreMain(cb) {
|
|
1184
|
+
__ATMAIN__.unshift(cb);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
function addOnExit(cb) {
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
function addOnPostRun(cb) {
|
|
1191
|
+
__ATPOSTRUN__.unshift(cb);
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
// include: runtime_math.js
|
|
1195
|
+
|
|
1196
|
+
|
|
1197
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
|
|
1198
|
+
|
|
1199
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
|
|
1200
|
+
|
|
1201
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
|
|
1202
|
+
|
|
1203
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
|
|
1204
|
+
|
|
1205
|
+
// end include: runtime_math.js
|
|
1206
|
+
// A counter of dependencies for calling run(). If we need to
|
|
1207
|
+
// do asynchronous work before running, increment this and
|
|
1208
|
+
// decrement it. Incrementing must happen in a place like
|
|
1209
|
+
// Module.preRun (used by emcc to add file preloading).
|
|
1210
|
+
// Note that you can add dependencies in preRun, even though
|
|
1211
|
+
// it happens right before run - run will be postponed until
|
|
1212
|
+
// the dependencies are met.
|
|
1213
|
+
var runDependencies = 0;
|
|
1214
|
+
var runDependencyWatcher = null;
|
|
1215
|
+
var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
|
|
1216
|
+
|
|
1217
|
+
function getUniqueRunDependency(id) {
|
|
1218
|
+
return id;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
function addRunDependency(id) {
|
|
1222
|
+
runDependencies++;
|
|
1223
|
+
|
|
1224
|
+
if (Module['monitorRunDependencies']) {
|
|
1225
|
+
Module['monitorRunDependencies'](runDependencies);
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
function removeRunDependency(id) {
|
|
1231
|
+
runDependencies--;
|
|
1232
|
+
|
|
1233
|
+
if (Module['monitorRunDependencies']) {
|
|
1234
|
+
Module['monitorRunDependencies'](runDependencies);
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
if (runDependencies == 0) {
|
|
1238
|
+
if (runDependencyWatcher !== null) {
|
|
1239
|
+
clearInterval(runDependencyWatcher);
|
|
1240
|
+
runDependencyWatcher = null;
|
|
1241
|
+
}
|
|
1242
|
+
if (dependenciesFulfilled) {
|
|
1243
|
+
var callback = dependenciesFulfilled;
|
|
1244
|
+
dependenciesFulfilled = null;
|
|
1245
|
+
callback(); // can add another dependenciesFulfilled
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
Module["preloadedImages"] = {}; // maps url to image data
|
|
1251
|
+
Module["preloadedAudios"] = {}; // maps url to audio data
|
|
1252
|
+
|
|
1253
|
+
/** @param {string|number=} what */
|
|
1254
|
+
function abort(what) {
|
|
1255
|
+
if (Module['onAbort']) {
|
|
1256
|
+
Module['onAbort'](what);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
what += '';
|
|
1260
|
+
err(what);
|
|
1261
|
+
|
|
1262
|
+
ABORT = true;
|
|
1263
|
+
EXITSTATUS = 1;
|
|
1264
|
+
|
|
1265
|
+
what = 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.';
|
|
1266
|
+
|
|
1267
|
+
// Use a wasm runtime error, because a JS error might be seen as a foreign
|
|
1268
|
+
// exception, which means we'd run destructors on it. We need the error to
|
|
1269
|
+
// simply make the program stop.
|
|
1270
|
+
var e = new WebAssembly.RuntimeError(what);
|
|
1271
|
+
|
|
1272
|
+
readyPromiseReject(e);
|
|
1273
|
+
// Throw the error whether or not MODULARIZE is set because abort is used
|
|
1274
|
+
// in code paths apart from instantiation where an exception is expected
|
|
1275
|
+
// to be thrown when abort is called.
|
|
1276
|
+
throw e;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
// {{MEM_INITIALIZER}}
|
|
1280
|
+
|
|
1281
|
+
// include: memoryprofiler.js
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
// end include: memoryprofiler.js
|
|
1285
|
+
// include: URIUtils.js
|
|
1286
|
+
|
|
1287
|
+
|
|
1288
|
+
function hasPrefix(str, prefix) {
|
|
1289
|
+
return String.prototype.startsWith ?
|
|
1290
|
+
str.startsWith(prefix) :
|
|
1291
|
+
str.indexOf(prefix) === 0;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
// Prefix of data URIs emitted by SINGLE_FILE and related options.
|
|
1295
|
+
var dataURIPrefix = 'data:application/octet-stream;base64,';
|
|
1296
|
+
|
|
1297
|
+
// Indicates whether filename is a base64 data URI.
|
|
1298
|
+
function isDataURI(filename) {
|
|
1299
|
+
return hasPrefix(filename, dataURIPrefix);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
var fileURIPrefix = "file://";
|
|
1303
|
+
|
|
1304
|
+
// Indicates whether filename is delivered via file protocol (as opposed to http/https)
|
|
1305
|
+
function isFileURI(filename) {
|
|
1306
|
+
return hasPrefix(filename, fileURIPrefix);
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
// end include: URIUtils.js
|
|
1310
|
+
var wasmBinaryFile = 'libsvc-simd.wasm';
|
|
1311
|
+
if (!isDataURI(wasmBinaryFile)) {
|
|
1312
|
+
wasmBinaryFile = locateFile(wasmBinaryFile);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
function getBinary(file) {
|
|
1316
|
+
try {
|
|
1317
|
+
if (file == wasmBinaryFile && wasmBinary) {
|
|
1318
|
+
return new Uint8Array(wasmBinary);
|
|
1319
|
+
}
|
|
1320
|
+
if (readBinary) {
|
|
1321
|
+
return readBinary(file);
|
|
1322
|
+
} else {
|
|
1323
|
+
throw "both async and sync fetching of the wasm failed";
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
catch (err) {
|
|
1327
|
+
abort(err);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
function getBinaryPromise() {
|
|
1332
|
+
if ((typeof __wxjs_environment !== 'undefined' && __wxjs_environment === 'miniprogram') || typeof worker !== 'undefined') {
|
|
1333
|
+
return Promise.resolve(wasmBinary || wasmBinaryFile);
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
// If we don't have the binary yet, try to to load it asynchronously.
|
|
1337
|
+
// Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
|
|
1338
|
+
// See https://github.com/github/fetch/pull/92#issuecomment-140665932
|
|
1339
|
+
// Cordova or Electron apps are typically loaded from a file:// url.
|
|
1340
|
+
// So use fetch if it is available and the url is not a file, otherwise fall back to XHR.
|
|
1341
|
+
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
|
|
1342
|
+
if (typeof fetch === 'function'
|
|
1343
|
+
&& !isFileURI(wasmBinaryFile)
|
|
1344
|
+
) {
|
|
1345
|
+
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
|
|
1346
|
+
if (!response['ok']) {
|
|
1347
|
+
throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
|
|
1348
|
+
}
|
|
1349
|
+
return response['arrayBuffer']();
|
|
1350
|
+
}).catch(function () {
|
|
1351
|
+
return getBinary(wasmBinaryFile);
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
else {
|
|
1355
|
+
if (readAsync) {
|
|
1356
|
+
// fetch is not available or url is file => try XHR (readAsync uses XHR internally)
|
|
1357
|
+
return new Promise(function(resolve, reject) {
|
|
1358
|
+
readAsync(wasmBinaryFile, function(response) { resolve(new Uint8Array(/** @type{!ArrayBuffer} */(response))) }, reject)
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
// Otherwise, getBinary should be able to get it synchronously
|
|
1365
|
+
return Promise.resolve().then(function() { return getBinary(wasmBinaryFile); });
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
// Create the wasm instance.
|
|
1369
|
+
// Receives the wasm imports, returns the exports.
|
|
1370
|
+
function createWasm() {
|
|
1371
|
+
// prepare imports
|
|
1372
|
+
var info = {
|
|
1373
|
+
'env': asmLibraryArg,
|
|
1374
|
+
'wasi_snapshot_preview1': asmLibraryArg,
|
|
1375
|
+
};
|
|
1376
|
+
// Load the wasm module and create an instance of using native support in the JS engine.
|
|
1377
|
+
// handle a generated wasm instance, receiving its exports and
|
|
1378
|
+
// performing other necessary setup
|
|
1379
|
+
/** @param {WebAssembly.Module=} module*/
|
|
1380
|
+
function receiveInstance(instance, module) {
|
|
1381
|
+
var exports = instance.exports;
|
|
1382
|
+
|
|
1383
|
+
Module['asm'] = exports;
|
|
1384
|
+
|
|
1385
|
+
wasmMemory = Module['asm']['memory'];
|
|
1386
|
+
updateGlobalBufferAndViews(wasmMemory.buffer);
|
|
1387
|
+
|
|
1388
|
+
wasmTable = Module['asm']['__indirect_function_table'];
|
|
1389
|
+
|
|
1390
|
+
removeRunDependency('wasm-instantiate');
|
|
1391
|
+
}
|
|
1392
|
+
// we can't run yet (except in a pthread, where we have a custom sync instantiator)
|
|
1393
|
+
addRunDependency('wasm-instantiate');
|
|
1394
|
+
|
|
1395
|
+
function receiveInstantiatedSource(output) {
|
|
1396
|
+
// 'output' is a WebAssemblyInstantiatedSource object which has both the module and instance.
|
|
1397
|
+
// receiveInstance() will swap in the exports (to Module.asm) so they can be called
|
|
1398
|
+
// 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.
|
|
1399
|
+
// When the regression is fixed, can restore the above USE_PTHREADS-enabled path.
|
|
1400
|
+
receiveInstance(output['instance']);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
function instantiateArrayBuffer(receiver) {
|
|
1404
|
+
return getBinaryPromise().then(function(binary) {
|
|
1405
|
+
return WebAssembly.instantiate(binary, info);
|
|
1406
|
+
}).then(receiver, function(reason) {
|
|
1407
|
+
err('failed to asynchronously prepare wasm: ' + reason);
|
|
1408
|
+
|
|
1409
|
+
abort(reason);
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
// Prefer streaming instantiation if available.
|
|
1414
|
+
function instantiateAsync() {
|
|
1415
|
+
if (!wasmBinary &&
|
|
1416
|
+
typeof WebAssembly.instantiateStreaming === 'function' &&
|
|
1417
|
+
!isDataURI(wasmBinaryFile) &&
|
|
1418
|
+
// Don't use streaming for file:// delivered objects in a webview, fetch them synchronously.
|
|
1419
|
+
!isFileURI(wasmBinaryFile) &&
|
|
1420
|
+
typeof fetch === 'function') {
|
|
1421
|
+
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function (response) {
|
|
1422
|
+
var result = WebAssembly.instantiateStreaming(response, info);
|
|
1423
|
+
return result.then(receiveInstantiatedSource, function(reason) {
|
|
1424
|
+
// We expect the most common failure cause to be a bad MIME type for the binary,
|
|
1425
|
+
// in which case falling back to ArrayBuffer instantiation should work.
|
|
1426
|
+
err('wasm streaming compile failed: ' + reason);
|
|
1427
|
+
err('falling back to ArrayBuffer instantiation');
|
|
1428
|
+
return instantiateArrayBuffer(receiveInstantiatedSource);
|
|
1429
|
+
});
|
|
1430
|
+
});
|
|
1431
|
+
} else {
|
|
1432
|
+
return instantiateArrayBuffer(receiveInstantiatedSource);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
|
|
1437
|
+
// to manually instantiate the Wasm module themselves. This allows pages to run the instantiation parallel
|
|
1438
|
+
// to any other async startup actions they are performing.
|
|
1439
|
+
if (Module['instantiateWasm']) {
|
|
1440
|
+
try {
|
|
1441
|
+
var exports = Module['instantiateWasm'](info, receiveInstance);
|
|
1442
|
+
return exports;
|
|
1443
|
+
} catch(e) {
|
|
1444
|
+
err('Module.instantiateWasm callback failed with error: ' + e);
|
|
1445
|
+
return false;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
// If instantiation fails, reject the module ready promise.
|
|
1450
|
+
instantiateAsync().catch(readyPromiseReject);
|
|
1451
|
+
return {}; // no exports yet; we'll fill them in later
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// Globals used by JS i64 conversions (see makeSetValue)
|
|
1455
|
+
var tempDouble;
|
|
1456
|
+
var tempI64;
|
|
1457
|
+
|
|
1458
|
+
// === Body ===
|
|
1459
|
+
|
|
1460
|
+
var ASM_CONSTS = {
|
|
1461
|
+
|
|
1462
|
+
};
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
|
|
1466
|
+
|
|
1467
|
+
|
|
1468
|
+
|
|
1469
|
+
function callRuntimeCallbacks(callbacks) {
|
|
1470
|
+
while(callbacks.length > 0) {
|
|
1471
|
+
var callback = callbacks.shift();
|
|
1472
|
+
if (typeof callback == 'function') {
|
|
1473
|
+
callback(Module); // Pass the module as the first argument.
|
|
1474
|
+
continue;
|
|
1475
|
+
}
|
|
1476
|
+
var func = callback.func;
|
|
1477
|
+
if (typeof func === 'number') {
|
|
1478
|
+
if (callback.arg === undefined) {
|
|
1479
|
+
wasmTable.get(func)();
|
|
1480
|
+
} else {
|
|
1481
|
+
wasmTable.get(func)(callback.arg);
|
|
1482
|
+
}
|
|
1483
|
+
} else {
|
|
1484
|
+
func(callback.arg === undefined ? null : callback.arg);
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
function demangle(func) {
|
|
1490
|
+
return func;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
function demangleAll(text) {
|
|
1494
|
+
var regex =
|
|
1495
|
+
/\b_Z[\w\d_]+/g;
|
|
1496
|
+
return text.replace(regex,
|
|
1497
|
+
function(x) {
|
|
1498
|
+
var y = demangle(x);
|
|
1499
|
+
return x === y ? x : (y + ' [' + x + ']');
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
function jsStackTrace() {
|
|
1504
|
+
var error = new Error();
|
|
1505
|
+
if (!error.stack) {
|
|
1506
|
+
// IE10+ special cases: It does have callstack info, but it is only populated if an Error object is thrown,
|
|
1507
|
+
// so try that as a special-case.
|
|
1508
|
+
try {
|
|
1509
|
+
throw new Error();
|
|
1510
|
+
} catch(e) {
|
|
1511
|
+
error = e;
|
|
1512
|
+
}
|
|
1513
|
+
if (!error.stack) {
|
|
1514
|
+
return '(no stack trace available)';
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
return error.stack.toString();
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
function stackTrace() {
|
|
1521
|
+
var js = jsStackTrace();
|
|
1522
|
+
if (Module['extraStackTrace']) js += '\n' + Module['extraStackTrace']();
|
|
1523
|
+
return demangleAll(js);
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
function ___assert_fail(condition, filename, line, func) {
|
|
1527
|
+
abort('Assertion failed: ' + UTF8ToString(condition) + ', at: ' + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']);
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
function _atexit(func, arg) {
|
|
1531
|
+
}
|
|
1532
|
+
function ___cxa_atexit(a0,a1
|
|
1533
|
+
) {
|
|
1534
|
+
return _atexit(a0,a1);
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
var SYSCALLS={mappings:{},buffers:[null,[],[]],printChar:function(stream, curr) {
|
|
1538
|
+
var buffer = SYSCALLS.buffers[stream];
|
|
1539
|
+
if (curr === 0 || curr === 10) {
|
|
1540
|
+
(stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
|
|
1541
|
+
buffer.length = 0;
|
|
1542
|
+
} else {
|
|
1543
|
+
buffer.push(curr);
|
|
1544
|
+
}
|
|
1545
|
+
},varargs:undefined,get:function() {
|
|
1546
|
+
SYSCALLS.varargs += 4;
|
|
1547
|
+
var ret = HEAP32[(((SYSCALLS.varargs)-(4))>>2)];
|
|
1548
|
+
return ret;
|
|
1549
|
+
},getStr:function(ptr) {
|
|
1550
|
+
var ret = UTF8ToString(ptr);
|
|
1551
|
+
return ret;
|
|
1552
|
+
},get64:function(low, high) {
|
|
1553
|
+
return low;
|
|
1554
|
+
}};
|
|
1555
|
+
function ___sys_access(path, amode) {
|
|
1556
|
+
path = SYSCALLS.getStr(path);
|
|
1557
|
+
return SYSCALLS.doAccess(path, amode);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
function setErrNo(value) {
|
|
1561
|
+
HEAP32[((___errno_location())>>2)]=value;
|
|
1562
|
+
return value;
|
|
1563
|
+
}
|
|
1564
|
+
function ___sys_fcntl64(fd, cmd, varargs) {SYSCALLS.varargs = varargs;
|
|
1565
|
+
|
|
1566
|
+
return 0;
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
function ___sys_fstat64(fd, buf) {
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
function ___sys_getpid() {
|
|
1573
|
+
return 42;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
function ___sys_ioctl(fd, op, varargs) {SYSCALLS.varargs = varargs;
|
|
1577
|
+
|
|
1578
|
+
return 0;
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
function ___sys_madvise1(addr, length, advice) {
|
|
1582
|
+
return 0; // advice is welcome, but ignored
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
function ___sys_nice(inc) {
|
|
1586
|
+
return -63; // no meaning to nice for our single-process environment
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
function ___sys_open(path, flags, varargs) {SYSCALLS.varargs = varargs;
|
|
1590
|
+
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
function ___sys_rename(old_path, new_path) {
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
function ___sys_stat64(path, buf) {
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
var tupleRegistrations={};
|
|
1600
|
+
|
|
1601
|
+
function runDestructors(destructors) {
|
|
1602
|
+
while (destructors.length) {
|
|
1603
|
+
var ptr = destructors.pop();
|
|
1604
|
+
var del = destructors.pop();
|
|
1605
|
+
del(ptr);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
function simpleReadValueFromPointer(pointer) {
|
|
1610
|
+
return this['fromWireType'](HEAPU32[pointer >> 2]);
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
var awaitingDependencies={};
|
|
1614
|
+
|
|
1615
|
+
var registeredTypes={};
|
|
1616
|
+
|
|
1617
|
+
var typeDependencies={};
|
|
1618
|
+
|
|
1619
|
+
var char_0=48;
|
|
1620
|
+
|
|
1621
|
+
var char_9=57;
|
|
1622
|
+
function makeLegalFunctionName(name) {
|
|
1623
|
+
if (undefined === name) {
|
|
1624
|
+
return '_unknown';
|
|
1625
|
+
}
|
|
1626
|
+
name = name.replace(/[^a-zA-Z0-9_]/g, '$');
|
|
1627
|
+
var f = name.charCodeAt(0);
|
|
1628
|
+
if (f >= char_0 && f <= char_9) {
|
|
1629
|
+
return '_' + name;
|
|
1630
|
+
} else {
|
|
1631
|
+
return name;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
function createNamedFunction(name, body) {
|
|
1635
|
+
return body;
|
|
1636
|
+
}
|
|
1637
|
+
function extendError(baseErrorType, errorName) {
|
|
1638
|
+
var errorClass = createNamedFunction(errorName, function(message) {
|
|
1639
|
+
this.name = errorName;
|
|
1640
|
+
this.message = message;
|
|
1641
|
+
|
|
1642
|
+
var stack = (new Error(message)).stack;
|
|
1643
|
+
if (stack !== undefined) {
|
|
1644
|
+
this.stack = this.toString() + '\n' +
|
|
1645
|
+
stack.replace(/^Error(:[^\n]*)?\n/, '');
|
|
1646
|
+
}
|
|
1647
|
+
});
|
|
1648
|
+
errorClass.prototype = Object.create(baseErrorType.prototype);
|
|
1649
|
+
errorClass.prototype.constructor = errorClass;
|
|
1650
|
+
errorClass.prototype.toString = function() {
|
|
1651
|
+
if (this.message === undefined) {
|
|
1652
|
+
return this.name;
|
|
1653
|
+
} else {
|
|
1654
|
+
return this.name + ': ' + this.message;
|
|
1655
|
+
}
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
return errorClass;
|
|
1659
|
+
}
|
|
1660
|
+
var InternalError=undefined;
|
|
1661
|
+
function throwInternalError(message) {
|
|
1662
|
+
throw new InternalError(message);
|
|
1663
|
+
}
|
|
1664
|
+
function whenDependentTypesAreResolved(myTypes, dependentTypes, getTypeConverters) {
|
|
1665
|
+
myTypes.forEach(function(type) {
|
|
1666
|
+
typeDependencies[type] = dependentTypes;
|
|
1667
|
+
});
|
|
1668
|
+
|
|
1669
|
+
function onComplete(typeConverters) {
|
|
1670
|
+
var myTypeConverters = getTypeConverters(typeConverters);
|
|
1671
|
+
if (myTypeConverters.length !== myTypes.length) {
|
|
1672
|
+
throwInternalError('Mismatched type converter count');
|
|
1673
|
+
}
|
|
1674
|
+
for (var i = 0; i < myTypes.length; ++i) {
|
|
1675
|
+
registerType(myTypes[i], myTypeConverters[i]);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
var typeConverters = new Array(dependentTypes.length);
|
|
1680
|
+
var unregisteredTypes = [];
|
|
1681
|
+
var registered = 0;
|
|
1682
|
+
dependentTypes.forEach(function(dt, i) {
|
|
1683
|
+
if (registeredTypes.hasOwnProperty(dt)) {
|
|
1684
|
+
typeConverters[i] = registeredTypes[dt];
|
|
1685
|
+
} else {
|
|
1686
|
+
unregisteredTypes.push(dt);
|
|
1687
|
+
if (!awaitingDependencies.hasOwnProperty(dt)) {
|
|
1688
|
+
awaitingDependencies[dt] = [];
|
|
1689
|
+
}
|
|
1690
|
+
awaitingDependencies[dt].push(function() {
|
|
1691
|
+
typeConverters[i] = registeredTypes[dt];
|
|
1692
|
+
++registered;
|
|
1693
|
+
if (registered === unregisteredTypes.length) {
|
|
1694
|
+
onComplete(typeConverters);
|
|
1695
|
+
}
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
});
|
|
1699
|
+
if (0 === unregisteredTypes.length) {
|
|
1700
|
+
onComplete(typeConverters);
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
function __embind_finalize_value_array(rawTupleType) {
|
|
1704
|
+
var reg = tupleRegistrations[rawTupleType];
|
|
1705
|
+
delete tupleRegistrations[rawTupleType];
|
|
1706
|
+
var elements = reg.elements;
|
|
1707
|
+
var elementsLength = elements.length;
|
|
1708
|
+
var elementTypes = elements.map(function(elt) { return elt.getterReturnType; }).
|
|
1709
|
+
concat(elements.map(function(elt) { return elt.setterArgumentType; }));
|
|
1710
|
+
|
|
1711
|
+
var rawConstructor = reg.rawConstructor;
|
|
1712
|
+
var rawDestructor = reg.rawDestructor;
|
|
1713
|
+
|
|
1714
|
+
whenDependentTypesAreResolved([rawTupleType], elementTypes, function(elementTypes) {
|
|
1715
|
+
elements.forEach(function(elt, i) {
|
|
1716
|
+
var getterReturnType = elementTypes[i];
|
|
1717
|
+
var getter = elt.getter;
|
|
1718
|
+
var getterContext = elt.getterContext;
|
|
1719
|
+
var setterArgumentType = elementTypes[i + elementsLength];
|
|
1720
|
+
var setter = elt.setter;
|
|
1721
|
+
var setterContext = elt.setterContext;
|
|
1722
|
+
elt.read = function(ptr) {
|
|
1723
|
+
return getterReturnType['fromWireType'](getter(getterContext, ptr));
|
|
1724
|
+
};
|
|
1725
|
+
elt.write = function(ptr, o) {
|
|
1726
|
+
var destructors = [];
|
|
1727
|
+
setter(setterContext, ptr, setterArgumentType['toWireType'](destructors, o));
|
|
1728
|
+
runDestructors(destructors);
|
|
1729
|
+
};
|
|
1730
|
+
});
|
|
1731
|
+
|
|
1732
|
+
return [{
|
|
1733
|
+
name: reg.name,
|
|
1734
|
+
'fromWireType': function(ptr) {
|
|
1735
|
+
var rv = new Array(elementsLength);
|
|
1736
|
+
for (var i = 0; i < elementsLength; ++i) {
|
|
1737
|
+
rv[i] = elements[i].read(ptr);
|
|
1738
|
+
}
|
|
1739
|
+
rawDestructor(ptr);
|
|
1740
|
+
return rv;
|
|
1741
|
+
},
|
|
1742
|
+
'toWireType': function(destructors, o) {
|
|
1743
|
+
if (elementsLength !== o.length) {
|
|
1744
|
+
throw new TypeError("Incorrect number of tuple elements for " + reg.name + ": expected=" + elementsLength + ", actual=" + o.length);
|
|
1745
|
+
}
|
|
1746
|
+
var ptr = rawConstructor();
|
|
1747
|
+
for (var i = 0; i < elementsLength; ++i) {
|
|
1748
|
+
elements[i].write(ptr, o[i]);
|
|
1749
|
+
}
|
|
1750
|
+
if (destructors !== null) {
|
|
1751
|
+
destructors.push(rawDestructor, ptr);
|
|
1752
|
+
}
|
|
1753
|
+
return ptr;
|
|
1754
|
+
},
|
|
1755
|
+
'argPackAdvance': 8,
|
|
1756
|
+
'readValueFromPointer': simpleReadValueFromPointer,
|
|
1757
|
+
destructorFunction: rawDestructor,
|
|
1758
|
+
}];
|
|
1759
|
+
});
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
var structRegistrations={};
|
|
1763
|
+
function __embind_finalize_value_object(structType) {
|
|
1764
|
+
var reg = structRegistrations[structType];
|
|
1765
|
+
delete structRegistrations[structType];
|
|
1766
|
+
|
|
1767
|
+
var rawConstructor = reg.rawConstructor;
|
|
1768
|
+
var rawDestructor = reg.rawDestructor;
|
|
1769
|
+
var fieldRecords = reg.fields;
|
|
1770
|
+
var fieldTypes = fieldRecords.map(function(field) { return field.getterReturnType; }).
|
|
1771
|
+
concat(fieldRecords.map(function(field) { return field.setterArgumentType; }));
|
|
1772
|
+
whenDependentTypesAreResolved([structType], fieldTypes, function(fieldTypes) {
|
|
1773
|
+
var fields = {};
|
|
1774
|
+
fieldRecords.forEach(function(field, i) {
|
|
1775
|
+
var fieldName = field.fieldName;
|
|
1776
|
+
var getterReturnType = fieldTypes[i];
|
|
1777
|
+
var getter = field.getter;
|
|
1778
|
+
var getterContext = field.getterContext;
|
|
1779
|
+
var setterArgumentType = fieldTypes[i + fieldRecords.length];
|
|
1780
|
+
var setter = field.setter;
|
|
1781
|
+
var setterContext = field.setterContext;
|
|
1782
|
+
fields[fieldName] = {
|
|
1783
|
+
read: function(ptr) {
|
|
1784
|
+
return getterReturnType['fromWireType'](
|
|
1785
|
+
getter(getterContext, ptr));
|
|
1786
|
+
},
|
|
1787
|
+
write: function(ptr, o) {
|
|
1788
|
+
var destructors = [];
|
|
1789
|
+
setter(setterContext, ptr, setterArgumentType['toWireType'](destructors, o));
|
|
1790
|
+
runDestructors(destructors);
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
});
|
|
1794
|
+
|
|
1795
|
+
return [{
|
|
1796
|
+
name: reg.name,
|
|
1797
|
+
'fromWireType': function(ptr) {
|
|
1798
|
+
var rv = {};
|
|
1799
|
+
for (var i in fields) {
|
|
1800
|
+
rv[i] = fields[i].read(ptr);
|
|
1801
|
+
}
|
|
1802
|
+
rawDestructor(ptr);
|
|
1803
|
+
return rv;
|
|
1804
|
+
},
|
|
1805
|
+
'toWireType': function(destructors, o) {
|
|
1806
|
+
// todo: Here we have an opportunity for -O3 level "unsafe" optimizations:
|
|
1807
|
+
// assume all fields are present without checking.
|
|
1808
|
+
for (var fieldName in fields) {
|
|
1809
|
+
if (!(fieldName in o)) {
|
|
1810
|
+
throw new TypeError('Missing field: "' + fieldName + '"');
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
var ptr = rawConstructor();
|
|
1814
|
+
for (fieldName in fields) {
|
|
1815
|
+
fields[fieldName].write(ptr, o[fieldName]);
|
|
1816
|
+
}
|
|
1817
|
+
if (destructors !== null) {
|
|
1818
|
+
destructors.push(rawDestructor, ptr);
|
|
1819
|
+
}
|
|
1820
|
+
return ptr;
|
|
1821
|
+
},
|
|
1822
|
+
'argPackAdvance': 8,
|
|
1823
|
+
'readValueFromPointer': simpleReadValueFromPointer,
|
|
1824
|
+
destructorFunction: rawDestructor,
|
|
1825
|
+
}];
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
function getShiftFromSize(size) {
|
|
1830
|
+
switch (size) {
|
|
1831
|
+
case 1: return 0;
|
|
1832
|
+
case 2: return 1;
|
|
1833
|
+
case 4: return 2;
|
|
1834
|
+
case 8: return 3;
|
|
1835
|
+
default:
|
|
1836
|
+
throw new TypeError('Unknown type size: ' + size);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
function embind_init_charCodes() {
|
|
1841
|
+
var codes = new Array(256);
|
|
1842
|
+
for (var i = 0; i < 256; ++i) {
|
|
1843
|
+
codes[i] = String.fromCharCode(i);
|
|
1844
|
+
}
|
|
1845
|
+
embind_charCodes = codes;
|
|
1846
|
+
}
|
|
1847
|
+
var embind_charCodes=undefined;
|
|
1848
|
+
function readLatin1String(ptr) {
|
|
1849
|
+
var ret = "";
|
|
1850
|
+
var c = ptr;
|
|
1851
|
+
while (HEAPU8[c]) {
|
|
1852
|
+
ret += embind_charCodes[HEAPU8[c++]];
|
|
1853
|
+
}
|
|
1854
|
+
return ret;
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
var BindingError=undefined;
|
|
1858
|
+
function throwBindingError(message) {
|
|
1859
|
+
throw new BindingError(message);
|
|
1860
|
+
}
|
|
1861
|
+
/** @param {Object=} options */
|
|
1862
|
+
function registerType(rawType, registeredInstance, options) {
|
|
1863
|
+
options = options || {};
|
|
1864
|
+
|
|
1865
|
+
if (!('argPackAdvance' in registeredInstance)) {
|
|
1866
|
+
throw new TypeError('registerType registeredInstance requires argPackAdvance');
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
var name = registeredInstance.name;
|
|
1870
|
+
if (!rawType) {
|
|
1871
|
+
throwBindingError('type "' + name + '" must have a positive integer typeid pointer');
|
|
1872
|
+
}
|
|
1873
|
+
if (registeredTypes.hasOwnProperty(rawType)) {
|
|
1874
|
+
if (options.ignoreDuplicateRegistrations) {
|
|
1875
|
+
return;
|
|
1876
|
+
} else {
|
|
1877
|
+
throwBindingError("Cannot register type '" + name + "' twice");
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
registeredTypes[rawType] = registeredInstance;
|
|
1882
|
+
delete typeDependencies[rawType];
|
|
1883
|
+
|
|
1884
|
+
if (awaitingDependencies.hasOwnProperty(rawType)) {
|
|
1885
|
+
var callbacks = awaitingDependencies[rawType];
|
|
1886
|
+
delete awaitingDependencies[rawType];
|
|
1887
|
+
callbacks.forEach(function(cb) {
|
|
1888
|
+
cb();
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
function __embind_register_bool(rawType, name, size, trueValue, falseValue) {
|
|
1893
|
+
var shift = getShiftFromSize(size);
|
|
1894
|
+
|
|
1895
|
+
name = readLatin1String(name);
|
|
1896
|
+
registerType(rawType, {
|
|
1897
|
+
name: name,
|
|
1898
|
+
'fromWireType': function(wt) {
|
|
1899
|
+
// ambiguous emscripten ABI: sometimes return values are
|
|
1900
|
+
// true or false, and sometimes integers (0 or 1)
|
|
1901
|
+
return !!wt;
|
|
1902
|
+
},
|
|
1903
|
+
'toWireType': function(destructors, o) {
|
|
1904
|
+
return o ? trueValue : falseValue;
|
|
1905
|
+
},
|
|
1906
|
+
'argPackAdvance': 8,
|
|
1907
|
+
'readValueFromPointer': function(pointer) {
|
|
1908
|
+
// TODO: if heap is fixed (like in asm.js) this could be executed outside
|
|
1909
|
+
var heap;
|
|
1910
|
+
if (size === 1) {
|
|
1911
|
+
heap = HEAP8;
|
|
1912
|
+
} else if (size === 2) {
|
|
1913
|
+
heap = HEAP16;
|
|
1914
|
+
} else if (size === 4) {
|
|
1915
|
+
heap = HEAP32;
|
|
1916
|
+
} else {
|
|
1917
|
+
throw new TypeError("Unknown boolean type size: " + name);
|
|
1918
|
+
}
|
|
1919
|
+
return this['fromWireType'](heap[pointer >> shift]);
|
|
1920
|
+
},
|
|
1921
|
+
destructorFunction: null, // This type does not need a destructor
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
function ClassHandle_isAliasOf(other) {
|
|
1926
|
+
if (!(this instanceof ClassHandle)) {
|
|
1927
|
+
return false;
|
|
1928
|
+
}
|
|
1929
|
+
if (!(other instanceof ClassHandle)) {
|
|
1930
|
+
return false;
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
var leftClass = this.$$.ptrType.registeredClass;
|
|
1934
|
+
var left = this.$$.ptr;
|
|
1935
|
+
var rightClass = other.$$.ptrType.registeredClass;
|
|
1936
|
+
var right = other.$$.ptr;
|
|
1937
|
+
|
|
1938
|
+
while (leftClass.baseClass) {
|
|
1939
|
+
left = leftClass.upcast(left);
|
|
1940
|
+
leftClass = leftClass.baseClass;
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
while (rightClass.baseClass) {
|
|
1944
|
+
right = rightClass.upcast(right);
|
|
1945
|
+
rightClass = rightClass.baseClass;
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
return leftClass === rightClass && left === right;
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
function shallowCopyInternalPointer(o) {
|
|
1952
|
+
return {
|
|
1953
|
+
count: o.count,
|
|
1954
|
+
deleteScheduled: o.deleteScheduled,
|
|
1955
|
+
preservePointerOnDelete: o.preservePointerOnDelete,
|
|
1956
|
+
ptr: o.ptr,
|
|
1957
|
+
ptrType: o.ptrType,
|
|
1958
|
+
smartPtr: o.smartPtr,
|
|
1959
|
+
smartPtrType: o.smartPtrType,
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
function throwInstanceAlreadyDeleted(obj) {
|
|
1964
|
+
function getInstanceTypeName(handle) {
|
|
1965
|
+
return handle.$$.ptrType.registeredClass.name;
|
|
1966
|
+
}
|
|
1967
|
+
throwBindingError(getInstanceTypeName(obj) + ' instance already deleted');
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
var finalizationGroup=false;
|
|
1971
|
+
|
|
1972
|
+
function detachFinalizer(handle) {}
|
|
1973
|
+
|
|
1974
|
+
function runDestructor($$) {
|
|
1975
|
+
if ($$.smartPtr) {
|
|
1976
|
+
$$.smartPtrType.rawDestructor($$.smartPtr);
|
|
1977
|
+
} else {
|
|
1978
|
+
$$.ptrType.registeredClass.rawDestructor($$.ptr);
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
function releaseClassHandle($$) {
|
|
1982
|
+
$$.count.value -= 1;
|
|
1983
|
+
var toDelete = 0 === $$.count.value;
|
|
1984
|
+
if (toDelete) {
|
|
1985
|
+
runDestructor($$);
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
function attachFinalizer(handle) {
|
|
1989
|
+
if ('undefined' === typeof FinalizationGroup) {
|
|
1990
|
+
attachFinalizer = function (handle) { return handle; };
|
|
1991
|
+
return handle;
|
|
1992
|
+
}
|
|
1993
|
+
// If the running environment has a FinalizationGroup (see
|
|
1994
|
+
// https://github.com/tc39/proposal-weakrefs), then attach finalizers
|
|
1995
|
+
// for class handles. We check for the presence of FinalizationGroup
|
|
1996
|
+
// at run-time, not build-time.
|
|
1997
|
+
finalizationGroup = new FinalizationGroup(function (iter) {
|
|
1998
|
+
for (var result = iter.next(); !result.done; result = iter.next()) {
|
|
1999
|
+
var $$ = result.value;
|
|
2000
|
+
if (!$$.ptr) {
|
|
2001
|
+
console.warn('object already deleted: ' + $$.ptr);
|
|
2002
|
+
} else {
|
|
2003
|
+
releaseClassHandle($$);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
});
|
|
2007
|
+
attachFinalizer = function(handle) {
|
|
2008
|
+
finalizationGroup.register(handle, handle.$$, handle.$$);
|
|
2009
|
+
return handle;
|
|
2010
|
+
};
|
|
2011
|
+
detachFinalizer = function(handle) {
|
|
2012
|
+
finalizationGroup.unregister(handle.$$);
|
|
2013
|
+
};
|
|
2014
|
+
return attachFinalizer(handle);
|
|
2015
|
+
}
|
|
2016
|
+
function ClassHandle_clone() {
|
|
2017
|
+
if (!this.$$.ptr) {
|
|
2018
|
+
throwInstanceAlreadyDeleted(this);
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
if (this.$$.preservePointerOnDelete) {
|
|
2022
|
+
this.$$.count.value += 1;
|
|
2023
|
+
return this;
|
|
2024
|
+
} else {
|
|
2025
|
+
var clone = attachFinalizer(Object.create(Object.getPrototypeOf(this), {
|
|
2026
|
+
$$: {
|
|
2027
|
+
value: shallowCopyInternalPointer(this.$$),
|
|
2028
|
+
}
|
|
2029
|
+
}));
|
|
2030
|
+
|
|
2031
|
+
clone.$$.count.value += 1;
|
|
2032
|
+
clone.$$.deleteScheduled = false;
|
|
2033
|
+
return clone;
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
function ClassHandle_delete() {
|
|
2038
|
+
if (!this.$$.ptr) {
|
|
2039
|
+
throwInstanceAlreadyDeleted(this);
|
|
2040
|
+
}
|
|
2041
|
+
|
|
2042
|
+
if (this.$$.deleteScheduled && !this.$$.preservePointerOnDelete) {
|
|
2043
|
+
throwBindingError('Object already scheduled for deletion');
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
detachFinalizer(this);
|
|
2047
|
+
releaseClassHandle(this.$$);
|
|
2048
|
+
|
|
2049
|
+
if (!this.$$.preservePointerOnDelete) {
|
|
2050
|
+
this.$$.smartPtr = undefined;
|
|
2051
|
+
this.$$.ptr = undefined;
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
function ClassHandle_isDeleted() {
|
|
2056
|
+
return !this.$$.ptr;
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
var delayFunction=undefined;
|
|
2060
|
+
|
|
2061
|
+
var deletionQueue=[];
|
|
2062
|
+
|
|
2063
|
+
function flushPendingDeletes() {
|
|
2064
|
+
while (deletionQueue.length) {
|
|
2065
|
+
var obj = deletionQueue.pop();
|
|
2066
|
+
obj.$$.deleteScheduled = false;
|
|
2067
|
+
obj['delete']();
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
function ClassHandle_deleteLater() {
|
|
2071
|
+
if (!this.$$.ptr) {
|
|
2072
|
+
throwInstanceAlreadyDeleted(this);
|
|
2073
|
+
}
|
|
2074
|
+
if (this.$$.deleteScheduled && !this.$$.preservePointerOnDelete) {
|
|
2075
|
+
throwBindingError('Object already scheduled for deletion');
|
|
2076
|
+
}
|
|
2077
|
+
deletionQueue.push(this);
|
|
2078
|
+
if (deletionQueue.length === 1 && delayFunction) {
|
|
2079
|
+
delayFunction(flushPendingDeletes);
|
|
2080
|
+
}
|
|
2081
|
+
this.$$.deleteScheduled = true;
|
|
2082
|
+
return this;
|
|
2083
|
+
}
|
|
2084
|
+
function init_ClassHandle() {
|
|
2085
|
+
ClassHandle.prototype['isAliasOf'] = ClassHandle_isAliasOf;
|
|
2086
|
+
ClassHandle.prototype['clone'] = ClassHandle_clone;
|
|
2087
|
+
ClassHandle.prototype['delete'] = ClassHandle_delete;
|
|
2088
|
+
ClassHandle.prototype['isDeleted'] = ClassHandle_isDeleted;
|
|
2089
|
+
ClassHandle.prototype['deleteLater'] = ClassHandle_deleteLater;
|
|
2090
|
+
}
|
|
2091
|
+
function ClassHandle() {
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
var registeredPointers={};
|
|
2095
|
+
|
|
2096
|
+
function ensureOverloadTable(proto, methodName, humanName) {
|
|
2097
|
+
if (undefined === proto[methodName].overloadTable) {
|
|
2098
|
+
var prevFunc = proto[methodName];
|
|
2099
|
+
// Inject an overload resolver function that routes to the appropriate overload based on the number of arguments.
|
|
2100
|
+
proto[methodName] = function() {
|
|
2101
|
+
// TODO This check can be removed in -O3 level "unsafe" optimizations.
|
|
2102
|
+
if (!proto[methodName].overloadTable.hasOwnProperty(arguments.length)) {
|
|
2103
|
+
throwBindingError("Function '" + humanName + "' called with an invalid number of arguments (" + arguments.length + ") - expects one of (" + proto[methodName].overloadTable + ")!");
|
|
2104
|
+
}
|
|
2105
|
+
return proto[methodName].overloadTable[arguments.length].apply(this, arguments);
|
|
2106
|
+
};
|
|
2107
|
+
// Move the previous function into the overload table.
|
|
2108
|
+
proto[methodName].overloadTable = [];
|
|
2109
|
+
proto[methodName].overloadTable[prevFunc.argCount] = prevFunc;
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
/** @param {number=} numArguments */
|
|
2113
|
+
function exposePublicSymbol(name, value, numArguments) {
|
|
2114
|
+
if (Module.hasOwnProperty(name)) {
|
|
2115
|
+
if (undefined === numArguments || (undefined !== Module[name].overloadTable && undefined !== Module[name].overloadTable[numArguments])) {
|
|
2116
|
+
throwBindingError("Cannot register public name '" + name + "' twice");
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
// We are exposing a function with the same name as an existing function. Create an overload table and a function selector
|
|
2120
|
+
// that routes between the two.
|
|
2121
|
+
ensureOverloadTable(Module, name, name);
|
|
2122
|
+
if (Module.hasOwnProperty(numArguments)) {
|
|
2123
|
+
throwBindingError("Cannot register multiple overloads of a function with the same number of arguments (" + numArguments + ")!");
|
|
2124
|
+
}
|
|
2125
|
+
// Add the new function into the overload table.
|
|
2126
|
+
Module[name].overloadTable[numArguments] = value;
|
|
2127
|
+
}
|
|
2128
|
+
else {
|
|
2129
|
+
Module[name] = value;
|
|
2130
|
+
if (undefined !== numArguments) {
|
|
2131
|
+
Module[name].numArguments = numArguments;
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
/** @constructor */
|
|
2137
|
+
function RegisteredClass(
|
|
2138
|
+
name,
|
|
2139
|
+
constructor,
|
|
2140
|
+
instancePrototype,
|
|
2141
|
+
rawDestructor,
|
|
2142
|
+
baseClass,
|
|
2143
|
+
getActualType,
|
|
2144
|
+
upcast,
|
|
2145
|
+
downcast
|
|
2146
|
+
) {
|
|
2147
|
+
this.name = name;
|
|
2148
|
+
this.constructor = constructor;
|
|
2149
|
+
this.instancePrototype = instancePrototype;
|
|
2150
|
+
this.rawDestructor = rawDestructor;
|
|
2151
|
+
this.baseClass = baseClass;
|
|
2152
|
+
this.getActualType = getActualType;
|
|
2153
|
+
this.upcast = upcast;
|
|
2154
|
+
this.downcast = downcast;
|
|
2155
|
+
this.pureVirtualFunctions = [];
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
function upcastPointer(ptr, ptrClass, desiredClass) {
|
|
2159
|
+
while (ptrClass !== desiredClass) {
|
|
2160
|
+
if (!ptrClass.upcast) {
|
|
2161
|
+
throwBindingError("Expected null or instance of " + desiredClass.name + ", got an instance of " + ptrClass.name);
|
|
2162
|
+
}
|
|
2163
|
+
ptr = ptrClass.upcast(ptr);
|
|
2164
|
+
ptrClass = ptrClass.baseClass;
|
|
2165
|
+
}
|
|
2166
|
+
return ptr;
|
|
2167
|
+
}
|
|
2168
|
+
function constNoSmartPtrRawPointerToWireType(destructors, handle) {
|
|
2169
|
+
if (handle === null) {
|
|
2170
|
+
if (this.isReference) {
|
|
2171
|
+
throwBindingError('null is not a valid ' + this.name);
|
|
2172
|
+
}
|
|
2173
|
+
return 0;
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
if (!handle.$$) {
|
|
2177
|
+
throwBindingError('Cannot pass "' + _embind_repr(handle) + '" as a ' + this.name);
|
|
2178
|
+
}
|
|
2179
|
+
if (!handle.$$.ptr) {
|
|
2180
|
+
throwBindingError('Cannot pass deleted object as a pointer of type ' + this.name);
|
|
2181
|
+
}
|
|
2182
|
+
var handleClass = handle.$$.ptrType.registeredClass;
|
|
2183
|
+
var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
|
|
2184
|
+
return ptr;
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
function genericPointerToWireType(destructors, handle) {
|
|
2188
|
+
var ptr;
|
|
2189
|
+
if (handle === null) {
|
|
2190
|
+
if (this.isReference) {
|
|
2191
|
+
throwBindingError('null is not a valid ' + this.name);
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
if (this.isSmartPointer) {
|
|
2195
|
+
ptr = this.rawConstructor();
|
|
2196
|
+
if (destructors !== null) {
|
|
2197
|
+
destructors.push(this.rawDestructor, ptr);
|
|
2198
|
+
}
|
|
2199
|
+
return ptr;
|
|
2200
|
+
} else {
|
|
2201
|
+
return 0;
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
if (!handle.$$) {
|
|
2206
|
+
throwBindingError('Cannot pass "' + _embind_repr(handle) + '" as a ' + this.name);
|
|
2207
|
+
}
|
|
2208
|
+
if (!handle.$$.ptr) {
|
|
2209
|
+
throwBindingError('Cannot pass deleted object as a pointer of type ' + this.name);
|
|
2210
|
+
}
|
|
2211
|
+
if (!this.isConst && handle.$$.ptrType.isConst) {
|
|
2212
|
+
throwBindingError('Cannot convert argument of type ' + (handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name) + ' to parameter type ' + this.name);
|
|
2213
|
+
}
|
|
2214
|
+
var handleClass = handle.$$.ptrType.registeredClass;
|
|
2215
|
+
ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
|
|
2216
|
+
|
|
2217
|
+
if (this.isSmartPointer) {
|
|
2218
|
+
// TODO: this is not strictly true
|
|
2219
|
+
// We could support BY_EMVAL conversions from raw pointers to smart pointers
|
|
2220
|
+
// because the smart pointer can hold a reference to the handle
|
|
2221
|
+
if (undefined === handle.$$.smartPtr) {
|
|
2222
|
+
throwBindingError('Passing raw pointer to smart pointer is illegal');
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
switch (this.sharingPolicy) {
|
|
2226
|
+
case 0: // NONE
|
|
2227
|
+
// no upcasting
|
|
2228
|
+
if (handle.$$.smartPtrType === this) {
|
|
2229
|
+
ptr = handle.$$.smartPtr;
|
|
2230
|
+
} else {
|
|
2231
|
+
throwBindingError('Cannot convert argument of type ' + (handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name) + ' to parameter type ' + this.name);
|
|
2232
|
+
}
|
|
2233
|
+
break;
|
|
2234
|
+
|
|
2235
|
+
case 1: // INTRUSIVE
|
|
2236
|
+
ptr = handle.$$.smartPtr;
|
|
2237
|
+
break;
|
|
2238
|
+
|
|
2239
|
+
case 2: // BY_EMVAL
|
|
2240
|
+
if (handle.$$.smartPtrType === this) {
|
|
2241
|
+
ptr = handle.$$.smartPtr;
|
|
2242
|
+
} else {
|
|
2243
|
+
var clonedHandle = handle['clone']();
|
|
2244
|
+
ptr = this.rawShare(
|
|
2245
|
+
ptr,
|
|
2246
|
+
__emval_register(function() {
|
|
2247
|
+
clonedHandle['delete']();
|
|
2248
|
+
})
|
|
2249
|
+
);
|
|
2250
|
+
if (destructors !== null) {
|
|
2251
|
+
destructors.push(this.rawDestructor, ptr);
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
break;
|
|
2255
|
+
|
|
2256
|
+
default:
|
|
2257
|
+
throwBindingError('Unsupporting sharing policy');
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
return ptr;
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
function nonConstNoSmartPtrRawPointerToWireType(destructors, handle) {
|
|
2264
|
+
if (handle === null) {
|
|
2265
|
+
if (this.isReference) {
|
|
2266
|
+
throwBindingError('null is not a valid ' + this.name);
|
|
2267
|
+
}
|
|
2268
|
+
return 0;
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
if (!handle.$$) {
|
|
2272
|
+
throwBindingError('Cannot pass "' + _embind_repr(handle) + '" as a ' + this.name);
|
|
2273
|
+
}
|
|
2274
|
+
if (!handle.$$.ptr) {
|
|
2275
|
+
throwBindingError('Cannot pass deleted object as a pointer of type ' + this.name);
|
|
2276
|
+
}
|
|
2277
|
+
if (handle.$$.ptrType.isConst) {
|
|
2278
|
+
throwBindingError('Cannot convert argument of type ' + handle.$$.ptrType.name + ' to parameter type ' + this.name);
|
|
2279
|
+
}
|
|
2280
|
+
var handleClass = handle.$$.ptrType.registeredClass;
|
|
2281
|
+
var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
|
|
2282
|
+
return ptr;
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
function RegisteredPointer_getPointee(ptr) {
|
|
2286
|
+
if (this.rawGetPointee) {
|
|
2287
|
+
ptr = this.rawGetPointee(ptr);
|
|
2288
|
+
}
|
|
2289
|
+
return ptr;
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
function RegisteredPointer_destructor(ptr) {
|
|
2293
|
+
if (this.rawDestructor) {
|
|
2294
|
+
this.rawDestructor(ptr);
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
function RegisteredPointer_deleteObject(handle) {
|
|
2299
|
+
if (handle !== null) {
|
|
2300
|
+
handle['delete']();
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
function downcastPointer(ptr, ptrClass, desiredClass) {
|
|
2305
|
+
if (ptrClass === desiredClass) {
|
|
2306
|
+
return ptr;
|
|
2307
|
+
}
|
|
2308
|
+
if (undefined === desiredClass.baseClass) {
|
|
2309
|
+
return null; // no conversion
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
var rv = downcastPointer(ptr, ptrClass, desiredClass.baseClass);
|
|
2313
|
+
if (rv === null) {
|
|
2314
|
+
return null;
|
|
2315
|
+
}
|
|
2316
|
+
return desiredClass.downcast(rv);
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
function getInheritedInstanceCount() {
|
|
2320
|
+
return Object.keys(registeredInstances).length;
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
function getLiveInheritedInstances() {
|
|
2324
|
+
var rv = [];
|
|
2325
|
+
for (var k in registeredInstances) {
|
|
2326
|
+
if (registeredInstances.hasOwnProperty(k)) {
|
|
2327
|
+
rv.push(registeredInstances[k]);
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
return rv;
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
function setDelayFunction(fn) {
|
|
2334
|
+
delayFunction = fn;
|
|
2335
|
+
if (deletionQueue.length && delayFunction) {
|
|
2336
|
+
delayFunction(flushPendingDeletes);
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
function init_embind() {
|
|
2340
|
+
Module['getInheritedInstanceCount'] = getInheritedInstanceCount;
|
|
2341
|
+
Module['getLiveInheritedInstances'] = getLiveInheritedInstances;
|
|
2342
|
+
Module['flushPendingDeletes'] = flushPendingDeletes;
|
|
2343
|
+
Module['setDelayFunction'] = setDelayFunction;
|
|
2344
|
+
}
|
|
2345
|
+
var registeredInstances={};
|
|
2346
|
+
|
|
2347
|
+
function getBasestPointer(class_, ptr) {
|
|
2348
|
+
if (ptr === undefined) {
|
|
2349
|
+
throwBindingError('ptr should not be undefined');
|
|
2350
|
+
}
|
|
2351
|
+
while (class_.baseClass) {
|
|
2352
|
+
ptr = class_.upcast(ptr);
|
|
2353
|
+
class_ = class_.baseClass;
|
|
2354
|
+
}
|
|
2355
|
+
return ptr;
|
|
2356
|
+
}
|
|
2357
|
+
function getInheritedInstance(class_, ptr) {
|
|
2358
|
+
ptr = getBasestPointer(class_, ptr);
|
|
2359
|
+
return registeredInstances[ptr];
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
function makeClassHandle(prototype, record) {
|
|
2363
|
+
if (!record.ptrType || !record.ptr) {
|
|
2364
|
+
throwInternalError('makeClassHandle requires ptr and ptrType');
|
|
2365
|
+
}
|
|
2366
|
+
var hasSmartPtrType = !!record.smartPtrType;
|
|
2367
|
+
var hasSmartPtr = !!record.smartPtr;
|
|
2368
|
+
if (hasSmartPtrType !== hasSmartPtr) {
|
|
2369
|
+
throwInternalError('Both smartPtrType and smartPtr must be specified');
|
|
2370
|
+
}
|
|
2371
|
+
record.count = { value: 1 };
|
|
2372
|
+
return attachFinalizer(Object.create(prototype, {
|
|
2373
|
+
$$: {
|
|
2374
|
+
value: record,
|
|
2375
|
+
},
|
|
2376
|
+
}));
|
|
2377
|
+
}
|
|
2378
|
+
function RegisteredPointer_fromWireType(ptr) {
|
|
2379
|
+
// ptr is a raw pointer (or a raw smartpointer)
|
|
2380
|
+
|
|
2381
|
+
// rawPointer is a maybe-null raw pointer
|
|
2382
|
+
var rawPointer = this.getPointee(ptr);
|
|
2383
|
+
if (!rawPointer) {
|
|
2384
|
+
this.destructor(ptr);
|
|
2385
|
+
return null;
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
var registeredInstance = getInheritedInstance(this.registeredClass, rawPointer);
|
|
2389
|
+
if (undefined !== registeredInstance) {
|
|
2390
|
+
// JS object has been neutered, time to repopulate it
|
|
2391
|
+
if (0 === registeredInstance.$$.count.value) {
|
|
2392
|
+
registeredInstance.$$.ptr = rawPointer;
|
|
2393
|
+
registeredInstance.$$.smartPtr = ptr;
|
|
2394
|
+
return registeredInstance['clone']();
|
|
2395
|
+
} else {
|
|
2396
|
+
// else, just increment reference count on existing object
|
|
2397
|
+
// it already has a reference to the smart pointer
|
|
2398
|
+
var rv = registeredInstance['clone']();
|
|
2399
|
+
this.destructor(ptr);
|
|
2400
|
+
return rv;
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
function makeDefaultHandle() {
|
|
2405
|
+
if (this.isSmartPointer) {
|
|
2406
|
+
return makeClassHandle(this.registeredClass.instancePrototype, {
|
|
2407
|
+
ptrType: this.pointeeType,
|
|
2408
|
+
ptr: rawPointer,
|
|
2409
|
+
smartPtrType: this,
|
|
2410
|
+
smartPtr: ptr,
|
|
2411
|
+
});
|
|
2412
|
+
} else {
|
|
2413
|
+
return makeClassHandle(this.registeredClass.instancePrototype, {
|
|
2414
|
+
ptrType: this,
|
|
2415
|
+
ptr: ptr,
|
|
2416
|
+
});
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
var actualType = this.registeredClass.getActualType(rawPointer);
|
|
2421
|
+
var registeredPointerRecord = registeredPointers[actualType];
|
|
2422
|
+
if (!registeredPointerRecord) {
|
|
2423
|
+
return makeDefaultHandle.call(this);
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
var toType;
|
|
2427
|
+
if (this.isConst) {
|
|
2428
|
+
toType = registeredPointerRecord.constPointerType;
|
|
2429
|
+
} else {
|
|
2430
|
+
toType = registeredPointerRecord.pointerType;
|
|
2431
|
+
}
|
|
2432
|
+
var dp = downcastPointer(
|
|
2433
|
+
rawPointer,
|
|
2434
|
+
this.registeredClass,
|
|
2435
|
+
toType.registeredClass);
|
|
2436
|
+
if (dp === null) {
|
|
2437
|
+
return makeDefaultHandle.call(this);
|
|
2438
|
+
}
|
|
2439
|
+
if (this.isSmartPointer) {
|
|
2440
|
+
return makeClassHandle(toType.registeredClass.instancePrototype, {
|
|
2441
|
+
ptrType: toType,
|
|
2442
|
+
ptr: dp,
|
|
2443
|
+
smartPtrType: this,
|
|
2444
|
+
smartPtr: ptr,
|
|
2445
|
+
});
|
|
2446
|
+
} else {
|
|
2447
|
+
return makeClassHandle(toType.registeredClass.instancePrototype, {
|
|
2448
|
+
ptrType: toType,
|
|
2449
|
+
ptr: dp,
|
|
2450
|
+
});
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
function init_RegisteredPointer() {
|
|
2454
|
+
RegisteredPointer.prototype.getPointee = RegisteredPointer_getPointee;
|
|
2455
|
+
RegisteredPointer.prototype.destructor = RegisteredPointer_destructor;
|
|
2456
|
+
RegisteredPointer.prototype['argPackAdvance'] = 8;
|
|
2457
|
+
RegisteredPointer.prototype['readValueFromPointer'] = simpleReadValueFromPointer;
|
|
2458
|
+
RegisteredPointer.prototype['deleteObject'] = RegisteredPointer_deleteObject;
|
|
2459
|
+
RegisteredPointer.prototype['fromWireType'] = RegisteredPointer_fromWireType;
|
|
2460
|
+
}
|
|
2461
|
+
/** @constructor
|
|
2462
|
+
@param {*=} pointeeType,
|
|
2463
|
+
@param {*=} sharingPolicy,
|
|
2464
|
+
@param {*=} rawGetPointee,
|
|
2465
|
+
@param {*=} rawConstructor,
|
|
2466
|
+
@param {*=} rawShare,
|
|
2467
|
+
@param {*=} rawDestructor,
|
|
2468
|
+
*/
|
|
2469
|
+
function RegisteredPointer(
|
|
2470
|
+
name,
|
|
2471
|
+
registeredClass,
|
|
2472
|
+
isReference,
|
|
2473
|
+
isConst,
|
|
2474
|
+
|
|
2475
|
+
// smart pointer properties
|
|
2476
|
+
isSmartPointer,
|
|
2477
|
+
pointeeType,
|
|
2478
|
+
sharingPolicy,
|
|
2479
|
+
rawGetPointee,
|
|
2480
|
+
rawConstructor,
|
|
2481
|
+
rawShare,
|
|
2482
|
+
rawDestructor
|
|
2483
|
+
) {
|
|
2484
|
+
this.name = name;
|
|
2485
|
+
this.registeredClass = registeredClass;
|
|
2486
|
+
this.isReference = isReference;
|
|
2487
|
+
this.isConst = isConst;
|
|
2488
|
+
|
|
2489
|
+
// smart pointer properties
|
|
2490
|
+
this.isSmartPointer = isSmartPointer;
|
|
2491
|
+
this.pointeeType = pointeeType;
|
|
2492
|
+
this.sharingPolicy = sharingPolicy;
|
|
2493
|
+
this.rawGetPointee = rawGetPointee;
|
|
2494
|
+
this.rawConstructor = rawConstructor;
|
|
2495
|
+
this.rawShare = rawShare;
|
|
2496
|
+
this.rawDestructor = rawDestructor;
|
|
2497
|
+
|
|
2498
|
+
if (!isSmartPointer && registeredClass.baseClass === undefined) {
|
|
2499
|
+
if (isConst) {
|
|
2500
|
+
this['toWireType'] = constNoSmartPtrRawPointerToWireType;
|
|
2501
|
+
this.destructorFunction = null;
|
|
2502
|
+
} else {
|
|
2503
|
+
this['toWireType'] = nonConstNoSmartPtrRawPointerToWireType;
|
|
2504
|
+
this.destructorFunction = null;
|
|
2505
|
+
}
|
|
2506
|
+
} else {
|
|
2507
|
+
this['toWireType'] = genericPointerToWireType;
|
|
2508
|
+
// Here we must leave this.destructorFunction undefined, since whether genericPointerToWireType returns
|
|
2509
|
+
// a pointer that needs to be freed up is runtime-dependent, and cannot be evaluated at registration time.
|
|
2510
|
+
// TODO: Create an alternative mechanism that allows removing the use of var destructors = []; array in
|
|
2511
|
+
// craftInvokerFunction altogether.
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
/** @param {number=} numArguments */
|
|
2516
|
+
function replacePublicSymbol(name, value, numArguments) {
|
|
2517
|
+
if (!Module.hasOwnProperty(name)) {
|
|
2518
|
+
throwInternalError('Replacing nonexistant public symbol');
|
|
2519
|
+
}
|
|
2520
|
+
// If there's an overload table for this symbol, replace the symbol in the overload table instead.
|
|
2521
|
+
if (undefined !== Module[name].overloadTable && undefined !== numArguments) {
|
|
2522
|
+
Module[name].overloadTable[numArguments] = value;
|
|
2523
|
+
}
|
|
2524
|
+
else {
|
|
2525
|
+
Module[name] = value;
|
|
2526
|
+
Module[name].argCount = numArguments;
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
function dynCallLegacy(sig, ptr, args) {
|
|
2531
|
+
if (args && args.length) {
|
|
2532
|
+
return Module['dynCall_' + sig].apply(null, [ptr].concat(args));
|
|
2533
|
+
}
|
|
2534
|
+
return Module['dynCall_' + sig].call(null, ptr);
|
|
2535
|
+
}
|
|
2536
|
+
function dynCall(sig, ptr, args) {
|
|
2537
|
+
// Without WASM_BIGINT support we cannot directly call function with i64 as
|
|
2538
|
+
// part of thier signature, so we rely the dynCall functions generated by
|
|
2539
|
+
// wasm-emscripten-finalize
|
|
2540
|
+
if (sig.indexOf('j') != -1) {
|
|
2541
|
+
return dynCallLegacy(sig, ptr, args);
|
|
2542
|
+
}
|
|
2543
|
+
return wasmTable.get(ptr).apply(null, args)
|
|
2544
|
+
}
|
|
2545
|
+
function getDynCaller(sig, ptr) {
|
|
2546
|
+
assert(sig.indexOf('j') >= 0, 'getDynCaller should only be called with i64 sigs')
|
|
2547
|
+
var argCache = [];
|
|
2548
|
+
return function() {
|
|
2549
|
+
argCache.length = arguments.length;
|
|
2550
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
2551
|
+
argCache[i] = arguments[i];
|
|
2552
|
+
}
|
|
2553
|
+
return dynCall(sig, ptr, argCache);
|
|
2554
|
+
};
|
|
2555
|
+
}
|
|
2556
|
+
function embind__requireFunction(signature, rawFunction) {
|
|
2557
|
+
signature = readLatin1String(signature);
|
|
2558
|
+
|
|
2559
|
+
function makeDynCaller() {
|
|
2560
|
+
if (signature.indexOf('j') != -1) {
|
|
2561
|
+
return getDynCaller(signature, rawFunction);
|
|
2562
|
+
}
|
|
2563
|
+
return wasmTable.get(rawFunction);
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
var fp = makeDynCaller();
|
|
2567
|
+
if (typeof fp !== "function") {
|
|
2568
|
+
throwBindingError("unknown function pointer with signature " + signature + ": " + rawFunction);
|
|
2569
|
+
}
|
|
2570
|
+
return fp;
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
var UnboundTypeError=undefined;
|
|
2574
|
+
|
|
2575
|
+
function getTypeName(type) {
|
|
2576
|
+
var ptr = ___getTypeName(type);
|
|
2577
|
+
var rv = readLatin1String(ptr);
|
|
2578
|
+
_free(ptr);
|
|
2579
|
+
return rv;
|
|
2580
|
+
}
|
|
2581
|
+
function throwUnboundTypeError(message, types) {
|
|
2582
|
+
var unboundTypes = [];
|
|
2583
|
+
var seen = {};
|
|
2584
|
+
function visit(type) {
|
|
2585
|
+
if (seen[type]) {
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2588
|
+
if (registeredTypes[type]) {
|
|
2589
|
+
return;
|
|
2590
|
+
}
|
|
2591
|
+
if (typeDependencies[type]) {
|
|
2592
|
+
typeDependencies[type].forEach(visit);
|
|
2593
|
+
return;
|
|
2594
|
+
}
|
|
2595
|
+
unboundTypes.push(type);
|
|
2596
|
+
seen[type] = true;
|
|
2597
|
+
}
|
|
2598
|
+
types.forEach(visit);
|
|
2599
|
+
|
|
2600
|
+
throw new UnboundTypeError(message + ': ' + unboundTypes.map(getTypeName).join([', ']));
|
|
2601
|
+
}
|
|
2602
|
+
function __embind_register_class(
|
|
2603
|
+
rawType,
|
|
2604
|
+
rawPointerType,
|
|
2605
|
+
rawConstPointerType,
|
|
2606
|
+
baseClassRawType,
|
|
2607
|
+
getActualTypeSignature,
|
|
2608
|
+
getActualType,
|
|
2609
|
+
upcastSignature,
|
|
2610
|
+
upcast,
|
|
2611
|
+
downcastSignature,
|
|
2612
|
+
downcast,
|
|
2613
|
+
name,
|
|
2614
|
+
destructorSignature,
|
|
2615
|
+
rawDestructor
|
|
2616
|
+
) {
|
|
2617
|
+
name = readLatin1String(name);
|
|
2618
|
+
getActualType = embind__requireFunction(getActualTypeSignature, getActualType);
|
|
2619
|
+
if (upcast) {
|
|
2620
|
+
upcast = embind__requireFunction(upcastSignature, upcast);
|
|
2621
|
+
}
|
|
2622
|
+
if (downcast) {
|
|
2623
|
+
downcast = embind__requireFunction(downcastSignature, downcast);
|
|
2624
|
+
}
|
|
2625
|
+
rawDestructor = embind__requireFunction(destructorSignature, rawDestructor);
|
|
2626
|
+
var legalFunctionName = makeLegalFunctionName(name);
|
|
2627
|
+
|
|
2628
|
+
exposePublicSymbol(legalFunctionName, function() {
|
|
2629
|
+
// this code cannot run if baseClassRawType is zero
|
|
2630
|
+
throwUnboundTypeError('Cannot construct ' + name + ' due to unbound types', [baseClassRawType]);
|
|
2631
|
+
});
|
|
2632
|
+
|
|
2633
|
+
whenDependentTypesAreResolved(
|
|
2634
|
+
[rawType, rawPointerType, rawConstPointerType],
|
|
2635
|
+
baseClassRawType ? [baseClassRawType] : [],
|
|
2636
|
+
function(base) {
|
|
2637
|
+
base = base[0];
|
|
2638
|
+
|
|
2639
|
+
var baseClass;
|
|
2640
|
+
var basePrototype;
|
|
2641
|
+
if (baseClassRawType) {
|
|
2642
|
+
baseClass = base.registeredClass;
|
|
2643
|
+
basePrototype = baseClass.instancePrototype;
|
|
2644
|
+
} else {
|
|
2645
|
+
basePrototype = ClassHandle.prototype;
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
var constructor = createNamedFunction(legalFunctionName, function() {
|
|
2649
|
+
if (Object.getPrototypeOf(this) !== instancePrototype) {
|
|
2650
|
+
throw new BindingError("Use 'new' to construct " + name);
|
|
2651
|
+
}
|
|
2652
|
+
if (undefined === registeredClass.constructor_body) {
|
|
2653
|
+
throw new BindingError(name + " has no accessible constructor");
|
|
2654
|
+
}
|
|
2655
|
+
var body = registeredClass.constructor_body[arguments.length];
|
|
2656
|
+
if (undefined === body) {
|
|
2657
|
+
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!");
|
|
2658
|
+
}
|
|
2659
|
+
return body.apply(this, arguments);
|
|
2660
|
+
});
|
|
2661
|
+
|
|
2662
|
+
var instancePrototype = Object.create(basePrototype, {
|
|
2663
|
+
constructor: { value: constructor },
|
|
2664
|
+
});
|
|
2665
|
+
|
|
2666
|
+
constructor.prototype = instancePrototype;
|
|
2667
|
+
|
|
2668
|
+
var registeredClass = new RegisteredClass(
|
|
2669
|
+
name,
|
|
2670
|
+
constructor,
|
|
2671
|
+
instancePrototype,
|
|
2672
|
+
rawDestructor,
|
|
2673
|
+
baseClass,
|
|
2674
|
+
getActualType,
|
|
2675
|
+
upcast,
|
|
2676
|
+
downcast);
|
|
2677
|
+
|
|
2678
|
+
var referenceConverter = new RegisteredPointer(
|
|
2679
|
+
name,
|
|
2680
|
+
registeredClass,
|
|
2681
|
+
true,
|
|
2682
|
+
false,
|
|
2683
|
+
false);
|
|
2684
|
+
|
|
2685
|
+
var pointerConverter = new RegisteredPointer(
|
|
2686
|
+
name + '*',
|
|
2687
|
+
registeredClass,
|
|
2688
|
+
false,
|
|
2689
|
+
false,
|
|
2690
|
+
false);
|
|
2691
|
+
|
|
2692
|
+
var constPointerConverter = new RegisteredPointer(
|
|
2693
|
+
name + ' const*',
|
|
2694
|
+
registeredClass,
|
|
2695
|
+
false,
|
|
2696
|
+
true,
|
|
2697
|
+
false);
|
|
2698
|
+
|
|
2699
|
+
registeredPointers[rawType] = {
|
|
2700
|
+
pointerType: pointerConverter,
|
|
2701
|
+
constPointerType: constPointerConverter
|
|
2702
|
+
};
|
|
2703
|
+
|
|
2704
|
+
replacePublicSymbol(legalFunctionName, constructor);
|
|
2705
|
+
|
|
2706
|
+
return [referenceConverter, pointerConverter, constPointerConverter];
|
|
2707
|
+
}
|
|
2708
|
+
);
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
function new_(constructor, argumentList) {
|
|
2712
|
+
if (!(constructor instanceof Function)) {
|
|
2713
|
+
throw new TypeError('new_ called with constructor type ' + typeof(constructor) + " which is not a function");
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
/*
|
|
2717
|
+
* Previously, the following line was just:
|
|
2718
|
+
|
|
2719
|
+
function dummy() {};
|
|
2720
|
+
|
|
2721
|
+
* Unfortunately, Chrome was preserving 'dummy' as the object's name, even though at creation, the 'dummy' has the
|
|
2722
|
+
* correct constructor name. Thus, objects created with IMVU.new would show up in the debugger as 'dummy', which
|
|
2723
|
+
* isn't very helpful. Using IMVU.createNamedFunction addresses the issue. Doublely-unfortunately, there's no way
|
|
2724
|
+
* to write a test for this behavior. -NRD 2013.02.22
|
|
2725
|
+
*/
|
|
2726
|
+
var dummy = createNamedFunction(constructor.name || 'unknownFunctionName', function(){});
|
|
2727
|
+
dummy.prototype = constructor.prototype;
|
|
2728
|
+
var obj = new dummy;
|
|
2729
|
+
|
|
2730
|
+
var r = constructor.apply(obj, argumentList);
|
|
2731
|
+
return (r instanceof Object) ? r : obj;
|
|
2732
|
+
}
|
|
2733
|
+
function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cppTargetFunc) {
|
|
2734
|
+
// humanName: a human-readable string name for the function to be generated.
|
|
2735
|
+
// argTypes: An array that contains the embind type objects for all types in the function signature.
|
|
2736
|
+
// argTypes[0] is the type object for the function return value.
|
|
2737
|
+
// argTypes[1] is the type object for function this object/class type, or null if not crafting an invoker for a class method.
|
|
2738
|
+
// argTypes[2...] are the actual function parameters.
|
|
2739
|
+
// classType: The embind type object for the class to be bound, or null if this is not a method of a class.
|
|
2740
|
+
// cppInvokerFunc: JS Function object to the C++-side function that interops into C++ code.
|
|
2741
|
+
// cppTargetFunc: Function pointer (an integer to FUNCTION_TABLE) to the target C++ function the cppInvokerFunc will end up calling.
|
|
2742
|
+
var argCount = argTypes.length;
|
|
2743
|
+
|
|
2744
|
+
if (argCount < 2) {
|
|
2745
|
+
throwBindingError("argTypes array size mismatch! Must at least get return value and 'this' types!");
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
var isClassMethodFunc = (argTypes[1] !== null && classType !== null);
|
|
2749
|
+
|
|
2750
|
+
var needsDestructorStack = false;
|
|
2751
|
+
|
|
2752
|
+
for(var i = 1; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here.
|
|
2753
|
+
if (argTypes[i] !== null && argTypes[i]['destructorFunction'] === undefined) { // The type does not define a destructor function - must use dynamic stack
|
|
2754
|
+
needsDestructorStack = true;
|
|
2755
|
+
break;
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
|
|
2759
|
+
var returns = (argTypes[0].name !== "void");
|
|
2760
|
+
|
|
2761
|
+
var invoker = cppInvokerFunc;
|
|
2762
|
+
var fn = cppTargetFunc;
|
|
2763
|
+
var retType = argTypes[0];
|
|
2764
|
+
var classParam = argTypes[1];
|
|
2765
|
+
|
|
2766
|
+
return function craftInvoker() {
|
|
2767
|
+
if (arguments.length !== argCount - 2) {
|
|
2768
|
+
throwBindingError(`function ${humanName} called with ${arguments.length} arguments, expected "${argCount - 2}" args!`);
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
var destructors = [];
|
|
2772
|
+
var dtorStack = needsDestructorStack ? destructors : null;
|
|
2773
|
+
|
|
2774
|
+
var thisWired;
|
|
2775
|
+
var argsWired = [];
|
|
2776
|
+
|
|
2777
|
+
if (isClassMethodFunc) {
|
|
2778
|
+
thisWired = classParam['toWireType'](dtorStack, this);
|
|
2779
|
+
argsWired.push(thisWired);
|
|
2780
|
+
}
|
|
2781
|
+
|
|
2782
|
+
for(var i = 0; i < argCount - 2; ++i) {
|
|
2783
|
+
argsWired.push(argTypes[i + 2]['toWireType'](dtorStack, arguments[i]));
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2786
|
+
var rv = invoker(fn, ...argsWired);
|
|
2787
|
+
|
|
2788
|
+
if (needsDestructorStack) {
|
|
2789
|
+
runDestructors(destructors);
|
|
2790
|
+
} else {
|
|
2791
|
+
var from = isClassMethodFunc ? 1 : 2;
|
|
2792
|
+
for(var i = from; i < argCount; ++i) { // Skip return value at index 0 - it's not deleted here. Also skip class type if not a method.
|
|
2793
|
+
var dtor = argTypes[i]['destructorFunction'];
|
|
2794
|
+
if (dtor) {
|
|
2795
|
+
dtor(argsWired[i - from]);
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
if (returns) {
|
|
2801
|
+
return retType['fromWireType'](rv);
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
function heap32VectorToArray(count, firstElement) {
|
|
2807
|
+
var array = [];
|
|
2808
|
+
for (var i = 0; i < count; i++) {
|
|
2809
|
+
array.push(HEAP32[(firstElement >> 2) + i]);
|
|
2810
|
+
}
|
|
2811
|
+
return array;
|
|
2812
|
+
}
|
|
2813
|
+
function __embind_register_class_class_function(
|
|
2814
|
+
rawClassType,
|
|
2815
|
+
methodName,
|
|
2816
|
+
argCount,
|
|
2817
|
+
rawArgTypesAddr,
|
|
2818
|
+
invokerSignature,
|
|
2819
|
+
rawInvoker,
|
|
2820
|
+
fn
|
|
2821
|
+
) {
|
|
2822
|
+
var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
|
|
2823
|
+
methodName = readLatin1String(methodName);
|
|
2824
|
+
rawInvoker = embind__requireFunction(invokerSignature, rawInvoker);
|
|
2825
|
+
whenDependentTypesAreResolved([], [rawClassType], function(classType) {
|
|
2826
|
+
classType = classType[0];
|
|
2827
|
+
var humanName = classType.name + '.' + methodName;
|
|
2828
|
+
|
|
2829
|
+
function unboundTypesHandler() {
|
|
2830
|
+
throwUnboundTypeError('Cannot call ' + humanName + ' due to unbound types', rawArgTypes);
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
var proto = classType.registeredClass.constructor;
|
|
2834
|
+
if (undefined === proto[methodName]) {
|
|
2835
|
+
// This is the first function to be registered with this name.
|
|
2836
|
+
unboundTypesHandler.argCount = argCount-1;
|
|
2837
|
+
proto[methodName] = unboundTypesHandler;
|
|
2838
|
+
} else {
|
|
2839
|
+
// There was an existing function with the same name registered. Set up a function overload routing table.
|
|
2840
|
+
ensureOverloadTable(proto, methodName, humanName);
|
|
2841
|
+
proto[methodName].overloadTable[argCount-1] = unboundTypesHandler;
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2844
|
+
whenDependentTypesAreResolved([], rawArgTypes, function(argTypes) {
|
|
2845
|
+
// Replace the initial unbound-types-handler stub with the proper function. If multiple overloads are registered,
|
|
2846
|
+
// the function handlers go into an overload table.
|
|
2847
|
+
var invokerArgsArray = [argTypes[0] /* return value */, null /* no class 'this'*/].concat(argTypes.slice(1) /* actual params */);
|
|
2848
|
+
var func = craftInvokerFunction(humanName, invokerArgsArray, null /* no class 'this'*/, rawInvoker, fn);
|
|
2849
|
+
if (undefined === proto[methodName].overloadTable) {
|
|
2850
|
+
func.argCount = argCount-1;
|
|
2851
|
+
proto[methodName] = func;
|
|
2852
|
+
} else {
|
|
2853
|
+
proto[methodName].overloadTable[argCount-1] = func;
|
|
2854
|
+
}
|
|
2855
|
+
return [];
|
|
2856
|
+
});
|
|
2857
|
+
return [];
|
|
2858
|
+
});
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
function __embind_register_class_constructor(
|
|
2862
|
+
rawClassType,
|
|
2863
|
+
argCount,
|
|
2864
|
+
rawArgTypesAddr,
|
|
2865
|
+
invokerSignature,
|
|
2866
|
+
invoker,
|
|
2867
|
+
rawConstructor
|
|
2868
|
+
) {
|
|
2869
|
+
assert(argCount > 0);
|
|
2870
|
+
var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
|
|
2871
|
+
invoker = embind__requireFunction(invokerSignature, invoker);
|
|
2872
|
+
var args = [rawConstructor];
|
|
2873
|
+
var destructors = [];
|
|
2874
|
+
|
|
2875
|
+
whenDependentTypesAreResolved([], [rawClassType], function(classType) {
|
|
2876
|
+
classType = classType[0];
|
|
2877
|
+
var humanName = 'constructor ' + classType.name;
|
|
2878
|
+
|
|
2879
|
+
if (undefined === classType.registeredClass.constructor_body) {
|
|
2880
|
+
classType.registeredClass.constructor_body = [];
|
|
2881
|
+
}
|
|
2882
|
+
if (undefined !== classType.registeredClass.constructor_body[argCount - 1]) {
|
|
2883
|
+
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!");
|
|
2884
|
+
}
|
|
2885
|
+
classType.registeredClass.constructor_body[argCount - 1] = function unboundTypeHandler() {
|
|
2886
|
+
throwUnboundTypeError('Cannot construct ' + classType.name + ' due to unbound types', rawArgTypes);
|
|
2887
|
+
};
|
|
2888
|
+
|
|
2889
|
+
whenDependentTypesAreResolved([], rawArgTypes, function(argTypes) {
|
|
2890
|
+
classType.registeredClass.constructor_body[argCount - 1] = function constructor_body() {
|
|
2891
|
+
if (arguments.length !== argCount - 1) {
|
|
2892
|
+
throwBindingError(humanName + ' called with ' + arguments.length + ' arguments, expected ' + (argCount-1));
|
|
2893
|
+
}
|
|
2894
|
+
destructors.length = 0;
|
|
2895
|
+
args.length = argCount;
|
|
2896
|
+
for (var i = 1; i < argCount; ++i) {
|
|
2897
|
+
args[i] = argTypes[i]['toWireType'](destructors, arguments[i - 1]);
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
var ptr = invoker.apply(null, args);
|
|
2901
|
+
runDestructors(destructors);
|
|
2902
|
+
|
|
2903
|
+
return argTypes[0]['fromWireType'](ptr);
|
|
2904
|
+
};
|
|
2905
|
+
return [];
|
|
2906
|
+
});
|
|
2907
|
+
return [];
|
|
2908
|
+
});
|
|
2909
|
+
}
|
|
2910
|
+
|
|
2911
|
+
function __embind_register_class_function(
|
|
2912
|
+
rawClassType,
|
|
2913
|
+
methodName,
|
|
2914
|
+
argCount,
|
|
2915
|
+
rawArgTypesAddr, // [ReturnType, ThisType, Args...]
|
|
2916
|
+
invokerSignature,
|
|
2917
|
+
rawInvoker,
|
|
2918
|
+
context,
|
|
2919
|
+
isPureVirtual
|
|
2920
|
+
) {
|
|
2921
|
+
var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
|
|
2922
|
+
methodName = readLatin1String(methodName);
|
|
2923
|
+
rawInvoker = embind__requireFunction(invokerSignature, rawInvoker);
|
|
2924
|
+
|
|
2925
|
+
whenDependentTypesAreResolved([], [rawClassType], function(classType) {
|
|
2926
|
+
classType = classType[0];
|
|
2927
|
+
var humanName = classType.name + '.' + methodName;
|
|
2928
|
+
|
|
2929
|
+
if (isPureVirtual) {
|
|
2930
|
+
classType.registeredClass.pureVirtualFunctions.push(methodName);
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2933
|
+
function unboundTypesHandler() {
|
|
2934
|
+
throwUnboundTypeError('Cannot call ' + humanName + ' due to unbound types', rawArgTypes);
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
var proto = classType.registeredClass.instancePrototype;
|
|
2938
|
+
var method = proto[methodName];
|
|
2939
|
+
if (undefined === method || (undefined === method.overloadTable && method.className !== classType.name && method.argCount === argCount - 2)) {
|
|
2940
|
+
// This is the first overload to be registered, OR we are replacing a function in the base class with a function in the derived class.
|
|
2941
|
+
unboundTypesHandler.argCount = argCount - 2;
|
|
2942
|
+
unboundTypesHandler.className = classType.name;
|
|
2943
|
+
proto[methodName] = unboundTypesHandler;
|
|
2944
|
+
} else {
|
|
2945
|
+
// There was an existing function with the same name registered. Set up a function overload routing table.
|
|
2946
|
+
ensureOverloadTable(proto, methodName, humanName);
|
|
2947
|
+
proto[methodName].overloadTable[argCount - 2] = unboundTypesHandler;
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2950
|
+
whenDependentTypesAreResolved([], rawArgTypes, function(argTypes) {
|
|
2951
|
+
|
|
2952
|
+
var memberFunction = craftInvokerFunction(humanName, argTypes, classType, rawInvoker, context);
|
|
2953
|
+
|
|
2954
|
+
// Replace the initial unbound-handler-stub function with the appropriate member function, now that all types
|
|
2955
|
+
// are resolved. If multiple overloads are registered for this function, the function goes into an overload table.
|
|
2956
|
+
if (undefined === proto[methodName].overloadTable) {
|
|
2957
|
+
// Set argCount in case an overload is registered later
|
|
2958
|
+
memberFunction.argCount = argCount - 2;
|
|
2959
|
+
proto[methodName] = memberFunction;
|
|
2960
|
+
} else {
|
|
2961
|
+
proto[methodName].overloadTable[argCount - 2] = memberFunction;
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2964
|
+
return [];
|
|
2965
|
+
});
|
|
2966
|
+
return [];
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
function validateThis(this_, classType, humanName) {
|
|
2971
|
+
if (!(this_ instanceof Object)) {
|
|
2972
|
+
throwBindingError(humanName + ' with invalid "this": ' + this_);
|
|
2973
|
+
}
|
|
2974
|
+
if (!(this_ instanceof classType.registeredClass.constructor)) {
|
|
2975
|
+
throwBindingError(humanName + ' incompatible with "this" of type ' + this_.constructor.name);
|
|
2976
|
+
}
|
|
2977
|
+
if (!this_.$$.ptr) {
|
|
2978
|
+
throwBindingError('cannot call emscripten binding method ' + humanName + ' on deleted object');
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2981
|
+
// todo: kill this
|
|
2982
|
+
return upcastPointer(
|
|
2983
|
+
this_.$$.ptr,
|
|
2984
|
+
this_.$$.ptrType.registeredClass,
|
|
2985
|
+
classType.registeredClass);
|
|
2986
|
+
}
|
|
2987
|
+
function __embind_register_class_property(
|
|
2988
|
+
classType,
|
|
2989
|
+
fieldName,
|
|
2990
|
+
getterReturnType,
|
|
2991
|
+
getterSignature,
|
|
2992
|
+
getter,
|
|
2993
|
+
getterContext,
|
|
2994
|
+
setterArgumentType,
|
|
2995
|
+
setterSignature,
|
|
2996
|
+
setter,
|
|
2997
|
+
setterContext
|
|
2998
|
+
) {
|
|
2999
|
+
fieldName = readLatin1String(fieldName);
|
|
3000
|
+
getter = embind__requireFunction(getterSignature, getter);
|
|
3001
|
+
|
|
3002
|
+
whenDependentTypesAreResolved([], [classType], function(classType) {
|
|
3003
|
+
classType = classType[0];
|
|
3004
|
+
var humanName = classType.name + '.' + fieldName;
|
|
3005
|
+
var desc = {
|
|
3006
|
+
get: function() {
|
|
3007
|
+
throwUnboundTypeError('Cannot access ' + humanName + ' due to unbound types', [getterReturnType, setterArgumentType]);
|
|
3008
|
+
},
|
|
3009
|
+
enumerable: true,
|
|
3010
|
+
configurable: true
|
|
3011
|
+
};
|
|
3012
|
+
if (setter) {
|
|
3013
|
+
desc.set = function() {
|
|
3014
|
+
throwUnboundTypeError('Cannot access ' + humanName + ' due to unbound types', [getterReturnType, setterArgumentType]);
|
|
3015
|
+
};
|
|
3016
|
+
} else {
|
|
3017
|
+
desc.set = function(v) {
|
|
3018
|
+
throwBindingError(humanName + ' is a read-only property');
|
|
3019
|
+
};
|
|
3020
|
+
}
|
|
3021
|
+
|
|
3022
|
+
Object.defineProperty(classType.registeredClass.instancePrototype, fieldName, desc);
|
|
3023
|
+
|
|
3024
|
+
whenDependentTypesAreResolved(
|
|
3025
|
+
[],
|
|
3026
|
+
(setter ? [getterReturnType, setterArgumentType] : [getterReturnType]),
|
|
3027
|
+
function(types) {
|
|
3028
|
+
var getterReturnType = types[0];
|
|
3029
|
+
var desc = {
|
|
3030
|
+
get: function() {
|
|
3031
|
+
var ptr = validateThis(this, classType, humanName + ' getter');
|
|
3032
|
+
return getterReturnType['fromWireType'](getter(getterContext, ptr));
|
|
3033
|
+
},
|
|
3034
|
+
enumerable: true
|
|
3035
|
+
};
|
|
3036
|
+
|
|
3037
|
+
if (setter) {
|
|
3038
|
+
setter = embind__requireFunction(setterSignature, setter);
|
|
3039
|
+
var setterArgumentType = types[1];
|
|
3040
|
+
desc.set = function(v) {
|
|
3041
|
+
var ptr = validateThis(this, classType, humanName + ' setter');
|
|
3042
|
+
var destructors = [];
|
|
3043
|
+
setter(setterContext, ptr, setterArgumentType['toWireType'](destructors, v));
|
|
3044
|
+
runDestructors(destructors);
|
|
3045
|
+
};
|
|
3046
|
+
}
|
|
3047
|
+
|
|
3048
|
+
Object.defineProperty(classType.registeredClass.instancePrototype, fieldName, desc);
|
|
3049
|
+
return [];
|
|
3050
|
+
});
|
|
3051
|
+
|
|
3052
|
+
return [];
|
|
3053
|
+
});
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
var emval_free_list=[];
|
|
3057
|
+
|
|
3058
|
+
var emval_handle_array=[{},{value:undefined},{value:null},{value:true},{value:false}];
|
|
3059
|
+
function __emval_decref(handle) {
|
|
3060
|
+
if (handle > 4 && 0 === --emval_handle_array[handle].refcount) {
|
|
3061
|
+
emval_handle_array[handle] = undefined;
|
|
3062
|
+
emval_free_list.push(handle);
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
|
|
3066
|
+
function count_emval_handles() {
|
|
3067
|
+
var count = 0;
|
|
3068
|
+
for (var i = 5; i < emval_handle_array.length; ++i) {
|
|
3069
|
+
if (emval_handle_array[i] !== undefined) {
|
|
3070
|
+
++count;
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
return count;
|
|
3074
|
+
}
|
|
3075
|
+
|
|
3076
|
+
function get_first_emval() {
|
|
3077
|
+
for (var i = 5; i < emval_handle_array.length; ++i) {
|
|
3078
|
+
if (emval_handle_array[i] !== undefined) {
|
|
3079
|
+
return emval_handle_array[i];
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
return null;
|
|
3083
|
+
}
|
|
3084
|
+
function init_emval() {
|
|
3085
|
+
Module['count_emval_handles'] = count_emval_handles;
|
|
3086
|
+
Module['get_first_emval'] = get_first_emval;
|
|
3087
|
+
}
|
|
3088
|
+
function __emval_register(value) {
|
|
3089
|
+
|
|
3090
|
+
switch(value){
|
|
3091
|
+
case undefined :{ return 1; }
|
|
3092
|
+
case null :{ return 2; }
|
|
3093
|
+
case true :{ return 3; }
|
|
3094
|
+
case false :{ return 4; }
|
|
3095
|
+
default:{
|
|
3096
|
+
var handle = emval_free_list.length ?
|
|
3097
|
+
emval_free_list.pop() :
|
|
3098
|
+
emval_handle_array.length;
|
|
3099
|
+
|
|
3100
|
+
emval_handle_array[handle] = {refcount: 1, value: value};
|
|
3101
|
+
return handle;
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
function __embind_register_emval(rawType, name) {
|
|
3106
|
+
name = readLatin1String(name);
|
|
3107
|
+
registerType(rawType, {
|
|
3108
|
+
name: name,
|
|
3109
|
+
'fromWireType': function(handle) {
|
|
3110
|
+
var rv = emval_handle_array[handle].value;
|
|
3111
|
+
__emval_decref(handle);
|
|
3112
|
+
return rv;
|
|
3113
|
+
},
|
|
3114
|
+
'toWireType': function(destructors, value) {
|
|
3115
|
+
return __emval_register(value);
|
|
3116
|
+
},
|
|
3117
|
+
'argPackAdvance': 8,
|
|
3118
|
+
'readValueFromPointer': simpleReadValueFromPointer,
|
|
3119
|
+
destructorFunction: null, // This type does not need a destructor
|
|
3120
|
+
|
|
3121
|
+
// TODO: do we need a deleteObject here? write a test where
|
|
3122
|
+
// emval is passed into JS via an interface
|
|
3123
|
+
});
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
function _embind_repr(v) {
|
|
3127
|
+
if (v === null) {
|
|
3128
|
+
return 'null';
|
|
3129
|
+
}
|
|
3130
|
+
var t = typeof v;
|
|
3131
|
+
if (t === 'object' || t === 'array' || t === 'function') {
|
|
3132
|
+
return v.toString();
|
|
3133
|
+
} else {
|
|
3134
|
+
return '' + v;
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
|
|
3138
|
+
function floatReadValueFromPointer(name, shift) {
|
|
3139
|
+
switch (shift) {
|
|
3140
|
+
case 2: return function(pointer) {
|
|
3141
|
+
return this['fromWireType'](HEAPF32[pointer >> 2]);
|
|
3142
|
+
};
|
|
3143
|
+
case 3: return function(pointer) {
|
|
3144
|
+
return this['fromWireType'](HEAPF64[pointer >> 3]);
|
|
3145
|
+
};
|
|
3146
|
+
default:
|
|
3147
|
+
throw new TypeError("Unknown float type: " + name);
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
function __embind_register_float(rawType, name, size) {
|
|
3151
|
+
var shift = getShiftFromSize(size);
|
|
3152
|
+
name = readLatin1String(name);
|
|
3153
|
+
registerType(rawType, {
|
|
3154
|
+
name: name,
|
|
3155
|
+
'fromWireType': function(value) {
|
|
3156
|
+
return value;
|
|
3157
|
+
},
|
|
3158
|
+
'toWireType': function(destructors, value) {
|
|
3159
|
+
// todo: Here we have an opportunity for -O3 level "unsafe" optimizations: we could
|
|
3160
|
+
// avoid the following if() and assume value is of proper type.
|
|
3161
|
+
if (typeof value !== "number" && typeof value !== "boolean") {
|
|
3162
|
+
throw new TypeError('Cannot convert "' + _embind_repr(value) + '" to ' + this.name);
|
|
3163
|
+
}
|
|
3164
|
+
return value;
|
|
3165
|
+
},
|
|
3166
|
+
'argPackAdvance': 8,
|
|
3167
|
+
'readValueFromPointer': floatReadValueFromPointer(name, shift),
|
|
3168
|
+
destructorFunction: null, // This type does not need a destructor
|
|
3169
|
+
});
|
|
3170
|
+
}
|
|
3171
|
+
|
|
3172
|
+
function integerReadValueFromPointer(name, shift, signed) {
|
|
3173
|
+
// integers are quite common, so generate very specialized functions
|
|
3174
|
+
switch (shift) {
|
|
3175
|
+
case 0: return signed ?
|
|
3176
|
+
function readS8FromPointer(pointer) { return HEAP8[pointer]; } :
|
|
3177
|
+
function readU8FromPointer(pointer) { return HEAPU8[pointer]; };
|
|
3178
|
+
case 1: return signed ?
|
|
3179
|
+
function readS16FromPointer(pointer) { return HEAP16[pointer >> 1]; } :
|
|
3180
|
+
function readU16FromPointer(pointer) { return HEAPU16[pointer >> 1]; };
|
|
3181
|
+
case 2: return signed ?
|
|
3182
|
+
function readS32FromPointer(pointer) { return HEAP32[pointer >> 2]; } :
|
|
3183
|
+
function readU32FromPointer(pointer) { return HEAPU32[pointer >> 2]; };
|
|
3184
|
+
default:
|
|
3185
|
+
throw new TypeError("Unknown integer type: " + name);
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
function __embind_register_integer(primitiveType, name, size, minRange, maxRange) {
|
|
3189
|
+
name = readLatin1String(name);
|
|
3190
|
+
if (maxRange === -1) { // LLVM doesn't have signed and unsigned 32-bit types, so u32 literals come out as 'i32 -1'. Always treat those as max u32.
|
|
3191
|
+
maxRange = 4294967295;
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
var shift = getShiftFromSize(size);
|
|
3195
|
+
|
|
3196
|
+
var fromWireType = function(value) {
|
|
3197
|
+
return value;
|
|
3198
|
+
};
|
|
3199
|
+
|
|
3200
|
+
if (minRange === 0) {
|
|
3201
|
+
var bitshift = 32 - 8*size;
|
|
3202
|
+
fromWireType = function(value) {
|
|
3203
|
+
return (value << bitshift) >>> bitshift;
|
|
3204
|
+
};
|
|
3205
|
+
}
|
|
3206
|
+
|
|
3207
|
+
var isUnsignedType = (name.indexOf('unsigned') != -1);
|
|
3208
|
+
|
|
3209
|
+
registerType(primitiveType, {
|
|
3210
|
+
name: name,
|
|
3211
|
+
'fromWireType': fromWireType,
|
|
3212
|
+
'toWireType': function(destructors, value) {
|
|
3213
|
+
// todo: Here we have an opportunity for -O3 level "unsafe" optimizations: we could
|
|
3214
|
+
// avoid the following two if()s and assume value is of proper type.
|
|
3215
|
+
if (typeof value !== "number" && typeof value !== "boolean") {
|
|
3216
|
+
throw new TypeError('Cannot convert "' + _embind_repr(value) + '" to ' + this.name);
|
|
3217
|
+
}
|
|
3218
|
+
if (value < minRange || value > maxRange) {
|
|
3219
|
+
throw new TypeError('Passing a number "' + _embind_repr(value) + '" from JS side to C/C++ side to an argument of type "' + name + '", which is outside the valid range [' + minRange + ', ' + maxRange + ']!');
|
|
3220
|
+
}
|
|
3221
|
+
return isUnsignedType ? (value >>> 0) : (value | 0);
|
|
3222
|
+
},
|
|
3223
|
+
'argPackAdvance': 8,
|
|
3224
|
+
'readValueFromPointer': integerReadValueFromPointer(name, shift, minRange !== 0),
|
|
3225
|
+
destructorFunction: null, // This type does not need a destructor
|
|
3226
|
+
});
|
|
3227
|
+
}
|
|
3228
|
+
|
|
3229
|
+
function __embind_register_memory_view(rawType, dataTypeIndex, name) {
|
|
3230
|
+
var typeMapping = [
|
|
3231
|
+
Int8Array,
|
|
3232
|
+
Uint8Array,
|
|
3233
|
+
Int16Array,
|
|
3234
|
+
Uint16Array,
|
|
3235
|
+
Int32Array,
|
|
3236
|
+
Uint32Array,
|
|
3237
|
+
Float32Array,
|
|
3238
|
+
Float64Array,
|
|
3239
|
+
];
|
|
3240
|
+
|
|
3241
|
+
var TA = typeMapping[dataTypeIndex];
|
|
3242
|
+
|
|
3243
|
+
function decodeMemoryView(handle) {
|
|
3244
|
+
handle = handle >> 2;
|
|
3245
|
+
var heap = HEAPU32;
|
|
3246
|
+
var size = heap[handle]; // in elements
|
|
3247
|
+
var data = heap[handle + 1]; // byte offset into emscripten heap
|
|
3248
|
+
return new TA(buffer, data, size);
|
|
3249
|
+
}
|
|
3250
|
+
|
|
3251
|
+
name = readLatin1String(name);
|
|
3252
|
+
registerType(rawType, {
|
|
3253
|
+
name: name,
|
|
3254
|
+
'fromWireType': decodeMemoryView,
|
|
3255
|
+
'argPackAdvance': 8,
|
|
3256
|
+
'readValueFromPointer': decodeMemoryView,
|
|
3257
|
+
}, {
|
|
3258
|
+
ignoreDuplicateRegistrations: true,
|
|
3259
|
+
});
|
|
3260
|
+
}
|
|
3261
|
+
|
|
3262
|
+
function __embind_register_std_string(rawType, name) {
|
|
3263
|
+
name = readLatin1String(name);
|
|
3264
|
+
var stdStringIsUTF8
|
|
3265
|
+
//process only std::string bindings with UTF8 support, in contrast to e.g. std::basic_string<unsigned char>
|
|
3266
|
+
= (name === "std::string");
|
|
3267
|
+
|
|
3268
|
+
registerType(rawType, {
|
|
3269
|
+
name: name,
|
|
3270
|
+
'fromWireType': function(value) {
|
|
3271
|
+
var length = HEAPU32[value >> 2];
|
|
3272
|
+
|
|
3273
|
+
var str;
|
|
3274
|
+
if (stdStringIsUTF8) {
|
|
3275
|
+
var decodeStartPtr = value + 4;
|
|
3276
|
+
// Looping here to support possible embedded '0' bytes
|
|
3277
|
+
for (var i = 0; i <= length; ++i) {
|
|
3278
|
+
var currentBytePtr = value + 4 + i;
|
|
3279
|
+
if (i == length || HEAPU8[currentBytePtr] == 0) {
|
|
3280
|
+
var maxRead = currentBytePtr - decodeStartPtr;
|
|
3281
|
+
var stringSegment = UTF8ToString(decodeStartPtr, maxRead);
|
|
3282
|
+
if (str === undefined) {
|
|
3283
|
+
str = stringSegment;
|
|
3284
|
+
} else {
|
|
3285
|
+
str += String.fromCharCode(0);
|
|
3286
|
+
str += stringSegment;
|
|
3287
|
+
}
|
|
3288
|
+
decodeStartPtr = currentBytePtr + 1;
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
} else {
|
|
3292
|
+
var a = new Array(length);
|
|
3293
|
+
for (var i = 0; i < length; ++i) {
|
|
3294
|
+
a[i] = String.fromCharCode(HEAPU8[value + 4 + i]);
|
|
3295
|
+
}
|
|
3296
|
+
str = a.join('');
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
_free(value);
|
|
3300
|
+
|
|
3301
|
+
return str;
|
|
3302
|
+
},
|
|
3303
|
+
'toWireType': function(destructors, value) {
|
|
3304
|
+
if (value instanceof ArrayBuffer) {
|
|
3305
|
+
value = new Uint8Array(value);
|
|
3306
|
+
}
|
|
3307
|
+
|
|
3308
|
+
var getLength;
|
|
3309
|
+
var valueIsOfTypeString = (typeof value === 'string');
|
|
3310
|
+
|
|
3311
|
+
if (!(valueIsOfTypeString || value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int8Array)) {
|
|
3312
|
+
throwBindingError('Cannot pass non-string to std::string');
|
|
3313
|
+
}
|
|
3314
|
+
if (stdStringIsUTF8 && valueIsOfTypeString) {
|
|
3315
|
+
getLength = function() {return lengthBytesUTF8(value);};
|
|
3316
|
+
} else {
|
|
3317
|
+
getLength = function() {return value.length;};
|
|
3318
|
+
}
|
|
3319
|
+
|
|
3320
|
+
// assumes 4-byte alignment
|
|
3321
|
+
var length = getLength();
|
|
3322
|
+
var ptr = _malloc(4 + length + 1);
|
|
3323
|
+
HEAPU32[ptr >> 2] = length;
|
|
3324
|
+
if (stdStringIsUTF8 && valueIsOfTypeString) {
|
|
3325
|
+
stringToUTF8(value, ptr + 4, length + 1);
|
|
3326
|
+
} else {
|
|
3327
|
+
if (valueIsOfTypeString) {
|
|
3328
|
+
for (var i = 0; i < length; ++i) {
|
|
3329
|
+
var charCode = value.charCodeAt(i);
|
|
3330
|
+
if (charCode > 255) {
|
|
3331
|
+
_free(ptr);
|
|
3332
|
+
throwBindingError('String has UTF-16 code units that do not fit in 8 bits');
|
|
3333
|
+
}
|
|
3334
|
+
HEAPU8[ptr + 4 + i] = charCode;
|
|
3335
|
+
}
|
|
3336
|
+
} else {
|
|
3337
|
+
for (var i = 0; i < length; ++i) {
|
|
3338
|
+
HEAPU8[ptr + 4 + i] = value[i];
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
|
|
3343
|
+
if (destructors !== null) {
|
|
3344
|
+
destructors.push(_free, ptr);
|
|
3345
|
+
}
|
|
3346
|
+
return ptr;
|
|
3347
|
+
},
|
|
3348
|
+
'argPackAdvance': 8,
|
|
3349
|
+
'readValueFromPointer': simpleReadValueFromPointer,
|
|
3350
|
+
destructorFunction: function(ptr) { _free(ptr); },
|
|
3351
|
+
});
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3354
|
+
function __embind_register_std_wstring(rawType, charSize, name) {
|
|
3355
|
+
name = readLatin1String(name);
|
|
3356
|
+
var decodeString, encodeString, getHeap, lengthBytesUTF, shift;
|
|
3357
|
+
if (charSize === 2) {
|
|
3358
|
+
decodeString = UTF16ToString;
|
|
3359
|
+
encodeString = stringToUTF16;
|
|
3360
|
+
lengthBytesUTF = lengthBytesUTF16;
|
|
3361
|
+
getHeap = function() { return HEAPU16; };
|
|
3362
|
+
shift = 1;
|
|
3363
|
+
} else if (charSize === 4) {
|
|
3364
|
+
decodeString = UTF32ToString;
|
|
3365
|
+
encodeString = stringToUTF32;
|
|
3366
|
+
lengthBytesUTF = lengthBytesUTF32;
|
|
3367
|
+
getHeap = function() { return HEAPU32; };
|
|
3368
|
+
shift = 2;
|
|
3369
|
+
}
|
|
3370
|
+
registerType(rawType, {
|
|
3371
|
+
name: name,
|
|
3372
|
+
'fromWireType': function(value) {
|
|
3373
|
+
// Code mostly taken from _embind_register_std_string fromWireType
|
|
3374
|
+
var length = HEAPU32[value >> 2];
|
|
3375
|
+
var HEAP = getHeap();
|
|
3376
|
+
var str;
|
|
3377
|
+
|
|
3378
|
+
var decodeStartPtr = value + 4;
|
|
3379
|
+
// Looping here to support possible embedded '0' bytes
|
|
3380
|
+
for (var i = 0; i <= length; ++i) {
|
|
3381
|
+
var currentBytePtr = value + 4 + i * charSize;
|
|
3382
|
+
if (i == length || HEAP[currentBytePtr >> shift] == 0) {
|
|
3383
|
+
var maxReadBytes = currentBytePtr - decodeStartPtr;
|
|
3384
|
+
var stringSegment = decodeString(decodeStartPtr, maxReadBytes);
|
|
3385
|
+
if (str === undefined) {
|
|
3386
|
+
str = stringSegment;
|
|
3387
|
+
} else {
|
|
3388
|
+
str += String.fromCharCode(0);
|
|
3389
|
+
str += stringSegment;
|
|
3390
|
+
}
|
|
3391
|
+
decodeStartPtr = currentBytePtr + charSize;
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
|
|
3395
|
+
_free(value);
|
|
3396
|
+
|
|
3397
|
+
return str;
|
|
3398
|
+
},
|
|
3399
|
+
'toWireType': function(destructors, value) {
|
|
3400
|
+
if (!(typeof value === 'string')) {
|
|
3401
|
+
throwBindingError('Cannot pass non-string to C++ string type ' + name);
|
|
3402
|
+
}
|
|
3403
|
+
|
|
3404
|
+
// assumes 4-byte alignment
|
|
3405
|
+
var length = lengthBytesUTF(value);
|
|
3406
|
+
var ptr = _malloc(4 + length + charSize);
|
|
3407
|
+
HEAPU32[ptr >> 2] = length >> shift;
|
|
3408
|
+
|
|
3409
|
+
encodeString(value, ptr + 4, length + charSize);
|
|
3410
|
+
|
|
3411
|
+
if (destructors !== null) {
|
|
3412
|
+
destructors.push(_free, ptr);
|
|
3413
|
+
}
|
|
3414
|
+
return ptr;
|
|
3415
|
+
},
|
|
3416
|
+
'argPackAdvance': 8,
|
|
3417
|
+
'readValueFromPointer': simpleReadValueFromPointer,
|
|
3418
|
+
destructorFunction: function(ptr) { _free(ptr); },
|
|
3419
|
+
});
|
|
3420
|
+
}
|
|
3421
|
+
|
|
3422
|
+
function __embind_register_value_array(
|
|
3423
|
+
rawType,
|
|
3424
|
+
name,
|
|
3425
|
+
constructorSignature,
|
|
3426
|
+
rawConstructor,
|
|
3427
|
+
destructorSignature,
|
|
3428
|
+
rawDestructor
|
|
3429
|
+
) {
|
|
3430
|
+
tupleRegistrations[rawType] = {
|
|
3431
|
+
name: readLatin1String(name),
|
|
3432
|
+
rawConstructor: embind__requireFunction(constructorSignature, rawConstructor),
|
|
3433
|
+
rawDestructor: embind__requireFunction(destructorSignature, rawDestructor),
|
|
3434
|
+
elements: [],
|
|
3435
|
+
};
|
|
3436
|
+
}
|
|
3437
|
+
|
|
3438
|
+
function __embind_register_value_array_element(
|
|
3439
|
+
rawTupleType,
|
|
3440
|
+
getterReturnType,
|
|
3441
|
+
getterSignature,
|
|
3442
|
+
getter,
|
|
3443
|
+
getterContext,
|
|
3444
|
+
setterArgumentType,
|
|
3445
|
+
setterSignature,
|
|
3446
|
+
setter,
|
|
3447
|
+
setterContext
|
|
3448
|
+
) {
|
|
3449
|
+
tupleRegistrations[rawTupleType].elements.push({
|
|
3450
|
+
getterReturnType: getterReturnType,
|
|
3451
|
+
getter: embind__requireFunction(getterSignature, getter),
|
|
3452
|
+
getterContext: getterContext,
|
|
3453
|
+
setterArgumentType: setterArgumentType,
|
|
3454
|
+
setter: embind__requireFunction(setterSignature, setter),
|
|
3455
|
+
setterContext: setterContext,
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
function __embind_register_value_object(
|
|
3460
|
+
rawType,
|
|
3461
|
+
name,
|
|
3462
|
+
constructorSignature,
|
|
3463
|
+
rawConstructor,
|
|
3464
|
+
destructorSignature,
|
|
3465
|
+
rawDestructor
|
|
3466
|
+
) {
|
|
3467
|
+
structRegistrations[rawType] = {
|
|
3468
|
+
name: readLatin1String(name),
|
|
3469
|
+
rawConstructor: embind__requireFunction(constructorSignature, rawConstructor),
|
|
3470
|
+
rawDestructor: embind__requireFunction(destructorSignature, rawDestructor),
|
|
3471
|
+
fields: [],
|
|
3472
|
+
};
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
function __embind_register_value_object_field(
|
|
3476
|
+
structType,
|
|
3477
|
+
fieldName,
|
|
3478
|
+
getterReturnType,
|
|
3479
|
+
getterSignature,
|
|
3480
|
+
getter,
|
|
3481
|
+
getterContext,
|
|
3482
|
+
setterArgumentType,
|
|
3483
|
+
setterSignature,
|
|
3484
|
+
setter,
|
|
3485
|
+
setterContext
|
|
3486
|
+
) {
|
|
3487
|
+
structRegistrations[structType].fields.push({
|
|
3488
|
+
fieldName: readLatin1String(fieldName),
|
|
3489
|
+
getterReturnType: getterReturnType,
|
|
3490
|
+
getter: embind__requireFunction(getterSignature, getter),
|
|
3491
|
+
getterContext: getterContext,
|
|
3492
|
+
setterArgumentType: setterArgumentType,
|
|
3493
|
+
setter: embind__requireFunction(setterSignature, setter),
|
|
3494
|
+
setterContext: setterContext,
|
|
3495
|
+
});
|
|
3496
|
+
}
|
|
3497
|
+
|
|
3498
|
+
function __embind_register_void(rawType, name) {
|
|
3499
|
+
name = readLatin1String(name);
|
|
3500
|
+
registerType(rawType, {
|
|
3501
|
+
isVoid: true, // void return values can be optimized out sometimes
|
|
3502
|
+
name: name,
|
|
3503
|
+
'argPackAdvance': 0,
|
|
3504
|
+
'fromWireType': function() {
|
|
3505
|
+
return undefined;
|
|
3506
|
+
},
|
|
3507
|
+
'toWireType': function(destructors, o) {
|
|
3508
|
+
// TODO: assert if anything else is given?
|
|
3509
|
+
return undefined;
|
|
3510
|
+
},
|
|
3511
|
+
});
|
|
3512
|
+
}
|
|
3513
|
+
|
|
3514
|
+
function requireHandle(handle) {
|
|
3515
|
+
if (!handle) {
|
|
3516
|
+
throwBindingError('Cannot use deleted val. handle = ' + handle);
|
|
3517
|
+
}
|
|
3518
|
+
return emval_handle_array[handle].value;
|
|
3519
|
+
}
|
|
3520
|
+
|
|
3521
|
+
function requireRegisteredType(rawType, humanName) {
|
|
3522
|
+
var impl = registeredTypes[rawType];
|
|
3523
|
+
if (undefined === impl) {
|
|
3524
|
+
throwBindingError(humanName + " has unknown type " + getTypeName(rawType));
|
|
3525
|
+
}
|
|
3526
|
+
return impl;
|
|
3527
|
+
}
|
|
3528
|
+
function __emval_as(handle, returnType, destructorsRef) {
|
|
3529
|
+
handle = requireHandle(handle);
|
|
3530
|
+
returnType = requireRegisteredType(returnType, 'emval::as');
|
|
3531
|
+
var destructors = [];
|
|
3532
|
+
var rd = __emval_register(destructors);
|
|
3533
|
+
HEAP32[destructorsRef >> 2] = rd;
|
|
3534
|
+
return returnType['toWireType'](destructors, handle);
|
|
3535
|
+
}
|
|
3536
|
+
|
|
3537
|
+
function __emval_lookupTypes(argCount, argTypes) {
|
|
3538
|
+
var a = new Array(argCount);
|
|
3539
|
+
for (var i = 0; i < argCount; ++i) {
|
|
3540
|
+
a[i] = requireRegisteredType(
|
|
3541
|
+
HEAP32[(argTypes >> 2) + i],
|
|
3542
|
+
"parameter " + i);
|
|
3543
|
+
}
|
|
3544
|
+
return a;
|
|
3545
|
+
}
|
|
3546
|
+
function __emval_call(handle, argCount, argTypes, argv) {
|
|
3547
|
+
handle = requireHandle(handle);
|
|
3548
|
+
var types = __emval_lookupTypes(argCount, argTypes);
|
|
3549
|
+
|
|
3550
|
+
var args = new Array(argCount);
|
|
3551
|
+
for (var i = 0; i < argCount; ++i) {
|
|
3552
|
+
var type = types[i];
|
|
3553
|
+
args[i] = type['readValueFromPointer'](argv);
|
|
3554
|
+
argv += type['argPackAdvance'];
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
var rv = handle.apply(undefined, args);
|
|
3558
|
+
return __emval_register(rv);
|
|
3559
|
+
}
|
|
3560
|
+
|
|
3561
|
+
function __emval_allocateDestructors(destructorsRef) {
|
|
3562
|
+
var destructors = [];
|
|
3563
|
+
HEAP32[destructorsRef >> 2] = __emval_register(destructors);
|
|
3564
|
+
return destructors;
|
|
3565
|
+
}
|
|
3566
|
+
|
|
3567
|
+
var emval_symbols={};
|
|
3568
|
+
function getStringOrSymbol(address) {
|
|
3569
|
+
var symbol = emval_symbols[address];
|
|
3570
|
+
if (symbol === undefined) {
|
|
3571
|
+
return readLatin1String(address);
|
|
3572
|
+
} else {
|
|
3573
|
+
return symbol;
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
|
|
3577
|
+
var emval_methodCallers=[];
|
|
3578
|
+
function __emval_call_method(caller, handle, methodName, destructorsRef, args) {
|
|
3579
|
+
caller = emval_methodCallers[caller];
|
|
3580
|
+
handle = requireHandle(handle);
|
|
3581
|
+
methodName = getStringOrSymbol(methodName);
|
|
3582
|
+
return caller(handle, methodName, __emval_allocateDestructors(destructorsRef), args);
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3585
|
+
function __emval_call_void_method(caller, handle, methodName, args) {
|
|
3586
|
+
caller = emval_methodCallers[caller];
|
|
3587
|
+
handle = requireHandle(handle);
|
|
3588
|
+
methodName = getStringOrSymbol(methodName);
|
|
3589
|
+
caller(handle, methodName, null, args);
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3592
|
+
|
|
3593
|
+
function __emval_delete(object, property) {
|
|
3594
|
+
object = requireHandle(object);
|
|
3595
|
+
property = requireHandle(property);
|
|
3596
|
+
return delete object[property];
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
function emval_get_global() {
|
|
3600
|
+
if (typeof globalThis === 'object') {
|
|
3601
|
+
return globalThis;
|
|
3602
|
+
}
|
|
3603
|
+
return (function(){
|
|
3604
|
+
return Function;
|
|
3605
|
+
})()('return this')();
|
|
3606
|
+
}
|
|
3607
|
+
function __emval_get_global(name) {
|
|
3608
|
+
if(name===0){
|
|
3609
|
+
return __emval_register(emval_get_global());
|
|
3610
|
+
} else {
|
|
3611
|
+
name = getStringOrSymbol(name);
|
|
3612
|
+
return __emval_register(emval_get_global()[name]);
|
|
3613
|
+
}
|
|
3614
|
+
}
|
|
3615
|
+
|
|
3616
|
+
function __emval_addMethodCaller(caller) {
|
|
3617
|
+
var id = emval_methodCallers.length;
|
|
3618
|
+
emval_methodCallers.push(caller);
|
|
3619
|
+
return id;
|
|
3620
|
+
}
|
|
3621
|
+
function __emval_get_method_caller(argCount, argTypes) {
|
|
3622
|
+
var types = __emval_lookupTypes(argCount, argTypes);
|
|
3623
|
+
|
|
3624
|
+
var retType = types[0];
|
|
3625
|
+
|
|
3626
|
+
var invokerFunction = function methodCaller(handle, name, destructors, args) {
|
|
3627
|
+
var offset = 0;
|
|
3628
|
+
var argsValue = [];
|
|
3629
|
+
|
|
3630
|
+
for (var i = 1; i < argCount; ++i) {
|
|
3631
|
+
argsValue.push(types[i]['readValueFromPointer'](args + offset));
|
|
3632
|
+
offset += types[i]['argPackAdvance'];
|
|
3633
|
+
}
|
|
3634
|
+
|
|
3635
|
+
var rv = handle[name](...argsValue);
|
|
3636
|
+
|
|
3637
|
+
for (var i = 1; i < argCount; ++i) {
|
|
3638
|
+
var dtor = types[i]['deleteObject'];
|
|
3639
|
+
if (dtor) {
|
|
3640
|
+
dtor(argsValue[i - 1]);
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
|
|
3644
|
+
if (!retType.isVoid) {
|
|
3645
|
+
return retType['toWireType'](destructors, rv);
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
|
|
3649
|
+
return __emval_addMethodCaller(invokerFunction);
|
|
3650
|
+
}
|
|
3651
|
+
|
|
3652
|
+
function __emval_get_property(handle, key) {
|
|
3653
|
+
handle = requireHandle(handle);
|
|
3654
|
+
key = requireHandle(key);
|
|
3655
|
+
return __emval_register(handle[key]);
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3658
|
+
function __emval_incref(handle) {
|
|
3659
|
+
if (handle > 4) {
|
|
3660
|
+
emval_handle_array[handle].refcount += 1;
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
|
|
3664
|
+
function __emval_instanceof(object, constructor) {
|
|
3665
|
+
object = requireHandle(object);
|
|
3666
|
+
constructor = requireHandle(constructor);
|
|
3667
|
+
return object instanceof constructor;
|
|
3668
|
+
}
|
|
3669
|
+
|
|
3670
|
+
function __emval_new_array() {
|
|
3671
|
+
return __emval_register([]);
|
|
3672
|
+
}
|
|
3673
|
+
|
|
3674
|
+
function __emval_new_cstring(v) {
|
|
3675
|
+
return __emval_register(getStringOrSymbol(v));
|
|
3676
|
+
}
|
|
3677
|
+
|
|
3678
|
+
function __emval_not(object) {
|
|
3679
|
+
object = requireHandle(object);
|
|
3680
|
+
return !object;
|
|
3681
|
+
}
|
|
3682
|
+
|
|
3683
|
+
function __emval_run_destructors(handle) {
|
|
3684
|
+
var destructors = emval_handle_array[handle].value;
|
|
3685
|
+
runDestructors(destructors);
|
|
3686
|
+
__emval_decref(handle);
|
|
3687
|
+
}
|
|
3688
|
+
|
|
3689
|
+
function __emval_set_property(handle, key, value) {
|
|
3690
|
+
handle = requireHandle(handle);
|
|
3691
|
+
key = requireHandle(key);
|
|
3692
|
+
value = requireHandle(value);
|
|
3693
|
+
handle[key] = value;
|
|
3694
|
+
}
|
|
3695
|
+
|
|
3696
|
+
function __emval_strictly_equals(first, second) {
|
|
3697
|
+
first = requireHandle(first);
|
|
3698
|
+
second = requireHandle(second);
|
|
3699
|
+
return first === second;
|
|
3700
|
+
}
|
|
3701
|
+
|
|
3702
|
+
function __emval_take_value(type, argv) {
|
|
3703
|
+
type = requireRegisteredType(type, '_emval_take_value');
|
|
3704
|
+
var v = type['readValueFromPointer'](argv);
|
|
3705
|
+
return __emval_register(v);
|
|
3706
|
+
}
|
|
3707
|
+
|
|
3708
|
+
function _abort() {
|
|
3709
|
+
abort();
|
|
3710
|
+
}
|
|
3711
|
+
|
|
3712
|
+
|
|
3713
|
+
function _clock() {
|
|
3714
|
+
if (_clock.start === undefined) _clock.start = Date.now();
|
|
3715
|
+
return ((Date.now() - _clock.start) * (1000000 / 1000))|0;
|
|
3716
|
+
}
|
|
3717
|
+
|
|
3718
|
+
var _emscripten_get_now;if (ENVIRONMENT_IS_NODE) {
|
|
3719
|
+
_emscripten_get_now = function() {
|
|
3720
|
+
var t = process['hrtime']();
|
|
3721
|
+
return t[0] * 1e3 + t[1] / 1e6;
|
|
3722
|
+
};
|
|
3723
|
+
} else if (typeof dateNow !== 'undefined') {
|
|
3724
|
+
_emscripten_get_now = dateNow;
|
|
3725
|
+
} else _emscripten_get_now = function() { return performance.now(); }
|
|
3726
|
+
;
|
|
3727
|
+
|
|
3728
|
+
var _emscripten_get_now_is_monotonic=true;;
|
|
3729
|
+
function _clock_gettime(clk_id, tp) {
|
|
3730
|
+
// int clock_gettime(clockid_t clk_id, struct timespec *tp);
|
|
3731
|
+
var now;
|
|
3732
|
+
if (clk_id === 0) {
|
|
3733
|
+
now = Date.now();
|
|
3734
|
+
} else if ((clk_id === 1 || clk_id === 4) && _emscripten_get_now_is_monotonic) {
|
|
3735
|
+
now = _emscripten_get_now();
|
|
3736
|
+
} else {
|
|
3737
|
+
setErrNo(28);
|
|
3738
|
+
return -1;
|
|
3739
|
+
}
|
|
3740
|
+
HEAP32[((tp)>>2)]=(now/1000)|0; // seconds
|
|
3741
|
+
HEAP32[(((tp)+(4))>>2)]=((now % 1000)*1000*1000)|0; // nanoseconds
|
|
3742
|
+
return 0;
|
|
3743
|
+
}
|
|
3744
|
+
|
|
3745
|
+
function _dlclose(handle) {
|
|
3746
|
+
abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking");
|
|
3747
|
+
}
|
|
3748
|
+
|
|
3749
|
+
function _dlopen(filename, flag) {
|
|
3750
|
+
abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking");
|
|
3751
|
+
}
|
|
3752
|
+
|
|
3753
|
+
function _dlsym(handle, symbol) {
|
|
3754
|
+
abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking");
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
function _emscripten_memcpy_big(dest, src, num) {
|
|
3758
|
+
HEAPU8.copyWithin(dest, src, src + num);
|
|
3759
|
+
}
|
|
3760
|
+
|
|
3761
|
+
function _emscripten_get_heap_size() {
|
|
3762
|
+
return HEAPU8.length;
|
|
3763
|
+
}
|
|
3764
|
+
|
|
3765
|
+
function emscripten_realloc_buffer(size) {
|
|
3766
|
+
try {
|
|
3767
|
+
// round size grow request up to wasm page size (fixed 64KB per spec)
|
|
3768
|
+
wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16); // .grow() takes a delta compared to the previous size
|
|
3769
|
+
updateGlobalBufferAndViews(wasmMemory.buffer);
|
|
3770
|
+
return 1 /*success*/;
|
|
3771
|
+
} catch(e) {
|
|
3772
|
+
}
|
|
3773
|
+
// implicit 0 return to save code size (caller will cast "undefined" into 0
|
|
3774
|
+
// anyhow)
|
|
3775
|
+
}
|
|
3776
|
+
function _emscripten_resize_heap(requestedSize) {
|
|
3777
|
+
requestedSize = requestedSize >>> 0;
|
|
3778
|
+
var oldSize = _emscripten_get_heap_size();
|
|
3779
|
+
// With pthreads, races can happen (another thread might increase the size in between), so return a failure, and let the caller retry.
|
|
3780
|
+
|
|
3781
|
+
// Memory resize rules:
|
|
3782
|
+
// 1. When resizing, always produce a resized heap that is at least 16MB (to avoid tiny heap sizes receiving lots of repeated resizes at startup)
|
|
3783
|
+
// 2. Always increase heap size to at least the requested size, rounded up to next page multiple.
|
|
3784
|
+
// 3a. If MEMORY_GROWTH_LINEAR_STEP == -1, excessively resize the heap geometrically: increase the heap size according to
|
|
3785
|
+
// MEMORY_GROWTH_GEOMETRIC_STEP factor (default +20%),
|
|
3786
|
+
// At most overreserve by MEMORY_GROWTH_GEOMETRIC_CAP bytes (default 96MB).
|
|
3787
|
+
// 3b. If MEMORY_GROWTH_LINEAR_STEP != -1, excessively resize the heap linearly: increase the heap size by at least MEMORY_GROWTH_LINEAR_STEP bytes.
|
|
3788
|
+
// 4. Max size for the heap is capped at 2048MB-WASM_PAGE_SIZE, or by MAXIMUM_MEMORY, or by ASAN limit, depending on which is smallest
|
|
3789
|
+
// 5. If we were unable to allocate as much memory, it may be due to over-eager decision to excessively reserve due to (3) above.
|
|
3790
|
+
// Hence if an allocation fails, cut down on the amount of excess growth, in an attempt to succeed to perform a smaller allocation.
|
|
3791
|
+
|
|
3792
|
+
// A limit was set for how much we can grow. We should not exceed that
|
|
3793
|
+
// (the wasm binary specifies it, so if we tried, we'd fail anyhow).
|
|
3794
|
+
var maxHeapSize = 2147483648;
|
|
3795
|
+
if (requestedSize > maxHeapSize) {
|
|
3796
|
+
return false;
|
|
3797
|
+
}
|
|
3798
|
+
|
|
3799
|
+
var minHeapSize = 16777216;
|
|
3800
|
+
|
|
3801
|
+
// Loop through potential heap size increases. If we attempt a too eager reservation that fails, cut down on the
|
|
3802
|
+
// attempted size and reserve a smaller bump instead. (max 3 times, chosen somewhat arbitrarily)
|
|
3803
|
+
for(var cutDown = 1; cutDown <= 4; cutDown *= 2) {
|
|
3804
|
+
var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown); // ensure geometric growth
|
|
3805
|
+
// but limit overreserving (default to capping at +96MB overgrowth at most)
|
|
3806
|
+
overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296 );
|
|
3807
|
+
|
|
3808
|
+
var newSize = Math.min(maxHeapSize, alignUp(Math.max(minHeapSize, requestedSize, overGrownHeapSize), 65536));
|
|
3809
|
+
|
|
3810
|
+
var replacement = emscripten_realloc_buffer(newSize);
|
|
3811
|
+
if (replacement) {
|
|
3812
|
+
|
|
3813
|
+
return true;
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
return false;
|
|
3817
|
+
}
|
|
3818
|
+
|
|
3819
|
+
var ENV={};
|
|
3820
|
+
|
|
3821
|
+
function getExecutableName() {
|
|
3822
|
+
return thisProgram || './this.program';
|
|
3823
|
+
}
|
|
3824
|
+
function getEnvStrings() {
|
|
3825
|
+
if (!getEnvStrings.strings) {
|
|
3826
|
+
// Default values.
|
|
3827
|
+
// Browser language detection #8751
|
|
3828
|
+
var lang = ((typeof navigator === 'object' && navigator.languages && navigator.languages[0]) || 'C').replace('-', '_') + '.UTF-8';
|
|
3829
|
+
var env = {
|
|
3830
|
+
'USER': 'web_user',
|
|
3831
|
+
'LOGNAME': 'web_user',
|
|
3832
|
+
'PATH': '/',
|
|
3833
|
+
'PWD': '/',
|
|
3834
|
+
'HOME': '/home/web_user',
|
|
3835
|
+
'LANG': lang,
|
|
3836
|
+
'_': getExecutableName()
|
|
3837
|
+
};
|
|
3838
|
+
// Apply the user-provided values, if any.
|
|
3839
|
+
for (var x in ENV) {
|
|
3840
|
+
env[x] = ENV[x];
|
|
3841
|
+
}
|
|
3842
|
+
var strings = [];
|
|
3843
|
+
for (var x in env) {
|
|
3844
|
+
strings.push(x + '=' + env[x]);
|
|
3845
|
+
}
|
|
3846
|
+
getEnvStrings.strings = strings;
|
|
3847
|
+
}
|
|
3848
|
+
return getEnvStrings.strings;
|
|
3849
|
+
}
|
|
3850
|
+
function _environ_get(__environ, environ_buf) {
|
|
3851
|
+
var bufSize = 0;
|
|
3852
|
+
getEnvStrings().forEach(function(string, i) {
|
|
3853
|
+
var ptr = environ_buf + bufSize;
|
|
3854
|
+
HEAP32[(((__environ)+(i * 4))>>2)]=ptr;
|
|
3855
|
+
writeAsciiToMemory(string, ptr);
|
|
3856
|
+
bufSize += string.length + 1;
|
|
3857
|
+
});
|
|
3858
|
+
return 0;
|
|
3859
|
+
}
|
|
3860
|
+
|
|
3861
|
+
function _environ_sizes_get(penviron_count, penviron_buf_size) {
|
|
3862
|
+
var strings = getEnvStrings();
|
|
3863
|
+
HEAP32[((penviron_count)>>2)]=strings.length;
|
|
3864
|
+
var bufSize = 0;
|
|
3865
|
+
strings.forEach(function(string) {
|
|
3866
|
+
bufSize += string.length + 1;
|
|
3867
|
+
});
|
|
3868
|
+
HEAP32[((penviron_buf_size)>>2)]=bufSize;
|
|
3869
|
+
return 0;
|
|
3870
|
+
}
|
|
3871
|
+
|
|
3872
|
+
function _fd_close(fd) {
|
|
3873
|
+
return 0;
|
|
3874
|
+
}
|
|
3875
|
+
|
|
3876
|
+
function _fd_fdstat_get(fd, pbuf) {
|
|
3877
|
+
// hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
|
|
3878
|
+
var type = fd == 1 || fd == 2 ? 2 : abort();
|
|
3879
|
+
HEAP8[((pbuf)>>0)]=type;
|
|
3880
|
+
// TODO HEAP16[(((pbuf)+(2))>>1)]=?;
|
|
3881
|
+
// TODO (tempI64 = [?>>>0,(tempDouble=?,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math.min((+(Math.floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[(((pbuf)+(8))>>2)]=tempI64[0],HEAP32[(((pbuf)+(12))>>2)]=tempI64[1]);
|
|
3882
|
+
// TODO (tempI64 = [?>>>0,(tempDouble=?,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math.min((+(Math.floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[(((pbuf)+(16))>>2)]=tempI64[0],HEAP32[(((pbuf)+(20))>>2)]=tempI64[1]);
|
|
3883
|
+
return 0;
|
|
3884
|
+
}
|
|
3885
|
+
|
|
3886
|
+
function _fd_read(fd, iov, iovcnt, pnum) {
|
|
3887
|
+
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
3888
|
+
var num = SYSCALLS.doReadv(stream, iov, iovcnt);
|
|
3889
|
+
HEAP32[((pnum)>>2)]=num
|
|
3890
|
+
return 0;
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3893
|
+
function _fd_seek(fd, offset_low, offset_high, whence, newOffset) {
|
|
3894
|
+
}
|
|
3895
|
+
|
|
3896
|
+
function flush_NO_FILESYSTEM() {
|
|
3897
|
+
// flush anything remaining in the buffers during shutdown
|
|
3898
|
+
if (typeof _fflush !== 'undefined') _fflush(0);
|
|
3899
|
+
var buffers = SYSCALLS.buffers;
|
|
3900
|
+
if (buffers[1].length) SYSCALLS.printChar(1, 10);
|
|
3901
|
+
if (buffers[2].length) SYSCALLS.printChar(2, 10);
|
|
3902
|
+
}
|
|
3903
|
+
function _fd_write(fd, iov, iovcnt, pnum) {
|
|
3904
|
+
// hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
|
|
3905
|
+
var num = 0;
|
|
3906
|
+
for (var i = 0; i < iovcnt; i++) {
|
|
3907
|
+
var ptr = HEAP32[(((iov)+(i*8))>>2)];
|
|
3908
|
+
var len = HEAP32[(((iov)+(i*8 + 4))>>2)];
|
|
3909
|
+
for (var j = 0; j < len; j++) {
|
|
3910
|
+
SYSCALLS.printChar(fd, HEAPU8[ptr+j]);
|
|
3911
|
+
}
|
|
3912
|
+
num += len;
|
|
3913
|
+
}
|
|
3914
|
+
HEAP32[((pnum)>>2)]=num
|
|
3915
|
+
return 0;
|
|
3916
|
+
}
|
|
3917
|
+
|
|
3918
|
+
function _gettimeofday(ptr) {
|
|
3919
|
+
var now = Date.now();
|
|
3920
|
+
HEAP32[((ptr)>>2)]=(now/1000)|0; // seconds
|
|
3921
|
+
HEAP32[(((ptr)+(4))>>2)]=((now % 1000)*1000)|0; // microseconds
|
|
3922
|
+
return 0;
|
|
3923
|
+
}
|
|
3924
|
+
|
|
3925
|
+
function _tzset() {
|
|
3926
|
+
// TODO: Use (malleable) environment variables instead of system settings.
|
|
3927
|
+
if (_tzset.called) return;
|
|
3928
|
+
_tzset.called = true;
|
|
3929
|
+
|
|
3930
|
+
var currentYear = new Date().getFullYear();
|
|
3931
|
+
var winter = new Date(currentYear, 0, 1);
|
|
3932
|
+
var summer = new Date(currentYear, 6, 1);
|
|
3933
|
+
var winterOffset = winter.getTimezoneOffset();
|
|
3934
|
+
var summerOffset = summer.getTimezoneOffset();
|
|
3935
|
+
|
|
3936
|
+
// Local standard timezone offset. Local standard time is not adjusted for daylight savings.
|
|
3937
|
+
// This code uses the fact that getTimezoneOffset returns a greater value during Standard Time versus Daylight Saving Time (DST).
|
|
3938
|
+
// Thus it determines the expected output during Standard Time, and it compares whether the output of the given date the same (Standard) or less (DST).
|
|
3939
|
+
var stdTimezoneOffset = Math.max(winterOffset, summerOffset);
|
|
3940
|
+
|
|
3941
|
+
// timezone is specified as seconds west of UTC ("The external variable
|
|
3942
|
+
// `timezone` shall be set to the difference, in seconds, between
|
|
3943
|
+
// Coordinated Universal Time (UTC) and local standard time."), the same
|
|
3944
|
+
// as returned by stdTimezoneOffset.
|
|
3945
|
+
// See http://pubs.opengroup.org/onlinepubs/009695399/functions/tzset.html
|
|
3946
|
+
HEAP32[((__get_timezone())>>2)]=stdTimezoneOffset * 60;
|
|
3947
|
+
|
|
3948
|
+
HEAP32[((__get_daylight())>>2)]=Number(winterOffset != summerOffset);
|
|
3949
|
+
|
|
3950
|
+
function extractZone(date) {
|
|
3951
|
+
var match = date.toTimeString().match(/\(([A-Za-z ]+)\)$/);
|
|
3952
|
+
return match ? match[1] : "GMT";
|
|
3953
|
+
};
|
|
3954
|
+
var winterName = extractZone(winter);
|
|
3955
|
+
var summerName = extractZone(summer);
|
|
3956
|
+
var winterNamePtr = allocateUTF8(winterName);
|
|
3957
|
+
var summerNamePtr = allocateUTF8(summerName);
|
|
3958
|
+
if (summerOffset < winterOffset) {
|
|
3959
|
+
// Northern hemisphere
|
|
3960
|
+
HEAP32[((__get_tzname())>>2)]=winterNamePtr;
|
|
3961
|
+
HEAP32[(((__get_tzname())+(4))>>2)]=summerNamePtr;
|
|
3962
|
+
} else {
|
|
3963
|
+
HEAP32[((__get_tzname())>>2)]=summerNamePtr;
|
|
3964
|
+
HEAP32[(((__get_tzname())+(4))>>2)]=winterNamePtr;
|
|
3965
|
+
}
|
|
3966
|
+
}
|
|
3967
|
+
function _localtime_r(time, tmPtr) {
|
|
3968
|
+
_tzset();
|
|
3969
|
+
var date = new Date(HEAP32[((time)>>2)]*1000);
|
|
3970
|
+
HEAP32[((tmPtr)>>2)]=date.getSeconds();
|
|
3971
|
+
HEAP32[(((tmPtr)+(4))>>2)]=date.getMinutes();
|
|
3972
|
+
HEAP32[(((tmPtr)+(8))>>2)]=date.getHours();
|
|
3973
|
+
HEAP32[(((tmPtr)+(12))>>2)]=date.getDate();
|
|
3974
|
+
HEAP32[(((tmPtr)+(16))>>2)]=date.getMonth();
|
|
3975
|
+
HEAP32[(((tmPtr)+(20))>>2)]=date.getFullYear()-1900;
|
|
3976
|
+
HEAP32[(((tmPtr)+(24))>>2)]=date.getDay();
|
|
3977
|
+
|
|
3978
|
+
var start = new Date(date.getFullYear(), 0, 1);
|
|
3979
|
+
var yday = ((date.getTime() - start.getTime()) / (1000 * 60 * 60 * 24))|0;
|
|
3980
|
+
HEAP32[(((tmPtr)+(28))>>2)]=yday;
|
|
3981
|
+
HEAP32[(((tmPtr)+(36))>>2)]=-(date.getTimezoneOffset() * 60);
|
|
3982
|
+
|
|
3983
|
+
// Attention: DST is in December in South, and some regions don't have DST at all.
|
|
3984
|
+
var summerOffset = new Date(date.getFullYear(), 6, 1).getTimezoneOffset();
|
|
3985
|
+
var winterOffset = start.getTimezoneOffset();
|
|
3986
|
+
var dst = (summerOffset != winterOffset && date.getTimezoneOffset() == Math.min(winterOffset, summerOffset))|0;
|
|
3987
|
+
HEAP32[(((tmPtr)+(32))>>2)]=dst;
|
|
3988
|
+
|
|
3989
|
+
var zonePtr = HEAP32[(((__get_tzname())+(dst ? 4 : 0))>>2)];
|
|
3990
|
+
HEAP32[(((tmPtr)+(40))>>2)]=zonePtr;
|
|
3991
|
+
|
|
3992
|
+
return tmPtr;
|
|
3993
|
+
}
|
|
3994
|
+
|
|
3995
|
+
function _pthread_create() {
|
|
3996
|
+
return 6;
|
|
3997
|
+
}
|
|
3998
|
+
|
|
3999
|
+
function _pthread_join() {
|
|
4000
|
+
return 28;
|
|
4001
|
+
}
|
|
4002
|
+
|
|
4003
|
+
function _setTempRet0($i) {
|
|
4004
|
+
setTempRet0(($i) | 0);
|
|
4005
|
+
}
|
|
4006
|
+
|
|
4007
|
+
function __isLeapYear(year) {
|
|
4008
|
+
return year%4 === 0 && (year%100 !== 0 || year%400 === 0);
|
|
4009
|
+
}
|
|
4010
|
+
|
|
4011
|
+
function __arraySum(array, index) {
|
|
4012
|
+
var sum = 0;
|
|
4013
|
+
for (var i = 0; i <= index; sum += array[i++]) {
|
|
4014
|
+
// no-op
|
|
4015
|
+
}
|
|
4016
|
+
return sum;
|
|
4017
|
+
}
|
|
4018
|
+
|
|
4019
|
+
var __MONTH_DAYS_LEAP=[31,29,31,30,31,30,31,31,30,31,30,31];
|
|
4020
|
+
|
|
4021
|
+
var __MONTH_DAYS_REGULAR=[31,28,31,30,31,30,31,31,30,31,30,31];
|
|
4022
|
+
function __addDays(date, days) {
|
|
4023
|
+
var newDate = new Date(date.getTime());
|
|
4024
|
+
while(days > 0) {
|
|
4025
|
+
var leap = __isLeapYear(newDate.getFullYear());
|
|
4026
|
+
var currentMonth = newDate.getMonth();
|
|
4027
|
+
var daysInCurrentMonth = (leap ? __MONTH_DAYS_LEAP : __MONTH_DAYS_REGULAR)[currentMonth];
|
|
4028
|
+
|
|
4029
|
+
if (days > daysInCurrentMonth-newDate.getDate()) {
|
|
4030
|
+
// we spill over to next month
|
|
4031
|
+
days -= (daysInCurrentMonth-newDate.getDate()+1);
|
|
4032
|
+
newDate.setDate(1);
|
|
4033
|
+
if (currentMonth < 11) {
|
|
4034
|
+
newDate.setMonth(currentMonth+1)
|
|
4035
|
+
} else {
|
|
4036
|
+
newDate.setMonth(0);
|
|
4037
|
+
newDate.setFullYear(newDate.getFullYear()+1);
|
|
4038
|
+
}
|
|
4039
|
+
} else {
|
|
4040
|
+
// we stay in current month
|
|
4041
|
+
newDate.setDate(newDate.getDate()+days);
|
|
4042
|
+
return newDate;
|
|
4043
|
+
}
|
|
4044
|
+
}
|
|
4045
|
+
|
|
4046
|
+
return newDate;
|
|
4047
|
+
}
|
|
4048
|
+
function _strftime(s, maxsize, format, tm) {
|
|
4049
|
+
// size_t strftime(char *restrict s, size_t maxsize, const char *restrict format, const struct tm *restrict timeptr);
|
|
4050
|
+
// http://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html
|
|
4051
|
+
|
|
4052
|
+
var tm_zone = HEAP32[(((tm)+(40))>>2)];
|
|
4053
|
+
|
|
4054
|
+
var date = {
|
|
4055
|
+
tm_sec: HEAP32[((tm)>>2)],
|
|
4056
|
+
tm_min: HEAP32[(((tm)+(4))>>2)],
|
|
4057
|
+
tm_hour: HEAP32[(((tm)+(8))>>2)],
|
|
4058
|
+
tm_mday: HEAP32[(((tm)+(12))>>2)],
|
|
4059
|
+
tm_mon: HEAP32[(((tm)+(16))>>2)],
|
|
4060
|
+
tm_year: HEAP32[(((tm)+(20))>>2)],
|
|
4061
|
+
tm_wday: HEAP32[(((tm)+(24))>>2)],
|
|
4062
|
+
tm_yday: HEAP32[(((tm)+(28))>>2)],
|
|
4063
|
+
tm_isdst: HEAP32[(((tm)+(32))>>2)],
|
|
4064
|
+
tm_gmtoff: HEAP32[(((tm)+(36))>>2)],
|
|
4065
|
+
tm_zone: tm_zone ? UTF8ToString(tm_zone) : ''
|
|
4066
|
+
};
|
|
4067
|
+
|
|
4068
|
+
var pattern = UTF8ToString(format);
|
|
4069
|
+
|
|
4070
|
+
// expand format
|
|
4071
|
+
var EXPANSION_RULES_1 = {
|
|
4072
|
+
'%c': '%a %b %d %H:%M:%S %Y', // Replaced by the locale's appropriate date and time representation - e.g., Mon Aug 3 14:02:01 2013
|
|
4073
|
+
'%D': '%m/%d/%y', // Equivalent to %m / %d / %y
|
|
4074
|
+
'%F': '%Y-%m-%d', // Equivalent to %Y - %m - %d
|
|
4075
|
+
'%h': '%b', // Equivalent to %b
|
|
4076
|
+
'%r': '%I:%M:%S %p', // Replaced by the time in a.m. and p.m. notation
|
|
4077
|
+
'%R': '%H:%M', // Replaced by the time in 24-hour notation
|
|
4078
|
+
'%T': '%H:%M:%S', // Replaced by the time
|
|
4079
|
+
'%x': '%m/%d/%y', // Replaced by the locale's appropriate date representation
|
|
4080
|
+
'%X': '%H:%M:%S', // Replaced by the locale's appropriate time representation
|
|
4081
|
+
// Modified Conversion Specifiers
|
|
4082
|
+
'%Ec': '%c', // Replaced by the locale's alternative appropriate date and time representation.
|
|
4083
|
+
'%EC': '%C', // Replaced by the name of the base year (period) in the locale's alternative representation.
|
|
4084
|
+
'%Ex': '%m/%d/%y', // Replaced by the locale's alternative date representation.
|
|
4085
|
+
'%EX': '%H:%M:%S', // Replaced by the locale's alternative time representation.
|
|
4086
|
+
'%Ey': '%y', // Replaced by the offset from %EC (year only) in the locale's alternative representation.
|
|
4087
|
+
'%EY': '%Y', // Replaced by the full alternative year representation.
|
|
4088
|
+
'%Od': '%d', // Replaced by the day of the month, using the locale's alternative numeric symbols, filled as needed with leading zeros if there is any alternative symbol for zero; otherwise, with leading <space> characters.
|
|
4089
|
+
'%Oe': '%e', // Replaced by the day of the month, using the locale's alternative numeric symbols, filled as needed with leading <space> characters.
|
|
4090
|
+
'%OH': '%H', // Replaced by the hour (24-hour clock) using the locale's alternative numeric symbols.
|
|
4091
|
+
'%OI': '%I', // Replaced by the hour (12-hour clock) using the locale's alternative numeric symbols.
|
|
4092
|
+
'%Om': '%m', // Replaced by the month using the locale's alternative numeric symbols.
|
|
4093
|
+
'%OM': '%M', // Replaced by the minutes using the locale's alternative numeric symbols.
|
|
4094
|
+
'%OS': '%S', // Replaced by the seconds using the locale's alternative numeric symbols.
|
|
4095
|
+
'%Ou': '%u', // Replaced by the weekday as a number in the locale's alternative representation (Monday=1).
|
|
4096
|
+
'%OU': '%U', // Replaced by the week number of the year (Sunday as the first day of the week, rules corresponding to %U ) using the locale's alternative numeric symbols.
|
|
4097
|
+
'%OV': '%V', // Replaced by the week number of the year (Monday as the first day of the week, rules corresponding to %V ) using the locale's alternative numeric symbols.
|
|
4098
|
+
'%Ow': '%w', // Replaced by the number of the weekday (Sunday=0) using the locale's alternative numeric symbols.
|
|
4099
|
+
'%OW': '%W', // Replaced by the week number of the year (Monday as the first day of the week) using the locale's alternative numeric symbols.
|
|
4100
|
+
'%Oy': '%y', // Replaced by the year (offset from %C ) using the locale's alternative numeric symbols.
|
|
4101
|
+
};
|
|
4102
|
+
for (var rule in EXPANSION_RULES_1) {
|
|
4103
|
+
pattern = pattern.replace(new RegExp(rule, 'g'), EXPANSION_RULES_1[rule]);
|
|
4104
|
+
}
|
|
4105
|
+
|
|
4106
|
+
var WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
4107
|
+
var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
4108
|
+
|
|
4109
|
+
function leadingSomething(value, digits, character) {
|
|
4110
|
+
var str = typeof value === 'number' ? value.toString() : (value || '');
|
|
4111
|
+
while (str.length < digits) {
|
|
4112
|
+
str = character[0]+str;
|
|
4113
|
+
}
|
|
4114
|
+
return str;
|
|
4115
|
+
}
|
|
4116
|
+
|
|
4117
|
+
function leadingNulls(value, digits) {
|
|
4118
|
+
return leadingSomething(value, digits, '0');
|
|
4119
|
+
}
|
|
4120
|
+
|
|
4121
|
+
function compareByDay(date1, date2) {
|
|
4122
|
+
function sgn(value) {
|
|
4123
|
+
return value < 0 ? -1 : (value > 0 ? 1 : 0);
|
|
4124
|
+
}
|
|
4125
|
+
|
|
4126
|
+
var compare;
|
|
4127
|
+
if ((compare = sgn(date1.getFullYear()-date2.getFullYear())) === 0) {
|
|
4128
|
+
if ((compare = sgn(date1.getMonth()-date2.getMonth())) === 0) {
|
|
4129
|
+
compare = sgn(date1.getDate()-date2.getDate());
|
|
4130
|
+
}
|
|
4131
|
+
}
|
|
4132
|
+
return compare;
|
|
4133
|
+
}
|
|
4134
|
+
|
|
4135
|
+
function getFirstWeekStartDate(janFourth) {
|
|
4136
|
+
switch (janFourth.getDay()) {
|
|
4137
|
+
case 0: // Sunday
|
|
4138
|
+
return new Date(janFourth.getFullYear()-1, 11, 29);
|
|
4139
|
+
case 1: // Monday
|
|
4140
|
+
return janFourth;
|
|
4141
|
+
case 2: // Tuesday
|
|
4142
|
+
return new Date(janFourth.getFullYear(), 0, 3);
|
|
4143
|
+
case 3: // Wednesday
|
|
4144
|
+
return new Date(janFourth.getFullYear(), 0, 2);
|
|
4145
|
+
case 4: // Thursday
|
|
4146
|
+
return new Date(janFourth.getFullYear(), 0, 1);
|
|
4147
|
+
case 5: // Friday
|
|
4148
|
+
return new Date(janFourth.getFullYear()-1, 11, 31);
|
|
4149
|
+
case 6: // Saturday
|
|
4150
|
+
return new Date(janFourth.getFullYear()-1, 11, 30);
|
|
4151
|
+
}
|
|
4152
|
+
}
|
|
4153
|
+
|
|
4154
|
+
function getWeekBasedYear(date) {
|
|
4155
|
+
var thisDate = __addDays(new Date(date.tm_year+1900, 0, 1), date.tm_yday);
|
|
4156
|
+
|
|
4157
|
+
var janFourthThisYear = new Date(thisDate.getFullYear(), 0, 4);
|
|
4158
|
+
var janFourthNextYear = new Date(thisDate.getFullYear()+1, 0, 4);
|
|
4159
|
+
|
|
4160
|
+
var firstWeekStartThisYear = getFirstWeekStartDate(janFourthThisYear);
|
|
4161
|
+
var firstWeekStartNextYear = getFirstWeekStartDate(janFourthNextYear);
|
|
4162
|
+
|
|
4163
|
+
if (compareByDay(firstWeekStartThisYear, thisDate) <= 0) {
|
|
4164
|
+
// this date is after the start of the first week of this year
|
|
4165
|
+
if (compareByDay(firstWeekStartNextYear, thisDate) <= 0) {
|
|
4166
|
+
return thisDate.getFullYear()+1;
|
|
4167
|
+
} else {
|
|
4168
|
+
return thisDate.getFullYear();
|
|
4169
|
+
}
|
|
4170
|
+
} else {
|
|
4171
|
+
return thisDate.getFullYear()-1;
|
|
4172
|
+
}
|
|
4173
|
+
}
|
|
4174
|
+
|
|
4175
|
+
var EXPANSION_RULES_2 = {
|
|
4176
|
+
'%a': function(date) {
|
|
4177
|
+
return WEEKDAYS[date.tm_wday].substring(0,3);
|
|
4178
|
+
},
|
|
4179
|
+
'%A': function(date) {
|
|
4180
|
+
return WEEKDAYS[date.tm_wday];
|
|
4181
|
+
},
|
|
4182
|
+
'%b': function(date) {
|
|
4183
|
+
return MONTHS[date.tm_mon].substring(0,3);
|
|
4184
|
+
},
|
|
4185
|
+
'%B': function(date) {
|
|
4186
|
+
return MONTHS[date.tm_mon];
|
|
4187
|
+
},
|
|
4188
|
+
'%C': function(date) {
|
|
4189
|
+
var year = date.tm_year+1900;
|
|
4190
|
+
return leadingNulls((year/100)|0,2);
|
|
4191
|
+
},
|
|
4192
|
+
'%d': function(date) {
|
|
4193
|
+
return leadingNulls(date.tm_mday, 2);
|
|
4194
|
+
},
|
|
4195
|
+
'%e': function(date) {
|
|
4196
|
+
return leadingSomething(date.tm_mday, 2, ' ');
|
|
4197
|
+
},
|
|
4198
|
+
'%g': function(date) {
|
|
4199
|
+
// %g, %G, and %V give values according to the ISO 8601:2000 standard week-based year.
|
|
4200
|
+
// In this system, weeks begin on a Monday and week 1 of the year is the week that includes
|
|
4201
|
+
// January 4th, which is also the week that includes the first Thursday of the year, and
|
|
4202
|
+
// is also the first week that contains at least four days in the year.
|
|
4203
|
+
// If the first Monday of January is the 2nd, 3rd, or 4th, the preceding days are part of
|
|
4204
|
+
// the last week of the preceding year; thus, for Saturday 2nd January 1999,
|
|
4205
|
+
// %G is replaced by 1998 and %V is replaced by 53. If December 29th, 30th,
|
|
4206
|
+
// or 31st is a Monday, it and any following days are part of week 1 of the following year.
|
|
4207
|
+
// Thus, for Tuesday 30th December 1997, %G is replaced by 1998 and %V is replaced by 01.
|
|
4208
|
+
|
|
4209
|
+
return getWeekBasedYear(date).toString().substring(2);
|
|
4210
|
+
},
|
|
4211
|
+
'%G': function(date) {
|
|
4212
|
+
return getWeekBasedYear(date);
|
|
4213
|
+
},
|
|
4214
|
+
'%H': function(date) {
|
|
4215
|
+
return leadingNulls(date.tm_hour, 2);
|
|
4216
|
+
},
|
|
4217
|
+
'%I': function(date) {
|
|
4218
|
+
var twelveHour = date.tm_hour;
|
|
4219
|
+
if (twelveHour == 0) twelveHour = 12;
|
|
4220
|
+
else if (twelveHour > 12) twelveHour -= 12;
|
|
4221
|
+
return leadingNulls(twelveHour, 2);
|
|
4222
|
+
},
|
|
4223
|
+
'%j': function(date) {
|
|
4224
|
+
// Day of the year (001-366)
|
|
4225
|
+
return leadingNulls(date.tm_mday+__arraySum(__isLeapYear(date.tm_year+1900) ? __MONTH_DAYS_LEAP : __MONTH_DAYS_REGULAR, date.tm_mon-1), 3);
|
|
4226
|
+
},
|
|
4227
|
+
'%m': function(date) {
|
|
4228
|
+
return leadingNulls(date.tm_mon+1, 2);
|
|
4229
|
+
},
|
|
4230
|
+
'%M': function(date) {
|
|
4231
|
+
return leadingNulls(date.tm_min, 2);
|
|
4232
|
+
},
|
|
4233
|
+
'%n': function() {
|
|
4234
|
+
return '\n';
|
|
4235
|
+
},
|
|
4236
|
+
'%p': function(date) {
|
|
4237
|
+
if (date.tm_hour >= 0 && date.tm_hour < 12) {
|
|
4238
|
+
return 'AM';
|
|
4239
|
+
} else {
|
|
4240
|
+
return 'PM';
|
|
4241
|
+
}
|
|
4242
|
+
},
|
|
4243
|
+
'%S': function(date) {
|
|
4244
|
+
return leadingNulls(date.tm_sec, 2);
|
|
4245
|
+
},
|
|
4246
|
+
'%t': function() {
|
|
4247
|
+
return '\t';
|
|
4248
|
+
},
|
|
4249
|
+
'%u': function(date) {
|
|
4250
|
+
return date.tm_wday || 7;
|
|
4251
|
+
},
|
|
4252
|
+
'%U': function(date) {
|
|
4253
|
+
// Replaced by the week number of the year as a decimal number [00,53].
|
|
4254
|
+
// The first Sunday of January is the first day of week 1;
|
|
4255
|
+
// days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
|
|
4256
|
+
var janFirst = new Date(date.tm_year+1900, 0, 1);
|
|
4257
|
+
var firstSunday = janFirst.getDay() === 0 ? janFirst : __addDays(janFirst, 7-janFirst.getDay());
|
|
4258
|
+
var endDate = new Date(date.tm_year+1900, date.tm_mon, date.tm_mday);
|
|
4259
|
+
|
|
4260
|
+
// is target date after the first Sunday?
|
|
4261
|
+
if (compareByDay(firstSunday, endDate) < 0) {
|
|
4262
|
+
// calculate difference in days between first Sunday and endDate
|
|
4263
|
+
var februaryFirstUntilEndMonth = __arraySum(__isLeapYear(endDate.getFullYear()) ? __MONTH_DAYS_LEAP : __MONTH_DAYS_REGULAR, endDate.getMonth()-1)-31;
|
|
4264
|
+
var firstSundayUntilEndJanuary = 31-firstSunday.getDate();
|
|
4265
|
+
var days = firstSundayUntilEndJanuary+februaryFirstUntilEndMonth+endDate.getDate();
|
|
4266
|
+
return leadingNulls(Math.ceil(days/7), 2);
|
|
4267
|
+
}
|
|
4268
|
+
|
|
4269
|
+
return compareByDay(firstSunday, janFirst) === 0 ? '01': '00';
|
|
4270
|
+
},
|
|
4271
|
+
'%V': function(date) {
|
|
4272
|
+
// Replaced by the week number of the year (Monday as the first day of the week)
|
|
4273
|
+
// as a decimal number [01,53]. If the week containing 1 January has four
|
|
4274
|
+
// or more days in the new year, then it is considered week 1.
|
|
4275
|
+
// Otherwise, it is the last week of the previous year, and the next week is week 1.
|
|
4276
|
+
// Both January 4th and the first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday]
|
|
4277
|
+
var janFourthThisYear = new Date(date.tm_year+1900, 0, 4);
|
|
4278
|
+
var janFourthNextYear = new Date(date.tm_year+1901, 0, 4);
|
|
4279
|
+
|
|
4280
|
+
var firstWeekStartThisYear = getFirstWeekStartDate(janFourthThisYear);
|
|
4281
|
+
var firstWeekStartNextYear = getFirstWeekStartDate(janFourthNextYear);
|
|
4282
|
+
|
|
4283
|
+
var endDate = __addDays(new Date(date.tm_year+1900, 0, 1), date.tm_yday);
|
|
4284
|
+
|
|
4285
|
+
if (compareByDay(endDate, firstWeekStartThisYear) < 0) {
|
|
4286
|
+
// if given date is before this years first week, then it belongs to the 53rd week of last year
|
|
4287
|
+
return '53';
|
|
4288
|
+
}
|
|
4289
|
+
|
|
4290
|
+
if (compareByDay(firstWeekStartNextYear, endDate) <= 0) {
|
|
4291
|
+
// if given date is after next years first week, then it belongs to the 01th week of next year
|
|
4292
|
+
return '01';
|
|
4293
|
+
}
|
|
4294
|
+
|
|
4295
|
+
// given date is in between CW 01..53 of this calendar year
|
|
4296
|
+
var daysDifference;
|
|
4297
|
+
if (firstWeekStartThisYear.getFullYear() < date.tm_year+1900) {
|
|
4298
|
+
// first CW of this year starts last year
|
|
4299
|
+
daysDifference = date.tm_yday+32-firstWeekStartThisYear.getDate()
|
|
4300
|
+
} else {
|
|
4301
|
+
// first CW of this year starts this year
|
|
4302
|
+
daysDifference = date.tm_yday+1-firstWeekStartThisYear.getDate();
|
|
4303
|
+
}
|
|
4304
|
+
return leadingNulls(Math.ceil(daysDifference/7), 2);
|
|
4305
|
+
},
|
|
4306
|
+
'%w': function(date) {
|
|
4307
|
+
return date.tm_wday;
|
|
4308
|
+
},
|
|
4309
|
+
'%W': function(date) {
|
|
4310
|
+
// Replaced by the week number of the year as a decimal number [00,53].
|
|
4311
|
+
// The first Monday of January is the first day of week 1;
|
|
4312
|
+
// days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
|
|
4313
|
+
var janFirst = new Date(date.tm_year, 0, 1);
|
|
4314
|
+
var firstMonday = janFirst.getDay() === 1 ? janFirst : __addDays(janFirst, janFirst.getDay() === 0 ? 1 : 7-janFirst.getDay()+1);
|
|
4315
|
+
var endDate = new Date(date.tm_year+1900, date.tm_mon, date.tm_mday);
|
|
4316
|
+
|
|
4317
|
+
// is target date after the first Monday?
|
|
4318
|
+
if (compareByDay(firstMonday, endDate) < 0) {
|
|
4319
|
+
var februaryFirstUntilEndMonth = __arraySum(__isLeapYear(endDate.getFullYear()) ? __MONTH_DAYS_LEAP : __MONTH_DAYS_REGULAR, endDate.getMonth()-1)-31;
|
|
4320
|
+
var firstMondayUntilEndJanuary = 31-firstMonday.getDate();
|
|
4321
|
+
var days = firstMondayUntilEndJanuary+februaryFirstUntilEndMonth+endDate.getDate();
|
|
4322
|
+
return leadingNulls(Math.ceil(days/7), 2);
|
|
4323
|
+
}
|
|
4324
|
+
return compareByDay(firstMonday, janFirst) === 0 ? '01': '00';
|
|
4325
|
+
},
|
|
4326
|
+
'%y': function(date) {
|
|
4327
|
+
// Replaced by the last two digits of the year as a decimal number [00,99]. [ tm_year]
|
|
4328
|
+
return (date.tm_year+1900).toString().substring(2);
|
|
4329
|
+
},
|
|
4330
|
+
'%Y': function(date) {
|
|
4331
|
+
// Replaced by the year as a decimal number (for example, 1997). [ tm_year]
|
|
4332
|
+
return date.tm_year+1900;
|
|
4333
|
+
},
|
|
4334
|
+
'%z': function(date) {
|
|
4335
|
+
// Replaced by the offset from UTC in the ISO 8601:2000 standard format ( +hhmm or -hhmm ).
|
|
4336
|
+
// For example, "-0430" means 4 hours 30 minutes behind UTC (west of Greenwich).
|
|
4337
|
+
var off = date.tm_gmtoff;
|
|
4338
|
+
var ahead = off >= 0;
|
|
4339
|
+
off = Math.abs(off) / 60;
|
|
4340
|
+
// convert from minutes into hhmm format (which means 60 minutes = 100 units)
|
|
4341
|
+
off = (off / 60)*100 + (off % 60);
|
|
4342
|
+
return (ahead ? '+' : '-') + String("0000" + off).slice(-4);
|
|
4343
|
+
},
|
|
4344
|
+
'%Z': function(date) {
|
|
4345
|
+
return date.tm_zone;
|
|
4346
|
+
},
|
|
4347
|
+
'%%': function() {
|
|
4348
|
+
return '%';
|
|
4349
|
+
}
|
|
4350
|
+
};
|
|
4351
|
+
for (var rule in EXPANSION_RULES_2) {
|
|
4352
|
+
if (pattern.indexOf(rule) >= 0) {
|
|
4353
|
+
pattern = pattern.replace(new RegExp(rule, 'g'), EXPANSION_RULES_2[rule](date));
|
|
4354
|
+
}
|
|
4355
|
+
}
|
|
4356
|
+
|
|
4357
|
+
var bytes = intArrayFromString(pattern, false);
|
|
4358
|
+
if (bytes.length > maxsize) {
|
|
4359
|
+
return 0;
|
|
4360
|
+
}
|
|
4361
|
+
|
|
4362
|
+
writeArrayToMemory(bytes, s);
|
|
4363
|
+
return bytes.length-1;
|
|
4364
|
+
}
|
|
4365
|
+
function _strftime_l(s, maxsize, format, tm) {
|
|
4366
|
+
return _strftime(s, maxsize, format, tm); // no locale support yet
|
|
4367
|
+
}
|
|
4368
|
+
InternalError = Module['InternalError'] = extendError(Error, 'InternalError');;
|
|
4369
|
+
embind_init_charCodes();
|
|
4370
|
+
BindingError = Module['BindingError'] = extendError(Error, 'BindingError');;
|
|
4371
|
+
init_ClassHandle();
|
|
4372
|
+
init_RegisteredPointer();
|
|
4373
|
+
init_embind();;
|
|
4374
|
+
UnboundTypeError = Module['UnboundTypeError'] = extendError(Error, 'UnboundTypeError');;
|
|
4375
|
+
init_emval();;
|
|
4376
|
+
var ASSERTIONS = false;
|
|
4377
|
+
|
|
4378
|
+
|
|
4379
|
+
|
|
4380
|
+
/** @type {function(string, boolean=, number=)} */
|
|
4381
|
+
function intArrayFromString(stringy, dontAddNull, length) {
|
|
4382
|
+
var len = length > 0 ? length : lengthBytesUTF8(stringy)+1;
|
|
4383
|
+
var u8array = new Array(len);
|
|
4384
|
+
var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
|
|
4385
|
+
if (dontAddNull) u8array.length = numBytesWritten;
|
|
4386
|
+
return u8array;
|
|
4387
|
+
}
|
|
4388
|
+
|
|
4389
|
+
function intArrayToString(array) {
|
|
4390
|
+
var ret = [];
|
|
4391
|
+
for (var i = 0; i < array.length; i++) {
|
|
4392
|
+
var chr = array[i];
|
|
4393
|
+
if (chr > 0xFF) {
|
|
4394
|
+
if (ASSERTIONS) {
|
|
4395
|
+
assert(false, 'Character code ' + chr + ' (' + String.fromCharCode(chr) + ') at offset ' + i + ' not in 0x00-0xFF.');
|
|
4396
|
+
}
|
|
4397
|
+
chr &= 0xFF;
|
|
4398
|
+
}
|
|
4399
|
+
ret.push(String.fromCharCode(chr));
|
|
4400
|
+
}
|
|
4401
|
+
return ret.join('');
|
|
4402
|
+
}
|
|
4403
|
+
|
|
4404
|
+
|
|
4405
|
+
var asmLibraryArg = {
|
|
4406
|
+
"__assert_fail": ___assert_fail,
|
|
4407
|
+
"__cxa_atexit": ___cxa_atexit,
|
|
4408
|
+
"__sys_access": ___sys_access,
|
|
4409
|
+
"__sys_fcntl64": ___sys_fcntl64,
|
|
4410
|
+
"__sys_fstat64": ___sys_fstat64,
|
|
4411
|
+
"__sys_getpid": ___sys_getpid,
|
|
4412
|
+
"__sys_ioctl": ___sys_ioctl,
|
|
4413
|
+
"__sys_madvise1": ___sys_madvise1,
|
|
4414
|
+
"__sys_nice": ___sys_nice,
|
|
4415
|
+
"__sys_open": ___sys_open,
|
|
4416
|
+
"__sys_rename": ___sys_rename,
|
|
4417
|
+
"__sys_stat64": ___sys_stat64,
|
|
4418
|
+
"_embind_finalize_value_array": __embind_finalize_value_array,
|
|
4419
|
+
"_embind_finalize_value_object": __embind_finalize_value_object,
|
|
4420
|
+
"_embind_register_bool": __embind_register_bool,
|
|
4421
|
+
"_embind_register_class": __embind_register_class,
|
|
4422
|
+
"_embind_register_class_class_function": __embind_register_class_class_function,
|
|
4423
|
+
"_embind_register_class_constructor": __embind_register_class_constructor,
|
|
4424
|
+
"_embind_register_class_function": __embind_register_class_function,
|
|
4425
|
+
"_embind_register_class_property": __embind_register_class_property,
|
|
4426
|
+
"_embind_register_emval": __embind_register_emval,
|
|
4427
|
+
"_embind_register_float": __embind_register_float,
|
|
4428
|
+
"_embind_register_integer": __embind_register_integer,
|
|
4429
|
+
"_embind_register_memory_view": __embind_register_memory_view,
|
|
4430
|
+
"_embind_register_std_string": __embind_register_std_string,
|
|
4431
|
+
"_embind_register_std_wstring": __embind_register_std_wstring,
|
|
4432
|
+
"_embind_register_value_array": __embind_register_value_array,
|
|
4433
|
+
"_embind_register_value_array_element": __embind_register_value_array_element,
|
|
4434
|
+
"_embind_register_value_object": __embind_register_value_object,
|
|
4435
|
+
"_embind_register_value_object_field": __embind_register_value_object_field,
|
|
4436
|
+
"_embind_register_void": __embind_register_void,
|
|
4437
|
+
"_emval_as": __emval_as,
|
|
4438
|
+
"_emval_call": __emval_call,
|
|
4439
|
+
"_emval_call_method": __emval_call_method,
|
|
4440
|
+
"_emval_call_void_method": __emval_call_void_method,
|
|
4441
|
+
"_emval_decref": __emval_decref,
|
|
4442
|
+
"_emval_delete": __emval_delete,
|
|
4443
|
+
"_emval_get_global": __emval_get_global,
|
|
4444
|
+
"_emval_get_method_caller": __emval_get_method_caller,
|
|
4445
|
+
"_emval_get_property": __emval_get_property,
|
|
4446
|
+
"_emval_incref": __emval_incref,
|
|
4447
|
+
"_emval_instanceof": __emval_instanceof,
|
|
4448
|
+
"_emval_new_array": __emval_new_array,
|
|
4449
|
+
"_emval_new_cstring": __emval_new_cstring,
|
|
4450
|
+
"_emval_not": __emval_not,
|
|
4451
|
+
"_emval_run_destructors": __emval_run_destructors,
|
|
4452
|
+
"_emval_set_property": __emval_set_property,
|
|
4453
|
+
"_emval_strictly_equals": __emval_strictly_equals,
|
|
4454
|
+
"_emval_take_value": __emval_take_value,
|
|
4455
|
+
"abort": _abort,
|
|
4456
|
+
"atexit": _atexit,
|
|
4457
|
+
"clock": _clock,
|
|
4458
|
+
"clock_gettime": _clock_gettime,
|
|
4459
|
+
"dlclose": _dlclose,
|
|
4460
|
+
"dlopen": _dlopen,
|
|
4461
|
+
"dlsym": _dlsym,
|
|
4462
|
+
"emscripten_memcpy_big": _emscripten_memcpy_big,
|
|
4463
|
+
"emscripten_resize_heap": _emscripten_resize_heap,
|
|
4464
|
+
"environ_get": _environ_get,
|
|
4465
|
+
"environ_sizes_get": _environ_sizes_get,
|
|
4466
|
+
"fd_close": _fd_close,
|
|
4467
|
+
"fd_fdstat_get": _fd_fdstat_get,
|
|
4468
|
+
"fd_read": _fd_read,
|
|
4469
|
+
"fd_seek": _fd_seek,
|
|
4470
|
+
"fd_write": _fd_write,
|
|
4471
|
+
"gettimeofday": _gettimeofday,
|
|
4472
|
+
"localtime_r": _localtime_r,
|
|
4473
|
+
"pthread_create": _pthread_create,
|
|
4474
|
+
"pthread_join": _pthread_join,
|
|
4475
|
+
"setTempRet0": _setTempRet0,
|
|
4476
|
+
"strftime_l": _strftime_l
|
|
4477
|
+
};
|
|
4478
|
+
var asm = createWasm();
|
|
4479
|
+
/** @type {function(...*):?} */
|
|
4480
|
+
var ___wasm_call_ctors = Module["___wasm_call_ctors"] = function() {
|
|
4481
|
+
return (___wasm_call_ctors = Module["___wasm_call_ctors"] = Module["asm"]["__wasm_call_ctors"]).apply(null, arguments);
|
|
4482
|
+
};
|
|
4483
|
+
|
|
4484
|
+
/** @type {function(...*):?} */
|
|
4485
|
+
var _memcpy = Module["_memcpy"] = function() {
|
|
4486
|
+
return (_memcpy = Module["_memcpy"] = Module["asm"]["memcpy"]).apply(null, arguments);
|
|
4487
|
+
};
|
|
4488
|
+
|
|
4489
|
+
/** @type {function(...*):?} */
|
|
4490
|
+
var _malloc = Module["_malloc"] = function() {
|
|
4491
|
+
return (_malloc = Module["_malloc"] = Module["asm"]["malloc"]).apply(null, arguments);
|
|
4492
|
+
};
|
|
4493
|
+
|
|
4494
|
+
/** @type {function(...*):?} */
|
|
4495
|
+
var _free = Module["_free"] = function() {
|
|
4496
|
+
return (_free = Module["_free"] = Module["asm"]["free"]).apply(null, arguments);
|
|
4497
|
+
};
|
|
4498
|
+
|
|
4499
|
+
/** @type {function(...*):?} */
|
|
4500
|
+
var _memset = Module["_memset"] = function() {
|
|
4501
|
+
return (_memset = Module["_memset"] = Module["asm"]["memset"]).apply(null, arguments);
|
|
4502
|
+
};
|
|
4503
|
+
|
|
4504
|
+
/** @type {function(...*):?} */
|
|
4505
|
+
var ___errno_location = Module["___errno_location"] = function() {
|
|
4506
|
+
return (___errno_location = Module["___errno_location"] = Module["asm"]["__errno_location"]).apply(null, arguments);
|
|
4507
|
+
};
|
|
4508
|
+
|
|
4509
|
+
/** @type {function(...*):?} */
|
|
4510
|
+
var _htons = Module["_htons"] = function() {
|
|
4511
|
+
return (_htons = Module["_htons"] = Module["asm"]["htons"]).apply(null, arguments);
|
|
4512
|
+
};
|
|
4513
|
+
|
|
4514
|
+
/** @type {function(...*):?} */
|
|
4515
|
+
var _ntohs = Module["_ntohs"] = function() {
|
|
4516
|
+
return (_ntohs = Module["_ntohs"] = Module["asm"]["ntohs"]).apply(null, arguments);
|
|
4517
|
+
};
|
|
4518
|
+
|
|
4519
|
+
/** @type {function(...*):?} */
|
|
4520
|
+
var _memalign = Module["_memalign"] = function() {
|
|
4521
|
+
return (_memalign = Module["_memalign"] = Module["asm"]["memalign"]).apply(null, arguments);
|
|
4522
|
+
};
|
|
4523
|
+
|
|
4524
|
+
/** @type {function(...*):?} */
|
|
4525
|
+
var ___getTypeName = Module["___getTypeName"] = function() {
|
|
4526
|
+
return (___getTypeName = Module["___getTypeName"] = Module["asm"]["__getTypeName"]).apply(null, arguments);
|
|
4527
|
+
};
|
|
4528
|
+
|
|
4529
|
+
/** @type {function(...*):?} */
|
|
4530
|
+
var ___embind_register_native_and_builtin_types = Module["___embind_register_native_and_builtin_types"] = function() {
|
|
4531
|
+
return (___embind_register_native_and_builtin_types = Module["___embind_register_native_and_builtin_types"] = Module["asm"]["__embind_register_native_and_builtin_types"]).apply(null, arguments);
|
|
4532
|
+
};
|
|
4533
|
+
|
|
4534
|
+
/** @type {function(...*):?} */
|
|
4535
|
+
var _htonl = Module["_htonl"] = function() {
|
|
4536
|
+
return (_htonl = Module["_htonl"] = Module["asm"]["htonl"]).apply(null, arguments);
|
|
4537
|
+
};
|
|
4538
|
+
|
|
4539
|
+
/** @type {function(...*):?} */
|
|
4540
|
+
var __get_tzname = Module["__get_tzname"] = function() {
|
|
4541
|
+
return (__get_tzname = Module["__get_tzname"] = Module["asm"]["_get_tzname"]).apply(null, arguments);
|
|
4542
|
+
};
|
|
4543
|
+
|
|
4544
|
+
/** @type {function(...*):?} */
|
|
4545
|
+
var __get_daylight = Module["__get_daylight"] = function() {
|
|
4546
|
+
return (__get_daylight = Module["__get_daylight"] = Module["asm"]["_get_daylight"]).apply(null, arguments);
|
|
4547
|
+
};
|
|
4548
|
+
|
|
4549
|
+
/** @type {function(...*):?} */
|
|
4550
|
+
var __get_timezone = Module["__get_timezone"] = function() {
|
|
4551
|
+
return (__get_timezone = Module["__get_timezone"] = Module["asm"]["_get_timezone"]).apply(null, arguments);
|
|
4552
|
+
};
|
|
4553
|
+
|
|
4554
|
+
/** @type {function(...*):?} */
|
|
4555
|
+
var _emscripten_main_thread_process_queued_calls = Module["_emscripten_main_thread_process_queued_calls"] = function() {
|
|
4556
|
+
return (_emscripten_main_thread_process_queued_calls = Module["_emscripten_main_thread_process_queued_calls"] = Module["asm"]["emscripten_main_thread_process_queued_calls"]).apply(null, arguments);
|
|
4557
|
+
};
|
|
4558
|
+
|
|
4559
|
+
/** @type {function(...*):?} */
|
|
4560
|
+
var stackSave = Module["stackSave"] = function() {
|
|
4561
|
+
return (stackSave = Module["stackSave"] = Module["asm"]["stackSave"]).apply(null, arguments);
|
|
4562
|
+
};
|
|
4563
|
+
|
|
4564
|
+
/** @type {function(...*):?} */
|
|
4565
|
+
var stackRestore = Module["stackRestore"] = function() {
|
|
4566
|
+
return (stackRestore = Module["stackRestore"] = Module["asm"]["stackRestore"]).apply(null, arguments);
|
|
4567
|
+
};
|
|
4568
|
+
|
|
4569
|
+
/** @type {function(...*):?} */
|
|
4570
|
+
var stackAlloc = Module["stackAlloc"] = function() {
|
|
4571
|
+
return (stackAlloc = Module["stackAlloc"] = Module["asm"]["stackAlloc"]).apply(null, arguments);
|
|
4572
|
+
};
|
|
4573
|
+
|
|
4574
|
+
/** @type {function(...*):?} */
|
|
4575
|
+
var dynCall_vij = Module["dynCall_vij"] = function() {
|
|
4576
|
+
return (dynCall_vij = Module["dynCall_vij"] = Module["asm"]["dynCall_vij"]).apply(null, arguments);
|
|
4577
|
+
};
|
|
4578
|
+
|
|
4579
|
+
/** @type {function(...*):?} */
|
|
4580
|
+
var dynCall_ji = Module["dynCall_ji"] = function() {
|
|
4581
|
+
return (dynCall_ji = Module["dynCall_ji"] = Module["asm"]["dynCall_ji"]).apply(null, arguments);
|
|
4582
|
+
};
|
|
4583
|
+
|
|
4584
|
+
/** @type {function(...*):?} */
|
|
4585
|
+
var dynCall_viiij = Module["dynCall_viiij"] = function() {
|
|
4586
|
+
return (dynCall_viiij = Module["dynCall_viiij"] = Module["asm"]["dynCall_viiij"]).apply(null, arguments);
|
|
4587
|
+
};
|
|
4588
|
+
|
|
4589
|
+
/** @type {function(...*):?} */
|
|
4590
|
+
var dynCall_viijii = Module["dynCall_viijii"] = function() {
|
|
4591
|
+
return (dynCall_viijii = Module["dynCall_viijii"] = Module["asm"]["dynCall_viijii"]).apply(null, arguments);
|
|
4592
|
+
};
|
|
4593
|
+
|
|
4594
|
+
/** @type {function(...*):?} */
|
|
4595
|
+
var dynCall_viij = Module["dynCall_viij"] = function() {
|
|
4596
|
+
return (dynCall_viij = Module["dynCall_viij"] = Module["asm"]["dynCall_viij"]).apply(null, arguments);
|
|
4597
|
+
};
|
|
4598
|
+
|
|
4599
|
+
/** @type {function(...*):?} */
|
|
4600
|
+
var dynCall_iij = Module["dynCall_iij"] = function() {
|
|
4601
|
+
return (dynCall_iij = Module["dynCall_iij"] = Module["asm"]["dynCall_iij"]).apply(null, arguments);
|
|
4602
|
+
};
|
|
4603
|
+
|
|
4604
|
+
/** @type {function(...*):?} */
|
|
4605
|
+
var dynCall_viji = Module["dynCall_viji"] = function() {
|
|
4606
|
+
return (dynCall_viji = Module["dynCall_viji"] = Module["asm"]["dynCall_viji"]).apply(null, arguments);
|
|
4607
|
+
};
|
|
4608
|
+
|
|
4609
|
+
/** @type {function(...*):?} */
|
|
4610
|
+
var dynCall_jiji = Module["dynCall_jiji"] = function() {
|
|
4611
|
+
return (dynCall_jiji = Module["dynCall_jiji"] = Module["asm"]["dynCall_jiji"]).apply(null, arguments);
|
|
4612
|
+
};
|
|
4613
|
+
|
|
4614
|
+
/** @type {function(...*):?} */
|
|
4615
|
+
var dynCall_iiiiij = Module["dynCall_iiiiij"] = function() {
|
|
4616
|
+
return (dynCall_iiiiij = Module["dynCall_iiiiij"] = Module["asm"]["dynCall_iiiiij"]).apply(null, arguments);
|
|
4617
|
+
};
|
|
4618
|
+
|
|
4619
|
+
/** @type {function(...*):?} */
|
|
4620
|
+
var dynCall_iiiiijj = Module["dynCall_iiiiijj"] = function() {
|
|
4621
|
+
return (dynCall_iiiiijj = Module["dynCall_iiiiijj"] = Module["asm"]["dynCall_iiiiijj"]).apply(null, arguments);
|
|
4622
|
+
};
|
|
4623
|
+
|
|
4624
|
+
/** @type {function(...*):?} */
|
|
4625
|
+
var dynCall_iiiiiijj = Module["dynCall_iiiiiijj"] = function() {
|
|
4626
|
+
return (dynCall_iiiiiijj = Module["dynCall_iiiiiijj"] = Module["asm"]["dynCall_iiiiiijj"]).apply(null, arguments);
|
|
4627
|
+
};
|
|
4628
|
+
|
|
4629
|
+
/** @type {function(...*):?} */
|
|
4630
|
+
var dynCall_jii = Module["dynCall_jii"] = function() {
|
|
4631
|
+
return (dynCall_jii = Module["dynCall_jii"] = Module["asm"]["dynCall_jii"]).apply(null, arguments);
|
|
4632
|
+
};
|
|
4633
|
+
|
|
4634
|
+
var _ff_h264_cabac_tables = Module['_ff_h264_cabac_tables'] = 151866;
|
|
4635
|
+
|
|
4636
|
+
|
|
4637
|
+
|
|
4638
|
+
// === Auto-generated postamble setup entry stuff ===
|
|
4639
|
+
|
|
4640
|
+
Module["setValue"] = setValue;
|
|
4641
|
+
Module["getValue"] = getValue;
|
|
4642
|
+
Module["UTF8ToString"] = UTF8ToString;
|
|
4643
|
+
Module["stringToUTF8"] = stringToUTF8;
|
|
4644
|
+
|
|
4645
|
+
var calledRun;
|
|
4646
|
+
|
|
4647
|
+
/**
|
|
4648
|
+
* @constructor
|
|
4649
|
+
* @this {ExitStatus}
|
|
4650
|
+
*/
|
|
4651
|
+
function ExitStatus(status) {
|
|
4652
|
+
this.name = "ExitStatus";
|
|
4653
|
+
this.message = "Program terminated with exit(" + status + ")";
|
|
4654
|
+
this.status = status;
|
|
4655
|
+
}
|
|
4656
|
+
|
|
4657
|
+
var calledMain = false;
|
|
4658
|
+
|
|
4659
|
+
dependenciesFulfilled = function runCaller() {
|
|
4660
|
+
// If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
|
|
4661
|
+
if (!calledRun) run();
|
|
4662
|
+
if (!calledRun) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
|
|
4663
|
+
};
|
|
4664
|
+
|
|
4665
|
+
/** @type {function(Array=)} */
|
|
4666
|
+
function run(args) {
|
|
4667
|
+
args = args || arguments_;
|
|
4668
|
+
|
|
4669
|
+
if (runDependencies > 0) {
|
|
4670
|
+
return;
|
|
4671
|
+
}
|
|
4672
|
+
|
|
4673
|
+
preRun();
|
|
4674
|
+
|
|
4675
|
+
if (runDependencies > 0) return; // a preRun added a dependency, run will be called later
|
|
4676
|
+
|
|
4677
|
+
function doRun() {
|
|
4678
|
+
// run may have just been called through dependencies being fulfilled just in this very frame,
|
|
4679
|
+
// or while the async setStatus time below was happening
|
|
4680
|
+
if (calledRun) return;
|
|
4681
|
+
calledRun = true;
|
|
4682
|
+
Module['calledRun'] = true;
|
|
4683
|
+
|
|
4684
|
+
if (ABORT) return;
|
|
4685
|
+
|
|
4686
|
+
initRuntime();
|
|
4687
|
+
|
|
4688
|
+
preMain();
|
|
4689
|
+
|
|
4690
|
+
readyPromiseResolve(Module);
|
|
4691
|
+
if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
|
|
4692
|
+
|
|
4693
|
+
postRun();
|
|
4694
|
+
}
|
|
4695
|
+
|
|
4696
|
+
if (Module['setStatus']) {
|
|
4697
|
+
Module['setStatus']('Running...');
|
|
4698
|
+
setTimeout(function() {
|
|
4699
|
+
setTimeout(function() {
|
|
4700
|
+
Module['setStatus']('');
|
|
4701
|
+
}, 1);
|
|
4702
|
+
doRun();
|
|
4703
|
+
}, 1);
|
|
4704
|
+
} else
|
|
4705
|
+
{
|
|
4706
|
+
doRun();
|
|
4707
|
+
}
|
|
4708
|
+
}
|
|
4709
|
+
Module['run'] = run;
|
|
4710
|
+
|
|
4711
|
+
/** @param {boolean|number=} implicit */
|
|
4712
|
+
function exit(status, implicit) {
|
|
4713
|
+
|
|
4714
|
+
// if this is just main exit-ing implicitly, and the status is 0, then we
|
|
4715
|
+
// don't need to do anything here and can just leave. if the status is
|
|
4716
|
+
// non-zero, though, then we need to report it.
|
|
4717
|
+
// (we may have warned about this earlier, if a situation justifies doing so)
|
|
4718
|
+
if (implicit && noExitRuntime && status === 0) {
|
|
4719
|
+
return;
|
|
4720
|
+
}
|
|
4721
|
+
|
|
4722
|
+
if (noExitRuntime) {
|
|
4723
|
+
} else {
|
|
4724
|
+
|
|
4725
|
+
EXITSTATUS = status;
|
|
4726
|
+
|
|
4727
|
+
exitRuntime();
|
|
4728
|
+
|
|
4729
|
+
if (Module['onExit']) Module['onExit'](status);
|
|
4730
|
+
|
|
4731
|
+
ABORT = true;
|
|
4732
|
+
}
|
|
4733
|
+
|
|
4734
|
+
quit_(status, new ExitStatus(status));
|
|
4735
|
+
}
|
|
4736
|
+
|
|
4737
|
+
if (Module['preInit']) {
|
|
4738
|
+
if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
|
|
4739
|
+
while (Module['preInit'].length > 0) {
|
|
4740
|
+
Module['preInit'].pop()();
|
|
4741
|
+
}
|
|
4742
|
+
}
|
|
4743
|
+
|
|
4744
|
+
noExitRuntime = true;
|
|
4745
|
+
|
|
4746
|
+
run();
|
|
4747
|
+
|
|
4748
|
+
|
|
4749
|
+
|
|
4750
|
+
|
|
4751
|
+
|
|
4752
|
+
|
|
4753
|
+
|
|
4754
|
+
return LIBSVC.ready
|
|
4755
|
+
}
|
|
4756
|
+
);
|
|
4757
|
+
})();
|
|
4758
|
+
if (typeof exports === 'object' && typeof module === 'object')
|
|
4759
|
+
module.exports = LIBSVC;
|
|
4760
|
+
else if (typeof define === 'function' && define['amd'])
|
|
4761
|
+
define([], function() { return LIBSVC; });
|
|
4762
|
+
else if (typeof exports === 'object')
|
|
4763
|
+
exports["LIBSVC"] = LIBSVC;
|
|
4764
|
+
/* eslint-disable */
|
|
4765
|
+
(function (LIBSVC) {
|
|
4766
|
+
var SFUTransportType = {};
|
|
4767
|
+
SFUTransportType[(SFUTransportType['kAudio'] = 1)] = 'kAudio';
|
|
4768
|
+
SFUTransportType[(SFUTransportType['kVideo'] = 2)] = 'kVideo';
|
|
4769
|
+
SFUTransportType[(SFUTransportType['kData'] = 3)] = 'kData';
|
|
4770
|
+
SFUTransportType[(SFUTransportType['kAnnotation'] = 4)] = 'kAnnotation';
|
|
4771
|
+
SFUTransportType[(SFUTransportType['kMessage'] = 5)] = 'kMessage';
|
|
4772
|
+
|
|
4773
|
+
var SFUTransportOrient = {};
|
|
4774
|
+
SFUTransportOrient[(SFUTransportOrient['kSend'] = 1)] = 'kSend';
|
|
4775
|
+
SFUTransportOrient[(SFUTransportOrient['kRecv'] = 2)] = 'kRecv';
|
|
4776
|
+
SFUTransportOrient[(SFUTransportOrient['kBoth'] = 3)] = 'kBoth';
|
|
4777
|
+
|
|
4778
|
+
var SFUUserRole = {};
|
|
4779
|
+
SFUUserRole[(SFUUserRole['kInteractive'] = 1)] = 'kInteractive';
|
|
4780
|
+
SFUUserRole[(SFUUserRole['kBroadcast'] = 2)] = 'kBroadcast';
|
|
4781
|
+
|
|
4782
|
+
var SFUReason = {};
|
|
4783
|
+
SFUReason[(SFUReason['kOK'] = 0)] = 'kOK';
|
|
4784
|
+
SFUReason[(SFUReason['kError'] = 320200)] = 'kError';
|
|
4785
|
+
SFUReason[(SFUReason['kExisted'] = 3202001)] = 'kExisted';
|
|
4786
|
+
SFUReason[(SFUReason['kNetworkError'] = 320202)] = 'kNetworkError';
|
|
4787
|
+
SFUReason[(SFUReason['kMCFailed'] = 320203)] = 'kMCFailed';
|
|
4788
|
+
SFUReason[(SFUReason['kMSSFailed'] = 320204)] = 'kMSSFailed';
|
|
4789
|
+
SFUReason[(SFUReason['kMSSLost'] = 320205)] = 'kMSSLost';
|
|
4790
|
+
SFUReason[(SFUReason['kAuthFailed'] = 320206)] = 'kAuthFailed';
|
|
4791
|
+
SFUReason[(SFUReason['kErkLoadFailedror'] = 320207)] = 'kLoadFailed';
|
|
4792
|
+
SFUReason[(SFUReason['kNoImplemented'] = 320208)] = 'kNoImplemented';
|
|
4793
|
+
|
|
4794
|
+
var SFUTransportStatus = {};
|
|
4795
|
+
SFUTransportStatus[(SFUTransportStatus['kReconnecting'] = 320100)] = 'kReconnecting';
|
|
4796
|
+
SFUTransportStatus[(SFUTransportStatus['kReconnectOK'] = 320101)] = 'kReconnectOK';
|
|
4797
|
+
SFUTransportStatus[(SFUTransportStatus['kReconnectNG'] = 320102)] = 'kReconnectNG';
|
|
4798
|
+
|
|
4799
|
+
var SFUEndpointStatus = {};
|
|
4800
|
+
SFUEndpointStatus[(SFUEndpointStatus['kHandshakeOK'] = 100)] = 'kHandshakeOK';
|
|
4801
|
+
SFUEndpointStatus[(SFUEndpointStatus['kHandshakeNG'] = 101)] = 'kHandshakeNG';
|
|
4802
|
+
SFUEndpointStatus[(SFUEndpointStatus['kConnectOK'] = 102)] = 'kConnectOK';
|
|
4803
|
+
SFUEndpointStatus[(SFUEndpointStatus['kConnectNG'] = 103)] = 'kConnectNG';
|
|
4804
|
+
|
|
4805
|
+
var VideoChannelType = {};
|
|
4806
|
+
VideoChannelType[(VideoChannelType['kAudio'] = 1)] = 'kAudio';
|
|
4807
|
+
VideoChannelType[(VideoChannelType['kVideo'] = 2)] = 'kVideo';
|
|
4808
|
+
VideoChannelType[(VideoChannelType['kData'] = 3)] = 'kData';
|
|
4809
|
+
VideoChannelType[(VideoChannelType['kAnnotation'] = 4)] = 'kAnnotation';
|
|
4810
|
+
VideoChannelType[(VideoChannelType['kMessage'] = 5)] = 'kMessage';
|
|
4811
|
+
|
|
4812
|
+
var VideoChannelOrient = {};
|
|
4813
|
+
VideoChannelOrient[(VideoChannelOrient['kSend'] = 1)] = 'kSend';
|
|
4814
|
+
VideoChannelOrient[(VideoChannelOrient['kRecv'] = 2)] = 'kRecv';
|
|
4815
|
+
VideoChannelOrient[(VideoChannelOrient['kBoth'] = 3)] = 'kBoth';
|
|
4816
|
+
|
|
4817
|
+
var VideoChannelMode = {};
|
|
4818
|
+
VideoChannelMode[(VideoChannelMode['kNormal'] = 0)] = 'kNormal';
|
|
4819
|
+
VideoChannelMode[(VideoChannelMode['kSmooth'] = 1)] = 'kSmooth';
|
|
4820
|
+
|
|
4821
|
+
var VideoRotation = {};
|
|
4822
|
+
VideoRotation[(VideoRotation['kRotation_0'] = 0)] = 'kRotation_0';
|
|
4823
|
+
VideoRotation[(VideoRotation['kRotation_90'] = 90)] = 'kRotation_90';
|
|
4824
|
+
VideoRotation[(VideoRotation['kRotation_180'] = 180)] = 'kRotation_180';
|
|
4825
|
+
VideoRotation[(VideoRotation['kRotation_270'] = 270)] = 'kRotation_270';
|
|
4826
|
+
|
|
4827
|
+
var VideoEncodeMode = {};
|
|
4828
|
+
VideoEncodeMode[(VideoEncodeMode['kVeryfast'] = 0)] = 'kVeryfast';
|
|
4829
|
+
VideoEncodeMode[(VideoEncodeMode['kUltrafast'] = 1)] = 'kUltrafast';
|
|
4830
|
+
VideoEncodeMode[(VideoEncodeMode['kUltrafastPlus'] = 2)] = 'kUltrafastPlus';
|
|
4831
|
+
|
|
4832
|
+
var TransportType = {};
|
|
4833
|
+
TransportType[(TransportType['kSignal'] = 0)] = 'kSignal';
|
|
4834
|
+
TransportType[(TransportType['kData'] = 1)] = 'kData';
|
|
4835
|
+
|
|
4836
|
+
var DataType = {};
|
|
4837
|
+
DataType[(DataType['kCoopration'] = 1)] = 'kCoopration';
|
|
4838
|
+
DataType[(DataType['kRemoteControl'] = 2)] = 'kRemoteControl';
|
|
4839
|
+
DataType[(DataType['kSubtitleRealtime'] = 3)] = 'kSubtitleRealtime';
|
|
4840
|
+
DataType[(DataType['kSubtitleRecord'] = 4)] = 'kSubtitleRecord';
|
|
4841
|
+
|
|
4842
|
+
LIBSVC['SFUReason'] = SFUReason;
|
|
4843
|
+
LIBSVC['SFUUserRole'] = SFUUserRole;
|
|
4844
|
+
LIBSVC['SFUTransportType'] = SFUTransportType;
|
|
4845
|
+
LIBSVC['SFUTransportStatus'] = SFUTransportStatus;
|
|
4846
|
+
LIBSVC['SFUTransportOrient'] = SFUTransportOrient;
|
|
4847
|
+
LIBSVC['SFUEndpointStatus'] = SFUEndpointStatus;
|
|
4848
|
+
LIBSVC['VideoChannelType'] = VideoChannelType;
|
|
4849
|
+
LIBSVC['VideoChannelOrient'] = VideoChannelOrient;
|
|
4850
|
+
LIBSVC['VideoEncodeMode'] = VideoEncodeMode;
|
|
4851
|
+
LIBSVC['TransportType'] = TransportType;
|
|
4852
|
+
LIBSVC['VideoChannelMode'] = VideoChannelMode;
|
|
4853
|
+
LIBSVC['VideoRotation'] = VideoRotation;
|
|
4854
|
+
LIBSVC['DataType'] = DataType;
|
|
4855
|
+
})(LIBSVC || (LIBSVC = {}));
|
|
4856
|
+
/* eslint-enable */
|
|
4857
|
+
|