syntaqlite 0.4.1 → 0.5.0
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/dialect.d.ts +2 -2
- package/dist/dialect.d.ts.map +1 -1
- package/dist/dialect_config.d.ts +1 -1
- package/dist/dialect_config.d.ts.map +1 -1
- package/dist/engine.d.ts +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/package.json +6 -2
- package/wasm/syntaqlite-runtime.js +4867 -0
- package/wasm/syntaqlite-runtime.wasm +0 -0
- package/wasm/syntaqlite-sqlite.wasm +0 -0
|
@@ -0,0 +1,4867 @@
|
|
|
1
|
+
// include: shell.js
|
|
2
|
+
// The Module object: Our interface to the outside world. We import
|
|
3
|
+
// and export values on it. There are various ways Module can be used:
|
|
4
|
+
// 1. Not defined. We create it here
|
|
5
|
+
// 2. A function parameter, function(moduleArg) => Promise<Module>
|
|
6
|
+
// 3. pre-run appended it, var Module = {}; ..generated code..
|
|
7
|
+
// 4. External script tag defines var Module.
|
|
8
|
+
// We need to check if Module already exists (e.g. case 3 above).
|
|
9
|
+
// Substitution will be replaced with actual code on later stage of the build,
|
|
10
|
+
// this way Closure Compiler will not mangle it (e.g. case 4. above).
|
|
11
|
+
// Note that if you want to run closure, and also to use Module
|
|
12
|
+
// after the generated code, you will need to define var Module = {};
|
|
13
|
+
// before the code. Then that object will be used in the code, and you
|
|
14
|
+
// can continue to use Module afterwards as well.
|
|
15
|
+
var Module = typeof Module != 'undefined' ? Module : {};
|
|
16
|
+
|
|
17
|
+
// Determine the runtime environment we are in. You can customize this by
|
|
18
|
+
// setting the ENVIRONMENT setting at compile time (see settings.js).
|
|
19
|
+
|
|
20
|
+
// Attempt to auto-detect the environment
|
|
21
|
+
var ENVIRONMENT_IS_WEB = typeof window == 'object';
|
|
22
|
+
var ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != 'undefined';
|
|
23
|
+
// N.b. Electron.js environment is simultaneously a NODE-environment, but
|
|
24
|
+
// also a web environment.
|
|
25
|
+
var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string' && process.type != 'renderer';
|
|
26
|
+
var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
|
|
27
|
+
|
|
28
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// --pre-jses are emitted after the Module integration code, so that they can
|
|
33
|
+
// refer to Module (if they choose; they can also define Module)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
var arguments_ = [];
|
|
37
|
+
var thisProgram = './this.program';
|
|
38
|
+
var quit_ = (status, toThrow) => {
|
|
39
|
+
throw toThrow;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// In MODULARIZE mode _scriptName needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there
|
|
43
|
+
// before the page load. In non-MODULARIZE modes generate it here.
|
|
44
|
+
var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
|
|
45
|
+
|
|
46
|
+
if (typeof __filename != 'undefined') { // Node
|
|
47
|
+
_scriptName = __filename;
|
|
48
|
+
} else
|
|
49
|
+
if (ENVIRONMENT_IS_WORKER) {
|
|
50
|
+
_scriptName = self.location.href;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// `/` should be present at the end if `scriptDirectory` is not empty
|
|
54
|
+
var scriptDirectory = '';
|
|
55
|
+
function locateFile(path) {
|
|
56
|
+
if (Module['locateFile']) {
|
|
57
|
+
return Module['locateFile'](path, scriptDirectory);
|
|
58
|
+
}
|
|
59
|
+
return scriptDirectory + path;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Hooks that are implemented differently in different runtime environments.
|
|
63
|
+
var readAsync, readBinary;
|
|
64
|
+
|
|
65
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
66
|
+
|
|
67
|
+
// These modules will usually be used on Node.js. Load them eagerly to avoid
|
|
68
|
+
// the complexity of lazy-loading.
|
|
69
|
+
var fs = require('fs');
|
|
70
|
+
var nodePath = require('path');
|
|
71
|
+
|
|
72
|
+
scriptDirectory = __dirname + '/';
|
|
73
|
+
|
|
74
|
+
// include: node_shell_read.js
|
|
75
|
+
readBinary = (filename) => {
|
|
76
|
+
// We need to re-wrap `file://` strings to URLs.
|
|
77
|
+
filename = isFileURI(filename) ? new URL(filename) : filename;
|
|
78
|
+
var ret = fs.readFileSync(filename);
|
|
79
|
+
return ret;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
readAsync = async (filename, binary = true) => {
|
|
83
|
+
// See the comment in the `readBinary` function.
|
|
84
|
+
filename = isFileURI(filename) ? new URL(filename) : filename;
|
|
85
|
+
var ret = fs.readFileSync(filename, binary ? undefined : 'utf8');
|
|
86
|
+
return ret;
|
|
87
|
+
};
|
|
88
|
+
// end include: node_shell_read.js
|
|
89
|
+
if (process.argv.length > 1) {
|
|
90
|
+
thisProgram = process.argv[1].replace(/\\/g, '/');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
arguments_ = process.argv.slice(2);
|
|
94
|
+
|
|
95
|
+
// MODULARIZE will export the module in the proper place outside, we don't need to export here
|
|
96
|
+
if (typeof module != 'undefined') {
|
|
97
|
+
module['exports'] = Module;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
quit_ = (status, toThrow) => {
|
|
101
|
+
process.exitCode = status;
|
|
102
|
+
throw toThrow;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
} else
|
|
106
|
+
|
|
107
|
+
// Note that this includes Node.js workers when relevant (pthreads is enabled).
|
|
108
|
+
// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
|
|
109
|
+
// ENVIRONMENT_IS_NODE.
|
|
110
|
+
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
|
|
111
|
+
try {
|
|
112
|
+
scriptDirectory = new URL('.', _scriptName).href; // includes trailing slash
|
|
113
|
+
} catch {
|
|
114
|
+
// Must be a `blob:` or `data:` URL (e.g. `blob:http://site.com/etc/etc`), we cannot
|
|
115
|
+
// infer anything from them.
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
{
|
|
119
|
+
// include: web_or_worker_shell_read.js
|
|
120
|
+
if (ENVIRONMENT_IS_WORKER) {
|
|
121
|
+
readBinary = (url) => {
|
|
122
|
+
var xhr = new XMLHttpRequest();
|
|
123
|
+
xhr.open('GET', url, false);
|
|
124
|
+
xhr.responseType = 'arraybuffer';
|
|
125
|
+
xhr.send(null);
|
|
126
|
+
return new Uint8Array(/** @type{!ArrayBuffer} */(xhr.response));
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
readAsync = async (url) => {
|
|
131
|
+
// Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
|
|
132
|
+
// See https://github.com/github/fetch/pull/92#issuecomment-140665932
|
|
133
|
+
// Cordova or Electron apps are typically loaded from a file:// url.
|
|
134
|
+
// So use XHR on webview if URL is a file URL.
|
|
135
|
+
if (isFileURI(url)) {
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
var xhr = new XMLHttpRequest();
|
|
138
|
+
xhr.open('GET', url, true);
|
|
139
|
+
xhr.responseType = 'arraybuffer';
|
|
140
|
+
xhr.onload = () => {
|
|
141
|
+
if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
|
|
142
|
+
resolve(xhr.response);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
reject(xhr.status);
|
|
146
|
+
};
|
|
147
|
+
xhr.onerror = reject;
|
|
148
|
+
xhr.send(null);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
var response = await fetch(url, { credentials: 'same-origin' });
|
|
152
|
+
if (response.ok) {
|
|
153
|
+
return response.arrayBuffer();
|
|
154
|
+
}
|
|
155
|
+
throw new Error(response.status + ' : ' + response.url);
|
|
156
|
+
};
|
|
157
|
+
// end include: web_or_worker_shell_read.js
|
|
158
|
+
}
|
|
159
|
+
} else
|
|
160
|
+
{
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
var out = console.log.bind(console);
|
|
164
|
+
var err = console.error.bind(console);
|
|
165
|
+
|
|
166
|
+
// end include: shell.js
|
|
167
|
+
|
|
168
|
+
// include: preamble.js
|
|
169
|
+
// === Preamble library stuff ===
|
|
170
|
+
|
|
171
|
+
// Documentation for the public APIs defined in this file must be updated in:
|
|
172
|
+
// site/source/docs/api_reference/preamble.js.rst
|
|
173
|
+
// A prebuilt local version of the documentation is available at:
|
|
174
|
+
// site/build/text/docs/api_reference/preamble.js.txt
|
|
175
|
+
// You can also build docs locally as HTML or other formats in site/
|
|
176
|
+
// An online HTML version (which may be of a different version of Emscripten)
|
|
177
|
+
// is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
|
|
178
|
+
|
|
179
|
+
var dynamicLibraries = [];
|
|
180
|
+
|
|
181
|
+
var wasmBinary;
|
|
182
|
+
|
|
183
|
+
// Wasm globals
|
|
184
|
+
|
|
185
|
+
var wasmMemory;
|
|
186
|
+
|
|
187
|
+
//========================================
|
|
188
|
+
// Runtime essentials
|
|
189
|
+
//========================================
|
|
190
|
+
|
|
191
|
+
// whether we are quitting the application. no code should run after this.
|
|
192
|
+
// set in exit() and abort()
|
|
193
|
+
var ABORT = false;
|
|
194
|
+
|
|
195
|
+
// set by exit() and abort(). Passed to 'onExit' handler.
|
|
196
|
+
// NOTE: This is also used as the process return code code in shell environments
|
|
197
|
+
// but only when noExitRuntime is false.
|
|
198
|
+
var EXITSTATUS;
|
|
199
|
+
|
|
200
|
+
// In STRICT mode, we only define assert() when ASSERTIONS is set. i.e. we
|
|
201
|
+
// don't define it at all in release modes. This matches the behaviour of
|
|
202
|
+
// MINIMAL_RUNTIME.
|
|
203
|
+
// TODO(sbc): Make this the default even without STRICT enabled.
|
|
204
|
+
/** @type {function(*, string=)} */
|
|
205
|
+
function assert(condition, text) {
|
|
206
|
+
if (!condition) {
|
|
207
|
+
// This build was created without ASSERTIONS defined. `assert()` should not
|
|
208
|
+
// ever be called in this configuration but in case there are callers in
|
|
209
|
+
// the wild leave this simple abort() implementation here for now.
|
|
210
|
+
abort(text);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Memory management
|
|
215
|
+
|
|
216
|
+
var HEAP,
|
|
217
|
+
/** @type {!Int8Array} */
|
|
218
|
+
HEAP8,
|
|
219
|
+
/** @type {!Uint8Array} */
|
|
220
|
+
HEAPU8,
|
|
221
|
+
/** @type {!Int16Array} */
|
|
222
|
+
HEAP16,
|
|
223
|
+
/** @type {!Uint16Array} */
|
|
224
|
+
HEAPU16,
|
|
225
|
+
/** @type {!Int32Array} */
|
|
226
|
+
HEAP32,
|
|
227
|
+
/** @type {!Uint32Array} */
|
|
228
|
+
HEAPU32,
|
|
229
|
+
/** @type {!Float32Array} */
|
|
230
|
+
HEAPF32,
|
|
231
|
+
/* BigInt64Array type is not correctly defined in closure
|
|
232
|
+
/** not-@type {!BigInt64Array} */
|
|
233
|
+
HEAP64,
|
|
234
|
+
/* BigUint64Array type is not correctly defined in closure
|
|
235
|
+
/** not-t@type {!BigUint64Array} */
|
|
236
|
+
HEAPU64,
|
|
237
|
+
/** @type {!Float64Array} */
|
|
238
|
+
HEAPF64;
|
|
239
|
+
|
|
240
|
+
var runtimeInitialized = false;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Indicates whether filename is delivered via file protocol (as opposed to http/https)
|
|
244
|
+
* @noinline
|
|
245
|
+
*/
|
|
246
|
+
var isFileURI = (filename) => filename.startsWith('file://');
|
|
247
|
+
|
|
248
|
+
// include: runtime_shared.js
|
|
249
|
+
// include: runtime_stack_check.js
|
|
250
|
+
// end include: runtime_stack_check.js
|
|
251
|
+
// include: runtime_exceptions.js
|
|
252
|
+
// end include: runtime_exceptions.js
|
|
253
|
+
// include: runtime_debug.js
|
|
254
|
+
// end include: runtime_debug.js
|
|
255
|
+
// include: memoryprofiler.js
|
|
256
|
+
// end include: memoryprofiler.js
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
function updateMemoryViews() {
|
|
260
|
+
var b = wasmMemory.buffer;
|
|
261
|
+
HEAP8 = new Int8Array(b);
|
|
262
|
+
HEAP16 = new Int16Array(b);
|
|
263
|
+
HEAPU8 = new Uint8Array(b);
|
|
264
|
+
HEAPU16 = new Uint16Array(b);
|
|
265
|
+
HEAP32 = new Int32Array(b);
|
|
266
|
+
HEAPU32 = new Uint32Array(b);
|
|
267
|
+
HEAPF32 = new Float32Array(b);
|
|
268
|
+
HEAPF64 = new Float64Array(b);
|
|
269
|
+
HEAP64 = new BigInt64Array(b);
|
|
270
|
+
HEAPU64 = new BigUint64Array(b);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// end include: runtime_shared.js
|
|
274
|
+
// In non-standalone/normal mode, we create the memory here.
|
|
275
|
+
// include: runtime_init_memory.js
|
|
276
|
+
// Create the wasm memory. (Note: this only applies if IMPORTED_MEMORY is defined)
|
|
277
|
+
|
|
278
|
+
// check for full engine support (use string 'subarray' to avoid closure compiler confusion)
|
|
279
|
+
|
|
280
|
+
function initMemory() {
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
if (Module['wasmMemory']) {
|
|
284
|
+
wasmMemory = Module['wasmMemory'];
|
|
285
|
+
} else
|
|
286
|
+
{
|
|
287
|
+
var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216;
|
|
288
|
+
|
|
289
|
+
/** @suppress {checkTypes} */
|
|
290
|
+
wasmMemory = new WebAssembly.Memory({
|
|
291
|
+
'initial': INITIAL_MEMORY / 65536,
|
|
292
|
+
// In theory we should not need to emit the maximum if we want "unlimited"
|
|
293
|
+
// or 4GB of memory, but VMs error on that atm, see
|
|
294
|
+
// https://github.com/emscripten-core/emscripten/issues/14130
|
|
295
|
+
// And in the pthreads case we definitely need to emit a maximum. So
|
|
296
|
+
// always emit one.
|
|
297
|
+
'maximum': 32768,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
updateMemoryViews();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// end include: runtime_init_memory.js
|
|
305
|
+
|
|
306
|
+
var __RELOC_FUNCS__ = [];
|
|
307
|
+
|
|
308
|
+
function preRun() {
|
|
309
|
+
if (Module['preRun']) {
|
|
310
|
+
if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
|
|
311
|
+
while (Module['preRun'].length) {
|
|
312
|
+
addOnPreRun(Module['preRun'].shift());
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
// Begin ATPRERUNS hooks
|
|
316
|
+
callRuntimeCallbacks(onPreRuns);
|
|
317
|
+
// End ATPRERUNS hooks
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function initRuntime() {
|
|
321
|
+
runtimeInitialized = true;
|
|
322
|
+
|
|
323
|
+
callRuntimeCallbacks(__RELOC_FUNCS__);
|
|
324
|
+
|
|
325
|
+
// Begin ATINITS hooks
|
|
326
|
+
if (!Module['noFSInit'] && !FS.initialized) FS.init();
|
|
327
|
+
TTY.init();
|
|
328
|
+
// End ATINITS hooks
|
|
329
|
+
|
|
330
|
+
wasmExports['__wasm_call_ctors']();
|
|
331
|
+
|
|
332
|
+
// Begin ATPOSTCTORS hooks
|
|
333
|
+
callRuntimeCallbacks(onPostCtors);
|
|
334
|
+
FS.ignorePermissions = false;
|
|
335
|
+
// End ATPOSTCTORS hooks
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function preMain() {
|
|
339
|
+
// No ATMAINS hooks
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function postRun() {
|
|
343
|
+
// PThreads reuse the runtime from the main thread.
|
|
344
|
+
|
|
345
|
+
if (Module['postRun']) {
|
|
346
|
+
if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
|
|
347
|
+
while (Module['postRun'].length) {
|
|
348
|
+
addOnPostRun(Module['postRun'].shift());
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Begin ATPOSTRUNS hooks
|
|
353
|
+
callRuntimeCallbacks(onPostRuns);
|
|
354
|
+
// End ATPOSTRUNS hooks
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// A counter of dependencies for calling run(). If we need to
|
|
358
|
+
// do asynchronous work before running, increment this and
|
|
359
|
+
// decrement it. Incrementing must happen in a place like
|
|
360
|
+
// Module.preRun (used by emcc to add file preloading).
|
|
361
|
+
// Note that you can add dependencies in preRun, even though
|
|
362
|
+
// it happens right before run - run will be postponed until
|
|
363
|
+
// the dependencies are met.
|
|
364
|
+
var runDependencies = 0;
|
|
365
|
+
var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
|
|
366
|
+
|
|
367
|
+
function getUniqueRunDependency(id) {
|
|
368
|
+
return id;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function addRunDependency(id) {
|
|
372
|
+
runDependencies++;
|
|
373
|
+
|
|
374
|
+
Module['monitorRunDependencies']?.(runDependencies);
|
|
375
|
+
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function removeRunDependency(id) {
|
|
379
|
+
runDependencies--;
|
|
380
|
+
|
|
381
|
+
Module['monitorRunDependencies']?.(runDependencies);
|
|
382
|
+
|
|
383
|
+
if (runDependencies == 0) {
|
|
384
|
+
if (dependenciesFulfilled) {
|
|
385
|
+
var callback = dependenciesFulfilled;
|
|
386
|
+
dependenciesFulfilled = null;
|
|
387
|
+
callback(); // can add another dependenciesFulfilled
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** @param {string|number=} what */
|
|
393
|
+
function abort(what) {
|
|
394
|
+
Module['onAbort']?.(what);
|
|
395
|
+
|
|
396
|
+
what = 'Aborted(' + what + ')';
|
|
397
|
+
// TODO(sbc): Should we remove printing and leave it up to whoever
|
|
398
|
+
// catches the exception?
|
|
399
|
+
err(what);
|
|
400
|
+
|
|
401
|
+
ABORT = true;
|
|
402
|
+
|
|
403
|
+
what += '. Build with -sASSERTIONS for more info.';
|
|
404
|
+
|
|
405
|
+
// Use a wasm runtime error, because a JS error might be seen as a foreign
|
|
406
|
+
// exception, which means we'd run destructors on it. We need the error to
|
|
407
|
+
// simply make the program stop.
|
|
408
|
+
// FIXME This approach does not work in Wasm EH because it currently does not assume
|
|
409
|
+
// all RuntimeErrors are from traps; it decides whether a RuntimeError is from
|
|
410
|
+
// a trap or not based on a hidden field within the object. So at the moment
|
|
411
|
+
// we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that
|
|
412
|
+
// allows this in the wasm spec.
|
|
413
|
+
|
|
414
|
+
// Suppress closure compiler warning here. Closure compiler's builtin extern
|
|
415
|
+
// definition for WebAssembly.RuntimeError claims it takes no arguments even
|
|
416
|
+
// though it can.
|
|
417
|
+
// TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
|
|
418
|
+
// See above, in the meantime, we resort to wasm code for trapping.
|
|
419
|
+
//
|
|
420
|
+
// In case abort() is called before the module is initialized, wasmExports
|
|
421
|
+
// and its exported '__trap' function is not available, in which case we throw
|
|
422
|
+
// a RuntimeError.
|
|
423
|
+
//
|
|
424
|
+
// We trap instead of throwing RuntimeError to prevent infinite-looping in
|
|
425
|
+
// Wasm EH code (because RuntimeError is considered as a foreign exception and
|
|
426
|
+
// caught by 'catch_all'), but in case throwing RuntimeError is fine because
|
|
427
|
+
// the module has not even been instantiated, even less running.
|
|
428
|
+
if (runtimeInitialized) {
|
|
429
|
+
___trap();
|
|
430
|
+
}
|
|
431
|
+
/** @suppress {checkTypes} */
|
|
432
|
+
var e = new WebAssembly.RuntimeError(what);
|
|
433
|
+
|
|
434
|
+
// Throw the error whether or not MODULARIZE is set because abort is used
|
|
435
|
+
// in code paths apart from instantiation where an exception is expected
|
|
436
|
+
// to be thrown when abort is called.
|
|
437
|
+
throw e;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
var wasmBinaryFile;
|
|
441
|
+
|
|
442
|
+
function findWasmBinary() {
|
|
443
|
+
return locateFile('syntaqlite_wasm.wasm');
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function getBinarySync(file) {
|
|
447
|
+
if (file == wasmBinaryFile && wasmBinary) {
|
|
448
|
+
return new Uint8Array(wasmBinary);
|
|
449
|
+
}
|
|
450
|
+
if (readBinary) {
|
|
451
|
+
return readBinary(file);
|
|
452
|
+
}
|
|
453
|
+
throw 'both async and sync fetching of the wasm failed';
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
async function getWasmBinary(binaryFile) {
|
|
457
|
+
// If we don't have the binary yet, load it asynchronously using readAsync.
|
|
458
|
+
if (!wasmBinary) {
|
|
459
|
+
// Fetch the binary using readAsync
|
|
460
|
+
try {
|
|
461
|
+
var response = await readAsync(binaryFile);
|
|
462
|
+
return new Uint8Array(response);
|
|
463
|
+
} catch {
|
|
464
|
+
// Fall back to getBinarySync below;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// Otherwise, getBinarySync should be able to get it synchronously
|
|
469
|
+
return getBinarySync(binaryFile);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
async function instantiateArrayBuffer(binaryFile, imports) {
|
|
473
|
+
try {
|
|
474
|
+
var binary = await getWasmBinary(binaryFile);
|
|
475
|
+
var instance = await WebAssembly.instantiate(binary, imports);
|
|
476
|
+
return instance;
|
|
477
|
+
} catch (reason) {
|
|
478
|
+
err(`failed to asynchronously prepare wasm: ${reason}`);
|
|
479
|
+
|
|
480
|
+
abort(reason);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
async function instantiateAsync(binary, binaryFile, imports) {
|
|
485
|
+
if (!binary && typeof WebAssembly.instantiateStreaming == 'function'
|
|
486
|
+
// Don't use streaming for file:// delivered objects in a webview, fetch them synchronously.
|
|
487
|
+
&& !isFileURI(binaryFile)
|
|
488
|
+
// Avoid instantiateStreaming() on Node.js environment for now, as while
|
|
489
|
+
// Node.js v18.1.0 implements it, it does not have a full fetch()
|
|
490
|
+
// implementation yet.
|
|
491
|
+
//
|
|
492
|
+
// Reference:
|
|
493
|
+
// https://github.com/emscripten-core/emscripten/pull/16917
|
|
494
|
+
&& !ENVIRONMENT_IS_NODE
|
|
495
|
+
) {
|
|
496
|
+
try {
|
|
497
|
+
var response = fetch(binaryFile, { credentials: 'same-origin' });
|
|
498
|
+
var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
|
|
499
|
+
return instantiationResult;
|
|
500
|
+
} catch (reason) {
|
|
501
|
+
// We expect the most common failure cause to be a bad MIME type for the binary,
|
|
502
|
+
// in which case falling back to ArrayBuffer instantiation should work.
|
|
503
|
+
err(`wasm streaming compile failed: ${reason}`);
|
|
504
|
+
err('falling back to ArrayBuffer instantiation');
|
|
505
|
+
// fall back of instantiateArrayBuffer below
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
return instantiateArrayBuffer(binaryFile, imports);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function getWasmImports() {
|
|
512
|
+
// prepare imports
|
|
513
|
+
return {
|
|
514
|
+
'env': wasmImports,
|
|
515
|
+
'wasi_snapshot_preview1': wasmImports,
|
|
516
|
+
'GOT.mem': new Proxy(wasmImports, GOTHandler),
|
|
517
|
+
'GOT.func': new Proxy(wasmImports, GOTHandler),
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// Create the wasm instance.
|
|
522
|
+
// Receives the wasm imports, returns the exports.
|
|
523
|
+
async function createWasm() {
|
|
524
|
+
// Load the wasm module and create an instance of using native support in the JS engine.
|
|
525
|
+
// handle a generated wasm instance, receiving its exports and
|
|
526
|
+
// performing other necessary setup
|
|
527
|
+
/** @param {WebAssembly.Module=} module*/
|
|
528
|
+
function receiveInstance(instance, module) {
|
|
529
|
+
wasmExports = instance.exports;
|
|
530
|
+
|
|
531
|
+
wasmExports = relocateExports(wasmExports, 1024);
|
|
532
|
+
|
|
533
|
+
var metadata = getDylinkMetadata(module);
|
|
534
|
+
if (metadata.neededDynlibs) {
|
|
535
|
+
dynamicLibraries = metadata.neededDynlibs.concat(dynamicLibraries);
|
|
536
|
+
}
|
|
537
|
+
mergeLibSymbols(wasmExports, 'main')
|
|
538
|
+
LDSO.init();
|
|
539
|
+
loadDylibs();
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
__RELOC_FUNCS__.push(wasmExports['__wasm_apply_data_relocs']);
|
|
544
|
+
|
|
545
|
+
removeRunDependency('wasm-instantiate');
|
|
546
|
+
return wasmExports;
|
|
547
|
+
}
|
|
548
|
+
// wait for the pthread pool (if any)
|
|
549
|
+
addRunDependency('wasm-instantiate');
|
|
550
|
+
|
|
551
|
+
// Prefer streaming instantiation if available.
|
|
552
|
+
function receiveInstantiationResult(result) {
|
|
553
|
+
// 'result' is a ResultObject object which has both the module and instance.
|
|
554
|
+
// receiveInstance() will swap in the exports (to Module.asm) so they can be called
|
|
555
|
+
return receiveInstance(result['instance'], result['module']);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
var info = getWasmImports();
|
|
559
|
+
|
|
560
|
+
// User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
|
|
561
|
+
// to manually instantiate the Wasm module themselves. This allows pages to
|
|
562
|
+
// run the instantiation parallel to any other async startup actions they are
|
|
563
|
+
// performing.
|
|
564
|
+
// Also pthreads and wasm workers initialize the wasm instance through this
|
|
565
|
+
// path.
|
|
566
|
+
if (Module['instantiateWasm']) {
|
|
567
|
+
return new Promise((resolve, reject) => {
|
|
568
|
+
Module['instantiateWasm'](info, (mod, inst) => {
|
|
569
|
+
resolve(receiveInstance(mod, inst));
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
wasmBinaryFile ??= findWasmBinary();
|
|
575
|
+
var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
|
|
576
|
+
var exports = receiveInstantiationResult(result);
|
|
577
|
+
return exports;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// end include: preamble.js
|
|
581
|
+
|
|
582
|
+
// Begin JS library code
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
class ExitStatus {
|
|
586
|
+
name = 'ExitStatus';
|
|
587
|
+
constructor(status) {
|
|
588
|
+
this.message = `Program terminated with exit(${status})`;
|
|
589
|
+
this.status = status;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
var GOT = {
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
var currentModuleWeakSymbols = new Set([]);
|
|
597
|
+
var GOTHandler = {
|
|
598
|
+
get(obj, symName) {
|
|
599
|
+
var rtn = GOT[symName];
|
|
600
|
+
if (!rtn) {
|
|
601
|
+
rtn = GOT[symName] = new WebAssembly.Global({'value': 'i32', 'mutable': true});
|
|
602
|
+
}
|
|
603
|
+
if (!currentModuleWeakSymbols.has(symName)) {
|
|
604
|
+
// Any non-weak reference to a symbol marks it as `required`, which
|
|
605
|
+
// enabled `reportUndefinedSymbols` to report undefined symbol errors
|
|
606
|
+
// correctly.
|
|
607
|
+
rtn.required = true;
|
|
608
|
+
}
|
|
609
|
+
return rtn;
|
|
610
|
+
},
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
var callRuntimeCallbacks = (callbacks) => {
|
|
614
|
+
while (callbacks.length > 0) {
|
|
615
|
+
// Pass the module as the first argument.
|
|
616
|
+
callbacks.shift()(Module);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
var onPostRuns = [];
|
|
620
|
+
var addOnPostRun = (cb) => onPostRuns.push(cb);
|
|
621
|
+
|
|
622
|
+
var onPreRuns = [];
|
|
623
|
+
var addOnPreRun = (cb) => onPreRuns.push(cb);
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
var UTF8Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder() : undefined;
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
|
|
630
|
+
* array that contains uint8 values, returns a copy of that string as a
|
|
631
|
+
* Javascript String object.
|
|
632
|
+
* heapOrArray is either a regular array, or a JavaScript typed array view.
|
|
633
|
+
* @param {number=} idx
|
|
634
|
+
* @param {number=} maxBytesToRead
|
|
635
|
+
* @return {string}
|
|
636
|
+
*/
|
|
637
|
+
var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead = NaN) => {
|
|
638
|
+
var endIdx = idx + maxBytesToRead;
|
|
639
|
+
var endPtr = idx;
|
|
640
|
+
// TextDecoder needs to know the byte length in advance, it doesn't stop on
|
|
641
|
+
// null terminator by itself. Also, use the length info to avoid running tiny
|
|
642
|
+
// strings through TextDecoder, since .subarray() allocates garbage.
|
|
643
|
+
// (As a tiny code save trick, compare endPtr against endIdx using a negation,
|
|
644
|
+
// so that undefined/NaN means Infinity)
|
|
645
|
+
while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
|
|
646
|
+
|
|
647
|
+
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
|
|
648
|
+
return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
|
|
649
|
+
}
|
|
650
|
+
var str = '';
|
|
651
|
+
// If building with TextDecoder, we have already computed the string length
|
|
652
|
+
// above, so test loop end condition against that
|
|
653
|
+
while (idx < endPtr) {
|
|
654
|
+
// For UTF8 byte structure, see:
|
|
655
|
+
// http://en.wikipedia.org/wiki/UTF-8#Description
|
|
656
|
+
// https://www.ietf.org/rfc/rfc2279.txt
|
|
657
|
+
// https://tools.ietf.org/html/rfc3629
|
|
658
|
+
var u0 = heapOrArray[idx++];
|
|
659
|
+
if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
|
|
660
|
+
var u1 = heapOrArray[idx++] & 63;
|
|
661
|
+
if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
|
|
662
|
+
var u2 = heapOrArray[idx++] & 63;
|
|
663
|
+
if ((u0 & 0xF0) == 0xE0) {
|
|
664
|
+
u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
|
|
665
|
+
} else {
|
|
666
|
+
u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
if (u0 < 0x10000) {
|
|
670
|
+
str += String.fromCharCode(u0);
|
|
671
|
+
} else {
|
|
672
|
+
var ch = u0 - 0x10000;
|
|
673
|
+
str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return str;
|
|
677
|
+
};
|
|
678
|
+
var getDylinkMetadata = (binary) => {
|
|
679
|
+
var offset = 0;
|
|
680
|
+
var end = 0;
|
|
681
|
+
|
|
682
|
+
function getU8() {
|
|
683
|
+
return binary[offset++];
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function getLEB() {
|
|
687
|
+
var ret = 0;
|
|
688
|
+
var mul = 1;
|
|
689
|
+
while (1) {
|
|
690
|
+
var byte = binary[offset++];
|
|
691
|
+
ret += ((byte & 0x7f) * mul);
|
|
692
|
+
mul *= 0x80;
|
|
693
|
+
if (!(byte & 0x80)) break;
|
|
694
|
+
}
|
|
695
|
+
return ret;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function getString() {
|
|
699
|
+
var len = getLEB();
|
|
700
|
+
offset += len;
|
|
701
|
+
return UTF8ArrayToString(binary, offset - len, len);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function getStringList() {
|
|
705
|
+
var count = getLEB();
|
|
706
|
+
var rtn = []
|
|
707
|
+
while (count--) rtn.push(getString());
|
|
708
|
+
return rtn;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/** @param {string=} message */
|
|
712
|
+
function failIf(condition, message) {
|
|
713
|
+
if (condition) throw new Error(message);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
if (binary instanceof WebAssembly.Module) {
|
|
717
|
+
var dylinkSection = WebAssembly.Module.customSections(binary, 'dylink.0');
|
|
718
|
+
failIf(dylinkSection.length === 0, 'need dylink section');
|
|
719
|
+
binary = new Uint8Array(dylinkSection[0]);
|
|
720
|
+
end = binary.length
|
|
721
|
+
} else {
|
|
722
|
+
var int32View = new Uint32Array(new Uint8Array(binary.subarray(0, 24)).buffer);
|
|
723
|
+
var magicNumberFound = int32View[0] == 0x6d736100;
|
|
724
|
+
failIf(!magicNumberFound, 'need to see wasm magic number'); // \0asm
|
|
725
|
+
// we should see the dylink custom section right after the magic number and wasm version
|
|
726
|
+
failIf(binary[8] !== 0, 'need the dylink section to be first')
|
|
727
|
+
offset = 9;
|
|
728
|
+
var section_size = getLEB(); //section size
|
|
729
|
+
end = offset + section_size;
|
|
730
|
+
var name = getString();
|
|
731
|
+
failIf(name !== 'dylink.0');
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
var customSection = { neededDynlibs: [], tlsExports: new Set(), weakImports: new Set(), runtimePaths: [] };
|
|
735
|
+
var WASM_DYLINK_MEM_INFO = 0x1;
|
|
736
|
+
var WASM_DYLINK_NEEDED = 0x2;
|
|
737
|
+
var WASM_DYLINK_EXPORT_INFO = 0x3;
|
|
738
|
+
var WASM_DYLINK_IMPORT_INFO = 0x4;
|
|
739
|
+
var WASM_DYLINK_RUNTIME_PATH = 0x5;
|
|
740
|
+
var WASM_SYMBOL_TLS = 0x100;
|
|
741
|
+
var WASM_SYMBOL_BINDING_MASK = 0x3;
|
|
742
|
+
var WASM_SYMBOL_BINDING_WEAK = 0x1;
|
|
743
|
+
while (offset < end) {
|
|
744
|
+
var subsectionType = getU8();
|
|
745
|
+
var subsectionSize = getLEB();
|
|
746
|
+
if (subsectionType === WASM_DYLINK_MEM_INFO) {
|
|
747
|
+
customSection.memorySize = getLEB();
|
|
748
|
+
customSection.memoryAlign = getLEB();
|
|
749
|
+
customSection.tableSize = getLEB();
|
|
750
|
+
customSection.tableAlign = getLEB();
|
|
751
|
+
} else if (subsectionType === WASM_DYLINK_NEEDED) {
|
|
752
|
+
customSection.neededDynlibs = getStringList();
|
|
753
|
+
} else if (subsectionType === WASM_DYLINK_EXPORT_INFO) {
|
|
754
|
+
var count = getLEB();
|
|
755
|
+
while (count--) {
|
|
756
|
+
var symname = getString();
|
|
757
|
+
var flags = getLEB();
|
|
758
|
+
if (flags & WASM_SYMBOL_TLS) {
|
|
759
|
+
customSection.tlsExports.add(symname);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
} else if (subsectionType === WASM_DYLINK_IMPORT_INFO) {
|
|
763
|
+
var count = getLEB();
|
|
764
|
+
while (count--) {
|
|
765
|
+
var modname = getString();
|
|
766
|
+
var symname = getString();
|
|
767
|
+
var flags = getLEB();
|
|
768
|
+
if ((flags & WASM_SYMBOL_BINDING_MASK) == WASM_SYMBOL_BINDING_WEAK) {
|
|
769
|
+
customSection.weakImports.add(symname);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
} else if (subsectionType === WASM_DYLINK_RUNTIME_PATH) {
|
|
773
|
+
customSection.runtimePaths = getStringList();
|
|
774
|
+
} else {
|
|
775
|
+
// unknown subsection
|
|
776
|
+
offset += subsectionSize;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
return customSection;
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* @param {number} ptr
|
|
786
|
+
* @param {string} type
|
|
787
|
+
*/
|
|
788
|
+
function getValue(ptr, type = 'i8') {
|
|
789
|
+
if (type.endsWith('*')) type = '*';
|
|
790
|
+
switch (type) {
|
|
791
|
+
case 'i1': return HEAP8[ptr];
|
|
792
|
+
case 'i8': return HEAP8[ptr];
|
|
793
|
+
case 'i16': return HEAP16[((ptr)>>1)];
|
|
794
|
+
case 'i32': return HEAP32[((ptr)>>2)];
|
|
795
|
+
case 'i64': return HEAP64[((ptr)>>3)];
|
|
796
|
+
case 'float': return HEAPF32[((ptr)>>2)];
|
|
797
|
+
case 'double': return HEAPF64[((ptr)>>3)];
|
|
798
|
+
case '*': return HEAPU32[((ptr)>>2)];
|
|
799
|
+
default: abort(`invalid type for getValue: ${type}`);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
var newDSO = (name, handle, syms) => {
|
|
804
|
+
var dso = {
|
|
805
|
+
refcount: Infinity,
|
|
806
|
+
name,
|
|
807
|
+
exports: syms,
|
|
808
|
+
global: true,
|
|
809
|
+
};
|
|
810
|
+
LDSO.loadedLibsByName[name] = dso;
|
|
811
|
+
if (handle != undefined) {
|
|
812
|
+
LDSO.loadedLibsByHandle[handle] = dso;
|
|
813
|
+
}
|
|
814
|
+
return dso;
|
|
815
|
+
};
|
|
816
|
+
var LDSO = {
|
|
817
|
+
loadedLibsByName:{
|
|
818
|
+
},
|
|
819
|
+
loadedLibsByHandle:{
|
|
820
|
+
},
|
|
821
|
+
init() {
|
|
822
|
+
newDSO('__main__', 0, wasmImports);
|
|
823
|
+
},
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
var ___heap_base = 201984;
|
|
829
|
+
|
|
830
|
+
var alignMemory = (size, alignment) => {
|
|
831
|
+
return Math.ceil(size / alignment) * alignment;
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
var getMemory = (size) => {
|
|
835
|
+
// After the runtime is initialized, we must only use sbrk() normally.
|
|
836
|
+
if (runtimeInitialized) {
|
|
837
|
+
// Currently we don't support freeing of static data when modules are
|
|
838
|
+
// unloaded via dlclose. This function is tagged as `noleakcheck` to
|
|
839
|
+
// avoid having this reported as leak.
|
|
840
|
+
return _calloc(size, 1);
|
|
841
|
+
}
|
|
842
|
+
var ret = ___heap_base;
|
|
843
|
+
// Keep __heap_base stack aligned.
|
|
844
|
+
var end = ret + alignMemory(size, 16);
|
|
845
|
+
___heap_base = end;
|
|
846
|
+
GOT['__heap_base'].value = end;
|
|
847
|
+
return ret;
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
var isInternalSym = (symName) => {
|
|
852
|
+
// TODO: find a way to mark these in the binary or avoid exporting them.
|
|
853
|
+
return [
|
|
854
|
+
'__cpp_exception',
|
|
855
|
+
'__c_longjmp',
|
|
856
|
+
'__wasm_apply_data_relocs',
|
|
857
|
+
'__dso_handle',
|
|
858
|
+
'__tls_size',
|
|
859
|
+
'__tls_align',
|
|
860
|
+
'__set_stack_limits',
|
|
861
|
+
'_emscripten_tls_init',
|
|
862
|
+
'__wasm_init_tls',
|
|
863
|
+
'__wasm_call_ctors',
|
|
864
|
+
'__start_em_asm',
|
|
865
|
+
'__stop_em_asm',
|
|
866
|
+
'__start_em_js',
|
|
867
|
+
'__stop_em_js',
|
|
868
|
+
].includes(symName) || symName.startsWith('__em_js__')
|
|
869
|
+
;
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
var uleb128Encode = (n, target) => {
|
|
873
|
+
if (n < 128) {
|
|
874
|
+
target.push(n);
|
|
875
|
+
} else {
|
|
876
|
+
target.push((n % 128) | 128, n >> 7);
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
var sigToWasmTypes = (sig) => {
|
|
881
|
+
var typeNames = {
|
|
882
|
+
'i': 'i32',
|
|
883
|
+
'j': 'i64',
|
|
884
|
+
'f': 'f32',
|
|
885
|
+
'd': 'f64',
|
|
886
|
+
'e': 'externref',
|
|
887
|
+
'p': 'i32',
|
|
888
|
+
};
|
|
889
|
+
var type = {
|
|
890
|
+
parameters: [],
|
|
891
|
+
results: sig[0] == 'v' ? [] : [typeNames[sig[0]]]
|
|
892
|
+
};
|
|
893
|
+
for (var i = 1; i < sig.length; ++i) {
|
|
894
|
+
type.parameters.push(typeNames[sig[i]]);
|
|
895
|
+
}
|
|
896
|
+
return type;
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
var generateFuncType = (sig, target) => {
|
|
900
|
+
var sigRet = sig.slice(0, 1);
|
|
901
|
+
var sigParam = sig.slice(1);
|
|
902
|
+
var typeCodes = {
|
|
903
|
+
'i': 0x7f, // i32
|
|
904
|
+
'p': 0x7f, // i32
|
|
905
|
+
'j': 0x7e, // i64
|
|
906
|
+
'f': 0x7d, // f32
|
|
907
|
+
'd': 0x7c, // f64
|
|
908
|
+
'e': 0x6f, // externref
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
// Parameters, length + signatures
|
|
912
|
+
target.push(0x60 /* form: func */);
|
|
913
|
+
uleb128Encode(sigParam.length, target);
|
|
914
|
+
for (var paramType of sigParam) {
|
|
915
|
+
target.push(typeCodes[paramType]);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// Return values, length + signatures
|
|
919
|
+
// With no multi-return in MVP, either 0 (void) or 1 (anything else)
|
|
920
|
+
if (sigRet == 'v') {
|
|
921
|
+
target.push(0x00);
|
|
922
|
+
} else {
|
|
923
|
+
target.push(0x01, typeCodes[sigRet]);
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
var convertJsFunctionToWasm = (func, sig) => {
|
|
927
|
+
|
|
928
|
+
// If the type reflection proposal is available, use the new
|
|
929
|
+
// "WebAssembly.Function" constructor.
|
|
930
|
+
// Otherwise, construct a minimal wasm module importing the JS function and
|
|
931
|
+
// re-exporting it.
|
|
932
|
+
if (typeof WebAssembly.Function == "function") {
|
|
933
|
+
return new WebAssembly.Function(sigToWasmTypes(sig), func);
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// The module is static, with the exception of the type section, which is
|
|
937
|
+
// generated based on the signature passed in.
|
|
938
|
+
var typeSectionBody = [
|
|
939
|
+
0x01, // count: 1
|
|
940
|
+
];
|
|
941
|
+
generateFuncType(sig, typeSectionBody);
|
|
942
|
+
|
|
943
|
+
// Rest of the module is static
|
|
944
|
+
var bytes = [
|
|
945
|
+
0x00, 0x61, 0x73, 0x6d, // magic ("\0asm")
|
|
946
|
+
0x01, 0x00, 0x00, 0x00, // version: 1
|
|
947
|
+
0x01, // Type section code
|
|
948
|
+
];
|
|
949
|
+
// Write the overall length of the type section followed by the body
|
|
950
|
+
uleb128Encode(typeSectionBody.length, bytes);
|
|
951
|
+
bytes.push(...typeSectionBody);
|
|
952
|
+
|
|
953
|
+
// The rest of the module is static
|
|
954
|
+
bytes.push(
|
|
955
|
+
0x02, 0x07, // import section
|
|
956
|
+
// (import "e" "f" (func 0 (type 0)))
|
|
957
|
+
0x01, 0x01, 0x65, 0x01, 0x66, 0x00, 0x00,
|
|
958
|
+
0x07, 0x05, // export section
|
|
959
|
+
// (export "f" (func 0 (type 0)))
|
|
960
|
+
0x01, 0x01, 0x66, 0x00, 0x00,
|
|
961
|
+
);
|
|
962
|
+
|
|
963
|
+
// We can compile this wasm module synchronously because it is very small.
|
|
964
|
+
// This accepts an import (at "e.f"), that it reroutes to an export (at "f")
|
|
965
|
+
var module = new WebAssembly.Module(new Uint8Array(bytes));
|
|
966
|
+
var instance = new WebAssembly.Instance(module, { 'e': { 'f': func } });
|
|
967
|
+
var wrappedFunc = instance.exports['f'];
|
|
968
|
+
return wrappedFunc;
|
|
969
|
+
};
|
|
970
|
+
|
|
971
|
+
var wasmTableMirror = [];
|
|
972
|
+
|
|
973
|
+
/** @type {WebAssembly.Table} */
|
|
974
|
+
var wasmTable = new WebAssembly.Table({
|
|
975
|
+
'initial': 223,
|
|
976
|
+
'element': 'anyfunc'
|
|
977
|
+
});
|
|
978
|
+
;
|
|
979
|
+
var getWasmTableEntry = (funcPtr) => {
|
|
980
|
+
var func = wasmTableMirror[funcPtr];
|
|
981
|
+
if (!func) {
|
|
982
|
+
/** @suppress {checkTypes} */
|
|
983
|
+
wasmTableMirror[funcPtr] = func = wasmTable.get(funcPtr);
|
|
984
|
+
}
|
|
985
|
+
return func;
|
|
986
|
+
};
|
|
987
|
+
|
|
988
|
+
var updateTableMap = (offset, count) => {
|
|
989
|
+
if (functionsInTableMap) {
|
|
990
|
+
for (var i = offset; i < offset + count; i++) {
|
|
991
|
+
var item = getWasmTableEntry(i);
|
|
992
|
+
// Ignore null values.
|
|
993
|
+
if (item) {
|
|
994
|
+
functionsInTableMap.set(item, i);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
var functionsInTableMap;
|
|
1001
|
+
|
|
1002
|
+
var getFunctionAddress = (func) => {
|
|
1003
|
+
// First, create the map if this is the first use.
|
|
1004
|
+
if (!functionsInTableMap) {
|
|
1005
|
+
functionsInTableMap = new WeakMap();
|
|
1006
|
+
updateTableMap(0, wasmTable.length);
|
|
1007
|
+
}
|
|
1008
|
+
return functionsInTableMap.get(func) || 0;
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
var freeTableIndexes = [];
|
|
1013
|
+
|
|
1014
|
+
var getEmptyTableSlot = () => {
|
|
1015
|
+
// Reuse a free index if there is one, otherwise grow.
|
|
1016
|
+
if (freeTableIndexes.length) {
|
|
1017
|
+
return freeTableIndexes.pop();
|
|
1018
|
+
}
|
|
1019
|
+
// Grow the table
|
|
1020
|
+
try {
|
|
1021
|
+
/** @suppress {checkTypes} */
|
|
1022
|
+
wasmTable.grow(1);
|
|
1023
|
+
} catch (err) {
|
|
1024
|
+
if (!(err instanceof RangeError)) {
|
|
1025
|
+
throw err;
|
|
1026
|
+
}
|
|
1027
|
+
throw 'Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.';
|
|
1028
|
+
}
|
|
1029
|
+
return wasmTable.length - 1;
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
var setWasmTableEntry = (idx, func) => {
|
|
1034
|
+
/** @suppress {checkTypes} */
|
|
1035
|
+
wasmTable.set(idx, func);
|
|
1036
|
+
// With ABORT_ON_WASM_EXCEPTIONS wasmTable.get is overridden to return wrapped
|
|
1037
|
+
// functions so we need to call it here to retrieve the potential wrapper correctly
|
|
1038
|
+
// instead of just storing 'func' directly into wasmTableMirror
|
|
1039
|
+
/** @suppress {checkTypes} */
|
|
1040
|
+
wasmTableMirror[idx] = wasmTable.get(idx);
|
|
1041
|
+
};
|
|
1042
|
+
/** @param {string=} sig */
|
|
1043
|
+
var addFunction = (func, sig) => {
|
|
1044
|
+
// Check if the function is already in the table, to ensure each function
|
|
1045
|
+
// gets a unique index.
|
|
1046
|
+
var rtn = getFunctionAddress(func);
|
|
1047
|
+
if (rtn) {
|
|
1048
|
+
return rtn;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
// It's not in the table, add it now.
|
|
1052
|
+
|
|
1053
|
+
var ret = getEmptyTableSlot();
|
|
1054
|
+
|
|
1055
|
+
// Set the new value.
|
|
1056
|
+
try {
|
|
1057
|
+
// Attempting to call this with JS function will cause of table.set() to fail
|
|
1058
|
+
setWasmTableEntry(ret, func);
|
|
1059
|
+
} catch (err) {
|
|
1060
|
+
if (!(err instanceof TypeError)) {
|
|
1061
|
+
throw err;
|
|
1062
|
+
}
|
|
1063
|
+
var wrapped = convertJsFunctionToWasm(func, sig);
|
|
1064
|
+
setWasmTableEntry(ret, wrapped);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
functionsInTableMap.set(func, ret);
|
|
1068
|
+
|
|
1069
|
+
return ret;
|
|
1070
|
+
};
|
|
1071
|
+
var updateGOT = (exports, replace) => {
|
|
1072
|
+
for (var symName in exports) {
|
|
1073
|
+
if (isInternalSym(symName)) {
|
|
1074
|
+
continue;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
var value = exports[symName];
|
|
1078
|
+
|
|
1079
|
+
GOT[symName] ||= new WebAssembly.Global({'value': 'i32', 'mutable': true});
|
|
1080
|
+
if (replace || GOT[symName].value == 0) {
|
|
1081
|
+
if (typeof value == 'function') {
|
|
1082
|
+
GOT[symName].value = addFunction(value);
|
|
1083
|
+
} else if (typeof value == 'number') {
|
|
1084
|
+
GOT[symName].value = value;
|
|
1085
|
+
} else {
|
|
1086
|
+
err(`unhandled export type for '${symName}': ${typeof value}`);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
};
|
|
1091
|
+
/** @param {boolean=} replace */
|
|
1092
|
+
var relocateExports = (exports, memoryBase, replace) => {
|
|
1093
|
+
var relocated = {};
|
|
1094
|
+
|
|
1095
|
+
for (var e in exports) {
|
|
1096
|
+
var value = exports[e];
|
|
1097
|
+
if (typeof value == 'object') {
|
|
1098
|
+
// a breaking change in the wasm spec, globals are now objects
|
|
1099
|
+
// https://github.com/WebAssembly/mutable-global/issues/1
|
|
1100
|
+
value = value.value;
|
|
1101
|
+
}
|
|
1102
|
+
if (typeof value == 'number') {
|
|
1103
|
+
value += memoryBase;
|
|
1104
|
+
}
|
|
1105
|
+
relocated[e] = value;
|
|
1106
|
+
}
|
|
1107
|
+
updateGOT(relocated, replace);
|
|
1108
|
+
return relocated;
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
var isSymbolDefined = (symName) => {
|
|
1112
|
+
// Ignore 'stub' symbols that are auto-generated as part of the original
|
|
1113
|
+
// `wasmImports` used to instantiate the main module.
|
|
1114
|
+
var existing = wasmImports[symName];
|
|
1115
|
+
if (!existing || existing.stub) {
|
|
1116
|
+
return false;
|
|
1117
|
+
}
|
|
1118
|
+
return true;
|
|
1119
|
+
};
|
|
1120
|
+
var resolveGlobalSymbol = (symName, direct = false) => {
|
|
1121
|
+
var sym;
|
|
1122
|
+
if (isSymbolDefined(symName)) {
|
|
1123
|
+
sym = wasmImports[symName];
|
|
1124
|
+
}
|
|
1125
|
+
return {sym, name: symName};
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
var onPostCtors = [];
|
|
1135
|
+
var addOnPostCtor = (cb) => onPostCtors.push(cb);
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
/**
|
|
1139
|
+
* Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
|
|
1140
|
+
* emscripten HEAP, returns a copy of that string as a Javascript String object.
|
|
1141
|
+
*
|
|
1142
|
+
* @param {number} ptr
|
|
1143
|
+
* @param {number=} maxBytesToRead - An optional length that specifies the
|
|
1144
|
+
* maximum number of bytes to read. You can omit this parameter to scan the
|
|
1145
|
+
* string until the first 0 byte. If maxBytesToRead is passed, and the string
|
|
1146
|
+
* at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
|
|
1147
|
+
* string will cut short at that byte index (i.e. maxBytesToRead will not
|
|
1148
|
+
* produce a string of exact length [ptr, ptr+maxBytesToRead[) N.B. mixing
|
|
1149
|
+
* frequent uses of UTF8ToString() with and without maxBytesToRead may throw
|
|
1150
|
+
* JS JIT optimizations off, so it is worth to consider consistently using one
|
|
1151
|
+
* @return {string}
|
|
1152
|
+
*/
|
|
1153
|
+
var UTF8ToString = (ptr, maxBytesToRead) => {
|
|
1154
|
+
return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
|
|
1155
|
+
};
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* @param {string=} libName
|
|
1159
|
+
* @param {Object=} localScope
|
|
1160
|
+
* @param {number=} handle
|
|
1161
|
+
*/
|
|
1162
|
+
var loadWebAssemblyModule = (binary, flags, libName, localScope, handle) => {
|
|
1163
|
+
var metadata = getDylinkMetadata(binary);
|
|
1164
|
+
currentModuleWeakSymbols = metadata.weakImports;
|
|
1165
|
+
|
|
1166
|
+
// loadModule loads the wasm module after all its dependencies have been loaded.
|
|
1167
|
+
// can be called both sync/async.
|
|
1168
|
+
function loadModule() {
|
|
1169
|
+
// alignments are powers of 2
|
|
1170
|
+
var memAlign = Math.pow(2, metadata.memoryAlign);
|
|
1171
|
+
// prepare memory
|
|
1172
|
+
var memoryBase = metadata.memorySize ? alignMemory(getMemory(metadata.memorySize + memAlign), memAlign) : 0; // TODO: add to cleanups
|
|
1173
|
+
var tableBase = metadata.tableSize ? wasmTable.length : 0;
|
|
1174
|
+
if (handle) {
|
|
1175
|
+
HEAP8[(handle)+(8)] = 1;
|
|
1176
|
+
HEAPU32[(((handle)+(12))>>2)] = memoryBase;
|
|
1177
|
+
HEAP32[(((handle)+(16))>>2)] = metadata.memorySize;
|
|
1178
|
+
HEAPU32[(((handle)+(20))>>2)] = tableBase;
|
|
1179
|
+
HEAP32[(((handle)+(24))>>2)] = metadata.tableSize;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
if (metadata.tableSize) {
|
|
1183
|
+
wasmTable.grow(metadata.tableSize);
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// This is the export map that we ultimately return. We declare it here
|
|
1187
|
+
// so it can be used within resolveSymbol. We resolve symbols against
|
|
1188
|
+
// this local symbol map in the case there they are not present on the
|
|
1189
|
+
// global Module object. We need this fallback because Modules sometime
|
|
1190
|
+
// need to import their own symbols
|
|
1191
|
+
var moduleExports;
|
|
1192
|
+
|
|
1193
|
+
function resolveSymbol(sym) {
|
|
1194
|
+
var resolved = resolveGlobalSymbol(sym).sym;
|
|
1195
|
+
if (!resolved && localScope) {
|
|
1196
|
+
resolved = localScope[sym];
|
|
1197
|
+
}
|
|
1198
|
+
if (!resolved) {
|
|
1199
|
+
resolved = moduleExports[sym];
|
|
1200
|
+
}
|
|
1201
|
+
return resolved;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
// TODO kill ↓↓↓ (except "symbols local to this module", it will likely be
|
|
1205
|
+
// not needed if we require that if A wants symbols from B it has to link
|
|
1206
|
+
// to B explicitly: similarly to -Wl,--no-undefined)
|
|
1207
|
+
//
|
|
1208
|
+
// wasm dynamic libraries are pure wasm, so they cannot assist in
|
|
1209
|
+
// their own loading. When side module A wants to import something
|
|
1210
|
+
// provided by a side module B that is loaded later, we need to
|
|
1211
|
+
// add a layer of indirection, but worse, we can't even tell what
|
|
1212
|
+
// to add the indirection for, without inspecting what A's imports
|
|
1213
|
+
// are. To do that here, we use a JS proxy (another option would
|
|
1214
|
+
// be to inspect the binary directly).
|
|
1215
|
+
var proxyHandler = {
|
|
1216
|
+
get(stubs, prop) {
|
|
1217
|
+
// symbols that should be local to this module
|
|
1218
|
+
switch (prop) {
|
|
1219
|
+
case '__memory_base':
|
|
1220
|
+
return memoryBase;
|
|
1221
|
+
case '__table_base':
|
|
1222
|
+
return tableBase;
|
|
1223
|
+
}
|
|
1224
|
+
if (prop in wasmImports && !wasmImports[prop].stub) {
|
|
1225
|
+
// No stub needed, symbol already exists in symbol table
|
|
1226
|
+
var res = wasmImports[prop];
|
|
1227
|
+
return res;
|
|
1228
|
+
}
|
|
1229
|
+
// Return a stub function that will resolve the symbol
|
|
1230
|
+
// when first called.
|
|
1231
|
+
if (!(prop in stubs)) {
|
|
1232
|
+
var resolved;
|
|
1233
|
+
stubs[prop] = (...args) => {
|
|
1234
|
+
resolved ||= resolveSymbol(prop);
|
|
1235
|
+
return resolved(...args);
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
return stubs[prop];
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
var proxy = new Proxy({}, proxyHandler);
|
|
1242
|
+
var info = {
|
|
1243
|
+
'GOT.mem': new Proxy({}, GOTHandler),
|
|
1244
|
+
'GOT.func': new Proxy({}, GOTHandler),
|
|
1245
|
+
'env': proxy,
|
|
1246
|
+
'wasi_snapshot_preview1': proxy,
|
|
1247
|
+
};
|
|
1248
|
+
|
|
1249
|
+
function postInstantiation(module, instance) {
|
|
1250
|
+
// add new entries to functionsInTableMap
|
|
1251
|
+
updateTableMap(tableBase, metadata.tableSize);
|
|
1252
|
+
moduleExports = relocateExports(instance.exports, memoryBase);
|
|
1253
|
+
if (!flags.allowUndefined) {
|
|
1254
|
+
reportUndefinedSymbols();
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
function addEmAsm(addr, body) {
|
|
1258
|
+
var args = [];
|
|
1259
|
+
var arity = 0;
|
|
1260
|
+
for (; arity < 16; arity++) {
|
|
1261
|
+
if (body.indexOf('$' + arity) != -1) {
|
|
1262
|
+
args.push('$' + arity);
|
|
1263
|
+
} else {
|
|
1264
|
+
break;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
args = args.join(',');
|
|
1268
|
+
var func = `(${args}) => { ${body} };`;
|
|
1269
|
+
ASM_CONSTS[start] = eval(func);
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
// Add any EM_ASM function that exist in the side module
|
|
1273
|
+
if ('__start_em_asm' in moduleExports) {
|
|
1274
|
+
var start = moduleExports['__start_em_asm'];
|
|
1275
|
+
var stop = moduleExports['__stop_em_asm'];
|
|
1276
|
+
|
|
1277
|
+
|
|
1278
|
+
while (start < stop) {
|
|
1279
|
+
var jsString = UTF8ToString(start);
|
|
1280
|
+
addEmAsm(start, jsString);
|
|
1281
|
+
start = HEAPU8.indexOf(0, start) + 1;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
function addEmJs(name, cSig, body) {
|
|
1286
|
+
// The signature here is a C signature (e.g. "(int foo, char* bar)").
|
|
1287
|
+
// See `create_em_js` in emcc.py` for the build-time version of this
|
|
1288
|
+
// code.
|
|
1289
|
+
var jsArgs = [];
|
|
1290
|
+
cSig = cSig.slice(1, -1)
|
|
1291
|
+
if (cSig != 'void') {
|
|
1292
|
+
cSig = cSig.split(',');
|
|
1293
|
+
for (var i in cSig) {
|
|
1294
|
+
var jsArg = cSig[i].split(' ').pop();
|
|
1295
|
+
jsArgs.push(jsArg.replace('*', ''));
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
var func = `(${jsArgs}) => ${body};`;
|
|
1299
|
+
moduleExports[name] = eval(func);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
for (var name in moduleExports) {
|
|
1303
|
+
if (name.startsWith('__em_js__')) {
|
|
1304
|
+
var start = moduleExports[name]
|
|
1305
|
+
var jsString = UTF8ToString(start);
|
|
1306
|
+
// EM_JS strings are stored in the data section in the form
|
|
1307
|
+
// SIG<::>BODY.
|
|
1308
|
+
var parts = jsString.split('<::>');
|
|
1309
|
+
addEmJs(name.replace('__em_js__', ''), parts[0], parts[1]);
|
|
1310
|
+
delete moduleExports[name];
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
// initialize the module
|
|
1315
|
+
var applyRelocs = moduleExports['__wasm_apply_data_relocs'];
|
|
1316
|
+
if (applyRelocs) {
|
|
1317
|
+
if (runtimeInitialized) {
|
|
1318
|
+
applyRelocs();
|
|
1319
|
+
} else {
|
|
1320
|
+
__RELOC_FUNCS__.push(applyRelocs);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
var init = moduleExports['__wasm_call_ctors'];
|
|
1324
|
+
if (init) {
|
|
1325
|
+
if (runtimeInitialized) {
|
|
1326
|
+
init();
|
|
1327
|
+
} else {
|
|
1328
|
+
// we aren't ready to run compiled code yet
|
|
1329
|
+
addOnPostCtor(init);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
return moduleExports;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
if (flags.loadAsync) {
|
|
1336
|
+
return (async () => {
|
|
1337
|
+
var instance;
|
|
1338
|
+
if (binary instanceof WebAssembly.Module) {
|
|
1339
|
+
instance = new WebAssembly.Instance(binary, info);
|
|
1340
|
+
} else {
|
|
1341
|
+
// Destructuring assignment without declaration has to be wrapped
|
|
1342
|
+
// with parens or parser will treat the l-value as an object
|
|
1343
|
+
// literal instead.
|
|
1344
|
+
({ module: binary, instance } = await WebAssembly.instantiate(binary, info));
|
|
1345
|
+
}
|
|
1346
|
+
return postInstantiation(binary, instance);
|
|
1347
|
+
})();
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
var module = binary instanceof WebAssembly.Module ? binary : new WebAssembly.Module(binary);
|
|
1351
|
+
var instance = new WebAssembly.Instance(module, info);
|
|
1352
|
+
return postInstantiation(module, instance);
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
// We need to set rpath in flags based on the current library's rpath.
|
|
1356
|
+
// We can't mutate flags or else if a depends on b and c and b depends on d,
|
|
1357
|
+
// then c will be loaded with b's rpath instead of a's.
|
|
1358
|
+
flags = {...flags, rpath: { parentLibPath: libName, paths: metadata.runtimePaths }}
|
|
1359
|
+
// now load needed libraries and the module itself.
|
|
1360
|
+
if (flags.loadAsync) {
|
|
1361
|
+
return metadata.neededDynlibs
|
|
1362
|
+
.reduce((chain, dynNeeded) => chain.then(() =>
|
|
1363
|
+
loadDynamicLibrary(dynNeeded, flags, localScope)
|
|
1364
|
+
), Promise.resolve())
|
|
1365
|
+
.then(loadModule);
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
metadata.neededDynlibs.forEach((needed) => loadDynamicLibrary(needed, flags, localScope));
|
|
1369
|
+
return loadModule();
|
|
1370
|
+
};
|
|
1371
|
+
|
|
1372
|
+
var mergeLibSymbols = (exports, libName) => {
|
|
1373
|
+
// add symbols into global namespace TODO: weak linking etc.
|
|
1374
|
+
for (var [sym, exp] of Object.entries(exports)) {
|
|
1375
|
+
|
|
1376
|
+
// When RTLD_GLOBAL is enabled, the symbols defined by this shared object
|
|
1377
|
+
// will be made available for symbol resolution of subsequently loaded
|
|
1378
|
+
// shared objects.
|
|
1379
|
+
//
|
|
1380
|
+
// We should copy the symbols (which include methods and variables) from
|
|
1381
|
+
// SIDE_MODULE to MAIN_MODULE.
|
|
1382
|
+
const setImport = (target) => {
|
|
1383
|
+
if (!isSymbolDefined(target)) {
|
|
1384
|
+
wasmImports[target] = exp;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
setImport(sym);
|
|
1388
|
+
|
|
1389
|
+
}
|
|
1390
|
+
};
|
|
1391
|
+
|
|
1392
|
+
|
|
1393
|
+
var asyncLoad = async (url) => {
|
|
1394
|
+
var arrayBuffer = await readAsync(url);
|
|
1395
|
+
return new Uint8Array(arrayBuffer);
|
|
1396
|
+
};
|
|
1397
|
+
|
|
1398
|
+
var preloadPlugins = [];
|
|
1399
|
+
var registerWasmPlugin = () => {
|
|
1400
|
+
// Use string keys here to avoid minification since the plugin consumer
|
|
1401
|
+
// also uses string keys.
|
|
1402
|
+
var wasmPlugin = {
|
|
1403
|
+
'promiseChainEnd': Promise.resolve(),
|
|
1404
|
+
'canHandle': (name) => {
|
|
1405
|
+
return !Module['noWasmDecoding'] && name.endsWith('.so')
|
|
1406
|
+
},
|
|
1407
|
+
'handle': (byteArray, name, onload, onerror) => {
|
|
1408
|
+
// loadWebAssemblyModule can not load modules out-of-order, so rather
|
|
1409
|
+
// than just running the promises in parallel, this makes a chain of
|
|
1410
|
+
// promises to run in series.
|
|
1411
|
+
wasmPlugin['promiseChainEnd'] = wasmPlugin['promiseChainEnd'].then(
|
|
1412
|
+
() => loadWebAssemblyModule(byteArray, {loadAsync: true, nodelete: true}, name, {})).then(
|
|
1413
|
+
(exports) => {
|
|
1414
|
+
preloadedWasm[name] = exports;
|
|
1415
|
+
onload(byteArray);
|
|
1416
|
+
},
|
|
1417
|
+
(error) => {
|
|
1418
|
+
err(`failed to instantiate wasm: ${name}: ${error}`);
|
|
1419
|
+
onerror();
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
preloadPlugins.push(wasmPlugin);
|
|
1424
|
+
};
|
|
1425
|
+
var preloadedWasm = {
|
|
1426
|
+
};
|
|
1427
|
+
|
|
1428
|
+
var PATH = {
|
|
1429
|
+
isAbs:(path) => path.charAt(0) === '/',
|
|
1430
|
+
splitPath:(filename) => {
|
|
1431
|
+
var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
|
|
1432
|
+
return splitPathRe.exec(filename).slice(1);
|
|
1433
|
+
},
|
|
1434
|
+
normalizeArray:(parts, allowAboveRoot) => {
|
|
1435
|
+
// if the path tries to go above the root, `up` ends up > 0
|
|
1436
|
+
var up = 0;
|
|
1437
|
+
for (var i = parts.length - 1; i >= 0; i--) {
|
|
1438
|
+
var last = parts[i];
|
|
1439
|
+
if (last === '.') {
|
|
1440
|
+
parts.splice(i, 1);
|
|
1441
|
+
} else if (last === '..') {
|
|
1442
|
+
parts.splice(i, 1);
|
|
1443
|
+
up++;
|
|
1444
|
+
} else if (up) {
|
|
1445
|
+
parts.splice(i, 1);
|
|
1446
|
+
up--;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
// if the path is allowed to go above the root, restore leading ..s
|
|
1450
|
+
if (allowAboveRoot) {
|
|
1451
|
+
for (; up; up--) {
|
|
1452
|
+
parts.unshift('..');
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
return parts;
|
|
1456
|
+
},
|
|
1457
|
+
normalize:(path) => {
|
|
1458
|
+
var isAbsolute = PATH.isAbs(path),
|
|
1459
|
+
trailingSlash = path.slice(-1) === '/';
|
|
1460
|
+
// Normalize the path
|
|
1461
|
+
path = PATH.normalizeArray(path.split('/').filter((p) => !!p), !isAbsolute).join('/');
|
|
1462
|
+
if (!path && !isAbsolute) {
|
|
1463
|
+
path = '.';
|
|
1464
|
+
}
|
|
1465
|
+
if (path && trailingSlash) {
|
|
1466
|
+
path += '/';
|
|
1467
|
+
}
|
|
1468
|
+
return (isAbsolute ? '/' : '') + path;
|
|
1469
|
+
},
|
|
1470
|
+
dirname:(path) => {
|
|
1471
|
+
var result = PATH.splitPath(path),
|
|
1472
|
+
root = result[0],
|
|
1473
|
+
dir = result[1];
|
|
1474
|
+
if (!root && !dir) {
|
|
1475
|
+
// No dirname whatsoever
|
|
1476
|
+
return '.';
|
|
1477
|
+
}
|
|
1478
|
+
if (dir) {
|
|
1479
|
+
// It has a dirname, strip trailing slash
|
|
1480
|
+
dir = dir.slice(0, -1);
|
|
1481
|
+
}
|
|
1482
|
+
return root + dir;
|
|
1483
|
+
},
|
|
1484
|
+
basename:(path) => path && path.match(/([^\/]+|\/)\/*$/)[1],
|
|
1485
|
+
join:(...paths) => PATH.normalize(paths.join('/')),
|
|
1486
|
+
join2:(l, r) => PATH.normalize(l + '/' + r),
|
|
1487
|
+
};
|
|
1488
|
+
var replaceORIGIN = (parentLibName, rpath) => {
|
|
1489
|
+
if (rpath.startsWith('$ORIGIN')) {
|
|
1490
|
+
// TODO: what to do if we only know the relative path of the file? It will return "." here.
|
|
1491
|
+
var origin = PATH.dirname(parentLibName);
|
|
1492
|
+
return rpath.replace('$ORIGIN', origin);
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
return rpath;
|
|
1496
|
+
};
|
|
1497
|
+
|
|
1498
|
+
|
|
1499
|
+
var stackSave = () => _emscripten_stack_get_current();
|
|
1500
|
+
|
|
1501
|
+
var stackRestore = (val) => __emscripten_stack_restore(val);
|
|
1502
|
+
var withStackSave = (f) => {
|
|
1503
|
+
var stack = stackSave();
|
|
1504
|
+
var ret = f();
|
|
1505
|
+
stackRestore(stack);
|
|
1506
|
+
return ret;
|
|
1507
|
+
};
|
|
1508
|
+
|
|
1509
|
+
var stackAlloc = (sz) => __emscripten_stack_alloc(sz);
|
|
1510
|
+
|
|
1511
|
+
var lengthBytesUTF8 = (str) => {
|
|
1512
|
+
var len = 0;
|
|
1513
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1514
|
+
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
|
|
1515
|
+
// unit, not a Unicode code point of the character! So decode
|
|
1516
|
+
// UTF16->UTF32->UTF8.
|
|
1517
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
1518
|
+
var c = str.charCodeAt(i); // possibly a lead surrogate
|
|
1519
|
+
if (c <= 0x7F) {
|
|
1520
|
+
len++;
|
|
1521
|
+
} else if (c <= 0x7FF) {
|
|
1522
|
+
len += 2;
|
|
1523
|
+
} else if (c >= 0xD800 && c <= 0xDFFF) {
|
|
1524
|
+
len += 4; ++i;
|
|
1525
|
+
} else {
|
|
1526
|
+
len += 3;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
return len;
|
|
1530
|
+
};
|
|
1531
|
+
|
|
1532
|
+
|
|
1533
|
+
var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
|
|
1534
|
+
// Parameter maxBytesToWrite is not optional. Negative values, 0, null,
|
|
1535
|
+
// undefined and false each don't write out any bytes.
|
|
1536
|
+
if (!(maxBytesToWrite > 0))
|
|
1537
|
+
return 0;
|
|
1538
|
+
|
|
1539
|
+
var startIdx = outIdx;
|
|
1540
|
+
var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
|
|
1541
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1542
|
+
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
|
|
1543
|
+
// unit, not a Unicode code point of the character! So decode
|
|
1544
|
+
// UTF16->UTF32->UTF8.
|
|
1545
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
1546
|
+
// For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description
|
|
1547
|
+
// and https://www.ietf.org/rfc/rfc2279.txt
|
|
1548
|
+
// and https://tools.ietf.org/html/rfc3629
|
|
1549
|
+
var u = str.charCodeAt(i); // possibly a lead surrogate
|
|
1550
|
+
if (u >= 0xD800 && u <= 0xDFFF) {
|
|
1551
|
+
var u1 = str.charCodeAt(++i);
|
|
1552
|
+
u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF);
|
|
1553
|
+
}
|
|
1554
|
+
if (u <= 0x7F) {
|
|
1555
|
+
if (outIdx >= endIdx) break;
|
|
1556
|
+
heap[outIdx++] = u;
|
|
1557
|
+
} else if (u <= 0x7FF) {
|
|
1558
|
+
if (outIdx + 1 >= endIdx) break;
|
|
1559
|
+
heap[outIdx++] = 0xC0 | (u >> 6);
|
|
1560
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
1561
|
+
} else if (u <= 0xFFFF) {
|
|
1562
|
+
if (outIdx + 2 >= endIdx) break;
|
|
1563
|
+
heap[outIdx++] = 0xE0 | (u >> 12);
|
|
1564
|
+
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
1565
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
1566
|
+
} else {
|
|
1567
|
+
if (outIdx + 3 >= endIdx) break;
|
|
1568
|
+
heap[outIdx++] = 0xF0 | (u >> 18);
|
|
1569
|
+
heap[outIdx++] = 0x80 | ((u >> 12) & 63);
|
|
1570
|
+
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
1571
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
// Null-terminate the pointer to the buffer.
|
|
1575
|
+
heap[outIdx] = 0;
|
|
1576
|
+
return outIdx - startIdx;
|
|
1577
|
+
};
|
|
1578
|
+
var stringToUTF8 = (str, outPtr, maxBytesToWrite) => {
|
|
1579
|
+
return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
|
|
1580
|
+
};
|
|
1581
|
+
|
|
1582
|
+
var stringToUTF8OnStack = (str) => {
|
|
1583
|
+
var size = lengthBytesUTF8(str) + 1;
|
|
1584
|
+
var ret = stackAlloc(size);
|
|
1585
|
+
stringToUTF8(str, ret, size);
|
|
1586
|
+
return ret;
|
|
1587
|
+
};
|
|
1588
|
+
|
|
1589
|
+
|
|
1590
|
+
var initRandomFill = () => {
|
|
1591
|
+
// This block is not needed on v19+ since crypto.getRandomValues is builtin
|
|
1592
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
1593
|
+
var nodeCrypto = require('crypto');
|
|
1594
|
+
return (view) => nodeCrypto.randomFillSync(view);
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
return (view) => crypto.getRandomValues(view);
|
|
1598
|
+
};
|
|
1599
|
+
var randomFill = (view) => {
|
|
1600
|
+
// Lazily init on the first invocation.
|
|
1601
|
+
(randomFill = initRandomFill())(view);
|
|
1602
|
+
};
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
|
|
1606
|
+
var PATH_FS = {
|
|
1607
|
+
resolve:(...args) => {
|
|
1608
|
+
var resolvedPath = '',
|
|
1609
|
+
resolvedAbsolute = false;
|
|
1610
|
+
for (var i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
1611
|
+
var path = (i >= 0) ? args[i] : FS.cwd();
|
|
1612
|
+
// Skip empty and invalid entries
|
|
1613
|
+
if (typeof path != 'string') {
|
|
1614
|
+
throw new TypeError('Arguments to path.resolve must be strings');
|
|
1615
|
+
} else if (!path) {
|
|
1616
|
+
return ''; // an invalid portion invalidates the whole thing
|
|
1617
|
+
}
|
|
1618
|
+
resolvedPath = path + '/' + resolvedPath;
|
|
1619
|
+
resolvedAbsolute = PATH.isAbs(path);
|
|
1620
|
+
}
|
|
1621
|
+
// At this point the path should be resolved to a full absolute path, but
|
|
1622
|
+
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
1623
|
+
resolvedPath = PATH.normalizeArray(resolvedPath.split('/').filter((p) => !!p), !resolvedAbsolute).join('/');
|
|
1624
|
+
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
|
1625
|
+
},
|
|
1626
|
+
relative:(from, to) => {
|
|
1627
|
+
from = PATH_FS.resolve(from).slice(1);
|
|
1628
|
+
to = PATH_FS.resolve(to).slice(1);
|
|
1629
|
+
function trim(arr) {
|
|
1630
|
+
var start = 0;
|
|
1631
|
+
for (; start < arr.length; start++) {
|
|
1632
|
+
if (arr[start] !== '') break;
|
|
1633
|
+
}
|
|
1634
|
+
var end = arr.length - 1;
|
|
1635
|
+
for (; end >= 0; end--) {
|
|
1636
|
+
if (arr[end] !== '') break;
|
|
1637
|
+
}
|
|
1638
|
+
if (start > end) return [];
|
|
1639
|
+
return arr.slice(start, end - start + 1);
|
|
1640
|
+
}
|
|
1641
|
+
var fromParts = trim(from.split('/'));
|
|
1642
|
+
var toParts = trim(to.split('/'));
|
|
1643
|
+
var length = Math.min(fromParts.length, toParts.length);
|
|
1644
|
+
var samePartsLength = length;
|
|
1645
|
+
for (var i = 0; i < length; i++) {
|
|
1646
|
+
if (fromParts[i] !== toParts[i]) {
|
|
1647
|
+
samePartsLength = i;
|
|
1648
|
+
break;
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
var outputParts = [];
|
|
1652
|
+
for (var i = samePartsLength; i < fromParts.length; i++) {
|
|
1653
|
+
outputParts.push('..');
|
|
1654
|
+
}
|
|
1655
|
+
outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
|
1656
|
+
return outputParts.join('/');
|
|
1657
|
+
},
|
|
1658
|
+
};
|
|
1659
|
+
|
|
1660
|
+
|
|
1661
|
+
|
|
1662
|
+
var FS_stdin_getChar_buffer = [];
|
|
1663
|
+
|
|
1664
|
+
|
|
1665
|
+
/** @type {function(string, boolean=, number=)} */
|
|
1666
|
+
var intArrayFromString = (stringy, dontAddNull, length) => {
|
|
1667
|
+
var len = length > 0 ? length : lengthBytesUTF8(stringy)+1;
|
|
1668
|
+
var u8array = new Array(len);
|
|
1669
|
+
var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
|
|
1670
|
+
if (dontAddNull) u8array.length = numBytesWritten;
|
|
1671
|
+
return u8array;
|
|
1672
|
+
};
|
|
1673
|
+
var FS_stdin_getChar = () => {
|
|
1674
|
+
if (!FS_stdin_getChar_buffer.length) {
|
|
1675
|
+
var result = null;
|
|
1676
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
1677
|
+
// we will read data by chunks of BUFSIZE
|
|
1678
|
+
var BUFSIZE = 256;
|
|
1679
|
+
var buf = Buffer.alloc(BUFSIZE);
|
|
1680
|
+
var bytesRead = 0;
|
|
1681
|
+
|
|
1682
|
+
// For some reason we must suppress a closure warning here, even though
|
|
1683
|
+
// fd definitely exists on process.stdin, and is even the proper way to
|
|
1684
|
+
// get the fd of stdin,
|
|
1685
|
+
// https://github.com/nodejs/help/issues/2136#issuecomment-523649904
|
|
1686
|
+
// This started to happen after moving this logic out of library_tty.js,
|
|
1687
|
+
// so it is related to the surrounding code in some unclear manner.
|
|
1688
|
+
/** @suppress {missingProperties} */
|
|
1689
|
+
var fd = process.stdin.fd;
|
|
1690
|
+
|
|
1691
|
+
try {
|
|
1692
|
+
bytesRead = fs.readSync(fd, buf, 0, BUFSIZE);
|
|
1693
|
+
} catch(e) {
|
|
1694
|
+
// Cross-platform differences: on Windows, reading EOF throws an
|
|
1695
|
+
// exception, but on other OSes, reading EOF returns 0. Uniformize
|
|
1696
|
+
// behavior by treating the EOF exception to return 0.
|
|
1697
|
+
if (e.toString().includes('EOF')) bytesRead = 0;
|
|
1698
|
+
else throw e;
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
if (bytesRead > 0) {
|
|
1702
|
+
result = buf.slice(0, bytesRead).toString('utf-8');
|
|
1703
|
+
}
|
|
1704
|
+
} else
|
|
1705
|
+
if (typeof window != 'undefined' &&
|
|
1706
|
+
typeof window.prompt == 'function') {
|
|
1707
|
+
// Browser.
|
|
1708
|
+
result = window.prompt('Input: '); // returns null on cancel
|
|
1709
|
+
if (result !== null) {
|
|
1710
|
+
result += '\n';
|
|
1711
|
+
}
|
|
1712
|
+
} else
|
|
1713
|
+
{}
|
|
1714
|
+
if (!result) {
|
|
1715
|
+
return null;
|
|
1716
|
+
}
|
|
1717
|
+
FS_stdin_getChar_buffer = intArrayFromString(result, true);
|
|
1718
|
+
}
|
|
1719
|
+
return FS_stdin_getChar_buffer.shift();
|
|
1720
|
+
};
|
|
1721
|
+
var TTY = {
|
|
1722
|
+
ttys:[],
|
|
1723
|
+
init() {
|
|
1724
|
+
// https://github.com/emscripten-core/emscripten/pull/1555
|
|
1725
|
+
// if (ENVIRONMENT_IS_NODE) {
|
|
1726
|
+
// // currently, FS.init does not distinguish if process.stdin is a file or TTY
|
|
1727
|
+
// // device, it always assumes it's a TTY device. because of this, we're forcing
|
|
1728
|
+
// // process.stdin to UTF8 encoding to at least make stdin reading compatible
|
|
1729
|
+
// // with text files until FS.init can be refactored.
|
|
1730
|
+
// process.stdin.setEncoding('utf8');
|
|
1731
|
+
// }
|
|
1732
|
+
},
|
|
1733
|
+
shutdown() {
|
|
1734
|
+
// https://github.com/emscripten-core/emscripten/pull/1555
|
|
1735
|
+
// if (ENVIRONMENT_IS_NODE) {
|
|
1736
|
+
// // inolen: any idea as to why node -e 'process.stdin.read()' wouldn't exit immediately (with process.stdin being a tty)?
|
|
1737
|
+
// // isaacs: because now it's reading from the stream, you've expressed interest in it, so that read() kicks off a _read() which creates a ReadReq operation
|
|
1738
|
+
// // inolen: I thought read() in that case was a synchronous operation that just grabbed some amount of buffered data if it exists?
|
|
1739
|
+
// // isaacs: it is. but it also triggers a _read() call, which calls readStart() on the handle
|
|
1740
|
+
// // isaacs: do process.stdin.pause() and i'd think it'd probably close the pending call
|
|
1741
|
+
// process.stdin.pause();
|
|
1742
|
+
// }
|
|
1743
|
+
},
|
|
1744
|
+
register(dev, ops) {
|
|
1745
|
+
TTY.ttys[dev] = { input: [], output: [], ops: ops };
|
|
1746
|
+
FS.registerDevice(dev, TTY.stream_ops);
|
|
1747
|
+
},
|
|
1748
|
+
stream_ops:{
|
|
1749
|
+
open(stream) {
|
|
1750
|
+
var tty = TTY.ttys[stream.node.rdev];
|
|
1751
|
+
if (!tty) {
|
|
1752
|
+
throw new FS.ErrnoError(43);
|
|
1753
|
+
}
|
|
1754
|
+
stream.tty = tty;
|
|
1755
|
+
stream.seekable = false;
|
|
1756
|
+
},
|
|
1757
|
+
close(stream) {
|
|
1758
|
+
// flush any pending line data
|
|
1759
|
+
stream.tty.ops.fsync(stream.tty);
|
|
1760
|
+
},
|
|
1761
|
+
fsync(stream) {
|
|
1762
|
+
stream.tty.ops.fsync(stream.tty);
|
|
1763
|
+
},
|
|
1764
|
+
read(stream, buffer, offset, length, pos /* ignored */) {
|
|
1765
|
+
if (!stream.tty || !stream.tty.ops.get_char) {
|
|
1766
|
+
throw new FS.ErrnoError(60);
|
|
1767
|
+
}
|
|
1768
|
+
var bytesRead = 0;
|
|
1769
|
+
for (var i = 0; i < length; i++) {
|
|
1770
|
+
var result;
|
|
1771
|
+
try {
|
|
1772
|
+
result = stream.tty.ops.get_char(stream.tty);
|
|
1773
|
+
} catch (e) {
|
|
1774
|
+
throw new FS.ErrnoError(29);
|
|
1775
|
+
}
|
|
1776
|
+
if (result === undefined && bytesRead === 0) {
|
|
1777
|
+
throw new FS.ErrnoError(6);
|
|
1778
|
+
}
|
|
1779
|
+
if (result === null || result === undefined) break;
|
|
1780
|
+
bytesRead++;
|
|
1781
|
+
buffer[offset+i] = result;
|
|
1782
|
+
}
|
|
1783
|
+
if (bytesRead) {
|
|
1784
|
+
stream.node.atime = Date.now();
|
|
1785
|
+
}
|
|
1786
|
+
return bytesRead;
|
|
1787
|
+
},
|
|
1788
|
+
write(stream, buffer, offset, length, pos) {
|
|
1789
|
+
if (!stream.tty || !stream.tty.ops.put_char) {
|
|
1790
|
+
throw new FS.ErrnoError(60);
|
|
1791
|
+
}
|
|
1792
|
+
try {
|
|
1793
|
+
for (var i = 0; i < length; i++) {
|
|
1794
|
+
stream.tty.ops.put_char(stream.tty, buffer[offset+i]);
|
|
1795
|
+
}
|
|
1796
|
+
} catch (e) {
|
|
1797
|
+
throw new FS.ErrnoError(29);
|
|
1798
|
+
}
|
|
1799
|
+
if (length) {
|
|
1800
|
+
stream.node.mtime = stream.node.ctime = Date.now();
|
|
1801
|
+
}
|
|
1802
|
+
return i;
|
|
1803
|
+
},
|
|
1804
|
+
},
|
|
1805
|
+
default_tty_ops:{
|
|
1806
|
+
get_char(tty) {
|
|
1807
|
+
return FS_stdin_getChar();
|
|
1808
|
+
},
|
|
1809
|
+
put_char(tty, val) {
|
|
1810
|
+
if (val === null || val === 10) {
|
|
1811
|
+
out(UTF8ArrayToString(tty.output));
|
|
1812
|
+
tty.output = [];
|
|
1813
|
+
} else {
|
|
1814
|
+
if (val != 0) tty.output.push(val); // val == 0 would cut text output off in the middle.
|
|
1815
|
+
}
|
|
1816
|
+
},
|
|
1817
|
+
fsync(tty) {
|
|
1818
|
+
if (tty.output?.length > 0) {
|
|
1819
|
+
out(UTF8ArrayToString(tty.output));
|
|
1820
|
+
tty.output = [];
|
|
1821
|
+
}
|
|
1822
|
+
},
|
|
1823
|
+
ioctl_tcgets(tty) {
|
|
1824
|
+
// typical setting
|
|
1825
|
+
return {
|
|
1826
|
+
c_iflag: 25856,
|
|
1827
|
+
c_oflag: 5,
|
|
1828
|
+
c_cflag: 191,
|
|
1829
|
+
c_lflag: 35387,
|
|
1830
|
+
c_cc: [
|
|
1831
|
+
0x03, 0x1c, 0x7f, 0x15, 0x04, 0x00, 0x01, 0x00, 0x11, 0x13, 0x1a, 0x00,
|
|
1832
|
+
0x12, 0x0f, 0x17, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
1833
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
1834
|
+
]
|
|
1835
|
+
};
|
|
1836
|
+
},
|
|
1837
|
+
ioctl_tcsets(tty, optional_actions, data) {
|
|
1838
|
+
// currently just ignore
|
|
1839
|
+
return 0;
|
|
1840
|
+
},
|
|
1841
|
+
ioctl_tiocgwinsz(tty) {
|
|
1842
|
+
return [24, 80];
|
|
1843
|
+
},
|
|
1844
|
+
},
|
|
1845
|
+
default_tty1_ops:{
|
|
1846
|
+
put_char(tty, val) {
|
|
1847
|
+
if (val === null || val === 10) {
|
|
1848
|
+
err(UTF8ArrayToString(tty.output));
|
|
1849
|
+
tty.output = [];
|
|
1850
|
+
} else {
|
|
1851
|
+
if (val != 0) tty.output.push(val);
|
|
1852
|
+
}
|
|
1853
|
+
},
|
|
1854
|
+
fsync(tty) {
|
|
1855
|
+
if (tty.output?.length > 0) {
|
|
1856
|
+
err(UTF8ArrayToString(tty.output));
|
|
1857
|
+
tty.output = [];
|
|
1858
|
+
}
|
|
1859
|
+
},
|
|
1860
|
+
},
|
|
1861
|
+
};
|
|
1862
|
+
|
|
1863
|
+
|
|
1864
|
+
var mmapAlloc = (size) => {
|
|
1865
|
+
abort();
|
|
1866
|
+
};
|
|
1867
|
+
var MEMFS = {
|
|
1868
|
+
ops_table:null,
|
|
1869
|
+
mount(mount) {
|
|
1870
|
+
return MEMFS.createNode(null, '/', 16895, 0);
|
|
1871
|
+
},
|
|
1872
|
+
createNode(parent, name, mode, dev) {
|
|
1873
|
+
if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
|
|
1874
|
+
// no supported
|
|
1875
|
+
throw new FS.ErrnoError(63);
|
|
1876
|
+
}
|
|
1877
|
+
MEMFS.ops_table ||= {
|
|
1878
|
+
dir: {
|
|
1879
|
+
node: {
|
|
1880
|
+
getattr: MEMFS.node_ops.getattr,
|
|
1881
|
+
setattr: MEMFS.node_ops.setattr,
|
|
1882
|
+
lookup: MEMFS.node_ops.lookup,
|
|
1883
|
+
mknod: MEMFS.node_ops.mknod,
|
|
1884
|
+
rename: MEMFS.node_ops.rename,
|
|
1885
|
+
unlink: MEMFS.node_ops.unlink,
|
|
1886
|
+
rmdir: MEMFS.node_ops.rmdir,
|
|
1887
|
+
readdir: MEMFS.node_ops.readdir,
|
|
1888
|
+
symlink: MEMFS.node_ops.symlink
|
|
1889
|
+
},
|
|
1890
|
+
stream: {
|
|
1891
|
+
llseek: MEMFS.stream_ops.llseek
|
|
1892
|
+
}
|
|
1893
|
+
},
|
|
1894
|
+
file: {
|
|
1895
|
+
node: {
|
|
1896
|
+
getattr: MEMFS.node_ops.getattr,
|
|
1897
|
+
setattr: MEMFS.node_ops.setattr
|
|
1898
|
+
},
|
|
1899
|
+
stream: {
|
|
1900
|
+
llseek: MEMFS.stream_ops.llseek,
|
|
1901
|
+
read: MEMFS.stream_ops.read,
|
|
1902
|
+
write: MEMFS.stream_ops.write,
|
|
1903
|
+
mmap: MEMFS.stream_ops.mmap,
|
|
1904
|
+
msync: MEMFS.stream_ops.msync
|
|
1905
|
+
}
|
|
1906
|
+
},
|
|
1907
|
+
link: {
|
|
1908
|
+
node: {
|
|
1909
|
+
getattr: MEMFS.node_ops.getattr,
|
|
1910
|
+
setattr: MEMFS.node_ops.setattr,
|
|
1911
|
+
readlink: MEMFS.node_ops.readlink
|
|
1912
|
+
},
|
|
1913
|
+
stream: {}
|
|
1914
|
+
},
|
|
1915
|
+
chrdev: {
|
|
1916
|
+
node: {
|
|
1917
|
+
getattr: MEMFS.node_ops.getattr,
|
|
1918
|
+
setattr: MEMFS.node_ops.setattr
|
|
1919
|
+
},
|
|
1920
|
+
stream: FS.chrdev_stream_ops
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
1923
|
+
var node = FS.createNode(parent, name, mode, dev);
|
|
1924
|
+
if (FS.isDir(node.mode)) {
|
|
1925
|
+
node.node_ops = MEMFS.ops_table.dir.node;
|
|
1926
|
+
node.stream_ops = MEMFS.ops_table.dir.stream;
|
|
1927
|
+
node.contents = {};
|
|
1928
|
+
} else if (FS.isFile(node.mode)) {
|
|
1929
|
+
node.node_ops = MEMFS.ops_table.file.node;
|
|
1930
|
+
node.stream_ops = MEMFS.ops_table.file.stream;
|
|
1931
|
+
node.usedBytes = 0; // The actual number of bytes used in the typed array, as opposed to contents.length which gives the whole capacity.
|
|
1932
|
+
// When the byte data of the file is populated, this will point to either a typed array, or a normal JS array. Typed arrays are preferred
|
|
1933
|
+
// for performance, and used by default. However, typed arrays are not resizable like normal JS arrays are, so there is a small disk size
|
|
1934
|
+
// penalty involved for appending file writes that continuously grow a file similar to std::vector capacity vs used -scheme.
|
|
1935
|
+
node.contents = null;
|
|
1936
|
+
} else if (FS.isLink(node.mode)) {
|
|
1937
|
+
node.node_ops = MEMFS.ops_table.link.node;
|
|
1938
|
+
node.stream_ops = MEMFS.ops_table.link.stream;
|
|
1939
|
+
} else if (FS.isChrdev(node.mode)) {
|
|
1940
|
+
node.node_ops = MEMFS.ops_table.chrdev.node;
|
|
1941
|
+
node.stream_ops = MEMFS.ops_table.chrdev.stream;
|
|
1942
|
+
}
|
|
1943
|
+
node.atime = node.mtime = node.ctime = Date.now();
|
|
1944
|
+
// add the new node to the parent
|
|
1945
|
+
if (parent) {
|
|
1946
|
+
parent.contents[name] = node;
|
|
1947
|
+
parent.atime = parent.mtime = parent.ctime = node.atime;
|
|
1948
|
+
}
|
|
1949
|
+
return node;
|
|
1950
|
+
},
|
|
1951
|
+
getFileDataAsTypedArray(node) {
|
|
1952
|
+
if (!node.contents) return new Uint8Array(0);
|
|
1953
|
+
if (node.contents.subarray) return node.contents.subarray(0, node.usedBytes); // Make sure to not return excess unused bytes.
|
|
1954
|
+
return new Uint8Array(node.contents);
|
|
1955
|
+
},
|
|
1956
|
+
expandFileStorage(node, newCapacity) {
|
|
1957
|
+
var prevCapacity = node.contents ? node.contents.length : 0;
|
|
1958
|
+
if (prevCapacity >= newCapacity) return; // No need to expand, the storage was already large enough.
|
|
1959
|
+
// Don't expand strictly to the given requested limit if it's only a very small increase, but instead geometrically grow capacity.
|
|
1960
|
+
// For small filesizes (<1MB), perform size*2 geometric increase, but for large sizes, do a much more conservative size*1.125 increase to
|
|
1961
|
+
// avoid overshooting the allocation cap by a very large margin.
|
|
1962
|
+
var CAPACITY_DOUBLING_MAX = 1024 * 1024;
|
|
1963
|
+
newCapacity = Math.max(newCapacity, (prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2.0 : 1.125)) >>> 0);
|
|
1964
|
+
if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256); // At minimum allocate 256b for each file when expanding.
|
|
1965
|
+
var oldContents = node.contents;
|
|
1966
|
+
node.contents = new Uint8Array(newCapacity); // Allocate new storage.
|
|
1967
|
+
if (node.usedBytes > 0) node.contents.set(oldContents.subarray(0, node.usedBytes), 0); // Copy old data over to the new storage.
|
|
1968
|
+
},
|
|
1969
|
+
resizeFileStorage(node, newSize) {
|
|
1970
|
+
if (node.usedBytes == newSize) return;
|
|
1971
|
+
if (newSize == 0) {
|
|
1972
|
+
node.contents = null; // Fully decommit when requesting a resize to zero.
|
|
1973
|
+
node.usedBytes = 0;
|
|
1974
|
+
} else {
|
|
1975
|
+
var oldContents = node.contents;
|
|
1976
|
+
node.contents = new Uint8Array(newSize); // Allocate new storage.
|
|
1977
|
+
if (oldContents) {
|
|
1978
|
+
node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes))); // Copy old data over to the new storage.
|
|
1979
|
+
}
|
|
1980
|
+
node.usedBytes = newSize;
|
|
1981
|
+
}
|
|
1982
|
+
},
|
|
1983
|
+
node_ops:{
|
|
1984
|
+
getattr(node) {
|
|
1985
|
+
var attr = {};
|
|
1986
|
+
// device numbers reuse inode numbers.
|
|
1987
|
+
attr.dev = FS.isChrdev(node.mode) ? node.id : 1;
|
|
1988
|
+
attr.ino = node.id;
|
|
1989
|
+
attr.mode = node.mode;
|
|
1990
|
+
attr.nlink = 1;
|
|
1991
|
+
attr.uid = 0;
|
|
1992
|
+
attr.gid = 0;
|
|
1993
|
+
attr.rdev = node.rdev;
|
|
1994
|
+
if (FS.isDir(node.mode)) {
|
|
1995
|
+
attr.size = 4096;
|
|
1996
|
+
} else if (FS.isFile(node.mode)) {
|
|
1997
|
+
attr.size = node.usedBytes;
|
|
1998
|
+
} else if (FS.isLink(node.mode)) {
|
|
1999
|
+
attr.size = node.link.length;
|
|
2000
|
+
} else {
|
|
2001
|
+
attr.size = 0;
|
|
2002
|
+
}
|
|
2003
|
+
attr.atime = new Date(node.atime);
|
|
2004
|
+
attr.mtime = new Date(node.mtime);
|
|
2005
|
+
attr.ctime = new Date(node.ctime);
|
|
2006
|
+
// NOTE: In our implementation, st_blocks = Math.ceil(st_size/st_blksize),
|
|
2007
|
+
// but this is not required by the standard.
|
|
2008
|
+
attr.blksize = 4096;
|
|
2009
|
+
attr.blocks = Math.ceil(attr.size / attr.blksize);
|
|
2010
|
+
return attr;
|
|
2011
|
+
},
|
|
2012
|
+
setattr(node, attr) {
|
|
2013
|
+
for (const key of ["mode", "atime", "mtime", "ctime"]) {
|
|
2014
|
+
if (attr[key] != null) {
|
|
2015
|
+
node[key] = attr[key];
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
if (attr.size !== undefined) {
|
|
2019
|
+
MEMFS.resizeFileStorage(node, attr.size);
|
|
2020
|
+
}
|
|
2021
|
+
},
|
|
2022
|
+
lookup(parent, name) {
|
|
2023
|
+
throw MEMFS.doesNotExistError;
|
|
2024
|
+
},
|
|
2025
|
+
mknod(parent, name, mode, dev) {
|
|
2026
|
+
return MEMFS.createNode(parent, name, mode, dev);
|
|
2027
|
+
},
|
|
2028
|
+
rename(old_node, new_dir, new_name) {
|
|
2029
|
+
var new_node;
|
|
2030
|
+
try {
|
|
2031
|
+
new_node = FS.lookupNode(new_dir, new_name);
|
|
2032
|
+
} catch (e) {}
|
|
2033
|
+
if (new_node) {
|
|
2034
|
+
if (FS.isDir(old_node.mode)) {
|
|
2035
|
+
// if we're overwriting a directory at new_name, make sure it's empty.
|
|
2036
|
+
for (var i in new_node.contents) {
|
|
2037
|
+
throw new FS.ErrnoError(55);
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
FS.hashRemoveNode(new_node);
|
|
2041
|
+
}
|
|
2042
|
+
// do the internal rewiring
|
|
2043
|
+
delete old_node.parent.contents[old_node.name];
|
|
2044
|
+
new_dir.contents[new_name] = old_node;
|
|
2045
|
+
old_node.name = new_name;
|
|
2046
|
+
new_dir.ctime = new_dir.mtime = old_node.parent.ctime = old_node.parent.mtime = Date.now();
|
|
2047
|
+
},
|
|
2048
|
+
unlink(parent, name) {
|
|
2049
|
+
delete parent.contents[name];
|
|
2050
|
+
parent.ctime = parent.mtime = Date.now();
|
|
2051
|
+
},
|
|
2052
|
+
rmdir(parent, name) {
|
|
2053
|
+
var node = FS.lookupNode(parent, name);
|
|
2054
|
+
for (var i in node.contents) {
|
|
2055
|
+
throw new FS.ErrnoError(55);
|
|
2056
|
+
}
|
|
2057
|
+
delete parent.contents[name];
|
|
2058
|
+
parent.ctime = parent.mtime = Date.now();
|
|
2059
|
+
},
|
|
2060
|
+
readdir(node) {
|
|
2061
|
+
return ['.', '..', ...Object.keys(node.contents)];
|
|
2062
|
+
},
|
|
2063
|
+
symlink(parent, newname, oldpath) {
|
|
2064
|
+
var node = MEMFS.createNode(parent, newname, 0o777 | 40960, 0);
|
|
2065
|
+
node.link = oldpath;
|
|
2066
|
+
return node;
|
|
2067
|
+
},
|
|
2068
|
+
readlink(node) {
|
|
2069
|
+
if (!FS.isLink(node.mode)) {
|
|
2070
|
+
throw new FS.ErrnoError(28);
|
|
2071
|
+
}
|
|
2072
|
+
return node.link;
|
|
2073
|
+
},
|
|
2074
|
+
},
|
|
2075
|
+
stream_ops:{
|
|
2076
|
+
read(stream, buffer, offset, length, position) {
|
|
2077
|
+
var contents = stream.node.contents;
|
|
2078
|
+
if (position >= stream.node.usedBytes) return 0;
|
|
2079
|
+
var size = Math.min(stream.node.usedBytes - position, length);
|
|
2080
|
+
if (size > 8 && contents.subarray) { // non-trivial, and typed array
|
|
2081
|
+
buffer.set(contents.subarray(position, position + size), offset);
|
|
2082
|
+
} else {
|
|
2083
|
+
for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i];
|
|
2084
|
+
}
|
|
2085
|
+
return size;
|
|
2086
|
+
},
|
|
2087
|
+
write(stream, buffer, offset, length, position, canOwn) {
|
|
2088
|
+
// If the buffer is located in main memory (HEAP), and if
|
|
2089
|
+
// memory can grow, we can't hold on to references of the
|
|
2090
|
+
// memory buffer, as they may get invalidated. That means we
|
|
2091
|
+
// need to do copy its contents.
|
|
2092
|
+
if (buffer.buffer === HEAP8.buffer) {
|
|
2093
|
+
canOwn = false;
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
if (!length) return 0;
|
|
2097
|
+
var node = stream.node;
|
|
2098
|
+
node.mtime = node.ctime = Date.now();
|
|
2099
|
+
|
|
2100
|
+
if (buffer.subarray && (!node.contents || node.contents.subarray)) { // This write is from a typed array to a typed array?
|
|
2101
|
+
if (canOwn) {
|
|
2102
|
+
node.contents = buffer.subarray(offset, offset + length);
|
|
2103
|
+
node.usedBytes = length;
|
|
2104
|
+
return length;
|
|
2105
|
+
} else if (node.usedBytes === 0 && position === 0) { // If this is a simple first write to an empty file, do a fast set since we don't need to care about old data.
|
|
2106
|
+
node.contents = buffer.slice(offset, offset + length);
|
|
2107
|
+
node.usedBytes = length;
|
|
2108
|
+
return length;
|
|
2109
|
+
} else if (position + length <= node.usedBytes) { // Writing to an already allocated and used subrange of the file?
|
|
2110
|
+
node.contents.set(buffer.subarray(offset, offset + length), position);
|
|
2111
|
+
return length;
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
// Appending to an existing file and we need to reallocate, or source data did not come as a typed array.
|
|
2116
|
+
MEMFS.expandFileStorage(node, position+length);
|
|
2117
|
+
if (node.contents.subarray && buffer.subarray) {
|
|
2118
|
+
// Use typed array write which is available.
|
|
2119
|
+
node.contents.set(buffer.subarray(offset, offset + length), position);
|
|
2120
|
+
} else {
|
|
2121
|
+
for (var i = 0; i < length; i++) {
|
|
2122
|
+
node.contents[position + i] = buffer[offset + i]; // Or fall back to manual write if not.
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
node.usedBytes = Math.max(node.usedBytes, position + length);
|
|
2126
|
+
return length;
|
|
2127
|
+
},
|
|
2128
|
+
llseek(stream, offset, whence) {
|
|
2129
|
+
var position = offset;
|
|
2130
|
+
if (whence === 1) {
|
|
2131
|
+
position += stream.position;
|
|
2132
|
+
} else if (whence === 2) {
|
|
2133
|
+
if (FS.isFile(stream.node.mode)) {
|
|
2134
|
+
position += stream.node.usedBytes;
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
if (position < 0) {
|
|
2138
|
+
throw new FS.ErrnoError(28);
|
|
2139
|
+
}
|
|
2140
|
+
return position;
|
|
2141
|
+
},
|
|
2142
|
+
mmap(stream, length, position, prot, flags) {
|
|
2143
|
+
if (!FS.isFile(stream.node.mode)) {
|
|
2144
|
+
throw new FS.ErrnoError(43);
|
|
2145
|
+
}
|
|
2146
|
+
var ptr;
|
|
2147
|
+
var allocated;
|
|
2148
|
+
var contents = stream.node.contents;
|
|
2149
|
+
// Only make a new copy when MAP_PRIVATE is specified.
|
|
2150
|
+
if (!(flags & 2) && contents && contents.buffer === HEAP8.buffer) {
|
|
2151
|
+
// We can't emulate MAP_SHARED when the file is not backed by the
|
|
2152
|
+
// buffer we're mapping to (e.g. the HEAP buffer).
|
|
2153
|
+
allocated = false;
|
|
2154
|
+
ptr = contents.byteOffset;
|
|
2155
|
+
} else {
|
|
2156
|
+
allocated = true;
|
|
2157
|
+
ptr = mmapAlloc(length);
|
|
2158
|
+
if (!ptr) {
|
|
2159
|
+
throw new FS.ErrnoError(48);
|
|
2160
|
+
}
|
|
2161
|
+
if (contents) {
|
|
2162
|
+
// Try to avoid unnecessary slices.
|
|
2163
|
+
if (position > 0 || position + length < contents.length) {
|
|
2164
|
+
if (contents.subarray) {
|
|
2165
|
+
contents = contents.subarray(position, position + length);
|
|
2166
|
+
} else {
|
|
2167
|
+
contents = Array.prototype.slice.call(contents, position, position + length);
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
HEAP8.set(contents, ptr);
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
return { ptr, allocated };
|
|
2174
|
+
},
|
|
2175
|
+
msync(stream, buffer, offset, length, mmapFlags) {
|
|
2176
|
+
MEMFS.stream_ops.write(stream, buffer, 0, length, offset, false);
|
|
2177
|
+
// should we check if bytesWritten and length are the same?
|
|
2178
|
+
return 0;
|
|
2179
|
+
},
|
|
2180
|
+
},
|
|
2181
|
+
};
|
|
2182
|
+
|
|
2183
|
+
|
|
2184
|
+
|
|
2185
|
+
var FS_createDataFile = (...args) => FS.createDataFile(...args);
|
|
2186
|
+
|
|
2187
|
+
var FS_handledByPreloadPlugin = (byteArray, fullname, finish, onerror) => {
|
|
2188
|
+
// Ensure plugins are ready.
|
|
2189
|
+
if (typeof Browser != 'undefined') Browser.init();
|
|
2190
|
+
|
|
2191
|
+
var handled = false;
|
|
2192
|
+
preloadPlugins.forEach((plugin) => {
|
|
2193
|
+
if (handled) return;
|
|
2194
|
+
if (plugin['canHandle'](fullname)) {
|
|
2195
|
+
plugin['handle'](byteArray, fullname, finish, onerror);
|
|
2196
|
+
handled = true;
|
|
2197
|
+
}
|
|
2198
|
+
});
|
|
2199
|
+
return handled;
|
|
2200
|
+
};
|
|
2201
|
+
var FS_createPreloadedFile = (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => {
|
|
2202
|
+
// TODO we should allow people to just pass in a complete filename instead
|
|
2203
|
+
// of parent and name being that we just join them anyways
|
|
2204
|
+
var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
|
|
2205
|
+
var dep = getUniqueRunDependency(`cp ${fullname}`); // might have several active requests for the same fullname
|
|
2206
|
+
function processData(byteArray) {
|
|
2207
|
+
function finish(byteArray) {
|
|
2208
|
+
preFinish?.();
|
|
2209
|
+
if (!dontCreateFile) {
|
|
2210
|
+
FS_createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
|
|
2211
|
+
}
|
|
2212
|
+
onload?.();
|
|
2213
|
+
removeRunDependency(dep);
|
|
2214
|
+
}
|
|
2215
|
+
if (FS_handledByPreloadPlugin(byteArray, fullname, finish, () => {
|
|
2216
|
+
onerror?.();
|
|
2217
|
+
removeRunDependency(dep);
|
|
2218
|
+
})) {
|
|
2219
|
+
return;
|
|
2220
|
+
}
|
|
2221
|
+
finish(byteArray);
|
|
2222
|
+
}
|
|
2223
|
+
addRunDependency(dep);
|
|
2224
|
+
if (typeof url == 'string') {
|
|
2225
|
+
asyncLoad(url).then(processData, onerror);
|
|
2226
|
+
} else {
|
|
2227
|
+
processData(url);
|
|
2228
|
+
}
|
|
2229
|
+
};
|
|
2230
|
+
|
|
2231
|
+
var FS_modeStringToFlags = (str) => {
|
|
2232
|
+
var flagModes = {
|
|
2233
|
+
'r': 0,
|
|
2234
|
+
'r+': 2,
|
|
2235
|
+
'w': 512 | 64 | 1,
|
|
2236
|
+
'w+': 512 | 64 | 2,
|
|
2237
|
+
'a': 1024 | 64 | 1,
|
|
2238
|
+
'a+': 1024 | 64 | 2,
|
|
2239
|
+
};
|
|
2240
|
+
var flags = flagModes[str];
|
|
2241
|
+
if (typeof flags == 'undefined') {
|
|
2242
|
+
throw new Error(`Unknown file open mode: ${str}`);
|
|
2243
|
+
}
|
|
2244
|
+
return flags;
|
|
2245
|
+
};
|
|
2246
|
+
|
|
2247
|
+
var FS_getMode = (canRead, canWrite) => {
|
|
2248
|
+
var mode = 0;
|
|
2249
|
+
if (canRead) mode |= 292 | 73;
|
|
2250
|
+
if (canWrite) mode |= 146;
|
|
2251
|
+
return mode;
|
|
2252
|
+
};
|
|
2253
|
+
|
|
2254
|
+
|
|
2255
|
+
|
|
2256
|
+
var FS = {
|
|
2257
|
+
root:null,
|
|
2258
|
+
mounts:[],
|
|
2259
|
+
devices:{
|
|
2260
|
+
},
|
|
2261
|
+
streams:[],
|
|
2262
|
+
nextInode:1,
|
|
2263
|
+
nameTable:null,
|
|
2264
|
+
currentPath:"/",
|
|
2265
|
+
initialized:false,
|
|
2266
|
+
ignorePermissions:true,
|
|
2267
|
+
filesystems:null,
|
|
2268
|
+
syncFSRequests:0,
|
|
2269
|
+
readFiles:{
|
|
2270
|
+
},
|
|
2271
|
+
ErrnoError:class {
|
|
2272
|
+
name = 'ErrnoError';
|
|
2273
|
+
// We set the `name` property to be able to identify `FS.ErrnoError`
|
|
2274
|
+
// - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
|
|
2275
|
+
// - when using PROXYFS, an error can come from an underlying FS
|
|
2276
|
+
// as different FS objects have their own FS.ErrnoError each,
|
|
2277
|
+
// the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
|
|
2278
|
+
// we'll use the reliable test `err.name == "ErrnoError"` instead
|
|
2279
|
+
constructor(errno) {
|
|
2280
|
+
this.errno = errno;
|
|
2281
|
+
}
|
|
2282
|
+
},
|
|
2283
|
+
FSStream:class {
|
|
2284
|
+
shared = {};
|
|
2285
|
+
get object() {
|
|
2286
|
+
return this.node;
|
|
2287
|
+
}
|
|
2288
|
+
set object(val) {
|
|
2289
|
+
this.node = val;
|
|
2290
|
+
}
|
|
2291
|
+
get isRead() {
|
|
2292
|
+
return (this.flags & 2097155) !== 1;
|
|
2293
|
+
}
|
|
2294
|
+
get isWrite() {
|
|
2295
|
+
return (this.flags & 2097155) !== 0;
|
|
2296
|
+
}
|
|
2297
|
+
get isAppend() {
|
|
2298
|
+
return (this.flags & 1024);
|
|
2299
|
+
}
|
|
2300
|
+
get flags() {
|
|
2301
|
+
return this.shared.flags;
|
|
2302
|
+
}
|
|
2303
|
+
set flags(val) {
|
|
2304
|
+
this.shared.flags = val;
|
|
2305
|
+
}
|
|
2306
|
+
get position() {
|
|
2307
|
+
return this.shared.position;
|
|
2308
|
+
}
|
|
2309
|
+
set position(val) {
|
|
2310
|
+
this.shared.position = val;
|
|
2311
|
+
}
|
|
2312
|
+
},
|
|
2313
|
+
FSNode:class {
|
|
2314
|
+
node_ops = {};
|
|
2315
|
+
stream_ops = {};
|
|
2316
|
+
readMode = 292 | 73;
|
|
2317
|
+
writeMode = 146;
|
|
2318
|
+
mounted = null;
|
|
2319
|
+
constructor(parent, name, mode, rdev) {
|
|
2320
|
+
if (!parent) {
|
|
2321
|
+
parent = this; // root node sets parent to itself
|
|
2322
|
+
}
|
|
2323
|
+
this.parent = parent;
|
|
2324
|
+
this.mount = parent.mount;
|
|
2325
|
+
this.id = FS.nextInode++;
|
|
2326
|
+
this.name = name;
|
|
2327
|
+
this.mode = mode;
|
|
2328
|
+
this.rdev = rdev;
|
|
2329
|
+
this.atime = this.mtime = this.ctime = Date.now();
|
|
2330
|
+
}
|
|
2331
|
+
get read() {
|
|
2332
|
+
return (this.mode & this.readMode) === this.readMode;
|
|
2333
|
+
}
|
|
2334
|
+
set read(val) {
|
|
2335
|
+
val ? this.mode |= this.readMode : this.mode &= ~this.readMode;
|
|
2336
|
+
}
|
|
2337
|
+
get write() {
|
|
2338
|
+
return (this.mode & this.writeMode) === this.writeMode;
|
|
2339
|
+
}
|
|
2340
|
+
set write(val) {
|
|
2341
|
+
val ? this.mode |= this.writeMode : this.mode &= ~this.writeMode;
|
|
2342
|
+
}
|
|
2343
|
+
get isFolder() {
|
|
2344
|
+
return FS.isDir(this.mode);
|
|
2345
|
+
}
|
|
2346
|
+
get isDevice() {
|
|
2347
|
+
return FS.isChrdev(this.mode);
|
|
2348
|
+
}
|
|
2349
|
+
},
|
|
2350
|
+
lookupPath(path, opts = {}) {
|
|
2351
|
+
if (!path) {
|
|
2352
|
+
throw new FS.ErrnoError(44);
|
|
2353
|
+
}
|
|
2354
|
+
opts.follow_mount ??= true
|
|
2355
|
+
|
|
2356
|
+
if (!PATH.isAbs(path)) {
|
|
2357
|
+
path = FS.cwd() + '/' + path;
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
// limit max consecutive symlinks to 40 (SYMLOOP_MAX).
|
|
2361
|
+
linkloop: for (var nlinks = 0; nlinks < 40; nlinks++) {
|
|
2362
|
+
// split the absolute path
|
|
2363
|
+
var parts = path.split('/').filter((p) => !!p);
|
|
2364
|
+
|
|
2365
|
+
// start at the root
|
|
2366
|
+
var current = FS.root;
|
|
2367
|
+
var current_path = '/';
|
|
2368
|
+
|
|
2369
|
+
for (var i = 0; i < parts.length; i++) {
|
|
2370
|
+
var islast = (i === parts.length-1);
|
|
2371
|
+
if (islast && opts.parent) {
|
|
2372
|
+
// stop resolving
|
|
2373
|
+
break;
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
if (parts[i] === '.') {
|
|
2377
|
+
continue;
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
if (parts[i] === '..') {
|
|
2381
|
+
current_path = PATH.dirname(current_path);
|
|
2382
|
+
if (FS.isRoot(current)) {
|
|
2383
|
+
path = current_path + '/' + parts.slice(i + 1).join('/');
|
|
2384
|
+
continue linkloop;
|
|
2385
|
+
} else {
|
|
2386
|
+
current = current.parent;
|
|
2387
|
+
}
|
|
2388
|
+
continue;
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
current_path = PATH.join2(current_path, parts[i]);
|
|
2392
|
+
try {
|
|
2393
|
+
current = FS.lookupNode(current, parts[i]);
|
|
2394
|
+
} catch (e) {
|
|
2395
|
+
// if noent_okay is true, suppress a ENOENT in the last component
|
|
2396
|
+
// and return an object with an undefined node. This is needed for
|
|
2397
|
+
// resolving symlinks in the path when creating a file.
|
|
2398
|
+
if ((e?.errno === 44) && islast && opts.noent_okay) {
|
|
2399
|
+
return { path: current_path };
|
|
2400
|
+
}
|
|
2401
|
+
throw e;
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
// jump to the mount's root node if this is a mountpoint
|
|
2405
|
+
if (FS.isMountpoint(current) && (!islast || opts.follow_mount)) {
|
|
2406
|
+
current = current.mounted.root;
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
// by default, lookupPath will not follow a symlink if it is the final path component.
|
|
2410
|
+
// setting opts.follow = true will override this behavior.
|
|
2411
|
+
if (FS.isLink(current.mode) && (!islast || opts.follow)) {
|
|
2412
|
+
if (!current.node_ops.readlink) {
|
|
2413
|
+
throw new FS.ErrnoError(52);
|
|
2414
|
+
}
|
|
2415
|
+
var link = current.node_ops.readlink(current);
|
|
2416
|
+
if (!PATH.isAbs(link)) {
|
|
2417
|
+
link = PATH.dirname(current_path) + '/' + link;
|
|
2418
|
+
}
|
|
2419
|
+
path = link + '/' + parts.slice(i + 1).join('/');
|
|
2420
|
+
continue linkloop;
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
return { path: current_path, node: current };
|
|
2424
|
+
}
|
|
2425
|
+
throw new FS.ErrnoError(32);
|
|
2426
|
+
},
|
|
2427
|
+
getPath(node) {
|
|
2428
|
+
var path;
|
|
2429
|
+
while (true) {
|
|
2430
|
+
if (FS.isRoot(node)) {
|
|
2431
|
+
var mount = node.mount.mountpoint;
|
|
2432
|
+
if (!path) return mount;
|
|
2433
|
+
return mount[mount.length-1] !== '/' ? `${mount}/${path}` : mount + path;
|
|
2434
|
+
}
|
|
2435
|
+
path = path ? `${node.name}/${path}` : node.name;
|
|
2436
|
+
node = node.parent;
|
|
2437
|
+
}
|
|
2438
|
+
},
|
|
2439
|
+
hashName(parentid, name) {
|
|
2440
|
+
var hash = 0;
|
|
2441
|
+
|
|
2442
|
+
for (var i = 0; i < name.length; i++) {
|
|
2443
|
+
hash = ((hash << 5) - hash + name.charCodeAt(i)) | 0;
|
|
2444
|
+
}
|
|
2445
|
+
return ((parentid + hash) >>> 0) % FS.nameTable.length;
|
|
2446
|
+
},
|
|
2447
|
+
hashAddNode(node) {
|
|
2448
|
+
var hash = FS.hashName(node.parent.id, node.name);
|
|
2449
|
+
node.name_next = FS.nameTable[hash];
|
|
2450
|
+
FS.nameTable[hash] = node;
|
|
2451
|
+
},
|
|
2452
|
+
hashRemoveNode(node) {
|
|
2453
|
+
var hash = FS.hashName(node.parent.id, node.name);
|
|
2454
|
+
if (FS.nameTable[hash] === node) {
|
|
2455
|
+
FS.nameTable[hash] = node.name_next;
|
|
2456
|
+
} else {
|
|
2457
|
+
var current = FS.nameTable[hash];
|
|
2458
|
+
while (current) {
|
|
2459
|
+
if (current.name_next === node) {
|
|
2460
|
+
current.name_next = node.name_next;
|
|
2461
|
+
break;
|
|
2462
|
+
}
|
|
2463
|
+
current = current.name_next;
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
},
|
|
2467
|
+
lookupNode(parent, name) {
|
|
2468
|
+
var errCode = FS.mayLookup(parent);
|
|
2469
|
+
if (errCode) {
|
|
2470
|
+
throw new FS.ErrnoError(errCode);
|
|
2471
|
+
}
|
|
2472
|
+
var hash = FS.hashName(parent.id, name);
|
|
2473
|
+
for (var node = FS.nameTable[hash]; node; node = node.name_next) {
|
|
2474
|
+
var nodeName = node.name;
|
|
2475
|
+
if (node.parent.id === parent.id && nodeName === name) {
|
|
2476
|
+
return node;
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
// if we failed to find it in the cache, call into the VFS
|
|
2480
|
+
return FS.lookup(parent, name);
|
|
2481
|
+
},
|
|
2482
|
+
createNode(parent, name, mode, rdev) {
|
|
2483
|
+
var node = new FS.FSNode(parent, name, mode, rdev);
|
|
2484
|
+
|
|
2485
|
+
FS.hashAddNode(node);
|
|
2486
|
+
|
|
2487
|
+
return node;
|
|
2488
|
+
},
|
|
2489
|
+
destroyNode(node) {
|
|
2490
|
+
FS.hashRemoveNode(node);
|
|
2491
|
+
},
|
|
2492
|
+
isRoot(node) {
|
|
2493
|
+
return node === node.parent;
|
|
2494
|
+
},
|
|
2495
|
+
isMountpoint(node) {
|
|
2496
|
+
return !!node.mounted;
|
|
2497
|
+
},
|
|
2498
|
+
isFile(mode) {
|
|
2499
|
+
return (mode & 61440) === 32768;
|
|
2500
|
+
},
|
|
2501
|
+
isDir(mode) {
|
|
2502
|
+
return (mode & 61440) === 16384;
|
|
2503
|
+
},
|
|
2504
|
+
isLink(mode) {
|
|
2505
|
+
return (mode & 61440) === 40960;
|
|
2506
|
+
},
|
|
2507
|
+
isChrdev(mode) {
|
|
2508
|
+
return (mode & 61440) === 8192;
|
|
2509
|
+
},
|
|
2510
|
+
isBlkdev(mode) {
|
|
2511
|
+
return (mode & 61440) === 24576;
|
|
2512
|
+
},
|
|
2513
|
+
isFIFO(mode) {
|
|
2514
|
+
return (mode & 61440) === 4096;
|
|
2515
|
+
},
|
|
2516
|
+
isSocket(mode) {
|
|
2517
|
+
return (mode & 49152) === 49152;
|
|
2518
|
+
},
|
|
2519
|
+
flagsToPermissionString(flag) {
|
|
2520
|
+
var perms = ['r', 'w', 'rw'][flag & 3];
|
|
2521
|
+
if ((flag & 512)) {
|
|
2522
|
+
perms += 'w';
|
|
2523
|
+
}
|
|
2524
|
+
return perms;
|
|
2525
|
+
},
|
|
2526
|
+
nodePermissions(node, perms) {
|
|
2527
|
+
if (FS.ignorePermissions) {
|
|
2528
|
+
return 0;
|
|
2529
|
+
}
|
|
2530
|
+
// return 0 if any user, group or owner bits are set.
|
|
2531
|
+
if (perms.includes('r') && !(node.mode & 292)) {
|
|
2532
|
+
return 2;
|
|
2533
|
+
} else if (perms.includes('w') && !(node.mode & 146)) {
|
|
2534
|
+
return 2;
|
|
2535
|
+
} else if (perms.includes('x') && !(node.mode & 73)) {
|
|
2536
|
+
return 2;
|
|
2537
|
+
}
|
|
2538
|
+
return 0;
|
|
2539
|
+
},
|
|
2540
|
+
mayLookup(dir) {
|
|
2541
|
+
if (!FS.isDir(dir.mode)) return 54;
|
|
2542
|
+
var errCode = FS.nodePermissions(dir, 'x');
|
|
2543
|
+
if (errCode) return errCode;
|
|
2544
|
+
if (!dir.node_ops.lookup) return 2;
|
|
2545
|
+
return 0;
|
|
2546
|
+
},
|
|
2547
|
+
mayCreate(dir, name) {
|
|
2548
|
+
if (!FS.isDir(dir.mode)) {
|
|
2549
|
+
return 54;
|
|
2550
|
+
}
|
|
2551
|
+
try {
|
|
2552
|
+
var node = FS.lookupNode(dir, name);
|
|
2553
|
+
return 20;
|
|
2554
|
+
} catch (e) {
|
|
2555
|
+
}
|
|
2556
|
+
return FS.nodePermissions(dir, 'wx');
|
|
2557
|
+
},
|
|
2558
|
+
mayDelete(dir, name, isdir) {
|
|
2559
|
+
var node;
|
|
2560
|
+
try {
|
|
2561
|
+
node = FS.lookupNode(dir, name);
|
|
2562
|
+
} catch (e) {
|
|
2563
|
+
return e.errno;
|
|
2564
|
+
}
|
|
2565
|
+
var errCode = FS.nodePermissions(dir, 'wx');
|
|
2566
|
+
if (errCode) {
|
|
2567
|
+
return errCode;
|
|
2568
|
+
}
|
|
2569
|
+
if (isdir) {
|
|
2570
|
+
if (!FS.isDir(node.mode)) {
|
|
2571
|
+
return 54;
|
|
2572
|
+
}
|
|
2573
|
+
if (FS.isRoot(node) || FS.getPath(node) === FS.cwd()) {
|
|
2574
|
+
return 10;
|
|
2575
|
+
}
|
|
2576
|
+
} else {
|
|
2577
|
+
if (FS.isDir(node.mode)) {
|
|
2578
|
+
return 31;
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
return 0;
|
|
2582
|
+
},
|
|
2583
|
+
mayOpen(node, flags) {
|
|
2584
|
+
if (!node) {
|
|
2585
|
+
return 44;
|
|
2586
|
+
}
|
|
2587
|
+
if (FS.isLink(node.mode)) {
|
|
2588
|
+
return 32;
|
|
2589
|
+
} else if (FS.isDir(node.mode)) {
|
|
2590
|
+
if (FS.flagsToPermissionString(flags) !== 'r' // opening for write
|
|
2591
|
+
|| (flags & (512 | 64))) { // TODO: check for O_SEARCH? (== search for dir only)
|
|
2592
|
+
return 31;
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
return FS.nodePermissions(node, FS.flagsToPermissionString(flags));
|
|
2596
|
+
},
|
|
2597
|
+
checkOpExists(op, err) {
|
|
2598
|
+
if (!op) {
|
|
2599
|
+
throw new FS.ErrnoError(err);
|
|
2600
|
+
}
|
|
2601
|
+
return op;
|
|
2602
|
+
},
|
|
2603
|
+
MAX_OPEN_FDS:4096,
|
|
2604
|
+
nextfd() {
|
|
2605
|
+
for (var fd = 0; fd <= FS.MAX_OPEN_FDS; fd++) {
|
|
2606
|
+
if (!FS.streams[fd]) {
|
|
2607
|
+
return fd;
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
throw new FS.ErrnoError(33);
|
|
2611
|
+
},
|
|
2612
|
+
getStreamChecked(fd) {
|
|
2613
|
+
var stream = FS.getStream(fd);
|
|
2614
|
+
if (!stream) {
|
|
2615
|
+
throw new FS.ErrnoError(8);
|
|
2616
|
+
}
|
|
2617
|
+
return stream;
|
|
2618
|
+
},
|
|
2619
|
+
getStream:(fd) => FS.streams[fd],
|
|
2620
|
+
createStream(stream, fd = -1) {
|
|
2621
|
+
|
|
2622
|
+
// clone it, so we can return an instance of FSStream
|
|
2623
|
+
stream = Object.assign(new FS.FSStream(), stream);
|
|
2624
|
+
if (fd == -1) {
|
|
2625
|
+
fd = FS.nextfd();
|
|
2626
|
+
}
|
|
2627
|
+
stream.fd = fd;
|
|
2628
|
+
FS.streams[fd] = stream;
|
|
2629
|
+
return stream;
|
|
2630
|
+
},
|
|
2631
|
+
closeStream(fd) {
|
|
2632
|
+
FS.streams[fd] = null;
|
|
2633
|
+
},
|
|
2634
|
+
dupStream(origStream, fd = -1) {
|
|
2635
|
+
var stream = FS.createStream(origStream, fd);
|
|
2636
|
+
stream.stream_ops?.dup?.(stream);
|
|
2637
|
+
return stream;
|
|
2638
|
+
},
|
|
2639
|
+
doSetAttr(stream, node, attr) {
|
|
2640
|
+
var setattr = stream?.stream_ops.setattr;
|
|
2641
|
+
var arg = setattr ? stream : node;
|
|
2642
|
+
setattr ??= node.node_ops.setattr;
|
|
2643
|
+
FS.checkOpExists(setattr, 63)
|
|
2644
|
+
setattr(arg, attr);
|
|
2645
|
+
},
|
|
2646
|
+
chrdev_stream_ops:{
|
|
2647
|
+
open(stream) {
|
|
2648
|
+
var device = FS.getDevice(stream.node.rdev);
|
|
2649
|
+
// override node's stream ops with the device's
|
|
2650
|
+
stream.stream_ops = device.stream_ops;
|
|
2651
|
+
// forward the open call
|
|
2652
|
+
stream.stream_ops.open?.(stream);
|
|
2653
|
+
},
|
|
2654
|
+
llseek() {
|
|
2655
|
+
throw new FS.ErrnoError(70);
|
|
2656
|
+
},
|
|
2657
|
+
},
|
|
2658
|
+
major:(dev) => ((dev) >> 8),
|
|
2659
|
+
minor:(dev) => ((dev) & 0xff),
|
|
2660
|
+
makedev:(ma, mi) => ((ma) << 8 | (mi)),
|
|
2661
|
+
registerDevice(dev, ops) {
|
|
2662
|
+
FS.devices[dev] = { stream_ops: ops };
|
|
2663
|
+
},
|
|
2664
|
+
getDevice:(dev) => FS.devices[dev],
|
|
2665
|
+
getMounts(mount) {
|
|
2666
|
+
var mounts = [];
|
|
2667
|
+
var check = [mount];
|
|
2668
|
+
|
|
2669
|
+
while (check.length) {
|
|
2670
|
+
var m = check.pop();
|
|
2671
|
+
|
|
2672
|
+
mounts.push(m);
|
|
2673
|
+
|
|
2674
|
+
check.push(...m.mounts);
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
return mounts;
|
|
2678
|
+
},
|
|
2679
|
+
syncfs(populate, callback) {
|
|
2680
|
+
if (typeof populate == 'function') {
|
|
2681
|
+
callback = populate;
|
|
2682
|
+
populate = false;
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2685
|
+
FS.syncFSRequests++;
|
|
2686
|
+
|
|
2687
|
+
if (FS.syncFSRequests > 1) {
|
|
2688
|
+
err(`warning: ${FS.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
var mounts = FS.getMounts(FS.root.mount);
|
|
2692
|
+
var completed = 0;
|
|
2693
|
+
|
|
2694
|
+
function doCallback(errCode) {
|
|
2695
|
+
FS.syncFSRequests--;
|
|
2696
|
+
return callback(errCode);
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
function done(errCode) {
|
|
2700
|
+
if (errCode) {
|
|
2701
|
+
if (!done.errored) {
|
|
2702
|
+
done.errored = true;
|
|
2703
|
+
return doCallback(errCode);
|
|
2704
|
+
}
|
|
2705
|
+
return;
|
|
2706
|
+
}
|
|
2707
|
+
if (++completed >= mounts.length) {
|
|
2708
|
+
doCallback(null);
|
|
2709
|
+
}
|
|
2710
|
+
};
|
|
2711
|
+
|
|
2712
|
+
// sync all mounts
|
|
2713
|
+
mounts.forEach((mount) => {
|
|
2714
|
+
if (!mount.type.syncfs) {
|
|
2715
|
+
return done(null);
|
|
2716
|
+
}
|
|
2717
|
+
mount.type.syncfs(mount, populate, done);
|
|
2718
|
+
});
|
|
2719
|
+
},
|
|
2720
|
+
mount(type, opts, mountpoint) {
|
|
2721
|
+
var root = mountpoint === '/';
|
|
2722
|
+
var pseudo = !mountpoint;
|
|
2723
|
+
var node;
|
|
2724
|
+
|
|
2725
|
+
if (root && FS.root) {
|
|
2726
|
+
throw new FS.ErrnoError(10);
|
|
2727
|
+
} else if (!root && !pseudo) {
|
|
2728
|
+
var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
|
|
2729
|
+
|
|
2730
|
+
mountpoint = lookup.path; // use the absolute path
|
|
2731
|
+
node = lookup.node;
|
|
2732
|
+
|
|
2733
|
+
if (FS.isMountpoint(node)) {
|
|
2734
|
+
throw new FS.ErrnoError(10);
|
|
2735
|
+
}
|
|
2736
|
+
|
|
2737
|
+
if (!FS.isDir(node.mode)) {
|
|
2738
|
+
throw new FS.ErrnoError(54);
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
var mount = {
|
|
2743
|
+
type,
|
|
2744
|
+
opts,
|
|
2745
|
+
mountpoint,
|
|
2746
|
+
mounts: []
|
|
2747
|
+
};
|
|
2748
|
+
|
|
2749
|
+
// create a root node for the fs
|
|
2750
|
+
var mountRoot = type.mount(mount);
|
|
2751
|
+
mountRoot.mount = mount;
|
|
2752
|
+
mount.root = mountRoot;
|
|
2753
|
+
|
|
2754
|
+
if (root) {
|
|
2755
|
+
FS.root = mountRoot;
|
|
2756
|
+
} else if (node) {
|
|
2757
|
+
// set as a mountpoint
|
|
2758
|
+
node.mounted = mount;
|
|
2759
|
+
|
|
2760
|
+
// add the new mount to the current mount's children
|
|
2761
|
+
if (node.mount) {
|
|
2762
|
+
node.mount.mounts.push(mount);
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
return mountRoot;
|
|
2767
|
+
},
|
|
2768
|
+
unmount(mountpoint) {
|
|
2769
|
+
var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
|
|
2770
|
+
|
|
2771
|
+
if (!FS.isMountpoint(lookup.node)) {
|
|
2772
|
+
throw new FS.ErrnoError(28);
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
// destroy the nodes for this mount, and all its child mounts
|
|
2776
|
+
var node = lookup.node;
|
|
2777
|
+
var mount = node.mounted;
|
|
2778
|
+
var mounts = FS.getMounts(mount);
|
|
2779
|
+
|
|
2780
|
+
Object.keys(FS.nameTable).forEach((hash) => {
|
|
2781
|
+
var current = FS.nameTable[hash];
|
|
2782
|
+
|
|
2783
|
+
while (current) {
|
|
2784
|
+
var next = current.name_next;
|
|
2785
|
+
|
|
2786
|
+
if (mounts.includes(current.mount)) {
|
|
2787
|
+
FS.destroyNode(current);
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2790
|
+
current = next;
|
|
2791
|
+
}
|
|
2792
|
+
});
|
|
2793
|
+
|
|
2794
|
+
// no longer a mountpoint
|
|
2795
|
+
node.mounted = null;
|
|
2796
|
+
|
|
2797
|
+
// remove this mount from the child mounts
|
|
2798
|
+
var idx = node.mount.mounts.indexOf(mount);
|
|
2799
|
+
node.mount.mounts.splice(idx, 1);
|
|
2800
|
+
},
|
|
2801
|
+
lookup(parent, name) {
|
|
2802
|
+
return parent.node_ops.lookup(parent, name);
|
|
2803
|
+
},
|
|
2804
|
+
mknod(path, mode, dev) {
|
|
2805
|
+
var lookup = FS.lookupPath(path, { parent: true });
|
|
2806
|
+
var parent = lookup.node;
|
|
2807
|
+
var name = PATH.basename(path);
|
|
2808
|
+
if (!name) {
|
|
2809
|
+
throw new FS.ErrnoError(28);
|
|
2810
|
+
}
|
|
2811
|
+
if (name === '.' || name === '..') {
|
|
2812
|
+
throw new FS.ErrnoError(20);
|
|
2813
|
+
}
|
|
2814
|
+
var errCode = FS.mayCreate(parent, name);
|
|
2815
|
+
if (errCode) {
|
|
2816
|
+
throw new FS.ErrnoError(errCode);
|
|
2817
|
+
}
|
|
2818
|
+
if (!parent.node_ops.mknod) {
|
|
2819
|
+
throw new FS.ErrnoError(63);
|
|
2820
|
+
}
|
|
2821
|
+
return parent.node_ops.mknod(parent, name, mode, dev);
|
|
2822
|
+
},
|
|
2823
|
+
statfs(path) {
|
|
2824
|
+
return FS.statfsNode(FS.lookupPath(path, {follow: true}).node);
|
|
2825
|
+
},
|
|
2826
|
+
statfsStream(stream) {
|
|
2827
|
+
// We keep a separate statfsStream function because noderawfs overrides
|
|
2828
|
+
// it. In noderawfs, stream.node is sometimes null. Instead, we need to
|
|
2829
|
+
// look at stream.path.
|
|
2830
|
+
return FS.statfsNode(stream.node);
|
|
2831
|
+
},
|
|
2832
|
+
statfsNode(node) {
|
|
2833
|
+
// NOTE: None of the defaults here are true. We're just returning safe and
|
|
2834
|
+
// sane values. Currently nodefs and rawfs replace these defaults,
|
|
2835
|
+
// other file systems leave them alone.
|
|
2836
|
+
var rtn = {
|
|
2837
|
+
bsize: 4096,
|
|
2838
|
+
frsize: 4096,
|
|
2839
|
+
blocks: 1e6,
|
|
2840
|
+
bfree: 5e5,
|
|
2841
|
+
bavail: 5e5,
|
|
2842
|
+
files: FS.nextInode,
|
|
2843
|
+
ffree: FS.nextInode - 1,
|
|
2844
|
+
fsid: 42,
|
|
2845
|
+
flags: 2,
|
|
2846
|
+
namelen: 255,
|
|
2847
|
+
};
|
|
2848
|
+
|
|
2849
|
+
if (node.node_ops.statfs) {
|
|
2850
|
+
Object.assign(rtn, node.node_ops.statfs(node.mount.opts.root));
|
|
2851
|
+
}
|
|
2852
|
+
return rtn;
|
|
2853
|
+
},
|
|
2854
|
+
create(path, mode = 0o666) {
|
|
2855
|
+
mode &= 4095;
|
|
2856
|
+
mode |= 32768;
|
|
2857
|
+
return FS.mknod(path, mode, 0);
|
|
2858
|
+
},
|
|
2859
|
+
mkdir(path, mode = 0o777) {
|
|
2860
|
+
mode &= 511 | 512;
|
|
2861
|
+
mode |= 16384;
|
|
2862
|
+
return FS.mknod(path, mode, 0);
|
|
2863
|
+
},
|
|
2864
|
+
mkdirTree(path, mode) {
|
|
2865
|
+
var dirs = path.split('/');
|
|
2866
|
+
var d = '';
|
|
2867
|
+
for (var dir of dirs) {
|
|
2868
|
+
if (!dir) continue;
|
|
2869
|
+
if (d || PATH.isAbs(path)) d += '/';
|
|
2870
|
+
d += dir;
|
|
2871
|
+
try {
|
|
2872
|
+
FS.mkdir(d, mode);
|
|
2873
|
+
} catch(e) {
|
|
2874
|
+
if (e.errno != 20) throw e;
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
},
|
|
2878
|
+
mkdev(path, mode, dev) {
|
|
2879
|
+
if (typeof dev == 'undefined') {
|
|
2880
|
+
dev = mode;
|
|
2881
|
+
mode = 0o666;
|
|
2882
|
+
}
|
|
2883
|
+
mode |= 8192;
|
|
2884
|
+
return FS.mknod(path, mode, dev);
|
|
2885
|
+
},
|
|
2886
|
+
symlink(oldpath, newpath) {
|
|
2887
|
+
if (!PATH_FS.resolve(oldpath)) {
|
|
2888
|
+
throw new FS.ErrnoError(44);
|
|
2889
|
+
}
|
|
2890
|
+
var lookup = FS.lookupPath(newpath, { parent: true });
|
|
2891
|
+
var parent = lookup.node;
|
|
2892
|
+
if (!parent) {
|
|
2893
|
+
throw new FS.ErrnoError(44);
|
|
2894
|
+
}
|
|
2895
|
+
var newname = PATH.basename(newpath);
|
|
2896
|
+
var errCode = FS.mayCreate(parent, newname);
|
|
2897
|
+
if (errCode) {
|
|
2898
|
+
throw new FS.ErrnoError(errCode);
|
|
2899
|
+
}
|
|
2900
|
+
if (!parent.node_ops.symlink) {
|
|
2901
|
+
throw new FS.ErrnoError(63);
|
|
2902
|
+
}
|
|
2903
|
+
return parent.node_ops.symlink(parent, newname, oldpath);
|
|
2904
|
+
},
|
|
2905
|
+
rename(old_path, new_path) {
|
|
2906
|
+
var old_dirname = PATH.dirname(old_path);
|
|
2907
|
+
var new_dirname = PATH.dirname(new_path);
|
|
2908
|
+
var old_name = PATH.basename(old_path);
|
|
2909
|
+
var new_name = PATH.basename(new_path);
|
|
2910
|
+
// parents must exist
|
|
2911
|
+
var lookup, old_dir, new_dir;
|
|
2912
|
+
|
|
2913
|
+
// let the errors from non existent directories percolate up
|
|
2914
|
+
lookup = FS.lookupPath(old_path, { parent: true });
|
|
2915
|
+
old_dir = lookup.node;
|
|
2916
|
+
lookup = FS.lookupPath(new_path, { parent: true });
|
|
2917
|
+
new_dir = lookup.node;
|
|
2918
|
+
|
|
2919
|
+
if (!old_dir || !new_dir) throw new FS.ErrnoError(44);
|
|
2920
|
+
// need to be part of the same mount
|
|
2921
|
+
if (old_dir.mount !== new_dir.mount) {
|
|
2922
|
+
throw new FS.ErrnoError(75);
|
|
2923
|
+
}
|
|
2924
|
+
// source must exist
|
|
2925
|
+
var old_node = FS.lookupNode(old_dir, old_name);
|
|
2926
|
+
// old path should not be an ancestor of the new path
|
|
2927
|
+
var relative = PATH_FS.relative(old_path, new_dirname);
|
|
2928
|
+
if (relative.charAt(0) !== '.') {
|
|
2929
|
+
throw new FS.ErrnoError(28);
|
|
2930
|
+
}
|
|
2931
|
+
// new path should not be an ancestor of the old path
|
|
2932
|
+
relative = PATH_FS.relative(new_path, old_dirname);
|
|
2933
|
+
if (relative.charAt(0) !== '.') {
|
|
2934
|
+
throw new FS.ErrnoError(55);
|
|
2935
|
+
}
|
|
2936
|
+
// see if the new path already exists
|
|
2937
|
+
var new_node;
|
|
2938
|
+
try {
|
|
2939
|
+
new_node = FS.lookupNode(new_dir, new_name);
|
|
2940
|
+
} catch (e) {
|
|
2941
|
+
// not fatal
|
|
2942
|
+
}
|
|
2943
|
+
// early out if nothing needs to change
|
|
2944
|
+
if (old_node === new_node) {
|
|
2945
|
+
return;
|
|
2946
|
+
}
|
|
2947
|
+
// we'll need to delete the old entry
|
|
2948
|
+
var isdir = FS.isDir(old_node.mode);
|
|
2949
|
+
var errCode = FS.mayDelete(old_dir, old_name, isdir);
|
|
2950
|
+
if (errCode) {
|
|
2951
|
+
throw new FS.ErrnoError(errCode);
|
|
2952
|
+
}
|
|
2953
|
+
// need delete permissions if we'll be overwriting.
|
|
2954
|
+
// need create permissions if new doesn't already exist.
|
|
2955
|
+
errCode = new_node ?
|
|
2956
|
+
FS.mayDelete(new_dir, new_name, isdir) :
|
|
2957
|
+
FS.mayCreate(new_dir, new_name);
|
|
2958
|
+
if (errCode) {
|
|
2959
|
+
throw new FS.ErrnoError(errCode);
|
|
2960
|
+
}
|
|
2961
|
+
if (!old_dir.node_ops.rename) {
|
|
2962
|
+
throw new FS.ErrnoError(63);
|
|
2963
|
+
}
|
|
2964
|
+
if (FS.isMountpoint(old_node) || (new_node && FS.isMountpoint(new_node))) {
|
|
2965
|
+
throw new FS.ErrnoError(10);
|
|
2966
|
+
}
|
|
2967
|
+
// if we are going to change the parent, check write permissions
|
|
2968
|
+
if (new_dir !== old_dir) {
|
|
2969
|
+
errCode = FS.nodePermissions(old_dir, 'w');
|
|
2970
|
+
if (errCode) {
|
|
2971
|
+
throw new FS.ErrnoError(errCode);
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
// remove the node from the lookup hash
|
|
2975
|
+
FS.hashRemoveNode(old_node);
|
|
2976
|
+
// do the underlying fs rename
|
|
2977
|
+
try {
|
|
2978
|
+
old_dir.node_ops.rename(old_node, new_dir, new_name);
|
|
2979
|
+
// update old node (we do this here to avoid each backend
|
|
2980
|
+
// needing to)
|
|
2981
|
+
old_node.parent = new_dir;
|
|
2982
|
+
} catch (e) {
|
|
2983
|
+
throw e;
|
|
2984
|
+
} finally {
|
|
2985
|
+
// add the node back to the hash (in case node_ops.rename
|
|
2986
|
+
// changed its name)
|
|
2987
|
+
FS.hashAddNode(old_node);
|
|
2988
|
+
}
|
|
2989
|
+
},
|
|
2990
|
+
rmdir(path) {
|
|
2991
|
+
var lookup = FS.lookupPath(path, { parent: true });
|
|
2992
|
+
var parent = lookup.node;
|
|
2993
|
+
var name = PATH.basename(path);
|
|
2994
|
+
var node = FS.lookupNode(parent, name);
|
|
2995
|
+
var errCode = FS.mayDelete(parent, name, true);
|
|
2996
|
+
if (errCode) {
|
|
2997
|
+
throw new FS.ErrnoError(errCode);
|
|
2998
|
+
}
|
|
2999
|
+
if (!parent.node_ops.rmdir) {
|
|
3000
|
+
throw new FS.ErrnoError(63);
|
|
3001
|
+
}
|
|
3002
|
+
if (FS.isMountpoint(node)) {
|
|
3003
|
+
throw new FS.ErrnoError(10);
|
|
3004
|
+
}
|
|
3005
|
+
parent.node_ops.rmdir(parent, name);
|
|
3006
|
+
FS.destroyNode(node);
|
|
3007
|
+
},
|
|
3008
|
+
readdir(path) {
|
|
3009
|
+
var lookup = FS.lookupPath(path, { follow: true });
|
|
3010
|
+
var node = lookup.node;
|
|
3011
|
+
var readdir = FS.checkOpExists(node.node_ops.readdir, 54);
|
|
3012
|
+
return readdir(node);
|
|
3013
|
+
},
|
|
3014
|
+
unlink(path) {
|
|
3015
|
+
var lookup = FS.lookupPath(path, { parent: true });
|
|
3016
|
+
var parent = lookup.node;
|
|
3017
|
+
if (!parent) {
|
|
3018
|
+
throw new FS.ErrnoError(44);
|
|
3019
|
+
}
|
|
3020
|
+
var name = PATH.basename(path);
|
|
3021
|
+
var node = FS.lookupNode(parent, name);
|
|
3022
|
+
var errCode = FS.mayDelete(parent, name, false);
|
|
3023
|
+
if (errCode) {
|
|
3024
|
+
// According to POSIX, we should map EISDIR to EPERM, but
|
|
3025
|
+
// we instead do what Linux does (and we must, as we use
|
|
3026
|
+
// the musl linux libc).
|
|
3027
|
+
throw new FS.ErrnoError(errCode);
|
|
3028
|
+
}
|
|
3029
|
+
if (!parent.node_ops.unlink) {
|
|
3030
|
+
throw new FS.ErrnoError(63);
|
|
3031
|
+
}
|
|
3032
|
+
if (FS.isMountpoint(node)) {
|
|
3033
|
+
throw new FS.ErrnoError(10);
|
|
3034
|
+
}
|
|
3035
|
+
parent.node_ops.unlink(parent, name);
|
|
3036
|
+
FS.destroyNode(node);
|
|
3037
|
+
},
|
|
3038
|
+
readlink(path) {
|
|
3039
|
+
var lookup = FS.lookupPath(path);
|
|
3040
|
+
var link = lookup.node;
|
|
3041
|
+
if (!link) {
|
|
3042
|
+
throw new FS.ErrnoError(44);
|
|
3043
|
+
}
|
|
3044
|
+
if (!link.node_ops.readlink) {
|
|
3045
|
+
throw new FS.ErrnoError(28);
|
|
3046
|
+
}
|
|
3047
|
+
return link.node_ops.readlink(link);
|
|
3048
|
+
},
|
|
3049
|
+
stat(path, dontFollow) {
|
|
3050
|
+
var lookup = FS.lookupPath(path, { follow: !dontFollow });
|
|
3051
|
+
var node = lookup.node;
|
|
3052
|
+
var getattr = FS.checkOpExists(node.node_ops.getattr, 63);
|
|
3053
|
+
return getattr(node);
|
|
3054
|
+
},
|
|
3055
|
+
fstat(fd) {
|
|
3056
|
+
var stream = FS.getStreamChecked(fd);
|
|
3057
|
+
var node = stream.node;
|
|
3058
|
+
var getattr = stream.stream_ops.getattr;
|
|
3059
|
+
var arg = getattr ? stream : node;
|
|
3060
|
+
getattr ??= node.node_ops.getattr;
|
|
3061
|
+
FS.checkOpExists(getattr, 63)
|
|
3062
|
+
return getattr(arg);
|
|
3063
|
+
},
|
|
3064
|
+
lstat(path) {
|
|
3065
|
+
return FS.stat(path, true);
|
|
3066
|
+
},
|
|
3067
|
+
doChmod(stream, node, mode, dontFollow) {
|
|
3068
|
+
FS.doSetAttr(stream, node, {
|
|
3069
|
+
mode: (mode & 4095) | (node.mode & ~4095),
|
|
3070
|
+
ctime: Date.now(),
|
|
3071
|
+
dontFollow
|
|
3072
|
+
});
|
|
3073
|
+
},
|
|
3074
|
+
chmod(path, mode, dontFollow) {
|
|
3075
|
+
var node;
|
|
3076
|
+
if (typeof path == 'string') {
|
|
3077
|
+
var lookup = FS.lookupPath(path, { follow: !dontFollow });
|
|
3078
|
+
node = lookup.node;
|
|
3079
|
+
} else {
|
|
3080
|
+
node = path;
|
|
3081
|
+
}
|
|
3082
|
+
FS.doChmod(null, node, mode, dontFollow);
|
|
3083
|
+
},
|
|
3084
|
+
lchmod(path, mode) {
|
|
3085
|
+
FS.chmod(path, mode, true);
|
|
3086
|
+
},
|
|
3087
|
+
fchmod(fd, mode) {
|
|
3088
|
+
var stream = FS.getStreamChecked(fd);
|
|
3089
|
+
FS.doChmod(stream, stream.node, mode, false);
|
|
3090
|
+
},
|
|
3091
|
+
doChown(stream, node, dontFollow) {
|
|
3092
|
+
FS.doSetAttr(stream, node, {
|
|
3093
|
+
timestamp: Date.now(),
|
|
3094
|
+
dontFollow
|
|
3095
|
+
// we ignore the uid / gid for now
|
|
3096
|
+
});
|
|
3097
|
+
},
|
|
3098
|
+
chown(path, uid, gid, dontFollow) {
|
|
3099
|
+
var node;
|
|
3100
|
+
if (typeof path == 'string') {
|
|
3101
|
+
var lookup = FS.lookupPath(path, { follow: !dontFollow });
|
|
3102
|
+
node = lookup.node;
|
|
3103
|
+
} else {
|
|
3104
|
+
node = path;
|
|
3105
|
+
}
|
|
3106
|
+
FS.doChown(null, node, dontFollow);
|
|
3107
|
+
},
|
|
3108
|
+
lchown(path, uid, gid) {
|
|
3109
|
+
FS.chown(path, uid, gid, true);
|
|
3110
|
+
},
|
|
3111
|
+
fchown(fd, uid, gid) {
|
|
3112
|
+
var stream = FS.getStreamChecked(fd);
|
|
3113
|
+
FS.doChown(stream, stream.node, false);
|
|
3114
|
+
},
|
|
3115
|
+
doTruncate(stream, node, len) {
|
|
3116
|
+
if (FS.isDir(node.mode)) {
|
|
3117
|
+
throw new FS.ErrnoError(31);
|
|
3118
|
+
}
|
|
3119
|
+
if (!FS.isFile(node.mode)) {
|
|
3120
|
+
throw new FS.ErrnoError(28);
|
|
3121
|
+
}
|
|
3122
|
+
var errCode = FS.nodePermissions(node, 'w');
|
|
3123
|
+
if (errCode) {
|
|
3124
|
+
throw new FS.ErrnoError(errCode);
|
|
3125
|
+
}
|
|
3126
|
+
FS.doSetAttr(stream, node, {
|
|
3127
|
+
size: len,
|
|
3128
|
+
timestamp: Date.now()
|
|
3129
|
+
});
|
|
3130
|
+
},
|
|
3131
|
+
truncate(path, len) {
|
|
3132
|
+
if (len < 0) {
|
|
3133
|
+
throw new FS.ErrnoError(28);
|
|
3134
|
+
}
|
|
3135
|
+
var node;
|
|
3136
|
+
if (typeof path == 'string') {
|
|
3137
|
+
var lookup = FS.lookupPath(path, { follow: true });
|
|
3138
|
+
node = lookup.node;
|
|
3139
|
+
} else {
|
|
3140
|
+
node = path;
|
|
3141
|
+
}
|
|
3142
|
+
FS.doTruncate(null, node, len);
|
|
3143
|
+
},
|
|
3144
|
+
ftruncate(fd, len) {
|
|
3145
|
+
var stream = FS.getStreamChecked(fd);
|
|
3146
|
+
if (len < 0 || (stream.flags & 2097155) === 0) {
|
|
3147
|
+
throw new FS.ErrnoError(28);
|
|
3148
|
+
}
|
|
3149
|
+
FS.doTruncate(stream, stream.node, len);
|
|
3150
|
+
},
|
|
3151
|
+
utime(path, atime, mtime) {
|
|
3152
|
+
var lookup = FS.lookupPath(path, { follow: true });
|
|
3153
|
+
var node = lookup.node;
|
|
3154
|
+
var setattr = FS.checkOpExists(node.node_ops.setattr, 63);
|
|
3155
|
+
setattr(node, {
|
|
3156
|
+
atime: atime,
|
|
3157
|
+
mtime: mtime
|
|
3158
|
+
});
|
|
3159
|
+
},
|
|
3160
|
+
open(path, flags, mode = 0o666) {
|
|
3161
|
+
if (path === "") {
|
|
3162
|
+
throw new FS.ErrnoError(44);
|
|
3163
|
+
}
|
|
3164
|
+
flags = typeof flags == 'string' ? FS_modeStringToFlags(flags) : flags;
|
|
3165
|
+
if ((flags & 64)) {
|
|
3166
|
+
mode = (mode & 4095) | 32768;
|
|
3167
|
+
} else {
|
|
3168
|
+
mode = 0;
|
|
3169
|
+
}
|
|
3170
|
+
var node;
|
|
3171
|
+
var isDirPath;
|
|
3172
|
+
if (typeof path == 'object') {
|
|
3173
|
+
node = path;
|
|
3174
|
+
} else {
|
|
3175
|
+
isDirPath = path.endsWith("/");
|
|
3176
|
+
// noent_okay makes it so that if the final component of the path
|
|
3177
|
+
// doesn't exist, lookupPath returns `node: undefined`. `path` will be
|
|
3178
|
+
// updated to point to the target of all symlinks.
|
|
3179
|
+
var lookup = FS.lookupPath(path, {
|
|
3180
|
+
follow: !(flags & 131072),
|
|
3181
|
+
noent_okay: true
|
|
3182
|
+
});
|
|
3183
|
+
node = lookup.node;
|
|
3184
|
+
path = lookup.path;
|
|
3185
|
+
}
|
|
3186
|
+
// perhaps we need to create the node
|
|
3187
|
+
var created = false;
|
|
3188
|
+
if ((flags & 64)) {
|
|
3189
|
+
if (node) {
|
|
3190
|
+
// if O_CREAT and O_EXCL are set, error out if the node already exists
|
|
3191
|
+
if ((flags & 128)) {
|
|
3192
|
+
throw new FS.ErrnoError(20);
|
|
3193
|
+
}
|
|
3194
|
+
} else if (isDirPath) {
|
|
3195
|
+
throw new FS.ErrnoError(31);
|
|
3196
|
+
} else {
|
|
3197
|
+
// node doesn't exist, try to create it
|
|
3198
|
+
// Ignore the permission bits here to ensure we can `open` this new
|
|
3199
|
+
// file below. We use chmod below the apply the permissions once the
|
|
3200
|
+
// file is open.
|
|
3201
|
+
node = FS.mknod(path, mode | 0o777, 0);
|
|
3202
|
+
created = true;
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
if (!node) {
|
|
3206
|
+
throw new FS.ErrnoError(44);
|
|
3207
|
+
}
|
|
3208
|
+
// can't truncate a device
|
|
3209
|
+
if (FS.isChrdev(node.mode)) {
|
|
3210
|
+
flags &= ~512;
|
|
3211
|
+
}
|
|
3212
|
+
// if asked only for a directory, then this must be one
|
|
3213
|
+
if ((flags & 65536) && !FS.isDir(node.mode)) {
|
|
3214
|
+
throw new FS.ErrnoError(54);
|
|
3215
|
+
}
|
|
3216
|
+
// check permissions, if this is not a file we just created now (it is ok to
|
|
3217
|
+
// create and write to a file with read-only permissions; it is read-only
|
|
3218
|
+
// for later use)
|
|
3219
|
+
if (!created) {
|
|
3220
|
+
var errCode = FS.mayOpen(node, flags);
|
|
3221
|
+
if (errCode) {
|
|
3222
|
+
throw new FS.ErrnoError(errCode);
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
// do truncation if necessary
|
|
3226
|
+
if ((flags & 512) && !created) {
|
|
3227
|
+
FS.truncate(node, 0);
|
|
3228
|
+
}
|
|
3229
|
+
// we've already handled these, don't pass down to the underlying vfs
|
|
3230
|
+
flags &= ~(128 | 512 | 131072);
|
|
3231
|
+
|
|
3232
|
+
// register the stream with the filesystem
|
|
3233
|
+
var stream = FS.createStream({
|
|
3234
|
+
node,
|
|
3235
|
+
path: FS.getPath(node), // we want the absolute path to the node
|
|
3236
|
+
flags,
|
|
3237
|
+
seekable: true,
|
|
3238
|
+
position: 0,
|
|
3239
|
+
stream_ops: node.stream_ops,
|
|
3240
|
+
// used by the file family libc calls (fopen, fwrite, ferror, etc.)
|
|
3241
|
+
ungotten: [],
|
|
3242
|
+
error: false
|
|
3243
|
+
});
|
|
3244
|
+
// call the new stream's open function
|
|
3245
|
+
if (stream.stream_ops.open) {
|
|
3246
|
+
stream.stream_ops.open(stream);
|
|
3247
|
+
}
|
|
3248
|
+
if (created) {
|
|
3249
|
+
FS.chmod(node, mode & 0o777);
|
|
3250
|
+
}
|
|
3251
|
+
if (Module['logReadFiles'] && !(flags & 1)) {
|
|
3252
|
+
if (!(path in FS.readFiles)) {
|
|
3253
|
+
FS.readFiles[path] = 1;
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
return stream;
|
|
3257
|
+
},
|
|
3258
|
+
close(stream) {
|
|
3259
|
+
if (FS.isClosed(stream)) {
|
|
3260
|
+
throw new FS.ErrnoError(8);
|
|
3261
|
+
}
|
|
3262
|
+
if (stream.getdents) stream.getdents = null; // free readdir state
|
|
3263
|
+
try {
|
|
3264
|
+
if (stream.stream_ops.close) {
|
|
3265
|
+
stream.stream_ops.close(stream);
|
|
3266
|
+
}
|
|
3267
|
+
} catch (e) {
|
|
3268
|
+
throw e;
|
|
3269
|
+
} finally {
|
|
3270
|
+
FS.closeStream(stream.fd);
|
|
3271
|
+
}
|
|
3272
|
+
stream.fd = null;
|
|
3273
|
+
},
|
|
3274
|
+
isClosed(stream) {
|
|
3275
|
+
return stream.fd === null;
|
|
3276
|
+
},
|
|
3277
|
+
llseek(stream, offset, whence) {
|
|
3278
|
+
if (FS.isClosed(stream)) {
|
|
3279
|
+
throw new FS.ErrnoError(8);
|
|
3280
|
+
}
|
|
3281
|
+
if (!stream.seekable || !stream.stream_ops.llseek) {
|
|
3282
|
+
throw new FS.ErrnoError(70);
|
|
3283
|
+
}
|
|
3284
|
+
if (whence != 0 && whence != 1 && whence != 2) {
|
|
3285
|
+
throw new FS.ErrnoError(28);
|
|
3286
|
+
}
|
|
3287
|
+
stream.position = stream.stream_ops.llseek(stream, offset, whence);
|
|
3288
|
+
stream.ungotten = [];
|
|
3289
|
+
return stream.position;
|
|
3290
|
+
},
|
|
3291
|
+
read(stream, buffer, offset, length, position) {
|
|
3292
|
+
if (length < 0 || position < 0) {
|
|
3293
|
+
throw new FS.ErrnoError(28);
|
|
3294
|
+
}
|
|
3295
|
+
if (FS.isClosed(stream)) {
|
|
3296
|
+
throw new FS.ErrnoError(8);
|
|
3297
|
+
}
|
|
3298
|
+
if ((stream.flags & 2097155) === 1) {
|
|
3299
|
+
throw new FS.ErrnoError(8);
|
|
3300
|
+
}
|
|
3301
|
+
if (FS.isDir(stream.node.mode)) {
|
|
3302
|
+
throw new FS.ErrnoError(31);
|
|
3303
|
+
}
|
|
3304
|
+
if (!stream.stream_ops.read) {
|
|
3305
|
+
throw new FS.ErrnoError(28);
|
|
3306
|
+
}
|
|
3307
|
+
var seeking = typeof position != 'undefined';
|
|
3308
|
+
if (!seeking) {
|
|
3309
|
+
position = stream.position;
|
|
3310
|
+
} else if (!stream.seekable) {
|
|
3311
|
+
throw new FS.ErrnoError(70);
|
|
3312
|
+
}
|
|
3313
|
+
var bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position);
|
|
3314
|
+
if (!seeking) stream.position += bytesRead;
|
|
3315
|
+
return bytesRead;
|
|
3316
|
+
},
|
|
3317
|
+
write(stream, buffer, offset, length, position, canOwn) {
|
|
3318
|
+
if (length < 0 || position < 0) {
|
|
3319
|
+
throw new FS.ErrnoError(28);
|
|
3320
|
+
}
|
|
3321
|
+
if (FS.isClosed(stream)) {
|
|
3322
|
+
throw new FS.ErrnoError(8);
|
|
3323
|
+
}
|
|
3324
|
+
if ((stream.flags & 2097155) === 0) {
|
|
3325
|
+
throw new FS.ErrnoError(8);
|
|
3326
|
+
}
|
|
3327
|
+
if (FS.isDir(stream.node.mode)) {
|
|
3328
|
+
throw new FS.ErrnoError(31);
|
|
3329
|
+
}
|
|
3330
|
+
if (!stream.stream_ops.write) {
|
|
3331
|
+
throw new FS.ErrnoError(28);
|
|
3332
|
+
}
|
|
3333
|
+
if (stream.seekable && stream.flags & 1024) {
|
|
3334
|
+
// seek to the end before writing in append mode
|
|
3335
|
+
FS.llseek(stream, 0, 2);
|
|
3336
|
+
}
|
|
3337
|
+
var seeking = typeof position != 'undefined';
|
|
3338
|
+
if (!seeking) {
|
|
3339
|
+
position = stream.position;
|
|
3340
|
+
} else if (!stream.seekable) {
|
|
3341
|
+
throw new FS.ErrnoError(70);
|
|
3342
|
+
}
|
|
3343
|
+
var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
|
|
3344
|
+
if (!seeking) stream.position += bytesWritten;
|
|
3345
|
+
return bytesWritten;
|
|
3346
|
+
},
|
|
3347
|
+
mmap(stream, length, position, prot, flags) {
|
|
3348
|
+
// User requests writing to file (prot & PROT_WRITE != 0).
|
|
3349
|
+
// Checking if we have permissions to write to the file unless
|
|
3350
|
+
// MAP_PRIVATE flag is set. According to POSIX spec it is possible
|
|
3351
|
+
// to write to file opened in read-only mode with MAP_PRIVATE flag,
|
|
3352
|
+
// as all modifications will be visible only in the memory of
|
|
3353
|
+
// the current process.
|
|
3354
|
+
if ((prot & 2) !== 0
|
|
3355
|
+
&& (flags & 2) === 0
|
|
3356
|
+
&& (stream.flags & 2097155) !== 2) {
|
|
3357
|
+
throw new FS.ErrnoError(2);
|
|
3358
|
+
}
|
|
3359
|
+
if ((stream.flags & 2097155) === 1) {
|
|
3360
|
+
throw new FS.ErrnoError(2);
|
|
3361
|
+
}
|
|
3362
|
+
if (!stream.stream_ops.mmap) {
|
|
3363
|
+
throw new FS.ErrnoError(43);
|
|
3364
|
+
}
|
|
3365
|
+
if (!length) {
|
|
3366
|
+
throw new FS.ErrnoError(28);
|
|
3367
|
+
}
|
|
3368
|
+
return stream.stream_ops.mmap(stream, length, position, prot, flags);
|
|
3369
|
+
},
|
|
3370
|
+
msync(stream, buffer, offset, length, mmapFlags) {
|
|
3371
|
+
if (!stream.stream_ops.msync) {
|
|
3372
|
+
return 0;
|
|
3373
|
+
}
|
|
3374
|
+
return stream.stream_ops.msync(stream, buffer, offset, length, mmapFlags);
|
|
3375
|
+
},
|
|
3376
|
+
ioctl(stream, cmd, arg) {
|
|
3377
|
+
if (!stream.stream_ops.ioctl) {
|
|
3378
|
+
throw new FS.ErrnoError(59);
|
|
3379
|
+
}
|
|
3380
|
+
return stream.stream_ops.ioctl(stream, cmd, arg);
|
|
3381
|
+
},
|
|
3382
|
+
readFile(path, opts = {}) {
|
|
3383
|
+
opts.flags = opts.flags || 0;
|
|
3384
|
+
opts.encoding = opts.encoding || 'binary';
|
|
3385
|
+
if (opts.encoding !== 'utf8' && opts.encoding !== 'binary') {
|
|
3386
|
+
throw new Error(`Invalid encoding type "${opts.encoding}"`);
|
|
3387
|
+
}
|
|
3388
|
+
var ret;
|
|
3389
|
+
var stream = FS.open(path, opts.flags);
|
|
3390
|
+
var stat = FS.stat(path);
|
|
3391
|
+
var length = stat.size;
|
|
3392
|
+
var buf = new Uint8Array(length);
|
|
3393
|
+
FS.read(stream, buf, 0, length, 0);
|
|
3394
|
+
if (opts.encoding === 'utf8') {
|
|
3395
|
+
ret = UTF8ArrayToString(buf);
|
|
3396
|
+
} else if (opts.encoding === 'binary') {
|
|
3397
|
+
ret = buf;
|
|
3398
|
+
}
|
|
3399
|
+
FS.close(stream);
|
|
3400
|
+
return ret;
|
|
3401
|
+
},
|
|
3402
|
+
writeFile(path, data, opts = {}) {
|
|
3403
|
+
opts.flags = opts.flags || 577;
|
|
3404
|
+
var stream = FS.open(path, opts.flags, opts.mode);
|
|
3405
|
+
if (typeof data == 'string') {
|
|
3406
|
+
var buf = new Uint8Array(lengthBytesUTF8(data)+1);
|
|
3407
|
+
var actualNumBytes = stringToUTF8Array(data, buf, 0, buf.length);
|
|
3408
|
+
FS.write(stream, buf, 0, actualNumBytes, undefined, opts.canOwn);
|
|
3409
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
3410
|
+
FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn);
|
|
3411
|
+
} else {
|
|
3412
|
+
throw new Error('Unsupported data type');
|
|
3413
|
+
}
|
|
3414
|
+
FS.close(stream);
|
|
3415
|
+
},
|
|
3416
|
+
cwd:() => FS.currentPath,
|
|
3417
|
+
chdir(path) {
|
|
3418
|
+
var lookup = FS.lookupPath(path, { follow: true });
|
|
3419
|
+
if (lookup.node === null) {
|
|
3420
|
+
throw new FS.ErrnoError(44);
|
|
3421
|
+
}
|
|
3422
|
+
if (!FS.isDir(lookup.node.mode)) {
|
|
3423
|
+
throw new FS.ErrnoError(54);
|
|
3424
|
+
}
|
|
3425
|
+
var errCode = FS.nodePermissions(lookup.node, 'x');
|
|
3426
|
+
if (errCode) {
|
|
3427
|
+
throw new FS.ErrnoError(errCode);
|
|
3428
|
+
}
|
|
3429
|
+
FS.currentPath = lookup.path;
|
|
3430
|
+
},
|
|
3431
|
+
createDefaultDirectories() {
|
|
3432
|
+
FS.mkdir('/tmp');
|
|
3433
|
+
FS.mkdir('/home');
|
|
3434
|
+
FS.mkdir('/home/web_user');
|
|
3435
|
+
},
|
|
3436
|
+
createDefaultDevices() {
|
|
3437
|
+
// create /dev
|
|
3438
|
+
FS.mkdir('/dev');
|
|
3439
|
+
// setup /dev/null
|
|
3440
|
+
FS.registerDevice(FS.makedev(1, 3), {
|
|
3441
|
+
read: () => 0,
|
|
3442
|
+
write: (stream, buffer, offset, length, pos) => length,
|
|
3443
|
+
llseek: () => 0,
|
|
3444
|
+
});
|
|
3445
|
+
FS.mkdev('/dev/null', FS.makedev(1, 3));
|
|
3446
|
+
// setup /dev/tty and /dev/tty1
|
|
3447
|
+
// stderr needs to print output using err() rather than out()
|
|
3448
|
+
// so we register a second tty just for it.
|
|
3449
|
+
TTY.register(FS.makedev(5, 0), TTY.default_tty_ops);
|
|
3450
|
+
TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);
|
|
3451
|
+
FS.mkdev('/dev/tty', FS.makedev(5, 0));
|
|
3452
|
+
FS.mkdev('/dev/tty1', FS.makedev(6, 0));
|
|
3453
|
+
// setup /dev/[u]random
|
|
3454
|
+
// use a buffer to avoid overhead of individual crypto calls per byte
|
|
3455
|
+
var randomBuffer = new Uint8Array(1024), randomLeft = 0;
|
|
3456
|
+
var randomByte = () => {
|
|
3457
|
+
if (randomLeft === 0) {
|
|
3458
|
+
randomFill(randomBuffer);
|
|
3459
|
+
randomLeft = randomBuffer.byteLength;
|
|
3460
|
+
}
|
|
3461
|
+
return randomBuffer[--randomLeft];
|
|
3462
|
+
};
|
|
3463
|
+
FS.createDevice('/dev', 'random', randomByte);
|
|
3464
|
+
FS.createDevice('/dev', 'urandom', randomByte);
|
|
3465
|
+
// we're not going to emulate the actual shm device,
|
|
3466
|
+
// just create the tmp dirs that reside in it commonly
|
|
3467
|
+
FS.mkdir('/dev/shm');
|
|
3468
|
+
FS.mkdir('/dev/shm/tmp');
|
|
3469
|
+
},
|
|
3470
|
+
createSpecialDirectories() {
|
|
3471
|
+
// create /proc/self/fd which allows /proc/self/fd/6 => readlink gives the
|
|
3472
|
+
// name of the stream for fd 6 (see test_unistd_ttyname)
|
|
3473
|
+
FS.mkdir('/proc');
|
|
3474
|
+
var proc_self = FS.mkdir('/proc/self');
|
|
3475
|
+
FS.mkdir('/proc/self/fd');
|
|
3476
|
+
FS.mount({
|
|
3477
|
+
mount() {
|
|
3478
|
+
var node = FS.createNode(proc_self, 'fd', 16895, 73);
|
|
3479
|
+
node.stream_ops = {
|
|
3480
|
+
llseek: MEMFS.stream_ops.llseek,
|
|
3481
|
+
};
|
|
3482
|
+
node.node_ops = {
|
|
3483
|
+
lookup(parent, name) {
|
|
3484
|
+
var fd = +name;
|
|
3485
|
+
var stream = FS.getStreamChecked(fd);
|
|
3486
|
+
var ret = {
|
|
3487
|
+
parent: null,
|
|
3488
|
+
mount: { mountpoint: 'fake' },
|
|
3489
|
+
node_ops: { readlink: () => stream.path },
|
|
3490
|
+
id: fd + 1,
|
|
3491
|
+
};
|
|
3492
|
+
ret.parent = ret; // make it look like a simple root node
|
|
3493
|
+
return ret;
|
|
3494
|
+
},
|
|
3495
|
+
readdir() {
|
|
3496
|
+
return Array.from(FS.streams.entries())
|
|
3497
|
+
.filter(([k, v]) => v)
|
|
3498
|
+
.map(([k, v]) => k.toString());
|
|
3499
|
+
}
|
|
3500
|
+
};
|
|
3501
|
+
return node;
|
|
3502
|
+
}
|
|
3503
|
+
}, {}, '/proc/self/fd');
|
|
3504
|
+
},
|
|
3505
|
+
createStandardStreams(input, output, error) {
|
|
3506
|
+
// TODO deprecate the old functionality of a single
|
|
3507
|
+
// input / output callback and that utilizes FS.createDevice
|
|
3508
|
+
// and instead require a unique set of stream ops
|
|
3509
|
+
|
|
3510
|
+
// by default, we symlink the standard streams to the
|
|
3511
|
+
// default tty devices. however, if the standard streams
|
|
3512
|
+
// have been overwritten we create a unique device for
|
|
3513
|
+
// them instead.
|
|
3514
|
+
if (input) {
|
|
3515
|
+
FS.createDevice('/dev', 'stdin', input);
|
|
3516
|
+
} else {
|
|
3517
|
+
FS.symlink('/dev/tty', '/dev/stdin');
|
|
3518
|
+
}
|
|
3519
|
+
if (output) {
|
|
3520
|
+
FS.createDevice('/dev', 'stdout', null, output);
|
|
3521
|
+
} else {
|
|
3522
|
+
FS.symlink('/dev/tty', '/dev/stdout');
|
|
3523
|
+
}
|
|
3524
|
+
if (error) {
|
|
3525
|
+
FS.createDevice('/dev', 'stderr', null, error);
|
|
3526
|
+
} else {
|
|
3527
|
+
FS.symlink('/dev/tty1', '/dev/stderr');
|
|
3528
|
+
}
|
|
3529
|
+
|
|
3530
|
+
// open default streams for the stdin, stdout and stderr devices
|
|
3531
|
+
var stdin = FS.open('/dev/stdin', 0);
|
|
3532
|
+
var stdout = FS.open('/dev/stdout', 1);
|
|
3533
|
+
var stderr = FS.open('/dev/stderr', 1);
|
|
3534
|
+
},
|
|
3535
|
+
staticInit() {
|
|
3536
|
+
FS.nameTable = new Array(4096);
|
|
3537
|
+
|
|
3538
|
+
FS.mount(MEMFS, {}, '/');
|
|
3539
|
+
|
|
3540
|
+
FS.createDefaultDirectories();
|
|
3541
|
+
FS.createDefaultDevices();
|
|
3542
|
+
FS.createSpecialDirectories();
|
|
3543
|
+
|
|
3544
|
+
FS.filesystems = {
|
|
3545
|
+
'MEMFS': MEMFS,
|
|
3546
|
+
};
|
|
3547
|
+
},
|
|
3548
|
+
init(input, output, error) {
|
|
3549
|
+
FS.initialized = true;
|
|
3550
|
+
|
|
3551
|
+
// Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
|
|
3552
|
+
input ??= Module['stdin'];
|
|
3553
|
+
output ??= Module['stdout'];
|
|
3554
|
+
error ??= Module['stderr'];
|
|
3555
|
+
|
|
3556
|
+
FS.createStandardStreams(input, output, error);
|
|
3557
|
+
},
|
|
3558
|
+
quit() {
|
|
3559
|
+
FS.initialized = false;
|
|
3560
|
+
// force-flush all streams, so we get musl std streams printed out
|
|
3561
|
+
// close all of our streams
|
|
3562
|
+
for (var stream of FS.streams) {
|
|
3563
|
+
if (stream) {
|
|
3564
|
+
FS.close(stream);
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
},
|
|
3568
|
+
findObject(path, dontResolveLastLink) {
|
|
3569
|
+
var ret = FS.analyzePath(path, dontResolveLastLink);
|
|
3570
|
+
if (!ret.exists) {
|
|
3571
|
+
return null;
|
|
3572
|
+
}
|
|
3573
|
+
return ret.object;
|
|
3574
|
+
},
|
|
3575
|
+
analyzePath(path, dontResolveLastLink) {
|
|
3576
|
+
// operate from within the context of the symlink's target
|
|
3577
|
+
try {
|
|
3578
|
+
var lookup = FS.lookupPath(path, { follow: !dontResolveLastLink });
|
|
3579
|
+
path = lookup.path;
|
|
3580
|
+
} catch (e) {
|
|
3581
|
+
}
|
|
3582
|
+
var ret = {
|
|
3583
|
+
isRoot: false, exists: false, error: 0, name: null, path: null, object: null,
|
|
3584
|
+
parentExists: false, parentPath: null, parentObject: null
|
|
3585
|
+
};
|
|
3586
|
+
try {
|
|
3587
|
+
var lookup = FS.lookupPath(path, { parent: true });
|
|
3588
|
+
ret.parentExists = true;
|
|
3589
|
+
ret.parentPath = lookup.path;
|
|
3590
|
+
ret.parentObject = lookup.node;
|
|
3591
|
+
ret.name = PATH.basename(path);
|
|
3592
|
+
lookup = FS.lookupPath(path, { follow: !dontResolveLastLink });
|
|
3593
|
+
ret.exists = true;
|
|
3594
|
+
ret.path = lookup.path;
|
|
3595
|
+
ret.object = lookup.node;
|
|
3596
|
+
ret.name = lookup.node.name;
|
|
3597
|
+
ret.isRoot = lookup.path === '/';
|
|
3598
|
+
} catch (e) {
|
|
3599
|
+
ret.error = e.errno;
|
|
3600
|
+
};
|
|
3601
|
+
return ret;
|
|
3602
|
+
},
|
|
3603
|
+
createPath(parent, path, canRead, canWrite) {
|
|
3604
|
+
parent = typeof parent == 'string' ? parent : FS.getPath(parent);
|
|
3605
|
+
var parts = path.split('/').reverse();
|
|
3606
|
+
while (parts.length) {
|
|
3607
|
+
var part = parts.pop();
|
|
3608
|
+
if (!part) continue;
|
|
3609
|
+
var current = PATH.join2(parent, part);
|
|
3610
|
+
try {
|
|
3611
|
+
FS.mkdir(current);
|
|
3612
|
+
} catch (e) {
|
|
3613
|
+
if (e.errno != 20) throw e;
|
|
3614
|
+
}
|
|
3615
|
+
parent = current;
|
|
3616
|
+
}
|
|
3617
|
+
return current;
|
|
3618
|
+
},
|
|
3619
|
+
createFile(parent, name, properties, canRead, canWrite) {
|
|
3620
|
+
var path = PATH.join2(typeof parent == 'string' ? parent : FS.getPath(parent), name);
|
|
3621
|
+
var mode = FS_getMode(canRead, canWrite);
|
|
3622
|
+
return FS.create(path, mode);
|
|
3623
|
+
},
|
|
3624
|
+
createDataFile(parent, name, data, canRead, canWrite, canOwn) {
|
|
3625
|
+
var path = name;
|
|
3626
|
+
if (parent) {
|
|
3627
|
+
parent = typeof parent == 'string' ? parent : FS.getPath(parent);
|
|
3628
|
+
path = name ? PATH.join2(parent, name) : parent;
|
|
3629
|
+
}
|
|
3630
|
+
var mode = FS_getMode(canRead, canWrite);
|
|
3631
|
+
var node = FS.create(path, mode);
|
|
3632
|
+
if (data) {
|
|
3633
|
+
if (typeof data == 'string') {
|
|
3634
|
+
var arr = new Array(data.length);
|
|
3635
|
+
for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
|
|
3636
|
+
data = arr;
|
|
3637
|
+
}
|
|
3638
|
+
// make sure we can write to the file
|
|
3639
|
+
FS.chmod(node, mode | 146);
|
|
3640
|
+
var stream = FS.open(node, 577);
|
|
3641
|
+
FS.write(stream, data, 0, data.length, 0, canOwn);
|
|
3642
|
+
FS.close(stream);
|
|
3643
|
+
FS.chmod(node, mode);
|
|
3644
|
+
}
|
|
3645
|
+
},
|
|
3646
|
+
createDevice(parent, name, input, output) {
|
|
3647
|
+
var path = PATH.join2(typeof parent == 'string' ? parent : FS.getPath(parent), name);
|
|
3648
|
+
var mode = FS_getMode(!!input, !!output);
|
|
3649
|
+
FS.createDevice.major ??= 64;
|
|
3650
|
+
var dev = FS.makedev(FS.createDevice.major++, 0);
|
|
3651
|
+
// Create a fake device that a set of stream ops to emulate
|
|
3652
|
+
// the old behavior.
|
|
3653
|
+
FS.registerDevice(dev, {
|
|
3654
|
+
open(stream) {
|
|
3655
|
+
stream.seekable = false;
|
|
3656
|
+
},
|
|
3657
|
+
close(stream) {
|
|
3658
|
+
// flush any pending line data
|
|
3659
|
+
if (output?.buffer?.length) {
|
|
3660
|
+
output(10);
|
|
3661
|
+
}
|
|
3662
|
+
},
|
|
3663
|
+
read(stream, buffer, offset, length, pos /* ignored */) {
|
|
3664
|
+
var bytesRead = 0;
|
|
3665
|
+
for (var i = 0; i < length; i++) {
|
|
3666
|
+
var result;
|
|
3667
|
+
try {
|
|
3668
|
+
result = input();
|
|
3669
|
+
} catch (e) {
|
|
3670
|
+
throw new FS.ErrnoError(29);
|
|
3671
|
+
}
|
|
3672
|
+
if (result === undefined && bytesRead === 0) {
|
|
3673
|
+
throw new FS.ErrnoError(6);
|
|
3674
|
+
}
|
|
3675
|
+
if (result === null || result === undefined) break;
|
|
3676
|
+
bytesRead++;
|
|
3677
|
+
buffer[offset+i] = result;
|
|
3678
|
+
}
|
|
3679
|
+
if (bytesRead) {
|
|
3680
|
+
stream.node.atime = Date.now();
|
|
3681
|
+
}
|
|
3682
|
+
return bytesRead;
|
|
3683
|
+
},
|
|
3684
|
+
write(stream, buffer, offset, length, pos) {
|
|
3685
|
+
for (var i = 0; i < length; i++) {
|
|
3686
|
+
try {
|
|
3687
|
+
output(buffer[offset+i]);
|
|
3688
|
+
} catch (e) {
|
|
3689
|
+
throw new FS.ErrnoError(29);
|
|
3690
|
+
}
|
|
3691
|
+
}
|
|
3692
|
+
if (length) {
|
|
3693
|
+
stream.node.mtime = stream.node.ctime = Date.now();
|
|
3694
|
+
}
|
|
3695
|
+
return i;
|
|
3696
|
+
}
|
|
3697
|
+
});
|
|
3698
|
+
return FS.mkdev(path, mode, dev);
|
|
3699
|
+
},
|
|
3700
|
+
forceLoadFile(obj) {
|
|
3701
|
+
if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
|
|
3702
|
+
if (typeof XMLHttpRequest != 'undefined') {
|
|
3703
|
+
throw new Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.");
|
|
3704
|
+
} else { // Command-line.
|
|
3705
|
+
try {
|
|
3706
|
+
obj.contents = readBinary(obj.url);
|
|
3707
|
+
obj.usedBytes = obj.contents.length;
|
|
3708
|
+
} catch (e) {
|
|
3709
|
+
throw new FS.ErrnoError(29);
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
},
|
|
3713
|
+
createLazyFile(parent, name, url, canRead, canWrite) {
|
|
3714
|
+
// Lazy chunked Uint8Array (implements get and length from Uint8Array).
|
|
3715
|
+
// Actual getting is abstracted away for eventual reuse.
|
|
3716
|
+
class LazyUint8Array {
|
|
3717
|
+
lengthKnown = false;
|
|
3718
|
+
chunks = []; // Loaded chunks. Index is the chunk number
|
|
3719
|
+
get(idx) {
|
|
3720
|
+
if (idx > this.length-1 || idx < 0) {
|
|
3721
|
+
return undefined;
|
|
3722
|
+
}
|
|
3723
|
+
var chunkOffset = idx % this.chunkSize;
|
|
3724
|
+
var chunkNum = (idx / this.chunkSize)|0;
|
|
3725
|
+
return this.getter(chunkNum)[chunkOffset];
|
|
3726
|
+
}
|
|
3727
|
+
setDataGetter(getter) {
|
|
3728
|
+
this.getter = getter;
|
|
3729
|
+
}
|
|
3730
|
+
cacheLength() {
|
|
3731
|
+
// Find length
|
|
3732
|
+
var xhr = new XMLHttpRequest();
|
|
3733
|
+
xhr.open('HEAD', url, false);
|
|
3734
|
+
xhr.send(null);
|
|
3735
|
+
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
|
|
3736
|
+
var datalength = Number(xhr.getResponseHeader("Content-length"));
|
|
3737
|
+
var header;
|
|
3738
|
+
var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
|
|
3739
|
+
var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
|
|
3740
|
+
|
|
3741
|
+
var chunkSize = 1024*1024; // Chunk size in bytes
|
|
3742
|
+
|
|
3743
|
+
if (!hasByteServing) chunkSize = datalength;
|
|
3744
|
+
|
|
3745
|
+
// Function to get a range from the remote URL.
|
|
3746
|
+
var doXHR = (from, to) => {
|
|
3747
|
+
if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
|
|
3748
|
+
if (to > datalength-1) throw new Error("only " + datalength + " bytes available! programmer error!");
|
|
3749
|
+
|
|
3750
|
+
// TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
|
|
3751
|
+
var xhr = new XMLHttpRequest();
|
|
3752
|
+
xhr.open('GET', url, false);
|
|
3753
|
+
if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
|
|
3754
|
+
|
|
3755
|
+
// Some hints to the browser that we want binary data.
|
|
3756
|
+
xhr.responseType = 'arraybuffer';
|
|
3757
|
+
if (xhr.overrideMimeType) {
|
|
3758
|
+
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
|
3759
|
+
}
|
|
3760
|
+
|
|
3761
|
+
xhr.send(null);
|
|
3762
|
+
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
|
|
3763
|
+
if (xhr.response !== undefined) {
|
|
3764
|
+
return new Uint8Array(/** @type{Array<number>} */(xhr.response || []));
|
|
3765
|
+
}
|
|
3766
|
+
return intArrayFromString(xhr.responseText || '', true);
|
|
3767
|
+
};
|
|
3768
|
+
var lazyArray = this;
|
|
3769
|
+
lazyArray.setDataGetter((chunkNum) => {
|
|
3770
|
+
var start = chunkNum * chunkSize;
|
|
3771
|
+
var end = (chunkNum+1) * chunkSize - 1; // including this byte
|
|
3772
|
+
end = Math.min(end, datalength-1); // if datalength-1 is selected, this is the last block
|
|
3773
|
+
if (typeof lazyArray.chunks[chunkNum] == 'undefined') {
|
|
3774
|
+
lazyArray.chunks[chunkNum] = doXHR(start, end);
|
|
3775
|
+
}
|
|
3776
|
+
if (typeof lazyArray.chunks[chunkNum] == 'undefined') throw new Error('doXHR failed!');
|
|
3777
|
+
return lazyArray.chunks[chunkNum];
|
|
3778
|
+
});
|
|
3779
|
+
|
|
3780
|
+
if (usesGzip || !datalength) {
|
|
3781
|
+
// if the server uses gzip or doesn't supply the length, we have to download the whole file to get the (uncompressed) length
|
|
3782
|
+
chunkSize = datalength = 1; // this will force getter(0)/doXHR do download the whole file
|
|
3783
|
+
datalength = this.getter(0).length;
|
|
3784
|
+
chunkSize = datalength;
|
|
3785
|
+
out("LazyFiles on gzip forces download of the whole file when length is accessed");
|
|
3786
|
+
}
|
|
3787
|
+
|
|
3788
|
+
this._length = datalength;
|
|
3789
|
+
this._chunkSize = chunkSize;
|
|
3790
|
+
this.lengthKnown = true;
|
|
3791
|
+
}
|
|
3792
|
+
get length() {
|
|
3793
|
+
if (!this.lengthKnown) {
|
|
3794
|
+
this.cacheLength();
|
|
3795
|
+
}
|
|
3796
|
+
return this._length;
|
|
3797
|
+
}
|
|
3798
|
+
get chunkSize() {
|
|
3799
|
+
if (!this.lengthKnown) {
|
|
3800
|
+
this.cacheLength();
|
|
3801
|
+
}
|
|
3802
|
+
return this._chunkSize;
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
if (typeof XMLHttpRequest != 'undefined') {
|
|
3807
|
+
if (!ENVIRONMENT_IS_WORKER) throw 'Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc';
|
|
3808
|
+
var lazyArray = new LazyUint8Array();
|
|
3809
|
+
var properties = { isDevice: false, contents: lazyArray };
|
|
3810
|
+
} else {
|
|
3811
|
+
var properties = { isDevice: false, url: url };
|
|
3812
|
+
}
|
|
3813
|
+
|
|
3814
|
+
var node = FS.createFile(parent, name, properties, canRead, canWrite);
|
|
3815
|
+
// This is a total hack, but I want to get this lazy file code out of the
|
|
3816
|
+
// core of MEMFS. If we want to keep this lazy file concept I feel it should
|
|
3817
|
+
// be its own thin LAZYFS proxying calls to MEMFS.
|
|
3818
|
+
if (properties.contents) {
|
|
3819
|
+
node.contents = properties.contents;
|
|
3820
|
+
} else if (properties.url) {
|
|
3821
|
+
node.contents = null;
|
|
3822
|
+
node.url = properties.url;
|
|
3823
|
+
}
|
|
3824
|
+
// Add a function that defers querying the file size until it is asked the first time.
|
|
3825
|
+
Object.defineProperties(node, {
|
|
3826
|
+
usedBytes: {
|
|
3827
|
+
get: function() { return this.contents.length; }
|
|
3828
|
+
}
|
|
3829
|
+
});
|
|
3830
|
+
// override each stream op with one that tries to force load the lazy file first
|
|
3831
|
+
var stream_ops = {};
|
|
3832
|
+
var keys = Object.keys(node.stream_ops);
|
|
3833
|
+
keys.forEach((key) => {
|
|
3834
|
+
var fn = node.stream_ops[key];
|
|
3835
|
+
stream_ops[key] = (...args) => {
|
|
3836
|
+
FS.forceLoadFile(node);
|
|
3837
|
+
return fn(...args);
|
|
3838
|
+
};
|
|
3839
|
+
});
|
|
3840
|
+
function writeChunks(stream, buffer, offset, length, position) {
|
|
3841
|
+
var contents = stream.node.contents;
|
|
3842
|
+
if (position >= contents.length)
|
|
3843
|
+
return 0;
|
|
3844
|
+
var size = Math.min(contents.length - position, length);
|
|
3845
|
+
if (contents.slice) { // normal array
|
|
3846
|
+
for (var i = 0; i < size; i++) {
|
|
3847
|
+
buffer[offset + i] = contents[position + i];
|
|
3848
|
+
}
|
|
3849
|
+
} else {
|
|
3850
|
+
for (var i = 0; i < size; i++) { // LazyUint8Array from sync binary XHR
|
|
3851
|
+
buffer[offset + i] = contents.get(position + i);
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
return size;
|
|
3855
|
+
}
|
|
3856
|
+
// use a custom read function
|
|
3857
|
+
stream_ops.read = (stream, buffer, offset, length, position) => {
|
|
3858
|
+
FS.forceLoadFile(node);
|
|
3859
|
+
return writeChunks(stream, buffer, offset, length, position)
|
|
3860
|
+
};
|
|
3861
|
+
// use a custom mmap function
|
|
3862
|
+
stream_ops.mmap = (stream, length, position, prot, flags) => {
|
|
3863
|
+
FS.forceLoadFile(node);
|
|
3864
|
+
var ptr = mmapAlloc(length);
|
|
3865
|
+
if (!ptr) {
|
|
3866
|
+
throw new FS.ErrnoError(48);
|
|
3867
|
+
}
|
|
3868
|
+
writeChunks(stream, HEAP8, ptr, length, position);
|
|
3869
|
+
return { ptr, allocated: true };
|
|
3870
|
+
};
|
|
3871
|
+
node.stream_ops = stream_ops;
|
|
3872
|
+
return node;
|
|
3873
|
+
},
|
|
3874
|
+
};
|
|
3875
|
+
|
|
3876
|
+
|
|
3877
|
+
var findLibraryFS = (libName, rpath) => {
|
|
3878
|
+
// If we're preloading a dynamic library, the runtime is not ready to call
|
|
3879
|
+
// __wasmfs_identify or __emscripten_find_dylib. So just quit out.
|
|
3880
|
+
//
|
|
3881
|
+
// This means that DT_NEEDED for the main module and transitive dependencies
|
|
3882
|
+
// of it won't work with this code path. Similarly, it means that calling
|
|
3883
|
+
// loadDynamicLibrary in a preRun hook can't use this code path.
|
|
3884
|
+
if (!runtimeInitialized) {
|
|
3885
|
+
return undefined;
|
|
3886
|
+
}
|
|
3887
|
+
if (PATH.isAbs(libName)) {
|
|
3888
|
+
try {
|
|
3889
|
+
FS.lookupPath(libName);
|
|
3890
|
+
return libName;
|
|
3891
|
+
} catch (e) {
|
|
3892
|
+
return undefined;
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
var rpathResolved = (rpath?.paths || []).map((p) => replaceORIGIN(rpath?.parentLibPath, p));
|
|
3896
|
+
return withStackSave(() => {
|
|
3897
|
+
// In dylink.c we use: `char buf[2*NAME_MAX+2];` and NAME_MAX is 255.
|
|
3898
|
+
// So we use the same size here.
|
|
3899
|
+
var bufSize = 2*255 + 2;
|
|
3900
|
+
var buf = stackAlloc(bufSize);
|
|
3901
|
+
var rpathC = stringToUTF8OnStack(rpathResolved.join(':'));
|
|
3902
|
+
var libNameC = stringToUTF8OnStack(libName);
|
|
3903
|
+
var resLibNameC = __emscripten_find_dylib(buf, rpathC, libNameC, bufSize);
|
|
3904
|
+
return resLibNameC ? UTF8ToString(resLibNameC) : undefined;
|
|
3905
|
+
});
|
|
3906
|
+
};
|
|
3907
|
+
|
|
3908
|
+
/**
|
|
3909
|
+
* @param {number=} handle
|
|
3910
|
+
* @param {Object=} localScope
|
|
3911
|
+
*/
|
|
3912
|
+
function loadDynamicLibrary(libName, flags = {global: true, nodelete: true}, localScope, handle) {
|
|
3913
|
+
// when loadDynamicLibrary did not have flags, libraries were loaded
|
|
3914
|
+
// globally & permanently
|
|
3915
|
+
|
|
3916
|
+
var dso = LDSO.loadedLibsByName[libName];
|
|
3917
|
+
if (dso) {
|
|
3918
|
+
// the library is being loaded or has been loaded already.
|
|
3919
|
+
if (!flags.global) {
|
|
3920
|
+
if (localScope) {
|
|
3921
|
+
Object.assign(localScope, dso.exports);
|
|
3922
|
+
}
|
|
3923
|
+
} else if (!dso.global) {
|
|
3924
|
+
// The library was previously loaded only locally but not
|
|
3925
|
+
// we have a request with global=true.
|
|
3926
|
+
dso.global = true;
|
|
3927
|
+
mergeLibSymbols(dso.exports, libName)
|
|
3928
|
+
}
|
|
3929
|
+
// same for "nodelete"
|
|
3930
|
+
if (flags.nodelete && dso.refcount !== Infinity) {
|
|
3931
|
+
dso.refcount = Infinity;
|
|
3932
|
+
}
|
|
3933
|
+
dso.refcount++
|
|
3934
|
+
if (handle) {
|
|
3935
|
+
LDSO.loadedLibsByHandle[handle] = dso;
|
|
3936
|
+
}
|
|
3937
|
+
return flags.loadAsync ? Promise.resolve(true) : true;
|
|
3938
|
+
}
|
|
3939
|
+
|
|
3940
|
+
// allocate new DSO
|
|
3941
|
+
dso = newDSO(libName, handle, 'loading');
|
|
3942
|
+
dso.refcount = flags.nodelete ? Infinity : 1;
|
|
3943
|
+
dso.global = flags.global;
|
|
3944
|
+
|
|
3945
|
+
// libName -> libData
|
|
3946
|
+
function loadLibData() {
|
|
3947
|
+
|
|
3948
|
+
// for wasm, we can use fetch for async, but for fs mode we can only imitate it
|
|
3949
|
+
if (handle) {
|
|
3950
|
+
var data = HEAPU32[(((handle)+(28))>>2)];
|
|
3951
|
+
var dataSize = HEAPU32[(((handle)+(32))>>2)];
|
|
3952
|
+
if (data && dataSize) {
|
|
3953
|
+
var libData = HEAP8.slice(data, data + dataSize);
|
|
3954
|
+
return flags.loadAsync ? Promise.resolve(libData) : libData;
|
|
3955
|
+
}
|
|
3956
|
+
}
|
|
3957
|
+
|
|
3958
|
+
var f = findLibraryFS(libName, flags.rpath);
|
|
3959
|
+
if (f) {
|
|
3960
|
+
var libData = FS.readFile(f, {encoding: 'binary'});
|
|
3961
|
+
return flags.loadAsync ? Promise.resolve(libData) : libData;
|
|
3962
|
+
}
|
|
3963
|
+
|
|
3964
|
+
var libFile = locateFile(libName);
|
|
3965
|
+
if (flags.loadAsync) {
|
|
3966
|
+
return asyncLoad(libFile);
|
|
3967
|
+
}
|
|
3968
|
+
|
|
3969
|
+
// load the binary synchronously
|
|
3970
|
+
if (!readBinary) {
|
|
3971
|
+
throw new Error(`${libFile}: file not found, and synchronous loading of external files is not available`);
|
|
3972
|
+
}
|
|
3973
|
+
return readBinary(libFile);
|
|
3974
|
+
}
|
|
3975
|
+
|
|
3976
|
+
// libName -> exports
|
|
3977
|
+
function getExports() {
|
|
3978
|
+
// lookup preloaded cache first
|
|
3979
|
+
var preloaded = preloadedWasm[libName];
|
|
3980
|
+
if (preloaded) {
|
|
3981
|
+
return flags.loadAsync ? Promise.resolve(preloaded) : preloaded;
|
|
3982
|
+
}
|
|
3983
|
+
|
|
3984
|
+
// module not preloaded - load lib data and create new module from it
|
|
3985
|
+
if (flags.loadAsync) {
|
|
3986
|
+
return loadLibData().then((libData) => loadWebAssemblyModule(libData, flags, libName, localScope, handle));
|
|
3987
|
+
}
|
|
3988
|
+
|
|
3989
|
+
return loadWebAssemblyModule(loadLibData(), flags, libName, localScope, handle);
|
|
3990
|
+
}
|
|
3991
|
+
|
|
3992
|
+
// module for lib is loaded - update the dso & global namespace
|
|
3993
|
+
function moduleLoaded(exports) {
|
|
3994
|
+
if (dso.global) {
|
|
3995
|
+
mergeLibSymbols(exports, libName);
|
|
3996
|
+
} else if (localScope) {
|
|
3997
|
+
Object.assign(localScope, exports);
|
|
3998
|
+
}
|
|
3999
|
+
dso.exports = exports;
|
|
4000
|
+
}
|
|
4001
|
+
|
|
4002
|
+
if (flags.loadAsync) {
|
|
4003
|
+
return getExports().then((exports) => {
|
|
4004
|
+
moduleLoaded(exports);
|
|
4005
|
+
return true;
|
|
4006
|
+
});
|
|
4007
|
+
}
|
|
4008
|
+
|
|
4009
|
+
moduleLoaded(getExports());
|
|
4010
|
+
return true;
|
|
4011
|
+
}
|
|
4012
|
+
|
|
4013
|
+
|
|
4014
|
+
var reportUndefinedSymbols = () => {
|
|
4015
|
+
for (var [symName, entry] of Object.entries(GOT)) {
|
|
4016
|
+
if (entry.value == 0) {
|
|
4017
|
+
var value = resolveGlobalSymbol(symName, true).sym;
|
|
4018
|
+
if (!value && !entry.required) {
|
|
4019
|
+
// Ignore undefined symbols that are imported as weak.
|
|
4020
|
+
continue;
|
|
4021
|
+
}
|
|
4022
|
+
if (typeof value == 'function') {
|
|
4023
|
+
/** @suppress {checkTypes} */
|
|
4024
|
+
entry.value = addFunction(value, value.sig);
|
|
4025
|
+
} else if (typeof value == 'number') {
|
|
4026
|
+
entry.value = value;
|
|
4027
|
+
} else {
|
|
4028
|
+
throw new Error(`bad export type for '${symName}': ${typeof value}`);
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
}
|
|
4032
|
+
};
|
|
4033
|
+
var loadDylibs = () => {
|
|
4034
|
+
if (!dynamicLibraries.length) {
|
|
4035
|
+
reportUndefinedSymbols();
|
|
4036
|
+
return;
|
|
4037
|
+
}
|
|
4038
|
+
|
|
4039
|
+
// Load binaries asynchronously
|
|
4040
|
+
addRunDependency('loadDylibs');
|
|
4041
|
+
dynamicLibraries
|
|
4042
|
+
.reduce((chain, lib) => chain.then(() =>
|
|
4043
|
+
loadDynamicLibrary(lib, {loadAsync: true, global: true, nodelete: true, allowUndefined: true})
|
|
4044
|
+
), Promise.resolve())
|
|
4045
|
+
.then(() => {
|
|
4046
|
+
// we got them all, wonderful
|
|
4047
|
+
reportUndefinedSymbols();
|
|
4048
|
+
removeRunDependency('loadDylibs');
|
|
4049
|
+
});
|
|
4050
|
+
};
|
|
4051
|
+
|
|
4052
|
+
|
|
4053
|
+
var noExitRuntime = true;
|
|
4054
|
+
|
|
4055
|
+
|
|
4056
|
+
|
|
4057
|
+
|
|
4058
|
+
/**
|
|
4059
|
+
* @param {number} ptr
|
|
4060
|
+
* @param {number} value
|
|
4061
|
+
* @param {string} type
|
|
4062
|
+
*/
|
|
4063
|
+
function setValue(ptr, value, type = 'i8') {
|
|
4064
|
+
if (type.endsWith('*')) type = '*';
|
|
4065
|
+
switch (type) {
|
|
4066
|
+
case 'i1': HEAP8[ptr] = value; break;
|
|
4067
|
+
case 'i8': HEAP8[ptr] = value; break;
|
|
4068
|
+
case 'i16': HEAP16[((ptr)>>1)] = value; break;
|
|
4069
|
+
case 'i32': HEAP32[((ptr)>>2)] = value; break;
|
|
4070
|
+
case 'i64': HEAP64[((ptr)>>3)] = BigInt(value); break;
|
|
4071
|
+
case 'float': HEAPF32[((ptr)>>2)] = value; break;
|
|
4072
|
+
case 'double': HEAPF64[((ptr)>>3)] = value; break;
|
|
4073
|
+
case '*': HEAPU32[((ptr)>>2)] = value; break;
|
|
4074
|
+
default: abort(`invalid type for setValue: ${type}`);
|
|
4075
|
+
}
|
|
4076
|
+
}
|
|
4077
|
+
|
|
4078
|
+
var ___assert_fail = (condition, filename, line, func) =>
|
|
4079
|
+
abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']);
|
|
4080
|
+
___assert_fail.sig = 'vppip';
|
|
4081
|
+
|
|
4082
|
+
var ___cpp_exception = new WebAssembly.Tag({'parameters': ['i32']});
|
|
4083
|
+
|
|
4084
|
+
|
|
4085
|
+
var ___memory_base = new WebAssembly.Global({'value': 'i32', 'mutable': false}, 1024);
|
|
4086
|
+
|
|
4087
|
+
var ___stack_high = 201984;
|
|
4088
|
+
|
|
4089
|
+
var ___stack_low = 136448;
|
|
4090
|
+
|
|
4091
|
+
var ___stack_pointer = new WebAssembly.Global({'value': 'i32', 'mutable': true}, 201984);
|
|
4092
|
+
|
|
4093
|
+
|
|
4094
|
+
|
|
4095
|
+
var SYSCALLS = {
|
|
4096
|
+
DEFAULT_POLLMASK:5,
|
|
4097
|
+
calculateAt(dirfd, path, allowEmpty) {
|
|
4098
|
+
if (PATH.isAbs(path)) {
|
|
4099
|
+
return path;
|
|
4100
|
+
}
|
|
4101
|
+
// relative path
|
|
4102
|
+
var dir;
|
|
4103
|
+
if (dirfd === -100) {
|
|
4104
|
+
dir = FS.cwd();
|
|
4105
|
+
} else {
|
|
4106
|
+
var dirstream = SYSCALLS.getStreamFromFD(dirfd);
|
|
4107
|
+
dir = dirstream.path;
|
|
4108
|
+
}
|
|
4109
|
+
if (path.length == 0) {
|
|
4110
|
+
if (!allowEmpty) {
|
|
4111
|
+
throw new FS.ErrnoError(44);;
|
|
4112
|
+
}
|
|
4113
|
+
return dir;
|
|
4114
|
+
}
|
|
4115
|
+
return dir + '/' + path;
|
|
4116
|
+
},
|
|
4117
|
+
writeStat(buf, stat) {
|
|
4118
|
+
HEAP32[((buf)>>2)] = stat.dev;
|
|
4119
|
+
HEAP32[(((buf)+(4))>>2)] = stat.mode;
|
|
4120
|
+
HEAPU32[(((buf)+(8))>>2)] = stat.nlink;
|
|
4121
|
+
HEAP32[(((buf)+(12))>>2)] = stat.uid;
|
|
4122
|
+
HEAP32[(((buf)+(16))>>2)] = stat.gid;
|
|
4123
|
+
HEAP32[(((buf)+(20))>>2)] = stat.rdev;
|
|
4124
|
+
HEAP64[(((buf)+(24))>>3)] = BigInt(stat.size);
|
|
4125
|
+
HEAP32[(((buf)+(32))>>2)] = 4096;
|
|
4126
|
+
HEAP32[(((buf)+(36))>>2)] = stat.blocks;
|
|
4127
|
+
var atime = stat.atime.getTime();
|
|
4128
|
+
var mtime = stat.mtime.getTime();
|
|
4129
|
+
var ctime = stat.ctime.getTime();
|
|
4130
|
+
HEAP64[(((buf)+(40))>>3)] = BigInt(Math.floor(atime / 1000));
|
|
4131
|
+
HEAPU32[(((buf)+(48))>>2)] = (atime % 1000) * 1000 * 1000;
|
|
4132
|
+
HEAP64[(((buf)+(56))>>3)] = BigInt(Math.floor(mtime / 1000));
|
|
4133
|
+
HEAPU32[(((buf)+(64))>>2)] = (mtime % 1000) * 1000 * 1000;
|
|
4134
|
+
HEAP64[(((buf)+(72))>>3)] = BigInt(Math.floor(ctime / 1000));
|
|
4135
|
+
HEAPU32[(((buf)+(80))>>2)] = (ctime % 1000) * 1000 * 1000;
|
|
4136
|
+
HEAP64[(((buf)+(88))>>3)] = BigInt(stat.ino);
|
|
4137
|
+
return 0;
|
|
4138
|
+
},
|
|
4139
|
+
writeStatFs(buf, stats) {
|
|
4140
|
+
HEAP32[(((buf)+(4))>>2)] = stats.bsize;
|
|
4141
|
+
HEAP32[(((buf)+(40))>>2)] = stats.bsize;
|
|
4142
|
+
HEAP32[(((buf)+(8))>>2)] = stats.blocks;
|
|
4143
|
+
HEAP32[(((buf)+(12))>>2)] = stats.bfree;
|
|
4144
|
+
HEAP32[(((buf)+(16))>>2)] = stats.bavail;
|
|
4145
|
+
HEAP32[(((buf)+(20))>>2)] = stats.files;
|
|
4146
|
+
HEAP32[(((buf)+(24))>>2)] = stats.ffree;
|
|
4147
|
+
HEAP32[(((buf)+(28))>>2)] = stats.fsid;
|
|
4148
|
+
HEAP32[(((buf)+(44))>>2)] = stats.flags; // ST_NOSUID
|
|
4149
|
+
HEAP32[(((buf)+(36))>>2)] = stats.namelen;
|
|
4150
|
+
},
|
|
4151
|
+
doMsync(addr, stream, len, flags, offset) {
|
|
4152
|
+
if (!FS.isFile(stream.node.mode)) {
|
|
4153
|
+
throw new FS.ErrnoError(43);
|
|
4154
|
+
}
|
|
4155
|
+
if (flags & 2) {
|
|
4156
|
+
// MAP_PRIVATE calls need not to be synced back to underlying fs
|
|
4157
|
+
return 0;
|
|
4158
|
+
}
|
|
4159
|
+
var buffer = HEAPU8.slice(addr, addr + len);
|
|
4160
|
+
FS.msync(stream, buffer, offset, len, flags);
|
|
4161
|
+
},
|
|
4162
|
+
getStreamFromFD(fd) {
|
|
4163
|
+
var stream = FS.getStreamChecked(fd);
|
|
4164
|
+
return stream;
|
|
4165
|
+
},
|
|
4166
|
+
varargs:undefined,
|
|
4167
|
+
getStr(ptr) {
|
|
4168
|
+
var ret = UTF8ToString(ptr);
|
|
4169
|
+
return ret;
|
|
4170
|
+
},
|
|
4171
|
+
};
|
|
4172
|
+
function ___syscall_fstat64(fd, buf) {
|
|
4173
|
+
try {
|
|
4174
|
+
|
|
4175
|
+
return SYSCALLS.writeStat(buf, FS.fstat(fd));
|
|
4176
|
+
} catch (e) {
|
|
4177
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4178
|
+
return -e.errno;
|
|
4179
|
+
}
|
|
4180
|
+
}
|
|
4181
|
+
___syscall_fstat64.sig = 'iip';
|
|
4182
|
+
|
|
4183
|
+
|
|
4184
|
+
function ___syscall_getcwd(buf, size) {
|
|
4185
|
+
try {
|
|
4186
|
+
|
|
4187
|
+
if (size === 0) return -28;
|
|
4188
|
+
var cwd = FS.cwd();
|
|
4189
|
+
var cwdLengthInBytes = lengthBytesUTF8(cwd) + 1;
|
|
4190
|
+
if (size < cwdLengthInBytes) return -68;
|
|
4191
|
+
stringToUTF8(cwd, buf, size);
|
|
4192
|
+
return cwdLengthInBytes;
|
|
4193
|
+
} catch (e) {
|
|
4194
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4195
|
+
return -e.errno;
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
___syscall_getcwd.sig = 'ipp';
|
|
4199
|
+
|
|
4200
|
+
function ___syscall_lstat64(path, buf) {
|
|
4201
|
+
try {
|
|
4202
|
+
|
|
4203
|
+
path = SYSCALLS.getStr(path);
|
|
4204
|
+
return SYSCALLS.writeStat(buf, FS.lstat(path));
|
|
4205
|
+
} catch (e) {
|
|
4206
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4207
|
+
return -e.errno;
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
___syscall_lstat64.sig = 'ipp';
|
|
4211
|
+
|
|
4212
|
+
function ___syscall_newfstatat(dirfd, path, buf, flags) {
|
|
4213
|
+
try {
|
|
4214
|
+
|
|
4215
|
+
path = SYSCALLS.getStr(path);
|
|
4216
|
+
var nofollow = flags & 256;
|
|
4217
|
+
var allowEmpty = flags & 4096;
|
|
4218
|
+
flags = flags & (~6400);
|
|
4219
|
+
path = SYSCALLS.calculateAt(dirfd, path, allowEmpty);
|
|
4220
|
+
return SYSCALLS.writeStat(buf, nofollow ? FS.lstat(path) : FS.stat(path));
|
|
4221
|
+
} catch (e) {
|
|
4222
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4223
|
+
return -e.errno;
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
___syscall_newfstatat.sig = 'iippi';
|
|
4227
|
+
|
|
4228
|
+
function ___syscall_stat64(path, buf) {
|
|
4229
|
+
try {
|
|
4230
|
+
|
|
4231
|
+
path = SYSCALLS.getStr(path);
|
|
4232
|
+
return SYSCALLS.writeStat(buf, FS.stat(path));
|
|
4233
|
+
} catch (e) {
|
|
4234
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4235
|
+
return -e.errno;
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
___syscall_stat64.sig = 'ipp';
|
|
4239
|
+
|
|
4240
|
+
var ___table_base = new WebAssembly.Global({'value': 'i32', 'mutable': false}, 1);
|
|
4241
|
+
|
|
4242
|
+
var __abort_js = () =>
|
|
4243
|
+
abort('');
|
|
4244
|
+
__abort_js.sig = 'v';
|
|
4245
|
+
|
|
4246
|
+
var getHeapMax = () =>
|
|
4247
|
+
// Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
|
|
4248
|
+
// full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
|
|
4249
|
+
// for any code that deals with heap sizes, which would require special
|
|
4250
|
+
// casing all heap size related code to treat 0 specially.
|
|
4251
|
+
2147483648;
|
|
4252
|
+
|
|
4253
|
+
|
|
4254
|
+
var growMemory = (size) => {
|
|
4255
|
+
var b = wasmMemory.buffer;
|
|
4256
|
+
var pages = ((size - b.byteLength + 65535) / 65536) | 0;
|
|
4257
|
+
try {
|
|
4258
|
+
// round size grow request up to wasm page size (fixed 64KB per spec)
|
|
4259
|
+
wasmMemory.grow(pages); // .grow() takes a delta compared to the previous size
|
|
4260
|
+
updateMemoryViews();
|
|
4261
|
+
return 1 /*success*/;
|
|
4262
|
+
} catch(e) {
|
|
4263
|
+
}
|
|
4264
|
+
// implicit 0 return to save code size (caller will cast "undefined" into 0
|
|
4265
|
+
// anyhow)
|
|
4266
|
+
};
|
|
4267
|
+
var _emscripten_resize_heap = (requestedSize) => {
|
|
4268
|
+
var oldSize = HEAPU8.length;
|
|
4269
|
+
// With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
|
|
4270
|
+
requestedSize >>>= 0;
|
|
4271
|
+
// With multithreaded builds, races can happen (another thread might increase the size
|
|
4272
|
+
// in between), so return a failure, and let the caller retry.
|
|
4273
|
+
|
|
4274
|
+
// Memory resize rules:
|
|
4275
|
+
// 1. Always increase heap size to at least the requested size, rounded up
|
|
4276
|
+
// to next page multiple.
|
|
4277
|
+
// 2a. If MEMORY_GROWTH_LINEAR_STEP == -1, excessively resize the heap
|
|
4278
|
+
// geometrically: increase the heap size according to
|
|
4279
|
+
// MEMORY_GROWTH_GEOMETRIC_STEP factor (default +20%), At most
|
|
4280
|
+
// overreserve by MEMORY_GROWTH_GEOMETRIC_CAP bytes (default 96MB).
|
|
4281
|
+
// 2b. If MEMORY_GROWTH_LINEAR_STEP != -1, excessively resize the heap
|
|
4282
|
+
// linearly: increase the heap size by at least
|
|
4283
|
+
// MEMORY_GROWTH_LINEAR_STEP bytes.
|
|
4284
|
+
// 3. Max size for the heap is capped at 2048MB-WASM_PAGE_SIZE, or by
|
|
4285
|
+
// MAXIMUM_MEMORY, or by ASAN limit, depending on which is smallest
|
|
4286
|
+
// 4. If we were unable to allocate as much memory, it may be due to
|
|
4287
|
+
// over-eager decision to excessively reserve due to (3) above.
|
|
4288
|
+
// Hence if an allocation fails, cut down on the amount of excess
|
|
4289
|
+
// growth, in an attempt to succeed to perform a smaller allocation.
|
|
4290
|
+
|
|
4291
|
+
// A limit is set for how much we can grow. We should not exceed that
|
|
4292
|
+
// (the wasm binary specifies it, so if we tried, we'd fail anyhow).
|
|
4293
|
+
var maxHeapSize = getHeapMax();
|
|
4294
|
+
if (requestedSize > maxHeapSize) {
|
|
4295
|
+
return false;
|
|
4296
|
+
}
|
|
4297
|
+
|
|
4298
|
+
// Loop through potential heap size increases. If we attempt a too eager
|
|
4299
|
+
// reservation that fails, cut down on the attempted size and reserve a
|
|
4300
|
+
// smaller bump instead. (max 3 times, chosen somewhat arbitrarily)
|
|
4301
|
+
for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
|
|
4302
|
+
var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown); // ensure geometric growth
|
|
4303
|
+
// but limit overreserving (default to capping at +96MB overgrowth at most)
|
|
4304
|
+
overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296 );
|
|
4305
|
+
|
|
4306
|
+
var newSize = Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536));
|
|
4307
|
+
|
|
4308
|
+
var replacement = growMemory(newSize);
|
|
4309
|
+
if (replacement) {
|
|
4310
|
+
|
|
4311
|
+
return true;
|
|
4312
|
+
}
|
|
4313
|
+
}
|
|
4314
|
+
return false;
|
|
4315
|
+
};
|
|
4316
|
+
_emscripten_resize_heap.sig = 'ip';
|
|
4317
|
+
|
|
4318
|
+
var ENV = {
|
|
4319
|
+
};
|
|
4320
|
+
|
|
4321
|
+
var getExecutableName = () => thisProgram || './this.program';
|
|
4322
|
+
var getEnvStrings = () => {
|
|
4323
|
+
if (!getEnvStrings.strings) {
|
|
4324
|
+
// Default values.
|
|
4325
|
+
// Browser language detection #8751
|
|
4326
|
+
var lang = ((typeof navigator == 'object' && navigator.languages && navigator.languages[0]) || 'C').replace('-', '_') + '.UTF-8';
|
|
4327
|
+
var env = {
|
|
4328
|
+
'USER': 'web_user',
|
|
4329
|
+
'LOGNAME': 'web_user',
|
|
4330
|
+
'PATH': '/',
|
|
4331
|
+
'PWD': '/',
|
|
4332
|
+
'HOME': '/home/web_user',
|
|
4333
|
+
'LANG': lang,
|
|
4334
|
+
'_': getExecutableName()
|
|
4335
|
+
};
|
|
4336
|
+
// Apply the user-provided values, if any.
|
|
4337
|
+
for (var x in ENV) {
|
|
4338
|
+
// x is a key in ENV; if ENV[x] is undefined, that means it was
|
|
4339
|
+
// explicitly set to be so. We allow user code to do that to
|
|
4340
|
+
// force variables with default values to remain unset.
|
|
4341
|
+
if (ENV[x] === undefined) delete env[x];
|
|
4342
|
+
else env[x] = ENV[x];
|
|
4343
|
+
}
|
|
4344
|
+
var strings = [];
|
|
4345
|
+
for (var x in env) {
|
|
4346
|
+
strings.push(`${x}=${env[x]}`);
|
|
4347
|
+
}
|
|
4348
|
+
getEnvStrings.strings = strings;
|
|
4349
|
+
}
|
|
4350
|
+
return getEnvStrings.strings;
|
|
4351
|
+
};
|
|
4352
|
+
|
|
4353
|
+
var _environ_get = (__environ, environ_buf) => {
|
|
4354
|
+
var bufSize = 0;
|
|
4355
|
+
var envp = 0;
|
|
4356
|
+
for (var string of getEnvStrings()) {
|
|
4357
|
+
var ptr = environ_buf + bufSize;
|
|
4358
|
+
HEAPU32[(((__environ)+(envp))>>2)] = ptr;
|
|
4359
|
+
bufSize += stringToUTF8(string, ptr, Infinity) + 1;
|
|
4360
|
+
envp += 4;
|
|
4361
|
+
}
|
|
4362
|
+
return 0;
|
|
4363
|
+
};
|
|
4364
|
+
_environ_get.sig = 'ipp';
|
|
4365
|
+
|
|
4366
|
+
|
|
4367
|
+
var _environ_sizes_get = (penviron_count, penviron_buf_size) => {
|
|
4368
|
+
var strings = getEnvStrings();
|
|
4369
|
+
HEAPU32[((penviron_count)>>2)] = strings.length;
|
|
4370
|
+
var bufSize = 0;
|
|
4371
|
+
for (var string of strings) {
|
|
4372
|
+
bufSize += lengthBytesUTF8(string) + 1;
|
|
4373
|
+
}
|
|
4374
|
+
HEAPU32[((penviron_buf_size)>>2)] = bufSize;
|
|
4375
|
+
return 0;
|
|
4376
|
+
};
|
|
4377
|
+
_environ_sizes_get.sig = 'ipp';
|
|
4378
|
+
|
|
4379
|
+
function _fd_close(fd) {
|
|
4380
|
+
try {
|
|
4381
|
+
|
|
4382
|
+
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
4383
|
+
FS.close(stream);
|
|
4384
|
+
return 0;
|
|
4385
|
+
} catch (e) {
|
|
4386
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4387
|
+
return e.errno;
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
_fd_close.sig = 'ii';
|
|
4391
|
+
|
|
4392
|
+
|
|
4393
|
+
var INT53_MAX = 9007199254740992;
|
|
4394
|
+
|
|
4395
|
+
var INT53_MIN = -9007199254740992;
|
|
4396
|
+
var bigintToI53Checked = (num) => (num < INT53_MIN || num > INT53_MAX) ? NaN : Number(num);
|
|
4397
|
+
function _fd_seek(fd, offset, whence, newOffset) {
|
|
4398
|
+
offset = bigintToI53Checked(offset);
|
|
4399
|
+
|
|
4400
|
+
|
|
4401
|
+
try {
|
|
4402
|
+
|
|
4403
|
+
if (isNaN(offset)) return 61;
|
|
4404
|
+
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
4405
|
+
FS.llseek(stream, offset, whence);
|
|
4406
|
+
HEAP64[((newOffset)>>3)] = BigInt(stream.position);
|
|
4407
|
+
if (stream.getdents && offset === 0 && whence === 0) stream.getdents = null; // reset readdir state
|
|
4408
|
+
return 0;
|
|
4409
|
+
} catch (e) {
|
|
4410
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4411
|
+
return e.errno;
|
|
4412
|
+
}
|
|
4413
|
+
;
|
|
4414
|
+
}
|
|
4415
|
+
_fd_seek.sig = 'iijip';
|
|
4416
|
+
|
|
4417
|
+
/** @param {number=} offset */
|
|
4418
|
+
var doWritev = (stream, iov, iovcnt, offset) => {
|
|
4419
|
+
var ret = 0;
|
|
4420
|
+
for (var i = 0; i < iovcnt; i++) {
|
|
4421
|
+
var ptr = HEAPU32[((iov)>>2)];
|
|
4422
|
+
var len = HEAPU32[(((iov)+(4))>>2)];
|
|
4423
|
+
iov += 8;
|
|
4424
|
+
var curr = FS.write(stream, HEAP8, ptr, len, offset);
|
|
4425
|
+
if (curr < 0) return -1;
|
|
4426
|
+
ret += curr;
|
|
4427
|
+
if (curr < len) {
|
|
4428
|
+
// No more space to write.
|
|
4429
|
+
break;
|
|
4430
|
+
}
|
|
4431
|
+
if (typeof offset != 'undefined') {
|
|
4432
|
+
offset += curr;
|
|
4433
|
+
}
|
|
4434
|
+
}
|
|
4435
|
+
return ret;
|
|
4436
|
+
};
|
|
4437
|
+
|
|
4438
|
+
function _fd_write(fd, iov, iovcnt, pnum) {
|
|
4439
|
+
try {
|
|
4440
|
+
|
|
4441
|
+
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
4442
|
+
var num = doWritev(stream, iov, iovcnt);
|
|
4443
|
+
HEAPU32[((pnum)>>2)] = num;
|
|
4444
|
+
return 0;
|
|
4445
|
+
} catch (e) {
|
|
4446
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4447
|
+
return e.errno;
|
|
4448
|
+
}
|
|
4449
|
+
}
|
|
4450
|
+
_fd_write.sig = 'iippp';
|
|
4451
|
+
|
|
4452
|
+
function _random_get(buffer, size) {
|
|
4453
|
+
try {
|
|
4454
|
+
|
|
4455
|
+
randomFill(HEAPU8.subarray(buffer, buffer + size));
|
|
4456
|
+
return 0;
|
|
4457
|
+
} catch (e) {
|
|
4458
|
+
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
4459
|
+
return e.errno;
|
|
4460
|
+
}
|
|
4461
|
+
}
|
|
4462
|
+
_random_get.sig = 'ipp';
|
|
4463
|
+
|
|
4464
|
+
|
|
4465
|
+
var runtimeKeepaliveCounter = 0;
|
|
4466
|
+
var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
|
|
4467
|
+
var _proc_exit = (code) => {
|
|
4468
|
+
EXITSTATUS = code;
|
|
4469
|
+
if (!keepRuntimeAlive()) {
|
|
4470
|
+
Module['onExit']?.(code);
|
|
4471
|
+
ABORT = true;
|
|
4472
|
+
}
|
|
4473
|
+
quit_(code, new ExitStatus(code));
|
|
4474
|
+
};
|
|
4475
|
+
_proc_exit.sig = 'vi';
|
|
4476
|
+
/** @param {boolean|number=} implicit */
|
|
4477
|
+
var exitJS = (status, implicit) => {
|
|
4478
|
+
EXITSTATUS = status;
|
|
4479
|
+
|
|
4480
|
+
_proc_exit(status);
|
|
4481
|
+
};
|
|
4482
|
+
|
|
4483
|
+
var handleException = (e) => {
|
|
4484
|
+
// Certain exception types we do not treat as errors since they are used for
|
|
4485
|
+
// internal control flow.
|
|
4486
|
+
// 1. ExitStatus, which is thrown by exit()
|
|
4487
|
+
// 2. "unwind", which is thrown by emscripten_unwind_to_js_event_loop() and others
|
|
4488
|
+
// that wish to return to JS event loop.
|
|
4489
|
+
if (e instanceof ExitStatus || e == 'unwind') {
|
|
4490
|
+
return EXITSTATUS;
|
|
4491
|
+
}
|
|
4492
|
+
quit_(1, e);
|
|
4493
|
+
};
|
|
4494
|
+
|
|
4495
|
+
|
|
4496
|
+
|
|
4497
|
+
var getCFunc = (ident) => {
|
|
4498
|
+
var func = Module['_' + ident]; // closure exported function
|
|
4499
|
+
return func;
|
|
4500
|
+
};
|
|
4501
|
+
|
|
4502
|
+
var writeArrayToMemory = (array, buffer) => {
|
|
4503
|
+
HEAP8.set(array, buffer);
|
|
4504
|
+
};
|
|
4505
|
+
|
|
4506
|
+
|
|
4507
|
+
|
|
4508
|
+
|
|
4509
|
+
|
|
4510
|
+
|
|
4511
|
+
/**
|
|
4512
|
+
* @param {string|null=} returnType
|
|
4513
|
+
* @param {Array=} argTypes
|
|
4514
|
+
* @param {Arguments|Array=} args
|
|
4515
|
+
* @param {Object=} opts
|
|
4516
|
+
*/
|
|
4517
|
+
var ccall = (ident, returnType, argTypes, args, opts) => {
|
|
4518
|
+
// For fast lookup of conversion functions
|
|
4519
|
+
var toC = {
|
|
4520
|
+
'string': (str) => {
|
|
4521
|
+
var ret = 0;
|
|
4522
|
+
if (str !== null && str !== undefined && str !== 0) { // null string
|
|
4523
|
+
ret = stringToUTF8OnStack(str);
|
|
4524
|
+
}
|
|
4525
|
+
return ret;
|
|
4526
|
+
},
|
|
4527
|
+
'array': (arr) => {
|
|
4528
|
+
var ret = stackAlloc(arr.length);
|
|
4529
|
+
writeArrayToMemory(arr, ret);
|
|
4530
|
+
return ret;
|
|
4531
|
+
}
|
|
4532
|
+
};
|
|
4533
|
+
|
|
4534
|
+
function convertReturnValue(ret) {
|
|
4535
|
+
if (returnType === 'string') {
|
|
4536
|
+
return UTF8ToString(ret);
|
|
4537
|
+
}
|
|
4538
|
+
if (returnType === 'boolean') return Boolean(ret);
|
|
4539
|
+
return ret;
|
|
4540
|
+
}
|
|
4541
|
+
|
|
4542
|
+
var func = getCFunc(ident);
|
|
4543
|
+
var cArgs = [];
|
|
4544
|
+
var stack = 0;
|
|
4545
|
+
if (args) {
|
|
4546
|
+
for (var i = 0; i < args.length; i++) {
|
|
4547
|
+
var converter = toC[argTypes[i]];
|
|
4548
|
+
if (converter) {
|
|
4549
|
+
if (stack === 0) stack = stackSave();
|
|
4550
|
+
cArgs[i] = converter(args[i]);
|
|
4551
|
+
} else {
|
|
4552
|
+
cArgs[i] = args[i];
|
|
4553
|
+
}
|
|
4554
|
+
}
|
|
4555
|
+
}
|
|
4556
|
+
var ret = func(...cArgs);
|
|
4557
|
+
function onDone(ret) {
|
|
4558
|
+
if (stack !== 0) stackRestore(stack);
|
|
4559
|
+
return convertReturnValue(ret);
|
|
4560
|
+
}
|
|
4561
|
+
|
|
4562
|
+
ret = onDone(ret);
|
|
4563
|
+
return ret;
|
|
4564
|
+
};
|
|
4565
|
+
|
|
4566
|
+
|
|
4567
|
+
|
|
4568
|
+
/**
|
|
4569
|
+
* @param {string=} returnType
|
|
4570
|
+
* @param {Array=} argTypes
|
|
4571
|
+
* @param {Object=} opts
|
|
4572
|
+
*/
|
|
4573
|
+
var cwrap = (ident, returnType, argTypes, opts) => {
|
|
4574
|
+
// When the function takes numbers and returns a number, we can just return
|
|
4575
|
+
// the original function
|
|
4576
|
+
var numericArgs = !argTypes || argTypes.every((type) => type === 'number' || type === 'boolean');
|
|
4577
|
+
var numericRet = returnType !== 'string';
|
|
4578
|
+
if (numericRet && numericArgs && !opts) {
|
|
4579
|
+
return getCFunc(ident);
|
|
4580
|
+
}
|
|
4581
|
+
return (...args) => ccall(ident, returnType, argTypes, args, opts);
|
|
4582
|
+
};
|
|
4583
|
+
|
|
4584
|
+
registerWasmPlugin();
|
|
4585
|
+
;
|
|
4586
|
+
|
|
4587
|
+
FS.createPreloadedFile = FS_createPreloadedFile;
|
|
4588
|
+
FS.staticInit();;
|
|
4589
|
+
|
|
4590
|
+
// This error may happen quite a bit. To avoid overhead we reuse it (and
|
|
4591
|
+
// suffer a lack of stack info).
|
|
4592
|
+
MEMFS.doesNotExistError = new FS.ErrnoError(44);
|
|
4593
|
+
/** @suppress {checkTypes} */
|
|
4594
|
+
MEMFS.doesNotExistError.stack = '<generic error, no stack>';
|
|
4595
|
+
;
|
|
4596
|
+
// End JS library code
|
|
4597
|
+
|
|
4598
|
+
// include: postlibrary.js
|
|
4599
|
+
// This file is included after the automatically-generated JS library code
|
|
4600
|
+
// but before the wasm module is created.
|
|
4601
|
+
|
|
4602
|
+
{
|
|
4603
|
+
// With WASM_ESM_INTEGRATION this has to happen at the top level and not
|
|
4604
|
+
// delayed until processModuleArgs.
|
|
4605
|
+
initMemory();
|
|
4606
|
+
|
|
4607
|
+
// Begin ATMODULES hooks
|
|
4608
|
+
if (Module['preloadPlugins']) preloadPlugins = Module['preloadPlugins'];
|
|
4609
|
+
if (Module['noExitRuntime']) noExitRuntime = Module['noExitRuntime'];
|
|
4610
|
+
if (Module['print']) out = Module['print'];
|
|
4611
|
+
if (Module['printErr']) err = Module['printErr'];
|
|
4612
|
+
if (Module['dynamicLibraries']) dynamicLibraries = Module['dynamicLibraries'];
|
|
4613
|
+
if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
|
|
4614
|
+
// End ATMODULES hooks
|
|
4615
|
+
|
|
4616
|
+
if (Module['arguments']) arguments_ = Module['arguments'];
|
|
4617
|
+
if (Module['thisProgram']) thisProgram = Module['thisProgram'];
|
|
4618
|
+
|
|
4619
|
+
}
|
|
4620
|
+
|
|
4621
|
+
// Begin runtime exports
|
|
4622
|
+
Module['ccall'] = ccall;
|
|
4623
|
+
Module['cwrap'] = cwrap;
|
|
4624
|
+
Module['loadDynamicLibrary'] = loadDynamicLibrary;
|
|
4625
|
+
// End runtime exports
|
|
4626
|
+
// Begin JS library exports
|
|
4627
|
+
// End JS library exports
|
|
4628
|
+
|
|
4629
|
+
// end include: postlibrary.js
|
|
4630
|
+
|
|
4631
|
+
var ASM_CONSTS = {
|
|
4632
|
+
|
|
4633
|
+
};
|
|
4634
|
+
var wasmImports = {
|
|
4635
|
+
/** @export */
|
|
4636
|
+
__assert_fail: ___assert_fail,
|
|
4637
|
+
/** @export */
|
|
4638
|
+
__cpp_exception: ___cpp_exception,
|
|
4639
|
+
/** @export */
|
|
4640
|
+
__heap_base: ___heap_base,
|
|
4641
|
+
/** @export */
|
|
4642
|
+
__indirect_function_table: wasmTable,
|
|
4643
|
+
/** @export */
|
|
4644
|
+
__memory_base: ___memory_base,
|
|
4645
|
+
/** @export */
|
|
4646
|
+
__stack_high: ___stack_high,
|
|
4647
|
+
/** @export */
|
|
4648
|
+
__stack_low: ___stack_low,
|
|
4649
|
+
/** @export */
|
|
4650
|
+
__stack_pointer: ___stack_pointer,
|
|
4651
|
+
/** @export */
|
|
4652
|
+
__syscall_fstat64: ___syscall_fstat64,
|
|
4653
|
+
/** @export */
|
|
4654
|
+
__syscall_getcwd: ___syscall_getcwd,
|
|
4655
|
+
/** @export */
|
|
4656
|
+
__syscall_lstat64: ___syscall_lstat64,
|
|
4657
|
+
/** @export */
|
|
4658
|
+
__syscall_newfstatat: ___syscall_newfstatat,
|
|
4659
|
+
/** @export */
|
|
4660
|
+
__syscall_stat64: ___syscall_stat64,
|
|
4661
|
+
/** @export */
|
|
4662
|
+
__table_base: ___table_base,
|
|
4663
|
+
/** @export */
|
|
4664
|
+
_abort_js: __abort_js,
|
|
4665
|
+
/** @export */
|
|
4666
|
+
emscripten_resize_heap: _emscripten_resize_heap,
|
|
4667
|
+
/** @export */
|
|
4668
|
+
environ_get: _environ_get,
|
|
4669
|
+
/** @export */
|
|
4670
|
+
environ_sizes_get: _environ_sizes_get,
|
|
4671
|
+
/** @export */
|
|
4672
|
+
fd_close: _fd_close,
|
|
4673
|
+
/** @export */
|
|
4674
|
+
fd_seek: _fd_seek,
|
|
4675
|
+
/** @export */
|
|
4676
|
+
fd_write: _fd_write,
|
|
4677
|
+
/** @export */
|
|
4678
|
+
memory: wasmMemory,
|
|
4679
|
+
/** @export */
|
|
4680
|
+
random_get: _random_get
|
|
4681
|
+
};
|
|
4682
|
+
var wasmExports;
|
|
4683
|
+
createWasm();
|
|
4684
|
+
var ___wasm_call_ctors = () => (___wasm_call_ctors = wasmExports['__wasm_call_ctors'])();
|
|
4685
|
+
var _wasm_alloc = Module['_wasm_alloc'] = (a0) => (_wasm_alloc = Module['_wasm_alloc'] = wasmExports['wasm_alloc'])(a0);
|
|
4686
|
+
var _wasm_ast_json = Module['_wasm_ast_json'] = (a0, a1) => (_wasm_ast_json = Module['_wasm_ast_json'] = wasmExports['wasm_ast_json'])(a0, a1);
|
|
4687
|
+
var _wasm_clear_all_cflags = Module['_wasm_clear_all_cflags'] = () => (_wasm_clear_all_cflags = Module['_wasm_clear_all_cflags'] = wasmExports['wasm_clear_all_cflags'])();
|
|
4688
|
+
var _wasm_clear_cflag = Module['_wasm_clear_cflag'] = (a0, a1) => (_wasm_clear_cflag = Module['_wasm_clear_cflag'] = wasmExports['wasm_clear_cflag'])(a0, a1);
|
|
4689
|
+
var _wasm_clear_dialect = Module['_wasm_clear_dialect'] = () => (_wasm_clear_dialect = Module['_wasm_clear_dialect'] = wasmExports['wasm_clear_dialect'])();
|
|
4690
|
+
var _wasm_clear_session_context = Module['_wasm_clear_session_context'] = () => (_wasm_clear_session_context = Module['_wasm_clear_session_context'] = wasmExports['wasm_clear_session_context'])();
|
|
4691
|
+
var _wasm_completions = Module['_wasm_completions'] = (a0, a1, a2, a3) => (_wasm_completions = Module['_wasm_completions'] = wasmExports['wasm_completions'])(a0, a1, a2, a3);
|
|
4692
|
+
var _wasm_diagnostics = Module['_wasm_diagnostics'] = (a0, a1, a2) => (_wasm_diagnostics = Module['_wasm_diagnostics'] = wasmExports['wasm_diagnostics'])(a0, a1, a2);
|
|
4693
|
+
var _wasm_extract = Module['_wasm_extract'] = (a0, a1) => (_wasm_extract = Module['_wasm_extract'] = wasmExports['wasm_extract'])(a0, a1);
|
|
4694
|
+
var _wasm_fmt = Module['_wasm_fmt'] = (a0, a1, a2, a3, a4, a5) => (_wasm_fmt = Module['_wasm_fmt'] = wasmExports['wasm_fmt'])(a0, a1, a2, a3, a4, a5);
|
|
4695
|
+
var _wasm_free = Module['_wasm_free'] = (a0, a1) => (_wasm_free = Module['_wasm_free'] = wasmExports['wasm_free'])(a0, a1);
|
|
4696
|
+
var _wasm_get_cflag_list = Module['_wasm_get_cflag_list'] = () => (_wasm_get_cflag_list = Module['_wasm_get_cflag_list'] = wasmExports['wasm_get_cflag_list'])();
|
|
4697
|
+
var _wasm_result_free = Module['_wasm_result_free'] = () => (_wasm_result_free = Module['_wasm_result_free'] = wasmExports['wasm_result_free'])();
|
|
4698
|
+
var _wasm_result_len = Module['_wasm_result_len'] = () => (_wasm_result_len = Module['_wasm_result_len'] = wasmExports['wasm_result_len'])();
|
|
4699
|
+
var _wasm_result_ptr = Module['_wasm_result_ptr'] = () => (_wasm_result_ptr = Module['_wasm_result_ptr'] = wasmExports['wasm_result_ptr'])();
|
|
4700
|
+
var _wasm_semantic_tokens = Module['_wasm_semantic_tokens'] = (a0, a1, a2, a3, a4) => (_wasm_semantic_tokens = Module['_wasm_semantic_tokens'] = wasmExports['wasm_semantic_tokens'])(a0, a1, a2, a3, a4);
|
|
4701
|
+
var _wasm_set_cflag = Module['_wasm_set_cflag'] = (a0, a1) => (_wasm_set_cflag = Module['_wasm_set_cflag'] = wasmExports['wasm_set_cflag'])(a0, a1);
|
|
4702
|
+
var _wasm_set_dialect = Module['_wasm_set_dialect'] = (a0) => (_wasm_set_dialect = Module['_wasm_set_dialect'] = wasmExports['wasm_set_dialect'])(a0);
|
|
4703
|
+
var _wasm_set_language_mode = Module['_wasm_set_language_mode'] = (a0) => (_wasm_set_language_mode = Module['_wasm_set_language_mode'] = wasmExports['wasm_set_language_mode'])(a0);
|
|
4704
|
+
var _wasm_set_session_context = Module['_wasm_set_session_context'] = (a0, a1) => (_wasm_set_session_context = Module['_wasm_set_session_context'] = wasmExports['wasm_set_session_context'])(a0, a1);
|
|
4705
|
+
var _wasm_set_session_context_ddl = Module['_wasm_set_session_context_ddl'] = (a0, a1) => (_wasm_set_session_context_ddl = Module['_wasm_set_session_context_ddl'] = wasmExports['wasm_set_session_context_ddl'])(a0, a1);
|
|
4706
|
+
var _wasm_set_sqlite_version = Module['_wasm_set_sqlite_version'] = (a0, a1) => (_wasm_set_sqlite_version = Module['_wasm_set_sqlite_version'] = wasmExports['wasm_set_sqlite_version'])(a0, a1);
|
|
4707
|
+
var _main = Module['_main'] = (a0, a1) => (_main = Module['_main'] = wasmExports['main'])(a0, a1);
|
|
4708
|
+
var _syntaqlite_analyzer_create_sqlite = Module['_syntaqlite_analyzer_create_sqlite'] = () => (_syntaqlite_analyzer_create_sqlite = Module['_syntaqlite_analyzer_create_sqlite'] = wasmExports['syntaqlite_analyzer_create_sqlite'])();
|
|
4709
|
+
var _syntaqlite_analyzer_create_with_dialect = Module['_syntaqlite_analyzer_create_with_dialect'] = (a0) => (_syntaqlite_analyzer_create_with_dialect = Module['_syntaqlite_analyzer_create_with_dialect'] = wasmExports['syntaqlite_analyzer_create_with_dialect'])(a0);
|
|
4710
|
+
var _syntaqlite_analyzer_destroy = Module['_syntaqlite_analyzer_destroy'] = (a0) => (_syntaqlite_analyzer_destroy = Module['_syntaqlite_analyzer_destroy'] = wasmExports['syntaqlite_analyzer_destroy'])(a0);
|
|
4711
|
+
var _syntaqlite_formatter_create_sqlite = Module['_syntaqlite_formatter_create_sqlite'] = () => (_syntaqlite_formatter_create_sqlite = Module['_syntaqlite_formatter_create_sqlite'] = wasmExports['syntaqlite_formatter_create_sqlite'])();
|
|
4712
|
+
var _syntaqlite_formatter_create_sqlite_with_config = Module['_syntaqlite_formatter_create_sqlite_with_config'] = (a0) => (_syntaqlite_formatter_create_sqlite_with_config = Module['_syntaqlite_formatter_create_sqlite_with_config'] = wasmExports['syntaqlite_formatter_create_sqlite_with_config'])(a0);
|
|
4713
|
+
var _syntaqlite_formatter_create_with_dialect = Module['_syntaqlite_formatter_create_with_dialect'] = (a0, a1) => (_syntaqlite_formatter_create_with_dialect = Module['_syntaqlite_formatter_create_with_dialect'] = wasmExports['syntaqlite_formatter_create_with_dialect'])(a0, a1);
|
|
4714
|
+
var _syntaqlite_formatter_destroy = Module['_syntaqlite_formatter_destroy'] = (a0) => (_syntaqlite_formatter_destroy = Module['_syntaqlite_formatter_destroy'] = wasmExports['syntaqlite_formatter_destroy'])(a0);
|
|
4715
|
+
var _syntaqlite_formatter_error_msg = Module['_syntaqlite_formatter_error_msg'] = (a0) => (_syntaqlite_formatter_error_msg = Module['_syntaqlite_formatter_error_msg'] = wasmExports['syntaqlite_formatter_error_msg'])(a0);
|
|
4716
|
+
var _syntaqlite_formatter_format = Module['_syntaqlite_formatter_format'] = (a0, a1, a2) => (_syntaqlite_formatter_format = Module['_syntaqlite_formatter_format'] = wasmExports['syntaqlite_formatter_format'])(a0, a1, a2);
|
|
4717
|
+
var _syntaqlite_formatter_output = Module['_syntaqlite_formatter_output'] = (a0) => (_syntaqlite_formatter_output = Module['_syntaqlite_formatter_output'] = wasmExports['syntaqlite_formatter_output'])(a0);
|
|
4718
|
+
var _syntaqlite_formatter_output_len = Module['_syntaqlite_formatter_output_len'] = (a0) => (_syntaqlite_formatter_output_len = Module['_syntaqlite_formatter_output_len'] = wasmExports['syntaqlite_formatter_output_len'])(a0);
|
|
4719
|
+
var _syntaqlite_string_destroy = Module['_syntaqlite_string_destroy'] = (a0) => (_syntaqlite_string_destroy = Module['_syntaqlite_string_destroy'] = wasmExports['syntaqlite_string_destroy'])(a0);
|
|
4720
|
+
var _syntaqlite_analyzer_add_function_overload = Module['_syntaqlite_analyzer_add_function_overload'] = (a0, a1, a2, a3, a4) => (_syntaqlite_analyzer_add_function_overload = Module['_syntaqlite_analyzer_add_function_overload'] = wasmExports['syntaqlite_analyzer_add_function_overload'])(a0, a1, a2, a3, a4);
|
|
4721
|
+
var _syntaqlite_analyzer_add_table_function = Module['_syntaqlite_analyzer_add_table_function'] = (a0, a1, a2, a3, a4, a5) => (_syntaqlite_analyzer_add_table_function = Module['_syntaqlite_analyzer_add_table_function'] = wasmExports['syntaqlite_analyzer_add_table_function'])(a0, a1, a2, a3, a4, a5);
|
|
4722
|
+
var _syntaqlite_analyzer_add_tables = Module['_syntaqlite_analyzer_add_tables'] = (a0, a1, a2) => (_syntaqlite_analyzer_add_tables = Module['_syntaqlite_analyzer_add_tables'] = wasmExports['syntaqlite_analyzer_add_tables'])(a0, a1, a2);
|
|
4723
|
+
var _syntaqlite_analyzer_add_views = Module['_syntaqlite_analyzer_add_views'] = (a0, a1, a2) => (_syntaqlite_analyzer_add_views = Module['_syntaqlite_analyzer_add_views'] = wasmExports['syntaqlite_analyzer_add_views'])(a0, a1, a2);
|
|
4724
|
+
var _syntaqlite_analyzer_load_schema_ddl = Module['_syntaqlite_analyzer_load_schema_ddl'] = (a0, a1, a2) => (_syntaqlite_analyzer_load_schema_ddl = Module['_syntaqlite_analyzer_load_schema_ddl'] = wasmExports['syntaqlite_analyzer_load_schema_ddl'])(a0, a1, a2);
|
|
4725
|
+
var _syntaqlite_analyzer_reset_catalog = Module['_syntaqlite_analyzer_reset_catalog'] = (a0) => (_syntaqlite_analyzer_reset_catalog = Module['_syntaqlite_analyzer_reset_catalog'] = wasmExports['syntaqlite_analyzer_reset_catalog'])(a0);
|
|
4726
|
+
var _syntaqlite_analyzer_analyze = Module['_syntaqlite_analyzer_analyze'] = (a0, a1, a2) => (_syntaqlite_analyzer_analyze = Module['_syntaqlite_analyzer_analyze'] = wasmExports['syntaqlite_analyzer_analyze'])(a0, a1, a2);
|
|
4727
|
+
var _syntaqlite_analyzer_column_lineage = Module['_syntaqlite_analyzer_column_lineage'] = (a0) => (_syntaqlite_analyzer_column_lineage = Module['_syntaqlite_analyzer_column_lineage'] = wasmExports['syntaqlite_analyzer_column_lineage'])(a0);
|
|
4728
|
+
var _syntaqlite_analyzer_column_lineage_count = Module['_syntaqlite_analyzer_column_lineage_count'] = (a0) => (_syntaqlite_analyzer_column_lineage_count = Module['_syntaqlite_analyzer_column_lineage_count'] = wasmExports['syntaqlite_analyzer_column_lineage_count'])(a0);
|
|
4729
|
+
var _syntaqlite_analyzer_diagnostic_count = Module['_syntaqlite_analyzer_diagnostic_count'] = (a0) => (_syntaqlite_analyzer_diagnostic_count = Module['_syntaqlite_analyzer_diagnostic_count'] = wasmExports['syntaqlite_analyzer_diagnostic_count'])(a0);
|
|
4730
|
+
var _syntaqlite_analyzer_diagnostics = Module['_syntaqlite_analyzer_diagnostics'] = (a0) => (_syntaqlite_analyzer_diagnostics = Module['_syntaqlite_analyzer_diagnostics'] = wasmExports['syntaqlite_analyzer_diagnostics'])(a0);
|
|
4731
|
+
var _syntaqlite_analyzer_lineage_complete = Module['_syntaqlite_analyzer_lineage_complete'] = (a0) => (_syntaqlite_analyzer_lineage_complete = Module['_syntaqlite_analyzer_lineage_complete'] = wasmExports['syntaqlite_analyzer_lineage_complete'])(a0);
|
|
4732
|
+
var _syntaqlite_analyzer_physical_table_count = Module['_syntaqlite_analyzer_physical_table_count'] = (a0) => (_syntaqlite_analyzer_physical_table_count = Module['_syntaqlite_analyzer_physical_table_count'] = wasmExports['syntaqlite_analyzer_physical_table_count'])(a0);
|
|
4733
|
+
var _syntaqlite_analyzer_physical_tables = Module['_syntaqlite_analyzer_physical_tables'] = (a0) => (_syntaqlite_analyzer_physical_tables = Module['_syntaqlite_analyzer_physical_tables'] = wasmExports['syntaqlite_analyzer_physical_tables'])(a0);
|
|
4734
|
+
var _syntaqlite_analyzer_relation_count = Module['_syntaqlite_analyzer_relation_count'] = (a0) => (_syntaqlite_analyzer_relation_count = Module['_syntaqlite_analyzer_relation_count'] = wasmExports['syntaqlite_analyzer_relation_count'])(a0);
|
|
4735
|
+
var _syntaqlite_analyzer_relations = Module['_syntaqlite_analyzer_relations'] = (a0) => (_syntaqlite_analyzer_relations = Module['_syntaqlite_analyzer_relations'] = wasmExports['syntaqlite_analyzer_relations'])(a0);
|
|
4736
|
+
var _syntaqlite_analyzer_render_diagnostics = Module['_syntaqlite_analyzer_render_diagnostics'] = (a0, a1) => (_syntaqlite_analyzer_render_diagnostics = Module['_syntaqlite_analyzer_render_diagnostics'] = wasmExports['syntaqlite_analyzer_render_diagnostics'])(a0, a1);
|
|
4737
|
+
var _syntaqlite_analyzer_unexpanded_view_count = Module['_syntaqlite_analyzer_unexpanded_view_count'] = (a0) => (_syntaqlite_analyzer_unexpanded_view_count = Module['_syntaqlite_analyzer_unexpanded_view_count'] = wasmExports['syntaqlite_analyzer_unexpanded_view_count'])(a0);
|
|
4738
|
+
var _syntaqlite_analyzer_unexpanded_views = Module['_syntaqlite_analyzer_unexpanded_views'] = (a0) => (_syntaqlite_analyzer_unexpanded_views = Module['_syntaqlite_analyzer_unexpanded_views'] = wasmExports['syntaqlite_analyzer_unexpanded_views'])(a0);
|
|
4739
|
+
var _syntaqlite_analyzer_set_check_level = Module['_syntaqlite_analyzer_set_check_level'] = (a0, a1, a2) => (_syntaqlite_analyzer_set_check_level = Module['_syntaqlite_analyzer_set_check_level'] = wasmExports['syntaqlite_analyzer_set_check_level'])(a0, a1, a2);
|
|
4740
|
+
var _syntaqlite_analyzer_set_mode = Module['_syntaqlite_analyzer_set_mode'] = (a0, a1) => (_syntaqlite_analyzer_set_mode = Module['_syntaqlite_analyzer_set_mode'] = wasmExports['syntaqlite_analyzer_set_mode'])(a0, a1);
|
|
4741
|
+
var _syntaqlite_analyzer_set_module_resolver = Module['_syntaqlite_analyzer_set_module_resolver'] = (a0, a1, a2) => (_syntaqlite_analyzer_set_module_resolver = Module['_syntaqlite_analyzer_set_module_resolver'] = wasmExports['syntaqlite_analyzer_set_module_resolver'])(a0, a1, a2);
|
|
4742
|
+
var _syntaqlite_analyzer_set_strict_schema = Module['_syntaqlite_analyzer_set_strict_schema'] = (a0, a1) => (_syntaqlite_analyzer_set_strict_schema = Module['_syntaqlite_analyzer_set_strict_schema'] = wasmExports['syntaqlite_analyzer_set_strict_schema'])(a0, a1);
|
|
4743
|
+
var _syntaqlite_analyzer_set_suggestion_threshold = Module['_syntaqlite_analyzer_set_suggestion_threshold'] = (a0, a1) => (_syntaqlite_analyzer_set_suggestion_threshold = Module['_syntaqlite_analyzer_set_suggestion_threshold'] = wasmExports['syntaqlite_analyzer_set_suggestion_threshold'])(a0, a1);
|
|
4744
|
+
var _syntaqlite_analyzer_statement_column_lineage = Module['_syntaqlite_analyzer_statement_column_lineage'] = (a0, a1) => (_syntaqlite_analyzer_statement_column_lineage = Module['_syntaqlite_analyzer_statement_column_lineage'] = wasmExports['syntaqlite_analyzer_statement_column_lineage'])(a0, a1);
|
|
4745
|
+
var _syntaqlite_analyzer_statement_column_lineage_count = Module['_syntaqlite_analyzer_statement_column_lineage_count'] = (a0, a1) => (_syntaqlite_analyzer_statement_column_lineage_count = Module['_syntaqlite_analyzer_statement_column_lineage_count'] = wasmExports['syntaqlite_analyzer_statement_column_lineage_count'])(a0, a1);
|
|
4746
|
+
var _syntaqlite_analyzer_statement_count = Module['_syntaqlite_analyzer_statement_count'] = (a0) => (_syntaqlite_analyzer_statement_count = Module['_syntaqlite_analyzer_statement_count'] = wasmExports['syntaqlite_analyzer_statement_count'])(a0);
|
|
4747
|
+
var _syntaqlite_analyzer_statement_defined_relation_count = Module['_syntaqlite_analyzer_statement_defined_relation_count'] = (a0, a1) => (_syntaqlite_analyzer_statement_defined_relation_count = Module['_syntaqlite_analyzer_statement_defined_relation_count'] = wasmExports['syntaqlite_analyzer_statement_defined_relation_count'])(a0, a1);
|
|
4748
|
+
var _syntaqlite_analyzer_statement_defined_relations = Module['_syntaqlite_analyzer_statement_defined_relations'] = (a0, a1) => (_syntaqlite_analyzer_statement_defined_relations = Module['_syntaqlite_analyzer_statement_defined_relations'] = wasmExports['syntaqlite_analyzer_statement_defined_relations'])(a0, a1);
|
|
4749
|
+
var _syntaqlite_analyzer_statement_diagnostic_count = Module['_syntaqlite_analyzer_statement_diagnostic_count'] = (a0, a1) => (_syntaqlite_analyzer_statement_diagnostic_count = Module['_syntaqlite_analyzer_statement_diagnostic_count'] = wasmExports['syntaqlite_analyzer_statement_diagnostic_count'])(a0, a1);
|
|
4750
|
+
var _syntaqlite_analyzer_statement_diagnostics = Module['_syntaqlite_analyzer_statement_diagnostics'] = (a0, a1) => (_syntaqlite_analyzer_statement_diagnostics = Module['_syntaqlite_analyzer_statement_diagnostics'] = wasmExports['syntaqlite_analyzer_statement_diagnostics'])(a0, a1);
|
|
4751
|
+
var _syntaqlite_analyzer_statement_physical_table_count = Module['_syntaqlite_analyzer_statement_physical_table_count'] = (a0, a1) => (_syntaqlite_analyzer_statement_physical_table_count = Module['_syntaqlite_analyzer_statement_physical_table_count'] = wasmExports['syntaqlite_analyzer_statement_physical_table_count'])(a0, a1);
|
|
4752
|
+
var _syntaqlite_analyzer_statement_physical_tables = Module['_syntaqlite_analyzer_statement_physical_tables'] = (a0, a1) => (_syntaqlite_analyzer_statement_physical_tables = Module['_syntaqlite_analyzer_statement_physical_tables'] = wasmExports['syntaqlite_analyzer_statement_physical_tables'])(a0, a1);
|
|
4753
|
+
var _syntaqlite_analyzer_statement_relation_count = Module['_syntaqlite_analyzer_statement_relation_count'] = (a0, a1) => (_syntaqlite_analyzer_statement_relation_count = Module['_syntaqlite_analyzer_statement_relation_count'] = wasmExports['syntaqlite_analyzer_statement_relation_count'])(a0, a1);
|
|
4754
|
+
var _syntaqlite_analyzer_statement_relations = Module['_syntaqlite_analyzer_statement_relations'] = (a0, a1) => (_syntaqlite_analyzer_statement_relations = Module['_syntaqlite_analyzer_statement_relations'] = wasmExports['syntaqlite_analyzer_statement_relations'])(a0, a1);
|
|
4755
|
+
var _syntaqlite_analyzer_statement_source = Module['_syntaqlite_analyzer_statement_source'] = (a0, a1) => (_syntaqlite_analyzer_statement_source = Module['_syntaqlite_analyzer_statement_source'] = wasmExports['syntaqlite_analyzer_statement_source'])(a0, a1);
|
|
4756
|
+
var _syntaqlite_analyzer_statement_unexpanded_view_count = Module['_syntaqlite_analyzer_statement_unexpanded_view_count'] = (a0, a1) => (_syntaqlite_analyzer_statement_unexpanded_view_count = Module['_syntaqlite_analyzer_statement_unexpanded_view_count'] = wasmExports['syntaqlite_analyzer_statement_unexpanded_view_count'])(a0, a1);
|
|
4757
|
+
var _syntaqlite_analyzer_statement_unexpanded_views = Module['_syntaqlite_analyzer_statement_unexpanded_views'] = (a0, a1) => (_syntaqlite_analyzer_statement_unexpanded_views = Module['_syntaqlite_analyzer_statement_unexpanded_views'] = wasmExports['syntaqlite_analyzer_statement_unexpanded_views'])(a0, a1);
|
|
4758
|
+
var _malloc = (a0) => (_malloc = wasmExports['malloc'])(a0);
|
|
4759
|
+
var _synq_extent_on_shift = Module['_synq_extent_on_shift'] = (a0, a1, a2) => (_synq_extent_on_shift = Module['_synq_extent_on_shift'] = wasmExports['synq_extent_on_shift'])(a0, a1, a2);
|
|
4760
|
+
var _synq_extent_on_reduce = Module['_synq_extent_on_reduce'] = (a0, a1) => (_synq_extent_on_reduce = Module['_synq_extent_on_reduce'] = wasmExports['synq_extent_on_reduce'])(a0, a1);
|
|
4761
|
+
var _calloc = (a0, a1) => (_calloc = wasmExports['calloc'])(a0, a1);
|
|
4762
|
+
var ___dl_seterr = (a0, a1) => (___dl_seterr = wasmExports['__dl_seterr'])(a0, a1);
|
|
4763
|
+
var __emscripten_find_dylib = (a0, a1, a2, a3) => (__emscripten_find_dylib = wasmExports['_emscripten_find_dylib'])(a0, a1, a2, a3);
|
|
4764
|
+
var _htonl = (a0) => (_htonl = wasmExports['htonl'])(a0);
|
|
4765
|
+
var _htons = (a0) => (_htons = wasmExports['htons'])(a0);
|
|
4766
|
+
var _ntohs = (a0) => (_ntohs = wasmExports['ntohs'])(a0);
|
|
4767
|
+
var ___trap = () => (___trap = wasmExports['__trap'])();
|
|
4768
|
+
var __emscripten_stack_restore = (a0) => (__emscripten_stack_restore = wasmExports['_emscripten_stack_restore'])(a0);
|
|
4769
|
+
var __emscripten_stack_alloc = (a0) => (__emscripten_stack_alloc = wasmExports['_emscripten_stack_alloc'])(a0);
|
|
4770
|
+
var _emscripten_stack_get_current = () => (_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'])();
|
|
4771
|
+
var ___wasm_apply_data_relocs = () => (___wasm_apply_data_relocs = wasmExports['__wasm_apply_data_relocs'])();
|
|
4772
|
+
|
|
4773
|
+
|
|
4774
|
+
// include: postamble.js
|
|
4775
|
+
// === Auto-generated postamble setup entry stuff ===
|
|
4776
|
+
|
|
4777
|
+
function callMain(args = []) {
|
|
4778
|
+
|
|
4779
|
+
var entryFunction = resolveGlobalSymbol('main').sym;;
|
|
4780
|
+
|
|
4781
|
+
// Main modules can't tell if they have main() at compile time, since it may
|
|
4782
|
+
// arrive from a dynamic library.
|
|
4783
|
+
if (!entryFunction) return;
|
|
4784
|
+
|
|
4785
|
+
args.unshift(thisProgram);
|
|
4786
|
+
|
|
4787
|
+
var argc = args.length;
|
|
4788
|
+
var argv = stackAlloc((argc + 1) * 4);
|
|
4789
|
+
var argv_ptr = argv;
|
|
4790
|
+
args.forEach((arg) => {
|
|
4791
|
+
HEAPU32[((argv_ptr)>>2)] = stringToUTF8OnStack(arg);
|
|
4792
|
+
argv_ptr += 4;
|
|
4793
|
+
});
|
|
4794
|
+
HEAPU32[((argv_ptr)>>2)] = 0;
|
|
4795
|
+
|
|
4796
|
+
try {
|
|
4797
|
+
|
|
4798
|
+
var ret = entryFunction(argc, argv);
|
|
4799
|
+
|
|
4800
|
+
// if we're not running an evented main loop, it's time to exit
|
|
4801
|
+
exitJS(ret, /* implicit = */ true);
|
|
4802
|
+
return ret;
|
|
4803
|
+
} catch (e) {
|
|
4804
|
+
return handleException(e);
|
|
4805
|
+
}
|
|
4806
|
+
}
|
|
4807
|
+
|
|
4808
|
+
function run(args = arguments_) {
|
|
4809
|
+
|
|
4810
|
+
if (runDependencies > 0) {
|
|
4811
|
+
dependenciesFulfilled = run;
|
|
4812
|
+
return;
|
|
4813
|
+
}
|
|
4814
|
+
|
|
4815
|
+
preRun();
|
|
4816
|
+
|
|
4817
|
+
// a preRun added a dependency, run will be called later
|
|
4818
|
+
if (runDependencies > 0) {
|
|
4819
|
+
dependenciesFulfilled = run;
|
|
4820
|
+
return;
|
|
4821
|
+
}
|
|
4822
|
+
|
|
4823
|
+
function doRun() {
|
|
4824
|
+
// run may have just been called through dependencies being fulfilled just in this very frame,
|
|
4825
|
+
// or while the async setStatus time below was happening
|
|
4826
|
+
Module['calledRun'] = true;
|
|
4827
|
+
|
|
4828
|
+
if (ABORT) return;
|
|
4829
|
+
|
|
4830
|
+
initRuntime();
|
|
4831
|
+
|
|
4832
|
+
preMain();
|
|
4833
|
+
|
|
4834
|
+
Module['onRuntimeInitialized']?.();
|
|
4835
|
+
|
|
4836
|
+
var noInitialRun = Module['noInitialRun'] || false;
|
|
4837
|
+
if (!noInitialRun) callMain(args);
|
|
4838
|
+
|
|
4839
|
+
postRun();
|
|
4840
|
+
}
|
|
4841
|
+
|
|
4842
|
+
if (Module['setStatus']) {
|
|
4843
|
+
Module['setStatus']('Running...');
|
|
4844
|
+
setTimeout(() => {
|
|
4845
|
+
setTimeout(() => Module['setStatus'](''), 1);
|
|
4846
|
+
doRun();
|
|
4847
|
+
}, 1);
|
|
4848
|
+
} else
|
|
4849
|
+
{
|
|
4850
|
+
doRun();
|
|
4851
|
+
}
|
|
4852
|
+
}
|
|
4853
|
+
|
|
4854
|
+
function preInit() {
|
|
4855
|
+
if (Module['preInit']) {
|
|
4856
|
+
if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
|
|
4857
|
+
while (Module['preInit'].length > 0) {
|
|
4858
|
+
Module['preInit'].shift()();
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
}
|
|
4862
|
+
|
|
4863
|
+
preInit();
|
|
4864
|
+
run();
|
|
4865
|
+
|
|
4866
|
+
// end include: postamble.js
|
|
4867
|
+
|