@gen3/workspaces 0.12.64 → 0.12.66

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.
Files changed (103) hide show
  1. package/TODO.md +6 -7
  2. package/dist/jupyterlite-builds/free-private/jupyter_lite_config.json +5 -19
  3. package/dist/jupyterlite-builds/free-private/requirements.txt +1 -1
  4. package/dist/jupyterlite-builds/remote-private/overrides.json +16 -0
  5. package/dist/jupyterlite-builds/scripts/build-gen3sdk-lite.sh +428 -0
  6. package/dist/jupyterlite-builds/scripts/build-jupyterlite.sh +150 -33
  7. package/dist/jupyterlite-builds/scripts/setup-env.sh +81 -0
  8. package/dist/jupyterlite-builds/scripts/sync-jupyter-assets-into-package.sh +19 -2
  9. package/dist/jupyterlite-builds/scripts/validate-jupyterlite-assets.sh +3 -0
  10. package/jupyterlite-builds/free-private/jupyter_lite_config.json +5 -19
  11. package/jupyterlite-builds/free-private/requirements.txt +1 -1
  12. package/jupyterlite-builds/remote-private/overrides.json +16 -0
  13. package/package.json +5 -3
  14. package/scripts/build-gen3sdk-lite.sh +428 -0
  15. package/scripts/build-jupyterlite.sh +150 -33
  16. package/scripts/patch-pyidode-lock.py +100 -0
  17. package/scripts/setup-env.sh +81 -0
  18. package/scripts/sync-jupyter-assets-into-package.sh +19 -2
  19. package/scripts/validate-jupyterlite-assets.sh +3 -0
  20. package/.jupyterlite.doit.db +0 -0
  21. package/dist/jupyterlite-builds/scripts/build-gen3sdk-lite_v2.sh +0 -310
  22. package/dist/jupyterlite-builds/scripts/build-jupyterlite_v2.sh +0 -111
  23. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/aiofiles-25.1.0-py3-none-any.whl +0 -0
  24. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/backoff-2.2.1-py3-none-any.whl +0 -0
  25. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/cdislogging-1.2.0-py3-none-any.whl +0 -0
  26. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/comm-0.2.3-py3-none-any.whl +0 -0
  27. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/dataclasses_json-0.5.9-py3-none-any.whl +0 -0
  28. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/dictionaryutils-4.0.0-py3-none-any.whl +0 -0
  29. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/drsclient-0.4.0-py3-none-any.whl +0 -0
  30. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/fastavro-1.12.2-py3-none-any.whl +0 -0
  31. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/gen3-4.28.3-py3-none-any.whl +0 -0
  32. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/gen3dictionary-3.0.0-py3-none-any.whl +0 -0
  33. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/gen3users-1.1.1-py3-none-any.whl +0 -0
  34. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/humanfriendly-10.0-py2.py3-none-any.whl +0 -0
  35. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/importlib_metadata-8.9.0-py3-none-any.whl +0 -0
  36. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/indexclient-6.3.0-py3-none-any.whl +0 -0
  37. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/ipykernel-6.9.2-py3-none-any.whl +0 -0
  38. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/ipython_pygments_lexers-1.1.1-py3-none-any.whl +0 -0
  39. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/marshmallow-3.26.2-py3-none-any.whl +0 -0
  40. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/marshmallow_enum-1.5.1-py2.py3-none-any.whl +0 -0
  41. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/mypy_extensions-1.1.0-py3-none-any.whl +0 -0
  42. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/piplite-0.8.5-py3-none-any.whl +0 -0
  43. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/pyodide_http-0.2.2-py3-none-any.whl +0 -0
  44. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/pyodide_kernel-0.8.5-py3-none-any.whl +0 -0
  45. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/pypfb-0.6.2-py3-none-any.whl +0 -0
  46. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/python_dateutil-2.9.0.post0-py2.py3-none-any.whl +0 -0
  47. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/python_json_logger-4.2.0-py3-none-any.whl +0 -0
  48. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/typing_inspect-0.9.0-py3-none-any.whl +0 -0
  49. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/xmltodict-0.13.0-py2.py3-none-any.whl +0 -0
  50. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/zipp-4.1.0-py3-none-any.whl +0 -0
  51. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_work/constraints.txt +0 -354
  52. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_work/excludes.txt +0 -3
  53. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_work/pylock.toml +0 -347
  54. package/jupyterlite-builds/free-private/.cache/pyodide-lock/_work/requirements.in +0 -26
  55. package/jupyterlite-builds/free-private/.cache/pyodide-lock/patched-pyodide-lock.json +0 -1
  56. package/jupyterlite-builds/free-private/.cache/pyodide-lock/pyodide-lock.json +0 -1
  57. package/jupyterlite-builds/free-private/.cache/pyodide-lock/remote-pyodide-lock.json +0 -1
  58. package/jupyterlite-builds/free-private/.cache/wheels/aiofiles-25.1.0-py3-none-any.whl.meta.json +0 -24
  59. package/jupyterlite-builds/free-private/.cache/wheels/backoff-2.2.1-py3-none-any.whl.meta.json +0 -24
  60. package/jupyterlite-builds/free-private/.cache/wheels/cdislogging-1.2.0-py3-none-any.whl.meta.json +0 -24
  61. package/jupyterlite-builds/free-private/.cache/wheels/dataclasses_json-0.5.9-py3-none-any.whl.meta.json +0 -24
  62. package/jupyterlite-builds/free-private/.cache/wheels/dictionaryutils-4.0.0-py3-none-any.whl.meta.json +0 -24
  63. package/jupyterlite-builds/free-private/.cache/wheels/drsclient-0.4.0-py3-none-any.whl.meta.json +0 -24
  64. package/jupyterlite-builds/free-private/.cache/wheels/fastavro-1.12.2-py3-none-any.whl.meta.json +0 -24
  65. package/jupyterlite-builds/free-private/.cache/wheels/gen3-4.28.3-py3-none-any.whl.meta.json +0 -24
  66. package/jupyterlite-builds/free-private/.cache/wheels/gen3dictionary-3.0.0-py3-none-any.whl.meta.json +0 -24
  67. package/jupyterlite-builds/free-private/.cache/wheels/gen3users-1.1.1-py3-none-any.whl.meta.json +0 -24
  68. package/jupyterlite-builds/free-private/.cache/wheels/humanfriendly-10.0-py2.py3-none-any.whl.meta.json +0 -24
  69. package/jupyterlite-builds/free-private/.cache/wheels/importlib_metadata-8.9.0-py3-none-any.whl.meta.json +0 -24
  70. package/jupyterlite-builds/free-private/.cache/wheels/indexclient-6.3.0-py3-none-any.whl.meta.json +0 -24
  71. package/jupyterlite-builds/free-private/.cache/wheels/marshmallow-3.26.2-py3-none-any.whl.meta.json +0 -24
  72. package/jupyterlite-builds/free-private/.cache/wheels/marshmallow_enum-1.5.1-py2.py3-none-any.whl.meta.json +0 -24
  73. package/jupyterlite-builds/free-private/.cache/wheels/mypy_extensions-1.1.0-py3-none-any.whl.meta.json +0 -24
  74. package/jupyterlite-builds/free-private/.cache/wheels/pypfb-0.6.2-py3-none-any.whl.meta.json +0 -24
  75. package/jupyterlite-builds/free-private/.cache/wheels/python_dateutil-2.9.0.post0-py2.py3-none-any.whl.meta.json +0 -24
  76. package/jupyterlite-builds/free-private/.cache/wheels/python_json_logger-4.2.0-py3-none-any.whl.meta.json +0 -24
  77. package/jupyterlite-builds/free-private/.cache/wheels/typing_inspect-0.9.0-py3-none-any.whl.meta.json +0 -24
  78. package/jupyterlite-builds/free-private/.cache/wheels/xmltodict-0.13.0-py2.py3-none-any.whl.meta.json +0 -24
  79. package/jupyterlite-builds/free-private/.cache/wheels/zipp-4.1.0-py3-none-any.whl.meta.json +0 -24
  80. package/jupyterlite-builds/free-private/cockle-config.json +0 -71
  81. package/jupyterlite-builds/free-private/cockle_wasm_env/.mambarc +0 -1
  82. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/coreutils.js +0 -5421
  83. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/coreutils.wasm +0 -0
  84. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/fs.d.ts +0 -375
  85. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/fs.js +0 -3401
  86. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/fs.wasm +0 -0
  87. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/grep.js +0 -3839
  88. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/grep.wasm +0 -0
  89. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/less.data +0 -0
  90. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/less.js +0 -5060
  91. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/less.wasm +0 -0
  92. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/sed.js +0 -3843
  93. package/jupyterlite-builds/free-private/cockle_wasm_env/bin/sed.wasm +0 -0
  94. package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/cockle_fs-0.3.0-h27506cd_2.json +0 -60
  95. package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/coreutils-9.10-h072c4ef_3.json +0 -52
  96. package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/emscripten-abi-4.0.9-h267e887_9.json +0 -31
  97. package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/grep-3.12-h8b79025_0.json +0 -52
  98. package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/history +0 -10
  99. package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/less-693-hf259948_0.json +0 -60
  100. package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/sed-4.9-h072c4ef_0.json +0 -52
  101. package/scripts/aiohttp-3.13.5-cp314-cp314-pyemscripten_2026_0_wasm32.whl +0 -0
  102. package/scripts/build-gen3sdk-lite_v2.sh +0 -310
  103. package/scripts/build-jupyterlite_v2.sh +0 -111
