/**1* @license2* Copyright 2019 The Emscripten Authors3* SPDX-License-Identifier: MIT4*/56// wasm2js.js - enough of a polyfill for the WebAssembly object so that we can load7// wasm2js code that way.89/** @suppress{duplicate, const, checkTypes} */10var WebAssembly = {11// Note that we do not use closure quoting (this['buffer'], etc.) on these12// functions, as they are just meant for internal use. In other words, this is13// not a fully general polyfill.14/** @constructor */15Memory: function(opts) {16#if SHARED_MEMORY17this.buffer = new SharedArrayBuffer(opts['initial'] * {{{ WASM_PAGE_SIZE }}});18#else19this.buffer = new ArrayBuffer(opts['initial'] * {{{ WASM_PAGE_SIZE }}});20#endif21},2223#if RELOCATABLE24// Only needed in RELOCATABLE builds since normal builds export the table25// from the wasm module.26// Table is not a normal constructor and instead returns the array object.27// That lets us use the length property automatically, which is simpler and28// smaller (but instanceof will not report that an instance of Table is an29// instance of this function).30Table: /** @constructor */ function(opts) {31var ret = new Array(opts['initial']);32#if ALLOW_TABLE_GROWTH33ret.grow = function(by) {34ret.push(null);35};36#else37#if ASSERTIONS // without assertions we'll throw on calling the missing function38ret.grow = function(by) {39abort('Unable to grow wasm table. Build with ALLOW_TABLE_GROWTH.')40};41#endif // ASSERTIONS42#endif // ALLOW_TABLE_GROWTH43ret.set = function(i, func) {44ret[i] = func;45};46ret.get = function(i) {47return ret[i];48};49return ret;50},51#endif5253Module: function(binary) {54// TODO: use the binary and info somehow - right now the wasm2js output is embedded in55// the main JS56},5758/** @constructor */59Instance: function(module, info) {60// TODO: use the module somehow - right now the wasm2js output is embedded in61// the main JS62// This will be replaced by the actual wasm2js code.63this.exports = Module['__wasm2jsInstantiate__'](info);64},6566instantiate: /** @suppress{checkTypes} */ function(binary, info) {67return {68then: function(ok) {69var module = new WebAssembly.Module(binary);70ok({71#if SHARED_MEMORY72'module': module,73#endif74'instance': new WebAssembly.Instance(module, info)75});76#if ASSERTIONS || WASM == 2 // see postamble_minimal.js which uses .catch77// Emulate a simple WebAssembly.instantiate(..).then(()=>{}).catch(()=>{}) syntax.78return { catch: function() {} };79#endif80}81};82},8384RuntimeError: Error,8586#if !MINIMAL_RUNTIME87isWasm2js: true,88#endif89};909192