blob: d8d3a59a4671e69ac2075fc2391c8f964794210c [file] [log] [blame]
// In MODULARIZE mode we wrap the generated code in a factory function
// and return either the Module itself, or a promise of the module.
//
// We assign to the `moduleRtn` global here and configure closure to see
// this as and extern so it won't get minified.
#if WASM_ASYNC_COMPILATION
#if USE_READY_PROMISE
moduleRtn = readyPromise;
#else
moduleRtn = {};
#endif
#else // WASM_ASYNC_COMPILATION
moduleRtn = Module;
#endif // WASM_ASYNC_COMPILATION
#if ASSERTIONS
// Assertion for attempting to access module properties on the incoming
// moduleArg. In the past we used this object as the prototype of the module
// and assigned properties to it, but now we return a distinct object. This
// keeps the instance private until it is ready (i.e the promise has been
// resolved).
for (const prop of Object.keys(Module)) {
if (!(prop in moduleArg)) {
Object.defineProperty(moduleArg, prop, {
configurable: true,
get() {
abort(`Access to module property ('${prop}') is no longer possible via the module constructor argument; Instead, use the result of the module constructor.`)
}
});
}
}
#endif