forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostamble_minimal.js
111 lines (88 loc) · 2.52 KB
/
postamble_minimal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// === Auto-generated postamble setup entry stuff ===
{{{ exportRuntime() }}}
function run() {
#if MEMORYPROFILER
emscriptenMemoryProfiler.onPreloadComplete();
#endif
#if PROXY_TO_PTHREAD
// User requested the PROXY_TO_PTHREAD option, so call a stub main which pthread_create()s a new thread
// that will call the user's real main() for the application.
var ret = _proxy_main();
#else
var ret = _main();
#endif
#if STACK_OVERFLOW_CHECK
checkStackCookie();
#endif
}
function initRuntime(asm) {
#if ASSERTIONS
runtimeInitialized = true;
#endif
#if USE_PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return;
// Pass the thread address inside the asm.js scope to store it for fast access that avoids the need for a FFI out.
__register_pthread_ptr(PThread.mainThreadBlock, /*isMainBrowserThread=*/!ENVIRONMENT_IS_WORKER, /*isMainRuntimeThread=*/1);
_emscripten_register_main_browser_thread_id(PThread.mainThreadBlock);
#endif
#if STACK_OVERFLOW_CHECK
writeStackCookie();
#endif
/*** RUN_GLOBAL_INITIALIZERS(); ***/
{{{ getQuoted('ATINITS') }}}
}
#if WASM
// Initialize wasm (asynchronous)
var imports = {
'env': asmLibraryArg
#if WASM_BACKEND == 0
, 'global': {
'NaN': NaN,
'Infinity': Infinity
},
'global.Math': Math,
'asm2wasm': {
'f64-rem': function(x, y) { return x % y; },
'debugger': function() {
#if ASSERTIONS // Disable debugger; statement from being present in release builds to avoid Firefox deoptimizations, see https://bugzilla.mozilla.org/show_bug.cgi?id=1538375
debugger;
#endif
}
}
#endif
};
#if ASSERTIONS
if (!Module['wasm']) throw 'Must load WebAssembly Module in to variable Module.wasm before adding compiled output .js script to the DOM';
#endif
#if DECLARE_ASM_MODULE_EXPORTS
/*** ASM_MODULE_EXPORTS_DECLARES ***/
#endif
WebAssembly.instantiate(Module['wasm'], imports).then(function(output) {
var asm = output.instance.exports;
#if DECLARE_ASM_MODULE_EXPORTS == 0
#if ENVIRONMENT_MAY_BE_NODE
for(var i in asm) (typeof process !== "undefined" ? global : this)[i] = Module[i] = asm[i];
#else
for(var i in asm) this[i] = Module[i] = asm[i];
#endif
#else
/*** ASM_MODULE_EXPORTS ***/
#endif
initRuntime(asm);
ready();
})
#if ASSERTIONS
.catch(function(error) {
console.error(error);
})
#endif
;
#else
// Initialize asm.js (synchronous)
#if ASSERTIONS
if (!Module['mem']) throw 'Must load memory initializer as an ArrayBuffer in to variable Module.mem before adding compiled output .js script to the DOM';
#endif
initRuntime(asm);
ready();
#endif
{{GLOBAL_VARS}}