aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/compile-php-to-wasm/Dockerfile2
-rw-r--r--examples/compile-php-to-wasm/php-wasm.js2191
-rwxr-xr-xexamples/compile-php-to-wasm/php-wasm.wasmbin4861440 -> 4838583 bytes
-rw-r--r--examples/php-on-wasm/php-wasm.php75
-rw-r--r--examples/rubyvm-on-php-on-wasm/php-wasm.php75
5 files changed, 916 insertions, 1427 deletions
diff --git a/examples/compile-php-to-wasm/Dockerfile b/examples/compile-php-to-wasm/Dockerfile
index eb58f15..18e703f 100644
--- a/examples/compile-php-to-wasm/Dockerfile
+++ b/examples/compile-php-to-wasm/Dockerfile
@@ -1,4 +1,4 @@
-FROM emscripten/emsdk:3.1.46
+FROM emscripten/emsdk:3.1.62
RUN git clone --depth=1 --branch=php-8.2.10 https://github.com/php/php-src
diff --git a/examples/compile-php-to-wasm/php-wasm.js b/examples/compile-php-to-wasm/php-wasm.js
index dba15e0..6e8cc58 100644
--- a/examples/compile-php-to-wasm/php-wasm.js
+++ b/examples/compile-php-to-wasm/php-wasm.js
@@ -3,16 +3,17 @@ import { createRequire } from 'module';
const require = createRequire(import.meta.url);
var Module = (() => {
- var _scriptDir = import.meta.url;
+ var _scriptName = import.meta.url;
return (
function(moduleArg = {}) {
+ var moduleRtn;
// include: shell.js
// The Module object: Our interface to the outside world. We import
// and export values on it. There are various ways Module can be used:
// 1. Not defined. We create it here
-// 2. A function parameter, function(Module) { ..generated code.. }
+// 2. A function parameter, function(moduleArg) => Promise<Module>
// 3. pre-run appended it, var Module = {}; ..generated code..
// 4. External script tag defines var Module.
// We need to check if Module already exists (e.g. case 3 above).
@@ -26,19 +27,39 @@ var Module = moduleArg;
// Set up the promise that indicates the Module is initialized
var readyPromiseResolve, readyPromiseReject;
-Module['ready'] = new Promise((resolve, reject) => {
+var readyPromise = new Promise((resolve, reject) => {
readyPromiseResolve = resolve;
readyPromiseReject = reject;
});
-["_main","_memory","_php_wasm_run","_fflush","___indirect_function_table","onRuntimeInitialized"].forEach((prop) => {
- if (!Object.getOwnPropertyDescriptor(Module['ready'], prop)) {
- Object.defineProperty(Module['ready'], prop, {
+["_memory","_php_wasm_run","___indirect_function_table","onRuntimeInitialized"].forEach((prop) => {
+ if (!Object.getOwnPropertyDescriptor(readyPromise, prop)) {
+ Object.defineProperty(readyPromise, prop, {
get: () => abort('You are getting ' + prop + ' on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js'),
set: () => abort('You are setting ' + prop + ' on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js'),
});
}
});
+// Determine the runtime environment we are in. You can customize this by
+// setting the ENVIRONMENT setting at compile time (see settings.js).
+
+var ENVIRONMENT_IS_WEB = false;
+var ENVIRONMENT_IS_WORKER = false;
+var ENVIRONMENT_IS_NODE = true;
+var ENVIRONMENT_IS_SHELL = false;
+
+if (Module['ENVIRONMENT']) {
+ throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)');
+}
+
+if (ENVIRONMENT_IS_NODE) {
+ // `require()` is no-op in an ESM module, use `createRequire()` to construct
+ // the require()` function. This is only necessary for multi-environment
+ // builds, `-sENVIRONMENT=node` emits a static import declaration instead.
+ // TODO: Swap all `require()`'s with `import()`'s?
+
+}
+
// --pre-jses are emitted after the Module integration code, so that they can
// refer to Module (if they choose; they can also define Module)
@@ -56,18 +77,6 @@ var quit_ = (status, toThrow) => {
throw toThrow;
};
-// Determine the runtime environment we are in. You can customize this by
-// setting the ENVIRONMENT setting at compile time (see settings.js).
-
-var ENVIRONMENT_IS_WEB = false;
-var ENVIRONMENT_IS_WORKER = false;
-var ENVIRONMENT_IS_NODE = true;
-var ENVIRONMENT_IS_SHELL = false;
-
-if (Module['ENVIRONMENT']) {
- throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)');
-}
-
// `/` should be present at the end if `scriptDirectory` is not empty
var scriptDirectory = '';
function locateFile(path) {
@@ -78,9 +87,7 @@ function locateFile(path) {
}
// Hooks that are implemented differently in different runtime environments.
-var read_,
- readAsync,
- readBinary;
+var readAsync, readBinary;
if (ENVIRONMENT_IS_NODE) {
if (typeof process == 'undefined' || !process.release || process.release.name !== 'node') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
@@ -93,47 +100,34 @@ if (ENVIRONMENT_IS_NODE) {
throw new Error('This emscripten-generated code requires node v16.0.0 (detected v' + nodeVersion + ')');
}
- // `require()` is no-op in an ESM module, use `createRequire()` to construct
- // the require()` function. This is only necessary for multi-environment
- // builds, `-sENVIRONMENT=node` emits a static import declaration instead.
- // TODO: Swap all `require()`'s with `import()`'s?
// These modules will usually be used on Node.js. Load them eagerly to avoid
// the complexity of lazy-loading.
var fs = require('fs');
var nodePath = require('path');
- if (ENVIRONMENT_IS_WORKER) {
- scriptDirectory = nodePath.dirname(scriptDirectory) + '/';
- } else {
- // EXPORT_ES6 + ENVIRONMENT_IS_NODE always requires use of import.meta.url,
- // since there's no way getting the current absolute path of the module when
- // support for that is not available.
- scriptDirectory = require('url').fileURLToPath(new URL('./', import.meta.url)); // includes trailing slash
- }
+ // EXPORT_ES6 + ENVIRONMENT_IS_NODE always requires use of import.meta.url,
+ // since there's no way getting the current absolute path of the module when
+ // support for that is not available.
+ scriptDirectory = require('url').fileURLToPath(new URL('./', import.meta.url)); // includes trailing slash
// include: node_shell_read.js
-read_ = (filename, binary) => {
+readBinary = (filename) => {
// We need to re-wrap `file://` strings to URLs. Normalizing isn't
// necessary in that case, the path should already be absolute.
filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
- return fs.readFileSync(filename, binary ? undefined : 'utf8');
-};
-
-readBinary = (filename) => {
- var ret = read_(filename, true);
- if (!ret.buffer) {
- ret = new Uint8Array(ret);
- }
+ var ret = fs.readFileSync(filename);
assert(ret.buffer);
return ret;
};
-readAsync = (filename, onload, onerror, binary = true) => {
- // See the comment in the `read_` function.
+readAsync = (filename, binary = true) => {
+ // See the comment in the `readBinary` function.
filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
- fs.readFile(filename, binary ? undefined : 'utf8', (err, data) => {
- if (err) onerror(err);
- else onload(binary ? data.buffer : data);
+ return new Promise((resolve, reject) => {
+ fs.readFile(filename, binary ? undefined : 'utf8', (err, data) => {
+ if (err) reject(err);
+ else resolve(binary ? data.buffer : data);
+ });
});
};
// end include: node_shell_read.js
@@ -150,77 +144,11 @@ readAsync = (filename, onload, onerror, binary = true) => {
throw toThrow;
};
- Module['inspect'] = () => '[Emscripten Module object]';
-
} else
if (ENVIRONMENT_IS_SHELL) {
if ((typeof process == 'object' && typeof require === 'function') || typeof window == 'object' || typeof importScripts == 'function') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
- if (typeof read != 'undefined') {
- read_ = read;
- }
-
- readBinary = (f) => {
- if (typeof readbuffer == 'function') {
- return new Uint8Array(readbuffer(f));
- }
- let data = read(f, 'binary');
- assert(typeof data == 'object');
- return data;
- };
-
- readAsync = (f, onload, onerror) => {
- setTimeout(() => onload(readBinary(f)));
- };
-
- if (typeof clearTimeout == 'undefined') {
- globalThis.clearTimeout = (id) => {};
- }
-
- if (typeof setTimeout == 'undefined') {
- // spidermonkey lacks setTimeout but we use it above in readAsync.
- globalThis.setTimeout = (f) => (typeof f == 'function') ? f() : abort();
- }
-
- if (typeof scriptArgs != 'undefined') {
- arguments_ = scriptArgs;
- } else if (typeof arguments != 'undefined') {
- arguments_ = arguments;
- }
-
- if (typeof quit == 'function') {
- quit_ = (status, toThrow) => {
- // Unlike node which has process.exitCode, d8 has no such mechanism. So we
- // have no way to set the exit code and then let the program exit with
- // that code when it naturally stops running (say, when all setTimeouts
- // have completed). For that reason, we must call `quit` - the only way to
- // set the exit code - but quit also halts immediately. To increase
- // consistency with node (and the web) we schedule the actual quit call
- // using a setTimeout to give the current stack and any exception handlers
- // a chance to run. This enables features such as addOnPostRun (which
- // expected to be able to run code after main returns).
- setTimeout(() => {
- if (!(toThrow instanceof ExitStatus)) {
- let toLog = toThrow;
- if (toThrow && typeof toThrow == 'object' && toThrow.stack) {
- toLog = [toThrow, toThrow.stack];
- }
- err(`exiting due to exception: ${toLog}`);
- }
- quit(status);
- });
- throw toThrow;
- };
- }
-
- if (typeof print != 'undefined') {
- // Prefer to use print/printErr where they exist, as they usually work better.
- if (typeof console == 'undefined') console = /** @type{!Console} */({});
- console.log = /** @type{!function(this:Console, ...*): undefined} */ (print);
- console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (typeof printErr != 'undefined' ? printErr : print);
- }
-
} else
// Note that this includes Node.js workers when relevant (pthreads is enabled).
@@ -236,7 +164,7 @@ var err = Module['printErr'] || console.error.bind(console);
// Merge back in the overrides
Object.assign(Module, moduleOverrides);
// Free the object hierarchy contained in the overrides, this lets the GC
-// reclaim data used e.g. in memoryInitializerRequest, which is a large typed array.
+// reclaim data used.
moduleOverrides = null;
checkIncomingModuleAPI();
@@ -257,13 +185,12 @@ assert(typeof Module['memoryInitializerPrefixURL'] == 'undefined', 'Module.memor
assert(typeof Module['pthreadMainPrefixURL'] == 'undefined', 'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead');
assert(typeof Module['cdInitializerPrefixURL'] == 'undefined', 'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead');
assert(typeof Module['filePackagePrefixURL'] == 'undefined', 'Module.filePackagePrefixURL option was removed, use Module.locateFile instead');
-assert(typeof Module['read'] == 'undefined', 'Module.read option was removed (modify read_ in JS)');
+assert(typeof Module['read'] == 'undefined', 'Module.read option was removed');
assert(typeof Module['readAsync'] == 'undefined', 'Module.readAsync option was removed (modify readAsync in JS)');
assert(typeof Module['readBinary'] == 'undefined', 'Module.readBinary option was removed (modify readBinary in JS)');
assert(typeof Module['setWindowTitle'] == 'undefined', 'Module.setWindowTitle option was removed (modify emscripten_set_window_title in JS)');
assert(typeof Module['TOTAL_MEMORY'] == 'undefined', 'Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY');
legacyModuleProp('asm', 'wasmExports');
-legacyModuleProp('read', 'read_');
legacyModuleProp('readAsync', 'readAsync');
legacyModuleProp('readBinary', 'readBinary');
legacyModuleProp('setWindowTitle', 'setWindowTitle');
@@ -277,14 +204,14 @@ var OPFS = 'OPFS is no longer included by default; build with -lopfs.js';
var NODEFS = 'NODEFS is no longer included by default; build with -lnodefs.js';
-assert(!ENVIRONMENT_IS_WEB, "web environment detected but not enabled at build time. Add 'web' to `-sENVIRONMENT` to enable.");
+assert(!ENVIRONMENT_IS_WEB, 'web environment detected but not enabled at build time. Add `web` to `-sENVIRONMENT` to enable.');
-assert(!ENVIRONMENT_IS_WORKER, "worker environment detected but not enabled at build time. Add 'worker' to `-sENVIRONMENT` to enable.");
-
-assert(!ENVIRONMENT_IS_SHELL, "shell environment detected but not enabled at build time. Add 'shell' to `-sENVIRONMENT` to enable.");
+assert(!ENVIRONMENT_IS_WORKER, 'worker environment detected but not enabled at build time. Add `worker` to `-sENVIRONMENT` to enable.');
+assert(!ENVIRONMENT_IS_SHELL, 'shell environment detected but not enabled at build time. Add `shell` to `-sENVIRONMENT` to enable.');
// end include: shell.js
+
// include: preamble.js
// === Preamble library stuff ===
@@ -296,12 +223,11 @@ assert(!ENVIRONMENT_IS_SHELL, "shell environment detected but not enabled at bui
// An online HTML version (which may be of a different version of Emscripten)
// is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
-var wasmBinary;
+var wasmBinary;
if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];legacyModuleProp('wasmBinary', 'wasmBinary');
-var noExitRuntime = Module['noExitRuntime'] || true;legacyModuleProp('noExitRuntime', 'noExitRuntime');
if (typeof WebAssembly != 'object') {
- abort('no native wasm support detected');
+ err('no native wasm support detected');
}
// Wasm globals
@@ -321,6 +247,10 @@ var ABORT = false;
// but only when noExitRuntime is false.
var EXITSTATUS;
+// In STRICT mode, we only define assert() when ASSERTIONS is set. i.e. we
+// don't define it at all in release modes. This matches the behaviour of
+// MINIMAL_RUNTIME.
+// TODO(sbc): Make this the default even without STRICT enabled.
/** @type {function(*, string=)} */
function assert(condition, text) {
if (!condition) {
@@ -330,6 +260,10 @@ function assert(condition, text) {
// We used to include malloc/free by default in the past. Show a helpful error in
// builds with assertions.
+function _free() {
+ // Show a helpful error since we used to include free by default in the past.
+ abort('free() called but not included in the build - add `_free` to EXPORTED_FUNCTIONS');
+}
// Memory management
@@ -351,6 +285,7 @@ var HEAP,
/** @type {!Float64Array} */
HEAPF64;
+// include: runtime_shared.js
function updateMemoryViews() {
var b = wasmMemory.buffer;
Module['HEAP8'] = HEAP8 = new Int8Array(b);
@@ -362,7 +297,7 @@ function updateMemoryViews() {
Module['HEAPF32'] = HEAPF32 = new Float32Array(b);
Module['HEAPF64'] = HEAPF64 = new Float64Array(b);
}
-
+// end include: runtime_shared.js
assert(!Module['STACK_SIZE'], 'STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time')
assert(typeof Int32Array != 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray != undefined && Int32Array.prototype.set != undefined,
@@ -427,12 +362,6 @@ var __ATPOSTRUN__ = []; // functions called after the main() is called
var runtimeInitialized = false;
-var runtimeKeepaliveCounter = 0;
-
-function keepRuntimeAlive() {
- return noExitRuntime || runtimeKeepaliveCounter > 0;
-}
-
function preRun() {
if (Module['preRun']) {
if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
@@ -450,7 +379,7 @@ function initRuntime() {
checkStackCookie();
-if (!Module["noFSInit"] && !FS.init.initialized)
+if (!Module['noFSInit'] && !FS.init.initialized)
FS.init();
FS.ignorePermissions = false;
@@ -525,9 +454,7 @@ function getUniqueRunDependency(id) {
function addRunDependency(id) {
runDependencies++;
- if (Module['monitorRunDependencies']) {
- Module['monitorRunDependencies'](runDependencies);
- }
+ Module['monitorRunDependencies']?.(runDependencies);
if (id) {
assert(!runDependencyTracking[id]);
@@ -561,9 +488,7 @@ function addRunDependency(id) {
function removeRunDependency(id) {
runDependencies--;
- if (Module['monitorRunDependencies']) {
- Module['monitorRunDependencies'](runDependencies);
- }
+ Module['monitorRunDependencies']?.(runDependencies);
if (id) {
assert(runDependencyTracking[id]);
@@ -586,9 +511,7 @@ function removeRunDependency(id) {
/** @param {string|number=} what */
function abort(what) {
- if (Module['onAbort']) {
- Module['onAbort'](what);
- }
+ Module['onAbort']?.(what);
what = 'Aborted(' + what + ')';
// TODO(sbc): Should we remove printing and leave it up to whoever
@@ -608,7 +531,7 @@ function abort(what) {
// allows this in the wasm spec.
// Suppress closure compiler warning here. Closure compiler's builtin extern
- // defintion for WebAssembly.RuntimeError claims it takes no arguments even
+ // definition for WebAssembly.RuntimeError claims it takes no arguments even
// though it can.
// TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
/** @suppress {checkTypes} */
@@ -627,39 +550,45 @@ function abort(what) {
// Prefix of data URIs emitted by SINGLE_FILE and related options.
var dataURIPrefix = 'data:application/octet-stream;base64,';
-// Indicates whether filename is a base64 data URI.
-function isDataURI(filename) {
- // Prefix of data URIs emitted by SINGLE_FILE and related options.
- return filename.startsWith(dataURIPrefix);
-}
-
-// Indicates whether filename is delivered via file protocol (as opposed to http/https)
-function isFileURI(filename) {
- return filename.startsWith('file://');
-}
+/**
+ * Indicates whether filename is a base64 data URI.
+ * @noinline
+ */
+var isDataURI = (filename) => filename.startsWith(dataURIPrefix);
+
+/**
+ * Indicates whether filename is delivered via file protocol (as opposed to http/https)
+ * @noinline
+ */
+var isFileURI = (filename) => filename.startsWith('file://');
// end include: URIUtils.js
-function createExportWrapper(name) {
- return function() {
+function createExportWrapper(name, nargs) {
+ return (...args) => {
assert(runtimeInitialized, `native function \`${name}\` called before runtime initialization`);
var f = wasmExports[name];
assert(f, `exported native function \`${name}\` not found`);
- return f.apply(null, arguments);
+ // Only assert for too many arguments. Too few can be valid since the missing arguments will be zero filled.
+ assert(args.length <= nargs, `native function \`${name}\` called with ${args.length} args but expects ${nargs}`);
+ return f(...args);
};
}
// include: runtime_exceptions.js
// end include: runtime_exceptions.js
-var wasmBinaryFile;
-if (Module['locateFile']) {
- wasmBinaryFile = 'php-wasm.wasm';
- if (!isDataURI(wasmBinaryFile)) {
- wasmBinaryFile = locateFile(wasmBinaryFile);
+function findWasmBinary() {
+ if (Module['locateFile']) {
+ var f = 'php-wasm.wasm';
+ if (!isDataURI(f)) {
+ return locateFile(f);
+ }
+ return f;
}
-} else {
// Use bundler-friendly `new URL(..., import.meta.url)` pattern; works in browsers too.
- wasmBinaryFile = new URL('php-wasm.wasm', import.meta.url).href;
+ return new URL('php-wasm.wasm', import.meta.url).href;
}
+var wasmBinaryFile;
+
function getBinarySync(file) {
if (file == wasmBinaryFile && wasmBinary) {
return new Uint8Array(wasmBinary);
@@ -667,26 +596,19 @@ function getBinarySync(file) {
if (readBinary) {
return readBinary(file);
}
- throw "both async and sync fetching of the wasm failed";
+ throw 'both async and sync fetching of the wasm failed';
}
function getBinaryPromise(binaryFile) {
- // If we don't have the binary yet, try to load it asynchronously.
- // Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
- // See https://github.com/github/fetch/pull/92#issuecomment-140665932
- // Cordova or Electron apps are typically loaded from a file:// url.
- // So use fetch if it is available and the url is not a file, otherwise fall back to XHR.
+ // If we don't have the binary yet, load it asynchronously using readAsync.
if (!wasmBinary
- && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
- if (typeof fetch == 'function'
- ) {
- return fetch(binaryFile, { credentials: 'same-origin' }).then((response) => {
- if (!response['ok']) {
- throw "failed to load wasm binary file at '" + binaryFile + "'";
- }
- return response['arrayBuffer']();
- }).catch(() => getBinarySync(binaryFile));
- }
+ ) {
+ // Fetch the binary using readAsync
+ return readAsync(binaryFile).then(
+ (response) => new Uint8Array(/** @type{!ArrayBuffer} */(response)),
+ // Fall back to getBinarySync if readAsync fails
+ () => getBinarySync(binaryFile)
+ );
}
// Otherwise, getBinarySync should be able to get it synchronously
@@ -696,8 +618,6 @@ function getBinaryPromise(binaryFile) {
function instantiateArrayBuffer(binaryFile, imports, receiver) {
return getBinaryPromise(binaryFile).then((binary) => {
return WebAssembly.instantiate(binary, imports);
- }).then((instance) => {
- return instance;
}).then(receiver, (reason) => {
err(`failed to asynchronously prepare wasm: ${reason}`);
@@ -743,14 +663,18 @@ function instantiateAsync(binary, binaryFile, imports, callback) {
return instantiateArrayBuffer(binaryFile, imports, callback);
}
-// Create the wasm instance.
-// Receives the wasm imports, returns the exports.
-function createWasm() {
+function getWasmImports() {
// prepare imports
- var info = {
+ return {
'env': wasmImports,
'wasi_snapshot_preview1': wasmImports,
- };
+ }
+}
+
+// Create the wasm instance.
+// Receives the wasm imports, returns the exports.
+function createWasm() {
+ var info = getWasmImports();
// Load the wasm module and create an instance of using native support in the JS engine.
// handle a generated wasm instance, receiving its exports and
// performing other necessary setup
@@ -762,16 +686,12 @@ function createWasm() {
wasmMemory = wasmExports['memory'];
- assert(wasmMemory, "memory not found in wasm exports");
- // This assertion doesn't hold when emscripten is run in --post-link
- // mode.
- // TODO(sbc): Read INITIAL_MEMORY out of the wasm file in post-link mode.
- //assert(wasmMemory.buffer.byteLength === 16777216);
+ assert(wasmMemory, 'memory not found in wasm exports');
updateMemoryViews();
wasmTable = wasmExports['__indirect_function_table'];
- assert(wasmTable, "table not found in wasm exports");
+ assert(wasmTable, 'table not found in wasm exports');
addOnInit(wasmExports['__wasm_call_ctors']);
@@ -803,7 +723,6 @@ function createWasm() {
// Also pthreads and wasm workers initialize the wasm instance through this
// path.
if (Module['instantiateWasm']) {
-
try {
return Module['instantiateWasm'](info, receiveInstance);
} catch(e) {
@@ -813,6 +732,8 @@ function createWasm() {
}
}
+ if (!wasmBinaryFile) wasmBinaryFile = findWasmBinary();
+
// If instantiation fails, reject the module ready promise.
instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult).catch(readyPromiseReject);
return {}; // no exports yet; we'll fill them in later
@@ -823,12 +744,12 @@ var tempDouble;
var tempI64;
// include: runtime_debug.js
-function legacyModuleProp(prop, newName, incomming=true) {
+function legacyModuleProp(prop, newName, incoming=true) {
if (!Object.getOwnPropertyDescriptor(Module, prop)) {
Object.defineProperty(Module, prop, {
configurable: true,
get() {
- let extra = incomming ? ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)' : '';
+ let extra = incoming ? ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)' : '';
abort(`\`Module.${prop}\` has been replaced by \`${newName}\`` + extra);
}
@@ -856,11 +777,11 @@ function isExportedByForceFilesystem(name) {
}
function missingGlobal(sym, msg) {
- if (typeof globalThis !== 'undefined') {
+ if (typeof globalThis != 'undefined') {
Object.defineProperty(globalThis, sym, {
configurable: true,
get() {
- warnOnce('`' + sym + '` is not longer defined by emscripten. ' + msg);
+ warnOnce(`\`${sym}\` is not longer defined by emscripten. ${msg}`);
return undefined;
}
});
@@ -871,13 +792,13 @@ missingGlobal('buffer', 'Please use HEAP8.buffer or wasmMemory.buffer');
missingGlobal('asm', 'Please use wasmExports instead');
function missingLibrarySymbol(sym) {
- if (typeof globalThis !== 'undefined' && !Object.getOwnPropertyDescriptor(globalThis, sym)) {
+ if (typeof globalThis != 'undefined' && !Object.getOwnPropertyDescriptor(globalThis, sym)) {
Object.defineProperty(globalThis, sym, {
configurable: true,
get() {
// Can't `abort()` here because it would break code that does runtime
// checks. e.g. `if (typeof SDL === 'undefined')`.
- var msg = '`' + sym + '` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line';
+ var msg = `\`${sym}\` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line`;
// DEFAULT_LIBRARY_FUNCS_TO_INCLUDE requires the name as it appears in
// library.js, which means $name for a JS name with no prefix, or name
// for a JS name like _name.
@@ -885,7 +806,7 @@ function missingLibrarySymbol(sym) {
if (!librarySymbol.startsWith('_')) {
librarySymbol = '$' + sym;
}
- msg += " (e.g. -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='" + librarySymbol + "')";
+ msg += ` (e.g. -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='${librarySymbol}')`;
if (isExportedByForceFilesystem(sym)) {
msg += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you';
}
@@ -894,7 +815,7 @@ function missingLibrarySymbol(sym) {
}
});
}
- // Any symbol that is not included from the JS libary is also (by definition)
+ // Any symbol that is not included from the JS library is also (by definition)
// not exported on the Module object.
unexportedRuntimeSymbol(sym);
}
@@ -904,7 +825,7 @@ function unexportedRuntimeSymbol(sym) {
Object.defineProperty(Module, sym, {
configurable: true,
get() {
- var msg = "'" + sym + "' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)";
+ var msg = `'${sym}' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)`;
if (isExportedByForceFilesystem(sym)) {
msg += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you';
}
@@ -915,16 +836,16 @@ function unexportedRuntimeSymbol(sym) {
}
// Used by XXXXX_DEBUG settings to output debug messages.
-function dbg(text) {
+function dbg(...args) {
// TODO(sbc): Make this configurable somehow. Its not always convenient for
// logging to show up as warnings.
- console.warn.apply(console, arguments);
+ console.warn(...args);
}
// end include: runtime_debug.js
// === Body ===
-
// end include: preamble.js
+
/** @constructor */
function ExitStatus(status) {
this.name = 'ExitStatus';
@@ -947,8 +868,8 @@ function dbg(text) {
function getValue(ptr, type = 'i8') {
if (type.endsWith('*')) type = '*';
switch (type) {
- case 'i1': return HEAP8[((ptr)>>0)];
- case 'i8': return HEAP8[((ptr)>>0)];
+ case 'i1': return HEAP8[ptr];
+ case 'i8': return HEAP8[ptr];
case 'i16': return HEAP16[((ptr)>>1)];
case 'i32': return HEAP32[((ptr)>>2)];
case 'i64': abort('to do getValue(i64) use WASM_BIGINT');
@@ -959,6 +880,8 @@ function dbg(text) {
}
}
+ var noExitRuntime = Module['noExitRuntime'] || true;
+
var ptrToString = (ptr) => {
assert(typeof ptr === 'number');
// With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
@@ -975,8 +898,8 @@ function dbg(text) {
function setValue(ptr, value, type = 'i8') {
if (type.endsWith('*')) type = '*';
switch (type) {
- case 'i1': HEAP8[((ptr)>>0)] = value; break;
- case 'i8': HEAP8[((ptr)>>0)] = value; break;
+ case 'i1': HEAP8[ptr] = value; break;
+ case 'i8': HEAP8[ptr] = value; break;
case 'i16': HEAP16[((ptr)>>1)] = value; break;
case 'i32': HEAP32[((ptr)>>2)] = value; break;
case 'i64': abort('to do setValue(i64) use WASM_BIGINT');
@@ -987,8 +910,12 @@ function dbg(text) {
}
}
+ var stackRestore = (val) => __emscripten_stack_restore(val);
+
+ var stackSave = () => _emscripten_stack_get_current();
+
var warnOnce = (text) => {
- if (!warnOnce.shown) warnOnce.shown = {};
+ warnOnce.shown ||= {};
if (!warnOnce.shown[text]) {
warnOnce.shown[text] = 1;
if (ENVIRONMENT_IS_NODE) text = 'warning: ' + text;
@@ -996,7 +923,7 @@ function dbg(text) {
}
};
- var UTF8Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder('utf8') : undefined;
+ var UTF8Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder() : undefined;
/**
* Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
@@ -1066,7 +993,7 @@ function dbg(text) {
* @return {string}
*/
var UTF8ToString = (ptr, maxBytesToRead) => {
- assert(typeof ptr == 'number');
+ assert(typeof ptr == 'number', `UTF8ToString expects a number (got ${typeof ptr})`);
return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
};
var ___assert_fail = (condition, filename, line, func) => {
@@ -1075,6 +1002,7 @@ function dbg(text) {
var wasmTableMirror = [];
+ /** @type {WebAssembly.Table} */
var wasmTable;
var getWasmTableEntry = (funcPtr) => {
var func = wasmTableMirror[funcPtr];
@@ -1082,7 +1010,7 @@ function dbg(text) {
if (funcPtr >= wasmTableMirror.length) wasmTableMirror.length = funcPtr + 1;
wasmTableMirror[funcPtr] = func = wasmTable.get(funcPtr);
}
- assert(wasmTable.get(funcPtr) == func, "JavaScript-side Wasm function table mirror is out of date!");
+ assert(wasmTable.get(funcPtr) == func, 'JavaScript-side Wasm function table mirror is out of date!');
return func;
};
var ___call_sighandler = (fp, sig) => getWasmTableEntry(fp)(sig);
@@ -1152,13 +1080,8 @@ function dbg(text) {
if (lastSlash === -1) return path;
return path.substr(lastSlash+1);
},
- join:function() {
- var paths = Array.prototype.slice.call(arguments);
- return PATH.normalize(paths.join('/'));
- },
- join2:(l, r) => {
- return PATH.normalize(l + '/' + r);
- },
+ join:(...paths) => PATH.normalize(paths.join('/')),
+ join2:(l, r) => PATH.normalize(l + '/' + r),
};
var initRandomFill = () => {
@@ -1187,7 +1110,7 @@ function dbg(text) {
}
}
// we couldn't find a proper implementation, as Math.random() is not suitable for /dev/random, see emscripten-core/emscripten/pull/7096
- abort("no cryptographic support found for randomDevice. consider polyfilling it if you want to use something insecure like Math.random(), e.g. put this in a --pre-js: var crypto = { getRandomValues: (array) => { for (var i = 0; i < array.length; i++) array[i] = (Math.random()*256)|0 } };");
+ abort('no cryptographic support found for randomDevice. consider polyfilling it if you want to use something insecure like Math.random(), e.g. put this in a --pre-js: var crypto = { getRandomValues: (array) => { for (var i = 0; i < array.length; i++) array[i] = (Math.random()*256)|0 } };');
};
var randomFill = (view) => {
// Lazily init on the first invocation.
@@ -1197,11 +1120,11 @@ function dbg(text) {
var PATH_FS = {
- resolve:function() {
+ resolve:(...args) => {
var resolvedPath = '',
resolvedAbsolute = false;
- for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
- var path = (i >= 0) ? arguments[i] : FS.cwd();
+ for (var i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
+ var path = (i >= 0) ? args[i] : FS.cwd();
// Skip empty and invalid entries
if (typeof path != 'string') {
throw new TypeError('Arguments to path.resolve must be strings');
@@ -1276,7 +1199,7 @@ function dbg(text) {
};
var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
- assert(typeof str === 'string');
+ assert(typeof str === 'string', `stringToUTF8Array expects a string (got ${typeof str})`);
// Parameter maxBytesToWrite is not optional. Negative values, 0, null,
// undefined and false each don't write out any bytes.
if (!(maxBytesToWrite > 0))
@@ -1349,34 +1272,20 @@ function dbg(text) {
var fd = process.stdin.fd;
try {
- bytesRead = fs.readSync(fd, buf);
+ bytesRead = fs.readSync(fd, buf, 0, BUFSIZE);
} catch(e) {
- // Cross-platform differences: on Windows, reading EOF throws an exception, but on other OSes,
- // reading EOF returns 0. Uniformize behavior by treating the EOF exception to return 0.
+ // Cross-platform differences: on Windows, reading EOF throws an
+ // exception, but on other OSes, reading EOF returns 0. Uniformize
+ // behavior by treating the EOF exception to return 0.
if (e.toString().includes('EOF')) bytesRead = 0;
else throw e;
}
if (bytesRead > 0) {
result = buf.slice(0, bytesRead).toString('utf-8');
- } else {
- result = null;
}
} else
- if (typeof window != 'undefined' &&
- typeof window.prompt == 'function') {
- // Browser.
- result = window.prompt('Input: '); // returns null on cancel
- if (result !== null) {
- result += '\n';
- }
- } else if (typeof readline == 'function') {
- // Command line.
- result = readline();
- if (result !== null) {
- result += '\n';
- }
- }
+ {}
if (!result) {
return null;
}
@@ -1552,55 +1461,53 @@ function dbg(text) {
// no supported
throw new FS.ErrnoError(63);
}
- if (!MEMFS.ops_table) {
- MEMFS.ops_table = {
- dir: {
- node: {
- getattr: MEMFS.node_ops.getattr,
- setattr: MEMFS.node_ops.setattr,
- lookup: MEMFS.node_ops.lookup,
- mknod: MEMFS.node_ops.mknod,
- rename: MEMFS.node_ops.rename,
- unlink: MEMFS.node_ops.unlink,
- rmdir: MEMFS.node_ops.rmdir,
- readdir: MEMFS.node_ops.readdir,
- symlink: MEMFS.node_ops.symlink
- },
- stream: {
- llseek: MEMFS.stream_ops.llseek
- }
+ MEMFS.ops_table ||= {
+ dir: {
+ node: {
+ getattr: MEMFS.node_ops.getattr,
+ setattr: MEMFS.node_ops.setattr,
+ lookup: MEMFS.node_ops.lookup,
+ mknod: MEMFS.node_ops.mknod,
+ rename: MEMFS.node_ops.rename,
+ unlink: MEMFS.node_ops.unlink,
+ rmdir: MEMFS.node_ops.rmdir,
+ readdir: MEMFS.node_ops.readdir,
+ symlink: MEMFS.node_ops.symlink
},
- file: {
- node: {
- getattr: MEMFS.node_ops.getattr,
- setattr: MEMFS.node_ops.setattr
- },
- stream: {
- llseek: MEMFS.stream_ops.llseek,
- read: MEMFS.stream_ops.read,
- write: MEMFS.stream_ops.write,
- allocate: MEMFS.stream_ops.allocate,
- mmap: MEMFS.stream_ops.mmap,
- msync: MEMFS.stream_ops.msync
- }
- },
- link: {
- node: {
- getattr: MEMFS.node_ops.getattr,
- setattr: MEMFS.node_ops.setattr,
- readlink: MEMFS.node_ops.readlink
- },
- stream: {}
+ stream: {
+ llseek: MEMFS.stream_ops.llseek
+ }
+ },
+ file: {
+ node: {
+ getattr: MEMFS.node_ops.getattr,
+ setattr: MEMFS.node_ops.setattr
},
- chrdev: {
- node: {
- getattr: MEMFS.node_ops.getattr,
- setattr: MEMFS.node_ops.setattr
- },
- stream: FS.chrdev_stream_ops
+ stream: {
+ llseek: MEMFS.stream_ops.llseek,
+ read: MEMFS.stream_ops.read,
+ write: MEMFS.stream_ops.write,
+ allocate: MEMFS.stream_ops.allocate,
+ mmap: MEMFS.stream_ops.mmap,
+ msync: MEMFS.stream_ops.msync
}
- };
- }
+ },
+ link: {
+ node: {
+ getattr: MEMFS.node_ops.getattr,
+ setattr: MEMFS.node_ops.setattr,
+ readlink: MEMFS.node_ops.readlink
+ },
+ stream: {}
+ },
+ chrdev: {
+ node: {
+ getattr: MEMFS.node_ops.getattr,
+ setattr: MEMFS.node_ops.setattr
+ },
+ stream: FS.chrdev_stream_ops
+ }
+ };
var node = FS.createNode(parent, name, mode, dev);
if (FS.isDir(node.mode)) {
node.node_ops = MEMFS.ops_table.dir.node;
@@ -1727,7 +1634,6 @@ function dbg(text) {
old_node.name = new_name;
new_dir.contents[new_name] = old_node;
new_dir.timestamp = old_node.parent.timestamp;
- old_node.parent = new_dir;
},
unlink(parent, name) {
delete parent.contents[name];
@@ -1743,10 +1649,7 @@ function dbg(text) {
},
readdir(node) {
var entries = ['.', '..'];
- for (var key in node.contents) {
- if (!node.contents.hasOwnProperty(key)) {
- continue;
- }
+ for (var key of Object.keys(node.contents)) {
entries.push(key);
}
return entries;
@@ -1873,23 +1776,26 @@ function dbg(text) {
/** @param {boolean=} noRunDep */
var asyncLoad = (url, onload, onerror, noRunDep) => {
var dep = !noRunDep ? getUniqueRunDependency(`al ${url}`) : '';
- readAsync(url, (arrayBuffer) => {
- assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
- onload(new Uint8Array(arrayBuffer));
- if (dep) removeRunDependency(dep);
- }, (event) => {
- if (onerror) {
- onerror();
- } else {
- throw `Loading data file "${url}" failed.`;
+ readAsync(url).then(
+ (arrayBuffer) => {
+ assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
+ onload(new Uint8Array(arrayBuffer));
+ if (dep) removeRunDependency(dep);
+ },
+ (err) => {
+ if (onerror) {
+ onerror();
+ } else {
+ throw `Loading data file "${url}" failed.`;
+ }
}
- });
+ );
if (dep) addRunDependency(dep);
};
var FS_createDataFile = (parent, name, fileData, canRead, canWrite, canOwn) => {
- return FS.createDataFile(parent, name, fileData, canRead, canWrite, canOwn);
+ FS.createDataFile(parent, name, fileData, canRead, canWrite, canOwn);
};
var preloadPlugins = Module['preloadPlugins'] || [];
@@ -1914,15 +1820,15 @@ function dbg(text) {
var dep = getUniqueRunDependency(`cp ${fullname}`); // might have several active requests for the same fullname
function processData(byteArray) {
function finish(byteArray) {
- if (preFinish) preFinish();
+ preFinish?.();
if (!dontCreateFile) {
FS_createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
}
- if (onload) onload();
+ onload?.();
removeRunDependency(dep);
}
if (FS_handledByPreloadPlugin(byteArray, fullname, finish, () => {
- if (onerror) onerror();
+ onerror?.();
removeRunDependency(dep);
})) {
return;
@@ -1931,7 +1837,7 @@ function dbg(text) {
}
addRunDependency(dep);
if (typeof url == 'string') {
- asyncLoad(url, (byteArray) => processData(byteArray), onerror);
+ asyncLoad(url, processData, onerror);
} else {
processData(url);
}
@@ -1963,143 +1869,134 @@ function dbg(text) {
- var ERRNO_MESSAGES = {
- 0:"Success",
- 1:"Arg list too long",
- 2:"Permission denied",
- 3:"Address already in use",
- 4:"Address not available",
- 5:"Address family not supported by protocol family",
- 6:"No more processes",
- 7:"Socket already connected",
- 8:"Bad file number",
- 9:"Trying to read unreadable message",
- 10:"Mount device busy",
- 11:"Operation canceled",
- 12:"No children",
- 13:"Connection aborted",
- 14:"Connection refused",
- 15:"Connection reset by peer",
- 16:"File locking deadlock error",
- 17:"Destination address required",
- 18:"Math arg out of domain of func",
- 19:"Quota exceeded",
- 20:"File exists",
- 21:"Bad address",
- 22:"File too large",
- 23:"Host is unreachable",
- 24:"Identifier removed",
- 25:"Illegal byte sequence",
- 26:"Connection already in progress",
- 27:"Interrupted system call",
- 28:"Invalid argument",
- 29:"I/O error",
- 30:"Socket is already connected",
- 31:"Is a directory",
- 32:"Too many symbolic links",
- 33:"Too many open files",
- 34:"Too many links",
- 35:"Message too long",
- 36:"Multihop attempted",
- 37:"File or path name too long",
- 38:"Network interface is not configured",
- 39:"Connection reset by network",
- 40:"Network is unreachable",
- 41:"Too many open files in system",
- 42:"No buffer space available",
- 43:"No such device",
- 44:"No such file or directory",
- 45:"Exec format error",
- 46:"No record locks available",
- 47:"The link has been severed",
- 48:"Not enough core",
- 49:"No message of desired type",
- 50:"Protocol not available",
- 51:"No space left on device",
- 52:"Function not implemented",
- 53:"Socket is not connected",
- 54:"Not a directory",
- 55:"Directory not empty",
- 56:"State not recoverable",
- 57:"Socket operation on non-socket",
- 59:"Not a typewriter",
- 60:"No such device or address",
- 61:"Value too large for defined data type",
- 62:"Previous owner died",
- 63:"Not super-user",
- 64:"Broken pipe",
- 65:"Protocol error",
- 66:"Unknown protocol",
- 67:"Protocol wrong type for socket",
- 68:"Math result not representable",
- 69:"Read only file system",
- 70:"Illegal seek",
- 71:"No such process",
- 72:"Stale file handle",
- 73:"Connection timed out",
- 74:"Text file busy",
- 75:"Cross-device link",
- 100:"Device not a stream",
- 101:"Bad font file fmt",
- 102:"Invalid slot",
- 103:"Invalid request code",
- 104:"No anode",
- 105:"Block device required",
- 106:"Channel number out of range",
- 107:"Level 3 halted",
- 108:"Level 3 reset",
- 109:"Link number out of range",
- 110:"Protocol driver not attached",
- 111:"No CSI structure available",
- 112:"Level 2 halted",
- 113:"Invalid exchange",
- 114:"Invalid request descriptor",
- 115:"Exchange full",
- 116:"No data (for no delay io)",
- 117:"Timer expired",
- 118:"Out of streams resources",
- 119:"Machine is not on the network",
- 120:"Package not installed",
- 121:"The object is remote",
- 122:"Advertise error",
- 123:"Srmount error",
- 124:"Communication error on send",
- 125:"Cross mount point (not really error)",
- 126:"Given log. name not unique",
- 127:"f.d. invalid for this operation",
- 128:"Remote address changed",
- 129:"Can access a needed shared lib",
- 130:"Accessing a corrupted shared lib",
- 131:".lib section in a.out corrupted",
- 132:"Attempting to link in too many libs",
- 133:"Attempting to exec a shared library",
- 135:"Streams pipe error",
- 136:"Too many users",
- 137:"Socket type not supported",
- 138:"Not supported",
- 139:"Protocol family not supported",
- 140:"Can't send after socket shutdown",
- 141:"Too many references",
- 142:"Host is down",
- 148:"No medium (in tape drive)",
- 156:"Level 2 not synchronized",
- };
- var ERRNO_CODES = {
- };
- var demangle = (func) => {
- warnOnce('warning: build with -sDEMANGLE_SUPPORT to link in libcxxabi demangling');
- return func;
+ var strError = (errno) => {
+ return UTF8ToString(_strerror(errno));
};
- var demangleAll = (text) => {
- var regex =
- /\b_Z[\w\d_]+/g;
- return text.replace(regex,
- function(x) {
- var y = demangle(x);
- return x === y ? x : (y + ' [' + x + ']');
- });
+
+ var ERRNO_CODES = {
+ 'EPERM': 63,
+ 'ENOENT': 44,
+ 'ESRCH': 71,
+ 'EINTR': 27,
+ 'EIO': 29,
+ 'ENXIO': 60,
+ 'E2BIG': 1,
+ 'ENOEXEC': 45,
+ 'EBADF': 8,
+ 'ECHILD': 12,
+ 'EAGAIN': 6,
+ 'EWOULDBLOCK': 6,
+ 'ENOMEM': 48,
+ 'EACCES': 2,
+ 'EFAULT': 21,
+ 'ENOTBLK': 105,
+ 'EBUSY': 10,
+ 'EEXIST': 20,
+ 'EXDEV': 75,
+ 'ENODEV': 43,
+ 'ENOTDIR': 54,
+ 'EISDIR': 31,
+ 'EINVAL': 28,
+ 'ENFILE': 41,
+ 'EMFILE': 33,
+ 'ENOTTY': 59,
+ 'ETXTBSY': 74,
+ 'EFBIG': 22,
+ 'ENOSPC': 51,
+ 'ESPIPE': 70,
+ 'EROFS': 69,
+ 'EMLINK': 34,
+ 'EPIPE': 64,
+ 'EDOM': 18,
+ 'ERANGE': 68,
+ 'ENOMSG': 49,
+ 'EIDRM': 24,
+ 'ECHRNG': 106,
+ 'EL2NSYNC': 156,
+ 'EL3HLT': 107,
+ 'EL3RST': 108,
+ 'ELNRNG': 109,
+ 'EUNATCH': 110,
+ 'ENOCSI': 111,
+ 'EL2HLT': 112,
+ 'EDEADLK': 16,
+ 'ENOLCK': 46,
+ 'EBADE': 113,
+ 'EBADR': 114,
+ 'EXFULL': 115,
+ 'ENOANO': 104,
+ 'EBADRQC': 103,
+ 'EBADSLT': 102,
+ 'EDEADLOCK': 16,
+ 'EBFONT': 101,
+ 'ENOSTR': 100,
+ 'ENODATA': 116,
+ 'ETIME': 117,
+ 'ENOSR': 118,
+ 'ENONET': 119,
+ 'ENOPKG': 120,
+ 'EREMOTE': 121,
+ 'ENOLINK': 47,
+ 'EADV': 122,
+ 'ESRMNT': 123,
+ 'ECOMM': 124,
+ 'EPROTO': 65,
+ 'EMULTIHOP': 36,
+ 'EDOTDOT': 125,
+ 'EBADMSG': 9,
+ 'ENOTUNIQ': 126,
+ 'EBADFD': 127,
+ 'EREMCHG': 128,
+ 'ELIBACC': 129,
+ 'ELIBBAD': 130,
+ 'ELIBSCN': 131,
+ 'ELIBMAX': 132,
+ 'ELIBEXEC': 133,
+ 'ENOSYS': 52,
+ 'ENOTEMPTY': 55,
+ 'ENAMETOOLONG': 37,
+ 'ELOOP': 32,
+ 'EOPNOTSUPP': 138,
+ 'EPFNOSUPPORT': 139,
+ 'ECONNRESET': 15,
+ 'ENOBUFS': 42,
+ 'EAFNOSUPPORT': 5,
+ 'EPROTOTYPE': 67,
+ 'ENOTSOCK': 57,
+ 'ENOPROTOOPT': 50,
+ 'ESHUTDOWN': 140,
+ 'ECONNREFUSED': 14,
+ 'EADDRINUSE': 3,
+ 'ECONNABORTED': 13,
+ 'ENETUNREACH': 40,
+ 'ENETDOWN': 38,
+ 'ETIMEDOUT': 73,
+ 'EHOSTDOWN': 142,
+ 'EHOSTUNREACH': 23,
+ 'EINPROGRESS': 26,
+ 'EALREADY': 7,
+ 'EDESTADDRREQ': 17,
+ 'EMSGSIZE': 35,
+ 'EPROTONOSUPPORT': 66,
+ 'ESOCKTNOSUPPORT': 137,
+ 'EADDRNOTAVAIL': 4,
+ 'ENETRESET': 39,
+ 'EISCONN': 30,
+ 'ENOTCONN': 53,
+ 'ETOOMANYREFS': 141,
+ 'EUSERS': 136,
+ 'EDQUOT': 19,
+ 'ESTALE': 72,
+ 'ENOTSUP': 138,
+ 'ENOMEDIUM': 148,
+ 'EILSEQ': 25,
+ 'EOVERFLOW': 61,
+ 'ECANCELED': 11,
+ 'ENOTRECOVERABLE': 56,
+ 'EOWNERDEAD': 62,
+ 'ESTRPIPE': 135,
};
var FS = {
root:null,
@@ -2112,11 +2009,101 @@ function dbg(text) {
currentPath:"/",
initialized:false,
ignorePermissions:true,
- ErrnoError:null,
+ ErrnoError:class extends Error {
+ // We set the `name` property to be able to identify `FS.ErrnoError`
+ // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
+ // - when using PROXYFS, an error can come from an underlying FS
+ // as different FS objects have their own FS.ErrnoError each,
+ // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
+ // we'll use the reliable test `err.name == "ErrnoError"` instead
+ constructor(errno) {
+ super(runtimeInitialized ? strError(errno) : '');
+ // TODO(sbc): Use the inline member declaration syntax once we
+ // support it in acorn and closure.
+ this.name = 'ErrnoError';
+ this.errno = errno;
+ for (var key in ERRNO_CODES) {
+ if (ERRNO_CODES[key] === errno) {
+ this.code = key;
+ break;
+ }
+ }
+ }
+ },
genericErrors:{
},
filesystems:null,
syncFSRequests:0,
+ FSStream:class {
+ constructor() {
+ // TODO(https://github.com/emscripten-core/emscripten/issues/21414):
+ // Use inline field declarations.
+ this.shared = {};
+ }
+ get object() {
+ return this.node;
+ }
+ set object(val) {
+ this.node = val;
+ }
+ get isRead() {
+ return (this.flags & 2097155) !== 1;
+ }
+ get isWrite() {
+ return (this.flags & 2097155) !== 0;
+ }
+ get isAppend() {
+ return (this.flags & 1024);
+ }
+ get flags() {
+ return this.shared.flags;
+ }
+ set flags(val) {
+ this.shared.flags = val;
+ }
+ get position() {
+ return this.shared.position;
+ }
+ set position(val) {
+ this.shared.position = val;
+ }
+ },
+ FSNode:class {
+ constructor(parent, name, mode, rdev) {
+ if (!parent) {
+ parent = this; // root node sets parent to itself
+ }
+ this.parent = parent;
+ this.mount = parent.mount;
+ this.mounted = null;
+ this.id = FS.nextInode++;
+ this.name = name;
+ this.mode = mode;
+ this.node_ops = {};
+ this.stream_ops = {};
+ this.rdev = rdev;
+ this.readMode = 292/*292*/ | 73/*73*/;
+ this.writeMode = 146/*146*/;
+ }
+ get read() {
+ return (this.mode & this.readMode) === this.readMode;
+ }
+ set read(val) {
+ val ? this.mode |= this.readMode : this.mode &= ~this.readMode;
+ }
+ get write() {
+ return (this.mode & this.writeMode) === this.writeMode;
+ }
+ set write(val) {
+ val ? this.mode |= this.writeMode : this.mode &= ~this.writeMode;
+ }
+ get isFolder() {
+ return FS.isDir(this.mode);
+ }
+ get isDevice() {
+ return FS.isChrdev(this.mode);
+ }
+ },
lookupPath(path, opts = {}) {
path = PATH_FS.resolve(path);
@@ -2219,7 +2206,7 @@ function dbg(text) {
lookupNode(parent, name) {
var errCode = FS.mayLookup(parent);
if (errCode) {
- throw new FS.ErrnoError(errCode, parent);
+ throw new FS.ErrnoError(errCode);
}
var hash = FS.hashName(parent.id, name);
for (var node = FS.nameTable[hash]; node; node = node.name_next) {
@@ -2291,6 +2278,7 @@ function dbg(text) {
return 0;
},
mayLookup(dir) {
+ if (!FS.isDir(dir.mode)) return 54;
var errCode = FS.nodePermissions(dir, 'x');
if (errCode) return errCode;
if (!dir.node_ops.lookup) return 2;
@@ -2361,44 +2349,8 @@ function dbg(text) {
},
getStream:(fd) => FS.streams[fd],
createStream(stream, fd = -1) {
- if (!FS.FSStream) {
- FS.FSStream = /** @constructor */ function() {
- this.shared = { };
- };
- FS.FSStream.prototype = {};
- Object.defineProperties(FS.FSStream.prototype, {
- object: {
- /** @this {FS.FSStream} */
- get() { return this.node; },
- /** @this {FS.FSStream} */
- set(val) { this.node = val; }
- },
- isRead: {
- /** @this {FS.FSStream} */
- get() { return (this.flags & 2097155) !== 1; }
- },
- isWrite: {
- /** @this {FS.FSStream} */
- get() { return (this.flags & 2097155) !== 0; }
- },
- isAppend: {
- /** @this {FS.FSStream} */
- get() { return (this.flags & 1024); }
- },
- flags: {
- /** @this {FS.FSStream} */
- get() { return this.shared.flags; },
- /** @this {FS.FSStream} */
- set(val) { this.shared.flags = val; },
- },
- position : {
- /** @this {FS.FSStream} */
- get() { return this.shared.position; },
- /** @this {FS.FSStream} */
- set(val) { this.shared.position = val; },
- },
- });
- }
+ assert(fd >= -1);
+
// clone it, so we can return an instance of FSStream
stream = Object.assign(new FS.FSStream(), stream);
if (fd == -1) {
@@ -2411,15 +2363,18 @@ function dbg(text) {
closeStream(fd) {
FS.streams[fd] = null;
},
+ dupStream(origStream, fd = -1) {
+ var stream = FS.createStream(origStream, fd);
+ stream.stream_ops?.dup?.(stream);
+ return stream;
+ },
chrdev_stream_ops:{
open(stream) {
var device = FS.getDevice(stream.node.rdev);
// override node's stream ops with the device's
stream.stream_ops = device.stream_ops;
// forward the open call
- if (stream.stream_ops.open) {
- stream.stream_ops.open(stream);
- }
+ stream.stream_ops.open?.(stream);
},
llseek() {
throw new FS.ErrnoError(70);
@@ -2441,7 +2396,7 @@ function dbg(text) {
mounts.push(m);
- check.push.apply(check, m.mounts);
+ check.push(...m.mounts);
}
return mounts;
@@ -2654,7 +2609,7 @@ function dbg(text) {
// parents must exist
var lookup, old_dir, new_dir;
- // let the errors from non existant directories percolate up
+ // let the errors from non existent directories percolate up
lookup = FS.lookupPath(old_path, { parent: true });
old_dir = lookup.node;
lookup = FS.lookupPath(new_path, { parent: true });
@@ -2720,6 +2675,9 @@ function dbg(text) {
// do the underlying fs rename
try {
old_dir.node_ops.rename(old_node, new_dir, new_name);
+ // update old node (we do this here to avoid each backend
+ // needing to)
+ old_node.parent = new_dir;
} catch (e) {
throw e;
} finally {
@@ -2897,8 +2855,8 @@ function dbg(text) {
throw new FS.ErrnoError(44);
}
flags = typeof flags == 'string' ? FS_modeStringToFlags(flags) : flags;
- mode = typeof mode == 'undefined' ? 438 /* 0666 */ : mode;
if ((flags & 64)) {
+ mode = typeof mode == 'undefined' ? 438 /* 0666 */ : mode;
mode = (mode & 4095) | 32768;
} else {
mode = 0;
@@ -3118,7 +3076,6 @@ function dbg(text) {
}
return stream.stream_ops.msync(stream, buffer, offset, length, mmapFlags);
},
- munmap:(stream) => 0,
ioctl(stream, cmd, arg) {
if (!stream.stream_ops.ioctl) {
throw new FS.ErrnoError(59);
@@ -3270,47 +3227,12 @@ function dbg(text) {
assert(stdout.fd === 1, `invalid handle for stdout (${stdout.fd})`);
assert(stderr.fd === 2, `invalid handle for stderr (${stderr.fd})`);
},
- ensureErrnoError() {
- if (FS.ErrnoError) return;
- FS.ErrnoError = /** @this{Object} */ function ErrnoError(errno, node) {
- // We set the `name` property to be able to identify `FS.ErrnoError`
- // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
- // - when using PROXYFS, an error can come from an underlying FS
- // as different FS objects have their own FS.ErrnoError each,
- // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
- // we'll use the reliable test `err.name == "ErrnoError"` instead
- this.name = 'ErrnoError';
- this.node = node;
- this.setErrno = /** @this{Object} */ function(errno) {
- this.errno = errno;
- for (var key in ERRNO_CODES) {
- if (ERRNO_CODES[key] === errno) {
- this.code = key;
- break;
- }
- }
- };
- this.setErrno(errno);
- this.message = ERRNO_MESSAGES[errno];
-
- // Try to get a maximally helpful stack trace. On Node.js, getting Error.stack
- // now ensures it shows what we want.
- if (this.stack) {
- // Define the stack property for Node.js 4, which otherwise errors on the next line.
- Object.defineProperty(this, "stack", { value: (new Error).stack, writable: true });
- this.stack = demangleAll(this.stack);
- }
- };
- FS.ErrnoError.prototype = new Error();
- FS.ErrnoError.prototype.constructor = FS.ErrnoError;
+ staticInit() {
// Some errors may happen quite a bit, to avoid overhead we reuse them (and suffer a lack of stack info)
[44].forEach((code) => {
FS.genericErrors[code] = new FS.ErrnoError(code);
FS.genericErrors[code].stack = '<generic error, no stack>';
});
- },
- staticInit() {
- FS.ensureErrnoError();
FS.nameTable = new Array(4096);
@@ -3328,8 +3250,6 @@ function dbg(text) {
assert(!FS.init.initialized, 'FS.init was previously called. If you want to initialize later with custom parameters, remove any earlier calls (note that one is automatically added to the generated code)');
FS.init.initialized = true;
- FS.ensureErrnoError();
-
// Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
Module['stdin'] = input || Module['stdin'];
Module['stdout'] = output || Module['stdout'];
@@ -3427,7 +3347,6 @@ function dbg(text) {
FS.close(stream);
FS.chmod(node, mode);
}
- return node;
},
createDevice(parent, name, input, output) {
var path = PATH.join2(typeof parent == 'string' ? parent : FS.getPath(parent), name);
@@ -3442,7 +3361,7 @@ function dbg(text) {
},
close(stream) {
// flush any pending line data
- if (output && output.buffer && output.buffer.length) {
+ if (output?.buffer?.length) {
output(10);
}
},
@@ -3487,122 +3406,113 @@ function dbg(text) {
if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
if (typeof XMLHttpRequest != 'undefined') {
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.");
- } else if (read_) {
- // Command-line.
+ } else { // Command-line.
try {
- // WARNING: Can't read binary files in V8's d8 or tracemonkey's js, as
- // read() will try to parse UTF8.
- obj.contents = intArrayFromString(read_(obj.url), true);
+ obj.contents = readBinary(obj.url);
obj.usedBytes = obj.contents.length;
} catch (e) {
throw new FS.ErrnoError(29);
}
- } else {
- throw new Error('Cannot load without read() or XMLHttpRequest.');
}
},
createLazyFile(parent, name, url, canRead, canWrite) {
- // Lazy chunked Uint8Array (implements get and length from Uint8Array). Actual getting is abstracted away for eventual reuse.
- /** @constructor */
- function LazyUint8Array() {
- this.lengthKnown = false;
- this.chunks = []; // Loaded chunks. Index is the chunk number
- }
- LazyUint8Array.prototype.get = /** @this{Object} */ function LazyUint8Array_get(idx) {
- if (idx > this.length-1 || idx < 0) {
- return undefined;
- }
- var chunkOffset = idx % this.chunkSize;
- var chunkNum = (idx / this.chunkSize)|0;
- return this.getter(chunkNum)[chunkOffset];
- };
- LazyUint8Array.prototype.setDataGetter = function LazyUint8Array_setDataGetter(getter) {
- this.getter = getter;
- };
- LazyUint8Array.prototype.cacheLength = function LazyUint8Array_cacheLength() {
- // Find length
- var xhr = new XMLHttpRequest();
- xhr.open('HEAD', url, false);
- xhr.send(null);
- if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
- var datalength = Number(xhr.getResponseHeader("Content-length"));
- var header;
- var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
- var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
-
- var chunkSize = 1024*1024; // Chunk size in bytes
-
- if (!hasByteServing) chunkSize = datalength;
-
- // Function to get a range from the remote URL.
- var doXHR = (from, to) => {
- if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
- if (to > datalength-1) throw new Error("only " + datalength + " bytes available! programmer error!");
-
- // TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
+ // Lazy chunked Uint8Array (implements get and length from Uint8Array).
+ // Actual getting is abstracted away for eventual reuse.
+ class LazyUint8Array {
+ constructor() {
+ this.lengthKnown = false;
+ this.chunks = []; // Loaded chunks. Index is the chunk number
+ }
+ get(idx) {
+ if (idx > this.length-1 || idx < 0) {
+ return undefined;
+ }
+ var chunkOffset = idx % this.chunkSize;
+ var chunkNum = (idx / this.chunkSize)|0;
+ return this.getter(chunkNum)[chunkOffset];
+ }
+ setDataGetter(getter) {
+ this.getter = getter;
+ }
+ cacheLength() {
+ // Find length
var xhr = new XMLHttpRequest();
- xhr.open('GET', url, false);
- if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
+ xhr.open('HEAD', url, false);
+ xhr.send(null);
+ if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
+ var datalength = Number(xhr.getResponseHeader("Content-length"));
+ var header;
+ var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
+ var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
+
+ var chunkSize = 1024*1024; // Chunk size in bytes
+
+ if (!hasByteServing) chunkSize = datalength;
+
+ // Function to get a range from the remote URL.
+ var doXHR = (from, to) => {
+ if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
+ if (to > datalength-1) throw new Error("only " + datalength + " bytes available! programmer error!");
- // Some hints to the browser that we want binary data.
- xhr.responseType = 'arraybuffer';
- if (xhr.overrideMimeType) {
- xhr.overrideMimeType('text/plain; charset=x-user-defined');
+ // TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', url, false);
+ if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
+
+ // Some hints to the browser that we want binary data.
+ xhr.responseType = 'arraybuffer';
+ if (xhr.overrideMimeType) {
+ xhr.overrideMimeType('text/plain; charset=x-user-defined');
+ }
+
+ xhr.send(null);
+ if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
+ if (xhr.response !== undefined) {
+ return new Uint8Array(/** @type{Array<number>} */(xhr.response || []));
+ }
+ return intArrayFromString(xhr.responseText || '', true);
+ };
+ var lazyArray = this;
+ lazyArray.setDataGetter((chunkNum) => {
+ var start = chunkNum * chunkSize;
+ var end = (chunkNum+1) * chunkSize - 1; // including this byte
+ end = Math.min(end, datalength-1); // if datalength-1 is selected, this is the last block
+ if (typeof lazyArray.chunks[chunkNum] == 'undefined') {
+ lazyArray.chunks[chunkNum] = doXHR(start, end);
+ }
+ if (typeof lazyArray.chunks[chunkNum] == 'undefined') throw new Error('doXHR failed!');
+ return lazyArray.chunks[chunkNum];
+ });
+
+ if (usesGzip || !datalength) {
+ // if the server uses gzip or doesn't supply the length, we have to download the whole file to get the (uncompressed) length
+ chunkSize = datalength = 1; // this will force getter(0)/doXHR do download the whole file
+ datalength = this.getter(0).length;
+ chunkSize = datalength;
+ out("LazyFiles on gzip forces download of the whole file when length is accessed");
}
- xhr.send(null);
- if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
- if (xhr.response !== undefined) {
- return new Uint8Array(/** @type{Array<number>} */(xhr.response || []));
+ this._length = datalength;
+ this._chunkSize = chunkSize;
+ this.lengthKnown = true;
+ }
+ get length() {
+ if (!this.lengthKnown) {
+ this.cacheLength();
}
- return intArrayFromString(xhr.responseText || '', true);
- };
- var lazyArray = this;
- lazyArray.setDataGetter((chunkNum) => {
- var start = chunkNum * chunkSize;
- var end = (chunkNum+1) * chunkSize - 1; // including this byte
- end = Math.min(end, datalength-1); // if datalength-1 is selected, this is the last block
- if (typeof lazyArray.chunks[chunkNum] == 'undefined') {
- lazyArray.chunks[chunkNum] = doXHR(start, end);
+ return this._length;
+ }
+ get chunkSize() {
+ if (!this.lengthKnown) {
+ this.cacheLength();
}
- if (typeof lazyArray.chunks[chunkNum] == 'undefined') throw new Error('doXHR failed!');
- return lazyArray.chunks[chunkNum];
- });
-
- if (usesGzip || !datalength) {
- // if the server uses gzip or doesn't supply the length, we have to download the whole file to get the (uncompressed) length
- chunkSize = datalength = 1; // this will force getter(0)/doXHR do download the whole file
- datalength = this.getter(0).length;
- chunkSize = datalength;
- out("LazyFiles on gzip forces download of the whole file when length is accessed");
+ return this._chunkSize;
}
+ }
- this._length = datalength;
- this._chunkSize = chunkSize;
- this.lengthKnown = true;
- };
if (typeof XMLHttpRequest != 'undefined') {
if (!ENVIRONMENT_IS_WORKER) throw 'Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc';
var lazyArray = new LazyUint8Array();
- Object.defineProperties(lazyArray, {
- length: {
- get: /** @this{Object} */ function() {
- if (!this.lengthKnown) {
- this.cacheLength();
- }
- return this._length;
- }
- },
- chunkSize: {
- get: /** @this{Object} */ function() {
- if (!this.lengthKnown) {
- this.cacheLength();
- }
- return this._chunkSize;
- }
- }
- });
-
var properties = { isDevice: false, contents: lazyArray };
} else {
var properties = { isDevice: false, url: url };
@@ -3621,7 +3531,7 @@ function dbg(text) {
// Add a function that defers querying the file size until it is asked the first time.
Object.defineProperties(node, {
usedBytes: {
- get: /** @this {FSNode} */ function() { return this.contents.length; }
+ get: function() { return this.contents.length; }
}
});
// override each stream op with one that tries to force load the lazy file first
@@ -3629,9 +3539,9 @@ function dbg(text) {
var keys = Object.keys(node.stream_ops);
keys.forEach((key) => {
var fn = node.stream_ops[key];
- stream_ops[key] = function forceLoadLazyFile() {
+ stream_ops[key] = (...args) => {
FS.forceLoadFile(node);
- return fn.apply(null, arguments);
+ return fn(...args);
};
});
function writeChunks(stream, buffer, offset, length, position) {
@@ -3712,34 +3622,26 @@ function dbg(text) {
return PATH.join2(dir, path);
},
doStat(func, path, buf) {
- try {
- var stat = func(path);
- } catch (e) {
- if (e && e.node && PATH.normalize(path) !== PATH.normalize(FS.getPath(e.node))) {
- // an error occurred while trying to look up the path; we should just report ENOTDIR
- return -54;
- }
- throw e;
- }
+ var stat = func(path);
HEAP32[((buf)>>2)] = stat.dev;
HEAP32[(((buf)+(4))>>2)] = stat.mode;
HEAPU32[(((buf)+(8))>>2)] = stat.nlink;
HEAP32[(((buf)+(12))>>2)] = stat.uid;
HEAP32[(((buf)+(16))>>2)] = stat.gid;
HEAP32[(((buf)+(20))>>2)] = stat.rdev;
- (tempI64 = [stat.size>>>0,(tempDouble=stat.size,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(24))>>2)] = tempI64[0],HEAP32[(((buf)+(28))>>2)] = tempI64[1]);
+ (tempI64 = [stat.size>>>0,(tempDouble = stat.size,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(24))>>2)] = tempI64[0],HEAP32[(((buf)+(28))>>2)] = tempI64[1]);
HEAP32[(((buf)+(32))>>2)] = 4096;
HEAP32[(((buf)+(36))>>2)] = stat.blocks;
var atime = stat.atime.getTime();
var mtime = stat.mtime.getTime();
var ctime = stat.ctime.getTime();
- (tempI64 = [Math.floor(atime / 1000)>>>0,(tempDouble=Math.floor(atime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(40))>>2)] = tempI64[0],HEAP32[(((buf)+(44))>>2)] = tempI64[1]);
+ (tempI64 = [Math.floor(atime / 1000)>>>0,(tempDouble = Math.floor(atime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(40))>>2)] = tempI64[0],HEAP32[(((buf)+(44))>>2)] = tempI64[1]);
HEAPU32[(((buf)+(48))>>2)] = (atime % 1000) * 1000;
- (tempI64 = [Math.floor(mtime / 1000)>>>0,(tempDouble=Math.floor(mtime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(56))>>2)] = tempI64[0],HEAP32[(((buf)+(60))>>2)] = tempI64[1]);
+ (tempI64 = [Math.floor(mtime / 1000)>>>0,(tempDouble = Math.floor(mtime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(56))>>2)] = tempI64[0],HEAP32[(((buf)+(60))>>2)] = tempI64[1]);
HEAPU32[(((buf)+(64))>>2)] = (mtime % 1000) * 1000;
- (tempI64 = [Math.floor(ctime / 1000)>>>0,(tempDouble=Math.floor(ctime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(72))>>2)] = tempI64[0],HEAP32[(((buf)+(76))>>2)] = tempI64[1]);
+ (tempI64 = [Math.floor(ctime / 1000)>>>0,(tempDouble = Math.floor(ctime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(72))>>2)] = tempI64[0],HEAP32[(((buf)+(76))>>2)] = tempI64[1]);
HEAPU32[(((buf)+(80))>>2)] = (ctime % 1000) * 1000;
- (tempI64 = [stat.ino>>>0,(tempDouble=stat.ino,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(88))>>2)] = tempI64[0],HEAP32[(((buf)+(92))>>2)] = tempI64[1]);
+ (tempI64 = [stat.ino>>>0,(tempDouble = stat.ino,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(88))>>2)] = tempI64[0],HEAP32[(((buf)+(92))>>2)] = tempI64[1]);
return 0;
},
doMsync(addr, stream, len, flags, offset) {
@@ -3753,23 +3655,15 @@ function dbg(text) {
var buffer = HEAPU8.slice(addr, addr + len);
FS.msync(stream, buffer, offset, len, flags);
},
- varargs:undefined,
- get() {
- assert(SYSCALLS.varargs != undefined);
- // the `+` prepended here is necessary to convince the JSCompiler that varargs is indeed a number.
- var ret = HEAP32[((+SYSCALLS.varargs)>>2)];
- SYSCALLS.varargs += 4;
- return ret;
+ getStreamFromFD(fd) {
+ var stream = FS.getStreamChecked(fd);
+ return stream;
},
- getp() { return SYSCALLS.get() },
+ varargs:undefined,
getStr(ptr) {
var ret = UTF8ToString(ptr);
return ret;
},
- getStreamFromFD(fd) {
- var stream = FS.getStreamChecked(fd);
- return stream;
- },
};
function ___syscall__newselect(nfds, readfds, writefds, exceptfds, timeout) {
try {
@@ -3821,8 +3715,13 @@ function dbg(text) {
if (stream.stream_ops.poll) {
var timeoutInMillis = -1;
if (timeout) {
+ // select(2) is declared to accept "struct timeval { time_t tv_sec; suseconds_t tv_usec; }".
+ // However, musl passes the two values to the syscall as an array of long values.
+ // Note that sizeof(time_t) != sizeof(long) in wasm32. The former is 8, while the latter is 4.
+ // This means using "C_STRUCTS.timeval.tv_usec" leads to a wrong offset.
+ // So, instead, we use POINTER_SIZE.
var tv_sec = (readfds ? HEAP32[((timeout)>>2)] : 0),
- tv_usec = (readfds ? HEAP32[(((timeout)+(8))>>2)] : 0);
+ tv_usec = (readfds ? HEAP32[(((timeout)+(4))>>2)] : 0);
timeoutInMillis = (tv_sec + tv_usec / 1000000) * 1000;
}
flags = stream.stream_ops.poll(stream, timeoutInMillis);
@@ -4498,10 +4397,6 @@ function dbg(text) {
return socket;
};
- var setErrNo = (value) => {
- HEAP32[((___errno_location())>>2)] = value;
- return value;
- };
var Sockets = {
BUFFER_SIZE:10240,
MAX_BUFFER_SIZE:10485760,
@@ -4666,7 +4561,6 @@ function dbg(text) {
return null;
},
};
-
function ___syscall_accept4(fd, addr, addrlen, flags, d1, d2) {
try {
@@ -4829,7 +4723,6 @@ function dbg(text) {
info.addr = DNS.lookup_addr(info.addr) || info.addr;
return info;
};
-
function ___syscall_bind(fd, addr, addrlen, d1, d2, d3) {
try {
@@ -4868,7 +4761,6 @@ function dbg(text) {
}
-
function ___syscall_connect(fd, addr, addrlen, d1, d2, d3) {
try {
@@ -4886,7 +4778,7 @@ function dbg(text) {
try {
var old = SYSCALLS.getStreamFromFD(fd);
- return FS.createStream(old).fd;
+ return FS.dupStream(old).fd;
} catch (e) {
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
return -e.errno;
@@ -4899,9 +4791,11 @@ function dbg(text) {
var old = SYSCALLS.getStreamFromFD(fd);
assert(!flags);
if (old.fd === newfd) return -28;
+ // Check newfd is within range of valid open file descriptors.
+ if (newfd < 0 || newfd >= FS.MAX_OPEN_FDS) return -8;
var existing = FS.getStream(newfd);
if (existing) FS.close(existing);
- return FS.createStream(old, newfd).fd;
+ return FS.dupStream(old, newfd).fd;
} catch (e) {
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
return -e.errno;
@@ -4953,6 +4847,16 @@ function dbg(text) {
}
}
+ /** @suppress {duplicate } */
+ function syscallGetVarargI() {
+ assert(SYSCALLS.varargs != undefined);
+ // the `+` prepended here is necessary to convince the JSCompiler that varargs is indeed a number.
+ var ret = HEAP32[((+SYSCALLS.varargs)>>2)];
+ SYSCALLS.varargs += 4;
+ return ret;
+ }
+ var syscallGetVarargP = syscallGetVarargI;
+
function ___syscall_fcntl64(fd, cmd, varargs) {
SYSCALLS.varargs = varargs;
@@ -4961,7 +4865,7 @@ function dbg(text) {
var stream = SYSCALLS.getStreamFromFD(fd);
switch (cmd) {
case 0: {
- var arg = SYSCALLS.get();
+ var arg = syscallGetVarargI();
if (arg < 0) {
return -28;
}
@@ -4969,7 +4873,7 @@ function dbg(text) {
arg++;
}
var newStream;
- newStream = FS.createStream(stream, arg);
+ newStream = FS.dupStream(stream, arg);
return newStream.fd;
}
case 1:
@@ -4978,31 +4882,22 @@ function dbg(text) {
case 3:
return stream.flags;
case 4: {
- var arg = SYSCALLS.get();
+ var arg = syscallGetVarargI();
stream.flags |= arg;
return 0;
}
- case 5: {
- var arg = SYSCALLS.getp();
+ case 12: {
+ var arg = syscallGetVarargP();
var offset = 0;
// We're always unlocked.
HEAP16[(((arg)+(offset))>>1)] = 2;
return 0;
}
- case 6:
- case 7:
+ case 13:
+ case 14:
return 0; // Pretend that the locking is successful.
- case 16:
- case 8:
- return -28; // These are for sockets. We don't have them fully implemented yet.
- case 9:
- // musl trusts getown return values, due to a bug where they must be, as they overlap with errors. just return -1 here, so fcntl() returns that, and we set errno ourselves.
- setErrNo(28);
- return -1;
- default: {
- return -28;
- }
}
+ return -28;
} catch (e) {
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
return -e.errno;
@@ -5031,14 +4926,13 @@ function dbg(text) {
}
}
-
var convertI32PairToI53Checked = (lo, hi) => {
assert(lo == (lo >>> 0) || lo == (lo|0)); // lo should either be a i32 or a u32
assert(hi === (hi|0)); // hi should be a i32
return ((hi + 0x200000) >>> 0 < 0x400001 - !!lo) ? (lo >>> 0) + hi * 4294967296 : NaN;
};
function ___syscall_ftruncate64(fd,length_low, length_high) {
- var length = convertI32PairToI53Checked(length_low, length_high);;
+ var length = convertI32PairToI53Checked(length_low, length_high);
try {
@@ -5058,7 +4952,6 @@ function dbg(text) {
assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
};
-
function ___syscall_getcwd(buf, size) {
try {
@@ -5079,9 +4972,7 @@ function dbg(text) {
try {
var stream = SYSCALLS.getStreamFromFD(fd)
- if (!stream.getdents) {
- stream.getdents = FS.readdir(stream.path);
- }
+ stream.getdents ||= FS.readdir(stream.path);
var struct_size = 280;
var pos = 0;
@@ -5111,10 +5002,10 @@ function dbg(text) {
8; // DT_REG, regular file.
}
assert(id);
- (tempI64 = [id>>>0,(tempDouble=id,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[((dirp + pos)>>2)] = tempI64[0],HEAP32[(((dirp + pos)+(4))>>2)] = tempI64[1]);
- (tempI64 = [(idx + 1) * struct_size>>>0,(tempDouble=(idx + 1) * struct_size,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((dirp + pos)+(8))>>2)] = tempI64[0],HEAP32[(((dirp + pos)+(12))>>2)] = tempI64[1]);
+ (tempI64 = [id>>>0,(tempDouble = id,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[((dirp + pos)>>2)] = tempI64[0],HEAP32[(((dirp + pos)+(4))>>2)] = tempI64[1]);
+ (tempI64 = [(idx + 1) * struct_size>>>0,(tempDouble = (idx + 1) * struct_size,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((dirp + pos)+(8))>>2)] = tempI64[0],HEAP32[(((dirp + pos)+(12))>>2)] = tempI64[1]);
HEAP16[(((dirp + pos)+(16))>>1)] = 280;
- HEAP8[(((dirp + pos)+(18))>>0)] = type;
+ HEAP8[(dirp + pos)+(18)] = type;
stringToUTF8(name, dirp + pos + 19, 256);
pos += struct_size;
idx += 1;
@@ -5129,7 +5020,6 @@ function dbg(text) {
-
function ___syscall_getpeername(fd, addr, addrlen, d1, d2, d3) {
try {
@@ -5148,7 +5038,6 @@ function dbg(text) {
-
function ___syscall_getsockname(fd, addr, addrlen, d1, d2, d3) {
try {
@@ -5163,7 +5052,6 @@ function dbg(text) {
}
}
-
function ___syscall_getsockopt(fd, level, optname, optval, optlen, d1) {
try {
@@ -5185,6 +5073,7 @@ function dbg(text) {
}
}
+
function ___syscall_ioctl(fd, op, varargs) {
SYSCALLS.varargs = varargs;
try {
@@ -5199,13 +5088,13 @@ function dbg(text) {
if (!stream.tty) return -59;
if (stream.tty.ops.ioctl_tcgets) {
var termios = stream.tty.ops.ioctl_tcgets(stream);
- var argp = SYSCALLS.getp();
+ var argp = syscallGetVarargP();
HEAP32[((argp)>>2)] = termios.c_iflag || 0;
HEAP32[(((argp)+(4))>>2)] = termios.c_oflag || 0;
HEAP32[(((argp)+(8))>>2)] = termios.c_cflag || 0;
HEAP32[(((argp)+(12))>>2)] = termios.c_lflag || 0;
for (var i = 0; i < 32; i++) {
- HEAP8[(((argp + i)+(17))>>0)] = termios.c_cc[i] || 0;
+ HEAP8[(argp + i)+(17)] = termios.c_cc[i] || 0;
}
return 0;
}
@@ -5222,14 +5111,14 @@ function dbg(text) {
case 21508: {
if (!stream.tty) return -59;
if (stream.tty.ops.ioctl_tcsets) {
- var argp = SYSCALLS.getp();
+ var argp = syscallGetVarargP();
var c_iflag = HEAP32[((argp)>>2)];
var c_oflag = HEAP32[(((argp)+(4))>>2)];
var c_cflag = HEAP32[(((argp)+(8))>>2)];
var c_lflag = HEAP32[(((argp)+(12))>>2)];
var c_cc = []
for (var i = 0; i < 32; i++) {
- c_cc.push(HEAP8[(((argp + i)+(17))>>0)]);
+ c_cc.push(HEAP8[(argp + i)+(17)]);
}
return stream.tty.ops.ioctl_tcsets(stream.tty, op, { c_iflag, c_oflag, c_cflag, c_lflag, c_cc });
}
@@ -5237,7 +5126,7 @@ function dbg(text) {
}
case 21519: {
if (!stream.tty) return -59;
- var argp = SYSCALLS.getp();
+ var argp = syscallGetVarargP();
HEAP32[((argp)>>2)] = 0;
return 0;
}
@@ -5246,7 +5135,7 @@ function dbg(text) {
return -28; // not supported
}
case 21531: {
- var argp = SYSCALLS.getp();
+ var argp = syscallGetVarargP();
return FS.ioctl(stream, op, argp);
}
case 21523: {
@@ -5255,7 +5144,7 @@ function dbg(text) {
if (!stream.tty) return -59;
if (stream.tty.ops.ioctl_tiocgwinsz) {
var winsize = stream.tty.ops.ioctl_tiocgwinsz(stream.tty);
- var argp = SYSCALLS.getp();
+ var argp = syscallGetVarargP();
HEAP16[((argp)>>1)] = winsize[0];
HEAP16[(((argp)+(2))>>1)] = winsize[1];
}
@@ -5280,7 +5169,6 @@ function dbg(text) {
}
}
-
function ___syscall_listen(fd, backlog) {
try {
@@ -5337,13 +5225,14 @@ function dbg(text) {
}
}
+
function ___syscall_openat(dirfd, path, flags, varargs) {
SYSCALLS.varargs = varargs;
try {
path = SYSCALLS.getStr(path);
path = SYSCALLS.calculateAt(dirfd, path);
- var mode = varargs ? SYSCALLS.get() : 0;
+ var mode = varargs ? syscallGetVarargI() : 0;
return FS.open(path, flags, mode).fd;
} catch (e) {
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
@@ -5564,7 +5453,6 @@ function dbg(text) {
return 'pipe[' + (PIPEFS.nextname.current++) + ']';
},
};
-
function ___syscall_pipe(fdPtr) {
try {
@@ -5636,7 +5524,6 @@ function dbg(text) {
-
function ___syscall_recvfrom(fd, buf, len, flags, addr, addrlen) {
try {
@@ -5683,7 +5570,6 @@ function dbg(text) {
}
-
function ___syscall_sendto(fd, message, length, flags, addr, addr_len) {
try {
@@ -5701,7 +5587,6 @@ function dbg(text) {
}
}
-
function ___syscall_socket(domain, type, protocol) {
try {
@@ -5811,15 +5696,35 @@ function dbg(text) {
}
}
- var nowIsMonotonic = true;;
+ var __abort_js = () => {
+ abort('native code called abort()');
+ };
+
+ var nowIsMonotonic = 1;
var __emscripten_get_now_is_monotonic = () => nowIsMonotonic;
+
+
+
+ var __emscripten_lookup_name = (name) => {
+ // uint32_t _emscripten_lookup_name(const char *name);
+ var nameString = UTF8ToString(name);
+ return inetPton4(DNS.lookup_name(nameString));
+ };
+
+ var __emscripten_memcpy_js = (dest, src, num) => HEAPU8.copyWithin(dest, src, src + num);
+
+ var __emscripten_runtime_keepalive_clear = () => {
+ noExitRuntime = false;
+ runtimeKeepaliveCounter = 0;
+ };
+
var __emscripten_throw_longjmp = () => {
throw Infinity;
};
function __gmtime_js(time_low, time_high,tmPtr) {
- var time = convertI32PairToI53Checked(time_low, time_high);;
+ var time = convertI32PairToI53Checked(time_low, time_high);
var date = new Date(time * 1000);
@@ -5836,9 +5741,7 @@ function dbg(text) {
;
}
- var isLeapYear = (year) => {
- return year%4 === 0 && (year%100 !== 0 || year%400 === 0);
- };
+ var isLeapYear = (year) => year%4 === 0 && (year%100 !== 0 || year%400 === 0);
var MONTH_DAYS_LEAP_CUMULATIVE = [0,31,60,91,121,152,182,213,244,274,305,335];
@@ -5852,7 +5755,7 @@ function dbg(text) {
};
function __localtime_js(time_low, time_high,tmPtr) {
- var time = convertI32PairToI53Checked(time_low, time_high);;
+ var time = convertI32PairToI53Checked(time_low, time_high);
var date = new Date(time*1000);
@@ -5878,6 +5781,9 @@ function dbg(text) {
}
+ /** @suppress {duplicate } */
+ var setTempRet0 = (val) => __emscripten_tempret_set(val);
+ var _setTempRet0 = setTempRet0;
var __mktime_js = function(tmPtr) {
@@ -5920,9 +5826,14 @@ function dbg(text) {
HEAP32[(((tmPtr)+(16))>>2)] = date.getMonth();
HEAP32[(((tmPtr)+(20))>>2)] = date.getYear();
- return date.getTime() / 1000;
+ var timeMs = date.getTime();
+ if (isNaN(timeMs)) {
+ return -1;
+ }
+ // Return time in microseconds
+ return timeMs / 1000;
})();
- return (setTempRet0((tempDouble=ret,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)), ret>>>0);
+ return (setTempRet0((tempDouble = ret,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)), ret>>>0);
};
@@ -5931,7 +5842,7 @@ function dbg(text) {
function __mmap_js(len,prot,flags,fd,offset_low, offset_high,allocated,addr) {
- var offset = convertI32PairToI53Checked(offset_low, offset_high);;
+ var offset = convertI32PairToI53Checked(offset_low, offset_high);
try {
@@ -5951,21 +5862,16 @@ function dbg(text) {
}
-
-
function __munmap_js(addr,len,prot,flags,fd,offset_low, offset_high) {
- var offset = convertI32PairToI53Checked(offset_low, offset_high);;
+ var offset = convertI32PairToI53Checked(offset_low, offset_high);
try {
- if (isNaN(offset)) return 61;
var stream = SYSCALLS.getStreamFromFD(fd);
if (prot & 2) {
SYSCALLS.doMsync(addr, stream, len, flags, offset);
}
- FS.munmap(stream);
- // implicitly return 0
} catch (e) {
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
return -e.errno;
@@ -5995,14 +5901,17 @@ function dbg(text) {
};
+ var runtimeKeepaliveCounter = 0;
+ var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
var _proc_exit = (code) => {
EXITSTATUS = code;
if (!keepRuntimeAlive()) {
- if (Module['onExit']) Module['onExit'](code);
+ Module['onExit']?.(code);
ABORT = true;
}
quit_(code, new ExitStatus(code));
};
+
/** @suppress {duplicate } */
/** @param {boolean|number=} implicit */
var exitJS = (status, implicit) => {
@@ -6021,6 +5930,7 @@ function dbg(text) {
};
var _exit = exitJS;
+
var maybeExit = () => {
if (!keepRuntimeAlive()) {
try {
@@ -6071,14 +5981,7 @@ function dbg(text) {
};
-
- var stringToNewUTF8 = (str) => {
- var size = lengthBytesUTF8(str) + 1;
- var ret = _malloc(size);
- if (ret) stringToUTF8(str, ret, size);
- return ret;
- };
- var __tzset_js = (timezone, daylight, tzname) => {
+ var __tzset_js = (timezone, daylight, std_name, dst_name) => {
// TODO: Use (malleable) environment variables instead of system settings.
var currentYear = new Date().getFullYear();
var winter = new Date(currentYear, 0, 1);
@@ -6086,9 +5989,12 @@ function dbg(text) {
var winterOffset = winter.getTimezoneOffset();
var summerOffset = summer.getTimezoneOffset();
- // Local standard timezone offset. Local standard time is not adjusted for daylight savings.
- // This code uses the fact that getTimezoneOffset returns a greater value during Standard Time versus Daylight Saving Time (DST).
- // Thus it determines the expected output during Standard Time, and it compares whether the output of the given date the same (Standard) or less (DST).
+ // Local standard timezone offset. Local standard time is not adjusted for
+ // daylight savings. This code uses the fact that getTimezoneOffset returns
+ // a greater value during Standard Time versus Daylight Saving Time (DST).
+ // Thus it determines the expected output during Standard Time, and it
+ // compares whether the output of the given date the same (Standard) or less
+ // (DST).
var stdTimezoneOffset = Math.max(winterOffset, summerOffset);
// timezone is specified as seconds west of UTC ("The external variable
@@ -6100,28 +6006,23 @@ function dbg(text) {
HEAP32[((daylight)>>2)] = Number(winterOffset != summerOffset);
- function extractZone(date) {
- var match = date.toTimeString().match(/\(([A-Za-z ]+)\)$/);
- return match ? match[1] : "GMT";
- };
+ var extractZone = (date) => date.toLocaleTimeString(undefined, {hour12:false, timeZoneName:'short'}).split(' ')[1];
var winterName = extractZone(winter);
var summerName = extractZone(summer);
- var winterNamePtr = stringToNewUTF8(winterName);
- var summerNamePtr = stringToNewUTF8(summerName);
+ assert(winterName);
+ assert(summerName);
+ assert(lengthBytesUTF8(winterName) <= 16, `timezone name truncated to fit in TZNAME_MAX (${winterName})`);
+ assert(lengthBytesUTF8(summerName) <= 16, `timezone name truncated to fit in TZNAME_MAX (${summerName})`);
if (summerOffset < winterOffset) {
// Northern hemisphere
- HEAPU32[((tzname)>>2)] = winterNamePtr;
- HEAPU32[(((tzname)+(4))>>2)] = summerNamePtr;
+ stringToUTF8(winterName, std_name, 17);
+ stringToUTF8(summerName, dst_name, 17);
} else {
- HEAPU32[((tzname)>>2)] = summerNamePtr;
- HEAPU32[(((tzname)+(4))>>2)] = winterNamePtr;
+ stringToUTF8(winterName, dst_name, 17);
+ stringToUTF8(summerName, std_name, 17);
}
};
- var _abort = () => {
- abort('native code called abort()');
- };
-
var _emscripten_date_now = () => Date.now();
var _emscripten_err = (str) => err(UTF8ToString(str));
@@ -6131,8 +6032,6 @@ function dbg(text) {
var _emscripten_get_heap_max = () => getHeapMax();
- var _emscripten_memcpy_js = (dest, src, num) => HEAPU8.copyWithin(dest, src, src + num);
-
var abortOnCannotGrowMemory = (requestedSize) => {
abort(`Cannot enlarge memory arrays to size ${requestedSize} bytes (OOM). Either (1) compile with -sINITIAL_MEMORY=X with X higher than the current value ${HEAP8.length}, (2) compile with -sALLOW_MEMORY_GROWTH which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -sABORTING_MALLOC=0`);
@@ -6184,12 +6083,11 @@ function dbg(text) {
var stringToAscii = (str, buffer) => {
for (var i = 0; i < str.length; ++i) {
assert(str.charCodeAt(i) === (str.charCodeAt(i) & 0xff));
- HEAP8[((buffer++)>>0)] = str.charCodeAt(i);
+ HEAP8[buffer++] = str.charCodeAt(i);
}
// Null-terminate the string
- HEAP8[((buffer)>>0)] = 0;
+ HEAP8[buffer] = 0;
};
-
var _environ_get = (__environ, environ_buf) => {
var bufSize = 0;
getEnvStrings().forEach((string, i) => {
@@ -6201,7 +6099,6 @@ function dbg(text) {
return 0;
};
-
var _environ_sizes_get = (penviron_count, penviron_buf_size) => {
var strings = getEnvStrings();
HEAPU32[((penviron_count)>>2)] = strings.length;
@@ -6239,10 +6136,10 @@ function dbg(text) {
FS.isLink(stream.mode) ? 7 :
4;
}
- HEAP8[((pbuf)>>0)] = type;
+ HEAP8[pbuf] = type;
HEAP16[(((pbuf)+(2))>>1)] = flags;
- (tempI64 = [rightsBase>>>0,(tempDouble=rightsBase,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((pbuf)+(8))>>2)] = tempI64[0],HEAP32[(((pbuf)+(12))>>2)] = tempI64[1]);
- (tempI64 = [rightsInheriting>>>0,(tempDouble=rightsInheriting,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((pbuf)+(16))>>2)] = tempI64[0],HEAP32[(((pbuf)+(20))>>2)] = tempI64[1]);
+ (tempI64 = [rightsBase>>>0,(tempDouble = rightsBase,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((pbuf)+(8))>>2)] = tempI64[0],HEAP32[(((pbuf)+(12))>>2)] = tempI64[1]);
+ (tempI64 = [rightsInheriting>>>0,(tempDouble = rightsInheriting,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((pbuf)+(16))>>2)] = tempI64[0],HEAP32[(((pbuf)+(20))>>2)] = tempI64[1]);
return 0;
} catch (e) {
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
@@ -6261,7 +6158,7 @@ function dbg(text) {
if (curr < 0) return -1;
ret += curr;
if (curr < len) break; // nothing more to read
- if (typeof offset !== 'undefined') {
+ if (typeof offset != 'undefined') {
offset += curr;
}
}
@@ -6283,7 +6180,7 @@ function dbg(text) {
function _fd_seek(fd,offset_low, offset_high,whence,newOffset) {
- var offset = convertI32PairToI53Checked(offset_low, offset_high);;
+ var offset = convertI32PairToI53Checked(offset_low, offset_high);
try {
@@ -6291,7 +6188,7 @@ function dbg(text) {
if (isNaN(offset)) return 61;
var stream = SYSCALLS.getStreamFromFD(fd);
FS.llseek(stream, offset, whence);
- (tempI64 = [stream.position>>>0,(tempDouble=stream.position,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[((newOffset)>>2)] = tempI64[0],HEAP32[(((newOffset)+(4))>>2)] = tempI64[1]);
+ (tempI64 = [stream.position>>>0,(tempDouble = stream.position,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[((newOffset)>>2)] = tempI64[0],HEAP32[(((newOffset)+(4))>>2)] = tempI64[1]);
if (stream.getdents && offset === 0 && whence === 0) stream.getdents = null; // reset readdir state
return 0;
} catch (e) {
@@ -6305,7 +6202,7 @@ function dbg(text) {
try {
var stream = SYSCALLS.getStreamFromFD(fd);
- if (stream.stream_ops && stream.stream_ops.fsync) {
+ if (stream.stream_ops?.fsync) {
return stream.stream_ops.fsync(stream);
}
return 0; // we can't do anything synchronously; the in-memory FS is already synced to
@@ -6325,7 +6222,7 @@ function dbg(text) {
var curr = FS.write(stream, HEAP8, ptr, len, offset);
if (curr < 0) return -1;
ret += curr;
- if (typeof offset !== 'undefined') {
+ if (typeof offset != 'undefined') {
offset += curr;
}
}
@@ -6540,42 +6437,6 @@ function dbg(text) {
- var getHostByName = (name) => {
- // generate hostent
- var ret = _malloc(20); // XXX possibly leaked, as are others here
- var nameBuf = stringToNewUTF8(name);
- HEAPU32[((ret)>>2)] = nameBuf;
- var aliasesBuf = _malloc(4);
- HEAPU32[((aliasesBuf)>>2)] = 0;
- HEAPU32[(((ret)+(4))>>2)] = aliasesBuf;
- var afinet = 2;
- HEAP32[(((ret)+(8))>>2)] = afinet;
- HEAP32[(((ret)+(12))>>2)] = 4;
- var addrListBuf = _malloc(12);
- HEAPU32[((addrListBuf)>>2)] = addrListBuf+8;
- HEAPU32[(((addrListBuf)+(4))>>2)] = 0;
- HEAP32[(((addrListBuf)+(8))>>2)] = inetPton4(DNS.lookup_name(name));
- HEAPU32[(((ret)+(16))>>2)] = addrListBuf;
- return ret;
- };
-
- var _gethostbyname = (name) => {
- return getHostByName(UTF8ToString(name));
- };
-
-
- var _gethostbyname_r = (name, ret, buf, buflen, out, err) => {
- var data = _gethostbyname(name);
- _memcpy(ret, data, 20);
- _free(data);
- HEAP32[((err)>>2)] = 0;
- HEAPU32[((out)>>2)] = ret;
- return 0;
- };
-
-
-
-
var _getnameinfo = (sa, salen, node, nodelen, serv, servlen, flags) => {
var info = readSockaddr(sa, salen);
if (info.errno) {
@@ -6740,267 +6601,6 @@ function dbg(text) {
- var writeArrayToMemory = (array, buffer) => {
- assert(array.length >= 0, 'writeArrayToMemory array must have a length (should be an array or typed array)')
- HEAP8.set(array, buffer);
- };
-
- var _strftime = (s, maxsize, format, tm) => {
- // size_t strftime(char *restrict s, size_t maxsize, const char *restrict format, const struct tm *restrict timeptr);
- // http://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html
-
- var tm_zone = HEAPU32[(((tm)+(40))>>2)];
-
- var date = {
- tm_sec: HEAP32[((tm)>>2)],
- tm_min: HEAP32[(((tm)+(4))>>2)],
- tm_hour: HEAP32[(((tm)+(8))>>2)],
- tm_mday: HEAP32[(((tm)+(12))>>2)],
- tm_mon: HEAP32[(((tm)+(16))>>2)],
- tm_year: HEAP32[(((tm)+(20))>>2)],
- tm_wday: HEAP32[(((tm)+(24))>>2)],
- tm_yday: HEAP32[(((tm)+(28))>>2)],
- tm_isdst: HEAP32[(((tm)+(32))>>2)],
- tm_gmtoff: HEAP32[(((tm)+(36))>>2)],
- tm_zone: tm_zone ? UTF8ToString(tm_zone) : ''
- };
-
- var pattern = UTF8ToString(format);
-
- // expand format
- var EXPANSION_RULES_1 = {
- '%c': '%a %b %d %H:%M:%S %Y', // Replaced by the locale's appropriate date and time representation - e.g., Mon Aug 3 14:02:01 2013
- '%D': '%m/%d/%y', // Equivalent to %m / %d / %y
- '%F': '%Y-%m-%d', // Equivalent to %Y - %m - %d
- '%h': '%b', // Equivalent to %b
- '%r': '%I:%M:%S %p', // Replaced by the time in a.m. and p.m. notation
- '%R': '%H:%M', // Replaced by the time in 24-hour notation
- '%T': '%H:%M:%S', // Replaced by the time
- '%x': '%m/%d/%y', // Replaced by the locale's appropriate date representation
- '%X': '%H:%M:%S', // Replaced by the locale's appropriate time representation
- // Modified Conversion Specifiers
- '%Ec': '%c', // Replaced by the locale's alternative appropriate date and time representation.
- '%EC': '%C', // Replaced by the name of the base year (period) in the locale's alternative representation.
- '%Ex': '%m/%d/%y', // Replaced by the locale's alternative date representation.
- '%EX': '%H:%M:%S', // Replaced by the locale's alternative time representation.
- '%Ey': '%y', // Replaced by the offset from %EC (year only) in the locale's alternative representation.
- '%EY': '%Y', // Replaced by the full alternative year representation.
- '%Od': '%d', // Replaced by the day of the month, using the locale's alternative numeric symbols, filled as needed with leading zeros if there is any alternative symbol for zero; otherwise, with leading <space> characters.
- '%Oe': '%e', // Replaced by the day of the month, using the locale's alternative numeric symbols, filled as needed with leading <space> characters.
- '%OH': '%H', // Replaced by the hour (24-hour clock) using the locale's alternative numeric symbols.
- '%OI': '%I', // Replaced by the hour (12-hour clock) using the locale's alternative numeric symbols.
- '%Om': '%m', // Replaced by the month using the locale's alternative numeric symbols.
- '%OM': '%M', // Replaced by the minutes using the locale's alternative numeric symbols.
- '%OS': '%S', // Replaced by the seconds using the locale's alternative numeric symbols.
- '%Ou': '%u', // Replaced by the weekday as a number in the locale's alternative representation (Monday=1).
- '%OU': '%U', // Replaced by the week number of the year (Sunday as the first day of the week, rules corresponding to %U ) using the locale's alternative numeric symbols.
- '%OV': '%V', // Replaced by the week number of the year (Monday as the first day of the week, rules corresponding to %V ) using the locale's alternative numeric symbols.
- '%Ow': '%w', // Replaced by the number of the weekday (Sunday=0) using the locale's alternative numeric symbols.
- '%OW': '%W', // Replaced by the week number of the year (Monday as the first day of the week) using the locale's alternative numeric symbols.
- '%Oy': '%y', // Replaced by the year (offset from %C ) using the locale's alternative numeric symbols.
- };
- for (var rule in EXPANSION_RULES_1) {
- pattern = pattern.replace(new RegExp(rule, 'g'), EXPANSION_RULES_1[rule]);
- }
-
- var WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
- var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
-
- function leadingSomething(value, digits, character) {
- var str = typeof value == 'number' ? value.toString() : (value || '');
- while (str.length < digits) {
- str = character[0]+str;
- }
- return str;
- }
-
- function leadingNulls(value, digits) {
- return leadingSomething(value, digits, '0');
- }
-
- function compareByDay(date1, date2) {
- function sgn(value) {
- return value < 0 ? -1 : (value > 0 ? 1 : 0);
- }
-
- var compare;
- if ((compare = sgn(date1.getFullYear()-date2.getFullYear())) === 0) {
- if ((compare = sgn(date1.getMonth()-date2.getMonth())) === 0) {
- compare = sgn(date1.getDate()-date2.getDate());
- }
- }
- return compare;
- }
-
- function getFirstWeekStartDate(janFourth) {
- switch (janFourth.getDay()) {
- case 0: // Sunday
- return new Date(janFourth.getFullYear()-1, 11, 29);
- case 1: // Monday
- return janFourth;
- case 2: // Tuesday
- return new Date(janFourth.getFullYear(), 0, 3);
- case 3: // Wednesday
- return new Date(janFourth.getFullYear(), 0, 2);
- case 4: // Thursday
- return new Date(janFourth.getFullYear(), 0, 1);
- case 5: // Friday
- return new Date(janFourth.getFullYear()-1, 11, 31);
- case 6: // Saturday
- return new Date(janFourth.getFullYear()-1, 11, 30);
- }
- }
-
- function getWeekBasedYear(date) {
- var thisDate = addDays(new Date(date.tm_year+1900, 0, 1), date.tm_yday);
-
- var janFourthThisYear = new Date(thisDate.getFullYear(), 0, 4);
- var janFourthNextYear = new Date(thisDate.getFullYear()+1, 0, 4);
-
- var firstWeekStartThisYear = getFirstWeekStartDate(janFourthThisYear);
- var firstWeekStartNextYear = getFirstWeekStartDate(janFourthNextYear);
-
- if (compareByDay(firstWeekStartThisYear, thisDate) <= 0) {
- // this date is after the start of the first week of this year
- if (compareByDay(firstWeekStartNextYear, thisDate) <= 0) {
- return thisDate.getFullYear()+1;
- }
- return thisDate.getFullYear();
- }
- return thisDate.getFullYear()-1;
- }
-
- var EXPANSION_RULES_2 = {
- '%a': (date) => WEEKDAYS[date.tm_wday].substring(0,3) ,
- '%A': (date) => WEEKDAYS[date.tm_wday],
- '%b': (date) => MONTHS[date.tm_mon].substring(0,3),
- '%B': (date) => MONTHS[date.tm_mon],
- '%C': (date) => {
- var year = date.tm_year+1900;
- return leadingNulls((year/100)|0,2);
- },
- '%d': (date) => leadingNulls(date.tm_mday, 2),
- '%e': (date) => leadingSomething(date.tm_mday, 2, ' '),
- '%g': (date) => {
- // %g, %G, and %V give values according to the ISO 8601:2000 standard week-based year.
- // In this system, weeks begin on a Monday and week 1 of the year is the week that includes
- // January 4th, which is also the week that includes the first Thursday of the year, and
- // is also the first week that contains at least four days in the year.
- // If the first Monday of January is the 2nd, 3rd, or 4th, the preceding days are part of
- // the last week of the preceding year; thus, for Saturday 2nd January 1999,
- // %G is replaced by 1998 and %V is replaced by 53. If December 29th, 30th,
- // or 31st is a Monday, it and any following days are part of week 1 of the following year.
- // Thus, for Tuesday 30th December 1997, %G is replaced by 1998 and %V is replaced by 01.
-
- return getWeekBasedYear(date).toString().substring(2);
- },
- '%G': (date) => getWeekBasedYear(date),
- '%H': (date) => leadingNulls(date.tm_hour, 2),
- '%I': (date) => {
- var twelveHour = date.tm_hour;
- if (twelveHour == 0) twelveHour = 12;
- else if (twelveHour > 12) twelveHour -= 12;
- return leadingNulls(twelveHour, 2);
- },
- '%j': (date) => {
- // Day of the year (001-366)
- return leadingNulls(date.tm_mday + arraySum(isLeapYear(date.tm_year+1900) ? MONTH_DAYS_LEAP : MONTH_DAYS_REGULAR, date.tm_mon-1), 3);
- },
- '%m': (date) => leadingNulls(date.tm_mon+1, 2),
- '%M': (date) => leadingNulls(date.tm_min, 2),
- '%n': () => '\n',
- '%p': (date) => {
- if (date.tm_hour >= 0 && date.tm_hour < 12) {
- return 'AM';
- }
- return 'PM';
- },
- '%S': (date) => leadingNulls(date.tm_sec, 2),
- '%t': () => '\t',
- '%u': (date) => date.tm_wday || 7,
- '%U': (date) => {
- var days = date.tm_yday + 7 - date.tm_wday;
- return leadingNulls(Math.floor(days / 7), 2);
- },
- '%V': (date) => {
- // Replaced by the week number of the year (Monday as the first day of the week)
- // as a decimal number [01,53]. If the week containing 1 January has four
- // or more days in the new year, then it is considered week 1.
- // Otherwise, it is the last week of the previous year, and the next week is week 1.
- // Both January 4th and the first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday]
- var val = Math.floor((date.tm_yday + 7 - (date.tm_wday + 6) % 7 ) / 7);
- // If 1 Jan is just 1-3 days past Monday, the previous week
- // is also in this year.
- if ((date.tm_wday + 371 - date.tm_yday - 2) % 7 <= 2) {
- val++;
- }
- if (!val) {
- val = 52;
- // If 31 December of prev year a Thursday, or Friday of a
- // leap year, then the prev year has 53 weeks.
- var dec31 = (date.tm_wday + 7 - date.tm_yday - 1) % 7;
- if (dec31 == 4 || (dec31 == 5 && isLeapYear(date.tm_year%400-1))) {
- val++;
- }
- } else if (val == 53) {
- // If 1 January is not a Thursday, and not a Wednesday of a
- // leap year, then this year has only 52 weeks.
- var jan1 = (date.tm_wday + 371 - date.tm_yday) % 7;
- if (jan1 != 4 && (jan1 != 3 || !isLeapYear(date.tm_year)))
- val = 1;
- }
- return leadingNulls(val, 2);
- },
- '%w': (date) => date.tm_wday,
- '%W': (date) => {
- var days = date.tm_yday + 7 - ((date.tm_wday + 6) % 7);
- return leadingNulls(Math.floor(days / 7), 2);
- },
- '%y': (date) => {
- // Replaced by the last two digits of the year as a decimal number [00,99]. [ tm_year]
- return (date.tm_year+1900).toString().substring(2);
- },
- // Replaced by the year as a decimal number (for example, 1997). [ tm_year]
- '%Y': (date) => date.tm_year+1900,
- '%z': (date) => {
- // Replaced by the offset from UTC in the ISO 8601:2000 standard format ( +hhmm or -hhmm ).
- // For example, "-0430" means 4 hours 30 minutes behind UTC (west of Greenwich).
- var off = date.tm_gmtoff;
- var ahead = off >= 0;
- off = Math.abs(off) / 60;
- // convert from minutes into hhmm format (which means 60 minutes = 100 units)
- off = (off / 60)*100 + (off % 60);
- return (ahead ? '+' : '-') + String("0000" + off).slice(-4);
- },
- '%Z': (date) => date.tm_zone,
- '%%': () => '%'
- };
-
- // Replace %% with a pair of NULLs (which cannot occur in a C string), then
- // re-inject them after processing.
- pattern = pattern.replace(/%%/g, '\0\0')
- for (var rule in EXPANSION_RULES_2) {
- if (pattern.includes(rule)) {
- pattern = pattern.replace(new RegExp(rule, 'g'), EXPANSION_RULES_2[rule](date));
- }
- }
- pattern = pattern.replace(/\0\0/g, '%')
-
- var bytes = intArrayFromString(pattern, false);
- if (bytes.length > maxsize) {
- return 0;
- }
-
- writeArrayToMemory(bytes, s);
- return bytes.length-1;
- };
-
-
-
-
-
-
-
var _strptime = (buf, format, tm) => {
// char *strptime(const char *restrict buf, const char *restrict format, struct tm *restrict tm);
@@ -7016,64 +6616,64 @@ function dbg(text) {
// reduce number of matchers
var EQUIVALENT_MATCHERS = {
- '%A': '%a',
- '%B': '%b',
- '%c': '%a %b %d %H:%M:%S %Y',
- '%D': '%m\\/%d\\/%y',
- '%e': '%d',
- '%F': '%Y-%m-%d',
- '%h': '%b',
- '%R': '%H\\:%M',
- '%r': '%I\\:%M\\:%S\\s%p',
- '%T': '%H\\:%M\\:%S',
- '%x': '%m\\/%d\\/(?:%y|%Y)',
- '%X': '%H\\:%M\\:%S'
+ 'A': '%a',
+ 'B': '%b',
+ 'c': '%a %b %d %H:%M:%S %Y',
+ 'D': '%m\\/%d\\/%y',
+ 'e': '%d',
+ 'F': '%Y-%m-%d',
+ 'h': '%b',
+ 'R': '%H\\:%M',
+ 'r': '%I\\:%M\\:%S\\s%p',
+ 'T': '%H\\:%M\\:%S',
+ 'x': '%m\\/%d\\/(?:%y|%Y)',
+ 'X': '%H\\:%M\\:%S'
};
- for (var matcher in EQUIVALENT_MATCHERS) {
- pattern = pattern.replace(matcher, EQUIVALENT_MATCHERS[matcher]);
- }
-
// TODO: take care of locale
var DATE_PATTERNS = {
- /* weeday name */ '%a': '(?:Sun(?:day)?)|(?:Mon(?:day)?)|(?:Tue(?:sday)?)|(?:Wed(?:nesday)?)|(?:Thu(?:rsday)?)|(?:Fri(?:day)?)|(?:Sat(?:urday)?)',
- /* month name */ '%b': '(?:Jan(?:uary)?)|(?:Feb(?:ruary)?)|(?:Mar(?:ch)?)|(?:Apr(?:il)?)|May|(?:Jun(?:e)?)|(?:Jul(?:y)?)|(?:Aug(?:ust)?)|(?:Sep(?:tember)?)|(?:Oct(?:ober)?)|(?:Nov(?:ember)?)|(?:Dec(?:ember)?)',
- /* century */ '%C': '\\d\\d',
- /* day of month */ '%d': '0[1-9]|[1-9](?!\\d)|1\\d|2\\d|30|31',
- /* hour (24hr) */ '%H': '\\d(?!\\d)|[0,1]\\d|20|21|22|23',
- /* hour (12hr) */ '%I': '\\d(?!\\d)|0\\d|10|11|12',
- /* day of year */ '%j': '00[1-9]|0?[1-9](?!\\d)|0?[1-9]\\d(?!\\d)|[1,2]\\d\\d|3[0-6]\\d',
- /* month */ '%m': '0[1-9]|[1-9](?!\\d)|10|11|12',
- /* minutes */ '%M': '0\\d|\\d(?!\\d)|[1-5]\\d',
- /* whitespace */ '%n': '\\s',
- /* AM/PM */ '%p': 'AM|am|PM|pm|A\\.M\\.|a\\.m\\.|P\\.M\\.|p\\.m\\.',
- /* seconds */ '%S': '0\\d|\\d(?!\\d)|[1-5]\\d|60',
- /* week number */ '%U': '0\\d|\\d(?!\\d)|[1-4]\\d|50|51|52|53',
- /* week number */ '%W': '0\\d|\\d(?!\\d)|[1-4]\\d|50|51|52|53',
- /* weekday number */ '%w': '[0-6]',
- /* 2-digit year */ '%y': '\\d\\d',
- /* 4-digit year */ '%Y': '\\d\\d\\d\\d',
- /* % */ '%%': '%',
- /* whitespace */ '%t': '\\s',
+ /* weekday name */ 'a': '(?:Sun(?:day)?)|(?:Mon(?:day)?)|(?:Tue(?:sday)?)|(?:Wed(?:nesday)?)|(?:Thu(?:rsday)?)|(?:Fri(?:day)?)|(?:Sat(?:urday)?)',
+ /* month name */ 'b': '(?:Jan(?:uary)?)|(?:Feb(?:ruary)?)|(?:Mar(?:ch)?)|(?:Apr(?:il)?)|May|(?:Jun(?:e)?)|(?:Jul(?:y)?)|(?:Aug(?:ust)?)|(?:Sep(?:tember)?)|(?:Oct(?:ober)?)|(?:Nov(?:ember)?)|(?:Dec(?:ember)?)',
+ /* century */ 'C': '\\d\\d',
+ /* day of month */ 'd': '0[1-9]|[1-9](?!\\d)|1\\d|2\\d|30|31',
+ /* hour (24hr) */ 'H': '\\d(?!\\d)|[0,1]\\d|20|21|22|23',
+ /* hour (12hr) */ 'I': '\\d(?!\\d)|0\\d|10|11|12',
+ /* day of year */ 'j': '00[1-9]|0?[1-9](?!\\d)|0?[1-9]\\d(?!\\d)|[1,2]\\d\\d|3[0-6]\\d',
+ /* month */ 'm': '0[1-9]|[1-9](?!\\d)|10|11|12',
+ /* minutes */ 'M': '0\\d|\\d(?!\\d)|[1-5]\\d',
+ /* whitespace */ 'n': ' ',
+ /* AM/PM */ 'p': 'AM|am|PM|pm|A\\.M\\.|a\\.m\\.|P\\.M\\.|p\\.m\\.',
+ /* seconds */ 'S': '0\\d|\\d(?!\\d)|[1-5]\\d|60',
+ /* week number */ 'U': '0\\d|\\d(?!\\d)|[1-4]\\d|50|51|52|53',
+ /* week number */ 'W': '0\\d|\\d(?!\\d)|[1-4]\\d|50|51|52|53',
+ /* weekday number */ 'w': '[0-6]',
+ /* 2-digit year */ 'y': '\\d\\d',
+ /* 4-digit year */ 'Y': '\\d\\d\\d\\d',
+ /* whitespace */ 't': ' ',
+ /* time zone */ 'z': 'Z|(?:[\\+\\-]\\d\\d:?(?:\\d\\d)?)'
};
var MONTH_NUMBERS = {JAN: 0, FEB: 1, MAR: 2, APR: 3, MAY: 4, JUN: 5, JUL: 6, AUG: 7, SEP: 8, OCT: 9, NOV: 10, DEC: 11};
var DAY_NUMBERS_SUN_FIRST = {SUN: 0, MON: 1, TUE: 2, WED: 3, THU: 4, FRI: 5, SAT: 6};
var DAY_NUMBERS_MON_FIRST = {MON: 0, TUE: 1, WED: 2, THU: 3, FRI: 4, SAT: 5, SUN: 6};
- for (var datePattern in DATE_PATTERNS) {
- pattern = pattern.replace(datePattern, '('+datePattern+DATE_PATTERNS[datePattern]+')');
- }
-
- // take care of capturing groups
var capture = [];
- for (var i=pattern.indexOf('%'); i>=0; i=pattern.indexOf('%')) {
- capture.push(pattern[i+1]);
- pattern = pattern.replace(new RegExp('\\%'+pattern[i+1], 'g'), '');
- }
+ var pattern_out = pattern
+ .replace(/%(.)/g, (m, c) => EQUIVALENT_MATCHERS[c] || m)
+ .replace(/%(.)/g, (_, c) => {
+ let pat = DATE_PATTERNS[c];
+ if (pat){
+ capture.push(c);
+ return `(${pat})`;
+ } else {
+ return c;
+ }
+ })
+ .replace( // any number of space or tab characters match zero or more spaces
+ /\s+/g,'\\s*'
+ );
- var matches = new RegExp('^'+pattern, "i").exec(UTF8ToString(buf))
- // out(UTF8ToString(buf)+ ' is matched by '+((new RegExp('^'+pattern)).source)+' into: '+JSON.stringify(matches));
+ var matches = new RegExp('^'+pattern_out, "i").exec(UTF8ToString(buf))
function initDate() {
function fixup(value, min, max) {
@@ -7085,7 +6685,8 @@ function dbg(text) {
day: fixup(HEAP32[(((tm)+(12))>>2)], 1, 31),
hour: fixup(HEAP32[(((tm)+(8))>>2)], 0, 23),
min: fixup(HEAP32[(((tm)+(4))>>2)], 0, 59),
- sec: fixup(HEAP32[((tm)>>2)], 0, 59)
+ sec: fixup(HEAP32[((tm)>>2)], 0, 59),
+ gmtoff: 0
};
};
@@ -7212,6 +6813,20 @@ function dbg(text) {
}
}
+ // time zone
+ if ((value = getMatch('z'))) {
+ // GMT offset as either 'Z' or +-HH:MM or +-HH or +-HHMM
+ if (value.toLowerCase() === 'z'){
+ date.gmtoff = 0;
+ } else {
+ var match = value.match(/^((?:\-|\+)\d\d):?(\d\d)?/);
+ date.gmtoff = match[1] * 3600;
+ if (match[2]) {
+ date.gmtoff += date.gmtoff >0 ? match[2] * 60 : -match[2] * 60
+ }
+ }
+ }
+
/*
tm_sec int seconds after the minute 0-61*
tm_min int minutes after the hour 0-59
@@ -7222,6 +6837,7 @@ function dbg(text) {
tm_wday int days since Sunday 0-6
tm_yday int days since January 1 0-365
tm_isdst int Daylight Saving Time flag
+ tm_gmtoff long offset from GMT (seconds)
*/
var fullDate = new Date(date.year, date.month, date.day, date.hour, date.min, date.sec, 0);
@@ -7234,7 +6850,8 @@ function dbg(text) {
HEAP32[(((tm)+(24))>>2)] = fullDate.getDay();
HEAP32[(((tm)+(28))>>2)] = arraySum(isLeapYear(fullDate.getFullYear()) ? MONTH_DAYS_LEAP : MONTH_DAYS_REGULAR, fullDate.getMonth()-1)+fullDate.getDate()-1;
HEAP32[(((tm)+(32))>>2)] = 0;
-
+ HEAP32[(((tm)+(36))>>2)] = date.gmtoff;
+
// we need to convert the matched sequence into an integer array to take care of UTF-8 characters > 0x7F
// TODO: not sure that intArrayFromString handles all unicode characters correctly
return buf+intArrayFromString(matches[0]).length-1;
@@ -7257,8 +6874,14 @@ function dbg(text) {
return func;
};
+ var writeArrayToMemory = (array, buffer) => {
+ assert(array.length >= 0, 'writeArrayToMemory array must have a length (should be an array or typed array)')
+ HEAP8.set(array, buffer);
+ };
+
+ var stackAlloc = (sz) => __emscripten_stack_alloc(sz);
var stringToUTF8OnStack = (str) => {
var size = lengthBytesUTF8(str) + 1;
var ret = stackAlloc(size);
@@ -7267,6 +6890,9 @@ function dbg(text) {
};
+
+
+
/**
* @param {string|null=} returnType
* @param {Array=} argTypes
@@ -7315,7 +6941,7 @@ function dbg(text) {
}
}
}
- var ret = func.apply(null, cArgs);
+ var ret = func(...cArgs);
function onDone(ret) {
if (stack !== 0) stackRestore(stack);
return convertReturnValue(ret);
@@ -7325,176 +6951,8 @@ function dbg(text) {
return ret;
};
- var FSNode = /** @constructor */ function(parent, name, mode, rdev) {
- if (!parent) {
- parent = this; // root node sets parent to itself
- }
- this.parent = parent;
- this.mount = parent.mount;
- this.mounted = null;
- this.id = FS.nextInode++;
- this.name = name;
- this.mode = mode;
- this.node_ops = {};
- this.stream_ops = {};
- this.rdev = rdev;
- };
- var readMode = 292/*292*/ | 73/*73*/;
- var writeMode = 146/*146*/;
- Object.defineProperties(FSNode.prototype, {
- read: {
- get: /** @this{FSNode} */function() {
- return (this.mode & readMode) === readMode;
- },
- set: /** @this{FSNode} */function(val) {
- val ? this.mode |= readMode : this.mode &= ~readMode;
- }
- },
- write: {
- get: /** @this{FSNode} */function() {
- return (this.mode & writeMode) === writeMode;
- },
- set: /** @this{FSNode} */function(val) {
- val ? this.mode |= writeMode : this.mode &= ~writeMode;
- }
- },
- isFolder: {
- get: /** @this{FSNode} */function() {
- return FS.isDir(this.mode);
- }
- },
- isDevice: {
- get: /** @this{FSNode} */function() {
- return FS.isChrdev(this.mode);
- }
- }
- });
- FS.FSNode = FSNode;
FS.createPreloadedFile = FS_createPreloadedFile;
FS.staticInit();;
-ERRNO_CODES = {
- 'EPERM': 63,
- 'ENOENT': 44,
- 'ESRCH': 71,
- 'EINTR': 27,
- 'EIO': 29,
- 'ENXIO': 60,
- 'E2BIG': 1,
- 'ENOEXEC': 45,
- 'EBADF': 8,
- 'ECHILD': 12,
- 'EAGAIN': 6,
- 'EWOULDBLOCK': 6,
- 'ENOMEM': 48,
- 'EACCES': 2,
- 'EFAULT': 21,
- 'ENOTBLK': 105,
- 'EBUSY': 10,
- 'EEXIST': 20,
- 'EXDEV': 75,
- 'ENODEV': 43,
- 'ENOTDIR': 54,
- 'EISDIR': 31,
- 'EINVAL': 28,
- 'ENFILE': 41,
- 'EMFILE': 33,
- 'ENOTTY': 59,
- 'ETXTBSY': 74,
- 'EFBIG': 22,
- 'ENOSPC': 51,
- 'ESPIPE': 70,
- 'EROFS': 69,
- 'EMLINK': 34,
- 'EPIPE': 64,
- 'EDOM': 18,
- 'ERANGE': 68,
- 'ENOMSG': 49,
- 'EIDRM': 24,
- 'ECHRNG': 106,
- 'EL2NSYNC': 156,
- 'EL3HLT': 107,
- 'EL3RST': 108,
- 'ELNRNG': 109,
- 'EUNATCH': 110,
- 'ENOCSI': 111,
- 'EL2HLT': 112,
- 'EDEADLK': 16,
- 'ENOLCK': 46,
- 'EBADE': 113,
- 'EBADR': 114,
- 'EXFULL': 115,
- 'ENOANO': 104,
- 'EBADRQC': 103,
- 'EBADSLT': 102,
- 'EDEADLOCK': 16,
- 'EBFONT': 101,
- 'ENOSTR': 100,
- 'ENODATA': 116,
- 'ETIME': 117,
- 'ENOSR': 118,
- 'ENONET': 119,
- 'ENOPKG': 120,
- 'EREMOTE': 121,
- 'ENOLINK': 47,
- 'EADV': 122,
- 'ESRMNT': 123,
- 'ECOMM': 124,
- 'EPROTO': 65,
- 'EMULTIHOP': 36,
- 'EDOTDOT': 125,
- 'EBADMSG': 9,
- 'ENOTUNIQ': 126,
- 'EBADFD': 127,
- 'EREMCHG': 128,
- 'ELIBACC': 129,
- 'ELIBBAD': 130,
- 'ELIBSCN': 131,
- 'ELIBMAX': 132,
- 'ELIBEXEC': 133,
- 'ENOSYS': 52,
- 'ENOTEMPTY': 55,
- 'ENAMETOOLONG': 37,
- 'ELOOP': 32,
- 'EOPNOTSUPP': 138,
- 'EPFNOSUPPORT': 139,
- 'ECONNRESET': 15,
- 'ENOBUFS': 42,
- 'EAFNOSUPPORT': 5,
- 'EPROTOTYPE': 67,
- 'ENOTSOCK': 57,
- 'ENOPROTOOPT': 50,
- 'ESHUTDOWN': 140,
- 'ECONNREFUSED': 14,
- 'EADDRINUSE': 3,
- 'ECONNABORTED': 13,
- 'ENETUNREACH': 40,
- 'ENETDOWN': 38,
- 'ETIMEDOUT': 73,
- 'EHOSTDOWN': 142,
- 'EHOSTUNREACH': 23,
- 'EINPROGRESS': 26,
- 'EALREADY': 7,
- 'EDESTADDRREQ': 17,
- 'EMSGSIZE': 35,
- 'EPROTONOSUPPORT': 66,
- 'ESOCKTNOSUPPORT': 137,
- 'EADDRNOTAVAIL': 4,
- 'ENETRESET': 39,
- 'EISCONN': 30,
- 'ENOTCONN': 53,
- 'ETOOMANYREFS': 141,
- 'EUSERS': 136,
- 'EDQUOT': 19,
- 'ESTALE': 72,
- 'ENOTSUP': 138,
- 'ENOMEDIUM': 148,
- 'EILSEQ': 25,
- 'EOVERFLOW': 61,
- 'ECANCELED': 11,
- 'ENOTRECOVERABLE': 56,
- 'EOWNERDEAD': 62,
- 'ESTRPIPE': 135,
- };;
function checkIncomingModuleAPI() {
ignoredModuleProp('fetchSettings');
}
@@ -7580,8 +7038,16 @@ var wasmImports = {
/** @export */
__syscall_utimensat: ___syscall_utimensat,
/** @export */
+ _abort_js: __abort_js,
+ /** @export */
_emscripten_get_now_is_monotonic: __emscripten_get_now_is_monotonic,
/** @export */
+ _emscripten_lookup_name: __emscripten_lookup_name,
+ /** @export */
+ _emscripten_memcpy_js: __emscripten_memcpy_js,
+ /** @export */
+ _emscripten_runtime_keepalive_clear: __emscripten_runtime_keepalive_clear,
+ /** @export */
_emscripten_throw_longjmp: __emscripten_throw_longjmp,
/** @export */
_gmtime_js: __gmtime_js,
@@ -7598,8 +7064,6 @@ var wasmImports = {
/** @export */
_tzset_js: __tzset_js,
/** @export */
- abort: _abort,
- /** @export */
emscripten_date_now: _emscripten_date_now,
/** @export */
emscripten_err: _emscripten_err,
@@ -7608,8 +7072,6 @@ var wasmImports = {
/** @export */
emscripten_get_now: _emscripten_get_now,
/** @export */
- emscripten_memcpy_js: _emscripten_memcpy_js,
- /** @export */
emscripten_resize_heap: _emscripten_resize_heap,
/** @export */
environ_get: _environ_get,
@@ -7636,82 +7098,75 @@ var wasmImports = {
/** @export */
getdtablesize: _getdtablesize,
/** @export */
- gethostbyname_r: _gethostbyname_r,
- /** @export */
getnameinfo: _getnameinfo,
/** @export */
getprotobyname: _getprotobyname,
/** @export */
getprotobynumber: _getprotobynumber,
/** @export */
- invoke_i: invoke_i,
+ invoke_i,
/** @export */
- invoke_ii: invoke_ii,
+ invoke_ii,
/** @export */
- invoke_iii: invoke_iii,
+ invoke_iii,
/** @export */
- invoke_iiii: invoke_iiii,
+ invoke_iiii,
/** @export */
- invoke_iiiii: invoke_iiiii,
+ invoke_iiiii,
/** @export */
- invoke_iiiiii: invoke_iiiiii,
+ invoke_iiiiii,
/** @export */
- invoke_iiiiiii: invoke_iiiiiii,
+ invoke_iiiiiii,
/** @export */
- invoke_iiiiiiiiii: invoke_iiiiiiiiii,
+ invoke_iiiiiiiiii,
/** @export */
- invoke_v: invoke_v,
+ invoke_v,
/** @export */
- invoke_vi: invoke_vi,
+ invoke_vi,
/** @export */
- invoke_vii: invoke_vii,
+ invoke_vii,
/** @export */
- invoke_viidii: invoke_viidii,
+ invoke_viidii,
/** @export */
- invoke_viii: invoke_viii,
+ invoke_viii,
/** @export */
- invoke_viiii: invoke_viiii,
+ invoke_viiii,
/** @export */
- invoke_viiiii: invoke_viiiii,
+ invoke_viiiii,
/** @export */
- invoke_viiiiii: invoke_viiiiii,
+ invoke_viiiiii,
/** @export */
makecontext: _makecontext,
/** @export */
proc_exit: _proc_exit,
/** @export */
- strftime: _strftime,
- /** @export */
strptime: _strptime,
/** @export */
swapcontext: _swapcontext
};
var wasmExports = createWasm();
-var ___wasm_call_ctors = createExportWrapper('__wasm_call_ctors');
-var _php_wasm_run = Module['_php_wasm_run'] = createExportWrapper('php_wasm_run');
-var _malloc = createExportWrapper('malloc');
-var setTempRet0 = createExportWrapper('setTempRet0');
-var _fflush = Module['_fflush'] = createExportWrapper('fflush');
-var _free = createExportWrapper('free');
-var _memcpy = createExportWrapper('memcpy');
-var ___errno_location = createExportWrapper('__errno_location');
-var _htons = createExportWrapper('htons');
-var _ntohs = createExportWrapper('ntohs');
-var _htonl = createExportWrapper('htonl');
-var _emscripten_builtin_memalign = createExportWrapper('emscripten_builtin_memalign');
-var __emscripten_timeout = createExportWrapper('_emscripten_timeout');
-var _setThrew = createExportWrapper('setThrew');
+var ___wasm_call_ctors = createExportWrapper('__wasm_call_ctors', 0);
+var _php_wasm_run = Module['_php_wasm_run'] = createExportWrapper('php_wasm_run', 1);
+var _fflush = createExportWrapper('fflush', 1);
+var _malloc = createExportWrapper('malloc', 1);
+var _strerror = createExportWrapper('strerror', 1);
+var _htons = createExportWrapper('htons', 1);
+var _ntohs = createExportWrapper('ntohs', 1);
+var _htonl = createExportWrapper('htonl', 1);
+var _emscripten_builtin_memalign = createExportWrapper('emscripten_builtin_memalign', 2);
+var __emscripten_timeout = createExportWrapper('_emscripten_timeout', 2);
+var _setThrew = createExportWrapper('setThrew', 2);
+var __emscripten_tempret_set = createExportWrapper('_emscripten_tempret_set', 1);
var _emscripten_stack_init = () => (_emscripten_stack_init = wasmExports['emscripten_stack_init'])();
var _emscripten_stack_get_free = () => (_emscripten_stack_get_free = wasmExports['emscripten_stack_get_free'])();
var _emscripten_stack_get_base = () => (_emscripten_stack_get_base = wasmExports['emscripten_stack_get_base'])();
var _emscripten_stack_get_end = () => (_emscripten_stack_get_end = wasmExports['emscripten_stack_get_end'])();
-var stackSave = createExportWrapper('stackSave');
-var stackRestore = createExportWrapper('stackRestore');
-var stackAlloc = createExportWrapper('stackAlloc');
+var __emscripten_stack_restore = (a0) => (__emscripten_stack_restore = wasmExports['_emscripten_stack_restore'])(a0);
+var __emscripten_stack_alloc = (a0) => (__emscripten_stack_alloc = wasmExports['_emscripten_stack_alloc'])(a0);
var _emscripten_stack_get_current = () => (_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'])();
-var dynCall_vij = Module['dynCall_vij'] = createExportWrapper('dynCall_vij');
-var dynCall_ji = Module['dynCall_ji'] = createExportWrapper('dynCall_ji');
-var dynCall_jiji = Module['dynCall_jiji'] = createExportWrapper('dynCall_jiji');
+var dynCall_vij = Module['dynCall_vij'] = createExportWrapper('dynCall_vij', 4);
+var dynCall_ji = Module['dynCall_ji'] = createExportWrapper('dynCall_ji', 2);
+var dynCall_jiji = Module['dynCall_jiji'] = createExportWrapper('dynCall_jiji', 5);
function invoke_iii(index,a1,a2) {
var sp = stackSave();
@@ -7903,12 +7358,10 @@ var missingLibrarySymbols = [
'readI53FromU64',
'convertI32PairToI53',
'convertU32PairToI53',
+ 'getTempRet0',
'growMemory',
- 'getCallstack',
'emscriptenLog',
- 'convertPCtoSourceLocation',
'readEmAsmArgs',
- 'jstoi_s',
'listenOnce',
'autoResumeAudioContext',
'dynCallLegacy',
@@ -7916,9 +7369,7 @@ var missingLibrarySymbols = [
'dynCall',
'runtimeKeepalivePush',
'runtimeKeepalivePop',
- 'safeSetTimeout',
'asmjsMangle',
- 'handleAllocatorInit',
'HandleAllocator',
'getNativeTypeSize',
'STACK_SIZE',
@@ -7948,10 +7399,10 @@ var missingLibrarySymbols = [
'UTF32ToString',
'stringToUTF32',
'lengthBytesUTF32',
+ 'stringToNewUTF8',
'registerKeyEventCallback',
'maybeCStringToJsString',
'findEventTarget',
- 'findCanvasEventTarget',
'getBoundingClientRect',
'fillMouseEventData',
'registerMouseEventCallback',
@@ -7991,11 +7442,13 @@ var missingLibrarySymbols = [
'setCanvasElementSize',
'getCanvasElementSize',
'jsStackTrace',
- 'stackTrace',
+ 'getCallstack',
+ 'convertPCtoSourceLocation',
'checkWasiClock',
'wasiRightsToMuslOFlags',
'wasiOFlagsToMuslOFlags',
'createDyncallWrapper',
+ 'safeSetTimeout',
'setImmediateWrapped',
'clearImmediateWrapped',
'polyfillSetImmediate',
@@ -8005,12 +7458,13 @@ var missingLibrarySymbols = [
'makePromiseCallback',
'ExceptionInfo',
'findMatchingCatch',
+ 'Browser_asyncPrepareDataCounter',
'setMainLoop',
'FS_unlink',
'FS_mkdirTree',
'_setNetworkCallback',
'heapObjectForWebGLType',
- 'heapAccessShiftForWebGLHeap',
+ 'toTypedArrayIndex',
'webgl_enable_ANGLE_instanced_arrays',
'webgl_enable_OES_vertex_array_object',
'webgl_enable_WEBGL_draw_buffers',
@@ -8019,7 +7473,6 @@ var missingLibrarySymbols = [
'computeUnpackAlignedImageSize',
'colorChannelsInGlTextureFormat',
'emscriptenWebGLGetTexPixelData',
- '__glGenObject',
'emscriptenWebGLGetUniform',
'webglGetUniformLocation',
'webglPrepareUniformLocationsBeforeFirstUse',
@@ -8029,14 +7482,14 @@ var missingLibrarySymbols = [
'writeGLArray',
'registerWebGlEventCallback',
'runAndAbortIfError',
- 'SDL_unicode',
- 'SDL_ttfContext',
- 'SDL_audio',
'ALLOC_NORMAL',
'ALLOC_STACK',
'allocate',
'writeStringToMemory',
'writeAsciiToMemory',
+ 'setErrNo',
+ 'demangle',
+ 'stackTrace',
];
missingLibrarySymbols.forEach(missingLibrarySymbol)
@@ -8049,28 +7502,20 @@ var unexportedSymbols = [
'addOnPostRun',
'addRunDependency',
'removeRunDependency',
- 'FS_createFolder',
- 'FS_createPath',
- 'FS_createLazyFile',
- 'FS_createLink',
- 'FS_createDevice',
- 'FS_readFile',
'out',
'err',
'callMain',
'abort',
- 'keepRuntimeAlive',
'wasmMemory',
'wasmExports',
- 'stackAlloc',
- 'stackSave',
- 'stackRestore',
- 'getTempRet0',
- 'setTempRet0',
'writeStackCookie',
'checkStackCookie',
'readI53FromI64',
'convertI32PairToI53Checked',
+ 'stackSave',
+ 'stackRestore',
+ 'stackAlloc',
+ 'setTempRet0',
'ptrToString',
'zeroMemory',
'exitJS',
@@ -8086,8 +7531,7 @@ var unexportedSymbols = [
'arraySum',
'addDays',
'ERRNO_CODES',
- 'ERRNO_MESSAGES',
- 'setErrNo',
+ 'strError',
'inetPton4',
'inetNtop4',
'inetPton6',
@@ -8095,24 +7539,25 @@ var unexportedSymbols = [
'readSockaddr',
'writeSockaddr',
'DNS',
- 'getHostByName',
'Protocols',
'Sockets',
'initRandomFill',
'randomFill',
'timers',
'warnOnce',
- 'UNWIND_CACHE',
'readEmAsmArgsArray',
'jstoi_q',
+ 'jstoi_s',
'getExecutableName',
'handleException',
+ 'keepRuntimeAlive',
'callUserCallback',
'maybeExit',
'asyncLoad',
'alignMemory',
'mmapAlloc',
'wasmTable',
+ 'noExitRuntime',
'getCFunc',
'freeTableIndexes',
'functionsInTableMap',
@@ -8129,15 +7574,14 @@ var unexportedSymbols = [
'intArrayFromString',
'stringToAscii',
'UTF16Decoder',
- 'stringToNewUTF8',
'stringToUTF8OnStack',
'writeArrayToMemory',
'JSEvents',
'specialHTMLTargets',
+ 'findCanvasEventTarget',
'currentFullscreenStrategy',
'restoreOldWindowedStyle',
- 'demangle',
- 'demangleAll',
+ 'UNWIND_CACHE',
'ExitStatus',
'getEnvStrings',
'doReadv',
@@ -8147,6 +7591,7 @@ var unexportedSymbols = [
'exceptionLast',
'exceptionCaught',
'Browser',
+ 'getPreloadedImageData__data',
'wget',
'SYSCALLS',
'getSocketFromFD',
@@ -8157,8 +7602,12 @@ var unexportedSymbols = [
'FS_getMode',
'FS_stdin_getChar_buffer',
'FS_stdin_getChar',
+ 'FS_createPath',
+ 'FS_createDevice',
+ 'FS_readFile',
'FS',
'FS_createDataFile',
+ 'FS_createLazyFile',
'MEMFS',
'TTY',
'PIPEFS',
@@ -8167,7 +7616,6 @@ var unexportedSymbols = [
'miniTempWebGLFloatBuffers',
'miniTempWebGLIntBuffers',
'GL',
- 'emscripten_webgl_power_preferences',
'AL',
'GLUT',
'EGL',
@@ -8177,6 +7625,8 @@ var unexportedSymbols = [
'SDL_gfx',
'allocateUTF8',
'allocateUTF8OnStack',
+ 'print',
+ 'printErr',
];
unexportedSymbols.forEach(unexportedRuntimeSymbol);
@@ -8226,7 +7676,7 @@ function run() {
initRuntime();
readyPromiseResolve(Module);
- if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
+ Module['onRuntimeInitialized']?.();
assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
@@ -8275,7 +7725,7 @@ function checkUnflushedContent() {
var stream = info.object;
var rdev = stream.rdev;
var tty = TTY.ttys[rdev];
- if (tty && tty.output && tty.output.length) {
+ if (tty?.output?.length) {
has = true;
}
});
@@ -8296,13 +7746,38 @@ if (Module['preInit']) {
run();
-
// end include: postamble.js
-
- return moduleArg.ready
+// include: postamble_modularize.js
+// In MODULARIZE mode we wrap the generated code in a factory function
+// and return either the Module itself, or a promise of the module.
+//
+// We assign to the `moduleRtn` global here and configure closure to see
+// this as and extern so it won't get minified.
+
+moduleRtn = readyPromise;
+
+// Assertion for attempting to access module properties on the incoming
+// moduleArg. In the past we used this object as the prototype of the module
+// and assigned properties to it, but now we return a distinct object. This
+// keeps the instance private until it is ready (i.e the promise has been
+// resolved).
+for (const prop of Object.keys(Module)) {
+ if (!(prop in moduleArg)) {
+ Object.defineProperty(moduleArg, prop, {
+ configurable: true,
+ get() {
+ abort(`Access to module property ('${prop}') is no longer possible via the module constructor argument; Instead, use the result of the module constructor.`)
+ }
+ });
+ }
}
+// end include: postamble_modularize.js
+
+
+ return moduleRtn;
+}
);
})();
-export default Module; \ No newline at end of file
+export default Module;
diff --git a/examples/compile-php-to-wasm/php-wasm.wasm b/examples/compile-php-to-wasm/php-wasm.wasm
index 45f378c..b33d7d1 100755
--- a/examples/compile-php-to-wasm/php-wasm.wasm
+++ b/examples/compile-php-to-wasm/php-wasm.wasm
Binary files differ
diff --git a/examples/php-on-wasm/php-wasm.php b/examples/php-on-wasm/php-wasm.php
index 697b5b3..787037c 100644
--- a/examples/php-on-wasm/php-wasm.php
+++ b/examples/php-on-wasm/php-wasm.php
@@ -30,7 +30,7 @@ $imports = [
'invoke_iiiii' => makeHostFunc('(i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiiii(...)),
'invoke_v' => makeHostFunc('(i32) -> ()', hostFunc__env__invoke_v(...)),
'invoke_ii' => makeHostFunc('(i32, i32) -> (i32)', hostFunc__env__invoke_ii(...)),
- 'abort' => makeHostFunc('() -> ()', hostFunc__env__abort(...)),
+ '_abort_js' => makeHostFunc('() -> ()', hostFunc__env___abort_js(...)),
'exit' => makeHostFunc('(i32) -> ()', hostFunc__env__exit(...)),
'invoke_viii' => makeHostFunc('(i32, i32, i32, i32) -> ()', hostFunc__env__invoke_viii(...)),
'invoke_vii' => makeHostFunc('(i32, i32, i32) -> ()', hostFunc__env__invoke_vii(...)),
@@ -45,7 +45,6 @@ $imports = [
'invoke_iiiiiiiiii' => makeHostFunc('(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiiiiiiiii(...)),
'strftime' => makeHostFunc('(i32, i32, i32, i32) -> (i32)', hostFunc__env__strftime(...)),
'getaddrinfo' => makeHostFunc('(i32, i32, i32, i32) -> (i32)', hostFunc__env__getaddrinfo(...)),
- 'gethostbyname_r' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__gethostbyname_r(...)),
'getdtablesize' => makeHostFunc('() -> (i32)', hostFunc__env__getdtablesize(...)),
'getprotobyname' => makeHostFunc('(i32) -> (i32)', hostFunc__env__getprotobyname(...)),
'getprotobynumber' => makeHostFunc('(i32) -> (i32)', hostFunc__env__getprotobynumber(...)),
@@ -64,7 +63,7 @@ $imports = [
'__syscall_fchownat' => makeHostFunc('(i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_fchownat(...)),
'__syscall_dup' => makeHostFunc('(i32) -> (i32)', hostFunc__env____syscall_dup(...)),
'__syscall_dup3' => makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env____syscall_dup3(...)),
- 'emscripten_memcpy_js' => makeHostFunc('(i32, i32, i32) -> ()', hostFunc__env__emscripten_memcpy_js(...)),
+ '_emscripten_memcpy_js' => makeHostFunc('(i32, i32, i32) -> ()', hostFunc__env___emscripten_memcpy_js(...)),
'emscripten_date_now' => makeHostFunc('() -> (f64)', hostFunc__env__emscripten_date_now(...)),
'_emscripten_get_now_is_monotonic' => makeHostFunc('() -> (i32)', hostFunc__env___emscripten_get_now_is_monotonic(...)),
'emscripten_get_now' => makeHostFunc('() -> (f64)', hostFunc__env__emscripten_get_now(...)),
@@ -79,6 +78,7 @@ $imports = [
'__syscall_mkdirat' => makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env____syscall_mkdirat(...)),
'__syscall_pipe' => makeHostFunc('(i32) -> (i32)', hostFunc__env____syscall_pipe(...)),
'__syscall_poll' => makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env____syscall_poll(...)),
+ '_emscripten_runtime_keepalive_clear' => makeHostFunc('() -> ()', hostFunc__env___emscripten_runtime_keepalive_clear(...)),
'__call_sighandler' => makeHostFunc('(i32, i32) -> ()', hostFunc__env____call_sighandler(...)),
'__syscall_getdents64' => makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env____syscall_getdents64(...)),
'__syscall_readlinkat' => makeHostFunc('(i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_readlinkat(...)),
@@ -97,6 +97,7 @@ $imports = [
'__syscall_accept4' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_accept4(...)),
'__syscall_bind' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_bind(...)),
'__syscall_connect' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_connect(...)),
+ '_emscripten_lookup_name' => makeHostFunc('(i32) -> (i32)', hostFunc__env___emscripten_lookup_name(...)),
'__syscall_getpeername' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_getpeername(...)),
'__syscall_getsockname' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_getsockname(...)),
'__syscall_getsockopt' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_getsockopt(...)),
@@ -136,23 +137,23 @@ function allocateStringOnWasmMemory(Runtime $runtime, string $str): int
{
// Plus 1 for the null terminator in C.
$size = \strlen($str) + 1;
- $outPtr = wasm_stackAlloc($runtime, $size);
+ $outPtr = _emscripten_stack_alloc($runtime, $size);
copyStringToWasmMemory($runtime, $outPtr, $str);
return $outPtr;
}
-function wasm_stackAlloc(Runtime $runtime, int $size): int
+function _emscripten_stack_alloc(Runtime $runtime, int $size): int
{
- $results = $runtime->invoke("stackAlloc", [$size]);
+ $results = $runtime->invoke("_emscripten_stack_alloc", [$size]);
\assert(\count($results) === 1);
$result = $results[0];
\assert(\is_int($result));
return $result;
}
-function wasm_stackSave(Runtime $runtime): int
+function emscripten_stack_get_current(Runtime $runtime): int
{
- $results = $runtime->invoke("stackSave", []);
+ $results = $runtime->invoke("emscripten_stack_get_current", []);
\assert(\count($results) === 1);
$result = $results[0];
\assert(\is_int($result));
@@ -238,7 +239,7 @@ function syscallCalculateAt(Runtime $runtime, int $dirfd, string $path): string
// Type: (i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iii(Runtime $runtime, int $index, int $a1, int $a2): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -249,7 +250,7 @@ function hostFunc__env__invoke_iii(Runtime $runtime, int $index, int $a1, int $a
// Type: (i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -262,7 +263,7 @@ function hostFunc__env__invoke_iiiii(Runtime $runtime, int $index, int $a1, int
// Type: (i32) -> ()
function hostFunc__env__invoke_v(Runtime $runtime, int $index): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->invokeByFuncAddr($func);
}
@@ -270,7 +271,7 @@ function hostFunc__env__invoke_v(Runtime $runtime, int $index): void
// Type: (i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -282,7 +283,7 @@ function hostFunc__env__invoke_iiii(Runtime $runtime, int $index, int $a1, int $
// Type: (i32, i32) -> (i32)
function hostFunc__env__invoke_ii(Runtime $runtime, int $index, int $a1): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->invokeByFuncAddr($func);
@@ -290,9 +291,9 @@ function hostFunc__env__invoke_ii(Runtime $runtime, int $index, int $a1): int
}
// Type: () -> ()
-function hostFunc__env__abort(Runtime $runtime): void
+function hostFunc__env___abort_js(Runtime $runtime): void
{
- throw new \RuntimeException('env::abort: not implemented');
+ throw new \RuntimeException('env::_abort_js: not implemented');
}
// Type: (i32) -> ()
@@ -304,7 +305,7 @@ function hostFunc__env__exit(Runtime $runtime): void
// Type: (i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viii(Runtime $runtime, int $index, int $a1, int $a2, int $a3): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -315,7 +316,7 @@ function hostFunc__env__invoke_viii(Runtime $runtime, int $index, int $a1, int $
// Type: (i32, i32, i32) -> ()
function hostFunc__env__invoke_vii(Runtime $runtime, int $index, int $a1, int $a2): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -325,7 +326,7 @@ function hostFunc__env__invoke_vii(Runtime $runtime, int $index, int $a1, int $a
// Type: (i32, i32) -> ()
function hostFunc__env__invoke_vi(Runtime $runtime, int $index, int $a1): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->invokeByFuncAddr($func);
@@ -334,7 +335,7 @@ function hostFunc__env__invoke_vi(Runtime $runtime, int $index, int $a1): void
// Type: (i32) -> (i32)
function hostFunc__env__invoke_i(Runtime $runtime, int $index): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->invokeByFuncAddr($func);
return $runtime->stack->popInt();
@@ -343,7 +344,7 @@ function hostFunc__env__invoke_i(Runtime $runtime, int $index): int
// Type: (i32, i32, i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4, int $a5, int $a6): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -358,7 +359,7 @@ function hostFunc__env__invoke_iiiiiii(Runtime $runtime, int $index, int $a1, in
// Type: (i32, i32, i32, i32) -> ()
function hostFunc__env____assert_fail(Runtime $runtime, int $index, int $a1, int $a2, int $a3): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -369,7 +370,7 @@ function hostFunc__env____assert_fail(Runtime $runtime, int $index, int $a1, int
// Type: (i32, i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -381,7 +382,7 @@ function hostFunc__env__invoke_viiii(Runtime $runtime, int $index, int $a1, int
// Type: (i32, i32, i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4, int $a5): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -394,7 +395,7 @@ function hostFunc__env__invoke_viiiii(Runtime $runtime, int $index, int $a1, int
// Type: (i32, i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4, int $a5): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -408,7 +409,7 @@ function hostFunc__env__invoke_iiiiii(Runtime $runtime, int $index, int $a1, int
// Type: (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiiiiiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4, int $a5, int $a6, int $a7, int $a8, int $a9): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -435,12 +436,6 @@ function hostFunc__env__getaddrinfo(Runtime $runtime): void
throw new \RuntimeException('env::getaddrinfo: not implemented');
}
-// Type: (i32, i32, i32, i32, i32, i32) -> (i32)
-function hostFunc__env__gethostbyname_r(Runtime $runtime): void
-{
- throw new \RuntimeException('env::gethostbyname_r: not implemented');
-}
-
// Type: () -> (i32)
function hostFunc__env__getdtablesize(Runtime $runtime): void
{
@@ -474,7 +469,7 @@ function hostFunc__env__getnameinfo(Runtime $runtime): void
// Type: (i32, i32, i32, i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viiiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4, int $a5, int $a6): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -488,7 +483,7 @@ function hostFunc__env__invoke_viiiiii(Runtime $runtime, int $index, int $a1, in
// Type: (i32, i32, i32, f64, i32, i32) -> ()
function hostFunc__env__invoke_viidii(Runtime $runtime, int $index, int $a1, int $a2, float $a3, int $a4, int $a5): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -631,7 +626,7 @@ function hostFunc__env____syscall_dup3(Runtime $runtime): void
}
// Type: (i32, i32, i32) -> ()
-function hostFunc__env__emscripten_memcpy_js(Runtime $runtime, int $dest, int $src, int $num): void
+function hostFunc__env___emscripten_memcpy_js(Runtime $runtime, int $dest, int $src, int $num): void
{
$mem = $runtime->getExportedMemory('memory');
\assert($mem !== null);
@@ -762,6 +757,12 @@ function hostFunc__env____syscall_poll(Runtime $runtime): void
throw new \RuntimeException('env::__syscall_poll: not implemented');
}
+// Type: () -> ()
+function hostFunc__env___emscripten_runtime_keepalive_clear(Runtime $runtime): void
+{
+ throw new \RuntimeException('env::_emscripten_runtime_keepalive_clear: not implemented');
+}
+
// Type: (i32, i32) -> ()
function hostFunc__env____call_sighandler(Runtime $runtime): void
{
@@ -870,6 +871,12 @@ function hostFunc__env____syscall_connect(Runtime $runtime): void
throw new \RuntimeException('env::__syscall_connect: not implemented');
}
+// Type: (i32) -> (i32)
+function hostFunc__env___emscripten_lookup_name(Runtime $runtime): void
+{
+ throw new \RuntimeException('env::_emscripten_lookup_name: not implemented');
+}
+
// Type: (i32, i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env____syscall_getpeername(Runtime $runtime): void
{
diff --git a/examples/rubyvm-on-php-on-wasm/php-wasm.php b/examples/rubyvm-on-php-on-wasm/php-wasm.php
index 723e210..e0c3a77 100644
--- a/examples/rubyvm-on-php-on-wasm/php-wasm.php
+++ b/examples/rubyvm-on-php-on-wasm/php-wasm.php
@@ -30,7 +30,7 @@ $imports = [
'invoke_iiiii' => makeHostFunc('(i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiiii(...)),
'invoke_v' => makeHostFunc('(i32) -> ()', hostFunc__env__invoke_v(...)),
'invoke_ii' => makeHostFunc('(i32, i32) -> (i32)', hostFunc__env__invoke_ii(...)),
- 'abort' => makeHostFunc('() -> ()', hostFunc__env__abort(...)),
+ '_abort_js' => makeHostFunc('() -> ()', hostFunc__env___abort_js(...)),
'exit' => makeHostFunc('(i32) -> ()', hostFunc__env__exit(...)),
'invoke_viii' => makeHostFunc('(i32, i32, i32, i32) -> ()', hostFunc__env__invoke_viii(...)),
'invoke_vii' => makeHostFunc('(i32, i32, i32) -> ()', hostFunc__env__invoke_vii(...)),
@@ -45,7 +45,6 @@ $imports = [
'invoke_iiiiiiiiii' => makeHostFunc('(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiiiiiiiii(...)),
'strftime' => makeHostFunc('(i32, i32, i32, i32) -> (i32)', hostFunc__env__strftime(...)),
'getaddrinfo' => makeHostFunc('(i32, i32, i32, i32) -> (i32)', hostFunc__env__getaddrinfo(...)),
- 'gethostbyname_r' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__gethostbyname_r(...)),
'getdtablesize' => makeHostFunc('() -> (i32)', hostFunc__env__getdtablesize(...)),
'getprotobyname' => makeHostFunc('(i32) -> (i32)', hostFunc__env__getprotobyname(...)),
'getprotobynumber' => makeHostFunc('(i32) -> (i32)', hostFunc__env__getprotobynumber(...)),
@@ -64,7 +63,7 @@ $imports = [
'__syscall_fchownat' => makeHostFunc('(i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_fchownat(...)),
'__syscall_dup' => makeHostFunc('(i32) -> (i32)', hostFunc__env____syscall_dup(...)),
'__syscall_dup3' => makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env____syscall_dup3(...)),
- 'emscripten_memcpy_js' => makeHostFunc('(i32, i32, i32) -> ()', hostFunc__env__emscripten_memcpy_js(...)),
+ '_emscripten_memcpy_js' => makeHostFunc('(i32, i32, i32) -> ()', hostFunc__env___emscripten_memcpy_js(...)),
'emscripten_date_now' => makeHostFunc('() -> (f64)', hostFunc__env__emscripten_date_now(...)),
'_emscripten_get_now_is_monotonic' => makeHostFunc('() -> (i32)', hostFunc__env___emscripten_get_now_is_monotonic(...)),
'emscripten_get_now' => makeHostFunc('() -> (f64)', hostFunc__env__emscripten_get_now(...)),
@@ -79,6 +78,7 @@ $imports = [
'__syscall_mkdirat' => makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env____syscall_mkdirat(...)),
'__syscall_pipe' => makeHostFunc('(i32) -> (i32)', hostFunc__env____syscall_pipe(...)),
'__syscall_poll' => makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env____syscall_poll(...)),
+ '_emscripten_runtime_keepalive_clear' => makeHostFunc('() -> ()', hostFunc__env___emscripten_runtime_keepalive_clear(...)),
'__call_sighandler' => makeHostFunc('(i32, i32) -> ()', hostFunc__env____call_sighandler(...)),
'__syscall_getdents64' => makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env____syscall_getdents64(...)),
'__syscall_readlinkat' => makeHostFunc('(i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_readlinkat(...)),
@@ -97,6 +97,7 @@ $imports = [
'__syscall_accept4' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_accept4(...)),
'__syscall_bind' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_bind(...)),
'__syscall_connect' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_connect(...)),
+ '_emscripten_lookup_name' => makeHostFunc('(i32) -> (i32)', hostFunc__env___emscripten_lookup_name(...)),
'__syscall_getpeername' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_getpeername(...)),
'__syscall_getsockname' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_getsockname(...)),
'__syscall_getsockopt' => makeHostFunc('(i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env____syscall_getsockopt(...)),
@@ -136,23 +137,23 @@ function allocateStringOnWasmMemory(Runtime $runtime, string $str): int
{
// Plus 1 for the null terminator in C.
$size = \strlen($str) + 1;
- $outPtr = wasm_stackAlloc($runtime, $size);
+ $outPtr = _emscripten_stack_alloc($runtime, $size);
copyStringToWasmMemory($runtime, $outPtr, $str);
return $outPtr;
}
-function wasm_stackAlloc(Runtime $runtime, int $size): int
+function _emscripten_stack_alloc(Runtime $runtime, int $size): int
{
- $results = $runtime->invoke("stackAlloc", [$size]);
+ $results = $runtime->invoke("_emscripten_stack_alloc", [$size]);
\assert(\count($results) === 1);
$result = $results[0];
\assert(\is_int($result));
return $result;
}
-function wasm_stackSave(Runtime $runtime): int
+function emscripten_stack_get_current(Runtime $runtime): int
{
- $results = $runtime->invoke("stackSave", []);
+ $results = $runtime->invoke("emscripten_stack_get_current", []);
\assert(\count($results) === 1);
$result = $results[0];
\assert(\is_int($result));
@@ -584,7 +585,7 @@ function fsMmap(Runtime $runtime, int $fd, int $len, int $offset, int $prot, int
// Type: (i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iii(Runtime $runtime, int $index, int $a1, int $a2): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -595,7 +596,7 @@ function hostFunc__env__invoke_iii(Runtime $runtime, int $index, int $a1, int $a
// Type: (i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -608,7 +609,7 @@ function hostFunc__env__invoke_iiiii(Runtime $runtime, int $index, int $a1, int
// Type: (i32) -> ()
function hostFunc__env__invoke_v(Runtime $runtime, int $index): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->invokeByFuncAddr($func);
}
@@ -616,7 +617,7 @@ function hostFunc__env__invoke_v(Runtime $runtime, int $index): void
// Type: (i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -628,7 +629,7 @@ function hostFunc__env__invoke_iiii(Runtime $runtime, int $index, int $a1, int $
// Type: (i32, i32) -> (i32)
function hostFunc__env__invoke_ii(Runtime $runtime, int $index, int $a1): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->invokeByFuncAddr($func);
@@ -636,9 +637,9 @@ function hostFunc__env__invoke_ii(Runtime $runtime, int $index, int $a1): int
}
// Type: () -> ()
-function hostFunc__env__abort(Runtime $runtime): void
+function hostFunc__env___abort_js(Runtime $runtime): void
{
- throw new \RuntimeException('env::abort: not implemented');
+ throw new \RuntimeException('env::_abort_js: not implemented');
}
// Type: (i32) -> ()
@@ -650,7 +651,7 @@ function hostFunc__env__exit(Runtime $runtime): void
// Type: (i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viii(Runtime $runtime, int $index, int $a1, int $a2, int $a3): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -661,7 +662,7 @@ function hostFunc__env__invoke_viii(Runtime $runtime, int $index, int $a1, int $
// Type: (i32, i32, i32) -> ()
function hostFunc__env__invoke_vii(Runtime $runtime, int $index, int $a1, int $a2): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -671,7 +672,7 @@ function hostFunc__env__invoke_vii(Runtime $runtime, int $index, int $a1, int $a
// Type: (i32, i32) -> ()
function hostFunc__env__invoke_vi(Runtime $runtime, int $index, int $a1): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->invokeByFuncAddr($func);
@@ -680,7 +681,7 @@ function hostFunc__env__invoke_vi(Runtime $runtime, int $index, int $a1): void
// Type: (i32) -> (i32)
function hostFunc__env__invoke_i(Runtime $runtime, int $index): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->invokeByFuncAddr($func);
return $runtime->stack->popInt();
@@ -689,7 +690,7 @@ function hostFunc__env__invoke_i(Runtime $runtime, int $index): int
// Type: (i32, i32, i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4, int $a5, int $a6): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -704,7 +705,7 @@ function hostFunc__env__invoke_iiiiiii(Runtime $runtime, int $index, int $a1, in
// Type: (i32, i32, i32, i32) -> ()
function hostFunc__env____assert_fail(Runtime $runtime, int $index, int $a1, int $a2, int $a3): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -715,7 +716,7 @@ function hostFunc__env____assert_fail(Runtime $runtime, int $index, int $a1, int
// Type: (i32, i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -727,7 +728,7 @@ function hostFunc__env__invoke_viiii(Runtime $runtime, int $index, int $a1, int
// Type: (i32, i32, i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4, int $a5): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -740,7 +741,7 @@ function hostFunc__env__invoke_viiiii(Runtime $runtime, int $index, int $a1, int
// Type: (i32, i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4, int $a5): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -754,7 +755,7 @@ function hostFunc__env__invoke_iiiiii(Runtime $runtime, int $index, int $a1, int
// Type: (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiiiiiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4, int $a5, int $a6, int $a7, int $a8, int $a9): int
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -781,12 +782,6 @@ function hostFunc__env__getaddrinfo(Runtime $runtime): void
throw new \RuntimeException('env::getaddrinfo: not implemented');
}
-// Type: (i32, i32, i32, i32, i32, i32) -> (i32)
-function hostFunc__env__gethostbyname_r(Runtime $runtime): void
-{
- throw new \RuntimeException('env::gethostbyname_r: not implemented');
-}
-
// Type: () -> (i32)
function hostFunc__env__getdtablesize(Runtime $runtime): void
{
@@ -820,7 +815,7 @@ function hostFunc__env__getnameinfo(Runtime $runtime): void
// Type: (i32, i32, i32, i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viiiiii(Runtime $runtime, int $index, int $a1, int $a2, int $a3, int $a4, int $a5, int $a6): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -834,7 +829,7 @@ function hostFunc__env__invoke_viiiiii(Runtime $runtime, int $index, int $a1, in
// Type: (i32, i32, i32, f64, i32, i32) -> ()
function hostFunc__env__invoke_viidii(Runtime $runtime, int $index, int $a1, int $a2, float $a3, int $a4, int $a5): void
{
- $sp = wasm_stackSave($runtime);
+ $sp = emscripten_stack_get_current($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->stack->pushValue($a1);
$runtime->stack->pushValue($a2);
@@ -1045,7 +1040,7 @@ function hostFunc__env____syscall_dup3(Runtime $runtime): void
}
// Type: (i32, i32, i32) -> ()
-function hostFunc__env__emscripten_memcpy_js(Runtime $runtime, int $dest, int $src, int $num): void
+function hostFunc__env___emscripten_memcpy_js(Runtime $runtime, int $dest, int $src, int $num): void
{
$mem = $runtime->getExportedMemory('memory');
\assert($mem !== null);
@@ -1188,6 +1183,12 @@ function hostFunc__env____syscall_poll(Runtime $runtime): void
throw new \RuntimeException('env::__syscall_poll: not implemented');
}
+// Type: () -> ()
+function hostFunc__env___emscripten_runtime_keepalive_clear(Runtime $runtime): void
+{
+ throw new \RuntimeException('env::_emscripten_runtime_keepalive_clear: not implemented');
+}
+
// Type: (i32, i32) -> ()
function hostFunc__env____call_sighandler(Runtime $runtime): void
{
@@ -1332,6 +1333,12 @@ function hostFunc__env____syscall_connect(Runtime $runtime): void
throw new \RuntimeException('env::__syscall_connect: not implemented');
}
+// Type: (i32) -> (i32)
+function hostFunc__env___emscripten_lookup_name(Runtime $runtime): void
+{
+ throw new \RuntimeException('env::_emscripten_lookup_name: not implemented');
+}
+
// Type: (i32, i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env____syscall_getpeername(Runtime $runtime): void
{