1996 lines
98 KiB
JavaScript
1996 lines
98 KiB
JavaScript
|
|
// xVS_beta.js (wasm attributes/methods)
|
|||
|
|
|
|||
|
|
// include: shell.js
|
|||
|
|
// include: minimum_runtime_check.js
|
|||
|
|
// end include: minimum_runtime_check.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(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).
|
|||
|
|
// Substitution will be replaced with actual code on later stage of the build,
|
|||
|
|
// this way Closure Compiler will not mangle it (e.g. case 4. above).
|
|||
|
|
// Note that if you want to run closure, and also to use Module
|
|||
|
|
// after the generated code, you will need to define var Module = {};
|
|||
|
|
// before the code. Then that object will be used in the code, and you
|
|||
|
|
// can continue to use Module afterwards as well.
|
|||
|
|
var Module = typeof Module != 'undefined' ? Module : {};
|
|||
|
|
|
|||
|
|
// Determine the runtime environment we are in. You can customize this by
|
|||
|
|
// setting the ENVIRONMENT setting at compile time (see settings.js).
|
|||
|
|
|
|||
|
|
// Attempt to auto-detect the environment
|
|||
|
|
var ENVIRONMENT_IS_WEB = !!globalThis.window;
|
|||
|
|
var ENVIRONMENT_IS_WORKER = !!globalThis.WorkerGlobalScope;
|
|||
|
|
// N.b. Electron.js environment is simultaneously a NODE-environment, but
|
|||
|
|
// also a web environment.
|
|||
|
|
var ENVIRONMENT_IS_NODE = globalThis.process?.versions?.node && globalThis.process?.type != 'renderer';
|
|||
|
|
var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
|
|||
|
|
|
|||
|
|
// --pre-jses are emitted after the Module integration code, so that they can
|
|||
|
|
// refer to Module (if they choose; they can also define Module)
|
|||
|
|
|
|||
|
|
|
|||
|
|
var arguments_ = [];
|
|||
|
|
var thisProgram = './this.program';
|
|||
|
|
var quit_ = (status, toThrow) => {
|
|||
|
|
throw toThrow;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// In MODULARIZE mode _scriptName needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there
|
|||
|
|
// before the page load. In non-MODULARIZE modes generate it here.
|
|||
|
|
var _scriptName = globalThis.document?.currentScript?.src;
|
|||
|
|
|
|||
|
|
if (typeof __filename != 'undefined') { // Node
|
|||
|
|
_scriptName = __filename;
|
|||
|
|
} else
|
|||
|
|
if (ENVIRONMENT_IS_WORKER) {
|
|||
|
|
_scriptName = self.location.href;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// `/` should be present at the end if `scriptDirectory` is not empty
|
|||
|
|
var scriptDirectory = '';
|
|||
|
|
function locateFile(path) {
|
|||
|
|
if (Module['locateFile']) {
|
|||
|
|
return Module['locateFile'](path, scriptDirectory);
|
|||
|
|
}
|
|||
|
|
return scriptDirectory + path;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Hooks that are implemented differently in different runtime environments.
|
|||
|
|
var readAsync, readBinary;
|
|||
|
|
|
|||
|
|
if (ENVIRONMENT_IS_NODE) {
|
|||
|
|
|
|||
|
|
// These modules will usually be used on Node.js. Load them eagerly to avoid
|
|||
|
|
// the complexity of lazy-loading.
|
|||
|
|
var fs = require('node:fs');
|
|||
|
|
|
|||
|
|
scriptDirectory = __dirname + '/';
|
|||
|
|
|
|||
|
|
// include: node_shell_read.js
|
|||
|
|
readBinary = (filename) => {
|
|||
|
|
// We need to re-wrap `file://` strings to URLs.
|
|||
|
|
filename = isFileURI(filename) ? new URL(filename) : filename;
|
|||
|
|
var ret = fs.readFileSync(filename);
|
|||
|
|
return ret;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
readAsync = async (filename, binary = true) => {
|
|||
|
|
// See the comment in the `readBinary` function.
|
|||
|
|
filename = isFileURI(filename) ? new URL(filename) : filename;
|
|||
|
|
var ret = fs.readFileSync(filename, binary ? undefined : 'utf8');
|
|||
|
|
return ret;
|
|||
|
|
};
|
|||
|
|
// end include: node_shell_read.js
|
|||
|
|
if (process.argv.length > 1) {
|
|||
|
|
thisProgram = process.argv[1].replace(/\\/g, '/');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
arguments_ = process.argv.slice(2);
|
|||
|
|
|
|||
|
|
// MODULARIZE will export the module in the proper place outside, we don't need to export here
|
|||
|
|
if (typeof module != 'undefined') {
|
|||
|
|
module['exports'] = Module;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
quit_ = (status, toThrow) => {
|
|||
|
|
process.exitCode = status;
|
|||
|
|
throw toThrow;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
} else
|
|||
|
|
|
|||
|
|
// Note that this includes Node.js workers when relevant (pthreads is enabled).
|
|||
|
|
// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
|
|||
|
|
// ENVIRONMENT_IS_NODE.
|
|||
|
|
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
|
|||
|
|
try {
|
|||
|
|
scriptDirectory = new URL('.', _scriptName).href; // includes trailing slash
|
|||
|
|
} catch {
|
|||
|
|
// Must be a `blob:` or `data:` URL (e.g. `blob:http://site.com/etc/etc`), we cannot
|
|||
|
|
// infer anything from them.
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
// include: web_or_worker_shell_read.js
|
|||
|
|
if (ENVIRONMENT_IS_WORKER) {
|
|||
|
|
readBinary = (url) => {
|
|||
|
|
var xhr = new XMLHttpRequest();
|
|||
|
|
xhr.open('GET', url, false);
|
|||
|
|
xhr.responseType = 'arraybuffer';
|
|||
|
|
xhr.send(null);
|
|||
|
|
return new Uint8Array(/** @type{!ArrayBuffer} */(xhr.response));
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
readAsync = async (url) => {
|
|||
|
|
// 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 XHR on webview if URL is a file URL.
|
|||
|
|
if (isFileURI(url)) {
|
|||
|
|
return new Promise((resolve, reject) => {
|
|||
|
|
var xhr = new XMLHttpRequest();
|
|||
|
|
xhr.open('GET', url, true);
|
|||
|
|
xhr.responseType = 'arraybuffer';
|
|||
|
|
xhr.onload = () => {
|
|||
|
|
if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
|
|||
|
|
resolve(xhr.response);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
reject(xhr.status);
|
|||
|
|
};
|
|||
|
|
xhr.onerror = reject;
|
|||
|
|
xhr.send(null);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
var response = await fetch(url, { credentials: 'same-origin' });
|
|||
|
|
if (response.ok) {
|
|||
|
|
return response.arrayBuffer();
|
|||
|
|
}
|
|||
|
|
throw new Error(response.status + ' : ' + response.url);
|
|||
|
|
};
|
|||
|
|
// end include: web_or_worker_shell_read.js
|
|||
|
|
}
|
|||
|
|
} else
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var out = console.log.bind(console);
|
|||
|
|
var err = console.error.bind(console);
|
|||
|
|
|
|||
|
|
// end include: shell.js
|
|||
|
|
|
|||
|
|
// include: preamble.js
|
|||
|
|
// === Preamble library stuff ===
|
|||
|
|
|
|||
|
|
// Documentation for the public APIs defined in this file must be updated in:
|
|||
|
|
// site/source/docs/api_reference/preamble.js.rst
|
|||
|
|
// A prebuilt local version of the documentation is available at:
|
|||
|
|
// site/build/text/docs/api_reference/preamble.js.txt
|
|||
|
|
// You can also build docs locally as HTML or other formats in site/
|
|||
|
|
// 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;
|
|||
|
|
|
|||
|
|
// Wasm globals
|
|||
|
|
|
|||
|
|
//========================================
|
|||
|
|
// Runtime essentials
|
|||
|
|
//========================================
|
|||
|
|
|
|||
|
|
// whether we are quitting the application. no code should run after this.
|
|||
|
|
// set in exit() and abort()
|
|||
|
|
var ABORT = false;
|
|||
|
|
|
|||
|
|
// set by exit() and abort(). Passed to 'onExit' handler.
|
|||
|
|
// NOTE: This is also used as the process return code in shell environments
|
|||
|
|
// 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) {
|
|||
|
|
// This build was created without ASSERTIONS defined. `assert()` should not
|
|||
|
|
// ever be called in this configuration but in case there are callers in
|
|||
|
|
// the wild leave this simple abort() implementation here for now.
|
|||
|
|
abort(text);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Indicates whether filename is delivered via file protocol (as opposed to http/https)
|
|||
|
|
* @noinline
|
|||
|
|
*/
|
|||
|
|
var isFileURI = (filename) => filename.startsWith('file://');
|
|||
|
|
|
|||
|
|
// include: runtime_common.js
|
|||
|
|
// include: runtime_stack_check.js
|
|||
|
|
// end include: runtime_stack_check.js
|
|||
|
|
// include: runtime_exceptions.js
|
|||
|
|
// end include: runtime_exceptions.js
|
|||
|
|
// include: runtime_debug.js
|
|||
|
|
// end include: runtime_debug.js
|
|||
|
|
// include: binaryDecode.js
|
|||
|
|
// Prevent Closure from minifying the binaryDecode() function, or otherwise
|
|||
|
|
// Closure may analyze through the WASM_BINARY_DATA placeholder string into this
|
|||
|
|
// function, leading into incorrect results.
|
|||
|
|
/** @noinline */
|
|||
|
|
function binaryDecode(bin) {
|
|||
|
|
for (var i = 0, l = bin.length, o = new Uint8Array(l), c; i < l; ++i) {
|
|||
|
|
c = bin.charCodeAt(i);
|
|||
|
|
o[i] = ~c >> 8 & c; // Recover the null byte in a manner that is compatible with https://crbug.com/453961758
|
|||
|
|
}
|
|||
|
|
return o;
|
|||
|
|
}
|
|||
|
|
// end include: binaryDecode.js
|
|||
|
|
// Memory management
|
|||
|
|
var
|
|||
|
|
/** @type {!Int8Array} */
|
|||
|
|
HEAP8,
|
|||
|
|
/** @type {!Uint8Array} */
|
|||
|
|
HEAPU8,
|
|||
|
|
/** @type {!Int16Array} */
|
|||
|
|
HEAP16,
|
|||
|
|
/** @type {!Uint16Array} */
|
|||
|
|
HEAPU16,
|
|||
|
|
/** @type {!Int32Array} */
|
|||
|
|
HEAP32,
|
|||
|
|
/** @type {!Uint32Array} */
|
|||
|
|
HEAPU32,
|
|||
|
|
/** @type {!Float32Array} */
|
|||
|
|
HEAPF32,
|
|||
|
|
/** @type {!Float64Array} */
|
|||
|
|
HEAPF64;
|
|||
|
|
|
|||
|
|
// BigInt64Array type is not correctly defined in closure
|
|||
|
|
var
|
|||
|
|
/** not-@type {!BigInt64Array} */
|
|||
|
|
HEAP64,
|
|||
|
|
/* BigUint64Array type is not correctly defined in closure
|
|||
|
|
/** not-@type {!BigUint64Array} */
|
|||
|
|
HEAPU64;
|
|||
|
|
|
|||
|
|
var runtimeInitialized = false;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
function updateMemoryViews() {
|
|||
|
|
var b = wasmMemory.buffer;
|
|||
|
|
HEAP8 = new Int8Array(b);
|
|||
|
|
HEAP16 = new Int16Array(b);
|
|||
|
|
HEAPU8 = new Uint8Array(b);
|
|||
|
|
HEAPU16 = new Uint16Array(b);
|
|||
|
|
HEAP32 = new Int32Array(b);
|
|||
|
|
HEAPU32 = new Uint32Array(b);
|
|||
|
|
HEAPF32 = new Float32Array(b);
|
|||
|
|
HEAPF64 = new Float64Array(b);
|
|||
|
|
HEAP64 = new BigInt64Array(b);
|
|||
|
|
HEAPU64 = new BigUint64Array(b);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// include: memoryprofiler.js
|
|||
|
|
// end include: memoryprofiler.js
|
|||
|
|
// end include: runtime_common.js
|
|||
|
|
function preRun() {
|
|||
|
|
if (Module['preRun']) {
|
|||
|
|
if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
|
|||
|
|
while (Module['preRun'].length) {
|
|||
|
|
addOnPreRun(Module['preRun'].shift());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// Begin ATPRERUNS hooks
|
|||
|
|
callRuntimeCallbacks(onPreRuns);
|
|||
|
|
// End ATPRERUNS hooks
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function initRuntime() {
|
|||
|
|
runtimeInitialized = true;
|
|||
|
|
|
|||
|
|
// No ATINITS hooks
|
|||
|
|
|
|||
|
|
wasmExports['__wasm_call_ctors']();
|
|||
|
|
|
|||
|
|
// No ATPOSTCTORS hooks
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function postRun() {
|
|||
|
|
// PThreads reuse the runtime from the main thread.
|
|||
|
|
|
|||
|
|
if (Module['postRun']) {
|
|||
|
|
if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
|
|||
|
|
while (Module['postRun'].length) {
|
|||
|
|
addOnPostRun(Module['postRun'].shift());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Begin ATPOSTRUNS hooks
|
|||
|
|
callRuntimeCallbacks(onPostRuns);
|
|||
|
|
// End ATPOSTRUNS hooks
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** @param {string|number=} what */
|
|||
|
|
function abort(what) {
|
|||
|
|
Module['onAbort']?.(what);
|
|||
|
|
|
|||
|
|
what = 'Aborted(' + what + ')';
|
|||
|
|
// TODO(sbc): Should we remove printing and leave it up to whoever
|
|||
|
|
// catches the exception?
|
|||
|
|
err(what);
|
|||
|
|
|
|||
|
|
ABORT = true;
|
|||
|
|
|
|||
|
|
what += '. Build with -sASSERTIONS for more info.';
|
|||
|
|
|
|||
|
|
// Use a wasm runtime error, because a JS error might be seen as a foreign
|
|||
|
|
// exception, which means we'd run destructors on it. We need the error to
|
|||
|
|
// simply make the program stop.
|
|||
|
|
// FIXME This approach does not work in Wasm EH because it currently does not assume
|
|||
|
|
// all RuntimeErrors are from traps; it decides whether a RuntimeError is from
|
|||
|
|
// a trap or not based on a hidden field within the object. So at the moment
|
|||
|
|
// we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that
|
|||
|
|
// allows this in the wasm spec.
|
|||
|
|
|
|||
|
|
// Suppress closure compiler warning here. Closure compiler's builtin extern
|
|||
|
|
// 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} */
|
|||
|
|
var e = new WebAssembly.RuntimeError(what);
|
|||
|
|
|
|||
|
|
// Throw the error whether or not MODULARIZE is set because abort is used
|
|||
|
|
// in code paths apart from instantiation where an exception is expected
|
|||
|
|
// to be thrown when abort is called.
|
|||
|
|
throw e;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var wasmBinaryFile;
|
|||
|
|
|
|||
|
|
function findWasmBinary() {
|
|||
|
|
return binaryDecode(' |