mirror of
https://github.com/penpot/penpot.git
synced 2026-05-10 02:28:16 +00:00
5947 lines
234 KiB
JavaScript
5947 lines
234 KiB
JavaScript
|
|
var Module = (() => {
|
|
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
|
|
|
|
return (
|
|
function(Module) {
|
|
Module = Module || {};
|
|
|
|
|
|
|
|
// 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.. }
|
|
// 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 : {};
|
|
|
|
// See https://caniuse.com/mdn-javascript_builtins_object_assign
|
|
|
|
// See https://caniuse.com/mdn-javascript_builtins_bigint64array
|
|
|
|
// Set up the promise that indicates the Module is initialized
|
|
var readyPromiseResolve, readyPromiseReject;
|
|
Module['ready'] = new Promise(function(resolve, reject) {
|
|
readyPromiseResolve = resolve;
|
|
readyPromiseReject = reject;
|
|
});
|
|
|
|
if (!Object.getOwnPropertyDescriptor(Module['ready'], '_add')) {
|
|
Object.defineProperty(Module['ready'], '_add', { configurable: true, get: function() { abort('You are getting _add 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') } });
|
|
Object.defineProperty(Module['ready'], '_add', { configurable: true, set: function() { abort('You are setting _add 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') } });
|
|
}
|
|
|
|
|
|
if (!Object.getOwnPropertyDescriptor(Module['ready'], '_fflush')) {
|
|
Object.defineProperty(Module['ready'], '_fflush', { configurable: true, get: function() { abort('You are getting _fflush 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') } });
|
|
Object.defineProperty(Module['ready'], '_fflush', { configurable: true, set: function() { abort('You are setting _fflush 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') } });
|
|
}
|
|
|
|
|
|
if (!Object.getOwnPropertyDescriptor(Module['ready'], '___getTypeName')) {
|
|
Object.defineProperty(Module['ready'], '___getTypeName', { configurable: true, get: function() { abort('You are getting ___getTypeName 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') } });
|
|
Object.defineProperty(Module['ready'], '___getTypeName', { configurable: true, set: function() { abort('You are setting ___getTypeName 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') } });
|
|
}
|
|
|
|
|
|
if (!Object.getOwnPropertyDescriptor(Module['ready'], '___embind_register_native_and_builtin_types')) {
|
|
Object.defineProperty(Module['ready'], '___embind_register_native_and_builtin_types', { configurable: true, get: function() { abort('You are getting ___embind_register_native_and_builtin_types 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') } });
|
|
Object.defineProperty(Module['ready'], '___embind_register_native_and_builtin_types', { configurable: true, set: function() { abort('You are setting ___embind_register_native_and_builtin_types 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') } });
|
|
}
|
|
|
|
|
|
if (!Object.getOwnPropertyDescriptor(Module['ready'], 'onRuntimeInitialized')) {
|
|
Object.defineProperty(Module['ready'], 'onRuntimeInitialized', { configurable: true, get: function() { abort('You are getting onRuntimeInitialized 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') } });
|
|
Object.defineProperty(Module['ready'], 'onRuntimeInitialized', { configurable: true, set: function() { abort('You are setting onRuntimeInitialized 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') } });
|
|
}
|
|
|
|
|
|
// --pre-jses are emitted after the Module integration code, so that they can
|
|
// refer to Module (if they choose; they can also define Module)
|
|
// Adds compile-time JS functions to augment Renderer interface.
|
|
(function (Renderer) {
|
|
console.log("preamble", Renderer);
|
|
Renderer.setCanvas = function setCanvas(canvas, attrs) {
|
|
console.log("GL", GL);
|
|
debugger
|
|
const context = GL.createContext(canvas, attrs);
|
|
if (!context) {
|
|
throw new Error('Could not create a new WebGL context')
|
|
}
|
|
console.log("setCanvas", canvas, attrs);
|
|
const gr = this._MakeGrContext();
|
|
console.log("gr", gr);
|
|
};
|
|
|
|
console.log("postamble");
|
|
}(Module));
|
|
|
|
|
|
// Sometimes an existing Module object exists with properties
|
|
// meant to overwrite the default module functionality. Here
|
|
// we collect those properties and reapply _after_ we configure
|
|
// the current environment's defaults to avoid having to be so
|
|
// defensive during initialization.
|
|
var moduleOverrides = Object.assign({}, Module);
|
|
|
|
var arguments_ = [];
|
|
var thisProgram = './this.program';
|
|
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 = true;
|
|
var ENVIRONMENT_IS_WORKER = false;
|
|
var ENVIRONMENT_IS_NODE = false;
|
|
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) {
|
|
if (Module['locateFile']) {
|
|
return Module['locateFile'](path, scriptDirectory);
|
|
}
|
|
return scriptDirectory + path;
|
|
}
|
|
|
|
// Hooks that are implemented differently in different runtime environments.
|
|
var read_,
|
|
readAsync,
|
|
readBinary,
|
|
setWindowTitle;
|
|
|
|
// Normally we don't log exceptions but instead let them bubble out the top
|
|
// level where the embedding environment (e.g. the browser) can handle
|
|
// them.
|
|
// However under v8 and node we sometimes exit the process direcly in which case
|
|
// its up to use us to log the exception before exiting.
|
|
// If we fix https://github.com/emscripten-core/emscripten/issues/15080
|
|
// this may no longer be needed under node.
|
|
function logExceptionOnExit(e) {
|
|
if (e instanceof ExitStatus) return;
|
|
let toLog = e;
|
|
if (e && typeof e == 'object' && e.stack) {
|
|
toLog = [e, e.stack];
|
|
}
|
|
err('exiting due to exception: ' + toLog);
|
|
}
|
|
|
|
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_ = function shell_read(f) {
|
|
return read(f);
|
|
};
|
|
}
|
|
|
|
readBinary = function readBinary(f) {
|
|
let data;
|
|
if (typeof readbuffer == 'function') {
|
|
return new Uint8Array(readbuffer(f));
|
|
}
|
|
data = read(f, 'binary');
|
|
assert(typeof data == 'object');
|
|
return data;
|
|
};
|
|
|
|
readAsync = function readAsync(f, onload, onerror) {
|
|
setTimeout(() => onload(readBinary(f)), 0);
|
|
};
|
|
|
|
if (typeof scriptArgs != 'undefined') {
|
|
arguments_ = scriptArgs;
|
|
} else if (typeof arguments != 'undefined') {
|
|
arguments_ = arguments;
|
|
}
|
|
|
|
if (typeof quit == 'function') {
|
|
quit_ = (status, toThrow) => {
|
|
logExceptionOnExit(toThrow);
|
|
quit(status);
|
|
};
|
|
}
|
|
|
|
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).
|
|
// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
|
|
// ENVIRONMENT_IS_NODE.
|
|
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
|
|
if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
|
|
scriptDirectory = self.location.href;
|
|
} else if (typeof document != 'undefined' && document.currentScript) { // web
|
|
scriptDirectory = document.currentScript.src;
|
|
}
|
|
// When MODULARIZE, this JS may be executed later, after document.currentScript
|
|
// is gone, so we saved it, and we use it here instead of any other info.
|
|
if (_scriptDir) {
|
|
scriptDirectory = _scriptDir;
|
|
}
|
|
// blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
|
|
// otherwise, slice off the final part of the url to find the script directory.
|
|
// if scriptDirectory does not contain a slash, lastIndexOf will return -1,
|
|
// and scriptDirectory will correctly be replaced with an empty string.
|
|
// If scriptDirectory contains a query (starting with ?) or a fragment (starting with #),
|
|
// they are removed because they could contain a slash.
|
|
if (scriptDirectory.indexOf('blob:') !== 0) {
|
|
scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf('/')+1);
|
|
} else {
|
|
scriptDirectory = '';
|
|
}
|
|
|
|
scriptDirectory += 'renderer/cpp/';
|
|
|
|
if (!(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?)');
|
|
|
|
// Differentiate the Web Worker from the Node Worker case, as reading must
|
|
// be done differently.
|
|
{
|
|
// include: web_or_worker_shell_read.js
|
|
|
|
|
|
read_ = (url) => {
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open('GET', url, false);
|
|
xhr.send(null);
|
|
return xhr.responseText;
|
|
}
|
|
|
|
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 = (url, onload, onerror) => {
|
|
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
|
|
onload(xhr.response);
|
|
return;
|
|
}
|
|
onerror();
|
|
};
|
|
xhr.onerror = onerror;
|
|
xhr.send(null);
|
|
}
|
|
|
|
// end include: web_or_worker_shell_read.js
|
|
}
|
|
|
|
setWindowTitle = (title) => document.title = title;
|
|
} else
|
|
{
|
|
throw new Error('environment detection error');
|
|
}
|
|
|
|
var out = Module['print'] || console.log.bind(console);
|
|
var err = Module['printErr'] || console.warn.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.
|
|
moduleOverrides = null;
|
|
checkIncomingModuleAPI();
|
|
|
|
// Emit code to handle expected values on the Module object. This applies Module.x
|
|
// to the proper local x. This has two benefits: first, we only emit it if it is
|
|
// expected to arrive, and second, by using a local everywhere else that can be
|
|
// minified.
|
|
|
|
if (Module['arguments']) arguments_ = Module['arguments'];legacyModuleProp('arguments', 'arguments_');
|
|
|
|
if (Module['thisProgram']) thisProgram = Module['thisProgram'];legacyModuleProp('thisProgram', 'thisProgram');
|
|
|
|
if (Module['quit']) quit_ = Module['quit'];legacyModuleProp('quit', 'quit_');
|
|
|
|
// perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
|
|
// Assertions on removed incoming Module JS APIs.
|
|
assert(typeof Module['memoryInitializerPrefixURL'] == 'undefined', 'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead');
|
|
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['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 setWindowTitle in JS)');
|
|
assert(typeof Module['TOTAL_MEMORY'] == 'undefined', 'Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY');
|
|
legacyModuleProp('read', 'read_');
|
|
legacyModuleProp('readAsync', 'readAsync');
|
|
legacyModuleProp('readBinary', 'readBinary');
|
|
legacyModuleProp('setWindowTitle', 'setWindowTitle');
|
|
var IDBFS = 'IDBFS is no longer included by default; build with -lidbfs.js';
|
|
var PROXYFS = 'PROXYFS is no longer included by default; build with -lproxyfs.js';
|
|
var WORKERFS = 'WORKERFS is no longer included by default; build with -lworkerfs.js';
|
|
var NODEFS = 'NODEFS is no longer included by default; build with -lnodefs.js';
|
|
function alignMemory() { abort('`alignMemory` is now a library function and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line'); }
|
|
|
|
assert(!ENVIRONMENT_IS_WORKER, "worker environment detected but not enabled at build time. Add 'worker' to `-sENVIRONMENT` to enable.");
|
|
|
|
assert(!ENVIRONMENT_IS_NODE, "node environment detected but not enabled at build time. Add 'node' to `-sENVIRONMENT` to enable.");
|
|
|
|
assert(!ENVIRONMENT_IS_SHELL, "shell environment detected but not enabled at build time. Add 'shell' to `-sENVIRONMENT` to enable.");
|
|
|
|
|
|
|
|
|
|
var STACK_ALIGN = 16;
|
|
var POINTER_SIZE = 4;
|
|
|
|
function getNativeTypeSize(type) {
|
|
switch (type) {
|
|
case 'i1': case 'i8': case 'u8': return 1;
|
|
case 'i16': case 'u16': return 2;
|
|
case 'i32': case 'u32': return 4;
|
|
case 'i64': case 'u64': return 8;
|
|
case 'float': return 4;
|
|
case 'double': return 8;
|
|
default: {
|
|
if (type[type.length - 1] === '*') {
|
|
return POINTER_SIZE;
|
|
} else if (type[0] === 'i') {
|
|
const bits = Number(type.substr(1));
|
|
assert(bits % 8 === 0, 'getNativeTypeSize invalid bits ' + bits + ', type ' + type);
|
|
return bits / 8;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function warnOnce(text) {
|
|
if (!warnOnce.shown) warnOnce.shown = {};
|
|
if (!warnOnce.shown[text]) {
|
|
warnOnce.shown[text] = 1;
|
|
err(text);
|
|
}
|
|
}
|
|
|
|
// include: runtime_functions.js
|
|
|
|
|
|
// This gives correct answers for everything less than 2^{14} = 16384
|
|
// I hope nobody is contemplating functions with 16384 arguments...
|
|
function uleb128Encode(n) {
|
|
assert(n < 16384);
|
|
if (n < 128) {
|
|
return [n];
|
|
}
|
|
return [(n % 128) | 128, n >> 7];
|
|
}
|
|
|
|
// Converts a signature like 'vii' into a description of the wasm types, like
|
|
// { parameters: ['i32', 'i32'], results: [] }.
|
|
function sigToWasmTypes(sig) {
|
|
var typeNames = {
|
|
'i': 'i32',
|
|
'j': 'i64',
|
|
'f': 'f32',
|
|
'd': 'f64',
|
|
'p': 'i32',
|
|
};
|
|
var type = {
|
|
parameters: [],
|
|
results: sig[0] == 'v' ? [] : [typeNames[sig[0]]]
|
|
};
|
|
for (var i = 1; i < sig.length; ++i) {
|
|
assert(sig[i] in typeNames, 'invalid signature char: ' + sig[i]);
|
|
type.parameters.push(typeNames[sig[i]]);
|
|
}
|
|
return type;
|
|
}
|
|
|
|
// Wraps a JS function as a wasm function with a given signature.
|
|
function convertJsFunctionToWasm(func, sig) {
|
|
|
|
// If the type reflection proposal is available, use the new
|
|
// "WebAssembly.Function" constructor.
|
|
// Otherwise, construct a minimal wasm module importing the JS function and
|
|
// re-exporting it.
|
|
if (typeof WebAssembly.Function == "function") {
|
|
return new WebAssembly.Function(sigToWasmTypes(sig), func);
|
|
}
|
|
|
|
// The module is static, with the exception of the type section, which is
|
|
// generated based on the signature passed in.
|
|
var typeSection = [
|
|
0x01, // count: 1
|
|
0x60, // form: func
|
|
];
|
|
var sigRet = sig.slice(0, 1);
|
|
var sigParam = sig.slice(1);
|
|
var typeCodes = {
|
|
'i': 0x7f, // i32
|
|
'p': 0x7f, // i32
|
|
'j': 0x7e, // i64
|
|
'f': 0x7d, // f32
|
|
'd': 0x7c, // f64
|
|
};
|
|
|
|
// Parameters, length + signatures
|
|
typeSection = typeSection.concat(uleb128Encode(sigParam.length));
|
|
for (var i = 0; i < sigParam.length; ++i) {
|
|
assert(sigParam[i] in typeCodes, 'invalid signature char: ' + sigParam[i]);
|
|
typeSection.push(typeCodes[sigParam[i]]);
|
|
}
|
|
|
|
// Return values, length + signatures
|
|
// With no multi-return in MVP, either 0 (void) or 1 (anything else)
|
|
if (sigRet == 'v') {
|
|
typeSection.push(0x00);
|
|
} else {
|
|
typeSection = typeSection.concat([0x01, typeCodes[sigRet]]);
|
|
}
|
|
|
|
// Write the section code and overall length of the type section into the
|
|
// section header
|
|
typeSection = [0x01 /* Type section code */].concat(
|
|
uleb128Encode(typeSection.length),
|
|
typeSection
|
|
);
|
|
|
|
// Rest of the module is static
|
|
var bytes = new Uint8Array([
|
|
0x00, 0x61, 0x73, 0x6d, // magic ("\0asm")
|
|
0x01, 0x00, 0x00, 0x00, // version: 1
|
|
].concat(typeSection, [
|
|
0x02, 0x07, // import section
|
|
// (import "e" "f" (func 0 (type 0)))
|
|
0x01, 0x01, 0x65, 0x01, 0x66, 0x00, 0x00,
|
|
0x07, 0x05, // export section
|
|
// (export "f" (func 0 (type 0)))
|
|
0x01, 0x01, 0x66, 0x00, 0x00,
|
|
]));
|
|
|
|
// We can compile this wasm module synchronously because it is very small.
|
|
// This accepts an import (at "e.f"), that it reroutes to an export (at "f")
|
|
var module = new WebAssembly.Module(bytes);
|
|
var instance = new WebAssembly.Instance(module, {
|
|
'e': {
|
|
'f': func
|
|
}
|
|
});
|
|
var wrappedFunc = instance.exports['f'];
|
|
return wrappedFunc;
|
|
}
|
|
|
|
var freeTableIndexes = [];
|
|
|
|
// Weak map of functions in the table to their indexes, created on first use.
|
|
var functionsInTableMap;
|
|
|
|
function getEmptyTableSlot() {
|
|
// Reuse a free index if there is one, otherwise grow.
|
|
if (freeTableIndexes.length) {
|
|
return freeTableIndexes.pop();
|
|
}
|
|
// Grow the table
|
|
try {
|
|
wasmTable.grow(1);
|
|
} catch (err) {
|
|
if (!(err instanceof RangeError)) {
|
|
throw err;
|
|
}
|
|
throw 'Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.';
|
|
}
|
|
return wasmTable.length - 1;
|
|
}
|
|
|
|
function updateTableMap(offset, count) {
|
|
for (var i = offset; i < offset + count; i++) {
|
|
var item = getWasmTableEntry(i);
|
|
// Ignore null values.
|
|
if (item) {
|
|
functionsInTableMap.set(item, i);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add a function to the table.
|
|
* 'sig' parameter is required if the function being added is a JS function.
|
|
* @param {string=} sig
|
|
*/
|
|
function addFunction(func, sig) {
|
|
assert(typeof func != 'undefined');
|
|
|
|
// Check if the function is already in the table, to ensure each function
|
|
// gets a unique index. First, create the map if this is the first use.
|
|
if (!functionsInTableMap) {
|
|
functionsInTableMap = new WeakMap();
|
|
updateTableMap(0, wasmTable.length);
|
|
}
|
|
if (functionsInTableMap.has(func)) {
|
|
return functionsInTableMap.get(func);
|
|
}
|
|
|
|
// It's not in the table, add it now.
|
|
|
|
var ret = getEmptyTableSlot();
|
|
|
|
// Set the new value.
|
|
try {
|
|
// Attempting to call this with JS function will cause of table.set() to fail
|
|
setWasmTableEntry(ret, func);
|
|
} catch (err) {
|
|
if (!(err instanceof TypeError)) {
|
|
throw err;
|
|
}
|
|
assert(typeof sig != 'undefined', 'Missing signature argument to addFunction: ' + func);
|
|
var wrapped = convertJsFunctionToWasm(func, sig);
|
|
setWasmTableEntry(ret, wrapped);
|
|
}
|
|
|
|
functionsInTableMap.set(func, ret);
|
|
|
|
return ret;
|
|
}
|
|
|
|
function removeFunction(index) {
|
|
functionsInTableMap.delete(getWasmTableEntry(index));
|
|
freeTableIndexes.push(index);
|
|
}
|
|
|
|
// end include: runtime_functions.js
|
|
// include: runtime_debug.js
|
|
|
|
|
|
function legacyModuleProp(prop, newName) {
|
|
if (!Object.getOwnPropertyDescriptor(Module, prop)) {
|
|
Object.defineProperty(Module, prop, {
|
|
configurable: true,
|
|
get: function() {
|
|
abort('Module.' + prop + ' has been replaced with plain ' + newName + ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function ignoredModuleProp(prop) {
|
|
if (Object.getOwnPropertyDescriptor(Module, prop)) {
|
|
abort('`Module.' + prop + '` was supplied but `' + prop + '` not included in INCOMING_MODULE_JS_API');
|
|
}
|
|
}
|
|
|
|
function unexportedMessage(sym, isFSSybol) {
|
|
var msg = "'" + sym + "' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the FAQ)";
|
|
if (isFSSybol) {
|
|
msg += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you';
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
function unexportedRuntimeSymbol(sym, isFSSybol) {
|
|
if (!Object.getOwnPropertyDescriptor(Module, sym)) {
|
|
Object.defineProperty(Module, sym, {
|
|
configurable: true,
|
|
get: function() {
|
|
abort(unexportedMessage(sym, isFSSybol));
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function unexportedRuntimeFunction(sym, isFSSybol) {
|
|
if (!Object.getOwnPropertyDescriptor(Module, sym)) {
|
|
Module[sym] = () => abort(unexportedMessage(sym, isFSSybol));
|
|
}
|
|
}
|
|
|
|
// end include: runtime_debug.js
|
|
var tempRet0 = 0;
|
|
var setTempRet0 = (value) => { tempRet0 = value; };
|
|
var getTempRet0 = () => tempRet0;
|
|
|
|
|
|
|
|
// === 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;
|
|
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');
|
|
}
|
|
|
|
// Wasm globals
|
|
|
|
var wasmMemory;
|
|
|
|
//========================================
|
|
// 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 code in shell environments
|
|
// but only when noExitRuntime is false.
|
|
var EXITSTATUS;
|
|
|
|
/** @type {function(*, string=)} */
|
|
function assert(condition, text) {
|
|
if (!condition) {
|
|
abort('Assertion failed' + (text ? ': ' + text : ''));
|
|
}
|
|
}
|
|
|
|
// Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
|
|
function getCFunc(ident) {
|
|
var func = Module['_' + ident]; // closure exported function
|
|
assert(func, 'Cannot call unknown function ' + ident + ', make sure it is exported');
|
|
return func;
|
|
}
|
|
|
|
// C calling interface.
|
|
/** @param {string|null=} returnType
|
|
@param {Array=} argTypes
|
|
@param {Arguments|Array=} args
|
|
@param {Object=} opts */
|
|
function ccall(ident, returnType, argTypes, args, opts) {
|
|
// For fast lookup of conversion functions
|
|
var toC = {
|
|
'string': function(str) {
|
|
var ret = 0;
|
|
if (str !== null && str !== undefined && str !== 0) { // null string
|
|
// at most 4 bytes per UTF-8 code point, +1 for the trailing '\0'
|
|
var len = (str.length << 2) + 1;
|
|
ret = stackAlloc(len);
|
|
stringToUTF8(str, ret, len);
|
|
}
|
|
return ret;
|
|
},
|
|
'array': function(arr) {
|
|
var ret = stackAlloc(arr.length);
|
|
writeArrayToMemory(arr, ret);
|
|
return ret;
|
|
}
|
|
};
|
|
|
|
function convertReturnValue(ret) {
|
|
if (returnType === 'string') {
|
|
|
|
return UTF8ToString(ret);
|
|
}
|
|
if (returnType === 'boolean') return Boolean(ret);
|
|
return ret;
|
|
}
|
|
|
|
var func = getCFunc(ident);
|
|
var cArgs = [];
|
|
var stack = 0;
|
|
assert(returnType !== 'array', 'Return type should not be "array".');
|
|
if (args) {
|
|
for (var i = 0; i < args.length; i++) {
|
|
var converter = toC[argTypes[i]];
|
|
if (converter) {
|
|
if (stack === 0) stack = stackSave();
|
|
cArgs[i] = converter(args[i]);
|
|
} else {
|
|
cArgs[i] = args[i];
|
|
}
|
|
}
|
|
}
|
|
var ret = func.apply(null, cArgs);
|
|
function onDone(ret) {
|
|
if (stack !== 0) stackRestore(stack);
|
|
return convertReturnValue(ret);
|
|
}
|
|
|
|
ret = onDone(ret);
|
|
return ret;
|
|
}
|
|
|
|
/** @param {string=} returnType
|
|
@param {Array=} argTypes
|
|
@param {Object=} opts */
|
|
function cwrap(ident, returnType, argTypes, opts) {
|
|
return function() {
|
|
return ccall(ident, returnType, argTypes, arguments, opts);
|
|
}
|
|
}
|
|
|
|
// We used to include malloc/free by default in the past. Show a helpful error in
|
|
// builds with assertions.
|
|
|
|
// include: runtime_legacy.js
|
|
|
|
|
|
var ALLOC_NORMAL = 0; // Tries to use _malloc()
|
|
var ALLOC_STACK = 1; // Lives for the duration of the current function call
|
|
|
|
/**
|
|
* allocate(): This function is no longer used by emscripten but is kept around to avoid
|
|
* breaking external users.
|
|
* You should normally not use allocate(), and instead allocate
|
|
* memory using _malloc()/stackAlloc(), initialize it with
|
|
* setValue(), and so forth.
|
|
* @param {(Uint8Array|Array<number>)} slab: An array of data.
|
|
* @param {number=} allocator : How to allocate memory, see ALLOC_*
|
|
*/
|
|
function allocate(slab, allocator) {
|
|
var ret;
|
|
assert(typeof allocator == 'number', 'allocate no longer takes a type argument')
|
|
assert(typeof slab != 'number', 'allocate no longer takes a number as arg0')
|
|
|
|
if (allocator == ALLOC_STACK) {
|
|
ret = stackAlloc(slab.length);
|
|
} else {
|
|
ret = _malloc(slab.length);
|
|
}
|
|
|
|
if (!slab.subarray && !slab.slice) {
|
|
slab = new Uint8Array(slab);
|
|
}
|
|
HEAPU8.set(slab, ret);
|
|
return ret;
|
|
}
|
|
|
|
// end include: runtime_legacy.js
|
|
// include: runtime_strings.js
|
|
|
|
|
|
// runtime_strings.js: Strings related runtime functions that are part of both MINIMAL_RUNTIME and regular runtime.
|
|
|
|
var UTF8Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder('utf8') : undefined;
|
|
|
|
// Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the given array that contains uint8 values, returns
|
|
// a copy of that string as a Javascript String object.
|
|
/**
|
|
* heapOrArray is either a regular array, or a JavaScript typed array view.
|
|
* @param {number} idx
|
|
* @param {number=} maxBytesToRead
|
|
* @return {string}
|
|
*/
|
|
function UTF8ArrayToString(heapOrArray, idx, maxBytesToRead) {
|
|
var endIdx = idx + maxBytesToRead;
|
|
var endPtr = idx;
|
|
// TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
|
|
// Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
|
|
// (As a tiny code save trick, compare endPtr against endIdx using a negation, so that undefined means Infinity)
|
|
while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
|
|
|
|
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
|
|
return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
|
|
} else {
|
|
var str = '';
|
|
// If building with TextDecoder, we have already computed the string length above, so test loop end condition against that
|
|
while (idx < endPtr) {
|
|
// For UTF8 byte structure, see:
|
|
// http://en.wikipedia.org/wiki/UTF-8#Description
|
|
// https://www.ietf.org/rfc/rfc2279.txt
|
|
// https://tools.ietf.org/html/rfc3629
|
|
var u0 = heapOrArray[idx++];
|
|
if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
|
|
var u1 = heapOrArray[idx++] & 63;
|
|
if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
|
|
var u2 = heapOrArray[idx++] & 63;
|
|
if ((u0 & 0xF0) == 0xE0) {
|
|
u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
|
|
} else {
|
|
if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte 0x' + u0.toString(16) + ' encountered when deserializing a UTF-8 string in wasm memory to a JS string!');
|
|
u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
|
|
}
|
|
|
|
if (u0 < 0x10000) {
|
|
str += String.fromCharCode(u0);
|
|
} else {
|
|
var ch = u0 - 0x10000;
|
|
str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
|
|
}
|
|
}
|
|
}
|
|
return str;
|
|
}
|
|
|
|
// Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the emscripten HEAP, returns a
|
|
// copy of that string as a Javascript String object.
|
|
// maxBytesToRead: an optional length that specifies the maximum number of bytes to read. You can omit
|
|
// this parameter to scan the string until the first \0 byte. If maxBytesToRead is
|
|
// passed, and the string at [ptr, ptr+maxBytesToReadr[ contains a null byte in the
|
|
// middle, then the string will cut short at that byte index (i.e. maxBytesToRead will
|
|
// not produce a string of exact length [ptr, ptr+maxBytesToRead[)
|
|
// N.B. mixing frequent uses of UTF8ToString() with and without maxBytesToRead may
|
|
// throw JS JIT optimizations off, so it is worth to consider consistently using one
|
|
// style or the other.
|
|
/**
|
|
* @param {number} ptr
|
|
* @param {number=} maxBytesToRead
|
|
* @return {string}
|
|
*/
|
|
function UTF8ToString(ptr, maxBytesToRead) {
|
|
return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
|
|
}
|
|
|
|
// Copies the given Javascript String object 'str' to the given byte array at address 'outIdx',
|
|
// encoded in UTF8 form and null-terminated. The copy will require at most str.length*4+1 bytes of space in the HEAP.
|
|
// Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
|
|
// Parameters:
|
|
// str: the Javascript string to copy.
|
|
// heap: the array to copy to. Each index in this array is assumed to be one 8-byte element.
|
|
// outIdx: The starting offset in the array to begin the copying.
|
|
// maxBytesToWrite: The maximum number of bytes this function can write to the array.
|
|
// This count should include the null terminator,
|
|
// i.e. if maxBytesToWrite=1, only the null terminator will be written and nothing else.
|
|
// maxBytesToWrite=0 does not write any bytes to the output, not even the null terminator.
|
|
// Returns the number of bytes written, EXCLUDING the null terminator.
|
|
|
|
function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
|
|
if (!(maxBytesToWrite > 0)) // Parameter maxBytesToWrite is not optional. Negative values, 0, null, undefined and false each don't write out any bytes.
|
|
return 0;
|
|
|
|
var startIdx = outIdx;
|
|
var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
|
|
for (var i = 0; i < str.length; ++i) {
|
|
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
|
|
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
// For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629
|
|
var u = str.charCodeAt(i); // possibly a lead surrogate
|
|
if (u >= 0xD800 && u <= 0xDFFF) {
|
|
var u1 = str.charCodeAt(++i);
|
|
u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF);
|
|
}
|
|
if (u <= 0x7F) {
|
|
if (outIdx >= endIdx) break;
|
|
heap[outIdx++] = u;
|
|
} else if (u <= 0x7FF) {
|
|
if (outIdx + 1 >= endIdx) break;
|
|
heap[outIdx++] = 0xC0 | (u >> 6);
|
|
heap[outIdx++] = 0x80 | (u & 63);
|
|
} else if (u <= 0xFFFF) {
|
|
if (outIdx + 2 >= endIdx) break;
|
|
heap[outIdx++] = 0xE0 | (u >> 12);
|
|
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
heap[outIdx++] = 0x80 | (u & 63);
|
|
} else {
|
|
if (outIdx + 3 >= endIdx) break;
|
|
if (u > 0x10FFFF) warnOnce('Invalid Unicode code point 0x' + u.toString(16) + ' encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).');
|
|
heap[outIdx++] = 0xF0 | (u >> 18);
|
|
heap[outIdx++] = 0x80 | ((u >> 12) & 63);
|
|
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
heap[outIdx++] = 0x80 | (u & 63);
|
|
}
|
|
}
|
|
// Null-terminate the pointer to the buffer.
|
|
heap[outIdx] = 0;
|
|
return outIdx - startIdx;
|
|
}
|
|
|
|
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
|
|
// null-terminated and encoded in UTF8 form. The copy will require at most str.length*4+1 bytes of space in the HEAP.
|
|
// Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
|
|
// Returns the number of bytes written, EXCLUDING the null terminator.
|
|
|
|
function stringToUTF8(str, outPtr, maxBytesToWrite) {
|
|
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);
|
|
}
|
|
|
|
// Returns the number of bytes the given Javascript string takes if encoded as a UTF8 byte array, EXCLUDING the null terminator byte.
|
|
function lengthBytesUTF8(str) {
|
|
var len = 0;
|
|
for (var i = 0; i < str.length; ++i) {
|
|
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
|
|
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
var u = str.charCodeAt(i); // possibly a lead surrogate
|
|
if (u >= 0xD800 && u <= 0xDFFF) u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF);
|
|
if (u <= 0x7F) ++len;
|
|
else if (u <= 0x7FF) len += 2;
|
|
else if (u <= 0xFFFF) len += 3;
|
|
else len += 4;
|
|
}
|
|
return len;
|
|
}
|
|
|
|
// end include: runtime_strings.js
|
|
// include: runtime_strings_extra.js
|
|
|
|
|
|
// runtime_strings_extra.js: Strings related runtime functions that are available only in regular runtime.
|
|
|
|
// Given a pointer 'ptr' to a null-terminated ASCII-encoded string in the emscripten HEAP, returns
|
|
// a copy of that string as a Javascript String object.
|
|
|
|
function AsciiToString(ptr) {
|
|
var str = '';
|
|
while (1) {
|
|
var ch = HEAPU8[((ptr++)>>0)];
|
|
if (!ch) return str;
|
|
str += String.fromCharCode(ch);
|
|
}
|
|
}
|
|
|
|
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
|
|
// null-terminated and encoded in ASCII form. The copy will require at most str.length+1 bytes of space in the HEAP.
|
|
|
|
function stringToAscii(str, outPtr) {
|
|
return writeAsciiToMemory(str, outPtr, false);
|
|
}
|
|
|
|
// Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns
|
|
// a copy of that string as a Javascript String object.
|
|
|
|
var UTF16Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder('utf-16le') : undefined;
|
|
|
|
function UTF16ToString(ptr, maxBytesToRead) {
|
|
assert(ptr % 2 == 0, 'Pointer passed to UTF16ToString must be aligned to two bytes!');
|
|
var endPtr = ptr;
|
|
// TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
|
|
// Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
|
|
var idx = endPtr >> 1;
|
|
var maxIdx = idx + maxBytesToRead / 2;
|
|
// If maxBytesToRead is not passed explicitly, it will be undefined, and this
|
|
// will always evaluate to true. This saves on code size.
|
|
while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx;
|
|
endPtr = idx << 1;
|
|
|
|
if (endPtr - ptr > 32 && UTF16Decoder) {
|
|
return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr));
|
|
} else {
|
|
var str = '';
|
|
|
|
// If maxBytesToRead is not passed explicitly, it will be undefined, and the for-loop's condition
|
|
// will always evaluate to true. The loop is then terminated on the first null char.
|
|
for (var i = 0; !(i >= maxBytesToRead / 2); ++i) {
|
|
var codeUnit = HEAP16[(((ptr)+(i*2))>>1)];
|
|
if (codeUnit == 0) break;
|
|
// fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
|
|
str += String.fromCharCode(codeUnit);
|
|
}
|
|
|
|
return str;
|
|
}
|
|
}
|
|
|
|
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
|
|
// null-terminated and encoded in UTF16 form. The copy will require at most str.length*4+2 bytes of space in the HEAP.
|
|
// Use the function lengthBytesUTF16() to compute the exact number of bytes (excluding null terminator) that this function will write.
|
|
// Parameters:
|
|
// str: the Javascript string to copy.
|
|
// outPtr: Byte address in Emscripten HEAP where to write the string to.
|
|
// maxBytesToWrite: The maximum number of bytes this function can write to the array. This count should include the null
|
|
// terminator, i.e. if maxBytesToWrite=2, only the null terminator will be written and nothing else.
|
|
// maxBytesToWrite<2 does not write any bytes to the output, not even the null terminator.
|
|
// Returns the number of bytes written, EXCLUDING the null terminator.
|
|
|
|
function stringToUTF16(str, outPtr, maxBytesToWrite) {
|
|
assert(outPtr % 2 == 0, 'Pointer passed to stringToUTF16 must be aligned to two bytes!');
|
|
assert(typeof maxBytesToWrite == 'number', 'stringToUTF16(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
|
|
// Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
|
|
if (maxBytesToWrite === undefined) {
|
|
maxBytesToWrite = 0x7FFFFFFF;
|
|
}
|
|
if (maxBytesToWrite < 2) return 0;
|
|
maxBytesToWrite -= 2; // Null terminator.
|
|
var startPtr = outPtr;
|
|
var numCharsToWrite = (maxBytesToWrite < str.length*2) ? (maxBytesToWrite / 2) : str.length;
|
|
for (var i = 0; i < numCharsToWrite; ++i) {
|
|
// charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP.
|
|
var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
|
|
HEAP16[((outPtr)>>1)] = codeUnit;
|
|
outPtr += 2;
|
|
}
|
|
// Null-terminate the pointer to the HEAP.
|
|
HEAP16[((outPtr)>>1)] = 0;
|
|
return outPtr - startPtr;
|
|
}
|
|
|
|
// Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte.
|
|
|
|
function lengthBytesUTF16(str) {
|
|
return str.length*2;
|
|
}
|
|
|
|
function UTF32ToString(ptr, maxBytesToRead) {
|
|
assert(ptr % 4 == 0, 'Pointer passed to UTF32ToString must be aligned to four bytes!');
|
|
var i = 0;
|
|
|
|
var str = '';
|
|
// If maxBytesToRead is not passed explicitly, it will be undefined, and this
|
|
// will always evaluate to true. This saves on code size.
|
|
while (!(i >= maxBytesToRead / 4)) {
|
|
var utf32 = HEAP32[(((ptr)+(i*4))>>2)];
|
|
if (utf32 == 0) break;
|
|
++i;
|
|
// Gotcha: fromCharCode constructs a character from a UTF-16 encoded code (pair), not from a Unicode code point! So encode the code point to UTF-16 for constructing.
|
|
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
if (utf32 >= 0x10000) {
|
|
var ch = utf32 - 0x10000;
|
|
str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
|
|
} else {
|
|
str += String.fromCharCode(utf32);
|
|
}
|
|
}
|
|
return str;
|
|
}
|
|
|
|
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
|
|
// null-terminated and encoded in UTF32 form. The copy will require at most str.length*4+4 bytes of space in the HEAP.
|
|
// Use the function lengthBytesUTF32() to compute the exact number of bytes (excluding null terminator) that this function will write.
|
|
// Parameters:
|
|
// str: the Javascript string to copy.
|
|
// outPtr: Byte address in Emscripten HEAP where to write the string to.
|
|
// maxBytesToWrite: The maximum number of bytes this function can write to the array. This count should include the null
|
|
// terminator, i.e. if maxBytesToWrite=4, only the null terminator will be written and nothing else.
|
|
// maxBytesToWrite<4 does not write any bytes to the output, not even the null terminator.
|
|
// Returns the number of bytes written, EXCLUDING the null terminator.
|
|
|
|
function stringToUTF32(str, outPtr, maxBytesToWrite) {
|
|
assert(outPtr % 4 == 0, 'Pointer passed to stringToUTF32 must be aligned to four bytes!');
|
|
assert(typeof maxBytesToWrite == 'number', 'stringToUTF32(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
|
|
// Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
|
|
if (maxBytesToWrite === undefined) {
|
|
maxBytesToWrite = 0x7FFFFFFF;
|
|
}
|
|
if (maxBytesToWrite < 4) return 0;
|
|
var startPtr = outPtr;
|
|
var endPtr = startPtr + maxBytesToWrite - 4;
|
|
for (var i = 0; i < str.length; ++i) {
|
|
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
|
|
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
|
|
if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {
|
|
var trailSurrogate = str.charCodeAt(++i);
|
|
codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF);
|
|
}
|
|
HEAP32[((outPtr)>>2)] = codeUnit;
|
|
outPtr += 4;
|
|
if (outPtr + 4 > endPtr) break;
|
|
}
|
|
// Null-terminate the pointer to the HEAP.
|
|
HEAP32[((outPtr)>>2)] = 0;
|
|
return outPtr - startPtr;
|
|
}
|
|
|
|
// Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte.
|
|
|
|
function lengthBytesUTF32(str) {
|
|
var len = 0;
|
|
for (var i = 0; i < str.length; ++i) {
|
|
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
|
|
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
var codeUnit = str.charCodeAt(i);
|
|
if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) ++i; // possibly a lead surrogate, so skip over the tail surrogate.
|
|
len += 4;
|
|
}
|
|
|
|
return len;
|
|
}
|
|
|
|
// Allocate heap space for a JS string, and write it there.
|
|
// It is the responsibility of the caller to free() that memory.
|
|
function allocateUTF8(str) {
|
|
var size = lengthBytesUTF8(str) + 1;
|
|
var ret = _malloc(size);
|
|
if (ret) stringToUTF8Array(str, HEAP8, ret, size);
|
|
return ret;
|
|
}
|
|
|
|
// Allocate stack space for a JS string, and write it there.
|
|
function allocateUTF8OnStack(str) {
|
|
var size = lengthBytesUTF8(str) + 1;
|
|
var ret = stackAlloc(size);
|
|
stringToUTF8Array(str, HEAP8, ret, size);
|
|
return ret;
|
|
}
|
|
|
|
// Deprecated: This function should not be called because it is unsafe and does not provide
|
|
// a maximum length limit of how many bytes it is allowed to write. Prefer calling the
|
|
// function stringToUTF8Array() instead, which takes in a maximum length that can be used
|
|
// to be secure from out of bounds writes.
|
|
/** @deprecated
|
|
@param {boolean=} dontAddNull */
|
|
function writeStringToMemory(string, buffer, dontAddNull) {
|
|
warnOnce('writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!');
|
|
|
|
var /** @type {number} */ lastChar, /** @type {number} */ end;
|
|
if (dontAddNull) {
|
|
// stringToUTF8Array always appends null. If we don't want to do that, remember the
|
|
// character that existed at the location where the null will be placed, and restore
|
|
// that after the write (below).
|
|
end = buffer + lengthBytesUTF8(string);
|
|
lastChar = HEAP8[end];
|
|
}
|
|
stringToUTF8(string, buffer, Infinity);
|
|
if (dontAddNull) HEAP8[end] = lastChar; // Restore the value under the null character.
|
|
}
|
|
|
|
function writeArrayToMemory(array, buffer) {
|
|
assert(array.length >= 0, 'writeArrayToMemory array must have a length (should be an array or typed array)')
|
|
HEAP8.set(array, buffer);
|
|
}
|
|
|
|
/** @param {boolean=} dontAddNull */
|
|
function writeAsciiToMemory(str, buffer, dontAddNull) {
|
|
for (var i = 0; i < str.length; ++i) {
|
|
assert(str.charCodeAt(i) === (str.charCodeAt(i) & 0xff));
|
|
HEAP8[((buffer++)>>0)] = str.charCodeAt(i);
|
|
}
|
|
// Null-terminate the pointer to the HEAP.
|
|
if (!dontAddNull) HEAP8[((buffer)>>0)] = 0;
|
|
}
|
|
|
|
// end include: runtime_strings_extra.js
|
|
// Memory management
|
|
|
|
var HEAP,
|
|
/** @type {!ArrayBuffer} */
|
|
buffer,
|
|
/** @type {!Int8Array} */
|
|
HEAP8,
|
|
/** @type {!Uint8Array} */
|
|
HEAPU8,
|
|
/** @type {!Int16Array} */
|
|
HEAP16,
|
|
/** @type {!Uint16Array} */
|
|
HEAPU16,
|
|
/** @type {!Int32Array} */
|
|
HEAP32,
|
|
/** @type {!Uint32Array} */
|
|
HEAPU32,
|
|
/** @type {!Float32Array} */
|
|
HEAPF32,
|
|
/** @type {!Float64Array} */
|
|
HEAPF64;
|
|
|
|
function updateGlobalBufferAndViews(buf) {
|
|
buffer = buf;
|
|
Module['HEAP8'] = HEAP8 = new Int8Array(buf);
|
|
Module['HEAP16'] = HEAP16 = new Int16Array(buf);
|
|
Module['HEAP32'] = HEAP32 = new Int32Array(buf);
|
|
Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf);
|
|
Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf);
|
|
Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf);
|
|
Module['HEAPF32'] = HEAPF32 = new Float32Array(buf);
|
|
Module['HEAPF64'] = HEAPF64 = new Float64Array(buf);
|
|
}
|
|
|
|
var TOTAL_STACK = 5242880;
|
|
if (Module['TOTAL_STACK']) assert(TOTAL_STACK === Module['TOTAL_STACK'], 'the stack size can no longer be determined at runtime')
|
|
|
|
var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 134217728;legacyModuleProp('INITIAL_MEMORY', 'INITIAL_MEMORY');
|
|
|
|
assert(INITIAL_MEMORY >= TOTAL_STACK, 'INITIAL_MEMORY should be larger than TOTAL_STACK, was ' + INITIAL_MEMORY + '! (TOTAL_STACK=' + TOTAL_STACK + ')');
|
|
|
|
// check for full engine support (use string 'subarray' to avoid closure compiler confusion)
|
|
assert(typeof Int32Array != 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray != undefined && Int32Array.prototype.set != undefined,
|
|
'JS engine does not provide full typed array support');
|
|
|
|
// If memory is defined in wasm, the user can't provide it.
|
|
assert(!Module['wasmMemory'], 'Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally');
|
|
assert(INITIAL_MEMORY == 134217728, 'Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically');
|
|
|
|
// include: runtime_init_table.js
|
|
// In regular non-RELOCATABLE mode the table is exported
|
|
// from the wasm module and this will be assigned once
|
|
// the exports are available.
|
|
var wasmTable;
|
|
|
|
// end include: runtime_init_table.js
|
|
// include: runtime_stack_check.js
|
|
|
|
|
|
// Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.
|
|
function writeStackCookie() {
|
|
var max = _emscripten_stack_get_end();
|
|
assert((max & 3) == 0);
|
|
// The stack grow downwards towards _emscripten_stack_get_end.
|
|
// We write cookies to the final two words in the stack and detect if they are
|
|
// ever overwritten.
|
|
HEAP32[((max)>>2)] = 0x2135467;
|
|
HEAP32[(((max)+(4))>>2)] = 0x89BACDFE;
|
|
// Also test the global address 0 for integrity.
|
|
HEAPU32[0] = 0x63736d65; /* 'emsc' */
|
|
}
|
|
|
|
function checkStackCookie() {
|
|
if (ABORT) return;
|
|
var max = _emscripten_stack_get_end();
|
|
var cookie1 = HEAPU32[((max)>>2)];
|
|
var cookie2 = HEAPU32[(((max)+(4))>>2)];
|
|
if (cookie1 != 0x2135467 || cookie2 != 0x89BACDFE) {
|
|
abort('Stack overflow! Stack cookie has been overwritten at 0x' + max.toString(16) + ', expected hex dwords 0x89BACDFE and 0x2135467, but received 0x' + cookie2.toString(16) + ' 0x' + cookie1.toString(16));
|
|
}
|
|
// Also test the global address 0 for integrity.
|
|
if (HEAPU32[0] !== 0x63736d65 /* 'emsc' */) abort('Runtime error: The application has corrupted its heap memory area (address zero)!');
|
|
}
|
|
|
|
// end include: runtime_stack_check.js
|
|
// include: runtime_assertions.js
|
|
|
|
|
|
// Endianness check
|
|
(function() {
|
|
var h16 = new Int16Array(1);
|
|
var h8 = new Int8Array(h16.buffer);
|
|
h16[0] = 0x6373;
|
|
if (h8[0] !== 0x73 || h8[1] !== 0x63) throw 'Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)';
|
|
})();
|
|
|
|
// end include: runtime_assertions.js
|
|
var __ATPRERUN__ = []; // functions called before the runtime is initialized
|
|
var __ATINIT__ = []; // functions called during startup
|
|
var __ATEXIT__ = []; // functions called during shutdown
|
|
var __ATPOSTRUN__ = []; // functions called after the main() is called
|
|
|
|
var runtimeInitialized = false;
|
|
|
|
function keepRuntimeAlive() {
|
|
return noExitRuntime;
|
|
}
|
|
|
|
function preRun() {
|
|
|
|
if (Module['preRun']) {
|
|
if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
|
|
while (Module['preRun'].length) {
|
|
addOnPreRun(Module['preRun'].shift());
|
|
}
|
|
}
|
|
|
|
callRuntimeCallbacks(__ATPRERUN__);
|
|
}
|
|
|
|
function initRuntime() {
|
|
assert(!runtimeInitialized);
|
|
runtimeInitialized = true;
|
|
|
|
checkStackCookie();
|
|
|
|
|
|
callRuntimeCallbacks(__ATINIT__);
|
|
}
|
|
|
|
function postRun() {
|
|
checkStackCookie();
|
|
|
|
if (Module['postRun']) {
|
|
if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
|
|
while (Module['postRun'].length) {
|
|
addOnPostRun(Module['postRun'].shift());
|
|
}
|
|
}
|
|
|
|
callRuntimeCallbacks(__ATPOSTRUN__);
|
|
}
|
|
|
|
function addOnPreRun(cb) {
|
|
__ATPRERUN__.unshift(cb);
|
|
}
|
|
|
|
function addOnInit(cb) {
|
|
__ATINIT__.unshift(cb);
|
|
}
|
|
|
|
function addOnExit(cb) {
|
|
}
|
|
|
|
function addOnPostRun(cb) {
|
|
__ATPOSTRUN__.unshift(cb);
|
|
}
|
|
|
|
// include: runtime_math.js
|
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
|
|
|
|
assert(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
|
|
assert(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
|
|
assert(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
|
|
assert(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
|
|
|
|
// end include: runtime_math.js
|
|
// A counter of dependencies for calling run(). If we need to
|
|
// do asynchronous work before running, increment this and
|
|
// decrement it. Incrementing must happen in a place like
|
|
// Module.preRun (used by emcc to add file preloading).
|
|
// Note that you can add dependencies in preRun, even though
|
|
// it happens right before run - run will be postponed until
|
|
// the dependencies are met.
|
|
var runDependencies = 0;
|
|
var runDependencyWatcher = null;
|
|
var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
|
|
var runDependencyTracking = {};
|
|
|
|
function getUniqueRunDependency(id) {
|
|
var orig = id;
|
|
while (1) {
|
|
if (!runDependencyTracking[id]) return id;
|
|
id = orig + Math.random();
|
|
}
|
|
}
|
|
|
|
function addRunDependency(id) {
|
|
runDependencies++;
|
|
|
|
if (Module['monitorRunDependencies']) {
|
|
Module['monitorRunDependencies'](runDependencies);
|
|
}
|
|
|
|
if (id) {
|
|
assert(!runDependencyTracking[id]);
|
|
runDependencyTracking[id] = 1;
|
|
if (runDependencyWatcher === null && typeof setInterval != 'undefined') {
|
|
// Check for missing dependencies every few seconds
|
|
runDependencyWatcher = setInterval(function() {
|
|
if (ABORT) {
|
|
clearInterval(runDependencyWatcher);
|
|
runDependencyWatcher = null;
|
|
return;
|
|
}
|
|
var shown = false;
|
|
for (var dep in runDependencyTracking) {
|
|
if (!shown) {
|
|
shown = true;
|
|
err('still waiting on run dependencies:');
|
|
}
|
|
err('dependency: ' + dep);
|
|
}
|
|
if (shown) {
|
|
err('(end of list)');
|
|
}
|
|
}, 10000);
|
|
}
|
|
} else {
|
|
err('warning: run dependency added without ID');
|
|
}
|
|
}
|
|
|
|
function removeRunDependency(id) {
|
|
runDependencies--;
|
|
|
|
if (Module['monitorRunDependencies']) {
|
|
Module['monitorRunDependencies'](runDependencies);
|
|
}
|
|
|
|
if (id) {
|
|
assert(runDependencyTracking[id]);
|
|
delete runDependencyTracking[id];
|
|
} else {
|
|
err('warning: run dependency removed without ID');
|
|
}
|
|
if (runDependencies == 0) {
|
|
if (runDependencyWatcher !== null) {
|
|
clearInterval(runDependencyWatcher);
|
|
runDependencyWatcher = null;
|
|
}
|
|
if (dependenciesFulfilled) {
|
|
var callback = dependenciesFulfilled;
|
|
dependenciesFulfilled = null;
|
|
callback(); // can add another dependenciesFulfilled
|
|
}
|
|
}
|
|
}
|
|
|
|
/** @param {string|number=} what */
|
|
function abort(what) {
|
|
{
|
|
if (Module['onAbort']) {
|
|
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;
|
|
EXITSTATUS = 1;
|
|
|
|
// 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
|
|
// defintion 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);
|
|
|
|
readyPromiseReject(e);
|
|
// 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;
|
|
}
|
|
|
|
// {{MEM_INITIALIZER}}
|
|
|
|
// include: memoryprofiler.js
|
|
|
|
|
|
// end include: memoryprofiler.js
|
|
// show errors on likely calls to FS when it was not included
|
|
var FS = {
|
|
error: function() {
|
|
abort('Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM');
|
|
},
|
|
init: function() { FS.error() },
|
|
createDataFile: function() { FS.error() },
|
|
createPreloadedFile: function() { FS.error() },
|
|
createLazyFile: function() { FS.error() },
|
|
open: function() { FS.error() },
|
|
mkdev: function() { FS.error() },
|
|
registerDevice: function() { FS.error() },
|
|
analyzePath: function() { FS.error() },
|
|
loadFilesFromDB: function() { FS.error() },
|
|
|
|
ErrnoError: function ErrnoError() { FS.error() },
|
|
};
|
|
Module['FS_createDataFile'] = FS.createDataFile;
|
|
Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
|
|
|
|
// include: URIUtils.js
|
|
|
|
|
|
// 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://');
|
|
}
|
|
|
|
// end include: URIUtils.js
|
|
/** @param {boolean=} fixedasm */
|
|
function createExportWrapper(name, fixedasm) {
|
|
return function() {
|
|
var displayName = name;
|
|
var asm = fixedasm;
|
|
if (!fixedasm) {
|
|
asm = Module['asm'];
|
|
}
|
|
assert(runtimeInitialized, 'native function `' + displayName + '` called before runtime initialization');
|
|
if (!asm[name]) {
|
|
assert(asm[name], 'exported native function `' + displayName + '` not found');
|
|
}
|
|
return asm[name].apply(null, arguments);
|
|
};
|
|
}
|
|
|
|
var wasmBinaryFile;
|
|
wasmBinaryFile = 'renderer.wasm';
|
|
if (!isDataURI(wasmBinaryFile)) {
|
|
wasmBinaryFile = locateFile(wasmBinaryFile);
|
|
}
|
|
|
|
function getBinary(file) {
|
|
try {
|
|
if (file == wasmBinaryFile && wasmBinary) {
|
|
return new Uint8Array(wasmBinary);
|
|
}
|
|
if (readBinary) {
|
|
return readBinary(file);
|
|
} else {
|
|
throw "both async and sync fetching of the wasm failed";
|
|
}
|
|
}
|
|
catch (err) {
|
|
abort(err);
|
|
}
|
|
}
|
|
|
|
function getBinaryPromise() {
|
|
// If we don't have the binary yet, try to 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 (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
|
|
if (typeof fetch == 'function'
|
|
) {
|
|
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
|
|
if (!response['ok']) {
|
|
throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
|
|
}
|
|
return response['arrayBuffer']();
|
|
}).catch(function () {
|
|
return getBinary(wasmBinaryFile);
|
|
});
|
|
}
|
|
}
|
|
|
|
// Otherwise, getBinary should be able to get it synchronously
|
|
return Promise.resolve().then(function() { return getBinary(wasmBinaryFile); });
|
|
}
|
|
|
|
// Create the wasm instance.
|
|
// Receives the wasm imports, returns the exports.
|
|
function createWasm() {
|
|
// prepare imports
|
|
var info = {
|
|
'env': asmLibraryArg,
|
|
'wasi_snapshot_preview1': asmLibraryArg,
|
|
};
|
|
// 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
|
|
/** @param {WebAssembly.Module=} module*/
|
|
function receiveInstance(instance, module) {
|
|
var exports = instance.exports;
|
|
|
|
Module['asm'] = exports;
|
|
|
|
wasmMemory = Module['asm']['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 === 134217728);
|
|
updateGlobalBufferAndViews(wasmMemory.buffer);
|
|
|
|
wasmTable = Module['asm']['__indirect_function_table'];
|
|
assert(wasmTable, "table not found in wasm exports");
|
|
|
|
addOnInit(Module['asm']['__wasm_call_ctors']);
|
|
|
|
removeRunDependency('wasm-instantiate');
|
|
|
|
}
|
|
// we can't run yet (except in a pthread, where we have a custom sync instantiator)
|
|
addRunDependency('wasm-instantiate');
|
|
|
|
// Prefer streaming instantiation if available.
|
|
// Async compilation can be confusing when an error on the page overwrites Module
|
|
// (for example, if the order of elements is wrong, and the one defining Module is
|
|
// later), so we save Module and check it later.
|
|
var trueModule = Module;
|
|
function receiveInstantiationResult(result) {
|
|
// 'result' is a ResultObject object which has both the module and instance.
|
|
// receiveInstance() will swap in the exports (to Module.asm) so they can be called
|
|
assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
|
|
trueModule = null;
|
|
// TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
|
|
// When the regression is fixed, can restore the above USE_PTHREADS-enabled path.
|
|
receiveInstance(result['instance']);
|
|
}
|
|
|
|
function instantiateArrayBuffer(receiver) {
|
|
return getBinaryPromise().then(function(binary) {
|
|
return WebAssembly.instantiate(binary, info);
|
|
}).then(function (instance) {
|
|
return instance;
|
|
}).then(receiver, function(reason) {
|
|
err('failed to asynchronously prepare wasm: ' + reason);
|
|
|
|
// Warn on some common problems.
|
|
if (isFileURI(wasmBinaryFile)) {
|
|
err('warning: Loading from a file URI (' + wasmBinaryFile + ') is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing');
|
|
}
|
|
abort(reason);
|
|
});
|
|
}
|
|
|
|
function instantiateAsync() {
|
|
if (!wasmBinary &&
|
|
typeof WebAssembly.instantiateStreaming == 'function' &&
|
|
!isDataURI(wasmBinaryFile) &&
|
|
typeof fetch == 'function') {
|
|
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
|
|
// Suppress closure warning here since the upstream definition for
|
|
// instantiateStreaming only allows Promise<Repsponse> rather than
|
|
// an actual Response.
|
|
// TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure is fixed.
|
|
/** @suppress {checkTypes} */
|
|
var result = WebAssembly.instantiateStreaming(response, info);
|
|
|
|
return result.then(
|
|
receiveInstantiationResult,
|
|
function(reason) {
|
|
// We expect the most common failure cause to be a bad MIME type for the binary,
|
|
// in which case falling back to ArrayBuffer instantiation should work.
|
|
err('wasm streaming compile failed: ' + reason);
|
|
err('falling back to ArrayBuffer instantiation');
|
|
return instantiateArrayBuffer(receiveInstantiationResult);
|
|
});
|
|
});
|
|
} else {
|
|
return instantiateArrayBuffer(receiveInstantiationResult);
|
|
}
|
|
}
|
|
|
|
// User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
|
|
// to manually instantiate the Wasm module themselves. This allows pages to run the instantiation parallel
|
|
// to any other async startup actions they are performing.
|
|
// Also pthreads and wasm workers initialize the wasm instance through this path.
|
|
if (Module['instantiateWasm']) {
|
|
try {
|
|
var exports = Module['instantiateWasm'](info, receiveInstance);
|
|
return exports;
|
|
} catch(e) {
|
|
err('Module.instantiateWasm callback failed with error: ' + e);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// If instantiation fails, reject the module ready promise.
|
|
instantiateAsync().catch(readyPromiseReject);
|
|
return {}; // no exports yet; we'll fill them in later
|
|
}
|
|
|
|
// Globals used by JS i64 conversions (see makeSetValue)
|
|
var tempDouble;
|
|
var tempI64;
|
|
|
|
// === Body ===
|
|
|
|
var ASM_CONSTS = {
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function callRuntimeCallbacks(callbacks) {
|
|
while (callbacks.length > 0) {
|
|
// Pass the module as the first argument.
|
|
callbacks.shift()(Module);
|
|
}
|
|
}
|
|
|
|
function withStackSave(f) {
|
|
var stack = stackSave();
|
|
var ret = f();
|
|
stackRestore(stack);
|
|
return ret;
|
|
}
|
|
function demangle(func) {
|
|
warnOnce('warning: build with -sDEMANGLE_SUPPORT to link in libcxxabi demangling');
|
|
return func;
|
|
}
|
|
|
|
function 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 + ']');
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* @param {number} ptr
|
|
* @param {string} type
|
|
*/
|
|
function getValue(ptr, type = 'i8') {
|
|
if (type.endsWith('*')) type = '*';
|
|
switch (type) {
|
|
case 'i1': return HEAP8[((ptr)>>0)];
|
|
case 'i8': return HEAP8[((ptr)>>0)];
|
|
case 'i16': return HEAP16[((ptr)>>1)];
|
|
case 'i32': return HEAP32[((ptr)>>2)];
|
|
case 'i64': return HEAP32[((ptr)>>2)];
|
|
case 'float': return HEAPF32[((ptr)>>2)];
|
|
case 'double': return HEAPF64[((ptr)>>3)];
|
|
case '*': return HEAPU32[((ptr)>>2)];
|
|
default: abort('invalid type for getValue: ' + type);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
var wasmTableMirror = [];
|
|
function getWasmTableEntry(funcPtr) {
|
|
var func = wasmTableMirror[funcPtr];
|
|
if (!func) {
|
|
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!");
|
|
return func;
|
|
}
|
|
|
|
function handleException(e) {
|
|
// Certain exception types we do not treat as errors since they are used for
|
|
// internal control flow.
|
|
// 1. ExitStatus, which is thrown by exit()
|
|
// 2. "unwind", which is thrown by emscripten_unwind_to_js_event_loop() and others
|
|
// that wish to return to JS event loop.
|
|
if (e instanceof ExitStatus || e == 'unwind') {
|
|
return EXITSTATUS;
|
|
}
|
|
quit_(1, e);
|
|
}
|
|
|
|
function jsStackTrace() {
|
|
var error = new Error();
|
|
if (!error.stack) {
|
|
// IE10+ special cases: It does have callstack info, but it is only
|
|
// populated if an Error object is thrown, so try that as a special-case.
|
|
try {
|
|
throw new Error();
|
|
} catch(e) {
|
|
error = e;
|
|
}
|
|
if (!error.stack) {
|
|
return '(no stack trace available)';
|
|
}
|
|
}
|
|
return error.stack.toString();
|
|
}
|
|
|
|
|
|
/**
|
|
* @param {number} ptr
|
|
* @param {number} value
|
|
* @param {string} type
|
|
*/
|
|
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 'i16': HEAP16[((ptr)>>1)] = value; break;
|
|
case 'i32': HEAP32[((ptr)>>2)] = value; break;
|
|
case 'i64': (tempI64 = [value>>>0,(tempDouble=value,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math.min((+(Math.floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[((ptr)>>2)] = tempI64[0],HEAP32[(((ptr)+(4))>>2)] = tempI64[1]); break;
|
|
case 'float': HEAPF32[((ptr)>>2)] = value; break;
|
|
case 'double': HEAPF64[((ptr)>>3)] = value; break;
|
|
case '*': HEAPU32[((ptr)>>2)] = value; break;
|
|
default: abort('invalid type for setValue: ' + type);
|
|
}
|
|
}
|
|
|
|
function setWasmTableEntry(idx, func) {
|
|
wasmTable.set(idx, func);
|
|
// With ABORT_ON_WASM_EXCEPTIONS wasmTable.get is overriden to return wrapped
|
|
// functions so we need to call it here to retrieve the potential wrapper correctly
|
|
// instead of just storing 'func' directly into wasmTableMirror
|
|
wasmTableMirror[idx] = wasmTable.get(idx);
|
|
}
|
|
|
|
function stackTrace() {
|
|
var js = jsStackTrace();
|
|
if (Module['extraStackTrace']) js += '\n' + Module['extraStackTrace']();
|
|
return demangleAll(js);
|
|
}
|
|
|
|
function setErrNo(value) {
|
|
HEAP32[((___errno_location())>>2)] = value;
|
|
return value;
|
|
}
|
|
|
|
var SYSCALLS = {varargs:undefined,get:function() {
|
|
assert(SYSCALLS.varargs != undefined);
|
|
SYSCALLS.varargs += 4;
|
|
var ret = HEAP32[(((SYSCALLS.varargs)-(4))>>2)];
|
|
return ret;
|
|
},getStr:function(ptr) {
|
|
var ret = UTF8ToString(ptr);
|
|
return ret;
|
|
}};
|
|
function ___syscall_fcntl64(fd, cmd, varargs) {
|
|
SYSCALLS.varargs = varargs;
|
|
|
|
return 0;
|
|
}
|
|
|
|
function ___syscall_fstat64(fd, buf) {
|
|
abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
|
|
}
|
|
|
|
function ___syscall_ioctl(fd, op, varargs) {
|
|
SYSCALLS.varargs = varargs;
|
|
|
|
return 0;
|
|
}
|
|
|
|
function ___syscall_lstat64(path, buf) {
|
|
abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
|
|
}
|
|
|
|
function ___syscall_newfstatat(dirfd, path, buf, flags) {
|
|
abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
|
|
}
|
|
|
|
function ___syscall_openat(dirfd, path, flags, varargs) {
|
|
SYSCALLS.varargs = varargs;
|
|
|
|
abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
|
|
}
|
|
|
|
function ___syscall_stat64(path, buf) {
|
|
abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
|
|
}
|
|
|
|
function __embind_register_bigint(primitiveType, name, size, minRange, maxRange) {}
|
|
|
|
function getShiftFromSize(size) {
|
|
switch (size) {
|
|
case 1: return 0;
|
|
case 2: return 1;
|
|
case 4: return 2;
|
|
case 8: return 3;
|
|
default:
|
|
throw new TypeError('Unknown type size: ' + size);
|
|
}
|
|
}
|
|
|
|
function embind_init_charCodes() {
|
|
var codes = new Array(256);
|
|
for (var i = 0; i < 256; ++i) {
|
|
codes[i] = String.fromCharCode(i);
|
|
}
|
|
embind_charCodes = codes;
|
|
}
|
|
var embind_charCodes = undefined;
|
|
function readLatin1String(ptr) {
|
|
var ret = "";
|
|
var c = ptr;
|
|
while (HEAPU8[c]) {
|
|
ret += embind_charCodes[HEAPU8[c++]];
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
var awaitingDependencies = {};
|
|
|
|
var registeredTypes = {};
|
|
|
|
var typeDependencies = {};
|
|
|
|
var char_0 = 48;
|
|
|
|
var char_9 = 57;
|
|
function makeLegalFunctionName(name) {
|
|
if (undefined === name) {
|
|
return '_unknown';
|
|
}
|
|
name = name.replace(/[^a-zA-Z0-9_]/g, '$');
|
|
var f = name.charCodeAt(0);
|
|
if (f >= char_0 && f <= char_9) {
|
|
return '_' + name;
|
|
}
|
|
return name;
|
|
}
|
|
function createNamedFunction(name, body) {
|
|
name = makeLegalFunctionName(name);
|
|
return function() {
|
|
"use strict";
|
|
return body.apply(this, arguments);
|
|
};
|
|
}
|
|
function extendError(baseErrorType, errorName) {
|
|
var errorClass = createNamedFunction(errorName, function(message) {
|
|
this.name = errorName;
|
|
this.message = message;
|
|
|
|
var stack = (new Error(message)).stack;
|
|
if (stack !== undefined) {
|
|
this.stack = this.toString() + '\n' +
|
|
stack.replace(/^Error(:[^\n]*)?\n/, '');
|
|
}
|
|
});
|
|
errorClass.prototype = Object.create(baseErrorType.prototype);
|
|
errorClass.prototype.constructor = errorClass;
|
|
errorClass.prototype.toString = function() {
|
|
if (this.message === undefined) {
|
|
return this.name;
|
|
} else {
|
|
return this.name + ': ' + this.message;
|
|
}
|
|
};
|
|
|
|
return errorClass;
|
|
}
|
|
var BindingError = undefined;
|
|
function throwBindingError(message) {
|
|
throw new BindingError(message);
|
|
}
|
|
|
|
var InternalError = undefined;
|
|
function throwInternalError(message) {
|
|
throw new InternalError(message);
|
|
}
|
|
function whenDependentTypesAreResolved(myTypes, dependentTypes, getTypeConverters) {
|
|
myTypes.forEach(function(type) {
|
|
typeDependencies[type] = dependentTypes;
|
|
});
|
|
|
|
function onComplete(typeConverters) {
|
|
var myTypeConverters = getTypeConverters(typeConverters);
|
|
if (myTypeConverters.length !== myTypes.length) {
|
|
throwInternalError('Mismatched type converter count');
|
|
}
|
|
for (var i = 0; i < myTypes.length; ++i) {
|
|
registerType(myTypes[i], myTypeConverters[i]);
|
|
}
|
|
}
|
|
|
|
var typeConverters = new Array(dependentTypes.length);
|
|
var unregisteredTypes = [];
|
|
var registered = 0;
|
|
dependentTypes.forEach((dt, i) => {
|
|
if (registeredTypes.hasOwnProperty(dt)) {
|
|
typeConverters[i] = registeredTypes[dt];
|
|
} else {
|
|
unregisteredTypes.push(dt);
|
|
if (!awaitingDependencies.hasOwnProperty(dt)) {
|
|
awaitingDependencies[dt] = [];
|
|
}
|
|
awaitingDependencies[dt].push(() => {
|
|
typeConverters[i] = registeredTypes[dt];
|
|
++registered;
|
|
if (registered === unregisteredTypes.length) {
|
|
onComplete(typeConverters);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
if (0 === unregisteredTypes.length) {
|
|
onComplete(typeConverters);
|
|
}
|
|
}
|
|
/** @param {Object=} options */
|
|
function registerType(rawType, registeredInstance, options = {}) {
|
|
if (!('argPackAdvance' in registeredInstance)) {
|
|
throw new TypeError('registerType registeredInstance requires argPackAdvance');
|
|
}
|
|
|
|
var name = registeredInstance.name;
|
|
if (!rawType) {
|
|
throwBindingError('type "' + name + '" must have a positive integer typeid pointer');
|
|
}
|
|
if (registeredTypes.hasOwnProperty(rawType)) {
|
|
if (options.ignoreDuplicateRegistrations) {
|
|
return;
|
|
} else {
|
|
throwBindingError("Cannot register type '" + name + "' twice");
|
|
}
|
|
}
|
|
|
|
registeredTypes[rawType] = registeredInstance;
|
|
delete typeDependencies[rawType];
|
|
|
|
if (awaitingDependencies.hasOwnProperty(rawType)) {
|
|
var callbacks = awaitingDependencies[rawType];
|
|
delete awaitingDependencies[rawType];
|
|
callbacks.forEach((cb) => cb());
|
|
}
|
|
}
|
|
function __embind_register_bool(rawType, name, size, trueValue, falseValue) {
|
|
var shift = getShiftFromSize(size);
|
|
|
|
name = readLatin1String(name);
|
|
registerType(rawType, {
|
|
name: name,
|
|
'fromWireType': function(wt) {
|
|
// ambiguous emscripten ABI: sometimes return values are
|
|
// true or false, and sometimes integers (0 or 1)
|
|
return !!wt;
|
|
},
|
|
'toWireType': function(destructors, o) {
|
|
return o ? trueValue : falseValue;
|
|
},
|
|
'argPackAdvance': 8,
|
|
'readValueFromPointer': function(pointer) {
|
|
// TODO: if heap is fixed (like in asm.js) this could be executed outside
|
|
var heap;
|
|
if (size === 1) {
|
|
heap = HEAP8;
|
|
} else if (size === 2) {
|
|
heap = HEAP16;
|
|
} else if (size === 4) {
|
|
heap = HEAP32;
|
|
} else {
|
|
throw new TypeError("Unknown boolean type size: " + name);
|
|
}
|
|
return this['fromWireType'](heap[pointer >> shift]);
|
|
},
|
|
destructorFunction: null, // This type does not need a destructor
|
|
});
|
|
}
|
|
|
|
function __embind_register_constant(name, type, value) {
|
|
name = readLatin1String(name);
|
|
whenDependentTypesAreResolved([], [type], function(type) {
|
|
type = type[0];
|
|
Module[name] = type['fromWireType'](value);
|
|
return [];
|
|
});
|
|
}
|
|
|
|
var emval_free_list = [];
|
|
|
|
var emval_handle_array = [{},{value:undefined},{value:null},{value:true},{value:false}];
|
|
function __emval_decref(handle) {
|
|
if (handle > 4 && 0 === --emval_handle_array[handle].refcount) {
|
|
emval_handle_array[handle] = undefined;
|
|
emval_free_list.push(handle);
|
|
}
|
|
}
|
|
|
|
function count_emval_handles() {
|
|
var count = 0;
|
|
for (var i = 5; i < emval_handle_array.length; ++i) {
|
|
if (emval_handle_array[i] !== undefined) {
|
|
++count;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
function get_first_emval() {
|
|
for (var i = 5; i < emval_handle_array.length; ++i) {
|
|
if (emval_handle_array[i] !== undefined) {
|
|
return emval_handle_array[i];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
function init_emval() {
|
|
Module['count_emval_handles'] = count_emval_handles;
|
|
Module['get_first_emval'] = get_first_emval;
|
|
}
|
|
var Emval = {toValue:(handle) => {
|
|
if (!handle) {
|
|
throwBindingError('Cannot use deleted val. handle = ' + handle);
|
|
}
|
|
return emval_handle_array[handle].value;
|
|
},toHandle:(value) => {
|
|
switch (value) {
|
|
case undefined: return 1;
|
|
case null: return 2;
|
|
case true: return 3;
|
|
case false: return 4;
|
|
default:{
|
|
var handle = emval_free_list.length ?
|
|
emval_free_list.pop() :
|
|
emval_handle_array.length;
|
|
|
|
emval_handle_array[handle] = {refcount: 1, value: value};
|
|
return handle;
|
|
}
|
|
}
|
|
}};
|
|
|
|
function simpleReadValueFromPointer(pointer) {
|
|
return this['fromWireType'](HEAP32[((pointer)>>2)]);
|
|
}
|
|
function __embind_register_emval(rawType, name) {
|
|
name = readLatin1String(name);
|
|
registerType(rawType, {
|
|
name: name,
|
|
'fromWireType': function(handle) {
|
|
var rv = Emval.toValue(handle);
|
|
__emval_decref(handle);
|
|
return rv;
|
|
},
|
|
'toWireType': function(destructors, value) {
|
|
return Emval.toHandle(value);
|
|
},
|
|
'argPackAdvance': 8,
|
|
'readValueFromPointer': simpleReadValueFromPointer,
|
|
destructorFunction: null, // This type does not need a destructor
|
|
|
|
// TODO: do we need a deleteObject here? write a test where
|
|
// emval is passed into JS via an interface
|
|
});
|
|
}
|
|
|
|
function embindRepr(v) {
|
|
if (v === null) {
|
|
return 'null';
|
|
}
|
|
var t = typeof v;
|
|
if (t === 'object' || t === 'array' || t === 'function') {
|
|
return v.toString();
|
|
} else {
|
|
return '' + v;
|
|
}
|
|
}
|
|
|
|
function floatReadValueFromPointer(name, shift) {
|
|
switch (shift) {
|
|
case 2: return function(pointer) {
|
|
return this['fromWireType'](HEAPF32[pointer >> 2]);
|
|
};
|
|
case 3: return function(pointer) {
|
|
return this['fromWireType'](HEAPF64[pointer >> 3]);
|
|
};
|
|
default:
|
|
throw new TypeError("Unknown float type: " + name);
|
|
}
|
|
}
|
|
function __embind_register_float(rawType, name, size) {
|
|
var shift = getShiftFromSize(size);
|
|
name = readLatin1String(name);
|
|
registerType(rawType, {
|
|
name: name,
|
|
'fromWireType': function(value) {
|
|
return value;
|
|
},
|
|
'toWireType': function(destructors, value) {
|
|
if (typeof value != "number" && typeof value != "boolean") {
|
|
throw new TypeError('Cannot convert "' + embindRepr(value) + '" to ' + this.name);
|
|
}
|
|
// The VM will perform JS to Wasm value conversion, according to the spec:
|
|
// https://www.w3.org/TR/wasm-js-api-1/#towebassemblyvalue
|
|
return value;
|
|
},
|
|
'argPackAdvance': 8,
|
|
'readValueFromPointer': floatReadValueFromPointer(name, shift),
|
|
destructorFunction: null, // This type does not need a destructor
|
|
});
|
|
}
|
|
|
|
function new_(constructor, argumentList) {
|
|
if (!(constructor instanceof Function)) {
|
|
throw new TypeError('new_ called with constructor type ' + typeof(constructor) + " which is not a function");
|
|
}
|
|
if (constructor === Function) {
|
|
throw new Error('new_ cannot create a new Function with DYNAMIC_EXECUTION == 0.');
|
|
}
|
|
/*
|
|
* Previously, the following line was just:
|
|
* function dummy() {};
|
|
* Unfortunately, Chrome was preserving 'dummy' as the object's name, even
|
|
* though at creation, the 'dummy' has the correct constructor name. Thus,
|
|
* objects created with IMVU.new would show up in the debugger as 'dummy',
|
|
* which isn't very helpful. Using IMVU.createNamedFunction addresses the
|
|
* issue. Doublely-unfortunately, there's no way to write a test for this
|
|
* behavior. -NRD 2013.02.22
|
|
*/
|
|
var dummy = createNamedFunction(constructor.name || 'unknownFunctionName', function(){});
|
|
dummy.prototype = constructor.prototype;
|
|
var obj = new dummy;
|
|
|
|
var r = constructor.apply(obj, argumentList);
|
|
return (r instanceof Object) ? r : obj;
|
|
}
|
|
|
|
function runDestructors(destructors) {
|
|
while (destructors.length) {
|
|
var ptr = destructors.pop();
|
|
var del = destructors.pop();
|
|
del(ptr);
|
|
}
|
|
}
|
|
function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cppTargetFunc) {
|
|
// humanName: a human-readable string name for the function to be generated.
|
|
// argTypes: An array that contains the embind type objects for all types in the function signature.
|
|
// argTypes[0] is the type object for the function return value.
|
|
// argTypes[1] is the type object for function this object/class type, or null if not crafting an invoker for a class method.
|
|
// argTypes[2...] are the actual function parameters.
|
|
// classType: The embind type object for the class to be bound, or null if this is not a method of a class.
|
|
// cppInvokerFunc: JS Function object to the C++-side function that interops into C++ code.
|
|
// cppTargetFunc: Function pointer (an integer to FUNCTION_TABLE) to the target C++ function the cppInvokerFunc will end up calling.
|
|
var argCount = argTypes.length;
|
|
|
|
if (argCount < 2) {
|
|
throwBindingError("argTypes array size mismatch! Must at least get return value and 'this' types!");
|
|
}
|
|
|
|
var isClassMethodFunc = (argTypes[1] !== null && classType !== null);
|
|
|
|
// Free functions with signature "void function()" do not need an invoker that marshalls between wire types.
|
|
// TODO: This omits argument count check - enable only at -O3 or similar.
|
|
// if (ENABLE_UNSAFE_OPTS && argCount == 2 && argTypes[0].name == "void" && !isClassMethodFunc) {
|
|
// return FUNCTION_TABLE[fn];
|
|
// }
|
|
|
|
// Determine if we need to use a dynamic stack to store the destructors for the function parameters.
|
|
// TODO: Remove this completely once all function invokers are being dynamically generated.
|
|
var needsDestructorStack = false;
|
|
|
|
for (var i = 1; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here.
|
|
if (argTypes[i] !== null && argTypes[i].destructorFunction === undefined) { // The type does not define a destructor function - must use dynamic stack
|
|
needsDestructorStack = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
var returns = (argTypes[0].name !== "void");
|
|
|
|
var expectedArgCount = argCount - 2;
|
|
var argsWired = new Array(expectedArgCount);
|
|
var invokerFuncArgs = [];
|
|
var destructors = [];
|
|
return function() {
|
|
if (arguments.length !== expectedArgCount) {
|
|
throwBindingError('function ' + humanName + ' called with ' +
|
|
arguments.length + ' arguments, expected ' + expectedArgCount +
|
|
' args!');
|
|
}
|
|
destructors.length = 0;
|
|
var thisWired;
|
|
invokerFuncArgs.length = isClassMethodFunc ? 2 : 1;
|
|
invokerFuncArgs[0] = cppTargetFunc;
|
|
if (isClassMethodFunc) {
|
|
thisWired = argTypes[1]['toWireType'](destructors, this);
|
|
invokerFuncArgs[1] = thisWired;
|
|
}
|
|
for (var i = 0; i < expectedArgCount; ++i) {
|
|
argsWired[i] = argTypes[i + 2]['toWireType'](destructors, arguments[i]);
|
|
invokerFuncArgs.push(argsWired[i]);
|
|
}
|
|
|
|
var rv = cppInvokerFunc.apply(null, invokerFuncArgs);
|
|
|
|
function onDone(rv) {
|
|
if (needsDestructorStack) {
|
|
runDestructors(destructors);
|
|
} else {
|
|
for (var i = isClassMethodFunc ? 1 : 2; i < argTypes.length; i++) {
|
|
var param = i === 1 ? thisWired : argsWired[i - 2];
|
|
if (argTypes[i].destructorFunction !== null) {
|
|
argTypes[i].destructorFunction(param);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (returns) {
|
|
return argTypes[0]['fromWireType'](rv);
|
|
}
|
|
}
|
|
|
|
return onDone(rv);
|
|
};
|
|
}
|
|
|
|
function ensureOverloadTable(proto, methodName, humanName) {
|
|
if (undefined === proto[methodName].overloadTable) {
|
|
var prevFunc = proto[methodName];
|
|
// Inject an overload resolver function that routes to the appropriate overload based on the number of arguments.
|
|
proto[methodName] = function() {
|
|
// TODO This check can be removed in -O3 level "unsafe" optimizations.
|
|
if (!proto[methodName].overloadTable.hasOwnProperty(arguments.length)) {
|
|
throwBindingError("Function '" + humanName + "' called with an invalid number of arguments (" + arguments.length + ") - expects one of (" + proto[methodName].overloadTable + ")!");
|
|
}
|
|
return proto[methodName].overloadTable[arguments.length].apply(this, arguments);
|
|
};
|
|
// Move the previous function into the overload table.
|
|
proto[methodName].overloadTable = [];
|
|
proto[methodName].overloadTable[prevFunc.argCount] = prevFunc;
|
|
}
|
|
}
|
|
/** @param {number=} numArguments */
|
|
function exposePublicSymbol(name, value, numArguments) {
|
|
if (Module.hasOwnProperty(name)) {
|
|
if (undefined === numArguments || (undefined !== Module[name].overloadTable && undefined !== Module[name].overloadTable[numArguments])) {
|
|
throwBindingError("Cannot register public name '" + name + "' twice");
|
|
}
|
|
|
|
// We are exposing a function with the same name as an existing function. Create an overload table and a function selector
|
|
// that routes between the two.
|
|
ensureOverloadTable(Module, name, name);
|
|
if (Module.hasOwnProperty(numArguments)) {
|
|
throwBindingError("Cannot register multiple overloads of a function with the same number of arguments (" + numArguments + ")!");
|
|
}
|
|
// Add the new function into the overload table.
|
|
Module[name].overloadTable[numArguments] = value;
|
|
}
|
|
else {
|
|
Module[name] = value;
|
|
if (undefined !== numArguments) {
|
|
Module[name].numArguments = numArguments;
|
|
}
|
|
}
|
|
}
|
|
|
|
function heap32VectorToArray(count, firstElement) {
|
|
var array = [];
|
|
for (var i = 0; i < count; i++) {
|
|
// TODO(https://github.com/emscripten-core/emscripten/issues/17310):
|
|
// Find a way to hoist the `>> 2` or `>> 3` out of this loop.
|
|
array.push(HEAPU32[(((firstElement)+(i * 4))>>2)]);
|
|
}
|
|
return array;
|
|
}
|
|
|
|
/** @param {number=} numArguments */
|
|
function replacePublicSymbol(name, value, numArguments) {
|
|
if (!Module.hasOwnProperty(name)) {
|
|
throwInternalError('Replacing nonexistant public symbol');
|
|
}
|
|
// If there's an overload table for this symbol, replace the symbol in the overload table instead.
|
|
if (undefined !== Module[name].overloadTable && undefined !== numArguments) {
|
|
Module[name].overloadTable[numArguments] = value;
|
|
}
|
|
else {
|
|
Module[name] = value;
|
|
Module[name].argCount = numArguments;
|
|
}
|
|
}
|
|
|
|
function dynCallLegacy(sig, ptr, args) {
|
|
assert(('dynCall_' + sig) in Module, 'bad function pointer type - no table for sig \'' + sig + '\'');
|
|
if (args && args.length) {
|
|
// j (64-bit integer) must be passed in as two numbers [low 32, high 32].
|
|
assert(args.length === sig.substring(1).replace(/j/g, '--').length);
|
|
} else {
|
|
assert(sig.length == 1);
|
|
}
|
|
var f = Module['dynCall_' + sig];
|
|
return args && args.length ? f.apply(null, [ptr].concat(args)) : f.call(null, ptr);
|
|
}
|
|
/** @param {Object=} args */
|
|
function dynCall(sig, ptr, args) {
|
|
// Without WASM_BIGINT support we cannot directly call function with i64 as
|
|
// part of thier signature, so we rely the dynCall functions generated by
|
|
// wasm-emscripten-finalize
|
|
if (sig.includes('j')) {
|
|
return dynCallLegacy(sig, ptr, args);
|
|
}
|
|
assert(getWasmTableEntry(ptr), 'missing table entry in dynCall: ' + ptr);
|
|
var rtn = getWasmTableEntry(ptr).apply(null, args);
|
|
return rtn;
|
|
}
|
|
function getDynCaller(sig, ptr) {
|
|
assert(sig.includes('j') || sig.includes('p'), 'getDynCaller should only be called with i64 sigs')
|
|
var argCache = [];
|
|
return function() {
|
|
argCache.length = 0;
|
|
Object.assign(argCache, arguments);
|
|
return dynCall(sig, ptr, argCache);
|
|
};
|
|
}
|
|
function embind__requireFunction(signature, rawFunction) {
|
|
signature = readLatin1String(signature);
|
|
|
|
function makeDynCaller() {
|
|
if (signature.includes('j')) {
|
|
return getDynCaller(signature, rawFunction);
|
|
}
|
|
return getWasmTableEntry(rawFunction);
|
|
}
|
|
|
|
var fp = makeDynCaller();
|
|
if (typeof fp != "function") {
|
|
throwBindingError("unknown function pointer with signature " + signature + ": " + rawFunction);
|
|
}
|
|
return fp;
|
|
}
|
|
|
|
var UnboundTypeError = undefined;
|
|
|
|
function getTypeName(type) {
|
|
var ptr = ___getTypeName(type);
|
|
var rv = readLatin1String(ptr);
|
|
_free(ptr);
|
|
return rv;
|
|
}
|
|
function throwUnboundTypeError(message, types) {
|
|
var unboundTypes = [];
|
|
var seen = {};
|
|
function visit(type) {
|
|
if (seen[type]) {
|
|
return;
|
|
}
|
|
if (registeredTypes[type]) {
|
|
return;
|
|
}
|
|
if (typeDependencies[type]) {
|
|
typeDependencies[type].forEach(visit);
|
|
return;
|
|
}
|
|
unboundTypes.push(type);
|
|
seen[type] = true;
|
|
}
|
|
types.forEach(visit);
|
|
|
|
throw new UnboundTypeError(message + ': ' + unboundTypes.map(getTypeName).join([', ']));
|
|
}
|
|
function __embind_register_function(name, argCount, rawArgTypesAddr, signature, rawInvoker, fn) {
|
|
var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
|
|
name = readLatin1String(name);
|
|
|
|
rawInvoker = embind__requireFunction(signature, rawInvoker);
|
|
|
|
exposePublicSymbol(name, function() {
|
|
throwUnboundTypeError('Cannot call ' + name + ' due to unbound types', argTypes);
|
|
}, argCount - 1);
|
|
|
|
whenDependentTypesAreResolved([], argTypes, function(argTypes) {
|
|
var invokerArgsArray = [argTypes[0] /* return value */, null /* no class 'this'*/].concat(argTypes.slice(1) /* actual params */);
|
|
replacePublicSymbol(name, craftInvokerFunction(name, invokerArgsArray, null /* no class 'this'*/, rawInvoker, fn), argCount - 1);
|
|
return [];
|
|
});
|
|
}
|
|
|
|
function integerReadValueFromPointer(name, shift, signed) {
|
|
// integers are quite common, so generate very specialized functions
|
|
switch (shift) {
|
|
case 0: return signed ?
|
|
function readS8FromPointer(pointer) { return HEAP8[pointer]; } :
|
|
function readU8FromPointer(pointer) { return HEAPU8[pointer]; };
|
|
case 1: return signed ?
|
|
function readS16FromPointer(pointer) { return HEAP16[pointer >> 1]; } :
|
|
function readU16FromPointer(pointer) { return HEAPU16[pointer >> 1]; };
|
|
case 2: return signed ?
|
|
function readS32FromPointer(pointer) { return HEAP32[pointer >> 2]; } :
|
|
function readU32FromPointer(pointer) { return HEAPU32[pointer >> 2]; };
|
|
default:
|
|
throw new TypeError("Unknown integer type: " + name);
|
|
}
|
|
}
|
|
function __embind_register_integer(primitiveType, name, size, minRange, maxRange) {
|
|
name = readLatin1String(name);
|
|
// LLVM doesn't have signed and unsigned 32-bit types, so u32 literals come
|
|
// out as 'i32 -1'. Always treat those as max u32.
|
|
if (maxRange === -1) {
|
|
maxRange = 4294967295;
|
|
}
|
|
|
|
var shift = getShiftFromSize(size);
|
|
|
|
var fromWireType = (value) => value;
|
|
|
|
if (minRange === 0) {
|
|
var bitshift = 32 - 8*size;
|
|
fromWireType = (value) => (value << bitshift) >>> bitshift;
|
|
}
|
|
|
|
var isUnsignedType = (name.includes('unsigned'));
|
|
var checkAssertions = (value, toTypeName) => {
|
|
if (typeof value != "number" && typeof value != "boolean") {
|
|
throw new TypeError('Cannot convert "' + embindRepr(value) + '" to ' + toTypeName);
|
|
}
|
|
if (value < minRange || value > maxRange) {
|
|
throw new TypeError('Passing a number "' + embindRepr(value) + '" from JS side to C/C++ side to an argument of type "' + name + '", which is outside the valid range [' + minRange + ', ' + maxRange + ']!');
|
|
}
|
|
}
|
|
var toWireType;
|
|
if (isUnsignedType) {
|
|
toWireType = function(destructors, value) {
|
|
checkAssertions(value, this.name);
|
|
return value >>> 0;
|
|
}
|
|
} else {
|
|
toWireType = function(destructors, value) {
|
|
checkAssertions(value, this.name);
|
|
// The VM will perform JS to Wasm value conversion, according to the spec:
|
|
// https://www.w3.org/TR/wasm-js-api-1/#towebassemblyvalue
|
|
return value;
|
|
}
|
|
}
|
|
registerType(primitiveType, {
|
|
name: name,
|
|
'fromWireType': fromWireType,
|
|
'toWireType': toWireType,
|
|
'argPackAdvance': 8,
|
|
'readValueFromPointer': integerReadValueFromPointer(name, shift, minRange !== 0),
|
|
destructorFunction: null, // This type does not need a destructor
|
|
});
|
|
}
|
|
|
|
function __embind_register_memory_view(rawType, dataTypeIndex, name) {
|
|
var typeMapping = [
|
|
Int8Array,
|
|
Uint8Array,
|
|
Int16Array,
|
|
Uint16Array,
|
|
Int32Array,
|
|
Uint32Array,
|
|
Float32Array,
|
|
Float64Array,
|
|
];
|
|
|
|
var TA = typeMapping[dataTypeIndex];
|
|
|
|
function decodeMemoryView(handle) {
|
|
handle = handle >> 2;
|
|
var heap = HEAPU32;
|
|
var size = heap[handle]; // in elements
|
|
var data = heap[handle + 1]; // byte offset into emscripten heap
|
|
return new TA(buffer, data, size);
|
|
}
|
|
|
|
name = readLatin1String(name);
|
|
registerType(rawType, {
|
|
name: name,
|
|
'fromWireType': decodeMemoryView,
|
|
'argPackAdvance': 8,
|
|
'readValueFromPointer': decodeMemoryView,
|
|
}, {
|
|
ignoreDuplicateRegistrations: true,
|
|
});
|
|
}
|
|
|
|
function __embind_register_std_string(rawType, name) {
|
|
name = readLatin1String(name);
|
|
var stdStringIsUTF8
|
|
//process only std::string bindings with UTF8 support, in contrast to e.g. std::basic_string<unsigned char>
|
|
= (name === "std::string");
|
|
|
|
registerType(rawType, {
|
|
name: name,
|
|
'fromWireType': function(value) {
|
|
var length = HEAPU32[((value)>>2)];
|
|
var payload = value + 4;
|
|
|
|
var str;
|
|
if (stdStringIsUTF8) {
|
|
var decodeStartPtr = payload;
|
|
// Looping here to support possible embedded '0' bytes
|
|
for (var i = 0; i <= length; ++i) {
|
|
var currentBytePtr = payload + i;
|
|
if (i == length || HEAPU8[currentBytePtr] == 0) {
|
|
var maxRead = currentBytePtr - decodeStartPtr;
|
|
var stringSegment = UTF8ToString(decodeStartPtr, maxRead);
|
|
if (str === undefined) {
|
|
str = stringSegment;
|
|
} else {
|
|
str += String.fromCharCode(0);
|
|
str += stringSegment;
|
|
}
|
|
decodeStartPtr = currentBytePtr + 1;
|
|
}
|
|
}
|
|
} else {
|
|
var a = new Array(length);
|
|
for (var i = 0; i < length; ++i) {
|
|
a[i] = String.fromCharCode(HEAPU8[payload + i]);
|
|
}
|
|
str = a.join('');
|
|
}
|
|
|
|
_free(value);
|
|
|
|
return str;
|
|
},
|
|
'toWireType': function(destructors, value) {
|
|
if (value instanceof ArrayBuffer) {
|
|
value = new Uint8Array(value);
|
|
}
|
|
|
|
var length;
|
|
var valueIsOfTypeString = (typeof value == 'string');
|
|
|
|
if (!(valueIsOfTypeString || value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int8Array)) {
|
|
throwBindingError('Cannot pass non-string to std::string');
|
|
}
|
|
if (stdStringIsUTF8 && valueIsOfTypeString) {
|
|
length = lengthBytesUTF8(value);
|
|
} else {
|
|
length = value.length;
|
|
}
|
|
|
|
// assumes 4-byte alignment
|
|
var base = _malloc(4 + length + 1);
|
|
var ptr = base + 4;
|
|
HEAPU32[((base)>>2)] = length;
|
|
if (stdStringIsUTF8 && valueIsOfTypeString) {
|
|
stringToUTF8(value, ptr, length + 1);
|
|
} else {
|
|
if (valueIsOfTypeString) {
|
|
for (var i = 0; i < length; ++i) {
|
|
var charCode = value.charCodeAt(i);
|
|
if (charCode > 255) {
|
|
_free(ptr);
|
|
throwBindingError('String has UTF-16 code units that do not fit in 8 bits');
|
|
}
|
|
HEAPU8[ptr + i] = charCode;
|
|
}
|
|
} else {
|
|
for (var i = 0; i < length; ++i) {
|
|
HEAPU8[ptr + i] = value[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
if (destructors !== null) {
|
|
destructors.push(_free, base);
|
|
}
|
|
return base;
|
|
},
|
|
'argPackAdvance': 8,
|
|
'readValueFromPointer': simpleReadValueFromPointer,
|
|
destructorFunction: function(ptr) { _free(ptr); },
|
|
});
|
|
}
|
|
|
|
function __embind_register_std_wstring(rawType, charSize, name) {
|
|
name = readLatin1String(name);
|
|
var decodeString, encodeString, getHeap, lengthBytesUTF, shift;
|
|
if (charSize === 2) {
|
|
decodeString = UTF16ToString;
|
|
encodeString = stringToUTF16;
|
|
lengthBytesUTF = lengthBytesUTF16;
|
|
getHeap = () => HEAPU16;
|
|
shift = 1;
|
|
} else if (charSize === 4) {
|
|
decodeString = UTF32ToString;
|
|
encodeString = stringToUTF32;
|
|
lengthBytesUTF = lengthBytesUTF32;
|
|
getHeap = () => HEAPU32;
|
|
shift = 2;
|
|
}
|
|
registerType(rawType, {
|
|
name: name,
|
|
'fromWireType': function(value) {
|
|
// Code mostly taken from _embind_register_std_string fromWireType
|
|
var length = HEAPU32[value >> 2];
|
|
var HEAP = getHeap();
|
|
var str;
|
|
|
|
var decodeStartPtr = value + 4;
|
|
// Looping here to support possible embedded '0' bytes
|
|
for (var i = 0; i <= length; ++i) {
|
|
var currentBytePtr = value + 4 + i * charSize;
|
|
if (i == length || HEAP[currentBytePtr >> shift] == 0) {
|
|
var maxReadBytes = currentBytePtr - decodeStartPtr;
|
|
var stringSegment = decodeString(decodeStartPtr, maxReadBytes);
|
|
if (str === undefined) {
|
|
str = stringSegment;
|
|
} else {
|
|
str += String.fromCharCode(0);
|
|
str += stringSegment;
|
|
}
|
|
decodeStartPtr = currentBytePtr + charSize;
|
|
}
|
|
}
|
|
|
|
_free(value);
|
|
|
|
return str;
|
|
},
|
|
'toWireType': function(destructors, value) {
|
|
if (!(typeof value == 'string')) {
|
|
throwBindingError('Cannot pass non-string to C++ string type ' + name);
|
|
}
|
|
|
|
// assumes 4-byte alignment
|
|
var length = lengthBytesUTF(value);
|
|
var ptr = _malloc(4 + length + charSize);
|
|
HEAPU32[ptr >> 2] = length >> shift;
|
|
|
|
encodeString(value, ptr + 4, length + charSize);
|
|
|
|
if (destructors !== null) {
|
|
destructors.push(_free, ptr);
|
|
}
|
|
return ptr;
|
|
},
|
|
'argPackAdvance': 8,
|
|
'readValueFromPointer': simpleReadValueFromPointer,
|
|
destructorFunction: function(ptr) { _free(ptr); },
|
|
});
|
|
}
|
|
|
|
function __embind_register_void(rawType, name) {
|
|
name = readLatin1String(name);
|
|
registerType(rawType, {
|
|
isVoid: true, // void return values can be optimized out sometimes
|
|
name: name,
|
|
'argPackAdvance': 0,
|
|
'fromWireType': function() {
|
|
return undefined;
|
|
},
|
|
'toWireType': function(destructors, o) {
|
|
// TODO: assert if anything else is given?
|
|
return undefined;
|
|
},
|
|
});
|
|
}
|
|
|
|
function __emscripten_date_now() {
|
|
return Date.now();
|
|
}
|
|
|
|
var nowIsMonotonic = true;;
|
|
function __emscripten_get_now_is_monotonic() {
|
|
return nowIsMonotonic;
|
|
}
|
|
|
|
function __emscripten_throw_longjmp() { throw Infinity; }
|
|
|
|
function __mmap_js(len, prot, flags, fd, off, allocated) {
|
|
return -52;
|
|
}
|
|
|
|
function __munmap_js(addr, len, prot, flags, fd, offset) {
|
|
}
|
|
|
|
function _abort() {
|
|
abort('native code called abort()');
|
|
}
|
|
|
|
var _emscripten_get_now;_emscripten_get_now = () => performance.now();
|
|
;
|
|
|
|
function __webgl_enable_ANGLE_instanced_arrays(ctx) {
|
|
// Extension available in WebGL 1 from Firefox 26 and Google Chrome 30 onwards. Core feature in WebGL 2.
|
|
var ext = ctx.getExtension('ANGLE_instanced_arrays');
|
|
if (ext) {
|
|
ctx['vertexAttribDivisor'] = function(index, divisor) { ext['vertexAttribDivisorANGLE'](index, divisor); };
|
|
ctx['drawArraysInstanced'] = function(mode, first, count, primcount) { ext['drawArraysInstancedANGLE'](mode, first, count, primcount); };
|
|
ctx['drawElementsInstanced'] = function(mode, count, type, indices, primcount) { ext['drawElementsInstancedANGLE'](mode, count, type, indices, primcount); };
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
function __webgl_enable_OES_vertex_array_object(ctx) {
|
|
// Extension available in WebGL 1 from Firefox 25 and WebKit 536.28/desktop Safari 6.0.3 onwards. Core feature in WebGL 2.
|
|
var ext = ctx.getExtension('OES_vertex_array_object');
|
|
if (ext) {
|
|
ctx['createVertexArray'] = function() { return ext['createVertexArrayOES'](); };
|
|
ctx['deleteVertexArray'] = function(vao) { ext['deleteVertexArrayOES'](vao); };
|
|
ctx['bindVertexArray'] = function(vao) { ext['bindVertexArrayOES'](vao); };
|
|
ctx['isVertexArray'] = function(vao) { return ext['isVertexArrayOES'](vao); };
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
function __webgl_enable_WEBGL_draw_buffers(ctx) {
|
|
// Extension available in WebGL 1 from Firefox 28 onwards. Core feature in WebGL 2.
|
|
var ext = ctx.getExtension('WEBGL_draw_buffers');
|
|
if (ext) {
|
|
ctx['drawBuffers'] = function(n, bufs) { ext['drawBuffersWEBGL'](n, bufs); };
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
function __webgl_enable_WEBGL_draw_instanced_base_vertex_base_instance(ctx) {
|
|
// Closure is expected to be allowed to minify the '.dibvbi' property, so not accessing it quoted.
|
|
return !!(ctx.dibvbi = ctx.getExtension('WEBGL_draw_instanced_base_vertex_base_instance'));
|
|
}
|
|
|
|
function __webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance(ctx) {
|
|
// Closure is expected to be allowed to minify the '.mdibvbi' property, so not accessing it quoted.
|
|
return !!(ctx.mdibvbi = ctx.getExtension('WEBGL_multi_draw_instanced_base_vertex_base_instance'));
|
|
}
|
|
|
|
function __webgl_enable_WEBGL_multi_draw(ctx) {
|
|
// Closure is expected to be allowed to minify the '.multiDrawWebgl' property, so not accessing it quoted.
|
|
return !!(ctx.multiDrawWebgl = ctx.getExtension('WEBGL_multi_draw'));
|
|
}
|
|
var GL = {counter:1,buffers:[],programs:[],framebuffers:[],renderbuffers:[],textures:[],shaders:[],vaos:[],contexts:[],offscreenCanvases:{},queries:[],samplers:[],transformFeedbacks:[],syncs:[],stringCache:{},stringiCache:{},unpackAlignment:4,recordError:function recordError(errorCode) {
|
|
if (!GL.lastError) {
|
|
GL.lastError = errorCode;
|
|
}
|
|
},getNewId:function(table) {
|
|
var ret = GL.counter++;
|
|
for (var i = table.length; i < ret; i++) {
|
|
table[i] = null;
|
|
}
|
|
return ret;
|
|
},getSource:function(shader, count, string, length) {
|
|
var source = '';
|
|
for (var i = 0; i < count; ++i) {
|
|
var len = length ? HEAP32[(((length)+(i*4))>>2)] : -1;
|
|
source += UTF8ToString(HEAP32[(((string)+(i*4))>>2)], len < 0 ? undefined : len);
|
|
}
|
|
return source;
|
|
},createContext:function(/** @type {HTMLCanvasElement} */ canvas, webGLContextAttributes) {
|
|
|
|
// BUG: Workaround Safari WebGL issue: After successfully acquiring WebGL context on a canvas,
|
|
// calling .getContext() will always return that context independent of which 'webgl' or 'webgl2'
|
|
// context version was passed. See https://bugs.webkit.org/show_bug.cgi?id=222758 and
|
|
// https://github.com/emscripten-core/emscripten/issues/13295.
|
|
// TODO: Once the bug is fixed and shipped in Safari, adjust the Safari version field in above check.
|
|
if (!canvas.getContextSafariWebGL2Fixed) {
|
|
canvas.getContextSafariWebGL2Fixed = canvas.getContext;
|
|
/** @type {function(this:HTMLCanvasElement, string, (Object|null)=): (Object|null)} */
|
|
function fixedGetContext(ver, attrs) {
|
|
var gl = canvas.getContextSafariWebGL2Fixed(ver, attrs);
|
|
return ((ver == 'webgl') == (gl instanceof WebGLRenderingContext)) ? gl : null;
|
|
}
|
|
canvas.getContext = fixedGetContext;
|
|
}
|
|
|
|
var ctx =
|
|
(webGLContextAttributes.majorVersion > 1)
|
|
?
|
|
canvas.getContext("webgl2", webGLContextAttributes)
|
|
:
|
|
(canvas.getContext("webgl", webGLContextAttributes)
|
|
// https://caniuse.com/#feat=webgl
|
|
);
|
|
|
|
if (!ctx) return 0;
|
|
|
|
var handle = GL.registerContext(ctx, webGLContextAttributes);
|
|
|
|
return handle;
|
|
},registerContext:function(ctx, webGLContextAttributes) {
|
|
// without pthreads a context is just an integer ID
|
|
var handle = GL.getNewId(GL.contexts);
|
|
|
|
var context = {
|
|
handle: handle,
|
|
attributes: webGLContextAttributes,
|
|
version: webGLContextAttributes.majorVersion,
|
|
GLctx: ctx
|
|
};
|
|
|
|
// Store the created context object so that we can access the context given a canvas without having to pass the parameters again.
|
|
if (ctx.canvas) ctx.canvas.GLctxObject = context;
|
|
GL.contexts[handle] = context;
|
|
if (typeof webGLContextAttributes.enableExtensionsByDefault == 'undefined' || webGLContextAttributes.enableExtensionsByDefault) {
|
|
GL.initExtensions(context);
|
|
}
|
|
|
|
return handle;
|
|
},makeContextCurrent:function(contextHandle) {
|
|
|
|
GL.currentContext = GL.contexts[contextHandle]; // Active Emscripten GL layer context object.
|
|
Module.ctx = GLctx = GL.currentContext && GL.currentContext.GLctx; // Active WebGL context object.
|
|
return !(contextHandle && !GLctx);
|
|
},getContext:function(contextHandle) {
|
|
return GL.contexts[contextHandle];
|
|
},deleteContext:function(contextHandle) {
|
|
if (GL.currentContext === GL.contexts[contextHandle]) GL.currentContext = null;
|
|
if (typeof JSEvents == 'object') JSEvents.removeAllHandlersOnTarget(GL.contexts[contextHandle].GLctx.canvas); // Release all JS event handlers on the DOM element that the GL context is associated with since the context is now deleted.
|
|
if (GL.contexts[contextHandle] && GL.contexts[contextHandle].GLctx.canvas) GL.contexts[contextHandle].GLctx.canvas.GLctxObject = undefined; // Make sure the canvas object no longer refers to the context object so there are no GC surprises.
|
|
GL.contexts[contextHandle] = null;
|
|
},initExtensions:function(context) {
|
|
// If this function is called without a specific context object, init the extensions of the currently active context.
|
|
if (!context) context = GL.currentContext;
|
|
|
|
if (context.initExtensionsDone) return;
|
|
context.initExtensionsDone = true;
|
|
|
|
var GLctx = context.GLctx;
|
|
|
|
// Detect the presence of a few extensions manually, this GL interop layer itself will need to know if they exist.
|
|
|
|
// Extensions that are only available in WebGL 1 (the calls will be no-ops if called on a WebGL 2 context active)
|
|
__webgl_enable_ANGLE_instanced_arrays(GLctx);
|
|
__webgl_enable_OES_vertex_array_object(GLctx);
|
|
__webgl_enable_WEBGL_draw_buffers(GLctx);
|
|
// Extensions that are available from WebGL >= 2 (no-op if called on a WebGL 1 context active)
|
|
__webgl_enable_WEBGL_draw_instanced_base_vertex_base_instance(GLctx);
|
|
__webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance(GLctx);
|
|
|
|
// On WebGL 2, EXT_disjoint_timer_query is replaced with an alternative
|
|
// that's based on core APIs, and exposes only the queryCounterEXT()
|
|
// entrypoint.
|
|
if (context.version >= 2) {
|
|
GLctx.disjointTimerQueryExt = GLctx.getExtension("EXT_disjoint_timer_query_webgl2");
|
|
}
|
|
|
|
// However, Firefox exposes the WebGL 1 version on WebGL 2 as well and
|
|
// thus we look for the WebGL 1 version again if the WebGL 2 version
|
|
// isn't present. https://bugzilla.mozilla.org/show_bug.cgi?id=1328882
|
|
if (context.version < 2 || !GLctx.disjointTimerQueryExt)
|
|
{
|
|
GLctx.disjointTimerQueryExt = GLctx.getExtension("EXT_disjoint_timer_query");
|
|
}
|
|
|
|
__webgl_enable_WEBGL_multi_draw(GLctx);
|
|
|
|
// .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
|
|
var exts = GLctx.getSupportedExtensions() || [];
|
|
exts.forEach(function(ext) {
|
|
// WEBGL_lose_context, WEBGL_debug_renderer_info and WEBGL_debug_shaders are not enabled by default.
|
|
if (!ext.includes('lose_context') && !ext.includes('debug')) {
|
|
// Call .getExtension() to enable that extension permanently.
|
|
GLctx.getExtension(ext);
|
|
}
|
|
});
|
|
}};
|
|
function _emscripten_glActiveTexture(x0) { GLctx['activeTexture'](x0) }
|
|
|
|
function _emscripten_glAttachShader(program, shader) {
|
|
GLctx.attachShader(GL.programs[program], GL.shaders[shader]);
|
|
}
|
|
|
|
function _emscripten_glBindAttribLocation(program, index, name) {
|
|
GLctx.bindAttribLocation(GL.programs[program], index, UTF8ToString(name));
|
|
}
|
|
|
|
function _emscripten_glBindBuffer(target, buffer) {
|
|
|
|
if (target == 0x88EB /*GL_PIXEL_PACK_BUFFER*/) {
|
|
// In WebGL 2 glReadPixels entry point, we need to use a different WebGL 2 API function call when a buffer is bound to
|
|
// GL_PIXEL_PACK_BUFFER_BINDING point, so must keep track whether that binding point is non-null to know what is
|
|
// the proper API function to call.
|
|
GLctx.currentPixelPackBufferBinding = buffer;
|
|
} else if (target == 0x88EC /*GL_PIXEL_UNPACK_BUFFER*/) {
|
|
// In WebGL 2 gl(Compressed)Tex(Sub)Image[23]D entry points, we need to
|
|
// use a different WebGL 2 API function call when a buffer is bound to
|
|
// GL_PIXEL_UNPACK_BUFFER_BINDING point, so must keep track whether that
|
|
// binding point is non-null to know what is the proper API function to
|
|
// call.
|
|
GLctx.currentPixelUnpackBufferBinding = buffer;
|
|
}
|
|
GLctx.bindBuffer(target, GL.buffers[buffer]);
|
|
}
|
|
|
|
function _emscripten_glBindFramebuffer(target, framebuffer) {
|
|
|
|
GLctx.bindFramebuffer(target, GL.framebuffers[framebuffer]);
|
|
|
|
}
|
|
|
|
function _emscripten_glBindRenderbuffer(target, renderbuffer) {
|
|
GLctx.bindRenderbuffer(target, GL.renderbuffers[renderbuffer]);
|
|
}
|
|
|
|
function _emscripten_glBindSampler(unit, sampler) {
|
|
GLctx['bindSampler'](unit, GL.samplers[sampler]);
|
|
}
|
|
|
|
function _emscripten_glBindTexture(target, texture) {
|
|
GLctx.bindTexture(target, GL.textures[texture]);
|
|
}
|
|
|
|
function _emscripten_glBindVertexArray(vao) {
|
|
GLctx['bindVertexArray'](GL.vaos[vao]);
|
|
}
|
|
|
|
function _emscripten_glBindVertexArrayOES(vao) {
|
|
GLctx['bindVertexArray'](GL.vaos[vao]);
|
|
}
|
|
|
|
function _emscripten_glBlendColor(x0, x1, x2, x3) { GLctx['blendColor'](x0, x1, x2, x3) }
|
|
|
|
function _emscripten_glBlendEquation(x0) { GLctx['blendEquation'](x0) }
|
|
|
|
function _emscripten_glBlendFunc(x0, x1) { GLctx['blendFunc'](x0, x1) }
|
|
|
|
function _emscripten_glBlitFramebuffer(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) { GLctx['blitFramebuffer'](x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) }
|
|
|
|
function _emscripten_glBufferData(target, size, data, usage) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
// If size is zero, WebGL would interpret uploading the whole input arraybuffer (starting from given offset), which would
|
|
// not make sense in WebAssembly, so avoid uploading if size is zero. However we must still call bufferData to establish a
|
|
// backing storage of zero bytes.
|
|
if (data && size) {
|
|
GLctx.bufferData(target, HEAPU8, usage, data, size);
|
|
} else {
|
|
GLctx.bufferData(target, size, usage);
|
|
}
|
|
} else {
|
|
// N.b. here first form specifies a heap subarray, second form an integer size, so the ?: code here is polymorphic. It is advised to avoid
|
|
// randomly mixing both uses in calling code, to avoid any potential JS engine JIT issues.
|
|
GLctx.bufferData(target, data ? HEAPU8.subarray(data, data+size) : size, usage);
|
|
}
|
|
}
|
|
|
|
function _emscripten_glBufferSubData(target, offset, size, data) {
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
size && GLctx.bufferSubData(target, offset, HEAPU8, data, size);
|
|
return;
|
|
}
|
|
GLctx.bufferSubData(target, offset, HEAPU8.subarray(data, data+size));
|
|
}
|
|
|
|
function _emscripten_glCheckFramebufferStatus(x0) { return GLctx['checkFramebufferStatus'](x0) }
|
|
|
|
function _emscripten_glClear(x0) { GLctx['clear'](x0) }
|
|
|
|
function _emscripten_glClearColor(x0, x1, x2, x3) { GLctx['clearColor'](x0, x1, x2, x3) }
|
|
|
|
function _emscripten_glClearStencil(x0) { GLctx['clearStencil'](x0) }
|
|
|
|
function convertI32PairToI53(lo, hi) {
|
|
// This function should not be getting called with too large unsigned numbers
|
|
// in high part (if hi >= 0x7FFFFFFFF, one should have been calling
|
|
// convertU32PairToI53())
|
|
assert(hi === (hi|0));
|
|
return (lo >>> 0) + hi * 4294967296;
|
|
}
|
|
function _emscripten_glClientWaitSync(sync, flags, timeoutLo, timeoutHi) {
|
|
// WebGL2 vs GLES3 differences: in GLES3, the timeout parameter is a uint64, where 0xFFFFFFFFFFFFFFFFULL means GL_TIMEOUT_IGNORED.
|
|
// In JS, there's no 64-bit value types, so instead timeout is taken to be signed, and GL_TIMEOUT_IGNORED is given value -1.
|
|
// Inherently the value accepted in the timeout is lossy, and can't take in arbitrary u64 bit pattern (but most likely doesn't matter)
|
|
// See https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.15
|
|
return GLctx.clientWaitSync(GL.syncs[sync], flags, convertI32PairToI53(timeoutLo, timeoutHi));
|
|
}
|
|
|
|
function _emscripten_glColorMask(red, green, blue, alpha) {
|
|
GLctx.colorMask(!!red, !!green, !!blue, !!alpha);
|
|
}
|
|
|
|
function _emscripten_glCompileShader(shader) {
|
|
GLctx.compileShader(GL.shaders[shader]);
|
|
}
|
|
|
|
function _emscripten_glCompressedTexImage2D(target, level, internalFormat, width, height, border, imageSize, data) {
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
if (GLctx.currentPixelUnpackBufferBinding || !imageSize) {
|
|
GLctx['compressedTexImage2D'](target, level, internalFormat, width, height, border, imageSize, data);
|
|
} else {
|
|
GLctx['compressedTexImage2D'](target, level, internalFormat, width, height, border, HEAPU8, data, imageSize);
|
|
}
|
|
return;
|
|
}
|
|
GLctx['compressedTexImage2D'](target, level, internalFormat, width, height, border, data ? HEAPU8.subarray((data), (data+imageSize)) : null);
|
|
}
|
|
|
|
function _emscripten_glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) {
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
if (GLctx.currentPixelUnpackBufferBinding || !imageSize) {
|
|
GLctx['compressedTexSubImage2D'](target, level, xoffset, yoffset, width, height, format, imageSize, data);
|
|
} else {
|
|
GLctx['compressedTexSubImage2D'](target, level, xoffset, yoffset, width, height, format, HEAPU8, data, imageSize);
|
|
}
|
|
return;
|
|
}
|
|
GLctx['compressedTexSubImage2D'](target, level, xoffset, yoffset, width, height, format, data ? HEAPU8.subarray((data), (data+imageSize)) : null);
|
|
}
|
|
|
|
function _emscripten_glCopyBufferSubData(x0, x1, x2, x3, x4) { GLctx['copyBufferSubData'](x0, x1, x2, x3, x4) }
|
|
|
|
function _emscripten_glCopyTexSubImage2D(x0, x1, x2, x3, x4, x5, x6, x7) { GLctx['copyTexSubImage2D'](x0, x1, x2, x3, x4, x5, x6, x7) }
|
|
|
|
function _emscripten_glCreateProgram() {
|
|
var id = GL.getNewId(GL.programs);
|
|
var program = GLctx.createProgram();
|
|
// Store additional information needed for each shader program:
|
|
program.name = id;
|
|
// Lazy cache results of glGetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH/GL_ACTIVE_ATTRIBUTE_MAX_LENGTH/GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH)
|
|
program.maxUniformLength = program.maxAttributeLength = program.maxUniformBlockNameLength = 0;
|
|
program.uniformIdCounter = 1;
|
|
GL.programs[id] = program;
|
|
return id;
|
|
}
|
|
|
|
function _emscripten_glCreateShader(shaderType) {
|
|
var id = GL.getNewId(GL.shaders);
|
|
GL.shaders[id] = GLctx.createShader(shaderType);
|
|
|
|
return id;
|
|
}
|
|
|
|
function _emscripten_glCullFace(x0) { GLctx['cullFace'](x0) }
|
|
|
|
function _emscripten_glDeleteBuffers(n, buffers) {
|
|
for (var i = 0; i < n; i++) {
|
|
var id = HEAP32[(((buffers)+(i*4))>>2)];
|
|
var buffer = GL.buffers[id];
|
|
|
|
// From spec: "glDeleteBuffers silently ignores 0's and names that do not
|
|
// correspond to existing buffer objects."
|
|
if (!buffer) continue;
|
|
|
|
GLctx.deleteBuffer(buffer);
|
|
buffer.name = 0;
|
|
GL.buffers[id] = null;
|
|
|
|
if (id == GLctx.currentPixelPackBufferBinding) GLctx.currentPixelPackBufferBinding = 0;
|
|
if (id == GLctx.currentPixelUnpackBufferBinding) GLctx.currentPixelUnpackBufferBinding = 0;
|
|
}
|
|
}
|
|
|
|
function _emscripten_glDeleteFramebuffers(n, framebuffers) {
|
|
for (var i = 0; i < n; ++i) {
|
|
var id = HEAP32[(((framebuffers)+(i*4))>>2)];
|
|
var framebuffer = GL.framebuffers[id];
|
|
if (!framebuffer) continue; // GL spec: "glDeleteFramebuffers silently ignores 0s and names that do not correspond to existing framebuffer objects".
|
|
GLctx.deleteFramebuffer(framebuffer);
|
|
framebuffer.name = 0;
|
|
GL.framebuffers[id] = null;
|
|
}
|
|
}
|
|
|
|
function _emscripten_glDeleteProgram(id) {
|
|
if (!id) return;
|
|
var program = GL.programs[id];
|
|
if (!program) { // glDeleteProgram actually signals an error when deleting a nonexisting object, unlike some other GL delete functions.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
GLctx.deleteProgram(program);
|
|
program.name = 0;
|
|
GL.programs[id] = null;
|
|
}
|
|
|
|
function _emscripten_glDeleteRenderbuffers(n, renderbuffers) {
|
|
for (var i = 0; i < n; i++) {
|
|
var id = HEAP32[(((renderbuffers)+(i*4))>>2)];
|
|
var renderbuffer = GL.renderbuffers[id];
|
|
if (!renderbuffer) continue; // GL spec: "glDeleteRenderbuffers silently ignores 0s and names that do not correspond to existing renderbuffer objects".
|
|
GLctx.deleteRenderbuffer(renderbuffer);
|
|
renderbuffer.name = 0;
|
|
GL.renderbuffers[id] = null;
|
|
}
|
|
}
|
|
|
|
function _emscripten_glDeleteSamplers(n, samplers) {
|
|
for (var i = 0; i < n; i++) {
|
|
var id = HEAP32[(((samplers)+(i*4))>>2)];
|
|
var sampler = GL.samplers[id];
|
|
if (!sampler) continue;
|
|
GLctx['deleteSampler'](sampler);
|
|
sampler.name = 0;
|
|
GL.samplers[id] = null;
|
|
}
|
|
}
|
|
|
|
function _emscripten_glDeleteShader(id) {
|
|
if (!id) return;
|
|
var shader = GL.shaders[id];
|
|
if (!shader) { // glDeleteShader actually signals an error when deleting a nonexisting object, unlike some other GL delete functions.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
GLctx.deleteShader(shader);
|
|
GL.shaders[id] = null;
|
|
}
|
|
|
|
function _emscripten_glDeleteSync(id) {
|
|
if (!id) return;
|
|
var sync = GL.syncs[id];
|
|
if (!sync) { // glDeleteSync signals an error when deleting a nonexisting object, unlike some other GL delete functions.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
GLctx.deleteSync(sync);
|
|
sync.name = 0;
|
|
GL.syncs[id] = null;
|
|
}
|
|
|
|
function _emscripten_glDeleteTextures(n, textures) {
|
|
for (var i = 0; i < n; i++) {
|
|
var id = HEAP32[(((textures)+(i*4))>>2)];
|
|
var texture = GL.textures[id];
|
|
if (!texture) continue; // GL spec: "glDeleteTextures silently ignores 0s and names that do not correspond to existing textures".
|
|
GLctx.deleteTexture(texture);
|
|
texture.name = 0;
|
|
GL.textures[id] = null;
|
|
}
|
|
}
|
|
|
|
function _emscripten_glDeleteVertexArrays(n, vaos) {
|
|
for (var i = 0; i < n; i++) {
|
|
var id = HEAP32[(((vaos)+(i*4))>>2)];
|
|
GLctx['deleteVertexArray'](GL.vaos[id]);
|
|
GL.vaos[id] = null;
|
|
}
|
|
}
|
|
|
|
function _emscripten_glDeleteVertexArraysOES(n, vaos) {
|
|
for (var i = 0; i < n; i++) {
|
|
var id = HEAP32[(((vaos)+(i*4))>>2)];
|
|
GLctx['deleteVertexArray'](GL.vaos[id]);
|
|
GL.vaos[id] = null;
|
|
}
|
|
}
|
|
|
|
function _emscripten_glDepthMask(flag) {
|
|
GLctx.depthMask(!!flag);
|
|
}
|
|
|
|
function _emscripten_glDisable(x0) { GLctx['disable'](x0) }
|
|
|
|
function _emscripten_glDisableVertexAttribArray(index) {
|
|
GLctx.disableVertexAttribArray(index);
|
|
}
|
|
|
|
function _emscripten_glDrawArrays(mode, first, count) {
|
|
|
|
GLctx.drawArrays(mode, first, count);
|
|
|
|
}
|
|
|
|
function _emscripten_glDrawArraysInstanced(mode, first, count, primcount) {
|
|
GLctx['drawArraysInstanced'](mode, first, count, primcount);
|
|
}
|
|
|
|
function _emscripten_glDrawArraysInstancedBaseInstanceWEBGL(mode, first, count, instanceCount, baseInstance) {
|
|
GLctx.dibvbi['drawArraysInstancedBaseInstanceWEBGL'](mode, first, count, instanceCount, baseInstance);
|
|
}
|
|
|
|
var tempFixedLengthArray = [];
|
|
function _emscripten_glDrawBuffers(n, bufs) {
|
|
|
|
var bufArray = tempFixedLengthArray[n];
|
|
for (var i = 0; i < n; i++) {
|
|
bufArray[i] = HEAP32[(((bufs)+(i*4))>>2)];
|
|
}
|
|
|
|
GLctx['drawBuffers'](bufArray);
|
|
}
|
|
|
|
function _emscripten_glDrawElements(mode, count, type, indices) {
|
|
|
|
GLctx.drawElements(mode, count, type, indices);
|
|
|
|
}
|
|
|
|
function _emscripten_glDrawElementsInstanced(mode, count, type, indices, primcount) {
|
|
GLctx['drawElementsInstanced'](mode, count, type, indices, primcount);
|
|
}
|
|
|
|
function _emscripten_glDrawElementsInstancedBaseVertexBaseInstanceWEBGL(mode, count, type, offset, instanceCount, baseVertex, baseinstance) {
|
|
GLctx.dibvbi['drawElementsInstancedBaseVertexBaseInstanceWEBGL'](mode, count, type, offset, instanceCount, baseVertex, baseinstance);
|
|
}
|
|
|
|
function _glDrawElements(mode, count, type, indices) {
|
|
|
|
GLctx.drawElements(mode, count, type, indices);
|
|
|
|
}
|
|
function _emscripten_glDrawRangeElements(mode, start, end, count, type, indices) {
|
|
// TODO: This should be a trivial pass-though function registered at the bottom of this page as
|
|
// glFuncs[6][1] += ' drawRangeElements';
|
|
// but due to https://bugzilla.mozilla.org/show_bug.cgi?id=1202427,
|
|
// we work around by ignoring the range.
|
|
_glDrawElements(mode, count, type, indices);
|
|
}
|
|
|
|
function _emscripten_glEnable(x0) { GLctx['enable'](x0) }
|
|
|
|
function _emscripten_glEnableVertexAttribArray(index) {
|
|
GLctx.enableVertexAttribArray(index);
|
|
}
|
|
|
|
function _emscripten_glFenceSync(condition, flags) {
|
|
var sync = GLctx.fenceSync(condition, flags);
|
|
if (sync) {
|
|
var id = GL.getNewId(GL.syncs);
|
|
sync.name = id;
|
|
GL.syncs[id] = sync;
|
|
return id;
|
|
} else {
|
|
return 0; // Failed to create a sync object
|
|
}
|
|
}
|
|
|
|
function _emscripten_glFinish() { GLctx['finish']() }
|
|
|
|
function _emscripten_glFlush() { GLctx['flush']() }
|
|
|
|
function _emscripten_glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) {
|
|
GLctx.framebufferRenderbuffer(target, attachment, renderbuffertarget,
|
|
GL.renderbuffers[renderbuffer]);
|
|
}
|
|
|
|
function _emscripten_glFramebufferTexture2D(target, attachment, textarget, texture, level) {
|
|
GLctx.framebufferTexture2D(target, attachment, textarget,
|
|
GL.textures[texture], level);
|
|
}
|
|
|
|
function _emscripten_glFrontFace(x0) { GLctx['frontFace'](x0) }
|
|
|
|
function __glGenObject(n, buffers, createFunction, objectTable
|
|
) {
|
|
for (var i = 0; i < n; i++) {
|
|
var buffer = GLctx[createFunction]();
|
|
var id = buffer && GL.getNewId(objectTable);
|
|
if (buffer) {
|
|
buffer.name = id;
|
|
objectTable[id] = buffer;
|
|
} else {
|
|
GL.recordError(0x502 /* GL_INVALID_OPERATION */);
|
|
}
|
|
HEAP32[(((buffers)+(i*4))>>2)] = id;
|
|
}
|
|
}
|
|
function _emscripten_glGenBuffers(n, buffers) {
|
|
__glGenObject(n, buffers, 'createBuffer', GL.buffers
|
|
);
|
|
}
|
|
|
|
function _emscripten_glGenFramebuffers(n, ids) {
|
|
__glGenObject(n, ids, 'createFramebuffer', GL.framebuffers
|
|
);
|
|
}
|
|
|
|
function _emscripten_glGenRenderbuffers(n, renderbuffers) {
|
|
__glGenObject(n, renderbuffers, 'createRenderbuffer', GL.renderbuffers
|
|
);
|
|
}
|
|
|
|
function _emscripten_glGenSamplers(n, samplers) {
|
|
__glGenObject(n, samplers, 'createSampler', GL.samplers
|
|
);
|
|
}
|
|
|
|
function _emscripten_glGenTextures(n, textures) {
|
|
__glGenObject(n, textures, 'createTexture', GL.textures
|
|
);
|
|
}
|
|
|
|
function _emscripten_glGenVertexArrays(n, arrays) {
|
|
__glGenObject(n, arrays, 'createVertexArray', GL.vaos
|
|
);
|
|
}
|
|
|
|
function _emscripten_glGenVertexArraysOES(n, arrays) {
|
|
__glGenObject(n, arrays, 'createVertexArray', GL.vaos
|
|
);
|
|
}
|
|
|
|
function _emscripten_glGenerateMipmap(x0) { GLctx['generateMipmap'](x0) }
|
|
|
|
function _emscripten_glGetBufferParameteriv(target, value, data) {
|
|
if (!data) {
|
|
// GLES2 specification does not specify how to behave if data is a null pointer. Since calling this function does not make sense
|
|
// if data == null, issue a GL error to notify user about it.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
HEAP32[((data)>>2)] = GLctx.getBufferParameter(target, value);
|
|
}
|
|
|
|
function _emscripten_glGetError() {
|
|
var error = GLctx.getError() || GL.lastError;
|
|
GL.lastError = 0/*GL_NO_ERROR*/;
|
|
return error;
|
|
}
|
|
|
|
function readI53FromI64(ptr) {
|
|
return HEAPU32[ptr>>2] + HEAP32[ptr+4>>2] * 4294967296;
|
|
}
|
|
|
|
function readI53FromU64(ptr) {
|
|
return HEAPU32[ptr>>2] + HEAPU32[ptr+4>>2] * 4294967296;
|
|
}
|
|
function writeI53ToI64(ptr, num) {
|
|
HEAPU32[ptr>>2] = num;
|
|
HEAPU32[ptr+4>>2] = (num - HEAPU32[ptr>>2])/4294967296;
|
|
var deserialized = (num >= 0) ? readI53FromU64(ptr) : readI53FromI64(ptr);
|
|
if (deserialized != num) warnOnce('writeI53ToI64() out of range: serialized JS Number ' + num + ' to Wasm heap as bytes lo=0x' + HEAPU32[ptr>>2].toString(16) + ', hi=0x' + HEAPU32[ptr+4>>2].toString(16) + ', which deserializes back to ' + deserialized + ' instead!');
|
|
}
|
|
function emscriptenWebGLGet(name_, p, type) {
|
|
// Guard against user passing a null pointer.
|
|
// Note that GLES2 spec does not say anything about how passing a null pointer should be treated.
|
|
// Testing on desktop core GL 3, the application crashes on glGetIntegerv to a null pointer, but
|
|
// better to report an error instead of doing anything random.
|
|
if (!p) {
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
var ret = undefined;
|
|
switch (name_) { // Handle a few trivial GLES values
|
|
case 0x8DFA: // GL_SHADER_COMPILER
|
|
ret = 1;
|
|
break;
|
|
case 0x8DF8: // GL_SHADER_BINARY_FORMATS
|
|
if (type != 0 && type != 1) {
|
|
GL.recordError(0x500); // GL_INVALID_ENUM
|
|
}
|
|
return; // Do not write anything to the out pointer, since no binary formats are supported.
|
|
case 0x87FE: // GL_NUM_PROGRAM_BINARY_FORMATS
|
|
case 0x8DF9: // GL_NUM_SHADER_BINARY_FORMATS
|
|
ret = 0;
|
|
break;
|
|
case 0x86A2: // GL_NUM_COMPRESSED_TEXTURE_FORMATS
|
|
// WebGL doesn't have GL_NUM_COMPRESSED_TEXTURE_FORMATS (it's obsolete since GL_COMPRESSED_TEXTURE_FORMATS returns a JS array that can be queried for length),
|
|
// so implement it ourselves to allow C++ GLES2 code get the length.
|
|
var formats = GLctx.getParameter(0x86A3 /*GL_COMPRESSED_TEXTURE_FORMATS*/);
|
|
ret = formats ? formats.length : 0;
|
|
break;
|
|
|
|
case 0x821D: // GL_NUM_EXTENSIONS
|
|
if (GL.currentContext.version < 2) {
|
|
GL.recordError(0x502 /* GL_INVALID_OPERATION */); // Calling GLES3/WebGL2 function with a GLES2/WebGL1 context
|
|
return;
|
|
}
|
|
// .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
|
|
var exts = GLctx.getSupportedExtensions() || [];
|
|
ret = 2 * exts.length; // each extension is duplicated, first in unprefixed WebGL form, and then a second time with "GL_" prefix.
|
|
break;
|
|
case 0x821B: // GL_MAJOR_VERSION
|
|
case 0x821C: // GL_MINOR_VERSION
|
|
if (GL.currentContext.version < 2) {
|
|
GL.recordError(0x500); // GL_INVALID_ENUM
|
|
return;
|
|
}
|
|
ret = name_ == 0x821B ? 3 : 0; // return version 3.0
|
|
break;
|
|
}
|
|
|
|
if (ret === undefined) {
|
|
var result = GLctx.getParameter(name_);
|
|
switch (typeof result) {
|
|
case "number":
|
|
ret = result;
|
|
break;
|
|
case "boolean":
|
|
ret = result ? 1 : 0;
|
|
break;
|
|
case "string":
|
|
GL.recordError(0x500); // GL_INVALID_ENUM
|
|
return;
|
|
case "object":
|
|
if (result === null) {
|
|
// null is a valid result for some (e.g., which buffer is bound - perhaps nothing is bound), but otherwise
|
|
// can mean an invalid name_, which we need to report as an error
|
|
switch (name_) {
|
|
case 0x8894: // ARRAY_BUFFER_BINDING
|
|
case 0x8B8D: // CURRENT_PROGRAM
|
|
case 0x8895: // ELEMENT_ARRAY_BUFFER_BINDING
|
|
case 0x8CA6: // FRAMEBUFFER_BINDING or DRAW_FRAMEBUFFER_BINDING
|
|
case 0x8CA7: // RENDERBUFFER_BINDING
|
|
case 0x8069: // TEXTURE_BINDING_2D
|
|
case 0x85B5: // WebGL 2 GL_VERTEX_ARRAY_BINDING, or WebGL 1 extension OES_vertex_array_object GL_VERTEX_ARRAY_BINDING_OES
|
|
case 0x8F36: // COPY_READ_BUFFER_BINDING or COPY_READ_BUFFER
|
|
case 0x8F37: // COPY_WRITE_BUFFER_BINDING or COPY_WRITE_BUFFER
|
|
case 0x88ED: // PIXEL_PACK_BUFFER_BINDING
|
|
case 0x88EF: // PIXEL_UNPACK_BUFFER_BINDING
|
|
case 0x8CAA: // READ_FRAMEBUFFER_BINDING
|
|
case 0x8919: // SAMPLER_BINDING
|
|
case 0x8C1D: // TEXTURE_BINDING_2D_ARRAY
|
|
case 0x806A: // TEXTURE_BINDING_3D
|
|
case 0x8E25: // TRANSFORM_FEEDBACK_BINDING
|
|
case 0x8C8F: // TRANSFORM_FEEDBACK_BUFFER_BINDING
|
|
case 0x8A28: // UNIFORM_BUFFER_BINDING
|
|
case 0x8514: { // TEXTURE_BINDING_CUBE_MAP
|
|
ret = 0;
|
|
break;
|
|
}
|
|
default: {
|
|
GL.recordError(0x500); // GL_INVALID_ENUM
|
|
return;
|
|
}
|
|
}
|
|
} else if (result instanceof Float32Array ||
|
|
result instanceof Uint32Array ||
|
|
result instanceof Int32Array ||
|
|
result instanceof Array) {
|
|
for (var i = 0; i < result.length; ++i) {
|
|
switch (type) {
|
|
case 0: HEAP32[(((p)+(i*4))>>2)] = result[i]; break;
|
|
case 2: HEAPF32[(((p)+(i*4))>>2)] = result[i]; break;
|
|
case 4: HEAP8[(((p)+(i))>>0)] = result[i] ? 1 : 0; break;
|
|
}
|
|
}
|
|
return;
|
|
} else {
|
|
try {
|
|
ret = result.name | 0;
|
|
} catch(e) {
|
|
GL.recordError(0x500); // GL_INVALID_ENUM
|
|
err('GL_INVALID_ENUM in glGet' + type + 'v: Unknown object returned from WebGL getParameter(' + name_ + ')! (error: ' + e + ')');
|
|
return;
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
GL.recordError(0x500); // GL_INVALID_ENUM
|
|
err('GL_INVALID_ENUM in glGet' + type + 'v: Native code calling glGet' + type + 'v(' + name_ + ') and it returns ' + result + ' of type ' + typeof(result) + '!');
|
|
return;
|
|
}
|
|
}
|
|
|
|
switch (type) {
|
|
case 1: writeI53ToI64(p, ret); break;
|
|
case 0: HEAP32[((p)>>2)] = ret; break;
|
|
case 2: HEAPF32[((p)>>2)] = ret; break;
|
|
case 4: HEAP8[((p)>>0)] = ret ? 1 : 0; break;
|
|
}
|
|
}
|
|
function _emscripten_glGetFloatv(name_, p) {
|
|
emscriptenWebGLGet(name_, p, 2);
|
|
}
|
|
|
|
function _emscripten_glGetFramebufferAttachmentParameteriv(target, attachment, pname, params) {
|
|
var result = GLctx.getFramebufferAttachmentParameter(target, attachment, pname);
|
|
if (result instanceof WebGLRenderbuffer ||
|
|
result instanceof WebGLTexture) {
|
|
result = result.name | 0;
|
|
}
|
|
HEAP32[((params)>>2)] = result;
|
|
}
|
|
|
|
function _emscripten_glGetIntegerv(name_, p) {
|
|
emscriptenWebGLGet(name_, p, 0);
|
|
}
|
|
|
|
function _emscripten_glGetProgramInfoLog(program, maxLength, length, infoLog) {
|
|
var log = GLctx.getProgramInfoLog(GL.programs[program]);
|
|
if (log === null) log = '(unknown error)';
|
|
var numBytesWrittenExclNull = (maxLength > 0 && infoLog) ? stringToUTF8(log, infoLog, maxLength) : 0;
|
|
if (length) HEAP32[((length)>>2)] = numBytesWrittenExclNull;
|
|
}
|
|
|
|
function _emscripten_glGetProgramiv(program, pname, p) {
|
|
if (!p) {
|
|
// GLES2 specification does not specify how to behave if p is a null pointer. Since calling this function does not make sense
|
|
// if p == null, issue a GL error to notify user about it.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
|
|
if (program >= GL.counter) {
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
|
|
program = GL.programs[program];
|
|
|
|
if (pname == 0x8B84) { // GL_INFO_LOG_LENGTH
|
|
var log = GLctx.getProgramInfoLog(program);
|
|
if (log === null) log = '(unknown error)';
|
|
HEAP32[((p)>>2)] = log.length + 1;
|
|
} else if (pname == 0x8B87 /* GL_ACTIVE_UNIFORM_MAX_LENGTH */) {
|
|
if (!program.maxUniformLength) {
|
|
for (var i = 0; i < GLctx.getProgramParameter(program, 0x8B86/*GL_ACTIVE_UNIFORMS*/); ++i) {
|
|
program.maxUniformLength = Math.max(program.maxUniformLength, GLctx.getActiveUniform(program, i).name.length+1);
|
|
}
|
|
}
|
|
HEAP32[((p)>>2)] = program.maxUniformLength;
|
|
} else if (pname == 0x8B8A /* GL_ACTIVE_ATTRIBUTE_MAX_LENGTH */) {
|
|
if (!program.maxAttributeLength) {
|
|
for (var i = 0; i < GLctx.getProgramParameter(program, 0x8B89/*GL_ACTIVE_ATTRIBUTES*/); ++i) {
|
|
program.maxAttributeLength = Math.max(program.maxAttributeLength, GLctx.getActiveAttrib(program, i).name.length+1);
|
|
}
|
|
}
|
|
HEAP32[((p)>>2)] = program.maxAttributeLength;
|
|
} else if (pname == 0x8A35 /* GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH */) {
|
|
if (!program.maxUniformBlockNameLength) {
|
|
for (var i = 0; i < GLctx.getProgramParameter(program, 0x8A36/*GL_ACTIVE_UNIFORM_BLOCKS*/); ++i) {
|
|
program.maxUniformBlockNameLength = Math.max(program.maxUniformBlockNameLength, GLctx.getActiveUniformBlockName(program, i).length+1);
|
|
}
|
|
}
|
|
HEAP32[((p)>>2)] = program.maxUniformBlockNameLength;
|
|
} else {
|
|
HEAP32[((p)>>2)] = GLctx.getProgramParameter(program, pname);
|
|
}
|
|
}
|
|
|
|
function _emscripten_glGetRenderbufferParameteriv(target, pname, params) {
|
|
if (!params) {
|
|
// GLES2 specification does not specify how to behave if params is a null pointer. Since calling this function does not make sense
|
|
// if params == null, issue a GL error to notify user about it.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
HEAP32[((params)>>2)] = GLctx.getRenderbufferParameter(target, pname);
|
|
}
|
|
|
|
function _emscripten_glGetShaderInfoLog(shader, maxLength, length, infoLog) {
|
|
var log = GLctx.getShaderInfoLog(GL.shaders[shader]);
|
|
if (log === null) log = '(unknown error)';
|
|
var numBytesWrittenExclNull = (maxLength > 0 && infoLog) ? stringToUTF8(log, infoLog, maxLength) : 0;
|
|
if (length) HEAP32[((length)>>2)] = numBytesWrittenExclNull;
|
|
}
|
|
|
|
function _emscripten_glGetShaderPrecisionFormat(shaderType, precisionType, range, precision) {
|
|
var result = GLctx.getShaderPrecisionFormat(shaderType, precisionType);
|
|
HEAP32[((range)>>2)] = result.rangeMin;
|
|
HEAP32[(((range)+(4))>>2)] = result.rangeMax;
|
|
HEAP32[((precision)>>2)] = result.precision;
|
|
}
|
|
|
|
function _emscripten_glGetShaderiv(shader, pname, p) {
|
|
if (!p) {
|
|
// GLES2 specification does not specify how to behave if p is a null pointer. Since calling this function does not make sense
|
|
// if p == null, issue a GL error to notify user about it.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
return;
|
|
}
|
|
if (pname == 0x8B84) { // GL_INFO_LOG_LENGTH
|
|
var log = GLctx.getShaderInfoLog(GL.shaders[shader]);
|
|
if (log === null) log = '(unknown error)';
|
|
// The GLES2 specification says that if the shader has an empty info log,
|
|
// a value of 0 is returned. Otherwise the log has a null char appended.
|
|
// (An empty string is falsey, so we can just check that instead of
|
|
// looking at log.length.)
|
|
var logLength = log ? log.length + 1 : 0;
|
|
HEAP32[((p)>>2)] = logLength;
|
|
} else if (pname == 0x8B88) { // GL_SHADER_SOURCE_LENGTH
|
|
var source = GLctx.getShaderSource(GL.shaders[shader]);
|
|
// source may be a null, or the empty string, both of which are falsey
|
|
// values that we report a 0 length for.
|
|
var sourceLength = source ? source.length + 1 : 0;
|
|
HEAP32[((p)>>2)] = sourceLength;
|
|
} else {
|
|
HEAP32[((p)>>2)] = GLctx.getShaderParameter(GL.shaders[shader], pname);
|
|
}
|
|
}
|
|
|
|
function stringToNewUTF8(jsString) {
|
|
var length = lengthBytesUTF8(jsString)+1;
|
|
var cString = _malloc(length);
|
|
stringToUTF8(jsString, cString, length);
|
|
return cString;
|
|
}
|
|
function _emscripten_glGetString(name_) {
|
|
var ret = GL.stringCache[name_];
|
|
if (!ret) {
|
|
switch (name_) {
|
|
case 0x1F03 /* GL_EXTENSIONS */:
|
|
var exts = GLctx.getSupportedExtensions() || []; // .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
|
|
exts = exts.concat(exts.map(function(e) { return "GL_" + e; }));
|
|
ret = stringToNewUTF8(exts.join(' '));
|
|
break;
|
|
case 0x1F00 /* GL_VENDOR */:
|
|
case 0x1F01 /* GL_RENDERER */:
|
|
case 0x9245 /* UNMASKED_VENDOR_WEBGL */:
|
|
case 0x9246 /* UNMASKED_RENDERER_WEBGL */:
|
|
var s = GLctx.getParameter(name_);
|
|
if (!s) {
|
|
GL.recordError(0x500/*GL_INVALID_ENUM*/);
|
|
}
|
|
ret = s && stringToNewUTF8(s);
|
|
break;
|
|
|
|
case 0x1F02 /* GL_VERSION */:
|
|
var glVersion = GLctx.getParameter(0x1F02 /*GL_VERSION*/);
|
|
// return GLES version string corresponding to the version of the WebGL context
|
|
if (GL.currentContext.version >= 2) glVersion = 'OpenGL ES 3.0 (' + glVersion + ')';
|
|
else
|
|
{
|
|
glVersion = 'OpenGL ES 2.0 (' + glVersion + ')';
|
|
}
|
|
ret = stringToNewUTF8(glVersion);
|
|
break;
|
|
case 0x8B8C /* GL_SHADING_LANGUAGE_VERSION */:
|
|
var glslVersion = GLctx.getParameter(0x8B8C /*GL_SHADING_LANGUAGE_VERSION*/);
|
|
// extract the version number 'N.M' from the string 'WebGL GLSL ES N.M ...'
|
|
var ver_re = /^WebGL GLSL ES ([0-9]\.[0-9][0-9]?)(?:$| .*)/;
|
|
var ver_num = glslVersion.match(ver_re);
|
|
if (ver_num !== null) {
|
|
if (ver_num[1].length == 3) ver_num[1] = ver_num[1] + '0'; // ensure minor version has 2 digits
|
|
glslVersion = 'OpenGL ES GLSL ES ' + ver_num[1] + ' (' + glslVersion + ')';
|
|
}
|
|
ret = stringToNewUTF8(glslVersion);
|
|
break;
|
|
default:
|
|
GL.recordError(0x500/*GL_INVALID_ENUM*/);
|
|
// fall through
|
|
}
|
|
GL.stringCache[name_] = ret;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
function _emscripten_glGetStringi(name, index) {
|
|
if (GL.currentContext.version < 2) {
|
|
GL.recordError(0x502 /* GL_INVALID_OPERATION */); // Calling GLES3/WebGL2 function with a GLES2/WebGL1 context
|
|
return 0;
|
|
}
|
|
var stringiCache = GL.stringiCache[name];
|
|
if (stringiCache) {
|
|
if (index < 0 || index >= stringiCache.length) {
|
|
GL.recordError(0x501/*GL_INVALID_VALUE*/);
|
|
return 0;
|
|
}
|
|
return stringiCache[index];
|
|
}
|
|
switch (name) {
|
|
case 0x1F03 /* GL_EXTENSIONS */:
|
|
var exts = GLctx.getSupportedExtensions() || []; // .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
|
|
exts = exts.concat(exts.map(function(e) { return "GL_" + e; }));
|
|
exts = exts.map(function(e) { return stringToNewUTF8(e); });
|
|
|
|
stringiCache = GL.stringiCache[name] = exts;
|
|
if (index < 0 || index >= stringiCache.length) {
|
|
GL.recordError(0x501/*GL_INVALID_VALUE*/);
|
|
return 0;
|
|
}
|
|
return stringiCache[index];
|
|
default:
|
|
GL.recordError(0x500/*GL_INVALID_ENUM*/);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/** @suppress {checkTypes} */
|
|
function jstoi_q(str) {
|
|
return parseInt(str);
|
|
}
|
|
|
|
/** @noinline */
|
|
function webglGetLeftBracePos(name) {
|
|
return name.slice(-1) == ']' && name.lastIndexOf('[');
|
|
}
|
|
function webglPrepareUniformLocationsBeforeFirstUse(program) {
|
|
var uniformLocsById = program.uniformLocsById, // Maps GLuint -> WebGLUniformLocation
|
|
uniformSizeAndIdsByName = program.uniformSizeAndIdsByName, // Maps name -> [uniform array length, GLuint]
|
|
i, j;
|
|
|
|
// On the first time invocation of glGetUniformLocation on this shader program:
|
|
// initialize cache data structures and discover which uniforms are arrays.
|
|
if (!uniformLocsById) {
|
|
// maps GLint integer locations to WebGLUniformLocations
|
|
program.uniformLocsById = uniformLocsById = {};
|
|
// maps integer locations back to uniform name strings, so that we can lazily fetch uniform array locations
|
|
program.uniformArrayNamesById = {};
|
|
|
|
for (i = 0; i < GLctx.getProgramParameter(program, 0x8B86/*GL_ACTIVE_UNIFORMS*/); ++i) {
|
|
var u = GLctx.getActiveUniform(program, i);
|
|
var nm = u.name;
|
|
var sz = u.size;
|
|
var lb = webglGetLeftBracePos(nm);
|
|
var arrayName = lb > 0 ? nm.slice(0, lb) : nm;
|
|
|
|
// Assign a new location.
|
|
var id = program.uniformIdCounter;
|
|
program.uniformIdCounter += sz;
|
|
// Eagerly get the location of the uniformArray[0] base element.
|
|
// The remaining indices >0 will be left for lazy evaluation to
|
|
// improve performance. Those may never be needed to fetch, if the
|
|
// application fills arrays always in full starting from the first
|
|
// element of the array.
|
|
uniformSizeAndIdsByName[arrayName] = [sz, id];
|
|
|
|
// Store placeholder integers in place that highlight that these
|
|
// >0 index locations are array indices pending population.
|
|
for(j = 0; j < sz; ++j) {
|
|
uniformLocsById[id] = j;
|
|
program.uniformArrayNamesById[id++] = arrayName;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function _emscripten_glGetUniformLocation(program, name) {
|
|
|
|
name = UTF8ToString(name);
|
|
|
|
if (program = GL.programs[program]) {
|
|
webglPrepareUniformLocationsBeforeFirstUse(program);
|
|
var uniformLocsById = program.uniformLocsById; // Maps GLuint -> WebGLUniformLocation
|
|
var arrayIndex = 0;
|
|
var uniformBaseName = name;
|
|
|
|
// Invariant: when populating integer IDs for uniform locations, we must maintain the precondition that
|
|
// arrays reside in contiguous addresses, i.e. for a 'vec4 colors[10];', colors[4] must be at location colors[0]+4.
|
|
// However, user might call glGetUniformLocation(program, "colors") for an array, so we cannot discover based on the user
|
|
// input arguments whether the uniform we are dealing with is an array. The only way to discover which uniforms are arrays
|
|
// is to enumerate over all the active uniforms in the program.
|
|
var leftBrace = webglGetLeftBracePos(name);
|
|
|
|
// If user passed an array accessor "[index]", parse the array index off the accessor.
|
|
if (leftBrace > 0) {
|
|
arrayIndex = jstoi_q(name.slice(leftBrace + 1)) >>> 0; // "index]", coerce parseInt(']') with >>>0 to treat "foo[]" as "foo[0]" and foo[-1] as unsigned out-of-bounds.
|
|
uniformBaseName = name.slice(0, leftBrace);
|
|
}
|
|
|
|
// Have we cached the location of this uniform before?
|
|
var sizeAndId = program.uniformSizeAndIdsByName[uniformBaseName]; // A pair [array length, GLint of the uniform location]
|
|
|
|
// If an uniform with this name exists, and if its index is within the array limits (if it's even an array),
|
|
// query the WebGLlocation, or return an existing cached location.
|
|
if (sizeAndId && arrayIndex < sizeAndId[0]) {
|
|
arrayIndex += sizeAndId[1]; // Add the base location of the uniform to the array index offset.
|
|
if ((uniformLocsById[arrayIndex] = uniformLocsById[arrayIndex] || GLctx.getUniformLocation(program, name))) {
|
|
return arrayIndex;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
// N.b. we are currently unable to distinguish between GL program IDs that never existed vs GL program IDs that have been deleted,
|
|
// so report GL_INVALID_VALUE in both cases.
|
|
GL.recordError(0x501 /* GL_INVALID_VALUE */);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
function _emscripten_glInvalidateFramebuffer(target, numAttachments, attachments) {
|
|
var list = tempFixedLengthArray[numAttachments];
|
|
for (var i = 0; i < numAttachments; i++) {
|
|
list[i] = HEAP32[(((attachments)+(i*4))>>2)];
|
|
}
|
|
|
|
GLctx['invalidateFramebuffer'](target, list);
|
|
}
|
|
|
|
function _emscripten_glInvalidateSubFramebuffer(target, numAttachments, attachments, x, y, width, height) {
|
|
var list = tempFixedLengthArray[numAttachments];
|
|
for (var i = 0; i < numAttachments; i++) {
|
|
list[i] = HEAP32[(((attachments)+(i*4))>>2)];
|
|
}
|
|
|
|
GLctx['invalidateSubFramebuffer'](target, list, x, y, width, height);
|
|
}
|
|
|
|
function _emscripten_glIsSync(sync) {
|
|
return GLctx.isSync(GL.syncs[sync]);
|
|
}
|
|
|
|
function _emscripten_glIsTexture(id) {
|
|
var texture = GL.textures[id];
|
|
if (!texture) return 0;
|
|
return GLctx.isTexture(texture);
|
|
}
|
|
|
|
function _emscripten_glLineWidth(x0) { GLctx['lineWidth'](x0) }
|
|
|
|
function _emscripten_glLinkProgram(program) {
|
|
program = GL.programs[program];
|
|
GLctx.linkProgram(program);
|
|
// Invalidate earlier computed uniform->ID mappings, those have now become stale
|
|
program.uniformLocsById = 0; // Mark as null-like so that glGetUniformLocation() knows to populate this again.
|
|
program.uniformSizeAndIdsByName = {};
|
|
|
|
}
|
|
|
|
function _emscripten_glMultiDrawArraysInstancedBaseInstanceWEBGL(mode, firsts, counts, instanceCounts, baseInstances, drawCount) {
|
|
GLctx.mdibvbi['multiDrawArraysInstancedBaseInstanceWEBGL'](
|
|
mode,
|
|
HEAP32,
|
|
firsts >> 2,
|
|
HEAP32,
|
|
counts >> 2,
|
|
HEAP32,
|
|
instanceCounts >> 2,
|
|
HEAPU32,
|
|
baseInstances >> 2,
|
|
drawCount);
|
|
}
|
|
|
|
function _emscripten_glMultiDrawElementsInstancedBaseVertexBaseInstanceWEBGL(mode, counts, type, offsets, instanceCounts, baseVertices, baseInstances, drawCount) {
|
|
GLctx.mdibvbi['multiDrawElementsInstancedBaseVertexBaseInstanceWEBGL'](
|
|
mode,
|
|
HEAP32,
|
|
counts >> 2,
|
|
type,
|
|
HEAP32,
|
|
offsets >> 2,
|
|
HEAP32,
|
|
instanceCounts >> 2,
|
|
HEAP32,
|
|
baseVertices >> 2,
|
|
HEAPU32,
|
|
baseInstances >> 2,
|
|
drawCount);
|
|
}
|
|
|
|
function _emscripten_glPixelStorei(pname, param) {
|
|
if (pname == 0xCF5 /* GL_UNPACK_ALIGNMENT */) {
|
|
GL.unpackAlignment = param;
|
|
}
|
|
GLctx.pixelStorei(pname, param);
|
|
}
|
|
|
|
function _emscripten_glReadBuffer(x0) { GLctx['readBuffer'](x0) }
|
|
|
|
function computeUnpackAlignedImageSize(width, height, sizePerPixel, alignment) {
|
|
function roundedToNextMultipleOf(x, y) {
|
|
return (x + y - 1) & -y;
|
|
}
|
|
var plainRowSize = width * sizePerPixel;
|
|
var alignedRowSize = roundedToNextMultipleOf(plainRowSize, alignment);
|
|
return height * alignedRowSize;
|
|
}
|
|
|
|
function __colorChannelsInGlTextureFormat(format) {
|
|
// Micro-optimizations for size: map format to size by subtracting smallest enum value (0x1902) from all values first.
|
|
// Also omit the most common size value (1) from the list, which is assumed by formats not on the list.
|
|
var colorChannels = {
|
|
// 0x1902 /* GL_DEPTH_COMPONENT */ - 0x1902: 1,
|
|
// 0x1906 /* GL_ALPHA */ - 0x1902: 1,
|
|
5: 3,
|
|
6: 4,
|
|
// 0x1909 /* GL_LUMINANCE */ - 0x1902: 1,
|
|
8: 2,
|
|
29502: 3,
|
|
29504: 4,
|
|
// 0x1903 /* GL_RED */ - 0x1902: 1,
|
|
26917: 2,
|
|
26918: 2,
|
|
// 0x8D94 /* GL_RED_INTEGER */ - 0x1902: 1,
|
|
29846: 3,
|
|
29847: 4
|
|
};
|
|
return colorChannels[format - 0x1902]||1;
|
|
}
|
|
|
|
function heapObjectForWebGLType(type) {
|
|
// Micro-optimization for size: Subtract lowest GL enum number (0x1400/* GL_BYTE */) from type to compare
|
|
// smaller values for the heap, for shorter generated code size.
|
|
// Also the type HEAPU16 is not tested for explicitly, but any unrecognized type will return out HEAPU16.
|
|
// (since most types are HEAPU16)
|
|
type -= 0x1400;
|
|
if (type == 0) return HEAP8;
|
|
|
|
if (type == 1) return HEAPU8;
|
|
|
|
if (type == 2) return HEAP16;
|
|
|
|
if (type == 4) return HEAP32;
|
|
|
|
if (type == 6) return HEAPF32;
|
|
|
|
if (type == 5
|
|
|| type == 28922
|
|
|| type == 28520
|
|
|| type == 30779
|
|
|| type == 30782
|
|
)
|
|
return HEAPU32;
|
|
|
|
return HEAPU16;
|
|
}
|
|
|
|
function heapAccessShiftForWebGLHeap(heap) {
|
|
return 31 - Math.clz32(heap.BYTES_PER_ELEMENT);
|
|
}
|
|
function emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, internalFormat) {
|
|
var heap = heapObjectForWebGLType(type);
|
|
var shift = heapAccessShiftForWebGLHeap(heap);
|
|
var byteSize = 1<<shift;
|
|
var sizePerPixel = __colorChannelsInGlTextureFormat(format) * byteSize;
|
|
var bytes = computeUnpackAlignedImageSize(width, height, sizePerPixel, GL.unpackAlignment);
|
|
return heap.subarray(pixels >> shift, pixels + bytes >> shift);
|
|
}
|
|
function _emscripten_glReadPixels(x, y, width, height, format, type, pixels) {
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
if (GLctx.currentPixelPackBufferBinding) {
|
|
GLctx.readPixels(x, y, width, height, format, type, pixels);
|
|
} else {
|
|
var heap = heapObjectForWebGLType(type);
|
|
GLctx.readPixels(x, y, width, height, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
|
|
}
|
|
return;
|
|
}
|
|
var pixelData = emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, format);
|
|
if (!pixelData) {
|
|
GL.recordError(0x500/*GL_INVALID_ENUM*/);
|
|
return;
|
|
}
|
|
GLctx.readPixels(x, y, width, height, format, type, pixelData);
|
|
}
|
|
|
|
function _emscripten_glRenderbufferStorage(x0, x1, x2, x3) { GLctx['renderbufferStorage'](x0, x1, x2, x3) }
|
|
|
|
function _emscripten_glRenderbufferStorageMultisample(x0, x1, x2, x3, x4) { GLctx['renderbufferStorageMultisample'](x0, x1, x2, x3, x4) }
|
|
|
|
function _emscripten_glSamplerParameterf(sampler, pname, param) {
|
|
GLctx['samplerParameterf'](GL.samplers[sampler], pname, param);
|
|
}
|
|
|
|
function _emscripten_glSamplerParameteri(sampler, pname, param) {
|
|
GLctx['samplerParameteri'](GL.samplers[sampler], pname, param);
|
|
}
|
|
|
|
function _emscripten_glSamplerParameteriv(sampler, pname, params) {
|
|
var param = HEAP32[((params)>>2)];
|
|
GLctx['samplerParameteri'](GL.samplers[sampler], pname, param);
|
|
}
|
|
|
|
function _emscripten_glScissor(x0, x1, x2, x3) { GLctx['scissor'](x0, x1, x2, x3) }
|
|
|
|
function _emscripten_glShaderSource(shader, count, string, length) {
|
|
var source = GL.getSource(shader, count, string, length);
|
|
|
|
GLctx.shaderSource(GL.shaders[shader], source);
|
|
}
|
|
|
|
function _emscripten_glStencilFunc(x0, x1, x2) { GLctx['stencilFunc'](x0, x1, x2) }
|
|
|
|
function _emscripten_glStencilFuncSeparate(x0, x1, x2, x3) { GLctx['stencilFuncSeparate'](x0, x1, x2, x3) }
|
|
|
|
function _emscripten_glStencilMask(x0) { GLctx['stencilMask'](x0) }
|
|
|
|
function _emscripten_glStencilMaskSeparate(x0, x1) { GLctx['stencilMaskSeparate'](x0, x1) }
|
|
|
|
function _emscripten_glStencilOp(x0, x1, x2) { GLctx['stencilOp'](x0, x1, x2) }
|
|
|
|
function _emscripten_glStencilOpSeparate(x0, x1, x2, x3) { GLctx['stencilOpSeparate'](x0, x1, x2, x3) }
|
|
|
|
function _emscripten_glTexImage2D(target, level, internalFormat, width, height, border, format, type, pixels) {
|
|
if (GL.currentContext.version >= 2) {
|
|
// WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
if (GLctx.currentPixelUnpackBufferBinding) {
|
|
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixels);
|
|
} else if (pixels) {
|
|
var heap = heapObjectForWebGLType(type);
|
|
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
|
|
} else {
|
|
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, null);
|
|
}
|
|
return;
|
|
}
|
|
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixels ? emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, internalFormat) : null);
|
|
}
|
|
|
|
function _emscripten_glTexParameterf(x0, x1, x2) { GLctx['texParameterf'](x0, x1, x2) }
|
|
|
|
function _emscripten_glTexParameterfv(target, pname, params) {
|
|
var param = HEAPF32[((params)>>2)];
|
|
GLctx.texParameterf(target, pname, param);
|
|
}
|
|
|
|
function _emscripten_glTexParameteri(x0, x1, x2) { GLctx['texParameteri'](x0, x1, x2) }
|
|
|
|
function _emscripten_glTexParameteriv(target, pname, params) {
|
|
var param = HEAP32[((params)>>2)];
|
|
GLctx.texParameteri(target, pname, param);
|
|
}
|
|
|
|
function _emscripten_glTexStorage2D(x0, x1, x2, x3, x4) { GLctx['texStorage2D'](x0, x1, x2, x3, x4) }
|
|
|
|
function _emscripten_glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) {
|
|
if (GL.currentContext.version >= 2) {
|
|
// WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
if (GLctx.currentPixelUnpackBufferBinding) {
|
|
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
|
|
} else if (pixels) {
|
|
var heap = heapObjectForWebGLType(type);
|
|
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
|
|
} else {
|
|
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, null);
|
|
}
|
|
return;
|
|
}
|
|
var pixelData = null;
|
|
if (pixels) pixelData = emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, 0);
|
|
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixelData);
|
|
}
|
|
|
|
function webglGetUniformLocation(location) {
|
|
var p = GLctx.currentProgram;
|
|
|
|
if (p) {
|
|
var webglLoc = p.uniformLocsById[location];
|
|
// p.uniformLocsById[location] stores either an integer, or a WebGLUniformLocation.
|
|
|
|
// If an integer, we have not yet bound the location, so do it now. The integer value specifies the array index
|
|
// we should bind to.
|
|
if (typeof webglLoc == 'number') {
|
|
p.uniformLocsById[location] = webglLoc = GLctx.getUniformLocation(p, p.uniformArrayNamesById[location] + (webglLoc > 0 ? '[' + webglLoc + ']' : ''));
|
|
}
|
|
// Else an already cached WebGLUniformLocation, return it.
|
|
return webglLoc;
|
|
} else {
|
|
GL.recordError(0x502/*GL_INVALID_OPERATION*/);
|
|
}
|
|
}
|
|
function _emscripten_glUniform1f(location, v0) {
|
|
GLctx.uniform1f(webglGetUniformLocation(location), v0);
|
|
}
|
|
|
|
var miniTempWebGLFloatBuffers = [];
|
|
function _emscripten_glUniform1fv(location, count, value) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
count && GLctx.uniform1fv(webglGetUniformLocation(location), HEAPF32, value>>2, count);
|
|
return;
|
|
}
|
|
|
|
if (count <= 288) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = miniTempWebGLFloatBuffers[count-1];
|
|
for (var i = 0; i < count; ++i) {
|
|
view[i] = HEAPF32[(((value)+(4*i))>>2)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((value)>>2, (value+count*4)>>2);
|
|
}
|
|
GLctx.uniform1fv(webglGetUniformLocation(location), view);
|
|
}
|
|
|
|
function _emscripten_glUniform1i(location, v0) {
|
|
GLctx.uniform1i(webglGetUniformLocation(location), v0);
|
|
}
|
|
|
|
var __miniTempWebGLIntBuffers = [];
|
|
function _emscripten_glUniform1iv(location, count, value) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
count && GLctx.uniform1iv(webglGetUniformLocation(location), HEAP32, value>>2, count);
|
|
return;
|
|
}
|
|
|
|
if (count <= 288) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = __miniTempWebGLIntBuffers[count-1];
|
|
for (var i = 0; i < count; ++i) {
|
|
view[i] = HEAP32[(((value)+(4*i))>>2)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAP32.subarray((value)>>2, (value+count*4)>>2);
|
|
}
|
|
GLctx.uniform1iv(webglGetUniformLocation(location), view);
|
|
}
|
|
|
|
function _emscripten_glUniform2f(location, v0, v1) {
|
|
GLctx.uniform2f(webglGetUniformLocation(location), v0, v1);
|
|
}
|
|
|
|
function _emscripten_glUniform2fv(location, count, value) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
count && GLctx.uniform2fv(webglGetUniformLocation(location), HEAPF32, value>>2, count*2);
|
|
return;
|
|
}
|
|
|
|
if (count <= 144) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = miniTempWebGLFloatBuffers[2*count-1];
|
|
for (var i = 0; i < 2*count; i += 2) {
|
|
view[i] = HEAPF32[(((value)+(4*i))>>2)];
|
|
view[i+1] = HEAPF32[(((value)+(4*i+4))>>2)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((value)>>2, (value+count*8)>>2);
|
|
}
|
|
GLctx.uniform2fv(webglGetUniformLocation(location), view);
|
|
}
|
|
|
|
function _emscripten_glUniform2i(location, v0, v1) {
|
|
GLctx.uniform2i(webglGetUniformLocation(location), v0, v1);
|
|
}
|
|
|
|
function _emscripten_glUniform2iv(location, count, value) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
count && GLctx.uniform2iv(webglGetUniformLocation(location), HEAP32, value>>2, count*2);
|
|
return;
|
|
}
|
|
|
|
if (count <= 144) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = __miniTempWebGLIntBuffers[2*count-1];
|
|
for (var i = 0; i < 2*count; i += 2) {
|
|
view[i] = HEAP32[(((value)+(4*i))>>2)];
|
|
view[i+1] = HEAP32[(((value)+(4*i+4))>>2)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAP32.subarray((value)>>2, (value+count*8)>>2);
|
|
}
|
|
GLctx.uniform2iv(webglGetUniformLocation(location), view);
|
|
}
|
|
|
|
function _emscripten_glUniform3f(location, v0, v1, v2) {
|
|
GLctx.uniform3f(webglGetUniformLocation(location), v0, v1, v2);
|
|
}
|
|
|
|
function _emscripten_glUniform3fv(location, count, value) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
count && GLctx.uniform3fv(webglGetUniformLocation(location), HEAPF32, value>>2, count*3);
|
|
return;
|
|
}
|
|
|
|
if (count <= 96) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = miniTempWebGLFloatBuffers[3*count-1];
|
|
for (var i = 0; i < 3*count; i += 3) {
|
|
view[i] = HEAPF32[(((value)+(4*i))>>2)];
|
|
view[i+1] = HEAPF32[(((value)+(4*i+4))>>2)];
|
|
view[i+2] = HEAPF32[(((value)+(4*i+8))>>2)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((value)>>2, (value+count*12)>>2);
|
|
}
|
|
GLctx.uniform3fv(webglGetUniformLocation(location), view);
|
|
}
|
|
|
|
function _emscripten_glUniform3i(location, v0, v1, v2) {
|
|
GLctx.uniform3i(webglGetUniformLocation(location), v0, v1, v2);
|
|
}
|
|
|
|
function _emscripten_glUniform3iv(location, count, value) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
count && GLctx.uniform3iv(webglGetUniformLocation(location), HEAP32, value>>2, count*3);
|
|
return;
|
|
}
|
|
|
|
if (count <= 96) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = __miniTempWebGLIntBuffers[3*count-1];
|
|
for (var i = 0; i < 3*count; i += 3) {
|
|
view[i] = HEAP32[(((value)+(4*i))>>2)];
|
|
view[i+1] = HEAP32[(((value)+(4*i+4))>>2)];
|
|
view[i+2] = HEAP32[(((value)+(4*i+8))>>2)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAP32.subarray((value)>>2, (value+count*12)>>2);
|
|
}
|
|
GLctx.uniform3iv(webglGetUniformLocation(location), view);
|
|
}
|
|
|
|
function _emscripten_glUniform4f(location, v0, v1, v2, v3) {
|
|
GLctx.uniform4f(webglGetUniformLocation(location), v0, v1, v2, v3);
|
|
}
|
|
|
|
function _emscripten_glUniform4fv(location, count, value) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
count && GLctx.uniform4fv(webglGetUniformLocation(location), HEAPF32, value>>2, count*4);
|
|
return;
|
|
}
|
|
|
|
if (count <= 72) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = miniTempWebGLFloatBuffers[4*count-1];
|
|
// hoist the heap out of the loop for size and for pthreads+growth.
|
|
var heap = HEAPF32;
|
|
value >>= 2;
|
|
for (var i = 0; i < 4 * count; i += 4) {
|
|
var dst = value + i;
|
|
view[i] = heap[dst];
|
|
view[i + 1] = heap[dst + 1];
|
|
view[i + 2] = heap[dst + 2];
|
|
view[i + 3] = heap[dst + 3];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((value)>>2, (value+count*16)>>2);
|
|
}
|
|
GLctx.uniform4fv(webglGetUniformLocation(location), view);
|
|
}
|
|
|
|
function _emscripten_glUniform4i(location, v0, v1, v2, v3) {
|
|
GLctx.uniform4i(webglGetUniformLocation(location), v0, v1, v2, v3);
|
|
}
|
|
|
|
function _emscripten_glUniform4iv(location, count, value) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
count && GLctx.uniform4iv(webglGetUniformLocation(location), HEAP32, value>>2, count*4);
|
|
return;
|
|
}
|
|
|
|
if (count <= 72) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = __miniTempWebGLIntBuffers[4*count-1];
|
|
for (var i = 0; i < 4*count; i += 4) {
|
|
view[i] = HEAP32[(((value)+(4*i))>>2)];
|
|
view[i+1] = HEAP32[(((value)+(4*i+4))>>2)];
|
|
view[i+2] = HEAP32[(((value)+(4*i+8))>>2)];
|
|
view[i+3] = HEAP32[(((value)+(4*i+12))>>2)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAP32.subarray((value)>>2, (value+count*16)>>2);
|
|
}
|
|
GLctx.uniform4iv(webglGetUniformLocation(location), view);
|
|
}
|
|
|
|
function _emscripten_glUniformMatrix2fv(location, count, transpose, value) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
count && GLctx.uniformMatrix2fv(webglGetUniformLocation(location), !!transpose, HEAPF32, value>>2, count*4);
|
|
return;
|
|
}
|
|
|
|
if (count <= 72) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = miniTempWebGLFloatBuffers[4*count-1];
|
|
for (var i = 0; i < 4*count; i += 4) {
|
|
view[i] = HEAPF32[(((value)+(4*i))>>2)];
|
|
view[i+1] = HEAPF32[(((value)+(4*i+4))>>2)];
|
|
view[i+2] = HEAPF32[(((value)+(4*i+8))>>2)];
|
|
view[i+3] = HEAPF32[(((value)+(4*i+12))>>2)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((value)>>2, (value+count*16)>>2);
|
|
}
|
|
GLctx.uniformMatrix2fv(webglGetUniformLocation(location), !!transpose, view);
|
|
}
|
|
|
|
function _emscripten_glUniformMatrix3fv(location, count, transpose, value) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
count && GLctx.uniformMatrix3fv(webglGetUniformLocation(location), !!transpose, HEAPF32, value>>2, count*9);
|
|
return;
|
|
}
|
|
|
|
if (count <= 32) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = miniTempWebGLFloatBuffers[9*count-1];
|
|
for (var i = 0; i < 9*count; i += 9) {
|
|
view[i] = HEAPF32[(((value)+(4*i))>>2)];
|
|
view[i+1] = HEAPF32[(((value)+(4*i+4))>>2)];
|
|
view[i+2] = HEAPF32[(((value)+(4*i+8))>>2)];
|
|
view[i+3] = HEAPF32[(((value)+(4*i+12))>>2)];
|
|
view[i+4] = HEAPF32[(((value)+(4*i+16))>>2)];
|
|
view[i+5] = HEAPF32[(((value)+(4*i+20))>>2)];
|
|
view[i+6] = HEAPF32[(((value)+(4*i+24))>>2)];
|
|
view[i+7] = HEAPF32[(((value)+(4*i+28))>>2)];
|
|
view[i+8] = HEAPF32[(((value)+(4*i+32))>>2)];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((value)>>2, (value+count*36)>>2);
|
|
}
|
|
GLctx.uniformMatrix3fv(webglGetUniformLocation(location), !!transpose, view);
|
|
}
|
|
|
|
function _emscripten_glUniformMatrix4fv(location, count, transpose, value) {
|
|
|
|
if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
|
|
count && GLctx.uniformMatrix4fv(webglGetUniformLocation(location), !!transpose, HEAPF32, value>>2, count*16);
|
|
return;
|
|
}
|
|
|
|
if (count <= 18) {
|
|
// avoid allocation when uploading few enough uniforms
|
|
var view = miniTempWebGLFloatBuffers[16*count-1];
|
|
// hoist the heap out of the loop for size and for pthreads+growth.
|
|
var heap = HEAPF32;
|
|
value >>= 2;
|
|
for (var i = 0; i < 16 * count; i += 16) {
|
|
var dst = value + i;
|
|
view[i] = heap[dst];
|
|
view[i + 1] = heap[dst + 1];
|
|
view[i + 2] = heap[dst + 2];
|
|
view[i + 3] = heap[dst + 3];
|
|
view[i + 4] = heap[dst + 4];
|
|
view[i + 5] = heap[dst + 5];
|
|
view[i + 6] = heap[dst + 6];
|
|
view[i + 7] = heap[dst + 7];
|
|
view[i + 8] = heap[dst + 8];
|
|
view[i + 9] = heap[dst + 9];
|
|
view[i + 10] = heap[dst + 10];
|
|
view[i + 11] = heap[dst + 11];
|
|
view[i + 12] = heap[dst + 12];
|
|
view[i + 13] = heap[dst + 13];
|
|
view[i + 14] = heap[dst + 14];
|
|
view[i + 15] = heap[dst + 15];
|
|
}
|
|
} else
|
|
{
|
|
var view = HEAPF32.subarray((value)>>2, (value+count*64)>>2);
|
|
}
|
|
GLctx.uniformMatrix4fv(webglGetUniformLocation(location), !!transpose, view);
|
|
}
|
|
|
|
function _emscripten_glUseProgram(program) {
|
|
program = GL.programs[program];
|
|
GLctx.useProgram(program);
|
|
// Record the currently active program so that we can access the uniform
|
|
// mapping table of that program.
|
|
GLctx.currentProgram = program;
|
|
}
|
|
|
|
function _emscripten_glVertexAttrib1f(x0, x1) { GLctx['vertexAttrib1f'](x0, x1) }
|
|
|
|
function _emscripten_glVertexAttrib2fv(index, v) {
|
|
|
|
GLctx.vertexAttrib2f(index, HEAPF32[v>>2], HEAPF32[v+4>>2]);
|
|
}
|
|
|
|
function _emscripten_glVertexAttrib3fv(index, v) {
|
|
|
|
GLctx.vertexAttrib3f(index, HEAPF32[v>>2], HEAPF32[v+4>>2], HEAPF32[v+8>>2]);
|
|
}
|
|
|
|
function _emscripten_glVertexAttrib4fv(index, v) {
|
|
|
|
GLctx.vertexAttrib4f(index, HEAPF32[v>>2], HEAPF32[v+4>>2], HEAPF32[v+8>>2], HEAPF32[v+12>>2]);
|
|
}
|
|
|
|
function _emscripten_glVertexAttribDivisor(index, divisor) {
|
|
GLctx['vertexAttribDivisor'](index, divisor);
|
|
}
|
|
|
|
function _emscripten_glVertexAttribIPointer(index, size, type, stride, ptr) {
|
|
GLctx['vertexAttribIPointer'](index, size, type, stride, ptr);
|
|
}
|
|
|
|
function _emscripten_glVertexAttribPointer(index, size, type, normalized, stride, ptr) {
|
|
GLctx.vertexAttribPointer(index, size, type, !!normalized, stride, ptr);
|
|
}
|
|
|
|
function _emscripten_glViewport(x0, x1, x2, x3) { GLctx['viewport'](x0, x1, x2, x3) }
|
|
|
|
function _emscripten_glWaitSync(sync, flags, timeoutLo, timeoutHi) {
|
|
// See WebGL2 vs GLES3 difference on GL_TIMEOUT_IGNORED above (https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.15)
|
|
GLctx.waitSync(GL.syncs[sync], flags, convertI32PairToI53(timeoutLo, timeoutHi));
|
|
}
|
|
|
|
function _emscripten_memcpy_big(dest, src, num) {
|
|
HEAPU8.copyWithin(dest, src, src + num);
|
|
}
|
|
|
|
function getHeapMax() {
|
|
// Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
|
|
// full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
|
|
// for any code that deals with heap sizes, which would require special
|
|
// casing all heap size related code to treat 0 specially.
|
|
return 2147483648;
|
|
}
|
|
|
|
function emscripten_realloc_buffer(size) {
|
|
try {
|
|
// round size grow request up to wasm page size (fixed 64KB per spec)
|
|
wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16); // .grow() takes a delta compared to the previous size
|
|
updateGlobalBufferAndViews(wasmMemory.buffer);
|
|
return 1 /*success*/;
|
|
} catch(e) {
|
|
err('emscripten_realloc_buffer: Attempted to grow heap from ' + buffer.byteLength + ' bytes to ' + size + ' bytes, but got error: ' + e);
|
|
}
|
|
// implicit 0 return to save code size (caller will cast "undefined" into 0
|
|
// anyhow)
|
|
}
|
|
function _emscripten_resize_heap(requestedSize) {
|
|
var oldSize = HEAPU8.length;
|
|
requestedSize = requestedSize >>> 0;
|
|
// With multithreaded builds, races can happen (another thread might increase the size
|
|
// in between), so return a failure, and let the caller retry.
|
|
assert(requestedSize > oldSize);
|
|
|
|
// Memory resize rules:
|
|
// 1. Always increase heap size to at least the requested size, rounded up
|
|
// to next page multiple.
|
|
// 2a. If MEMORY_GROWTH_LINEAR_STEP == -1, excessively resize the heap
|
|
// geometrically: increase the heap size according to
|
|
// MEMORY_GROWTH_GEOMETRIC_STEP factor (default +20%), At most
|
|
// overreserve by MEMORY_GROWTH_GEOMETRIC_CAP bytes (default 96MB).
|
|
// 2b. If MEMORY_GROWTH_LINEAR_STEP != -1, excessively resize the heap
|
|
// linearly: increase the heap size by at least
|
|
// MEMORY_GROWTH_LINEAR_STEP bytes.
|
|
// 3. Max size for the heap is capped at 2048MB-WASM_PAGE_SIZE, or by
|
|
// MAXIMUM_MEMORY, or by ASAN limit, depending on which is smallest
|
|
// 4. If we were unable to allocate as much memory, it may be due to
|
|
// over-eager decision to excessively reserve due to (3) above.
|
|
// Hence if an allocation fails, cut down on the amount of excess
|
|
// growth, in an attempt to succeed to perform a smaller allocation.
|
|
|
|
// A limit is set for how much we can grow. We should not exceed that
|
|
// (the wasm binary specifies it, so if we tried, we'd fail anyhow).
|
|
var maxHeapSize = getHeapMax();
|
|
if (requestedSize > maxHeapSize) {
|
|
err('Cannot enlarge memory, asked to go up to ' + requestedSize + ' bytes, but the limit is ' + maxHeapSize + ' bytes!');
|
|
return false;
|
|
}
|
|
|
|
let alignUp = (x, multiple) => x + (multiple - x % multiple) % multiple;
|
|
|
|
// Loop through potential heap size increases. If we attempt a too eager
|
|
// reservation that fails, cut down on the attempted size and reserve a
|
|
// smaller bump instead. (max 3 times, chosen somewhat arbitrarily)
|
|
for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
|
|
var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown); // ensure geometric growth
|
|
// but limit overreserving (default to capping at +96MB overgrowth at most)
|
|
overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296 );
|
|
|
|
var newSize = Math.min(maxHeapSize, alignUp(Math.max(requestedSize, overGrownHeapSize), 65536));
|
|
|
|
var replacement = emscripten_realloc_buffer(newSize);
|
|
if (replacement) {
|
|
|
|
return true;
|
|
}
|
|
}
|
|
err('Failed to grow the heap from ' + oldSize + ' bytes to ' + newSize + ' bytes, not enough memory!');
|
|
return false;
|
|
}
|
|
|
|
var ENV = {};
|
|
|
|
function getExecutableName() {
|
|
return thisProgram || './this.program';
|
|
}
|
|
function getEnvStrings() {
|
|
if (!getEnvStrings.strings) {
|
|
// Default values.
|
|
// Browser language detection #8751
|
|
var lang = ((typeof navigator == 'object' && navigator.languages && navigator.languages[0]) || 'C').replace('-', '_') + '.UTF-8';
|
|
var env = {
|
|
'USER': 'web_user',
|
|
'LOGNAME': 'web_user',
|
|
'PATH': '/',
|
|
'PWD': '/',
|
|
'HOME': '/home/web_user',
|
|
'LANG': lang,
|
|
'_': getExecutableName()
|
|
};
|
|
// Apply the user-provided values, if any.
|
|
for (var x in ENV) {
|
|
// x is a key in ENV; if ENV[x] is undefined, that means it was
|
|
// explicitly set to be so. We allow user code to do that to
|
|
// force variables with default values to remain unset.
|
|
if (ENV[x] === undefined) delete env[x];
|
|
else env[x] = ENV[x];
|
|
}
|
|
var strings = [];
|
|
for (var x in env) {
|
|
strings.push(x + '=' + env[x]);
|
|
}
|
|
getEnvStrings.strings = strings;
|
|
}
|
|
return getEnvStrings.strings;
|
|
}
|
|
function _environ_get(__environ, environ_buf) {
|
|
var bufSize = 0;
|
|
getEnvStrings().forEach(function(string, i) {
|
|
var ptr = environ_buf + bufSize;
|
|
HEAPU32[(((__environ)+(i*4))>>2)] = ptr;
|
|
writeAsciiToMemory(string, ptr);
|
|
bufSize += string.length + 1;
|
|
});
|
|
return 0;
|
|
}
|
|
|
|
function _environ_sizes_get(penviron_count, penviron_buf_size) {
|
|
var strings = getEnvStrings();
|
|
HEAPU32[((penviron_count)>>2)] = strings.length;
|
|
var bufSize = 0;
|
|
strings.forEach(function(string) {
|
|
bufSize += string.length + 1;
|
|
});
|
|
HEAPU32[((penviron_buf_size)>>2)] = bufSize;
|
|
return 0;
|
|
}
|
|
|
|
function _exit(status) {
|
|
// void _exit(int status);
|
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/exit.html
|
|
exit(status);
|
|
}
|
|
|
|
function _fd_close(fd) {
|
|
abort('fd_close called without SYSCALLS_REQUIRE_FILESYSTEM');
|
|
}
|
|
|
|
function 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 _fd_pread(fd, iov, iovcnt, offset_low, offset_high, pnum) {
|
|
abort('fd_pread called without SYSCALLS_REQUIRE_FILESYSTEM');
|
|
}
|
|
|
|
function _fd_read(fd, iov, iovcnt, pnum) {
|
|
abort('fd_read called without SYSCALLS_REQUIRE_FILESYSTEM');
|
|
}
|
|
|
|
function _fd_seek(fd, offset_low, offset_high, whence, newOffset) {
|
|
return 70;
|
|
}
|
|
|
|
var printCharBuffers = [null,[],[]];
|
|
function printChar(stream, curr) {
|
|
var buffer = printCharBuffers[stream];
|
|
assert(buffer);
|
|
if (curr === 0 || curr === 10) {
|
|
(stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
|
|
buffer.length = 0;
|
|
} else {
|
|
buffer.push(curr);
|
|
}
|
|
}
|
|
function flush_NO_FILESYSTEM() {
|
|
// flush anything remaining in the buffers during shutdown
|
|
_fflush(0);
|
|
if (printCharBuffers[1].length) printChar(1, 10);
|
|
if (printCharBuffers[2].length) printChar(2, 10);
|
|
}
|
|
function _fd_write(fd, iov, iovcnt, pnum) {
|
|
// hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
|
|
var num = 0;
|
|
for (var i = 0; i < iovcnt; i++) {
|
|
var ptr = HEAPU32[((iov)>>2)];
|
|
var len = HEAPU32[(((iov)+(4))>>2)];
|
|
iov += 8;
|
|
for (var j = 0; j < len; j++) {
|
|
printChar(fd, HEAPU8[ptr+j]);
|
|
}
|
|
num += len;
|
|
}
|
|
HEAPU32[((pnum)>>2)] = num;
|
|
return 0;
|
|
}
|
|
|
|
function _getTempRet0() {
|
|
return getTempRet0();
|
|
}
|
|
|
|
function _setTempRet0(val) {
|
|
setTempRet0(val);
|
|
}
|
|
|
|
function __isLeapYear(year) {
|
|
return year%4 === 0 && (year%100 !== 0 || year%400 === 0);
|
|
}
|
|
|
|
function __arraySum(array, index) {
|
|
var sum = 0;
|
|
for (var i = 0; i <= index; sum += array[i++]) {
|
|
// no-op
|
|
}
|
|
return sum;
|
|
}
|
|
|
|
var __MONTH_DAYS_LEAP = [31,29,31,30,31,30,31,31,30,31,30,31];
|
|
|
|
var __MONTH_DAYS_REGULAR = [31,28,31,30,31,30,31,31,30,31,30,31];
|
|
function __addDays(date, days) {
|
|
var newDate = new Date(date.getTime());
|
|
while (days > 0) {
|
|
var leap = __isLeapYear(newDate.getFullYear());
|
|
var currentMonth = newDate.getMonth();
|
|
var daysInCurrentMonth = (leap ? __MONTH_DAYS_LEAP : __MONTH_DAYS_REGULAR)[currentMonth];
|
|
|
|
if (days > daysInCurrentMonth-newDate.getDate()) {
|
|
// we spill over to next month
|
|
days -= (daysInCurrentMonth-newDate.getDate()+1);
|
|
newDate.setDate(1);
|
|
if (currentMonth < 11) {
|
|
newDate.setMonth(currentMonth+1)
|
|
} else {
|
|
newDate.setMonth(0);
|
|
newDate.setFullYear(newDate.getFullYear()+1);
|
|
}
|
|
} else {
|
|
// we stay in current month
|
|
newDate.setDate(newDate.getDate()+days);
|
|
return newDate;
|
|
}
|
|
}
|
|
|
|
return newDate;
|
|
}
|
|
function _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 = HEAP32[(((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;
|
|
} else {
|
|
return thisDate.getFullYear();
|
|
}
|
|
} else {
|
|
return thisDate.getFullYear()-1;
|
|
}
|
|
}
|
|
|
|
var EXPANSION_RULES_2 = {
|
|
'%a': function(date) {
|
|
return WEEKDAYS[date.tm_wday].substring(0,3);
|
|
},
|
|
'%A': function(date) {
|
|
return WEEKDAYS[date.tm_wday];
|
|
},
|
|
'%b': function(date) {
|
|
return MONTHS[date.tm_mon].substring(0,3);
|
|
},
|
|
'%B': function(date) {
|
|
return MONTHS[date.tm_mon];
|
|
},
|
|
'%C': function(date) {
|
|
var year = date.tm_year+1900;
|
|
return leadingNulls((year/100)|0,2);
|
|
},
|
|
'%d': function(date) {
|
|
return leadingNulls(date.tm_mday, 2);
|
|
},
|
|
'%e': function(date) {
|
|
return leadingSomething(date.tm_mday, 2, ' ');
|
|
},
|
|
'%g': function(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': function(date) {
|
|
return getWeekBasedYear(date);
|
|
},
|
|
'%H': function(date) {
|
|
return leadingNulls(date.tm_hour, 2);
|
|
},
|
|
'%I': function(date) {
|
|
var twelveHour = date.tm_hour;
|
|
if (twelveHour == 0) twelveHour = 12;
|
|
else if (twelveHour > 12) twelveHour -= 12;
|
|
return leadingNulls(twelveHour, 2);
|
|
},
|
|
'%j': function(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': function(date) {
|
|
return leadingNulls(date.tm_mon+1, 2);
|
|
},
|
|
'%M': function(date) {
|
|
return leadingNulls(date.tm_min, 2);
|
|
},
|
|
'%n': function() {
|
|
return '\n';
|
|
},
|
|
'%p': function(date) {
|
|
if (date.tm_hour >= 0 && date.tm_hour < 12) {
|
|
return 'AM';
|
|
} else {
|
|
return 'PM';
|
|
}
|
|
},
|
|
'%S': function(date) {
|
|
return leadingNulls(date.tm_sec, 2);
|
|
},
|
|
'%t': function() {
|
|
return '\t';
|
|
},
|
|
'%u': function(date) {
|
|
return date.tm_wday || 7;
|
|
},
|
|
'%U': function(date) {
|
|
var days = date.tm_yday + 7 - date.tm_wday;
|
|
return leadingNulls(Math.floor(days / 7), 2);
|
|
},
|
|
'%V': function(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': function(date) {
|
|
return date.tm_wday;
|
|
},
|
|
'%W': function(date) {
|
|
var days = date.tm_yday + 7 - ((date.tm_wday + 6) % 7);
|
|
return leadingNulls(Math.floor(days / 7), 2);
|
|
},
|
|
'%y': function(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);
|
|
},
|
|
'%Y': function(date) {
|
|
// Replaced by the year as a decimal number (for example, 1997). [ tm_year]
|
|
return date.tm_year+1900;
|
|
},
|
|
'%z': function(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': function(date) {
|
|
return date.tm_zone;
|
|
},
|
|
'%%': function() {
|
|
return '%';
|
|
}
|
|
};
|
|
|
|
// 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;
|
|
}
|
|
function _strftime_l(s, maxsize, format, tm) {
|
|
return _strftime(s, maxsize, format, tm); // no locale support yet
|
|
}
|
|
embind_init_charCodes();
|
|
BindingError = Module['BindingError'] = extendError(Error, 'BindingError');;
|
|
InternalError = Module['InternalError'] = extendError(Error, 'InternalError');;
|
|
init_emval();;
|
|
UnboundTypeError = Module['UnboundTypeError'] = extendError(Error, 'UnboundTypeError');;
|
|
var GLctx;;
|
|
for (var i = 0; i < 32; ++i) tempFixedLengthArray.push(new Array(i));;
|
|
var miniTempWebGLFloatBuffersStorage = new Float32Array(288);
|
|
for (/**@suppress{duplicate}*/var i = 0; i < 288; ++i) {
|
|
miniTempWebGLFloatBuffers[i] = miniTempWebGLFloatBuffersStorage.subarray(0, i+1);
|
|
}
|
|
;
|
|
var __miniTempWebGLIntBuffersStorage = new Int32Array(288);
|
|
for (/**@suppress{duplicate}*/var i = 0; i < 288; ++i) {
|
|
__miniTempWebGLIntBuffers[i] = __miniTempWebGLIntBuffersStorage.subarray(0, i+1);
|
|
}
|
|
;
|
|
var ASSERTIONS = true;
|
|
|
|
|
|
|
|
/** @type {function(string, boolean=, number=)} */
|
|
function intArrayFromString(stringy, dontAddNull, length) {
|
|
var len = length > 0 ? length : lengthBytesUTF8(stringy)+1;
|
|
var u8array = new Array(len);
|
|
var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
|
|
if (dontAddNull) u8array.length = numBytesWritten;
|
|
return u8array;
|
|
}
|
|
|
|
function intArrayToString(array) {
|
|
var ret = [];
|
|
for (var i = 0; i < array.length; i++) {
|
|
var chr = array[i];
|
|
if (chr > 0xFF) {
|
|
if (ASSERTIONS) {
|
|
assert(false, 'Character code ' + chr + ' (' + String.fromCharCode(chr) + ') at offset ' + i + ' not in 0x00-0xFF.');
|
|
}
|
|
chr &= 0xFF;
|
|
}
|
|
ret.push(String.fromCharCode(chr));
|
|
}
|
|
return ret.join('');
|
|
}
|
|
|
|
|
|
function checkIncomingModuleAPI() {
|
|
ignoredModuleProp('fetchSettings');
|
|
}
|
|
var asmLibraryArg = {
|
|
"__syscall_fcntl64": ___syscall_fcntl64,
|
|
"__syscall_fstat64": ___syscall_fstat64,
|
|
"__syscall_ioctl": ___syscall_ioctl,
|
|
"__syscall_lstat64": ___syscall_lstat64,
|
|
"__syscall_newfstatat": ___syscall_newfstatat,
|
|
"__syscall_openat": ___syscall_openat,
|
|
"__syscall_stat64": ___syscall_stat64,
|
|
"_embind_register_bigint": __embind_register_bigint,
|
|
"_embind_register_bool": __embind_register_bool,
|
|
"_embind_register_constant": __embind_register_constant,
|
|
"_embind_register_emval": __embind_register_emval,
|
|
"_embind_register_float": __embind_register_float,
|
|
"_embind_register_function": __embind_register_function,
|
|
"_embind_register_integer": __embind_register_integer,
|
|
"_embind_register_memory_view": __embind_register_memory_view,
|
|
"_embind_register_std_string": __embind_register_std_string,
|
|
"_embind_register_std_wstring": __embind_register_std_wstring,
|
|
"_embind_register_void": __embind_register_void,
|
|
"_emscripten_date_now": __emscripten_date_now,
|
|
"_emscripten_get_now_is_monotonic": __emscripten_get_now_is_monotonic,
|
|
"_emscripten_throw_longjmp": __emscripten_throw_longjmp,
|
|
"_mmap_js": __mmap_js,
|
|
"_munmap_js": __munmap_js,
|
|
"abort": _abort,
|
|
"emscripten_get_now": _emscripten_get_now,
|
|
"emscripten_glActiveTexture": _emscripten_glActiveTexture,
|
|
"emscripten_glAttachShader": _emscripten_glAttachShader,
|
|
"emscripten_glBindAttribLocation": _emscripten_glBindAttribLocation,
|
|
"emscripten_glBindBuffer": _emscripten_glBindBuffer,
|
|
"emscripten_glBindFramebuffer": _emscripten_glBindFramebuffer,
|
|
"emscripten_glBindRenderbuffer": _emscripten_glBindRenderbuffer,
|
|
"emscripten_glBindSampler": _emscripten_glBindSampler,
|
|
"emscripten_glBindTexture": _emscripten_glBindTexture,
|
|
"emscripten_glBindVertexArray": _emscripten_glBindVertexArray,
|
|
"emscripten_glBindVertexArrayOES": _emscripten_glBindVertexArrayOES,
|
|
"emscripten_glBlendColor": _emscripten_glBlendColor,
|
|
"emscripten_glBlendEquation": _emscripten_glBlendEquation,
|
|
"emscripten_glBlendFunc": _emscripten_glBlendFunc,
|
|
"emscripten_glBlitFramebuffer": _emscripten_glBlitFramebuffer,
|
|
"emscripten_glBufferData": _emscripten_glBufferData,
|
|
"emscripten_glBufferSubData": _emscripten_glBufferSubData,
|
|
"emscripten_glCheckFramebufferStatus": _emscripten_glCheckFramebufferStatus,
|
|
"emscripten_glClear": _emscripten_glClear,
|
|
"emscripten_glClearColor": _emscripten_glClearColor,
|
|
"emscripten_glClearStencil": _emscripten_glClearStencil,
|
|
"emscripten_glClientWaitSync": _emscripten_glClientWaitSync,
|
|
"emscripten_glColorMask": _emscripten_glColorMask,
|
|
"emscripten_glCompileShader": _emscripten_glCompileShader,
|
|
"emscripten_glCompressedTexImage2D": _emscripten_glCompressedTexImage2D,
|
|
"emscripten_glCompressedTexSubImage2D": _emscripten_glCompressedTexSubImage2D,
|
|
"emscripten_glCopyBufferSubData": _emscripten_glCopyBufferSubData,
|
|
"emscripten_glCopyTexSubImage2D": _emscripten_glCopyTexSubImage2D,
|
|
"emscripten_glCreateProgram": _emscripten_glCreateProgram,
|
|
"emscripten_glCreateShader": _emscripten_glCreateShader,
|
|
"emscripten_glCullFace": _emscripten_glCullFace,
|
|
"emscripten_glDeleteBuffers": _emscripten_glDeleteBuffers,
|
|
"emscripten_glDeleteFramebuffers": _emscripten_glDeleteFramebuffers,
|
|
"emscripten_glDeleteProgram": _emscripten_glDeleteProgram,
|
|
"emscripten_glDeleteRenderbuffers": _emscripten_glDeleteRenderbuffers,
|
|
"emscripten_glDeleteSamplers": _emscripten_glDeleteSamplers,
|
|
"emscripten_glDeleteShader": _emscripten_glDeleteShader,
|
|
"emscripten_glDeleteSync": _emscripten_glDeleteSync,
|
|
"emscripten_glDeleteTextures": _emscripten_glDeleteTextures,
|
|
"emscripten_glDeleteVertexArrays": _emscripten_glDeleteVertexArrays,
|
|
"emscripten_glDeleteVertexArraysOES": _emscripten_glDeleteVertexArraysOES,
|
|
"emscripten_glDepthMask": _emscripten_glDepthMask,
|
|
"emscripten_glDisable": _emscripten_glDisable,
|
|
"emscripten_glDisableVertexAttribArray": _emscripten_glDisableVertexAttribArray,
|
|
"emscripten_glDrawArrays": _emscripten_glDrawArrays,
|
|
"emscripten_glDrawArraysInstanced": _emscripten_glDrawArraysInstanced,
|
|
"emscripten_glDrawArraysInstancedBaseInstanceWEBGL": _emscripten_glDrawArraysInstancedBaseInstanceWEBGL,
|
|
"emscripten_glDrawBuffers": _emscripten_glDrawBuffers,
|
|
"emscripten_glDrawElements": _emscripten_glDrawElements,
|
|
"emscripten_glDrawElementsInstanced": _emscripten_glDrawElementsInstanced,
|
|
"emscripten_glDrawElementsInstancedBaseVertexBaseInstanceWEBGL": _emscripten_glDrawElementsInstancedBaseVertexBaseInstanceWEBGL,
|
|
"emscripten_glDrawRangeElements": _emscripten_glDrawRangeElements,
|
|
"emscripten_glEnable": _emscripten_glEnable,
|
|
"emscripten_glEnableVertexAttribArray": _emscripten_glEnableVertexAttribArray,
|
|
"emscripten_glFenceSync": _emscripten_glFenceSync,
|
|
"emscripten_glFinish": _emscripten_glFinish,
|
|
"emscripten_glFlush": _emscripten_glFlush,
|
|
"emscripten_glFramebufferRenderbuffer": _emscripten_glFramebufferRenderbuffer,
|
|
"emscripten_glFramebufferTexture2D": _emscripten_glFramebufferTexture2D,
|
|
"emscripten_glFrontFace": _emscripten_glFrontFace,
|
|
"emscripten_glGenBuffers": _emscripten_glGenBuffers,
|
|
"emscripten_glGenFramebuffers": _emscripten_glGenFramebuffers,
|
|
"emscripten_glGenRenderbuffers": _emscripten_glGenRenderbuffers,
|
|
"emscripten_glGenSamplers": _emscripten_glGenSamplers,
|
|
"emscripten_glGenTextures": _emscripten_glGenTextures,
|
|
"emscripten_glGenVertexArrays": _emscripten_glGenVertexArrays,
|
|
"emscripten_glGenVertexArraysOES": _emscripten_glGenVertexArraysOES,
|
|
"emscripten_glGenerateMipmap": _emscripten_glGenerateMipmap,
|
|
"emscripten_glGetBufferParameteriv": _emscripten_glGetBufferParameteriv,
|
|
"emscripten_glGetError": _emscripten_glGetError,
|
|
"emscripten_glGetFloatv": _emscripten_glGetFloatv,
|
|
"emscripten_glGetFramebufferAttachmentParameteriv": _emscripten_glGetFramebufferAttachmentParameteriv,
|
|
"emscripten_glGetIntegerv": _emscripten_glGetIntegerv,
|
|
"emscripten_glGetProgramInfoLog": _emscripten_glGetProgramInfoLog,
|
|
"emscripten_glGetProgramiv": _emscripten_glGetProgramiv,
|
|
"emscripten_glGetRenderbufferParameteriv": _emscripten_glGetRenderbufferParameteriv,
|
|
"emscripten_glGetShaderInfoLog": _emscripten_glGetShaderInfoLog,
|
|
"emscripten_glGetShaderPrecisionFormat": _emscripten_glGetShaderPrecisionFormat,
|
|
"emscripten_glGetShaderiv": _emscripten_glGetShaderiv,
|
|
"emscripten_glGetString": _emscripten_glGetString,
|
|
"emscripten_glGetStringi": _emscripten_glGetStringi,
|
|
"emscripten_glGetUniformLocation": _emscripten_glGetUniformLocation,
|
|
"emscripten_glInvalidateFramebuffer": _emscripten_glInvalidateFramebuffer,
|
|
"emscripten_glInvalidateSubFramebuffer": _emscripten_glInvalidateSubFramebuffer,
|
|
"emscripten_glIsSync": _emscripten_glIsSync,
|
|
"emscripten_glIsTexture": _emscripten_glIsTexture,
|
|
"emscripten_glLineWidth": _emscripten_glLineWidth,
|
|
"emscripten_glLinkProgram": _emscripten_glLinkProgram,
|
|
"emscripten_glMultiDrawArraysInstancedBaseInstanceWEBGL": _emscripten_glMultiDrawArraysInstancedBaseInstanceWEBGL,
|
|
"emscripten_glMultiDrawElementsInstancedBaseVertexBaseInstanceWEBGL": _emscripten_glMultiDrawElementsInstancedBaseVertexBaseInstanceWEBGL,
|
|
"emscripten_glPixelStorei": _emscripten_glPixelStorei,
|
|
"emscripten_glReadBuffer": _emscripten_glReadBuffer,
|
|
"emscripten_glReadPixels": _emscripten_glReadPixels,
|
|
"emscripten_glRenderbufferStorage": _emscripten_glRenderbufferStorage,
|
|
"emscripten_glRenderbufferStorageMultisample": _emscripten_glRenderbufferStorageMultisample,
|
|
"emscripten_glSamplerParameterf": _emscripten_glSamplerParameterf,
|
|
"emscripten_glSamplerParameteri": _emscripten_glSamplerParameteri,
|
|
"emscripten_glSamplerParameteriv": _emscripten_glSamplerParameteriv,
|
|
"emscripten_glScissor": _emscripten_glScissor,
|
|
"emscripten_glShaderSource": _emscripten_glShaderSource,
|
|
"emscripten_glStencilFunc": _emscripten_glStencilFunc,
|
|
"emscripten_glStencilFuncSeparate": _emscripten_glStencilFuncSeparate,
|
|
"emscripten_glStencilMask": _emscripten_glStencilMask,
|
|
"emscripten_glStencilMaskSeparate": _emscripten_glStencilMaskSeparate,
|
|
"emscripten_glStencilOp": _emscripten_glStencilOp,
|
|
"emscripten_glStencilOpSeparate": _emscripten_glStencilOpSeparate,
|
|
"emscripten_glTexImage2D": _emscripten_glTexImage2D,
|
|
"emscripten_glTexParameterf": _emscripten_glTexParameterf,
|
|
"emscripten_glTexParameterfv": _emscripten_glTexParameterfv,
|
|
"emscripten_glTexParameteri": _emscripten_glTexParameteri,
|
|
"emscripten_glTexParameteriv": _emscripten_glTexParameteriv,
|
|
"emscripten_glTexStorage2D": _emscripten_glTexStorage2D,
|
|
"emscripten_glTexSubImage2D": _emscripten_glTexSubImage2D,
|
|
"emscripten_glUniform1f": _emscripten_glUniform1f,
|
|
"emscripten_glUniform1fv": _emscripten_glUniform1fv,
|
|
"emscripten_glUniform1i": _emscripten_glUniform1i,
|
|
"emscripten_glUniform1iv": _emscripten_glUniform1iv,
|
|
"emscripten_glUniform2f": _emscripten_glUniform2f,
|
|
"emscripten_glUniform2fv": _emscripten_glUniform2fv,
|
|
"emscripten_glUniform2i": _emscripten_glUniform2i,
|
|
"emscripten_glUniform2iv": _emscripten_glUniform2iv,
|
|
"emscripten_glUniform3f": _emscripten_glUniform3f,
|
|
"emscripten_glUniform3fv": _emscripten_glUniform3fv,
|
|
"emscripten_glUniform3i": _emscripten_glUniform3i,
|
|
"emscripten_glUniform3iv": _emscripten_glUniform3iv,
|
|
"emscripten_glUniform4f": _emscripten_glUniform4f,
|
|
"emscripten_glUniform4fv": _emscripten_glUniform4fv,
|
|
"emscripten_glUniform4i": _emscripten_glUniform4i,
|
|
"emscripten_glUniform4iv": _emscripten_glUniform4iv,
|
|
"emscripten_glUniformMatrix2fv": _emscripten_glUniformMatrix2fv,
|
|
"emscripten_glUniformMatrix3fv": _emscripten_glUniformMatrix3fv,
|
|
"emscripten_glUniformMatrix4fv": _emscripten_glUniformMatrix4fv,
|
|
"emscripten_glUseProgram": _emscripten_glUseProgram,
|
|
"emscripten_glVertexAttrib1f": _emscripten_glVertexAttrib1f,
|
|
"emscripten_glVertexAttrib2fv": _emscripten_glVertexAttrib2fv,
|
|
"emscripten_glVertexAttrib3fv": _emscripten_glVertexAttrib3fv,
|
|
"emscripten_glVertexAttrib4fv": _emscripten_glVertexAttrib4fv,
|
|
"emscripten_glVertexAttribDivisor": _emscripten_glVertexAttribDivisor,
|
|
"emscripten_glVertexAttribIPointer": _emscripten_glVertexAttribIPointer,
|
|
"emscripten_glVertexAttribPointer": _emscripten_glVertexAttribPointer,
|
|
"emscripten_glViewport": _emscripten_glViewport,
|
|
"emscripten_glWaitSync": _emscripten_glWaitSync,
|
|
"emscripten_memcpy_big": _emscripten_memcpy_big,
|
|
"emscripten_resize_heap": _emscripten_resize_heap,
|
|
"environ_get": _environ_get,
|
|
"environ_sizes_get": _environ_sizes_get,
|
|
"exit": _exit,
|
|
"fd_close": _fd_close,
|
|
"fd_pread": _fd_pread,
|
|
"fd_read": _fd_read,
|
|
"fd_seek": _fd_seek,
|
|
"fd_write": _fd_write,
|
|
"getTempRet0": _getTempRet0,
|
|
"invoke_ii": invoke_ii,
|
|
"invoke_iii": invoke_iii,
|
|
"invoke_iiii": invoke_iiii,
|
|
"invoke_iiiii": invoke_iiiii,
|
|
"invoke_iiiiii": invoke_iiiiii,
|
|
"invoke_iiiiiii": invoke_iiiiiii,
|
|
"invoke_iiiiiiiiii": invoke_iiiiiiiiii,
|
|
"invoke_v": invoke_v,
|
|
"invoke_vi": invoke_vi,
|
|
"invoke_vii": invoke_vii,
|
|
"invoke_viii": invoke_viii,
|
|
"invoke_viiii": invoke_viiii,
|
|
"invoke_viiiii": invoke_viiiii,
|
|
"invoke_viiiiii": invoke_viiiiii,
|
|
"invoke_viiiiiiiii": invoke_viiiiiiiii,
|
|
"setTempRet0": _setTempRet0,
|
|
"strftime_l": _strftime_l
|
|
};
|
|
var asm = createWasm();
|
|
/** @type {function(...*):?} */
|
|
var ___wasm_call_ctors = Module["___wasm_call_ctors"] = createExportWrapper("__wasm_call_ctors");
|
|
|
|
/** @type {function(...*):?} */
|
|
var _add = Module["_add"] = createExportWrapper("add");
|
|
|
|
/** @type {function(...*):?} */
|
|
var _free = Module["_free"] = createExportWrapper("free");
|
|
|
|
/** @type {function(...*):?} */
|
|
var _malloc = Module["_malloc"] = createExportWrapper("malloc");
|
|
|
|
/** @type {function(...*):?} */
|
|
var ___errno_location = Module["___errno_location"] = createExportWrapper("__errno_location");
|
|
|
|
/** @type {function(...*):?} */
|
|
var _fflush = Module["_fflush"] = createExportWrapper("fflush");
|
|
|
|
/** @type {function(...*):?} */
|
|
var _saveSetjmp = Module["_saveSetjmp"] = createExportWrapper("saveSetjmp");
|
|
|
|
/** @type {function(...*):?} */
|
|
var ___getTypeName = Module["___getTypeName"] = createExportWrapper("__getTypeName");
|
|
|
|
/** @type {function(...*):?} */
|
|
var ___embind_register_native_and_builtin_types = Module["___embind_register_native_and_builtin_types"] = createExportWrapper("__embind_register_native_and_builtin_types");
|
|
|
|
/** @type {function(...*):?} */
|
|
var ___dl_seterr = Module["___dl_seterr"] = createExportWrapper("__dl_seterr");
|
|
|
|
/** @type {function(...*):?} */
|
|
var _setThrew = Module["_setThrew"] = createExportWrapper("setThrew");
|
|
|
|
/** @type {function(...*):?} */
|
|
var _emscripten_stack_init = Module["_emscripten_stack_init"] = function() {
|
|
return (_emscripten_stack_init = Module["_emscripten_stack_init"] = Module["asm"]["emscripten_stack_init"]).apply(null, arguments);
|
|
};
|
|
|
|
/** @type {function(...*):?} */
|
|
var _emscripten_stack_get_free = Module["_emscripten_stack_get_free"] = function() {
|
|
return (_emscripten_stack_get_free = Module["_emscripten_stack_get_free"] = Module["asm"]["emscripten_stack_get_free"]).apply(null, arguments);
|
|
};
|
|
|
|
/** @type {function(...*):?} */
|
|
var _emscripten_stack_get_base = Module["_emscripten_stack_get_base"] = function() {
|
|
return (_emscripten_stack_get_base = Module["_emscripten_stack_get_base"] = Module["asm"]["emscripten_stack_get_base"]).apply(null, arguments);
|
|
};
|
|
|
|
/** @type {function(...*):?} */
|
|
var _emscripten_stack_get_end = Module["_emscripten_stack_get_end"] = function() {
|
|
return (_emscripten_stack_get_end = Module["_emscripten_stack_get_end"] = Module["asm"]["emscripten_stack_get_end"]).apply(null, arguments);
|
|
};
|
|
|
|
/** @type {function(...*):?} */
|
|
var stackSave = Module["stackSave"] = createExportWrapper("stackSave");
|
|
|
|
/** @type {function(...*):?} */
|
|
var stackRestore = Module["stackRestore"] = createExportWrapper("stackRestore");
|
|
|
|
/** @type {function(...*):?} */
|
|
var stackAlloc = Module["stackAlloc"] = createExportWrapper("stackAlloc");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_iiij = Module["dynCall_iiij"] = createExportWrapper("dynCall_iiij");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_iiiij = Module["dynCall_iiiij"] = createExportWrapper("dynCall_iiiij");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_viij = Module["dynCall_viij"] = createExportWrapper("dynCall_viij");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_viiij = Module["dynCall_viiij"] = createExportWrapper("dynCall_viiij");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_viji = Module["dynCall_viji"] = createExportWrapper("dynCall_viji");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_vijiii = Module["dynCall_vijiii"] = createExportWrapper("dynCall_vijiii");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_jiiiiii = Module["dynCall_jiiiiii"] = createExportWrapper("dynCall_jiiiiii");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_jiiiiji = Module["dynCall_jiiiiji"] = createExportWrapper("dynCall_jiiiiji");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_ji = Module["dynCall_ji"] = createExportWrapper("dynCall_ji");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_iijj = Module["dynCall_iijj"] = createExportWrapper("dynCall_iijj");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_viiiiij = Module["dynCall_viiiiij"] = createExportWrapper("dynCall_viiiiij");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_vij = Module["dynCall_vij"] = createExportWrapper("dynCall_vij");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_jii = Module["dynCall_jii"] = createExportWrapper("dynCall_jii");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_iij = Module["dynCall_iij"] = createExportWrapper("dynCall_iij");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_jiji = Module["dynCall_jiji"] = createExportWrapper("dynCall_jiji");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_viijii = Module["dynCall_viijii"] = createExportWrapper("dynCall_viijii");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_iiiiij = Module["dynCall_iiiiij"] = createExportWrapper("dynCall_iiiiij");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_iiiiijj = Module["dynCall_iiiiijj"] = createExportWrapper("dynCall_iiiiijj");
|
|
|
|
/** @type {function(...*):?} */
|
|
var dynCall_iiiiiijj = Module["dynCall_iiiiiijj"] = createExportWrapper("dynCall_iiiiiijj");
|
|
|
|
|
|
function invoke_vii(index,a1,a2) {
|
|
var sp = stackSave();
|
|
try {
|
|
getWasmTableEntry(index)(a1,a2);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_ii(index,a1) {
|
|
var sp = stackSave();
|
|
try {
|
|
return getWasmTableEntry(index)(a1);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_viiii(index,a1,a2,a3,a4) {
|
|
var sp = stackSave();
|
|
try {
|
|
getWasmTableEntry(index)(a1,a2,a3,a4);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_iii(index,a1,a2) {
|
|
var sp = stackSave();
|
|
try {
|
|
return getWasmTableEntry(index)(a1,a2);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_vi(index,a1) {
|
|
var sp = stackSave();
|
|
try {
|
|
getWasmTableEntry(index)(a1);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_iiii(index,a1,a2,a3) {
|
|
var sp = stackSave();
|
|
try {
|
|
return getWasmTableEntry(index)(a1,a2,a3);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_viiiii(index,a1,a2,a3,a4,a5) {
|
|
var sp = stackSave();
|
|
try {
|
|
getWasmTableEntry(index)(a1,a2,a3,a4,a5);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_iiiii(index,a1,a2,a3,a4) {
|
|
var sp = stackSave();
|
|
try {
|
|
return getWasmTableEntry(index)(a1,a2,a3,a4);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_viii(index,a1,a2,a3) {
|
|
var sp = stackSave();
|
|
try {
|
|
getWasmTableEntry(index)(a1,a2,a3);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_iiiiii(index,a1,a2,a3,a4,a5) {
|
|
var sp = stackSave();
|
|
try {
|
|
return getWasmTableEntry(index)(a1,a2,a3,a4,a5);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6) {
|
|
var sp = stackSave();
|
|
try {
|
|
return getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_iiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9) {
|
|
var sp = stackSave();
|
|
try {
|
|
return getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7,a8,a9);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_v(index) {
|
|
var sp = stackSave();
|
|
try {
|
|
getWasmTableEntry(index)();
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_viiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9) {
|
|
var sp = stackSave();
|
|
try {
|
|
getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7,a8,a9);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
function invoke_viiiiii(index,a1,a2,a3,a4,a5,a6) {
|
|
var sp = stackSave();
|
|
try {
|
|
getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6);
|
|
} catch(e) {
|
|
stackRestore(sp);
|
|
if (e !== e+0) throw e;
|
|
_setThrew(1, 0);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
// === Auto-generated postamble setup entry stuff ===
|
|
|
|
unexportedRuntimeFunction('ccall', false);
|
|
unexportedRuntimeFunction('cwrap', false);
|
|
unexportedRuntimeFunction('allocate', false);
|
|
unexportedRuntimeFunction('UTF8ArrayToString', false);
|
|
unexportedRuntimeFunction('UTF8ToString', false);
|
|
unexportedRuntimeFunction('stringToUTF8Array', false);
|
|
unexportedRuntimeFunction('stringToUTF8', false);
|
|
unexportedRuntimeFunction('lengthBytesUTF8', false);
|
|
unexportedRuntimeFunction('addOnPreRun', false);
|
|
unexportedRuntimeFunction('addOnInit', false);
|
|
unexportedRuntimeFunction('addOnPreMain', false);
|
|
unexportedRuntimeFunction('addOnExit', false);
|
|
unexportedRuntimeFunction('addOnPostRun', false);
|
|
unexportedRuntimeFunction('addRunDependency', true);
|
|
unexportedRuntimeFunction('removeRunDependency', true);
|
|
unexportedRuntimeFunction('FS_createFolder', false);
|
|
unexportedRuntimeFunction('FS_createPath', true);
|
|
unexportedRuntimeFunction('FS_createDataFile', true);
|
|
unexportedRuntimeFunction('FS_createPreloadedFile', true);
|
|
unexportedRuntimeFunction('FS_createLazyFile', true);
|
|
unexportedRuntimeFunction('FS_createLink', false);
|
|
unexportedRuntimeFunction('FS_createDevice', true);
|
|
unexportedRuntimeFunction('FS_unlink', true);
|
|
unexportedRuntimeFunction('getLEB', false);
|
|
unexportedRuntimeFunction('getFunctionTables', false);
|
|
unexportedRuntimeFunction('alignFunctionTables', false);
|
|
unexportedRuntimeFunction('registerFunctions', false);
|
|
unexportedRuntimeFunction('addFunction', false);
|
|
unexportedRuntimeFunction('removeFunction', false);
|
|
unexportedRuntimeFunction('prettyPrint', false);
|
|
unexportedRuntimeFunction('getCompilerSetting', false);
|
|
unexportedRuntimeFunction('print', false);
|
|
unexportedRuntimeFunction('printErr', false);
|
|
unexportedRuntimeFunction('getTempRet0', false);
|
|
unexportedRuntimeFunction('setTempRet0', false);
|
|
unexportedRuntimeFunction('callMain', false);
|
|
unexportedRuntimeFunction('abort', false);
|
|
unexportedRuntimeFunction('keepRuntimeAlive', false);
|
|
unexportedRuntimeFunction('wasmMemory', false);
|
|
unexportedRuntimeFunction('warnOnce', false);
|
|
unexportedRuntimeFunction('stackSave', false);
|
|
unexportedRuntimeFunction('stackRestore', false);
|
|
unexportedRuntimeFunction('stackAlloc', false);
|
|
unexportedRuntimeFunction('AsciiToString', false);
|
|
unexportedRuntimeFunction('stringToAscii', false);
|
|
unexportedRuntimeFunction('UTF16ToString', false);
|
|
unexportedRuntimeFunction('stringToUTF16', false);
|
|
unexportedRuntimeFunction('lengthBytesUTF16', false);
|
|
unexportedRuntimeFunction('UTF32ToString', false);
|
|
unexportedRuntimeFunction('stringToUTF32', false);
|
|
unexportedRuntimeFunction('lengthBytesUTF32', false);
|
|
unexportedRuntimeFunction('allocateUTF8', false);
|
|
unexportedRuntimeFunction('allocateUTF8OnStack', false);
|
|
unexportedRuntimeFunction('ExitStatus', false);
|
|
unexportedRuntimeFunction('intArrayFromString', false);
|
|
unexportedRuntimeFunction('intArrayToString', false);
|
|
unexportedRuntimeFunction('writeStringToMemory', false);
|
|
unexportedRuntimeFunction('writeArrayToMemory', false);
|
|
unexportedRuntimeFunction('writeAsciiToMemory', false);
|
|
Module["writeStackCookie"] = writeStackCookie;
|
|
Module["checkStackCookie"] = checkStackCookie;
|
|
unexportedRuntimeFunction('ptrToString', false);
|
|
unexportedRuntimeFunction('zeroMemory', false);
|
|
unexportedRuntimeFunction('stringToNewUTF8', false);
|
|
unexportedRuntimeFunction('getHeapMax', false);
|
|
unexportedRuntimeFunction('emscripten_realloc_buffer', false);
|
|
unexportedRuntimeFunction('ENV', false);
|
|
unexportedRuntimeFunction('ERRNO_CODES', false);
|
|
unexportedRuntimeFunction('ERRNO_MESSAGES', false);
|
|
unexportedRuntimeFunction('setErrNo', false);
|
|
unexportedRuntimeFunction('inetPton4', false);
|
|
unexportedRuntimeFunction('inetNtop4', false);
|
|
unexportedRuntimeFunction('inetPton6', false);
|
|
unexportedRuntimeFunction('inetNtop6', false);
|
|
unexportedRuntimeFunction('readSockaddr', false);
|
|
unexportedRuntimeFunction('writeSockaddr', false);
|
|
unexportedRuntimeFunction('DNS', false);
|
|
unexportedRuntimeFunction('getHostByName', false);
|
|
unexportedRuntimeFunction('Protocols', false);
|
|
unexportedRuntimeFunction('Sockets', false);
|
|
unexportedRuntimeFunction('getRandomDevice', false);
|
|
unexportedRuntimeFunction('traverseStack', false);
|
|
unexportedRuntimeFunction('UNWIND_CACHE', false);
|
|
unexportedRuntimeFunction('convertPCtoSourceLocation', false);
|
|
unexportedRuntimeFunction('readAsmConstArgsArray', false);
|
|
unexportedRuntimeFunction('readAsmConstArgs', false);
|
|
unexportedRuntimeFunction('mainThreadEM_ASM', false);
|
|
unexportedRuntimeFunction('jstoi_q', false);
|
|
unexportedRuntimeFunction('jstoi_s', false);
|
|
unexportedRuntimeFunction('getExecutableName', false);
|
|
unexportedRuntimeFunction('listenOnce', false);
|
|
unexportedRuntimeFunction('autoResumeAudioContext', false);
|
|
unexportedRuntimeFunction('dynCallLegacy', false);
|
|
unexportedRuntimeFunction('getDynCaller', false);
|
|
unexportedRuntimeFunction('dynCall', false);
|
|
unexportedRuntimeFunction('handleException', false);
|
|
unexportedRuntimeFunction('runtimeKeepalivePush', false);
|
|
unexportedRuntimeFunction('runtimeKeepalivePop', false);
|
|
unexportedRuntimeFunction('callUserCallback', false);
|
|
unexportedRuntimeFunction('maybeExit', false);
|
|
unexportedRuntimeFunction('safeSetTimeout', false);
|
|
unexportedRuntimeFunction('asmjsMangle', false);
|
|
unexportedRuntimeFunction('asyncLoad', false);
|
|
unexportedRuntimeFunction('alignMemory', false);
|
|
unexportedRuntimeFunction('mmapAlloc', false);
|
|
unexportedRuntimeFunction('writeI53ToI64', false);
|
|
unexportedRuntimeFunction('writeI53ToI64Clamped', false);
|
|
unexportedRuntimeFunction('writeI53ToI64Signaling', false);
|
|
unexportedRuntimeFunction('writeI53ToU64Clamped', false);
|
|
unexportedRuntimeFunction('writeI53ToU64Signaling', false);
|
|
unexportedRuntimeFunction('readI53FromI64', false);
|
|
unexportedRuntimeFunction('readI53FromU64', false);
|
|
unexportedRuntimeFunction('convertI32PairToI53', false);
|
|
unexportedRuntimeFunction('convertI32PairToI53Checked', false);
|
|
unexportedRuntimeFunction('convertU32PairToI53', false);
|
|
unexportedRuntimeFunction('reallyNegative', false);
|
|
unexportedRuntimeFunction('unSign', false);
|
|
unexportedRuntimeFunction('strLen', false);
|
|
unexportedRuntimeFunction('reSign', false);
|
|
unexportedRuntimeFunction('formatString', false);
|
|
unexportedRuntimeFunction('setValue', false);
|
|
unexportedRuntimeFunction('getValue', false);
|
|
unexportedRuntimeFunction('PATH', false);
|
|
unexportedRuntimeFunction('PATH_FS', false);
|
|
unexportedRuntimeFunction('SYSCALLS', false);
|
|
unexportedRuntimeFunction('getSocketFromFD', false);
|
|
unexportedRuntimeFunction('getSocketAddress', false);
|
|
unexportedRuntimeFunction('JSEvents', false);
|
|
unexportedRuntimeFunction('registerKeyEventCallback', false);
|
|
unexportedRuntimeFunction('specialHTMLTargets', false);
|
|
unexportedRuntimeFunction('maybeCStringToJsString', false);
|
|
unexportedRuntimeFunction('findEventTarget', false);
|
|
unexportedRuntimeFunction('findCanvasEventTarget', false);
|
|
unexportedRuntimeFunction('getBoundingClientRect', false);
|
|
unexportedRuntimeFunction('fillMouseEventData', false);
|
|
unexportedRuntimeFunction('registerMouseEventCallback', false);
|
|
unexportedRuntimeFunction('registerWheelEventCallback', false);
|
|
unexportedRuntimeFunction('registerUiEventCallback', false);
|
|
unexportedRuntimeFunction('registerFocusEventCallback', false);
|
|
unexportedRuntimeFunction('fillDeviceOrientationEventData', false);
|
|
unexportedRuntimeFunction('registerDeviceOrientationEventCallback', false);
|
|
unexportedRuntimeFunction('fillDeviceMotionEventData', false);
|
|
unexportedRuntimeFunction('registerDeviceMotionEventCallback', false);
|
|
unexportedRuntimeFunction('screenOrientation', false);
|
|
unexportedRuntimeFunction('fillOrientationChangeEventData', false);
|
|
unexportedRuntimeFunction('registerOrientationChangeEventCallback', false);
|
|
unexportedRuntimeFunction('fillFullscreenChangeEventData', false);
|
|
unexportedRuntimeFunction('registerFullscreenChangeEventCallback', false);
|
|
unexportedRuntimeFunction('JSEvents_requestFullscreen', false);
|
|
unexportedRuntimeFunction('JSEvents_resizeCanvasForFullscreen', false);
|
|
unexportedRuntimeFunction('registerRestoreOldStyle', false);
|
|
unexportedRuntimeFunction('hideEverythingExceptGivenElement', false);
|
|
unexportedRuntimeFunction('restoreHiddenElements', false);
|
|
unexportedRuntimeFunction('setLetterbox', false);
|
|
unexportedRuntimeFunction('currentFullscreenStrategy', false);
|
|
unexportedRuntimeFunction('restoreOldWindowedStyle', false);
|
|
unexportedRuntimeFunction('softFullscreenResizeWebGLRenderTarget', false);
|
|
unexportedRuntimeFunction('doRequestFullscreen', false);
|
|
unexportedRuntimeFunction('fillPointerlockChangeEventData', false);
|
|
unexportedRuntimeFunction('registerPointerlockChangeEventCallback', false);
|
|
unexportedRuntimeFunction('registerPointerlockErrorEventCallback', false);
|
|
unexportedRuntimeFunction('requestPointerLock', false);
|
|
unexportedRuntimeFunction('fillVisibilityChangeEventData', false);
|
|
unexportedRuntimeFunction('registerVisibilityChangeEventCallback', false);
|
|
unexportedRuntimeFunction('registerTouchEventCallback', false);
|
|
unexportedRuntimeFunction('fillGamepadEventData', false);
|
|
unexportedRuntimeFunction('registerGamepadEventCallback', false);
|
|
unexportedRuntimeFunction('registerBeforeUnloadEventCallback', false);
|
|
unexportedRuntimeFunction('fillBatteryEventData', false);
|
|
unexportedRuntimeFunction('battery', false);
|
|
unexportedRuntimeFunction('registerBatteryEventCallback', false);
|
|
unexportedRuntimeFunction('setCanvasElementSize', false);
|
|
unexportedRuntimeFunction('getCanvasElementSize', false);
|
|
unexportedRuntimeFunction('demangle', false);
|
|
unexportedRuntimeFunction('demangleAll', false);
|
|
unexportedRuntimeFunction('jsStackTrace', false);
|
|
unexportedRuntimeFunction('stackTrace', false);
|
|
unexportedRuntimeFunction('getEnvStrings', false);
|
|
unexportedRuntimeFunction('checkWasiClock', false);
|
|
unexportedRuntimeFunction('flush_NO_FILESYSTEM', false);
|
|
unexportedRuntimeFunction('dlopenMissingError', false);
|
|
unexportedRuntimeFunction('setImmediateWrapped', false);
|
|
unexportedRuntimeFunction('clearImmediateWrapped', false);
|
|
unexportedRuntimeFunction('polyfillSetImmediate', false);
|
|
unexportedRuntimeFunction('uncaughtExceptionCount', false);
|
|
unexportedRuntimeFunction('exceptionLast', false);
|
|
unexportedRuntimeFunction('exceptionCaught', false);
|
|
unexportedRuntimeFunction('ExceptionInfo', false);
|
|
unexportedRuntimeFunction('exception_addRef', false);
|
|
unexportedRuntimeFunction('exception_decRef', false);
|
|
unexportedRuntimeFunction('Browser', false);
|
|
unexportedRuntimeFunction('setMainLoop', false);
|
|
unexportedRuntimeFunction('wget', false);
|
|
unexportedRuntimeFunction('tempFixedLengthArray', false);
|
|
unexportedRuntimeFunction('miniTempWebGLFloatBuffers', false);
|
|
unexportedRuntimeFunction('heapObjectForWebGLType', false);
|
|
unexportedRuntimeFunction('heapAccessShiftForWebGLHeap', false);
|
|
unexportedRuntimeFunction('GL', false);
|
|
unexportedRuntimeFunction('emscriptenWebGLGet', false);
|
|
unexportedRuntimeFunction('computeUnpackAlignedImageSize', false);
|
|
unexportedRuntimeFunction('emscriptenWebGLGetTexPixelData', false);
|
|
unexportedRuntimeFunction('emscriptenWebGLGetUniform', false);
|
|
unexportedRuntimeFunction('webglGetUniformLocation', false);
|
|
unexportedRuntimeFunction('webglPrepareUniformLocationsBeforeFirstUse', false);
|
|
unexportedRuntimeFunction('webglGetLeftBracePos', false);
|
|
unexportedRuntimeFunction('emscriptenWebGLGetVertexAttrib', false);
|
|
unexportedRuntimeFunction('writeGLArray', false);
|
|
unexportedRuntimeFunction('AL', false);
|
|
unexportedRuntimeFunction('SDL_unicode', false);
|
|
unexportedRuntimeFunction('SDL_ttfContext', false);
|
|
unexportedRuntimeFunction('SDL_audio', false);
|
|
unexportedRuntimeFunction('SDL', false);
|
|
unexportedRuntimeFunction('SDL_gfx', false);
|
|
unexportedRuntimeFunction('GLUT', false);
|
|
unexportedRuntimeFunction('EGL', false);
|
|
unexportedRuntimeFunction('GLFW_Window', false);
|
|
unexportedRuntimeFunction('GLFW', false);
|
|
unexportedRuntimeFunction('GLEW', false);
|
|
unexportedRuntimeFunction('IDBStore', false);
|
|
unexportedRuntimeFunction('runAndAbortIfError', false);
|
|
unexportedRuntimeFunction('emscriptenWebGLGetIndexed', false);
|
|
unexportedRuntimeFunction('InternalError', false);
|
|
unexportedRuntimeFunction('BindingError', false);
|
|
unexportedRuntimeFunction('UnboundTypeError', false);
|
|
unexportedRuntimeFunction('PureVirtualError', false);
|
|
unexportedRuntimeFunction('init_embind', false);
|
|
unexportedRuntimeFunction('throwInternalError', false);
|
|
unexportedRuntimeFunction('throwBindingError', false);
|
|
unexportedRuntimeFunction('throwUnboundTypeError', false);
|
|
unexportedRuntimeFunction('ensureOverloadTable', false);
|
|
unexportedRuntimeFunction('exposePublicSymbol', false);
|
|
unexportedRuntimeFunction('replacePublicSymbol', false);
|
|
unexportedRuntimeFunction('extendError', false);
|
|
unexportedRuntimeFunction('createNamedFunction', false);
|
|
unexportedRuntimeFunction('embindRepr', false);
|
|
unexportedRuntimeFunction('registeredInstances', false);
|
|
unexportedRuntimeFunction('getBasestPointer', false);
|
|
unexportedRuntimeFunction('registerInheritedInstance', false);
|
|
unexportedRuntimeFunction('unregisterInheritedInstance', false);
|
|
unexportedRuntimeFunction('getInheritedInstance', false);
|
|
unexportedRuntimeFunction('getInheritedInstanceCount', false);
|
|
unexportedRuntimeFunction('getLiveInheritedInstances', false);
|
|
unexportedRuntimeFunction('registeredTypes', false);
|
|
unexportedRuntimeFunction('awaitingDependencies', false);
|
|
unexportedRuntimeFunction('typeDependencies', false);
|
|
unexportedRuntimeFunction('registeredPointers', false);
|
|
unexportedRuntimeFunction('registerType', false);
|
|
unexportedRuntimeFunction('whenDependentTypesAreResolved', false);
|
|
unexportedRuntimeFunction('embind_charCodes', false);
|
|
unexportedRuntimeFunction('embind_init_charCodes', false);
|
|
unexportedRuntimeFunction('readLatin1String', false);
|
|
unexportedRuntimeFunction('getTypeName', false);
|
|
unexportedRuntimeFunction('heap32VectorToArray', false);
|
|
unexportedRuntimeFunction('requireRegisteredType', false);
|
|
unexportedRuntimeFunction('getShiftFromSize', false);
|
|
unexportedRuntimeFunction('integerReadValueFromPointer', false);
|
|
unexportedRuntimeFunction('enumReadValueFromPointer', false);
|
|
unexportedRuntimeFunction('floatReadValueFromPointer', false);
|
|
unexportedRuntimeFunction('simpleReadValueFromPointer', false);
|
|
unexportedRuntimeFunction('runDestructors', false);
|
|
unexportedRuntimeFunction('new_', false);
|
|
unexportedRuntimeFunction('craftInvokerFunction', false);
|
|
unexportedRuntimeFunction('embind__requireFunction', false);
|
|
unexportedRuntimeFunction('tupleRegistrations', false);
|
|
unexportedRuntimeFunction('structRegistrations', false);
|
|
unexportedRuntimeFunction('genericPointerToWireType', false);
|
|
unexportedRuntimeFunction('constNoSmartPtrRawPointerToWireType', false);
|
|
unexportedRuntimeFunction('nonConstNoSmartPtrRawPointerToWireType', false);
|
|
unexportedRuntimeFunction('init_RegisteredPointer', false);
|
|
unexportedRuntimeFunction('RegisteredPointer', false);
|
|
unexportedRuntimeFunction('RegisteredPointer_getPointee', false);
|
|
unexportedRuntimeFunction('RegisteredPointer_destructor', false);
|
|
unexportedRuntimeFunction('RegisteredPointer_deleteObject', false);
|
|
unexportedRuntimeFunction('RegisteredPointer_fromWireType', false);
|
|
unexportedRuntimeFunction('runDestructor', false);
|
|
unexportedRuntimeFunction('releaseClassHandle', false);
|
|
unexportedRuntimeFunction('finalizationRegistry', false);
|
|
unexportedRuntimeFunction('detachFinalizer_deps', false);
|
|
unexportedRuntimeFunction('detachFinalizer', false);
|
|
unexportedRuntimeFunction('attachFinalizer', false);
|
|
unexportedRuntimeFunction('makeClassHandle', false);
|
|
unexportedRuntimeFunction('init_ClassHandle', false);
|
|
unexportedRuntimeFunction('ClassHandle', false);
|
|
unexportedRuntimeFunction('ClassHandle_isAliasOf', false);
|
|
unexportedRuntimeFunction('throwInstanceAlreadyDeleted', false);
|
|
unexportedRuntimeFunction('ClassHandle_clone', false);
|
|
unexportedRuntimeFunction('ClassHandle_delete', false);
|
|
unexportedRuntimeFunction('deletionQueue', false);
|
|
unexportedRuntimeFunction('ClassHandle_isDeleted', false);
|
|
unexportedRuntimeFunction('ClassHandle_deleteLater', false);
|
|
unexportedRuntimeFunction('flushPendingDeletes', false);
|
|
unexportedRuntimeFunction('delayFunction', false);
|
|
unexportedRuntimeFunction('setDelayFunction', false);
|
|
unexportedRuntimeFunction('RegisteredClass', false);
|
|
unexportedRuntimeFunction('shallowCopyInternalPointer', false);
|
|
unexportedRuntimeFunction('downcastPointer', false);
|
|
unexportedRuntimeFunction('upcastPointer', false);
|
|
unexportedRuntimeFunction('validateThis', false);
|
|
unexportedRuntimeFunction('char_0', false);
|
|
unexportedRuntimeFunction('char_9', false);
|
|
unexportedRuntimeFunction('makeLegalFunctionName', false);
|
|
unexportedRuntimeFunction('emval_handle_array', false);
|
|
unexportedRuntimeFunction('emval_free_list', false);
|
|
unexportedRuntimeFunction('emval_symbols', false);
|
|
unexportedRuntimeFunction('init_emval', false);
|
|
unexportedRuntimeFunction('count_emval_handles', false);
|
|
unexportedRuntimeFunction('get_first_emval', false);
|
|
unexportedRuntimeFunction('getStringOrSymbol', false);
|
|
unexportedRuntimeFunction('Emval', false);
|
|
unexportedRuntimeFunction('emval_newers', false);
|
|
unexportedRuntimeFunction('craftEmvalAllocator', false);
|
|
unexportedRuntimeFunction('emval_get_global', false);
|
|
unexportedRuntimeFunction('emval_lookupTypes', false);
|
|
unexportedRuntimeFunction('emval_allocateDestructors', false);
|
|
unexportedRuntimeFunction('emval_methodCallers', false);
|
|
unexportedRuntimeFunction('emval_addMethodCaller', false);
|
|
unexportedRuntimeFunction('emval_registeredMethods', false);
|
|
unexportedRuntimeSymbol('ALLOC_NORMAL', false);
|
|
unexportedRuntimeSymbol('ALLOC_STACK', false);
|
|
|
|
var calledRun;
|
|
|
|
/**
|
|
* @constructor
|
|
* @this {ExitStatus}
|
|
*/
|
|
function ExitStatus(status) {
|
|
this.name = "ExitStatus";
|
|
this.message = "Program terminated with exit(" + status + ")";
|
|
this.status = status;
|
|
}
|
|
|
|
var calledMain = false;
|
|
|
|
dependenciesFulfilled = function runCaller() {
|
|
// If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
|
|
if (!calledRun) run();
|
|
if (!calledRun) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
|
|
};
|
|
|
|
function stackCheckInit() {
|
|
// This is normally called automatically during __wasm_call_ctors but need to
|
|
// get these values before even running any of the ctors so we call it redundantly
|
|
// here.
|
|
_emscripten_stack_init();
|
|
// TODO(sbc): Move writeStackCookie to native to to avoid this.
|
|
writeStackCookie();
|
|
}
|
|
|
|
/** @type {function(Array=)} */
|
|
function run(args) {
|
|
args = args || arguments_;
|
|
|
|
if (runDependencies > 0) {
|
|
return;
|
|
}
|
|
|
|
stackCheckInit();
|
|
|
|
preRun();
|
|
|
|
// a preRun added a dependency, run will be called later
|
|
if (runDependencies > 0) {
|
|
return;
|
|
}
|
|
|
|
function doRun() {
|
|
// run may have just been called through dependencies being fulfilled just in this very frame,
|
|
// or while the async setStatus time below was happening
|
|
if (calledRun) return;
|
|
calledRun = true;
|
|
Module['calledRun'] = true;
|
|
|
|
if (ABORT) return;
|
|
|
|
initRuntime();
|
|
|
|
readyPromiseResolve(Module);
|
|
if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
|
|
|
|
assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
|
|
|
|
postRun();
|
|
}
|
|
|
|
if (Module['setStatus']) {
|
|
Module['setStatus']('Running...');
|
|
setTimeout(function() {
|
|
setTimeout(function() {
|
|
Module['setStatus']('');
|
|
}, 1);
|
|
doRun();
|
|
}, 1);
|
|
} else
|
|
{
|
|
doRun();
|
|
}
|
|
checkStackCookie();
|
|
}
|
|
Module['run'] = run;
|
|
|
|
function checkUnflushedContent() {
|
|
// Compiler settings do not allow exiting the runtime, so flushing
|
|
// the streams is not possible. but in ASSERTIONS mode we check
|
|
// if there was something to flush, and if so tell the user they
|
|
// should request that the runtime be exitable.
|
|
// Normally we would not even include flush() at all, but in ASSERTIONS
|
|
// builds we do so just for this check, and here we see if there is any
|
|
// content to flush, that is, we check if there would have been
|
|
// something a non-ASSERTIONS build would have not seen.
|
|
// How we flush the streams depends on whether we are in SYSCALLS_REQUIRE_FILESYSTEM=0
|
|
// mode (which has its own special function for this; otherwise, all
|
|
// the code is inside libc)
|
|
var oldOut = out;
|
|
var oldErr = err;
|
|
var has = false;
|
|
out = err = (x) => {
|
|
has = true;
|
|
}
|
|
try { // it doesn't matter if it fails
|
|
flush_NO_FILESYSTEM();
|
|
} catch(e) {}
|
|
out = oldOut;
|
|
err = oldErr;
|
|
if (has) {
|
|
warnOnce('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline when you printf etc.');
|
|
warnOnce('(this may also be due to not including full filesystem support - try building with -sFORCE_FILESYSTEM)');
|
|
}
|
|
}
|
|
|
|
/** @param {boolean|number=} implicit */
|
|
function exit(status, implicit) {
|
|
EXITSTATUS = status;
|
|
|
|
checkUnflushedContent();
|
|
|
|
// if exit() was called explicitly, warn the user if the runtime isn't actually being shut down
|
|
if (keepRuntimeAlive() && !implicit) {
|
|
var msg = 'program exited (with status: ' + status + '), but EXIT_RUNTIME is not set, so halting execution but not exiting the runtime or preventing further async execution (build with EXIT_RUNTIME=1, if you want a true shutdown)';
|
|
readyPromiseReject(msg);
|
|
err(msg);
|
|
}
|
|
|
|
procExit(status);
|
|
}
|
|
|
|
function procExit(code) {
|
|
EXITSTATUS = code;
|
|
if (!keepRuntimeAlive()) {
|
|
if (Module['onExit']) Module['onExit'](code);
|
|
ABORT = true;
|
|
}
|
|
quit_(code, new ExitStatus(code));
|
|
}
|
|
|
|
if (Module['preInit']) {
|
|
if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
|
|
while (Module['preInit'].length > 0) {
|
|
Module['preInit'].pop()();
|
|
}
|
|
}
|
|
|
|
run();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Module.ready
|
|
}
|
|
);
|
|
})();
|
|
if (typeof exports === 'object' && typeof module === 'object')
|
|
module.exports = Module;
|
|
else if (typeof define === 'function' && define['amd'])
|
|
define([], function() { return Module; });
|
|
else if (typeof exports === 'object')
|
|
exports["Module"] = Module;
|