Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/browser/test_cwrap_early.js
4150 views
1
Module['preRun'] = () => {
2
console.log('preRun');
3
// it is ok to call cwrap before the runtime is loaded. we don't need the code
4
// and everything to be ready, since cwrap just prepares to call code, it
5
// doesn't actually call it
6
var wrappedAdd = Module['cwrap']('add', 'number', ['number', 'number']);
7
// but to call the compiled code, we must wait for the runtime
8
Module['onRuntimeInitialized'] = async () => {
9
console.log('onRuntimeInitialized');
10
if (wrappedAdd(5, 6) != 11) throw '5 + 6 should be 11';
11
// report success
12
await fetch('/report_result?0');
13
window.close();
14
};
15
};
16
17