File: test_cwrap_early.js

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 121,872 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,365; asm: 2,415; lisp: 1,869
file content (15 lines) | stat: -rw-r--r-- 638 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Module['preRun'] = () => {
  console.log('preRun');
  // it is ok to call cwrap before the runtime is loaded. we don't need the code
  // and everything to be ready, since cwrap just prepares to call code, it 
  // doesn't actually call it
  var wrappedAdd = Module['cwrap']('add', 'number', ['number', 'number']);
  // but to call the compiled code, we must wait for the runtime
  Module['onRuntimeInitialized'] = async () => {
    console.log('onRuntimeInitialized');
    if (wrappedAdd(5, 6) != 11) throw '5 + 6 should be 11';
    // report success
    await fetch('http://localhost:8888/report_result?0');
    window.close();
  };
};