Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/src/postamble_modularize.js
4128 views
1
// In MODULARIZE mode we wrap the generated code in a factory function
2
// and return either the Module itself, or a promise of the module.
3
//
4
// We assign to the `moduleRtn` global here and configure closure to see
5
// this as and extern so it won't get minified.
6
7
if (runtimeInitialized) {
8
moduleRtn = Module;
9
} else {
10
// Set up the promise that indicates the Module is initialized
11
moduleRtn = new Promise((resolve, reject) => {
12
readyPromiseResolve = resolve;
13
readyPromiseReject = reject;
14
});
15
}
16
17
#if ASSERTIONS
18
// Assertion for attempting to access module properties on the incoming
19
// moduleArg. In the past we used this object as the prototype of the module
20
// and assigned properties to it, but now we return a distinct object. This
21
// keeps the instance private until it is ready (i.e the promise has been
22
// resolved).
23
for (const prop of Object.keys(Module)) {
24
if (!(prop in moduleArg)) {
25
Object.defineProperty(moduleArg, prop, {
26
configurable: true,
27
get() {
28
abort(`Access to module property ('${prop}') is no longer possible via the module constructor argument; Instead, use the result of the module constructor.`)
29
}
30
});
31
}
32
}
33
#endif
34
35