@@ -1,3843 +0,0 @@
1
- var Module = (() => {
2
- var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
3
- return (
4
- async function(moduleArg = {}) {
5
- var moduleRtn;
6
-
7
- // include: shell.js
8
- // The Module object: Our interface to the outside world. We import
9
- // and export values on it. There are various ways Module can be used:
10
- // 1. Not defined. We create it here
11
- // 2. A function parameter, function(moduleArg) => Promise<Module>
12
- // 3. pre-run appended it, var Module = {}; ..generated code..
13
- // 4. External script tag defines var Module.
14
- // We need to check if Module already exists (e.g. case 3 above).
15
- // Substitution will be replaced with actual code on later stage of the build,
16
- // this way Closure Compiler will not mangle it (e.g. case 4. above).
17
- // Note that if you want to run closure, and also to use Module
18
- // after the generated code, you will need to define var Module = {};
19
- // before the code. Then that object will be used in the code, and you
20
- // can continue to use Module afterwards as well.
21
- var Module = moduleArg;
22
-
23
- // Set up the promise that indicates the Module is initialized
24
- var readyPromiseResolve, readyPromiseReject;
25
-
26
- var readyPromise = new Promise((resolve, reject) => {
27
- readyPromiseResolve = resolve;
28
- readyPromiseReject = reject;
29
- });
30
-
31
- // Determine the runtime environment we are in. You can customize this by
32
- // setting the ENVIRONMENT setting at compile time (see settings.js).
33
- // Attempt to auto-detect the environment
34
- var ENVIRONMENT_IS_WEB = typeof window == "object";
35
-
36
- var ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != "undefined";
37
-
38
- // N.b. Electron.js environment is simultaneously a NODE-environment, but
39
- // also a web environment.
40
- var ENVIRONMENT_IS_NODE = typeof process == "object" && process.versions?.node && process.type != "renderer";
41
-
42
- if (ENVIRONMENT_IS_NODE) {}
43
-
44
- // --pre-jses are emitted after the Module integration code, so that they can
45
- // refer to Module (if they choose; they can also define Module)
46
- var arguments_ = [];
47
-
48
- var thisProgram = "./this.program";
49
-
50
- var quit_ = (status, toThrow) => {
51
- throw toThrow;
52
- };
53
-
54
- if (typeof __filename != "undefined") {
55
- // Node
56
- _scriptName = __filename;
57
- } else if (ENVIRONMENT_IS_WORKER) {
58
- _scriptName = self.location.href;
59
- }
60
-
61
- // `/` should be present at the end if `scriptDirectory` is not empty
62
- var scriptDirectory = "";
63
-
64
- function locateFile(path) {
65
- if (Module["locateFile"]) {
66
- return Module["locateFile"](path, scriptDirectory);
67
- }
68
- return scriptDirectory + path;
69
- }
70
-
71
- // Hooks that are implemented differently in different runtime environments.
72
- var readAsync, readBinary;
73
-
74
- if (ENVIRONMENT_IS_NODE) {
75
- // These modules will usually be used on Node.js. Load them eagerly to avoid
76
- // the complexity of lazy-loading.
77
- var fs = require("fs");
78
- var nodePath = require("path");
79
- scriptDirectory = __dirname + "/";
80
- // include: node_shell_read.js
81
- readBinary = filename => {
82
- // We need to re-wrap `file://` strings to URLs.
83
- filename = isFileURI(filename) ? new URL(filename) : filename;
84
- var ret = fs.readFileSync(filename);
85
- return ret;
86
- };
87
- readAsync = async (filename, binary = true) => {
88
- // See the comment in the `readBinary` function.
89
- filename = isFileURI(filename) ? new URL(filename) : filename;
90
- var ret = fs.readFileSync(filename, binary ? undefined : "utf8");
91
- return ret;
92
- };
93
- // end include: node_shell_read.js
94
- if (process.argv.length > 1) {
95
- thisProgram = process.argv[1].replace(/\\/g, "/");
96
- }
97
- arguments_ = process.argv.slice(2);
98
- quit_ = (status, toThrow) => {
99
- process.exitCode = status;
100
- throw toThrow;
101
- };
102
- } else // Note that this includes Node.js workers when relevant (pthreads is enabled).
103
- // Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
104
- // ENVIRONMENT_IS_NODE.
105
- if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
106
- try {
107
- scriptDirectory = new URL(".", _scriptName).href;
108
- } catch {}
109
- {
110
- // include: web_or_worker_shell_read.js
111
- if (ENVIRONMENT_IS_WORKER) {
112
- readBinary = url => {
113
- var xhr = new XMLHttpRequest;
114
- xhr.open("GET", url, false);
115
- xhr.responseType = "arraybuffer";
116
- xhr.send(null);
117
- return new Uint8Array(/** @type{!ArrayBuffer} */ (xhr.response));
118
- };
119
- }
120
- readAsync = async url => {
121
- // Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
122
- // See https://github.com/github/fetch/pull/92#issuecomment-140665932
123
- // Cordova or Electron apps are typically loaded from a file:// url.
124
- // So use XHR on webview if URL is a file URL.
125
- if (isFileURI(url)) {
126
- return new Promise((resolve, reject) => {
127
- var xhr = new XMLHttpRequest;
128
- xhr.open("GET", url, true);
129
- xhr.responseType = "arraybuffer";
130
- xhr.onload = () => {
131
- if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) {
132
- // file URLs can return 0
133
- resolve(xhr.response);
134
- return;
135
- }
136
- reject(xhr.status);
137
- };
138
- xhr.onerror = reject;
139
- xhr.send(null);
140
- });
141
- }
142
- var response = await fetch(url, {
143
- credentials: "same-origin"
144
- });
145
- if (response.ok) {
146
- return response.arrayBuffer();
147
- }
148
- throw new Error(response.status + " : " + response.url);
149
- };
150
- }
151
- } else {}
152
-
153
- var out = console.log.bind(console);
154
-
155
- var err = console.error.bind(console);
156
-
157
- // end include: shell.js
158
- // include: preamble.js
159
- // === Preamble library stuff ===
160
- // Documentation for the public APIs defined in this file must be updated in:
161
- // site/source/docs/api_reference/preamble.js.rst
162
- // A prebuilt local version of the documentation is available at:
163
- // site/build/text/docs/api_reference/preamble.js.txt
164
- // You can also build docs locally as HTML or other formats in site/
165
- // An online HTML version (which may be of a different version of Emscripten)
166
- // is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
167
- var wasmBinary;
168
-
169
- // Wasm globals
170
- var wasmMemory;
171
-
172
- //========================================
173
- // Runtime essentials
174
- //========================================
175
- // whether we are quitting the application. no code should run after this.
176
- // set in exit() and abort()
177
- var ABORT = false;
178
-
179
- // set by exit() and abort(). Passed to 'onExit' handler.
180
- // NOTE: This is also used as the process return code code in shell environments
181
- // but only when noExitRuntime is false.
182
- var EXITSTATUS;
183
-
184
- // Memory management
185
- var /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /* BigInt64Array type is not correctly defined in closure
186
- /** not-@type {!BigInt64Array} */ HEAP64, /* BigUint64Array type is not correctly defined in closure
187
- /** not-t@type {!BigUint64Array} */ HEAPU64, /** @type {!Float64Array} */ HEAPF64;
188
-
189
- var runtimeInitialized = false;
190
-
191
- var runtimeExited = false;
192
-
193
- /**
194
- * Indicates whether filename is delivered via file protocol (as opposed to http/https)
195
- * @noinline
196
- */ var isFileURI = filename => filename.startsWith("file://");
197
-
198
- // include: runtime_shared.js
199
- // include: runtime_stack_check.js
200
- // end include: runtime_stack_check.js
201
- // include: runtime_exceptions.js
202
- // end include: runtime_exceptions.js
203
- // include: runtime_debug.js
204
- // end include: runtime_debug.js
205
- // include: memoryprofiler.js
206
- // end include: memoryprofiler.js
207
- function updateMemoryViews() {
208
- var b = wasmMemory.buffer;
209
- HEAP8 = new Int8Array(b);
210
- HEAP16 = new Int16Array(b);
211
- HEAPU8 = new Uint8Array(b);
212
- HEAPU16 = new Uint16Array(b);
213
- HEAP32 = new Int32Array(b);
214
- HEAPU32 = new Uint32Array(b);
215
- HEAPF32 = new Float32Array(b);
216
- HEAPF64 = new Float64Array(b);
217
- HEAP64 = new BigInt64Array(b);
218
- HEAPU64 = new BigUint64Array(b);
219
- }
220
-
221
- // end include: runtime_shared.js
222
- function preRun() {
223
- if (Module["preRun"]) {
224
- if (typeof Module["preRun"] == "function") Module["preRun"] = [ Module["preRun"] ];
225
- while (Module["preRun"].length) {
226
- addOnPreRun(Module["preRun"].shift());
227
- }
228
- }
229
- // Begin ATPRERUNS hooks
230
- callRuntimeCallbacks(onPreRuns);
231
- }
232
-
233
- function initRuntime() {
234
- runtimeInitialized = true;
235
- // Begin ATINITS hooks
236
- if (!Module["noFSInit"] && !FS.initialized) FS.init();
237
- TTY.init();
238
- // End ATINITS hooks
239
- wasmExports["z"]();
240
- // Begin ATPOSTCTORS hooks
241
- FS.ignorePermissions = false;
242
- }
243
-
244
- function preMain() {}
245
-
246
- function exitRuntime() {
247
- // PThreads reuse the runtime from the main thread.
248
- ___funcs_on_exit();
249
- // Native atexit() functions
250
- // Begin ATEXITS hooks
251
- FS.quit();
252
- TTY.shutdown();
253
- // End ATEXITS hooks
254
- runtimeExited = true;
255
- }
256
-
257
- function postRun() {
258
- // PThreads reuse the runtime from the main thread.
259
- if (Module["postRun"]) {
260
- if (typeof Module["postRun"] == "function") Module["postRun"] = [ Module["postRun"] ];
261
- while (Module["postRun"].length) {
262
- addOnPostRun(Module["postRun"].shift());
263
- }
264
- }
265
- // Begin ATPOSTRUNS hooks
266
- callRuntimeCallbacks(onPostRuns);
267
- }
268
-
269
- // A counter of dependencies for calling run(). If we need to
270
- // do asynchronous work before running, increment this and
271
- // decrement it. Incrementing must happen in a place like
272
- // Module.preRun (used by emcc to add file preloading).
273
- // Note that you can add dependencies in preRun, even though
274
- // it happens right before run - run will be postponed until
275
- // the dependencies are met.
276
- var runDependencies = 0;
277
-
278
- var dependenciesFulfilled = null;
279
-
280
- // overridden to take different actions when all run dependencies are fulfilled
281
- function getUniqueRunDependency(id) {
282
- return id;
283
- }
284
-
285
- function addRunDependency(id) {
286
- runDependencies++;
287
- Module["monitorRunDependencies"]?.(runDependencies);
288
- }
289
-
290
- function removeRunDependency(id) {
291
- runDependencies--;
292
- Module["monitorRunDependencies"]?.(runDependencies);
293
- if (runDependencies == 0) {
294
- if (dependenciesFulfilled) {
295
- var callback = dependenciesFulfilled;
296
- dependenciesFulfilled = null;
297
- callback();
298
- }
299
- }
300
- }
301
-
302
- /** @param {string|number=} what */ function abort(what) {
303
- Module["onAbort"]?.(what);
304
- what = "Aborted(" + what + ")";
305
- // TODO(sbc): Should we remove printing and leave it up to whoever
306
- // catches the exception?
307
- err(what);
308
- ABORT = true;
309
- what += ". Build with -sASSERTIONS for more info.";
310
- // Use a wasm runtime error, because a JS error might be seen as a foreign
311
- // exception, which means we'd run destructors on it. We need the error to
312
- // simply make the program stop.
313
- // FIXME This approach does not work in Wasm EH because it currently does not assume
314
- // all RuntimeErrors are from traps; it decides whether a RuntimeError is from
315
- // a trap or not based on a hidden field within the object. So at the moment
316
- // we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that
317
- // allows this in the wasm spec.
318
- // Suppress closure compiler warning here. Closure compiler's builtin extern
319
- // definition for WebAssembly.RuntimeError claims it takes no arguments even
320
- // though it can.
321
- // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
322
- /** @suppress {checkTypes} */ var e = new WebAssembly.RuntimeError(what);
323
- readyPromiseReject(e);
324
- // Throw the error whether or not MODULARIZE is set because abort is used
325
- // in code paths apart from instantiation where an exception is expected
326
- // to be thrown when abort is called.
327
- throw e;
328
- }
329
-
330
- var wasmBinaryFile;
331
-
332
- function findWasmBinary() {
333
- return locateFile("sed.wasm");
334
- }
335
-
336
- function getBinarySync(file) {
337
- if (file == wasmBinaryFile && wasmBinary) {
338
- return new Uint8Array(wasmBinary);
339
- }
340
- if (readBinary) {
341
- return readBinary(file);
342
- }
343
- throw "both async and sync fetching of the wasm failed";
344
- }
345
-
346
- async function getWasmBinary(binaryFile) {
347
- // If we don't have the binary yet, load it asynchronously using readAsync.
348
- if (!wasmBinary) {
349
- // Fetch the binary using readAsync
350
- try {
351
- var response = await readAsync(binaryFile);
352
- return new Uint8Array(response);
353
- } catch {}
354
- }
355
- // Otherwise, getBinarySync should be able to get it synchronously
356
- return getBinarySync(binaryFile);
357
- }
358
-
359
- async function instantiateArrayBuffer(binaryFile, imports) {
360
- try {
361
- var binary = await getWasmBinary(binaryFile);
362
- var instance = await WebAssembly.instantiate(binary, imports);
363
- return instance;
364
- } catch (reason) {
365
- err(`failed to asynchronously prepare wasm: ${reason}`);
366
- abort(reason);
367
- }
368
- }
369
-
370
- async function instantiateAsync(binary, binaryFile, imports) {
371
- if (!binary && typeof WebAssembly.instantiateStreaming == "function" && !isFileURI(binaryFile) && !ENVIRONMENT_IS_NODE) {
372
- try {
373
- var response = fetch(binaryFile, {
374
- credentials: "same-origin"
375
- });
376
- var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
377
- return instantiationResult;
378
- } catch (reason) {
379
- // We expect the most common failure cause to be a bad MIME type for the binary,
380
- // in which case falling back to ArrayBuffer instantiation should work.
381
- err(`wasm streaming compile failed: ${reason}`);
382
- err("falling back to ArrayBuffer instantiation");
383
- }
384
- }
385
- return instantiateArrayBuffer(binaryFile, imports);
386
- }
387
-
388
- function getWasmImports() {
389
- // prepare imports
390
- return {
391
- "a": wasmImports
392
- };
393
- }
394
-
395
- // Create the wasm instance.
396
- // Receives the wasm imports, returns the exports.
397
- async function createWasm() {
398
- // Load the wasm module and create an instance of using native support in the JS engine.
399
- // handle a generated wasm instance, receiving its exports and
400
- // performing other necessary setup
401
- /** @param {WebAssembly.Module=} module*/ function receiveInstance(instance, module) {
402
- wasmExports = instance.exports;
403
- wasmMemory = wasmExports["y"];
404
- updateMemoryViews();
405
- removeRunDependency("wasm-instantiate");
406
- return wasmExports;
407
- }
408
- // wait for the pthread pool (if any)
409
- addRunDependency("wasm-instantiate");
410
- // Prefer streaming instantiation if available.
411
- function receiveInstantiationResult(result) {
412
- // 'result' is a ResultObject object which has both the module and instance.
413
- // receiveInstance() will swap in the exports (to Module.asm) so they can be called
414
- // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
415
- // When the regression is fixed, can restore the above PTHREADS-enabled path.
416
- return receiveInstance(result["instance"]);
417
- }
418
- var info = getWasmImports();
419
- // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
420
- // to manually instantiate the Wasm module themselves. This allows pages to
421
- // run the instantiation parallel to any other async startup actions they are
422
- // performing.
423
- // Also pthreads and wasm workers initialize the wasm instance through this
424
- // path.
425
- if (Module["instantiateWasm"]) {
426
- return new Promise((resolve, reject) => {
427
- Module["instantiateWasm"](info, (mod, inst) => {
428
- resolve(receiveInstance(mod, inst));
429
- });
430
- });
431
- }
432
- wasmBinaryFile ??= findWasmBinary();
433
- try {
434
- var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
435
- var exports = receiveInstantiationResult(result);
436
- return exports;
437
- } catch (e) {
438
- // If instantiation fails, reject the module ready promise.
439
- readyPromiseReject(e);
440
- return Promise.reject(e);
441
- }
442
- }
443
-
444
- // end include: preamble.js
445
- // Begin JS library code
446
- class ExitStatus {
447
- name="ExitStatus";
448
- constructor(status) {
449
- this.message = `Program terminated with exit(${status})`;
450
- this.status = status;
451
- }
452
- }
453
-
454
- var callRuntimeCallbacks = callbacks => {
455
- while (callbacks.length > 0) {
456
- // Pass the module as the first argument.
457
- callbacks.shift()(Module);
458
- }
459
- };
460
-
461
- var onPostRuns = [];
462
-
463
- var addOnPostRun = cb => onPostRuns.push(cb);
464
-
465
- var onPreRuns = [];
466
-
467
- var addOnPreRun = cb => onPreRuns.push(cb);
468
-
469
- var noExitRuntime = false;
470
-
471
- var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder : undefined;
472
-
473
- /**
474
- * Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
475
- * array that contains uint8 values, returns a copy of that string as a
476
- * Javascript String object.
477
- * heapOrArray is either a regular array, or a JavaScript typed array view.
478
- * @param {number=} idx
479
- * @param {number=} maxBytesToRead
480
- * @return {string}
481
- */ var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead = NaN) => {
482
- var endIdx = idx + maxBytesToRead;
483
- var endPtr = idx;
484
- // TextDecoder needs to know the byte length in advance, it doesn't stop on
485
- // null terminator by itself. Also, use the length info to avoid running tiny
486
- // strings through TextDecoder, since .subarray() allocates garbage.
487
- // (As a tiny code save trick, compare endPtr against endIdx using a negation,
488
- // so that undefined/NaN means Infinity)
489
- while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
490
- // When using conditional TextDecoder, skip it for short strings as the overhead of the native call is not worth it.
491
- if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
492
- return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
493
- }
494
- var str = "";
495
- // If building with TextDecoder, we have already computed the string length
496
- // above, so test loop end condition against that
497
- while (idx < endPtr) {
498
- // For UTF8 byte structure, see:
499
- // http://en.wikipedia.org/wiki/UTF-8#Description
500
- // https://www.ietf.org/rfc/rfc2279.txt
501
- // https://tools.ietf.org/html/rfc3629
502
- var u0 = heapOrArray[idx++];
503
- if (!(u0 & 128)) {
504
- str += String.fromCharCode(u0);
505
- continue;
506
- }
507
- var u1 = heapOrArray[idx++] & 63;
508
- if ((u0 & 224) == 192) {
509
- str += String.fromCharCode(((u0 & 31) << 6) | u1);
510
- continue;
511
- }
512
- var u2 = heapOrArray[idx++] & 63;
513
- if ((u0 & 240) == 224) {
514
- u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
515
- } else {
516
- u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
517
- }
518
- if (u0 < 65536) {
519
- str += String.fromCharCode(u0);
520
- } else {
521
- var ch = u0 - 65536;
522
- str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023));
523
- }
524
- }
525
- return str;
526
- };
527
-
528
- /**
529
- * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
530
- * emscripten HEAP, returns a copy of that string as a Javascript String object.
531
- *
532
- * @param {number} ptr
533
- * @param {number=} maxBytesToRead - An optional length that specifies the
534
- * maximum number of bytes to read. You can omit this parameter to scan the
535
- * string until the first 0 byte. If maxBytesToRead is passed, and the string
536
- * at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
537
- * string will cut short at that byte index (i.e. maxBytesToRead will not
538
- * produce a string of exact length [ptr, ptr+maxBytesToRead[) N.B. mixing
539
- * frequent uses of UTF8ToString() with and without maxBytesToRead may throw
540
- * JS JIT optimizations off, so it is worth to consider consistently using one
541
- * @return {string}
542
- */ var UTF8ToString = (ptr, maxBytesToRead) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
543
-
544
- var ___assert_fail = (condition, filename, line, func) => abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [ filename ? UTF8ToString(filename) : "unknown filename", line, func ? UTF8ToString(func) : "unknown function" ]);
545
-
546
- var PATH = {
547
- isAbs: path => path.charAt(0) === "/",
548
- splitPath: filename => {
549
- var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
550
- return splitPathRe.exec(filename).slice(1);
551
- },
552
- normalizeArray: (parts, allowAboveRoot) => {
553
- // if the path tries to go above the root, `up` ends up > 0
554
- var up = 0;
555
- for (var i = parts.length - 1; i >= 0; i--) {
556
- var last = parts[i];
557
- if (last === ".") {
558
- parts.splice(i, 1);
559
- } else if (last === "..") {
560
- parts.splice(i, 1);
561
- up++;
562
- } else if (up) {
563
- parts.splice(i, 1);
564
- up--;
565
- }
566
- }
567
- // if the path is allowed to go above the root, restore leading ..s
568
- if (allowAboveRoot) {
569
- for (;up; up--) {
570
- parts.unshift("..");
571
- }
572
- }
573
- return parts;
574
- },
575
- normalize: path => {
576
- var isAbsolute = PATH.isAbs(path), trailingSlash = path.slice(-1) === "/";
577
- // Normalize the path
578
- path = PATH.normalizeArray(path.split("/").filter(p => !!p), !isAbsolute).join("/");
579
- if (!path && !isAbsolute) {
580
- path = ".";
581
- }
582
- if (path && trailingSlash) {
583
- path += "/";
584
- }
585
- return (isAbsolute ? "/" : "") + path;
586
- },
587
- dirname: path => {
588
- var result = PATH.splitPath(path), root = result[0], dir = result[1];
589
- if (!root && !dir) {
590
- // No dirname whatsoever
591
- return ".";
592
- }
593
- if (dir) {
594
- // It has a dirname, strip trailing slash
595
- dir = dir.slice(0, -1);
596
- }
597
- return root + dir;
598
- },
599
- basename: path => path && path.match(/([^\/]+|\/)\/*$/)[1],
600
- join: (...paths) => PATH.normalize(paths.join("/")),
601
- join2: (l, r) => PATH.normalize(l + "/" + r)
602
- };
603
-
604
- var initRandomFill = () => {
605
- // This block is not needed on v19+ since crypto.getRandomValues is builtin
606
- if (ENVIRONMENT_IS_NODE) {
607
- var nodeCrypto = require("crypto");
608
- return view => nodeCrypto.randomFillSync(view);
609
- }
610
- return view => crypto.getRandomValues(view);
611
- };
612
-
613
- var randomFill = view => {
614
- // Lazily init on the first invocation.
615
- (randomFill = initRandomFill())(view);
616
- };
617
-
618
- var PATH_FS = {
619
- resolve: (...args) => {
620
- var resolvedPath = "", resolvedAbsolute = false;
621
- for (var i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
622
- var path = (i >= 0) ? args[i] : FS.cwd();
623
- // Skip empty and invalid entries
624
- if (typeof path != "string") {
625
- throw new TypeError("Arguments to path.resolve must be strings");
626
- } else if (!path) {
627
- return "";
628
- }
629
- resolvedPath = path + "/" + resolvedPath;
630
- resolvedAbsolute = PATH.isAbs(path);
631
- }
632
- // At this point the path should be resolved to a full absolute path, but
633
- // handle relative paths to be safe (might happen when process.cwd() fails)
634
- resolvedPath = PATH.normalizeArray(resolvedPath.split("/").filter(p => !!p), !resolvedAbsolute).join("/");
635
- return ((resolvedAbsolute ? "/" : "") + resolvedPath) || ".";
636
- },
637
- relative: (from, to) => {
638
- from = PATH_FS.resolve(from).slice(1);
639
- to = PATH_FS.resolve(to).slice(1);
640
- function trim(arr) {
641
- var start = 0;
642
- for (;start < arr.length; start++) {
643
- if (arr[start] !== "") break;
644
- }
645
- var end = arr.length - 1;
646
- for (;end >= 0; end--) {
647
- if (arr[end] !== "") break;
648
- }
649
- if (start > end) return [];
650
- return arr.slice(start, end - start + 1);
651
- }
652
- var fromParts = trim(from.split("/"));
653
- var toParts = trim(to.split("/"));
654
- var length = Math.min(fromParts.length, toParts.length);
655
- var samePartsLength = length;
656
- for (var i = 0; i < length; i++) {
657
- if (fromParts[i] !== toParts[i]) {
658
- samePartsLength = i;
659
- break;
660
- }
661
- }
662
- var outputParts = [];
663
- for (var i = samePartsLength; i < fromParts.length; i++) {
664
- outputParts.push("..");
665
- }
666
- outputParts = outputParts.concat(toParts.slice(samePartsLength));
667
- return outputParts.join("/");
668
- }
669
- };
670
-
671
- var FS_stdin_getChar_buffer = [];
672
-
673
- var lengthBytesUTF8 = str => {
674
- var len = 0;
675
- for (var i = 0; i < str.length; ++i) {
676
- // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
677
- // unit, not a Unicode code point of the character! So decode
678
- // UTF16->UTF32->UTF8.
679
- // See http://unicode.org/faq/utf_bom.html#utf16-3
680
- var c = str.charCodeAt(i);
681
- // possibly a lead surrogate
682
- if (c <= 127) {
683
- len++;
684
- } else if (c <= 2047) {
685
- len += 2;
686
- } else if (c >= 55296 && c <= 57343) {
687
- len += 4;
688
- ++i;
689
- } else {
690
- len += 3;
691
- }
692
- }
693
- return len;
694
- };
695
-
696
- var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
697
- // Parameter maxBytesToWrite is not optional. Negative values, 0, null,
698
- // undefined and false each don't write out any bytes.
699
- if (!(maxBytesToWrite > 0)) return 0;
700
- var startIdx = outIdx;
701
- var endIdx = outIdx + maxBytesToWrite - 1;
702
- // -1 for string null terminator.
703
- for (var i = 0; i < str.length; ++i) {
704
- // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
705
- // unit, not a Unicode code point of the character! So decode
706
- // UTF16->UTF32->UTF8.
707
- // See http://unicode.org/faq/utf_bom.html#utf16-3
708
- // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description
709
- // and https://www.ietf.org/rfc/rfc2279.txt
710
- // and https://tools.ietf.org/html/rfc3629
711
- var u = str.charCodeAt(i);
712
- // possibly a lead surrogate
713
- if (u >= 55296 && u <= 57343) {
714
- var u1 = str.charCodeAt(++i);
715
- u = 65536 + ((u & 1023) << 10) | (u1 & 1023);
716
- }
717
- if (u <= 127) {
718
- if (outIdx >= endIdx) break;
719
- heap[outIdx++] = u;
720
- } else if (u <= 2047) {
721
- if (outIdx + 1 >= endIdx) break;
722
- heap[outIdx++] = 192 | (u >> 6);
723
- heap[outIdx++] = 128 | (u & 63);
724
- } else if (u <= 65535) {
725
- if (outIdx + 2 >= endIdx) break;
726
- heap[outIdx++] = 224 | (u >> 12);
727
- heap[outIdx++] = 128 | ((u >> 6) & 63);
728
- heap[outIdx++] = 128 | (u & 63);
729
- } else {
730
- if (outIdx + 3 >= endIdx) break;
731
- heap[outIdx++] = 240 | (u >> 18);
732
- heap[outIdx++] = 128 | ((u >> 12) & 63);
733
- heap[outIdx++] = 128 | ((u >> 6) & 63);
734
- heap[outIdx++] = 128 | (u & 63);
735
- }
736
- }
737
- // Null-terminate the pointer to the buffer.
738
- heap[outIdx] = 0;
739
- return outIdx - startIdx;
740
- };
741
-
742
- /** @type {function(string, boolean=, number=)} */ var intArrayFromString = (stringy, dontAddNull, length) => {
743
- var len = length > 0 ? length : lengthBytesUTF8(stringy) + 1;
744
- var u8array = new Array(len);
745
- var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
746
- if (dontAddNull) u8array.length = numBytesWritten;
747
- return u8array;
748
- };
749
-
750
- var FS_stdin_getChar = () => {
751
- if (!FS_stdin_getChar_buffer.length) {
752
- var result = null;
753
- if (ENVIRONMENT_IS_NODE) {
754
- // we will read data by chunks of BUFSIZE
755
- var BUFSIZE = 256;
756
- var buf = Buffer.alloc(BUFSIZE);
757
- var bytesRead = 0;
758
- // For some reason we must suppress a closure warning here, even though
759
- // fd definitely exists on process.stdin, and is even the proper way to
760
- // get the fd of stdin,
761
- // https://github.com/nodejs/help/issues/2136#issuecomment-523649904
762
- // This started to happen after moving this logic out of library_tty.js,
763
- // so it is related to the surrounding code in some unclear manner.
764
- /** @suppress {missingProperties} */ var fd = process.stdin.fd;
765
- try {
766
- bytesRead = fs.readSync(fd, buf, 0, BUFSIZE);
767
- } catch (e) {
768
- // Cross-platform differences: on Windows, reading EOF throws an
769
- // exception, but on other OSes, reading EOF returns 0. Uniformize
770
- // behavior by treating the EOF exception to return 0.
771
- if (e.toString().includes("EOF")) bytesRead = 0; else throw e;
772
- }
773
- if (bytesRead > 0) {
774
- result = buf.slice(0, bytesRead).toString("utf-8");
775
- }
776
- } else if (typeof window != "undefined" && typeof window.prompt == "function") {
777
- // Browser.
778
- result = window.prompt("Input: ");
779
- // returns null on cancel
780
- if (result !== null) {
781
- result += "\n";
782
- }
783
- } else {}
784
- if (!result) {
785
- return null;
786
- }
787
- FS_stdin_getChar_buffer = intArrayFromString(result, true);
788
- }
789
- return FS_stdin_getChar_buffer.shift();
790
- };
791
-
792
- var TTY = {
793
- ttys: [],
794
- init() {},
795
- shutdown() {},
796
- register(dev, ops) {
797
- TTY.ttys[dev] = {
798
- input: [],
799
- output: [],
800
- ops
801
- };
802
- FS.registerDevice(dev, TTY.stream_ops);
803
- },
804
- stream_ops: {
805
- open(stream) {
806
- var tty = TTY.ttys[stream.node.rdev];
807
- if (!tty) {
808
- throw new FS.ErrnoError(43);
809
- }
810
- stream.tty = tty;
811
- stream.seekable = false;
812
- },
813
- close(stream) {
814
- // flush any pending line data
815
- stream.tty.ops.fsync(stream.tty);
816
- },
817
- fsync(stream) {
818
- stream.tty.ops.fsync(stream.tty);
819
- },
820
- read(stream, buffer, offset, length, pos) {
821
- if (!stream.tty || !stream.tty.ops.get_char) {
822
- throw new FS.ErrnoError(60);
823
- }
824
- var bytesRead = 0;
825
- for (var i = 0; i < length; i++) {
826
- var result;
827
- try {
828
- result = stream.tty.ops.get_char(stream.tty);
829
- } catch (e) {
830
- throw new FS.ErrnoError(29);
831
- }
832
- if (result === undefined && bytesRead === 0) {
833
- throw new FS.ErrnoError(6);
834
- }
835
- if (result === null || result === undefined) break;
836
- bytesRead++;
837
- buffer[offset + i] = result;
838
- }
839
- if (bytesRead) {
840
- stream.node.atime = Date.now();
841
- }
842
- return bytesRead;
843
- },
844
- write(stream, buffer, offset, length, pos) {
845
- if (!stream.tty || !stream.tty.ops.put_char) {
846
- throw new FS.ErrnoError(60);
847
- }
848
- try {
849
- for (var i = 0; i < length; i++) {
850
- stream.tty.ops.put_char(stream.tty, buffer[offset + i]);
851
- }
852
- } catch (e) {
853
- throw new FS.ErrnoError(29);
854
- }
855
- if (length) {
856
- stream.node.mtime = stream.node.ctime = Date.now();
857
- }
858
- return i;
859
- }
860
- },
861
- default_tty_ops: {
862
- get_char(tty) {
863
- return FS_stdin_getChar();
864
- },
865
- put_char(tty, val) {
866
- if (val === null || val === 10) {
867
- out(UTF8ArrayToString(tty.output));
868
- tty.output = [];
869
- } else {
870
- if (val != 0) tty.output.push(val);
871
- }
872
- },
873
- fsync(tty) {
874
- if (tty.output?.length > 0) {
875
- out(UTF8ArrayToString(tty.output));
876
- tty.output = [];
877
- }
878
- },
879
- ioctl_tcgets(tty) {
880
- // typical setting
881
- return {
882
- c_iflag: 25856,
883
- c_oflag: 5,
884
- c_cflag: 191,
885
- c_lflag: 35387,
886
- c_cc: [ 3, 28, 127, 21, 4, 0, 1, 0, 17, 19, 26, 0, 18, 15, 23, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
887
- };
888
- },
889
- ioctl_tcsets(tty, optional_actions, data) {
890
- // currently just ignore
891
- return 0;
892
- },
893
- ioctl_tiocgwinsz(tty) {
894
- return [ 24, 80 ];
895
- }
896
- },
897
- default_tty1_ops: {
898
- put_char(tty, val) {
899
- if (val === null || val === 10) {
900
- err(UTF8ArrayToString(tty.output));
901
- tty.output = [];
902
- } else {
903
- if (val != 0) tty.output.push(val);
904
- }
905
- },
906
- fsync(tty) {
907
- if (tty.output?.length > 0) {
908
- err(UTF8ArrayToString(tty.output));
909
- tty.output = [];
910
- }
911
- }
912
- }
913
- };
914
-
915
- var mmapAlloc = size => {
916
- abort();
917
- };
918
-
919
- var MEMFS = {
920
- ops_table: null,
921
- mount(mount) {
922
- return MEMFS.createNode(null, "/", 16895, 0);
923
- },
924
- createNode(parent, name, mode, dev) {
925
- if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
926
- // no supported
927
- throw new FS.ErrnoError(63);
928
- }
929
- MEMFS.ops_table ||= {
930
- dir: {
931
- node: {
932
- getattr: MEMFS.node_ops.getattr,
933
- setattr: MEMFS.node_ops.setattr,
934
- lookup: MEMFS.node_ops.lookup,
935
- mknod: MEMFS.node_ops.mknod,
936
- rename: MEMFS.node_ops.rename,
937
- unlink: MEMFS.node_ops.unlink,
938
- rmdir: MEMFS.node_ops.rmdir,
939
- readdir: MEMFS.node_ops.readdir,
940
- symlink: MEMFS.node_ops.symlink
941
- },
942
- stream: {
943
- llseek: MEMFS.stream_ops.llseek
944
- }
945
- },
946
- file: {
947
- node: {
948
- getattr: MEMFS.node_ops.getattr,
949
- setattr: MEMFS.node_ops.setattr
950
- },
951
- stream: {
952
- llseek: MEMFS.stream_ops.llseek,
953
- read: MEMFS.stream_ops.read,
954
- write: MEMFS.stream_ops.write,
955
- mmap: MEMFS.stream_ops.mmap,
956
- msync: MEMFS.stream_ops.msync
957
- }
958
- },
959
- link: {
960
- node: {
961
- getattr: MEMFS.node_ops.getattr,
962
- setattr: MEMFS.node_ops.setattr,
963
- readlink: MEMFS.node_ops.readlink
964
- },
965
- stream: {}
966
- },
967
- chrdev: {
968
- node: {
969
- getattr: MEMFS.node_ops.getattr,
970
- setattr: MEMFS.node_ops.setattr
971
- },
972
- stream: FS.chrdev_stream_ops
973
- }
974
- };
975
- var node = FS.createNode(parent, name, mode, dev);
976
- if (FS.isDir(node.mode)) {
977
- node.node_ops = MEMFS.ops_table.dir.node;
978
- node.stream_ops = MEMFS.ops_table.dir.stream;
979
- node.contents = {};
980
- } else if (FS.isFile(node.mode)) {
981
- node.node_ops = MEMFS.ops_table.file.node;
982
- node.stream_ops = MEMFS.ops_table.file.stream;
983
- node.usedBytes = 0;
984
- // The actual number of bytes used in the typed array, as opposed to contents.length which gives the whole capacity.
985
- // 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
986
- // for performance, and used by default. However, typed arrays are not resizable like normal JS arrays are, so there is a small disk size
987
- // penalty involved for appending file writes that continuously grow a file similar to std::vector capacity vs used -scheme.
988
- node.contents = null;
989
- } else if (FS.isLink(node.mode)) {
990
- node.node_ops = MEMFS.ops_table.link.node;
991
- node.stream_ops = MEMFS.ops_table.link.stream;
992
- } else if (FS.isChrdev(node.mode)) {
993
- node.node_ops = MEMFS.ops_table.chrdev.node;
994
- node.stream_ops = MEMFS.ops_table.chrdev.stream;
995
- }
996
- node.atime = node.mtime = node.ctime = Date.now();
997
- // add the new node to the parent
998
- if (parent) {
999
- parent.contents[name] = node;
1000
- parent.atime = parent.mtime = parent.ctime = node.atime;
1001
- }
1002
- return node;
1003
- },
1004
- getFileDataAsTypedArray(node) {
1005
- if (!node.contents) return new Uint8Array(0);
1006
- if (node.contents.subarray) return node.contents.subarray(0, node.usedBytes);
1007
- // Make sure to not return excess unused bytes.
1008
- return new Uint8Array(node.contents);
1009
- },
1010
- expandFileStorage(node, newCapacity) {
1011
- var prevCapacity = node.contents ? node.contents.length : 0;
1012
- if (prevCapacity >= newCapacity) return;
1013
- // No need to expand, the storage was already large enough.
1014
- // Don't expand strictly to the given requested limit if it's only a very small increase, but instead geometrically grow capacity.
1015
- // For small filesizes (<1MB), perform size*2 geometric increase, but for large sizes, do a much more conservative size*1.125 increase to
1016
- // avoid overshooting the allocation cap by a very large margin.
1017
- var CAPACITY_DOUBLING_MAX = 1024 * 1024;
1018
- newCapacity = Math.max(newCapacity, (prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2 : 1.125)) >>> 0);
1019
- if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256);
1020
- // At minimum allocate 256b for each file when expanding.
1021
- var oldContents = node.contents;
1022
- node.contents = new Uint8Array(newCapacity);
1023
- // Allocate new storage.
1024
- if (node.usedBytes > 0) node.contents.set(oldContents.subarray(0, node.usedBytes), 0);
1025
- },
1026
- resizeFileStorage(node, newSize) {
1027
- if (node.usedBytes == newSize) return;
1028
- if (newSize == 0) {
1029
- node.contents = null;
1030
- // Fully decommit when requesting a resize to zero.
1031
- node.usedBytes = 0;
1032
- } else {
1033
- var oldContents = node.contents;
1034
- node.contents = new Uint8Array(newSize);
1035
- // Allocate new storage.
1036
- if (oldContents) {
1037
- node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes)));
1038
- }
1039
- node.usedBytes = newSize;
1040
- }
1041
- },
1042
- node_ops: {
1043
- getattr(node) {
1044
- var attr = {};
1045
- // device numbers reuse inode numbers.
1046
- attr.dev = FS.isChrdev(node.mode) ? node.id : 1;
1047
- attr.ino = node.id;
1048
- attr.mode = node.mode;
1049
- attr.nlink = 1;
1050
- attr.uid = 0;
1051
- attr.gid = 0;
1052
- attr.rdev = node.rdev;
1053
- if (FS.isDir(node.mode)) {
1054
- attr.size = 4096;
1055
- } else if (FS.isFile(node.mode)) {
1056
- attr.size = node.usedBytes;
1057
- } else if (FS.isLink(node.mode)) {
1058
- attr.size = node.link.length;
1059
- } else {
1060
- attr.size = 0;
1061
- }
1062
- attr.atime = new Date(node.atime);
1063
- attr.mtime = new Date(node.mtime);
1064
- attr.ctime = new Date(node.ctime);
1065
- // NOTE: In our implementation, st_blocks = Math.ceil(st_size/st_blksize),
1066
- // but this is not required by the standard.
1067
- attr.blksize = 4096;
1068
- attr.blocks = Math.ceil(attr.size / attr.blksize);
1069
- return attr;
1070
- },
1071
- setattr(node, attr) {
1072
- for (const key of [ "mode", "atime", "mtime", "ctime" ]) {
1073
- if (attr[key] != null) {
1074
- node[key] = attr[key];
1075
- }
1076
- }
1077
- if (attr.size !== undefined) {
1078
- MEMFS.resizeFileStorage(node, attr.size);
1079
- }
1080
- },
1081
- lookup(parent, name) {
1082
- throw MEMFS.doesNotExistError;
1083
- },
1084
- mknod(parent, name, mode, dev) {
1085
- return MEMFS.createNode(parent, name, mode, dev);
1086
- },
1087
- rename(old_node, new_dir, new_name) {
1088
- var new_node;
1089
- try {
1090
- new_node = FS.lookupNode(new_dir, new_name);
1091
- } catch (e) {}
1092
- if (new_node) {
1093
- if (FS.isDir(old_node.mode)) {
1094
- // if we're overwriting a directory at new_name, make sure it's empty.
1095
- for (var i in new_node.contents) {
1096
- throw new FS.ErrnoError(55);
1097
- }
1098
- }
1099
- FS.hashRemoveNode(new_node);
1100
- }
1101
- // do the internal rewiring
1102
- delete old_node.parent.contents[old_node.name];
1103
- new_dir.contents[new_name] = old_node;
1104
- old_node.name = new_name;
1105
- new_dir.ctime = new_dir.mtime = old_node.parent.ctime = old_node.parent.mtime = Date.now();
1106
- },
1107
- unlink(parent, name) {
1108
- delete parent.contents[name];
1109
- parent.ctime = parent.mtime = Date.now();
1110
- },
1111
- rmdir(parent, name) {
1112
- var node = FS.lookupNode(parent, name);
1113
- for (var i in node.contents) {
1114
- throw new FS.ErrnoError(55);
1115
- }
1116
- delete parent.contents[name];
1117
- parent.ctime = parent.mtime = Date.now();
1118
- },
1119
- readdir(node) {
1120
- return [ ".", "..", ...Object.keys(node.contents) ];
1121
- },
1122
- symlink(parent, newname, oldpath) {
1123
- var node = MEMFS.createNode(parent, newname, 511 | 40960, 0);
1124
- node.link = oldpath;
1125
- return node;
1126
- },
1127
- readlink(node) {
1128
- if (!FS.isLink(node.mode)) {
1129
- throw new FS.ErrnoError(28);
1130
- }
1131
- return node.link;
1132
- }
1133
- },
1134
- stream_ops: {
1135
- read(stream, buffer, offset, length, position) {
1136
- var contents = stream.node.contents;
1137
- if (position >= stream.node.usedBytes) return 0;
1138
- var size = Math.min(stream.node.usedBytes - position, length);
1139
- if (size > 8 && contents.subarray) {
1140
- // non-trivial, and typed array
1141
- buffer.set(contents.subarray(position, position + size), offset);
1142
- } else {
1143
- for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i];
1144
- }
1145
- return size;
1146
- },
1147
- write(stream, buffer, offset, length, position, canOwn) {
1148
- // If the buffer is located in main memory (HEAP), and if
1149
- // memory can grow, we can't hold on to references of the
1150
- // memory buffer, as they may get invalidated. That means we
1151
- // need to do copy its contents.
1152
- if (buffer.buffer === HEAP8.buffer) {
1153
- canOwn = false;
1154
- }
1155
- if (!length) return 0;
1156
- var node = stream.node;
1157
- node.mtime = node.ctime = Date.now();
1158
- if (buffer.subarray && (!node.contents || node.contents.subarray)) {
1159
- // This write is from a typed array to a typed array?
1160
- if (canOwn) {
1161
- node.contents = buffer.subarray(offset, offset + length);
1162
- node.usedBytes = length;
1163
- return length;
1164
- } else if (node.usedBytes === 0 && position === 0) {
1165
- // 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.
1166
- node.contents = buffer.slice(offset, offset + length);
1167
- node.usedBytes = length;
1168
- return length;
1169
- } else if (position + length <= node.usedBytes) {
1170
- // Writing to an already allocated and used subrange of the file?
1171
- node.contents.set(buffer.subarray(offset, offset + length), position);
1172
- return length;
1173
- }
1174
- }
1175
- // Appending to an existing file and we need to reallocate, or source data did not come as a typed array.
1176
- MEMFS.expandFileStorage(node, position + length);
1177
- if (node.contents.subarray && buffer.subarray) {
1178
- // Use typed array write which is available.
1179
- node.contents.set(buffer.subarray(offset, offset + length), position);
1180
- } else {
1181
- for (var i = 0; i < length; i++) {
1182
- node.contents[position + i] = buffer[offset + i];
1183
- }
1184
- }
1185
- node.usedBytes = Math.max(node.usedBytes, position + length);
1186
- return length;
1187
- },
1188
- llseek(stream, offset, whence) {
1189
- var position = offset;
1190
- if (whence === 1) {
1191
- position += stream.position;
1192
- } else if (whence === 2) {
1193
- if (FS.isFile(stream.node.mode)) {
1194
- position += stream.node.usedBytes;
1195
- }
1196
- }
1197
- if (position < 0) {
1198
- throw new FS.ErrnoError(28);
1199
- }
1200
- return position;
1201
- },
1202
- mmap(stream, length, position, prot, flags) {
1203
- if (!FS.isFile(stream.node.mode)) {
1204
- throw new FS.ErrnoError(43);
1205
- }
1206
- var ptr;
1207
- var allocated;
1208
- var contents = stream.node.contents;
1209
- // Only make a new copy when MAP_PRIVATE is specified.
1210
- if (!(flags & 2) && contents && contents.buffer === HEAP8.buffer) {
1211
- // We can't emulate MAP_SHARED when the file is not backed by the
1212
- // buffer we're mapping to (e.g. the HEAP buffer).
1213
- allocated = false;
1214
- ptr = contents.byteOffset;
1215
- } else {
1216
- allocated = true;
1217
- ptr = mmapAlloc(length);
1218
- if (!ptr) {
1219
- throw new FS.ErrnoError(48);
1220
- }
1221
- if (contents) {
1222
- // Try to avoid unnecessary slices.
1223
- if (position > 0 || position + length < contents.length) {
1224
- if (contents.subarray) {
1225
- contents = contents.subarray(position, position + length);
1226
- } else {
1227
- contents = Array.prototype.slice.call(contents, position, position + length);
1228
- }
1229
- }
1230
- HEAP8.set(contents, ptr);
1231
- }
1232
- }
1233
- return {
1234
- ptr,
1235
- allocated
1236
- };
1237
- },
1238
- msync(stream, buffer, offset, length, mmapFlags) {
1239
- MEMFS.stream_ops.write(stream, buffer, 0, length, offset, false);
1240
- // should we check if bytesWritten and length are the same?
1241
- return 0;
1242
- }
1243
- }
1244
- };
1245
-
1246
- var asyncLoad = async url => {
1247
- var arrayBuffer = await readAsync(url);
1248
- return new Uint8Array(arrayBuffer);
1249
- };
1250
-
1251
- var FS_createDataFile = (...args) => FS.createDataFile(...args);
1252
-
1253
- var preloadPlugins = [];
1254
-
1255
- var FS_handledByPreloadPlugin = (byteArray, fullname, finish, onerror) => {
1256
- // Ensure plugins are ready.
1257
- if (typeof Browser != "undefined") Browser.init();
1258
- var handled = false;
1259
- preloadPlugins.forEach(plugin => {
1260
- if (handled) return;
1261
- if (plugin["canHandle"](fullname)) {
1262
- plugin["handle"](byteArray, fullname, finish, onerror);
1263
- handled = true;
1264
- }
1265
- });
1266
- return handled;
1267
- };
1268
-
1269
- var FS_createPreloadedFile = (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => {
1270
- // TODO we should allow people to just pass in a complete filename instead
1271
- // of parent and name being that we just join them anyways
1272
- var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
1273
- var dep = getUniqueRunDependency(`cp ${fullname}`);
1274
- // might have several active requests for the same fullname
1275
- function processData(byteArray) {
1276
- function finish(byteArray) {
1277
- preFinish?.();
1278
- if (!dontCreateFile) {
1279
- FS_createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
1280
- }
1281
- onload?.();
1282
- removeRunDependency(dep);
1283
- }
1284
- if (FS_handledByPreloadPlugin(byteArray, fullname, finish, () => {
1285
- onerror?.();
1286
- removeRunDependency(dep);
1287
- })) {
1288
- return;
1289
- }
1290
- finish(byteArray);
1291
- }
1292
- addRunDependency(dep);
1293
- if (typeof url == "string") {
1294
- asyncLoad(url).then(processData, onerror);
1295
- } else {
1296
- processData(url);
1297
- }
1298
- };
1299
-
1300
- var FS_modeStringToFlags = str => {
1301
- var flagModes = {
1302
- "r": 0,
1303
- "r+": 2,
1304
- "w": 512 | 64 | 1,
1305
- "w+": 512 | 64 | 2,
1306
- "a": 1024 | 64 | 1,
1307
- "a+": 1024 | 64 | 2
1308
- };
1309
- var flags = flagModes[str];
1310
- if (typeof flags == "undefined") {
1311
- throw new Error(`Unknown file open mode: ${str}`);
1312
- }
1313
- return flags;
1314
- };
1315
-
1316
- var FS_getMode = (canRead, canWrite) => {
1317
- var mode = 0;
1318
- if (canRead) mode |= 292 | 73;
1319
- if (canWrite) mode |= 146;
1320
- return mode;
1321
- };
1322
-
1323
- var FS = {
1324
- root: null,
1325
- mounts: [],
1326
- devices: {},
1327
- streams: [],
1328
- nextInode: 1,
1329
- nameTable: null,
1330
- currentPath: "/",
1331
- initialized: false,
1332
- ignorePermissions: true,
1333
- filesystems: null,
1334
- syncFSRequests: 0,
1335
- readFiles: {},
1336
- ErrnoError: class {
1337
- name="ErrnoError";
1338
- // We set the `name` property to be able to identify `FS.ErrnoError`
1339
- // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
1340
- // - when using PROXYFS, an error can come from an underlying FS
1341
- // as different FS objects have their own FS.ErrnoError each,
1342
- // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
1343
- // we'll use the reliable test `err.name == "ErrnoError"` instead
1344
- constructor(errno) {
1345
- this.errno = errno;
1346
- }
1347
- },
1348
- FSStream: class {
1349
- shared={};
1350
- get object() {
1351
- return this.node;
1352
- }
1353
- set object(val) {
1354
- this.node = val;
1355
- }
1356
- get isRead() {
1357
- return (this.flags & 2097155) !== 1;
1358
- }
1359
- get isWrite() {
1360
- return (this.flags & 2097155) !== 0;
1361
- }
1362
- get isAppend() {
1363
- return (this.flags & 1024);
1364
- }
1365
- get flags() {
1366
- return this.shared.flags;
1367
- }
1368
- set flags(val) {
1369
- this.shared.flags = val;
1370
- }
1371
- get position() {
1372
- return this.shared.position;
1373
- }
1374
- set position(val) {
1375
- this.shared.position = val;
1376
- }
1377
- },
1378
- FSNode: class {
1379
- node_ops={};
1380
- stream_ops={};
1381
- readMode=292 | 73;
1382
- writeMode=146;
1383
- mounted=null;
1384
- constructor(parent, name, mode, rdev) {
1385
- if (!parent) {
1386
- parent = this;
1387
- }
1388
- this.parent = parent;
1389
- this.mount = parent.mount;
1390
- this.id = FS.nextInode++;
1391
- this.name = name;
1392
- this.mode = mode;
1393
- this.rdev = rdev;
1394
- this.atime = this.mtime = this.ctime = Date.now();
1395
- }
1396
- get read() {
1397
- return (this.mode & this.readMode) === this.readMode;
1398
- }
1399
- set read(val) {
1400
- val ? this.mode |= this.readMode : this.mode &= ~this.readMode;
1401
- }
1402
- get write() {
1403
- return (this.mode & this.writeMode) === this.writeMode;
1404
- }
1405
- set write(val) {
1406
- val ? this.mode |= this.writeMode : this.mode &= ~this.writeMode;
1407
- }
1408
- get isFolder() {
1409
- return FS.isDir(this.mode);
1410
- }
1411
- get isDevice() {
1412
- return FS.isChrdev(this.mode);
1413
- }
1414
- },
1415
- lookupPath(path, opts = {}) {
1416
- if (!path) {
1417
- throw new FS.ErrnoError(44);
1418
- }
1419
- opts.follow_mount ??= true;
1420
- if (!PATH.isAbs(path)) {
1421
- path = FS.cwd() + "/" + path;
1422
- }
1423
- // limit max consecutive symlinks to 40 (SYMLOOP_MAX).
1424
- linkloop: for (var nlinks = 0; nlinks < 40; nlinks++) {
1425
- // split the absolute path
1426
- var parts = path.split("/").filter(p => !!p);
1427
- // start at the root
1428
- var current = FS.root;
1429
- var current_path = "/";
1430
- for (var i = 0; i < parts.length; i++) {
1431
- var islast = (i === parts.length - 1);
1432
- if (islast && opts.parent) {
1433
- // stop resolving
1434
- break;
1435
- }
1436
- if (parts[i] === ".") {
1437
- continue;
1438
- }
1439
- if (parts[i] === "..") {
1440
- current_path = PATH.dirname(current_path);
1441
- if (FS.isRoot(current)) {
1442
- path = current_path + "/" + parts.slice(i + 1).join("/");
1443
- continue linkloop;
1444
- } else {
1445
- current = current.parent;
1446
- }
1447
- continue;
1448
- }
1449
- current_path = PATH.join2(current_path, parts[i]);
1450
- try {
1451
- current = FS.lookupNode(current, parts[i]);
1452
- } catch (e) {
1453
- // if noent_okay is true, suppress a ENOENT in the last component
1454
- // and return an object with an undefined node. This is needed for
1455
- // resolving symlinks in the path when creating a file.
1456
- if ((e?.errno === 44) && islast && opts.noent_okay) {
1457
- return {
1458
- path: current_path
1459
- };
1460
- }
1461
- throw e;
1462
- }
1463
- // jump to the mount's root node if this is a mountpoint
1464
- if (FS.isMountpoint(current) && (!islast || opts.follow_mount)) {
1465
- current = current.mounted.root;
1466
- }
1467
- // by default, lookupPath will not follow a symlink if it is the final path component.
1468
- // setting opts.follow = true will override this behavior.
1469
- if (FS.isLink(current.mode) && (!islast || opts.follow)) {
1470
- if (!current.node_ops.readlink) {
1471
- throw new FS.ErrnoError(52);
1472
- }
1473
- var link = current.node_ops.readlink(current);
1474
- if (!PATH.isAbs(link)) {
1475
- link = PATH.dirname(current_path) + "/" + link;
1476
- }
1477
- path = link + "/" + parts.slice(i + 1).join("/");
1478
- continue linkloop;
1479
- }
1480
- }
1481
- return {
1482
- path: current_path,
1483
- node: current
1484
- };
1485
- }
1486
- throw new FS.ErrnoError(32);
1487
- },
1488
- getPath(node) {
1489
- var path;
1490
- while (true) {
1491
- if (FS.isRoot(node)) {
1492
- var mount = node.mount.mountpoint;
1493
- if (!path) return mount;
1494
- return mount[mount.length - 1] !== "/" ? `${mount}/${path}` : mount + path;
1495
- }
1496
- path = path ? `${node.name}/${path}` : node.name;
1497
- node = node.parent;
1498
- }
1499
- },
1500
- hashName(parentid, name) {
1501
- var hash = 0;
1502
- for (var i = 0; i < name.length; i++) {
1503
- hash = ((hash << 5) - hash + name.charCodeAt(i)) | 0;
1504
- }
1505
- return ((parentid + hash) >>> 0) % FS.nameTable.length;
1506
- },
1507
- hashAddNode(node) {
1508
- var hash = FS.hashName(node.parent.id, node.name);
1509
- node.name_next = FS.nameTable[hash];
1510
- FS.nameTable[hash] = node;
1511
- },
1512
- hashRemoveNode(node) {
1513
- var hash = FS.hashName(node.parent.id, node.name);
1514
- if (FS.nameTable[hash] === node) {
1515
- FS.nameTable[hash] = node.name_next;
1516
- } else {
1517
- var current = FS.nameTable[hash];
1518
- while (current) {
1519
- if (current.name_next === node) {
1520
- current.name_next = node.name_next;
1521
- break;
1522
- }
1523
- current = current.name_next;
1524
- }
1525
- }
1526
- },
1527
- lookupNode(parent, name) {
1528
- var errCode = FS.mayLookup(parent);
1529
- if (errCode) {
1530
- throw new FS.ErrnoError(errCode);
1531
- }
1532
- var hash = FS.hashName(parent.id, name);
1533
- for (var node = FS.nameTable[hash]; node; node = node.name_next) {
1534
- var nodeName = node.name;
1535
- if (node.parent.id === parent.id && nodeName === name) {
1536
- return node;
1537
- }
1538
- }
1539
- // if we failed to find it in the cache, call into the VFS
1540
- return FS.lookup(parent, name);
1541
- },
1542
- createNode(parent, name, mode, rdev) {
1543
- var node = new FS.FSNode(parent, name, mode, rdev);
1544
- FS.hashAddNode(node);
1545
- return node;
1546
- },
1547
- destroyNode(node) {
1548
- FS.hashRemoveNode(node);
1549
- },
1550
- isRoot(node) {
1551
- return node === node.parent;
1552
- },
1553
- isMountpoint(node) {
1554
- return !!node.mounted;
1555
- },
1556
- isFile(mode) {
1557
- return (mode & 61440) === 32768;
1558
- },
1559
- isDir(mode) {
1560
- return (mode & 61440) === 16384;
1561
- },
1562
- isLink(mode) {
1563
- return (mode & 61440) === 40960;
1564
- },
1565
- isChrdev(mode) {
1566
- return (mode & 61440) === 8192;
1567
- },
1568
- isBlkdev(mode) {
1569
- return (mode & 61440) === 24576;
1570
- },
1571
- isFIFO(mode) {
1572
- return (mode & 61440) === 4096;
1573
- },
1574
- isSocket(mode) {
1575
- return (mode & 49152) === 49152;
1576
- },
1577
- flagsToPermissionString(flag) {
1578
- var perms = [ "r", "w", "rw" ][flag & 3];
1579
- if ((flag & 512)) {
1580
- perms += "w";
1581
- }
1582
- return perms;
1583
- },
1584
- nodePermissions(node, perms) {
1585
- if (FS.ignorePermissions) {
1586
- return 0;
1587
- }
1588
- // return 0 if any user, group or owner bits are set.
1589
- if (perms.includes("r") && !(node.mode & 292)) {
1590
- return 2;
1591
- } else if (perms.includes("w") && !(node.mode & 146)) {
1592
- return 2;
1593
- } else if (perms.includes("x") && !(node.mode & 73)) {
1594
- return 2;
1595
- }
1596
- return 0;
1597
- },
1598
- mayLookup(dir) {
1599
- if (!FS.isDir(dir.mode)) return 54;
1600
- var errCode = FS.nodePermissions(dir, "x");
1601
- if (errCode) return errCode;
1602
- if (!dir.node_ops.lookup) return 2;
1603
- return 0;
1604
- },
1605
- mayCreate(dir, name) {
1606
- if (!FS.isDir(dir.mode)) {
1607
- return 54;
1608
- }
1609
- try {
1610
- var node = FS.lookupNode(dir, name);
1611
- return 20;
1612
- } catch (e) {}
1613
- return FS.nodePermissions(dir, "wx");
1614
- },
1615
- mayDelete(dir, name, isdir) {
1616
- var node;
1617
- try {
1618
- node = FS.lookupNode(dir, name);
1619
- } catch (e) {
1620
- return e.errno;
1621
- }
1622
- var errCode = FS.nodePermissions(dir, "wx");
1623
- if (errCode) {
1624
- return errCode;
1625
- }
1626
- if (isdir) {
1627
- if (!FS.isDir(node.mode)) {
1628
- return 54;
1629
- }
1630
- if (FS.isRoot(node) || FS.getPath(node) === FS.cwd()) {
1631
- return 10;
1632
- }
1633
- } else {
1634
- if (FS.isDir(node.mode)) {
1635
- return 31;
1636
- }
1637
- }
1638
- return 0;
1639
- },
1640
- mayOpen(node, flags) {
1641
- if (!node) {
1642
- return 44;
1643
- }
1644
- if (FS.isLink(node.mode)) {
1645
- return 32;
1646
- } else if (FS.isDir(node.mode)) {
1647
- if (FS.flagsToPermissionString(flags) !== "r" || (flags & (512 | 64))) {
1648
- // TODO: check for O_SEARCH? (== search for dir only)
1649
- return 31;
1650
- }
1651
- }
1652
- return FS.nodePermissions(node, FS.flagsToPermissionString(flags));
1653
- },
1654
- checkOpExists(op, err) {
1655
- if (!op) {
1656
- throw new FS.ErrnoError(err);
1657
- }
1658
- return op;
1659
- },
1660
- MAX_OPEN_FDS: 4096,
1661
- nextfd() {
1662
- for (var fd = 0; fd <= FS.MAX_OPEN_FDS; fd++) {
1663
- if (!FS.streams[fd]) {
1664
- return fd;
1665
- }
1666
- }
1667
- throw new FS.ErrnoError(33);
1668
- },
1669
- getStreamChecked(fd) {
1670
- var stream = FS.getStream(fd);
1671
- if (!stream) {
1672
- throw new FS.ErrnoError(8);
1673
- }
1674
- return stream;
1675
- },
1676
- getStream: fd => FS.streams[fd],
1677
- createStream(stream, fd = -1) {
1678
- // clone it, so we can return an instance of FSStream
1679
- stream = Object.assign(new FS.FSStream, stream);
1680
- if (fd == -1) {
1681
- fd = FS.nextfd();
1682
- }
1683
- stream.fd = fd;
1684
- FS.streams[fd] = stream;
1685
- return stream;
1686
- },
1687
- closeStream(fd) {
1688
- FS.streams[fd] = null;
1689
- },
1690
- dupStream(origStream, fd = -1) {
1691
- var stream = FS.createStream(origStream, fd);
1692
- stream.stream_ops?.dup?.(stream);
1693
- return stream;
1694
- },
1695
- doSetAttr(stream, node, attr) {
1696
- var setattr = stream?.stream_ops.setattr;
1697
- var arg = setattr ? stream : node;
1698
- setattr ??= node.node_ops.setattr;
1699
- FS.checkOpExists(setattr, 63);
1700
- setattr(arg, attr);
1701
- },
1702
- chrdev_stream_ops: {
1703
- open(stream) {
1704
- var device = FS.getDevice(stream.node.rdev);
1705
- // override node's stream ops with the device's
1706
- stream.stream_ops = device.stream_ops;
1707
- // forward the open call
1708
- stream.stream_ops.open?.(stream);
1709
- },
1710
- llseek() {
1711
- throw new FS.ErrnoError(70);
1712
- }
1713
- },
1714
- major: dev => ((dev) >> 8),
1715
- minor: dev => ((dev) & 255),
1716
- makedev: (ma, mi) => ((ma) << 8 | (mi)),
1717
- registerDevice(dev, ops) {
1718
- FS.devices[dev] = {
1719
- stream_ops: ops
1720
- };
1721
- },
1722
- getDevice: dev => FS.devices[dev],
1723
- getMounts(mount) {
1724
- var mounts = [];
1725
- var check = [ mount ];
1726
- while (check.length) {
1727
- var m = check.pop();
1728
- mounts.push(m);
1729
- check.push(...m.mounts);
1730
- }
1731
- return mounts;
1732
- },
1733
- syncfs(populate, callback) {
1734
- if (typeof populate == "function") {
1735
- callback = populate;
1736
- populate = false;
1737
- }
1738
- FS.syncFSRequests++;
1739
- if (FS.syncFSRequests > 1) {
1740
- err(`warning: ${FS.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);
1741
- }
1742
- var mounts = FS.getMounts(FS.root.mount);
1743
- var completed = 0;
1744
- function doCallback(errCode) {
1745
- FS.syncFSRequests--;
1746
- return callback(errCode);
1747
- }
1748
- function done(errCode) {
1749
- if (errCode) {
1750
- if (!done.errored) {
1751
- done.errored = true;
1752
- return doCallback(errCode);
1753
- }
1754
- return;
1755
- }
1756
- if (++completed >= mounts.length) {
1757
- doCallback(null);
1758
- }
1759
- }
1760
- // sync all mounts
1761
- mounts.forEach(mount => {
1762
- if (!mount.type.syncfs) {
1763
- return done(null);
1764
- }
1765
- mount.type.syncfs(mount, populate, done);
1766
- });
1767
- },
1768
- mount(type, opts, mountpoint) {
1769
- var root = mountpoint === "/";
1770
- var pseudo = !mountpoint;
1771
- var node;
1772
- if (root && FS.root) {
1773
- throw new FS.ErrnoError(10);
1774
- } else if (!root && !pseudo) {
1775
- var lookup = FS.lookupPath(mountpoint, {
1776
- follow_mount: false
1777
- });
1778
- mountpoint = lookup.path;
1779
- // use the absolute path
1780
- node = lookup.node;
1781
- if (FS.isMountpoint(node)) {
1782
- throw new FS.ErrnoError(10);
1783
- }
1784
- if (!FS.isDir(node.mode)) {
1785
- throw new FS.ErrnoError(54);
1786
- }
1787
- }
1788
- var mount = {
1789
- type,
1790
- opts,
1791
- mountpoint,
1792
- mounts: []
1793
- };
1794
- // create a root node for the fs
1795
- var mountRoot = type.mount(mount);
1796
- mountRoot.mount = mount;
1797
- mount.root = mountRoot;
1798
- if (root) {
1799
- FS.root = mountRoot;
1800
- } else if (node) {
1801
- // set as a mountpoint
1802
- node.mounted = mount;
1803
- // add the new mount to the current mount's children
1804
- if (node.mount) {
1805
- node.mount.mounts.push(mount);
1806
- }
1807
- }
1808
- return mountRoot;
1809
- },
1810
- unmount(mountpoint) {
1811
- var lookup = FS.lookupPath(mountpoint, {
1812
- follow_mount: false
1813
- });
1814
- if (!FS.isMountpoint(lookup.node)) {
1815
- throw new FS.ErrnoError(28);
1816
- }
1817
- // destroy the nodes for this mount, and all its child mounts
1818
- var node = lookup.node;
1819
- var mount = node.mounted;
1820
- var mounts = FS.getMounts(mount);
1821
- Object.keys(FS.nameTable).forEach(hash => {
1822
- var current = FS.nameTable[hash];
1823
- while (current) {
1824
- var next = current.name_next;
1825
- if (mounts.includes(current.mount)) {
1826
- FS.destroyNode(current);
1827
- }
1828
- current = next;
1829
- }
1830
- });
1831
- // no longer a mountpoint
1832
- node.mounted = null;
1833
- // remove this mount from the child mounts
1834
- var idx = node.mount.mounts.indexOf(mount);
1835
- node.mount.mounts.splice(idx, 1);
1836
- },
1837
- lookup(parent, name) {
1838
- return parent.node_ops.lookup(parent, name);
1839
- },
1840
- mknod(path, mode, dev) {
1841
- var lookup = FS.lookupPath(path, {
1842
- parent: true
1843
- });
1844
- var parent = lookup.node;
1845
- var name = PATH.basename(path);
1846
- if (!name) {
1847
- throw new FS.ErrnoError(28);
1848
- }
1849
- if (name === "." || name === "..") {
1850
- throw new FS.ErrnoError(20);
1851
- }
1852
- var errCode = FS.mayCreate(parent, name);
1853
- if (errCode) {
1854
- throw new FS.ErrnoError(errCode);
1855
- }
1856
- if (!parent.node_ops.mknod) {
1857
- throw new FS.ErrnoError(63);
1858
- }
1859
- return parent.node_ops.mknod(parent, name, mode, dev);
1860
- },
1861
- statfs(path) {
1862
- return FS.statfsNode(FS.lookupPath(path, {
1863
- follow: true
1864
- }).node);
1865
- },
1866
- statfsStream(stream) {
1867
- // We keep a separate statfsStream function because noderawfs overrides
1868
- // it. In noderawfs, stream.node is sometimes null. Instead, we need to
1869
- // look at stream.path.
1870
- return FS.statfsNode(stream.node);
1871
- },
1872
- statfsNode(node) {
1873
- // NOTE: None of the defaults here are true. We're just returning safe and
1874
- // sane values. Currently nodefs and rawfs replace these defaults,
1875
- // other file systems leave them alone.
1876
- var rtn = {
1877
- bsize: 4096,
1878
- frsize: 4096,
1879
- blocks: 1e6,
1880
- bfree: 5e5,
1881
- bavail: 5e5,
1882
- files: FS.nextInode,
1883
- ffree: FS.nextInode - 1,
1884
- fsid: 42,
1885
- flags: 2,
1886
- namelen: 255
1887
- };
1888
- if (node.node_ops.statfs) {
1889
- Object.assign(rtn, node.node_ops.statfs(node.mount.opts.root));
1890
- }
1891
- return rtn;
1892
- },
1893
- create(path, mode = 438) {
1894
- mode &= 4095;
1895
- mode |= 32768;
1896
- return FS.mknod(path, mode, 0);
1897
- },
1898
- mkdir(path, mode = 511) {
1899
- mode &= 511 | 512;
1900
- mode |= 16384;
1901
- return FS.mknod(path, mode, 0);
1902
- },
1903
- mkdirTree(path, mode) {
1904
- var dirs = path.split("/");
1905
- var d = "";
1906
- for (var dir of dirs) {
1907
- if (!dir) continue;
1908
- if (d || PATH.isAbs(path)) d += "/";
1909
- d += dir;
1910
- try {
1911
- FS.mkdir(d, mode);
1912
- } catch (e) {
1913
- if (e.errno != 20) throw e;
1914
- }
1915
- }
1916
- },
1917
- mkdev(path, mode, dev) {
1918
- if (typeof dev == "undefined") {
1919
- dev = mode;
1920
- mode = 438;
1921
- }
1922
- mode |= 8192;
1923
- return FS.mknod(path, mode, dev);
1924
- },
1925
- symlink(oldpath, newpath) {
1926
- if (!PATH_FS.resolve(oldpath)) {
1927
- throw new FS.ErrnoError(44);
1928
- }
1929
- var lookup = FS.lookupPath(newpath, {
1930
- parent: true
1931
- });
1932
- var parent = lookup.node;
1933
- if (!parent) {
1934
- throw new FS.ErrnoError(44);
1935
- }
1936
- var newname = PATH.basename(newpath);
1937
- var errCode = FS.mayCreate(parent, newname);
1938
- if (errCode) {
1939
- throw new FS.ErrnoError(errCode);
1940
- }
1941
- if (!parent.node_ops.symlink) {
1942
- throw new FS.ErrnoError(63);
1943
- }
1944
- return parent.node_ops.symlink(parent, newname, oldpath);
1945
- },
1946
- rename(old_path, new_path) {
1947
- var old_dirname = PATH.dirname(old_path);
1948
- var new_dirname = PATH.dirname(new_path);
1949
- var old_name = PATH.basename(old_path);
1950
- var new_name = PATH.basename(new_path);
1951
- // parents must exist
1952
- var lookup, old_dir, new_dir;
1953
- // let the errors from non existent directories percolate up
1954
- lookup = FS.lookupPath(old_path, {
1955
- parent: true
1956
- });
1957
- old_dir = lookup.node;
1958
- lookup = FS.lookupPath(new_path, {
1959
- parent: true
1960
- });
1961
- new_dir = lookup.node;
1962
- if (!old_dir || !new_dir) throw new FS.ErrnoError(44);
1963
- // need to be part of the same mount
1964
- if (old_dir.mount !== new_dir.mount) {
1965
- throw new FS.ErrnoError(75);
1966
- }
1967
- // source must exist
1968
- var old_node = FS.lookupNode(old_dir, old_name);
1969
- // old path should not be an ancestor of the new path
1970
- var relative = PATH_FS.relative(old_path, new_dirname);
1971
- if (relative.charAt(0) !== ".") {
1972
- throw new FS.ErrnoError(28);
1973
- }
1974
- // new path should not be an ancestor of the old path
1975
- relative = PATH_FS.relative(new_path, old_dirname);
1976
- if (relative.charAt(0) !== ".") {
1977
- throw new FS.ErrnoError(55);
1978
- }
1979
- // see if the new path already exists
1980
- var new_node;
1981
- try {
1982
- new_node = FS.lookupNode(new_dir, new_name);
1983
- } catch (e) {}
1984
- // early out if nothing needs to change
1985
- if (old_node === new_node) {
1986
- return;
1987
- }
1988
- // we'll need to delete the old entry
1989
- var isdir = FS.isDir(old_node.mode);
1990
- var errCode = FS.mayDelete(old_dir, old_name, isdir);
1991
- if (errCode) {
1992
- throw new FS.ErrnoError(errCode);
1993
- }
1994
- // need delete permissions if we'll be overwriting.
1995
- // need create permissions if new doesn't already exist.
1996
- errCode = new_node ? FS.mayDelete(new_dir, new_name, isdir) : FS.mayCreate(new_dir, new_name);
1997
- if (errCode) {
1998
- throw new FS.ErrnoError(errCode);
1999
- }
2000
- if (!old_dir.node_ops.rename) {
2001
- throw new FS.ErrnoError(63);
2002
- }
2003
- if (FS.isMountpoint(old_node) || (new_node && FS.isMountpoint(new_node))) {
2004
- throw new FS.ErrnoError(10);
2005
- }
2006
- // if we are going to change the parent, check write permissions
2007
- if (new_dir !== old_dir) {
2008
- errCode = FS.nodePermissions(old_dir, "w");
2009
- if (errCode) {
2010
- throw new FS.ErrnoError(errCode);
2011
- }
2012
- }
2013
- // remove the node from the lookup hash
2014
- FS.hashRemoveNode(old_node);
2015
- // do the underlying fs rename
2016
- try {
2017
- old_dir.node_ops.rename(old_node, new_dir, new_name);
2018
- // update old node (we do this here to avoid each backend
2019
- // needing to)
2020
- old_node.parent = new_dir;
2021
- } catch (e) {
2022
- throw e;
2023
- } finally {
2024
- // add the node back to the hash (in case node_ops.rename
2025
- // changed its name)
2026
- FS.hashAddNode(old_node);
2027
- }
2028
- },
2029
- rmdir(path) {
2030
- var lookup = FS.lookupPath(path, {
2031
- parent: true
2032
- });
2033
- var parent = lookup.node;
2034
- var name = PATH.basename(path);
2035
- var node = FS.lookupNode(parent, name);
2036
- var errCode = FS.mayDelete(parent, name, true);
2037
- if (errCode) {
2038
- throw new FS.ErrnoError(errCode);
2039
- }
2040
- if (!parent.node_ops.rmdir) {
2041
- throw new FS.ErrnoError(63);
2042
- }
2043
- if (FS.isMountpoint(node)) {
2044
- throw new FS.ErrnoError(10);
2045
- }
2046
- parent.node_ops.rmdir(parent, name);
2047
- FS.destroyNode(node);
2048
- },
2049
- readdir(path) {
2050
- var lookup = FS.lookupPath(path, {
2051
- follow: true
2052
- });
2053
- var node = lookup.node;
2054
- var readdir = FS.checkOpExists(node.node_ops.readdir, 54);
2055
- return readdir(node);
2056
- },
2057
- unlink(path) {
2058
- var lookup = FS.lookupPath(path, {
2059
- parent: true
2060
- });
2061
- var parent = lookup.node;
2062
- if (!parent) {
2063
- throw new FS.ErrnoError(44);
2064
- }
2065
- var name = PATH.basename(path);
2066
- var node = FS.lookupNode(parent, name);
2067
- var errCode = FS.mayDelete(parent, name, false);
2068
- if (errCode) {
2069
- // According to POSIX, we should map EISDIR to EPERM, but
2070
- // we instead do what Linux does (and we must, as we use
2071
- // the musl linux libc).
2072
- throw new FS.ErrnoError(errCode);
2073
- }
2074
- if (!parent.node_ops.unlink) {
2075
- throw new FS.ErrnoError(63);
2076
- }
2077
- if (FS.isMountpoint(node)) {
2078
- throw new FS.ErrnoError(10);
2079
- }
2080
- parent.node_ops.unlink(parent, name);
2081
- FS.destroyNode(node);
2082
- },
2083
- readlink(path) {
2084
- var lookup = FS.lookupPath(path);
2085
- var link = lookup.node;
2086
- if (!link) {
2087
- throw new FS.ErrnoError(44);
2088
- }
2089
- if (!link.node_ops.readlink) {
2090
- throw new FS.ErrnoError(28);
2091
- }
2092
- return link.node_ops.readlink(link);
2093
- },
2094
- stat(path, dontFollow) {
2095
- var lookup = FS.lookupPath(path, {
2096
- follow: !dontFollow
2097
- });
2098
- var node = lookup.node;
2099
- var getattr = FS.checkOpExists(node.node_ops.getattr, 63);
2100
- return getattr(node);
2101
- },
2102
- fstat(fd) {
2103
- var stream = FS.getStreamChecked(fd);
2104
- var node = stream.node;
2105
- var getattr = stream.stream_ops.getattr;
2106
- var arg = getattr ? stream : node;
2107
- getattr ??= node.node_ops.getattr;
2108
- FS.checkOpExists(getattr, 63);
2109
- return getattr(arg);
2110
- },
2111
- lstat(path) {
2112
- return FS.stat(path, true);
2113
- },
2114
- doChmod(stream, node, mode, dontFollow) {
2115
- FS.doSetAttr(stream, node, {
2116
- mode: (mode & 4095) | (node.mode & ~4095),
2117
- ctime: Date.now(),
2118
- dontFollow
2119
- });
2120
- },
2121
- chmod(path, mode, dontFollow) {
2122
- var node;
2123
- if (typeof path == "string") {
2124
- var lookup = FS.lookupPath(path, {
2125
- follow: !dontFollow
2126
- });
2127
- node = lookup.node;
2128
- } else {
2129
- node = path;
2130
- }
2131
- FS.doChmod(null, node, mode, dontFollow);
2132
- },
2133
- lchmod(path, mode) {
2134
- FS.chmod(path, mode, true);
2135
- },
2136
- fchmod(fd, mode) {
2137
- var stream = FS.getStreamChecked(fd);
2138
- FS.doChmod(stream, stream.node, mode, false);
2139
- },
2140
- doChown(stream, node, dontFollow) {
2141
- FS.doSetAttr(stream, node, {
2142
- timestamp: Date.now(),
2143
- dontFollow
2144
- });
2145
- },
2146
- chown(path, uid, gid, dontFollow) {
2147
- var node;
2148
- if (typeof path == "string") {
2149
- var lookup = FS.lookupPath(path, {
2150
- follow: !dontFollow
2151
- });
2152
- node = lookup.node;
2153
- } else {
2154
- node = path;
2155
- }
2156
- FS.doChown(null, node, dontFollow);
2157
- },
2158
- lchown(path, uid, gid) {
2159
- FS.chown(path, uid, gid, true);
2160
- },
2161
- fchown(fd, uid, gid) {
2162
- var stream = FS.getStreamChecked(fd);
2163
- FS.doChown(stream, stream.node, false);
2164
- },
2165
- doTruncate(stream, node, len) {
2166
- if (FS.isDir(node.mode)) {
2167
- throw new FS.ErrnoError(31);
2168
- }
2169
- if (!FS.isFile(node.mode)) {
2170
- throw new FS.ErrnoError(28);
2171
- }
2172
- var errCode = FS.nodePermissions(node, "w");
2173
- if (errCode) {
2174
- throw new FS.ErrnoError(errCode);
2175
- }
2176
- FS.doSetAttr(stream, node, {
2177
- size: len,
2178
- timestamp: Date.now()
2179
- });
2180
- },
2181
- truncate(path, len) {
2182
- if (len < 0) {
2183
- throw new FS.ErrnoError(28);
2184
- }
2185
- var node;
2186
- if (typeof path == "string") {
2187
- var lookup = FS.lookupPath(path, {
2188
- follow: true
2189
- });
2190
- node = lookup.node;
2191
- } else {
2192
- node = path;
2193
- }
2194
- FS.doTruncate(null, node, len);
2195
- },
2196
- ftruncate(fd, len) {
2197
- var stream = FS.getStreamChecked(fd);
2198
- if (len < 0 || (stream.flags & 2097155) === 0) {
2199
- throw new FS.ErrnoError(28);
2200
- }
2201
- FS.doTruncate(stream, stream.node, len);
2202
- },
2203
- utime(path, atime, mtime) {
2204
- var lookup = FS.lookupPath(path, {
2205
- follow: true
2206
- });
2207
- var node = lookup.node;
2208
- var setattr = FS.checkOpExists(node.node_ops.setattr, 63);
2209
- setattr(node, {
2210
- atime,
2211
- mtime
2212
- });
2213
- },
2214
- open(path, flags, mode = 438) {
2215
- if (path === "") {
2216
- throw new FS.ErrnoError(44);
2217
- }
2218
- flags = typeof flags == "string" ? FS_modeStringToFlags(flags) : flags;
2219
- if ((flags & 64)) {
2220
- mode = (mode & 4095) | 32768;
2221
- } else {
2222
- mode = 0;
2223
- }
2224
- var node;
2225
- var isDirPath;
2226
- if (typeof path == "object") {
2227
- node = path;
2228
- } else {
2229
- isDirPath = path.endsWith("/");
2230
- // noent_okay makes it so that if the final component of the path
2231
- // doesn't exist, lookupPath returns `node: undefined`. `path` will be
2232
- // updated to point to the target of all symlinks.
2233
- var lookup = FS.lookupPath(path, {
2234
- follow: !(flags & 131072),
2235
- noent_okay: true
2236
- });
2237
- node = lookup.node;
2238
- path = lookup.path;
2239
- }
2240
- // perhaps we need to create the node
2241
- var created = false;
2242
- if ((flags & 64)) {
2243
- if (node) {
2244
- // if O_CREAT and O_EXCL are set, error out if the node already exists
2245
- if ((flags & 128)) {
2246
- throw new FS.ErrnoError(20);
2247
- }
2248
- } else if (isDirPath) {
2249
- throw new FS.ErrnoError(31);
2250
- } else {
2251
- // node doesn't exist, try to create it
2252
- // Ignore the permission bits here to ensure we can `open` this new
2253
- // file below. We use chmod below the apply the permissions once the
2254
- // file is open.
2255
- node = FS.mknod(path, mode | 511, 0);
2256
- created = true;
2257
- }
2258
- }
2259
- if (!node) {
2260
- throw new FS.ErrnoError(44);
2261
- }
2262
- // can't truncate a device
2263
- if (FS.isChrdev(node.mode)) {
2264
- flags &= ~512;
2265
- }
2266
- // if asked only for a directory, then this must be one
2267
- if ((flags & 65536) && !FS.isDir(node.mode)) {
2268
- throw new FS.ErrnoError(54);
2269
- }
2270
- // check permissions, if this is not a file we just created now (it is ok to
2271
- // create and write to a file with read-only permissions; it is read-only
2272
- // for later use)
2273
- if (!created) {
2274
- var errCode = FS.mayOpen(node, flags);
2275
- if (errCode) {
2276
- throw new FS.ErrnoError(errCode);
2277
- }
2278
- }
2279
- // do truncation if necessary
2280
- if ((flags & 512) && !created) {
2281
- FS.truncate(node, 0);
2282
- }
2283
- // we've already handled these, don't pass down to the underlying vfs
2284
- flags &= ~(128 | 512 | 131072);
2285
- // register the stream with the filesystem
2286
- var stream = FS.createStream({
2287
- node,
2288
- path: FS.getPath(node),
2289
- // we want the absolute path to the node
2290
- flags,
2291
- seekable: true,
2292
- position: 0,
2293
- stream_ops: node.stream_ops,
2294
- // used by the file family libc calls (fopen, fwrite, ferror, etc.)
2295
- ungotten: [],
2296
- error: false
2297
- });
2298
- // call the new stream's open function
2299
- if (stream.stream_ops.open) {
2300
- stream.stream_ops.open(stream);
2301
- }
2302
- if (created) {
2303
- FS.chmod(node, mode & 511);
2304
- }
2305
- if (Module["logReadFiles"] && !(flags & 1)) {
2306
- if (!(path in FS.readFiles)) {
2307
- FS.readFiles[path] = 1;
2308
- }
2309
- }
2310
- return stream;
2311
- },
2312
- close(stream) {
2313
- if (FS.isClosed(stream)) {
2314
- throw new FS.ErrnoError(8);
2315
- }
2316
- if (stream.getdents) stream.getdents = null;
2317
- // free readdir state
2318
- try {
2319
- if (stream.stream_ops.close) {
2320
- stream.stream_ops.close(stream);
2321
- }
2322
- } catch (e) {
2323
- throw e;
2324
- } finally {
2325
- FS.closeStream(stream.fd);
2326
- }
2327
- stream.fd = null;
2328
- },
2329
- isClosed(stream) {
2330
- return stream.fd === null;
2331
- },
2332
- llseek(stream, offset, whence) {
2333
- if (FS.isClosed(stream)) {
2334
- throw new FS.ErrnoError(8);
2335
- }
2336
- if (!stream.seekable || !stream.stream_ops.llseek) {
2337
- throw new FS.ErrnoError(70);
2338
- }
2339
- if (whence != 0 && whence != 1 && whence != 2) {
2340
- throw new FS.ErrnoError(28);
2341
- }
2342
- stream.position = stream.stream_ops.llseek(stream, offset, whence);
2343
- stream.ungotten = [];
2344
- return stream.position;
2345
- },
2346
- read(stream, buffer, offset, length, position) {
2347
- if (length < 0 || position < 0) {
2348
- throw new FS.ErrnoError(28);
2349
- }
2350
- if (FS.isClosed(stream)) {
2351
- throw new FS.ErrnoError(8);
2352
- }
2353
- if ((stream.flags & 2097155) === 1) {
2354
- throw new FS.ErrnoError(8);
2355
- }
2356
- if (FS.isDir(stream.node.mode)) {
2357
- throw new FS.ErrnoError(31);
2358
- }
2359
- if (!stream.stream_ops.read) {
2360
- throw new FS.ErrnoError(28);
2361
- }
2362
- var seeking = typeof position != "undefined";
2363
- if (!seeking) {
2364
- position = stream.position;
2365
- } else if (!stream.seekable) {
2366
- throw new FS.ErrnoError(70);
2367
- }
2368
- var bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position);
2369
- if (!seeking) stream.position += bytesRead;
2370
- return bytesRead;
2371
- },
2372
- write(stream, buffer, offset, length, position, canOwn) {
2373
- if (length < 0 || position < 0) {
2374
- throw new FS.ErrnoError(28);
2375
- }
2376
- if (FS.isClosed(stream)) {
2377
- throw new FS.ErrnoError(8);
2378
- }
2379
- if ((stream.flags & 2097155) === 0) {
2380
- throw new FS.ErrnoError(8);
2381
- }
2382
- if (FS.isDir(stream.node.mode)) {
2383
- throw new FS.ErrnoError(31);
2384
- }
2385
- if (!stream.stream_ops.write) {
2386
- throw new FS.ErrnoError(28);
2387
- }
2388
- if (stream.seekable && stream.flags & 1024) {
2389
- // seek to the end before writing in append mode
2390
- FS.llseek(stream, 0, 2);
2391
- }
2392
- var seeking = typeof position != "undefined";
2393
- if (!seeking) {
2394
- position = stream.position;
2395
- } else if (!stream.seekable) {
2396
- throw new FS.ErrnoError(70);
2397
- }
2398
- var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
2399
- if (!seeking) stream.position += bytesWritten;
2400
- return bytesWritten;
2401
- },
2402
- mmap(stream, length, position, prot, flags) {
2403
- // User requests writing to file (prot & PROT_WRITE != 0).
2404
- // Checking if we have permissions to write to the file unless
2405
- // MAP_PRIVATE flag is set. According to POSIX spec it is possible
2406
- // to write to file opened in read-only mode with MAP_PRIVATE flag,
2407
- // as all modifications will be visible only in the memory of
2408
- // the current process.
2409
- if ((prot & 2) !== 0 && (flags & 2) === 0 && (stream.flags & 2097155) !== 2) {
2410
- throw new FS.ErrnoError(2);
2411
- }
2412
- if ((stream.flags & 2097155) === 1) {
2413
- throw new FS.ErrnoError(2);
2414
- }
2415
- if (!stream.stream_ops.mmap) {
2416
- throw new FS.ErrnoError(43);
2417
- }
2418
- if (!length) {
2419
- throw new FS.ErrnoError(28);
2420
- }
2421
- return stream.stream_ops.mmap(stream, length, position, prot, flags);
2422
- },
2423
- msync(stream, buffer, offset, length, mmapFlags) {
2424
- if (!stream.stream_ops.msync) {
2425
- return 0;
2426
- }
2427
- return stream.stream_ops.msync(stream, buffer, offset, length, mmapFlags);
2428
- },
2429
- ioctl(stream, cmd, arg) {
2430
- if (!stream.stream_ops.ioctl) {
2431
- throw new FS.ErrnoError(59);
2432
- }
2433
- return stream.stream_ops.ioctl(stream, cmd, arg);
2434
- },
2435
- readFile(path, opts = {}) {
2436
- opts.flags = opts.flags || 0;
2437
- opts.encoding = opts.encoding || "binary";
2438
- if (opts.encoding !== "utf8" && opts.encoding !== "binary") {
2439
- throw new Error(`Invalid encoding type "${opts.encoding}"`);
2440
- }
2441
- var ret;
2442
- var stream = FS.open(path, opts.flags);
2443
- var stat = FS.stat(path);
2444
- var length = stat.size;
2445
- var buf = new Uint8Array(length);
2446
- FS.read(stream, buf, 0, length, 0);
2447
- if (opts.encoding === "utf8") {
2448
- ret = UTF8ArrayToString(buf);
2449
- } else if (opts.encoding === "binary") {
2450
- ret = buf;
2451
- }
2452
- FS.close(stream);
2453
- return ret;
2454
- },
2455
- writeFile(path, data, opts = {}) {
2456
- opts.flags = opts.flags || 577;
2457
- var stream = FS.open(path, opts.flags, opts.mode);
2458
- if (typeof data == "string") {
2459
- var buf = new Uint8Array(lengthBytesUTF8(data) + 1);
2460
- var actualNumBytes = stringToUTF8Array(data, buf, 0, buf.length);
2461
- FS.write(stream, buf, 0, actualNumBytes, undefined, opts.canOwn);
2462
- } else if (ArrayBuffer.isView(data)) {
2463
- FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn);
2464
- } else {
2465
- throw new Error("Unsupported data type");
2466
- }
2467
- FS.close(stream);
2468
- },
2469
- cwd: () => FS.currentPath,
2470
- chdir(path) {
2471
- var lookup = FS.lookupPath(path, {
2472
- follow: true
2473
- });
2474
- if (lookup.node === null) {
2475
- throw new FS.ErrnoError(44);
2476
- }
2477
- if (!FS.isDir(lookup.node.mode)) {
2478
- throw new FS.ErrnoError(54);
2479
- }
2480
- var errCode = FS.nodePermissions(lookup.node, "x");
2481
- if (errCode) {
2482
- throw new FS.ErrnoError(errCode);
2483
- }
2484
- FS.currentPath = lookup.path;
2485
- },
2486
- createDefaultDirectories() {
2487
- FS.mkdir("/tmp");
2488
- FS.mkdir("/home");
2489
- FS.mkdir("/home/web_user");
2490
- },
2491
- createDefaultDevices() {
2492
- // create /dev
2493
- FS.mkdir("/dev");
2494
- // setup /dev/null
2495
- FS.registerDevice(FS.makedev(1, 3), {
2496
- read: () => 0,
2497
- write: (stream, buffer, offset, length, pos) => length,
2498
- llseek: () => 0
2499
- });
2500
- FS.mkdev("/dev/null", FS.makedev(1, 3));
2501
- // setup /dev/tty and /dev/tty1
2502
- // stderr needs to print output using err() rather than out()
2503
- // so we register a second tty just for it.
2504
- TTY.register(FS.makedev(5, 0), TTY.default_tty_ops);
2505
- TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);
2506
- FS.mkdev("/dev/tty", FS.makedev(5, 0));
2507
- FS.mkdev("/dev/tty1", FS.makedev(6, 0));
2508
- // setup /dev/[u]random
2509
- // use a buffer to avoid overhead of individual crypto calls per byte
2510
- var randomBuffer = new Uint8Array(1024), randomLeft = 0;
2511
- var randomByte = () => {
2512
- if (randomLeft === 0) {
2513
- randomFill(randomBuffer);
2514
- randomLeft = randomBuffer.byteLength;
2515
- }
2516
- return randomBuffer[--randomLeft];
2517
- };
2518
- FS.createDevice("/dev", "random", randomByte);
2519
- FS.createDevice("/dev", "urandom", randomByte);
2520
- // we're not going to emulate the actual shm device,
2521
- // just create the tmp dirs that reside in it commonly
2522
- FS.mkdir("/dev/shm");
2523
- FS.mkdir("/dev/shm/tmp");
2524
- },
2525
- createSpecialDirectories() {
2526
- // create /proc/self/fd which allows /proc/self/fd/6 => readlink gives the
2527
- // name of the stream for fd 6 (see test_unistd_ttyname)
2528
- FS.mkdir("/proc");
2529
- var proc_self = FS.mkdir("/proc/self");
2530
- FS.mkdir("/proc/self/fd");
2531
- FS.mount({
2532
- mount() {
2533
- var node = FS.createNode(proc_self, "fd", 16895, 73);
2534
- node.stream_ops = {
2535
- llseek: MEMFS.stream_ops.llseek
2536
- };
2537
- node.node_ops = {
2538
- lookup(parent, name) {
2539
- var fd = +name;
2540
- var stream = FS.getStreamChecked(fd);
2541
- var ret = {
2542
- parent: null,
2543
- mount: {
2544
- mountpoint: "fake"
2545
- },
2546
- node_ops: {
2547
- readlink: () => stream.path
2548
- },
2549
- id: fd + 1
2550
- };
2551
- ret.parent = ret;
2552
- // make it look like a simple root node
2553
- return ret;
2554
- },
2555
- readdir() {
2556
- return Array.from(FS.streams.entries()).filter(([k, v]) => v).map(([k, v]) => k.toString());
2557
- }
2558
- };
2559
- return node;
2560
- }
2561
- }, {}, "/proc/self/fd");
2562
- },
2563
- createStandardStreams(input, output, error) {
2564
- // TODO deprecate the old functionality of a single
2565
- // input / output callback and that utilizes FS.createDevice
2566
- // and instead require a unique set of stream ops
2567
- // by default, we symlink the standard streams to the
2568
- // default tty devices. however, if the standard streams
2569
- // have been overwritten we create a unique device for
2570
- // them instead.
2571
- if (input) {
2572
- FS.createDevice("/dev", "stdin", input);
2573
- } else {
2574
- FS.symlink("/dev/tty", "/dev/stdin");
2575
- }
2576
- if (output) {
2577
- FS.createDevice("/dev", "stdout", null, output);
2578
- } else {
2579
- FS.symlink("/dev/tty", "/dev/stdout");
2580
- }
2581
- if (error) {
2582
- FS.createDevice("/dev", "stderr", null, error);
2583
- } else {
2584
- FS.symlink("/dev/tty1", "/dev/stderr");
2585
- }
2586
- // open default streams for the stdin, stdout and stderr devices
2587
- var stdin = FS.open("/dev/stdin", 0);
2588
- var stdout = FS.open("/dev/stdout", 1);
2589
- var stderr = FS.open("/dev/stderr", 1);
2590
- },
2591
- staticInit() {
2592
- FS.nameTable = new Array(4096);
2593
- FS.mount(MEMFS, {}, "/");
2594
- FS.createDefaultDirectories();
2595
- FS.createDefaultDevices();
2596
- FS.createSpecialDirectories();
2597
- FS.filesystems = {
2598
- "MEMFS": MEMFS
2599
- };
2600
- },
2601
- init(input, output, error) {
2602
- FS.initialized = true;
2603
- // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
2604
- input ??= Module["stdin"];
2605
- output ??= Module["stdout"];
2606
- error ??= Module["stderr"];
2607
- FS.createStandardStreams(input, output, error);
2608
- },
2609
- quit() {
2610
- FS.initialized = false;
2611
- // force-flush all streams, so we get musl std streams printed out
2612
- _fflush(0);
2613
- // close all of our streams
2614
- for (var stream of FS.streams) {
2615
- if (stream) {
2616
- FS.close(stream);
2617
- }
2618
- }
2619
- },
2620
- findObject(path, dontResolveLastLink) {
2621
- var ret = FS.analyzePath(path, dontResolveLastLink);
2622
- if (!ret.exists) {
2623
- return null;
2624
- }
2625
- return ret.object;
2626
- },
2627
- analyzePath(path, dontResolveLastLink) {
2628
- // operate from within the context of the symlink's target
2629
- try {
2630
- var lookup = FS.lookupPath(path, {
2631
- follow: !dontResolveLastLink
2632
- });
2633
- path = lookup.path;
2634
- } catch (e) {}
2635
- var ret = {
2636
- isRoot: false,
2637
- exists: false,
2638
- error: 0,
2639
- name: null,
2640
- path: null,
2641
- object: null,
2642
- parentExists: false,
2643
- parentPath: null,
2644
- parentObject: null
2645
- };
2646
- try {
2647
- var lookup = FS.lookupPath(path, {
2648
- parent: true
2649
- });
2650
- ret.parentExists = true;
2651
- ret.parentPath = lookup.path;
2652
- ret.parentObject = lookup.node;
2653
- ret.name = PATH.basename(path);
2654
- lookup = FS.lookupPath(path, {
2655
- follow: !dontResolveLastLink
2656
- });
2657
- ret.exists = true;
2658
- ret.path = lookup.path;
2659
- ret.object = lookup.node;
2660
- ret.name = lookup.node.name;
2661
- ret.isRoot = lookup.path === "/";
2662
- } catch (e) {
2663
- ret.error = e.errno;
2664
- }
2665
- return ret;
2666
- },
2667
- createPath(parent, path, canRead, canWrite) {
2668
- parent = typeof parent == "string" ? parent : FS.getPath(parent);
2669
- var parts = path.split("/").reverse();
2670
- while (parts.length) {
2671
- var part = parts.pop();
2672
- if (!part) continue;
2673
- var current = PATH.join2(parent, part);
2674
- try {
2675
- FS.mkdir(current);
2676
- } catch (e) {
2677
- if (e.errno != 20) throw e;
2678
- }
2679
- parent = current;
2680
- }
2681
- return current;
2682
- },
2683
- createFile(parent, name, properties, canRead, canWrite) {
2684
- var path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name);
2685
- var mode = FS_getMode(canRead, canWrite);
2686
- return FS.create(path, mode);
2687
- },
2688
- createDataFile(parent, name, data, canRead, canWrite, canOwn) {
2689
- var path = name;
2690
- if (parent) {
2691
- parent = typeof parent == "string" ? parent : FS.getPath(parent);
2692
- path = name ? PATH.join2(parent, name) : parent;
2693
- }
2694
- var mode = FS_getMode(canRead, canWrite);
2695
- var node = FS.create(path, mode);
2696
- if (data) {
2697
- if (typeof data == "string") {
2698
- var arr = new Array(data.length);
2699
- for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
2700
- data = arr;
2701
- }
2702
- // make sure we can write to the file
2703
- FS.chmod(node, mode | 146);
2704
- var stream = FS.open(node, 577);
2705
- FS.write(stream, data, 0, data.length, 0, canOwn);
2706
- FS.close(stream);
2707
- FS.chmod(node, mode);
2708
- }
2709
- },
2710
- createDevice(parent, name, input, output) {
2711
- var path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name);
2712
- var mode = FS_getMode(!!input, !!output);
2713
- FS.createDevice.major ??= 64;
2714
- var dev = FS.makedev(FS.createDevice.major++, 0);
2715
- // Create a fake device that a set of stream ops to emulate
2716
- // the old behavior.
2717
- FS.registerDevice(dev, {
2718
- open(stream) {
2719
- stream.seekable = false;
2720
- },
2721
- close(stream) {
2722
- // flush any pending line data
2723
- if (output?.buffer?.length) {
2724
- output(10);
2725
- }
2726
- },
2727
- read(stream, buffer, offset, length, pos) {
2728
- var bytesRead = 0;
2729
- for (var i = 0; i < length; i++) {
2730
- var result;
2731
- try {
2732
- result = input();
2733
- } catch (e) {
2734
- throw new FS.ErrnoError(29);
2735
- }
2736
- if (result === undefined && bytesRead === 0) {
2737
- throw new FS.ErrnoError(6);
2738
- }
2739
- if (result === null || result === undefined) break;
2740
- bytesRead++;
2741
- buffer[offset + i] = result;
2742
- }
2743
- if (bytesRead) {
2744
- stream.node.atime = Date.now();
2745
- }
2746
- return bytesRead;
2747
- },
2748
- write(stream, buffer, offset, length, pos) {
2749
- for (var i = 0; i < length; i++) {
2750
- try {
2751
- output(buffer[offset + i]);
2752
- } catch (e) {
2753
- throw new FS.ErrnoError(29);
2754
- }
2755
- }
2756
- if (length) {
2757
- stream.node.mtime = stream.node.ctime = Date.now();
2758
- }
2759
- return i;
2760
- }
2761
- });
2762
- return FS.mkdev(path, mode, dev);
2763
- },
2764
- forceLoadFile(obj) {
2765
- if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
2766
- if (typeof XMLHttpRequest != "undefined") {
2767
- 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.");
2768
- } else {
2769
- // Command-line.
2770
- try {
2771
- obj.contents = readBinary(obj.url);
2772
- obj.usedBytes = obj.contents.length;
2773
- } catch (e) {
2774
- throw new FS.ErrnoError(29);
2775
- }
2776
- }
2777
- },
2778
- createLazyFile(parent, name, url, canRead, canWrite) {
2779
- // Lazy chunked Uint8Array (implements get and length from Uint8Array).
2780
- // Actual getting is abstracted away for eventual reuse.
2781
- class LazyUint8Array {
2782
- lengthKnown=false;
2783
- chunks=[];
2784
- // Loaded chunks. Index is the chunk number
2785
- get(idx) {
2786
- if (idx > this.length - 1 || idx < 0) {
2787
- return undefined;
2788
- }
2789
- var chunkOffset = idx % this.chunkSize;
2790
- var chunkNum = (idx / this.chunkSize) | 0;
2791
- return this.getter(chunkNum)[chunkOffset];
2792
- }
2793
- setDataGetter(getter) {
2794
- this.getter = getter;
2795
- }
2796
- cacheLength() {
2797
- // Find length
2798
- var xhr = new XMLHttpRequest;
2799
- xhr.open("HEAD", url, false);
2800
- xhr.send(null);
2801
- if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
2802
- var datalength = Number(xhr.getResponseHeader("Content-length"));
2803
- var header;
2804
- var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
2805
- var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
2806
- var chunkSize = 1024 * 1024;
2807
- // Chunk size in bytes
2808
- if (!hasByteServing) chunkSize = datalength;
2809
- // Function to get a range from the remote URL.
2810
- var doXHR = (from, to) => {
2811
- if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
2812
- if (to > datalength - 1) throw new Error("only " + datalength + " bytes available! programmer error!");
2813
- // TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
2814
- var xhr = new XMLHttpRequest;
2815
- xhr.open("GET", url, false);
2816
- if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
2817
- // Some hints to the browser that we want binary data.
2818
- xhr.responseType = "arraybuffer";
2819
- if (xhr.overrideMimeType) {
2820
- xhr.overrideMimeType("text/plain; charset=x-user-defined");
2821
- }
2822
- xhr.send(null);
2823
- if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
2824
- if (xhr.response !== undefined) {
2825
- return new Uint8Array(/** @type{Array<number>} */ (xhr.response || []));
2826
- }
2827
- return intArrayFromString(xhr.responseText || "", true);
2828
- };
2829
- var lazyArray = this;
2830
- lazyArray.setDataGetter(chunkNum => {
2831
- var start = chunkNum * chunkSize;
2832
- var end = (chunkNum + 1) * chunkSize - 1;
2833
- // including this byte
2834
- end = Math.min(end, datalength - 1);
2835
- // if datalength-1 is selected, this is the last block
2836
- if (typeof lazyArray.chunks[chunkNum] == "undefined") {
2837
- lazyArray.chunks[chunkNum] = doXHR(start, end);
2838
- }
2839
- if (typeof lazyArray.chunks[chunkNum] == "undefined") throw new Error("doXHR failed!");
2840
- return lazyArray.chunks[chunkNum];
2841
- });
2842
- if (usesGzip || !datalength) {
2843
- // if the server uses gzip or doesn't supply the length, we have to download the whole file to get the (uncompressed) length
2844
- chunkSize = datalength = 1;
2845
- // this will force getter(0)/doXHR do download the whole file
2846
- datalength = this.getter(0).length;
2847
- chunkSize = datalength;
2848
- out("LazyFiles on gzip forces download of the whole file when length is accessed");
2849
- }
2850
- this._length = datalength;
2851
- this._chunkSize = chunkSize;
2852
- this.lengthKnown = true;
2853
- }
2854
- get length() {
2855
- if (!this.lengthKnown) {
2856
- this.cacheLength();
2857
- }
2858
- return this._length;
2859
- }
2860
- get chunkSize() {
2861
- if (!this.lengthKnown) {
2862
- this.cacheLength();
2863
- }
2864
- return this._chunkSize;
2865
- }
2866
- }
2867
- if (typeof XMLHttpRequest != "undefined") {
2868
- if (!ENVIRONMENT_IS_WORKER) throw "Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc";
2869
- var lazyArray = new LazyUint8Array;
2870
- var properties = {
2871
- isDevice: false,
2872
- contents: lazyArray
2873
- };
2874
- } else {
2875
- var properties = {
2876
- isDevice: false,
2877
- url
2878
- };
2879
- }
2880
- var node = FS.createFile(parent, name, properties, canRead, canWrite);
2881
- // This is a total hack, but I want to get this lazy file code out of the
2882
- // core of MEMFS. If we want to keep this lazy file concept I feel it should
2883
- // be its own thin LAZYFS proxying calls to MEMFS.
2884
- if (properties.contents) {
2885
- node.contents = properties.contents;
2886
- } else if (properties.url) {
2887
- node.contents = null;
2888
- node.url = properties.url;
2889
- }
2890
- // Add a function that defers querying the file size until it is asked the first time.
2891
- Object.defineProperties(node, {
2892
- usedBytes: {
2893
- get: function() {
2894
- return this.contents.length;
2895
- }
2896
- }
2897
- });
2898
- // override each stream op with one that tries to force load the lazy file first
2899
- var stream_ops = {};
2900
- var keys = Object.keys(node.stream_ops);
2901
- keys.forEach(key => {
2902
- var fn = node.stream_ops[key];
2903
- stream_ops[key] = (...args) => {
2904
- FS.forceLoadFile(node);
2905
- return fn(...args);
2906
- };
2907
- });
2908
- function writeChunks(stream, buffer, offset, length, position) {
2909
- var contents = stream.node.contents;
2910
- if (position >= contents.length) return 0;
2911
- var size = Math.min(contents.length - position, length);
2912
- if (contents.slice) {
2913
- // normal array
2914
- for (var i = 0; i < size; i++) {
2915
- buffer[offset + i] = contents[position + i];
2916
- }
2917
- } else {
2918
- for (var i = 0; i < size; i++) {
2919
- // LazyUint8Array from sync binary XHR
2920
- buffer[offset + i] = contents.get(position + i);
2921
- }
2922
- }
2923
- return size;
2924
- }
2925
- // use a custom read function
2926
- stream_ops.read = (stream, buffer, offset, length, position) => {
2927
- FS.forceLoadFile(node);
2928
- return writeChunks(stream, buffer, offset, length, position);
2929
- };
2930
- // use a custom mmap function
2931
- stream_ops.mmap = (stream, length, position, prot, flags) => {
2932
- FS.forceLoadFile(node);
2933
- var ptr = mmapAlloc(length);
2934
- if (!ptr) {
2935
- throw new FS.ErrnoError(48);
2936
- }
2937
- writeChunks(stream, HEAP8, ptr, length, position);
2938
- return {
2939
- ptr,
2940
- allocated: true
2941
- };
2942
- };
2943
- node.stream_ops = stream_ops;
2944
- return node;
2945
- }
2946
- };
2947
-
2948
- var SYSCALLS = {
2949
- DEFAULT_POLLMASK: 5,
2950
- calculateAt(dirfd, path, allowEmpty) {
2951
- if (PATH.isAbs(path)) {
2952
- return path;
2953
- }
2954
- // relative path
2955
- var dir;
2956
- if (dirfd === -100) {
2957
- dir = FS.cwd();
2958
- } else {
2959
- var dirstream = SYSCALLS.getStreamFromFD(dirfd);
2960
- dir = dirstream.path;
2961
- }
2962
- if (path.length == 0) {
2963
- if (!allowEmpty) {
2964
- throw new FS.ErrnoError(44);
2965
- }
2966
- return dir;
2967
- }
2968
- return dir + "/" + path;
2969
- },
2970
- writeStat(buf, stat) {
2971
- HEAP32[((buf) >> 2)] = stat.dev;
2972
- HEAP32[(((buf) + (4)) >> 2)] = stat.mode;
2973
- HEAPU32[(((buf) + (8)) >> 2)] = stat.nlink;
2974
- HEAP32[(((buf) + (12)) >> 2)] = stat.uid;
2975
- HEAP32[(((buf) + (16)) >> 2)] = stat.gid;
2976
- HEAP32[(((buf) + (20)) >> 2)] = stat.rdev;
2977
- HEAP64[(((buf) + (24)) >> 3)] = BigInt(stat.size);
2978
- HEAP32[(((buf) + (32)) >> 2)] = 4096;
2979
- HEAP32[(((buf) + (36)) >> 2)] = stat.blocks;
2980
- var atime = stat.atime.getTime();
2981
- var mtime = stat.mtime.getTime();
2982
- var ctime = stat.ctime.getTime();
2983
- HEAP64[(((buf) + (40)) >> 3)] = BigInt(Math.floor(atime / 1e3));
2984
- HEAPU32[(((buf) + (48)) >> 2)] = (atime % 1e3) * 1e3 * 1e3;
2985
- HEAP64[(((buf) + (56)) >> 3)] = BigInt(Math.floor(mtime / 1e3));
2986
- HEAPU32[(((buf) + (64)) >> 2)] = (mtime % 1e3) * 1e3 * 1e3;
2987
- HEAP64[(((buf) + (72)) >> 3)] = BigInt(Math.floor(ctime / 1e3));
2988
- HEAPU32[(((buf) + (80)) >> 2)] = (ctime % 1e3) * 1e3 * 1e3;
2989
- HEAP64[(((buf) + (88)) >> 3)] = BigInt(stat.ino);
2990
- return 0;
2991
- },
2992
- writeStatFs(buf, stats) {
2993
- HEAP32[(((buf) + (4)) >> 2)] = stats.bsize;
2994
- HEAP32[(((buf) + (40)) >> 2)] = stats.bsize;
2995
- HEAP32[(((buf) + (8)) >> 2)] = stats.blocks;
2996
- HEAP32[(((buf) + (12)) >> 2)] = stats.bfree;
2997
- HEAP32[(((buf) + (16)) >> 2)] = stats.bavail;
2998
- HEAP32[(((buf) + (20)) >> 2)] = stats.files;
2999
- HEAP32[(((buf) + (24)) >> 2)] = stats.ffree;
3000
- HEAP32[(((buf) + (28)) >> 2)] = stats.fsid;
3001
- HEAP32[(((buf) + (44)) >> 2)] = stats.flags;
3002
- // ST_NOSUID
3003
- HEAP32[(((buf) + (36)) >> 2)] = stats.namelen;
3004
- },
3005
- doMsync(addr, stream, len, flags, offset) {
3006
- if (!FS.isFile(stream.node.mode)) {
3007
- throw new FS.ErrnoError(43);
3008
- }
3009
- if (flags & 2) {
3010
- // MAP_PRIVATE calls need not to be synced back to underlying fs
3011
- return 0;
3012
- }
3013
- var buffer = HEAPU8.slice(addr, addr + len);
3014
- FS.msync(stream, buffer, offset, len, flags);
3015
- },
3016
- getStreamFromFD(fd) {
3017
- var stream = FS.getStreamChecked(fd);
3018
- return stream;
3019
- },
3020
- varargs: undefined,
3021
- getStr(ptr) {
3022
- var ret = UTF8ToString(ptr);
3023
- return ret;
3024
- }
3025
- };
3026
-
3027
- function ___syscall_chmod(path, mode) {
3028
- try {
3029
- path = SYSCALLS.getStr(path);
3030
- FS.chmod(path, mode);
3031
- return 0;
3032
- } catch (e) {
3033
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3034
- return -e.errno;
3035
- }
3036
- }
3037
-
3038
- function ___syscall_fchmod(fd, mode) {
3039
- try {
3040
- FS.fchmod(fd, mode);
3041
- return 0;
3042
- } catch (e) {
3043
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3044
- return -e.errno;
3045
- }
3046
- }
3047
-
3048
- function ___syscall_fchown32(fd, owner, group) {
3049
- try {
3050
- FS.fchown(fd, owner, group);
3051
- return 0;
3052
- } catch (e) {
3053
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3054
- return -e.errno;
3055
- }
3056
- }
3057
-
3058
- /** @suppress {duplicate } */ var syscallGetVarargI = () => {
3059
- // the `+` prepended here is necessary to convince the JSCompiler that varargs is indeed a number.
3060
- var ret = HEAP32[((+SYSCALLS.varargs) >> 2)];
3061
- SYSCALLS.varargs += 4;
3062
- return ret;
3063
- };
3064
-
3065
- var syscallGetVarargP = syscallGetVarargI;
3066
-
3067
- function ___syscall_fcntl64(fd, cmd, varargs) {
3068
- SYSCALLS.varargs = varargs;
3069
- try {
3070
- var stream = SYSCALLS.getStreamFromFD(fd);
3071
- switch (cmd) {
3072
- case 0:
3073
- {
3074
- var arg = syscallGetVarargI();
3075
- if (arg < 0) {
3076
- return -28;
3077
- }
3078
- while (FS.streams[arg]) {
3079
- arg++;
3080
- }
3081
- var newStream;
3082
- newStream = FS.dupStream(stream, arg);
3083
- return newStream.fd;
3084
- }
3085
-
3086
- case 1:
3087
- case 2:
3088
- return 0;
3089
-
3090
- // FD_CLOEXEC makes no sense for a single process.
3091
- case 3:
3092
- return stream.flags;
3093
-
3094
- case 4:
3095
- {
3096
- var arg = syscallGetVarargI();
3097
- stream.flags |= arg;
3098
- return 0;
3099
- }
3100
-
3101
- case 12:
3102
- {
3103
- var arg = syscallGetVarargP();
3104
- var offset = 0;
3105
- // We're always unlocked.
3106
- HEAP16[(((arg) + (offset)) >> 1)] = 2;
3107
- return 0;
3108
- }
3109
-
3110
- case 13:
3111
- case 14:
3112
- // Pretend that the locking is successful. These are process-level locks,
3113
- // and Emscripten programs are a single process. If we supported linking a
3114
- // filesystem between programs, we'd need to do more here.
3115
- // See https://github.com/emscripten-core/emscripten/issues/23697
3116
- return 0;
3117
- }
3118
- return -28;
3119
- } catch (e) {
3120
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3121
- return -e.errno;
3122
- }
3123
- }
3124
-
3125
- function ___syscall_fstat64(fd, buf) {
3126
- try {
3127
- return SYSCALLS.writeStat(buf, FS.fstat(fd));
3128
- } catch (e) {
3129
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3130
- return -e.errno;
3131
- }
3132
- }
3133
-
3134
- function ___syscall_ioctl(fd, op, varargs) {
3135
- SYSCALLS.varargs = varargs;
3136
- try {
3137
- var stream = SYSCALLS.getStreamFromFD(fd);
3138
- switch (op) {
3139
- case 21509:
3140
- {
3141
- if (!stream.tty) return -59;
3142
- return 0;
3143
- }
3144
-
3145
- case 21505:
3146
- {
3147
- if (!stream.tty) return -59;
3148
- if (stream.tty.ops.ioctl_tcgets) {
3149
- var termios = stream.tty.ops.ioctl_tcgets(stream);
3150
- var argp = syscallGetVarargP();
3151
- HEAP32[((argp) >> 2)] = termios.c_iflag || 0;
3152
- HEAP32[(((argp) + (4)) >> 2)] = termios.c_oflag || 0;
3153
- HEAP32[(((argp) + (8)) >> 2)] = termios.c_cflag || 0;
3154
- HEAP32[(((argp) + (12)) >> 2)] = termios.c_lflag || 0;
3155
- for (var i = 0; i < 32; i++) {
3156
- HEAP8[(argp + i) + (17)] = termios.c_cc[i] || 0;
3157
- }
3158
- return 0;
3159
- }
3160
- return 0;
3161
- }
3162
-
3163
- case 21510:
3164
- case 21511:
3165
- case 21512:
3166
- {
3167
- if (!stream.tty) return -59;
3168
- return 0;
3169
- }
3170
-
3171
- case 21506:
3172
- case 21507:
3173
- case 21508:
3174
- {
3175
- if (!stream.tty) return -59;
3176
- if (stream.tty.ops.ioctl_tcsets) {
3177
- var argp = syscallGetVarargP();
3178
- var c_iflag = HEAP32[((argp) >> 2)];
3179
- var c_oflag = HEAP32[(((argp) + (4)) >> 2)];
3180
- var c_cflag = HEAP32[(((argp) + (8)) >> 2)];
3181
- var c_lflag = HEAP32[(((argp) + (12)) >> 2)];
3182
- var c_cc = [];
3183
- for (var i = 0; i < 32; i++) {
3184
- c_cc.push(HEAP8[(argp + i) + (17)]);
3185
- }
3186
- return stream.tty.ops.ioctl_tcsets(stream.tty, op, {
3187
- c_iflag,
3188
- c_oflag,
3189
- c_cflag,
3190
- c_lflag,
3191
- c_cc
3192
- });
3193
- }
3194
- return 0;
3195
- }
3196
-
3197
- case 21519:
3198
- {
3199
- if (!stream.tty) return -59;
3200
- var argp = syscallGetVarargP();
3201
- HEAP32[((argp) >> 2)] = 0;
3202
- return 0;
3203
- }
3204
-
3205
- case 21520:
3206
- {
3207
- if (!stream.tty) return -59;
3208
- return -28;
3209
- }
3210
-
3211
- case 21531:
3212
- {
3213
- var argp = syscallGetVarargP();
3214
- return FS.ioctl(stream, op, argp);
3215
- }
3216
-
3217
- case 21523:
3218
- {
3219
- // TODO: in theory we should write to the winsize struct that gets
3220
- // passed in, but for now musl doesn't read anything on it
3221
- if (!stream.tty) return -59;
3222
- if (stream.tty.ops.ioctl_tiocgwinsz) {
3223
- var winsize = stream.tty.ops.ioctl_tiocgwinsz(stream.tty);
3224
- var argp = syscallGetVarargP();
3225
- HEAP16[((argp) >> 1)] = winsize[0];
3226
- HEAP16[(((argp) + (2)) >> 1)] = winsize[1];
3227
- }
3228
- return 0;
3229
- }
3230
-
3231
- case 21524:
3232
- {
3233
- // TODO: technically, this ioctl call should change the window size.
3234
- // but, since emscripten doesn't have any concept of a terminal window
3235
- // yet, we'll just silently throw it away as we do TIOCGWINSZ
3236
- if (!stream.tty) return -59;
3237
- return 0;
3238
- }
3239
-
3240
- case 21515:
3241
- {
3242
- if (!stream.tty) return -59;
3243
- return 0;
3244
- }
3245
-
3246
- default:
3247
- return -28;
3248
- }
3249
- } catch (e) {
3250
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3251
- return -e.errno;
3252
- }
3253
- }
3254
-
3255
- function ___syscall_newfstatat(dirfd, path, buf, flags) {
3256
- try {
3257
- path = SYSCALLS.getStr(path);
3258
- var nofollow = flags & 256;
3259
- var allowEmpty = flags & 4096;
3260
- flags = flags & (~6400);
3261
- path = SYSCALLS.calculateAt(dirfd, path, allowEmpty);
3262
- return SYSCALLS.writeStat(buf, nofollow ? FS.lstat(path) : FS.stat(path));
3263
- } catch (e) {
3264
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3265
- return -e.errno;
3266
- }
3267
- }
3268
-
3269
- function ___syscall_openat(dirfd, path, flags, varargs) {
3270
- SYSCALLS.varargs = varargs;
3271
- try {
3272
- path = SYSCALLS.getStr(path);
3273
- path = SYSCALLS.calculateAt(dirfd, path);
3274
- var mode = varargs ? syscallGetVarargI() : 0;
3275
- return FS.open(path, flags, mode).fd;
3276
- } catch (e) {
3277
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3278
- return -e.errno;
3279
- }
3280
- }
3281
-
3282
- var stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
3283
-
3284
- function ___syscall_readlinkat(dirfd, path, buf, bufsize) {
3285
- try {
3286
- path = SYSCALLS.getStr(path);
3287
- path = SYSCALLS.calculateAt(dirfd, path);
3288
- if (bufsize <= 0) return -28;
3289
- var ret = FS.readlink(path);
3290
- var len = Math.min(bufsize, lengthBytesUTF8(ret));
3291
- var endChar = HEAP8[buf + len];
3292
- stringToUTF8(ret, buf, bufsize + 1);
3293
- // readlink is one of the rare functions that write out a C string, but does never append a null to the output buffer(!)
3294
- // stringToUTF8() always appends a null byte, so restore the character under the null byte after the write.
3295
- HEAP8[buf + len] = endChar;
3296
- return len;
3297
- } catch (e) {
3298
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3299
- return -e.errno;
3300
- }
3301
- }
3302
-
3303
- function ___syscall_renameat(olddirfd, oldpath, newdirfd, newpath) {
3304
- try {
3305
- oldpath = SYSCALLS.getStr(oldpath);
3306
- newpath = SYSCALLS.getStr(newpath);
3307
- oldpath = SYSCALLS.calculateAt(olddirfd, oldpath);
3308
- newpath = SYSCALLS.calculateAt(newdirfd, newpath);
3309
- FS.rename(oldpath, newpath);
3310
- return 0;
3311
- } catch (e) {
3312
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3313
- return -e.errno;
3314
- }
3315
- }
3316
-
3317
- function ___syscall_unlinkat(dirfd, path, flags) {
3318
- try {
3319
- path = SYSCALLS.getStr(path);
3320
- path = SYSCALLS.calculateAt(dirfd, path);
3321
- if (!flags) {
3322
- FS.unlink(path);
3323
- } else if (flags === 512) {
3324
- FS.rmdir(path);
3325
- } else {
3326
- return -28;
3327
- }
3328
- return 0;
3329
- } catch (e) {
3330
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3331
- return -e.errno;
3332
- }
3333
- }
3334
-
3335
- var __abort_js = () => abort("");
3336
-
3337
- var getExecutableName = () => thisProgram || "./this.program";
3338
-
3339
- var __emscripten_get_progname = (str, len) => stringToUTF8(getExecutableName(), str, len);
3340
-
3341
- var _emscripten_get_now = () => performance.now();
3342
-
3343
- var _emscripten_date_now = () => Date.now();
3344
-
3345
- var nowIsMonotonic = 1;
3346
-
3347
- var checkWasiClock = clock_id => clock_id >= 0 && clock_id <= 3;
3348
-
3349
- var INT53_MAX = 9007199254740992;
3350
-
3351
- var INT53_MIN = -9007199254740992;
3352
-
3353
- var bigintToI53Checked = num => (num < INT53_MIN || num > INT53_MAX) ? NaN : Number(num);
3354
-
3355
- function _clock_time_get(clk_id, ignored_precision, ptime) {
3356
- ignored_precision = bigintToI53Checked(ignored_precision);
3357
- if (!checkWasiClock(clk_id)) {
3358
- return 28;
3359
- }
3360
- var now;
3361
- // all wasi clocks but realtime are monotonic
3362
- if (clk_id === 0) {
3363
- now = _emscripten_date_now();
3364
- } else if (nowIsMonotonic) {
3365
- now = _emscripten_get_now();
3366
- } else {
3367
- return 52;
3368
- }
3369
- // "now" is in ms, and wasi times are in ns.
3370
- var nsec = Math.round(now * 1e3 * 1e3);
3371
- HEAP64[((ptime) >> 3)] = BigInt(nsec);
3372
- return 0;
3373
- }
3374
-
3375
- var getHeapMax = () => // Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
3376
- // full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
3377
- // for any code that deals with heap sizes, which would require special
3378
- // casing all heap size related code to treat 0 specially.
3379
- 2147483648;
3380
-
3381
- var alignMemory = (size, alignment) => Math.ceil(size / alignment) * alignment;
3382
-
3383
- var growMemory = size => {
3384
- var b = wasmMemory.buffer;
3385
- var pages = ((size - b.byteLength + 65535) / 65536) | 0;
3386
- try {
3387
- // round size grow request up to wasm page size (fixed 64KB per spec)
3388
- wasmMemory.grow(pages);
3389
- // .grow() takes a delta compared to the previous size
3390
- updateMemoryViews();
3391
- return 1;
3392
- } catch (e) {}
3393
- };
3394
-
3395
- var _emscripten_resize_heap = requestedSize => {
3396
- var oldSize = HEAPU8.length;
3397
- // With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
3398
- requestedSize >>>= 0;
3399
- // With multithreaded builds, races can happen (another thread might increase the size
3400
- // in between), so return a failure, and let the caller retry.
3401
- // Memory resize rules:
3402
- // 1. Always increase heap size to at least the requested size, rounded up
3403
- // to next page multiple.
3404
- // 2a. If MEMORY_GROWTH_LINEAR_STEP == -1, excessively resize the heap
3405
- // geometrically: increase the heap size according to
3406
- // MEMORY_GROWTH_GEOMETRIC_STEP factor (default +20%), At most
3407
- // overreserve by MEMORY_GROWTH_GEOMETRIC_CAP bytes (default 96MB).
3408
- // 2b. If MEMORY_GROWTH_LINEAR_STEP != -1, excessively resize the heap
3409
- // linearly: increase the heap size by at least
3410
- // MEMORY_GROWTH_LINEAR_STEP bytes.
3411
- // 3. Max size for the heap is capped at 2048MB-WASM_PAGE_SIZE, or by
3412
- // MAXIMUM_MEMORY, or by ASAN limit, depending on which is smallest
3413
- // 4. If we were unable to allocate as much memory, it may be due to
3414
- // over-eager decision to excessively reserve due to (3) above.
3415
- // Hence if an allocation fails, cut down on the amount of excess
3416
- // growth, in an attempt to succeed to perform a smaller allocation.
3417
- // A limit is set for how much we can grow. We should not exceed that
3418
- // (the wasm binary specifies it, so if we tried, we'd fail anyhow).
3419
- var maxHeapSize = getHeapMax();
3420
- if (requestedSize > maxHeapSize) {
3421
- return false;
3422
- }
3423
- // Loop through potential heap size increases. If we attempt a too eager
3424
- // reservation that fails, cut down on the attempted size and reserve a
3425
- // smaller bump instead. (max 3 times, chosen somewhat arbitrarily)
3426
- for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
3427
- var overGrownHeapSize = oldSize * (1 + .2 / cutDown);
3428
- // ensure geometric growth
3429
- // but limit overreserving (default to capping at +96MB overgrowth at most)
3430
- overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296);
3431
- var newSize = Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536));
3432
- var replacement = growMemory(newSize);
3433
- if (replacement) {
3434
- return true;
3435
- }
3436
- }
3437
- return false;
3438
- };
3439
-
3440
- var ENV = {};
3441
-
3442
- var getEnvStrings = () => {
3443
- if (!getEnvStrings.strings) {
3444
- // Default values.
3445
- // Browser language detection #8751
3446
- var lang = ((typeof navigator == "object" && navigator.languages && navigator.languages[0]) || "C").replace("-", "_") + ".UTF-8";
3447
- var env = {
3448
- "USER": "web_user",
3449
- "LOGNAME": "web_user",
3450
- "PATH": "/",
3451
- "PWD": "/",
3452
- "HOME": "/home/web_user",
3453
- "LANG": lang,
3454
- "_": getExecutableName()
3455
- };
3456
- // Apply the user-provided values, if any.
3457
- for (var x in ENV) {
3458
- // x is a key in ENV; if ENV[x] is undefined, that means it was
3459
- // explicitly set to be so. We allow user code to do that to
3460
- // force variables with default values to remain unset.
3461
- if (ENV[x] === undefined) delete env[x]; else env[x] = ENV[x];
3462
- }
3463
- var strings = [];
3464
- for (var x in env) {
3465
- strings.push(`${x}=${env[x]}`);
3466
- }
3467
- getEnvStrings.strings = strings;
3468
- }
3469
- return getEnvStrings.strings;
3470
- };
3471
-
3472
- var _environ_get = (__environ, environ_buf) => {
3473
- var bufSize = 0;
3474
- var envp = 0;
3475
- for (var string of getEnvStrings()) {
3476
- var ptr = environ_buf + bufSize;
3477
- HEAPU32[(((__environ) + (envp)) >> 2)] = ptr;
3478
- bufSize += stringToUTF8(string, ptr, Infinity) + 1;
3479
- envp += 4;
3480
- }
3481
- return 0;
3482
- };
3483
-
3484
- var _environ_sizes_get = (penviron_count, penviron_buf_size) => {
3485
- var strings = getEnvStrings();
3486
- HEAPU32[((penviron_count) >> 2)] = strings.length;
3487
- var bufSize = 0;
3488
- for (var string of strings) {
3489
- bufSize += lengthBytesUTF8(string) + 1;
3490
- }
3491
- HEAPU32[((penviron_buf_size) >> 2)] = bufSize;
3492
- return 0;
3493
- };
3494
-
3495
- var runtimeKeepaliveCounter = 0;
3496
-
3497
- var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
3498
-
3499
- var _proc_exit = code => {
3500
- EXITSTATUS = code;
3501
- if (!keepRuntimeAlive()) {
3502
- Module["onExit"]?.(code);
3503
- ABORT = true;
3504
- }
3505
- quit_(code, new ExitStatus(code));
3506
- };
3507
-
3508
- /** @suppress {duplicate } */ /** @param {boolean|number=} implicit */ var exitJS = (status, implicit) => {
3509
- EXITSTATUS = status;
3510
- if (!keepRuntimeAlive()) {
3511
- exitRuntime();
3512
- }
3513
- _proc_exit(status);
3514
- };
3515
-
3516
- var _exit = exitJS;
3517
-
3518
- function _fd_close(fd) {
3519
- try {
3520
- var stream = SYSCALLS.getStreamFromFD(fd);
3521
- FS.close(stream);
3522
- return 0;
3523
- } catch (e) {
3524
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3525
- return e.errno;
3526
- }
3527
- }
3528
-
3529
- function _fd_fdstat_get(fd, pbuf) {
3530
- try {
3531
- var rightsBase = 0;
3532
- var rightsInheriting = 0;
3533
- var flags = 0;
3534
- {
3535
- var stream = SYSCALLS.getStreamFromFD(fd);
3536
- // All character devices are terminals (other things a Linux system would
3537
- // assume is a character device, like the mouse, we have special APIs for).
3538
- var type = stream.tty ? 2 : FS.isDir(stream.mode) ? 3 : FS.isLink(stream.mode) ? 7 : 4;
3539
- }
3540
- HEAP8[pbuf] = type;
3541
- HEAP16[(((pbuf) + (2)) >> 1)] = flags;
3542
- HEAP64[(((pbuf) + (8)) >> 3)] = BigInt(rightsBase);
3543
- HEAP64[(((pbuf) + (16)) >> 3)] = BigInt(rightsInheriting);
3544
- return 0;
3545
- } catch (e) {
3546
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3547
- return e.errno;
3548
- }
3549
- }
3550
-
3551
- /** @param {number=} offset */ var doReadv = (stream, iov, iovcnt, offset) => {
3552
- var ret = 0;
3553
- for (var i = 0; i < iovcnt; i++) {
3554
- var ptr = HEAPU32[((iov) >> 2)];
3555
- var len = HEAPU32[(((iov) + (4)) >> 2)];
3556
- iov += 8;
3557
- var curr = FS.read(stream, HEAP8, ptr, len, offset);
3558
- if (curr < 0) return -1;
3559
- ret += curr;
3560
- if (curr < len) break;
3561
- // nothing more to read
3562
- if (typeof offset != "undefined") {
3563
- offset += curr;
3564
- }
3565
- }
3566
- return ret;
3567
- };
3568
-
3569
- function _fd_read(fd, iov, iovcnt, pnum) {
3570
- try {
3571
- var stream = SYSCALLS.getStreamFromFD(fd);
3572
- var num = doReadv(stream, iov, iovcnt);
3573
- HEAPU32[((pnum) >> 2)] = num;
3574
- return 0;
3575
- } catch (e) {
3576
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3577
- return e.errno;
3578
- }
3579
- }
3580
-
3581
- function _fd_seek(fd, offset, whence, newOffset) {
3582
- offset = bigintToI53Checked(offset);
3583
- try {
3584
- if (isNaN(offset)) return 61;
3585
- var stream = SYSCALLS.getStreamFromFD(fd);
3586
- FS.llseek(stream, offset, whence);
3587
- HEAP64[((newOffset) >> 3)] = BigInt(stream.position);
3588
- if (stream.getdents && offset === 0 && whence === 0) stream.getdents = null;
3589
- // reset readdir state
3590
- return 0;
3591
- } catch (e) {
3592
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3593
- return e.errno;
3594
- }
3595
- }
3596
-
3597
- /** @param {number=} offset */ var doWritev = (stream, iov, iovcnt, offset) => {
3598
- var ret = 0;
3599
- for (var i = 0; i < iovcnt; i++) {
3600
- var ptr = HEAPU32[((iov) >> 2)];
3601
- var len = HEAPU32[(((iov) + (4)) >> 2)];
3602
- iov += 8;
3603
- var curr = FS.write(stream, HEAP8, ptr, len, offset);
3604
- if (curr < 0) return -1;
3605
- ret += curr;
3606
- if (curr < len) {
3607
- // No more space to write.
3608
- break;
3609
- }
3610
- if (typeof offset != "undefined") {
3611
- offset += curr;
3612
- }
3613
- }
3614
- return ret;
3615
- };
3616
-
3617
- function _fd_write(fd, iov, iovcnt, pnum) {
3618
- try {
3619
- var stream = SYSCALLS.getStreamFromFD(fd);
3620
- var num = doWritev(stream, iov, iovcnt);
3621
- HEAPU32[((pnum) >> 2)] = num;
3622
- return 0;
3623
- } catch (e) {
3624
- if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3625
- return e.errno;
3626
- }
3627
- }
3628
-
3629
- var handleException = e => {
3630
- // Certain exception types we do not treat as errors since they are used for
3631
- // internal control flow.
3632
- // 1. ExitStatus, which is thrown by exit()
3633
- // 2. "unwind", which is thrown by emscripten_unwind_to_js_event_loop() and others
3634
- // that wish to return to JS event loop.
3635
- if (e instanceof ExitStatus || e == "unwind") {
3636
- return EXITSTATUS;
3637
- }
3638
- quit_(1, e);
3639
- };
3640
-
3641
- var stackAlloc = sz => __emscripten_stack_alloc(sz);
3642
-
3643
- var stringToUTF8OnStack = str => {
3644
- var size = lengthBytesUTF8(str) + 1;
3645
- var ret = stackAlloc(size);
3646
- stringToUTF8(str, ret, size);
3647
- return ret;
3648
- };
3649
-
3650
- var FS_createPath = (...args) => FS.createPath(...args);
3651
-
3652
- var FS_unlink = (...args) => FS.unlink(...args);
3653
-
3654
- var FS_createLazyFile = (...args) => FS.createLazyFile(...args);
3655
-
3656
- var FS_createDevice = (...args) => FS.createDevice(...args);
3657
-
3658
- FS.createPreloadedFile = FS_createPreloadedFile;
3659
-
3660
- FS.staticInit();
3661
-
3662
- // This error may happen quite a bit. To avoid overhead we reuse it (and
3663
- // suffer a lack of stack info).
3664
- MEMFS.doesNotExistError = new FS.ErrnoError(44);
3665
-
3666
- /** @suppress {checkTypes} */ MEMFS.doesNotExistError.stack = "<generic error, no stack>";
3667
-
3668
- // End JS library code
3669
- // include: postlibrary.js
3670
- // This file is included after the automatically-generated JS library code
3671
- // but before the wasm module is created.
3672
- {
3673
- // Begin ATMODULES hooks
3674
- if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"];
3675
- if (Module["preloadPlugins"]) preloadPlugins = Module["preloadPlugins"];
3676
- if (Module["print"]) out = Module["print"];
3677
- if (Module["printErr"]) err = Module["printErr"];
3678
- if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
3679
- // End ATMODULES hooks
3680
- if (Module["arguments"]) arguments_ = Module["arguments"];
3681
- if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
3682
- }
3683
-
3684
- // Begin runtime exports
3685
- Module["addRunDependency"] = addRunDependency;
3686
-
3687
- Module["removeRunDependency"] = removeRunDependency;
3688
-
3689
- Module["ENV"] = ENV;
3690
-
3691
- Module["getEnvStrings"] = getEnvStrings;
3692
-
3693
- Module["FS_createPreloadedFile"] = FS_createPreloadedFile;
3694
-
3695
- Module["FS_unlink"] = FS_unlink;
3696
-
3697
- Module["FS_createPath"] = FS_createPath;
3698
-
3699
- Module["FS_createDevice"] = FS_createDevice;
3700
-
3701
- Module["FS"] = FS;
3702
-
3703
- Module["FS_createDataFile"] = FS_createDataFile;
3704
-
3705
- Module["FS_createLazyFile"] = FS_createLazyFile;
3706
-
3707
- Module["TTY"] = TTY;
3708
-
3709
- // End runtime exports
3710
- // Begin JS library exports
3711
- // End JS library exports
3712
- // end include: postlibrary.js
3713
- var wasmImports = {
3714
- /** @export */ b: ___assert_fail,
3715
- /** @export */ d: ___syscall_chmod,
3716
- /** @export */ i: ___syscall_fchmod,
3717
- /** @export */ x: ___syscall_fchown32,
3718
- /** @export */ c: ___syscall_fcntl64,
3719
- /** @export */ w: ___syscall_fstat64,
3720
- /** @export */ l: ___syscall_ioctl,
3721
- /** @export */ v: ___syscall_newfstatat,
3722
- /** @export */ h: ___syscall_openat,
3723
- /** @export */ p: ___syscall_readlinkat,
3724
- /** @export */ o: ___syscall_renameat,
3725
- /** @export */ n: ___syscall_unlinkat,
3726
- /** @export */ j: __abort_js,
3727
- /** @export */ q: __emscripten_get_progname,
3728
- /** @export */ r: _clock_time_get,
3729
- /** @export */ m: _emscripten_resize_heap,
3730
- /** @export */ t: _environ_get,
3731
- /** @export */ u: _environ_sizes_get,
3732
- /** @export */ a: _exit,
3733
- /** @export */ f: _fd_close,
3734
- /** @export */ g: _fd_fdstat_get,
3735
- /** @export */ k: _fd_read,
3736
- /** @export */ s: _fd_seek,
3737
- /** @export */ e: _fd_write
3738
- };
3739
-
3740
- var wasmExports = await createWasm();
3741
-
3742
- // Imports from the Wasm binary.
3743
- var ___wasm_call_ctors = wasmExports["z"];
3744
-
3745
- var _main = Module["_main"] = wasmExports["A"];
3746
-
3747
- var ___funcs_on_exit = wasmExports["B"];
3748
-
3749
- var _fflush = wasmExports["C"];
3750
-
3751
- var __emscripten_stack_alloc = wasmExports["D"];
3752
-
3753
- // include: postamble.js
3754
- // === Auto-generated postamble setup entry stuff ===
3755
- function callMain(args = []) {
3756
- var entryFunction = _main;
3757
- args.unshift(thisProgram);
3758
- var argc = args.length;
3759
- var argv = stackAlloc((argc + 1) * 4);
3760
- var argv_ptr = argv;
3761
- args.forEach(arg => {
3762
- HEAPU32[((argv_ptr) >> 2)] = stringToUTF8OnStack(arg);
3763
- argv_ptr += 4;
3764
- });
3765
- HEAPU32[((argv_ptr) >> 2)] = 0;
3766
- try {
3767
- var ret = entryFunction(argc, argv);
3768
- // if we're not running an evented main loop, it's time to exit
3769
- exitJS(ret, /* implicit = */ true);
3770
- return ret;
3771
- } catch (e) {
3772
- return handleException(e);
3773
- }
3774
- }
3775
-
3776
- function run(args = arguments_) {
3777
- if (runDependencies > 0) {
3778
- dependenciesFulfilled = run;
3779
- return;
3780
- }
3781
- preRun();
3782
- // a preRun added a dependency, run will be called later
3783
- if (runDependencies > 0) {
3784
- dependenciesFulfilled = run;
3785
- return;
3786
- }
3787
- function doRun() {
3788
- // run may have just been called through dependencies being fulfilled just in this very frame,
3789
- // or while the async setStatus time below was happening
3790
- Module["calledRun"] = true;
3791
- if (ABORT) return;
3792
- initRuntime();
3793
- preMain();
3794
- readyPromiseResolve(Module);
3795
- Module["onRuntimeInitialized"]?.();
3796
- var noInitialRun = Module["noInitialRun"] || false;
3797
- if (!noInitialRun) callMain(args);
3798
- postRun();
3799
- }
3800
- if (Module["setStatus"]) {
3801
- Module["setStatus"]("Running...");
3802
- setTimeout(() => {
3803
- setTimeout(() => Module["setStatus"](""), 1);
3804
- doRun();
3805
- }, 1);
3806
- } else {
3807
- doRun();
3808
- }
3809
- }
3810
-
3811
- function preInit() {
3812
- if (Module["preInit"]) {
3813
- if (typeof Module["preInit"] == "function") Module["preInit"] = [ Module["preInit"] ];
3814
- while (Module["preInit"].length > 0) {
3815
- Module["preInit"].shift()();
3816
- }
3817
- }
3818
- }
3819
-
3820
- preInit();
3821
-
3822
- run();
3823
-
3824
- // end include: postamble.js
3825
- // include: postamble_modularize.js
3826
- // In MODULARIZE mode we wrap the generated code in a factory function
3827
- // and return either the Module itself, or a promise of the module.
3828
- // We assign to the `moduleRtn` global here and configure closure to see
3829
- // this as and extern so it won't get minified.
3830
- moduleRtn = readyPromise;
3831
-
3832
-
3833
- return moduleRtn;
3834
- }
3835
- );
3836
- })();
3837
- if (typeof exports === 'object' && typeof module === 'object') {
3838
- module.exports = Module;
3839
- // This default export looks redundant, but it allows TS to import this
3840
- // commonjs style module.
3841
- module.exports.default = Module;
3842
- } else if (typeof define === 'function' && define['amd'])
3843
- define([], () => Module);