File: embind_lib_with_asyncify.test.js

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 121,860 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,366; asm: 2,415; lisp: 1,869
file content (49 lines) | stat: -rw-r--r-- 1,712 bytes parent folder | download | duplicates (2)
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
Module['onRuntimeInitialized'] = async () => {
  try {
    let delayedThrowResult = Module["delayed_throw"]();
    assert(delayedThrowResult instanceof Promise);
    let err = await delayedThrowResult.then(() => '', err => err.message);
    assert(err === 'my message', `"${err}" doesn't contain the expected error`);

    let fooResult = Module["foo"]();
    assert(fooResult instanceof Promise);
    fooResult = await fooResult;
    assert(fooResult === 10);

    let barInstancePromise = new Module["Bar"]();
    assert(barInstancePromise instanceof Promise);
    let barInstance = await barInstancePromise;
    assert(barInstance instanceof Module["Bar"]);
    assert(barInstance.x === 20);

    let barMethodResult = barInstance.method();
    assert(barMethodResult instanceof Promise);
    assert(await barMethodResult === 30);

    assert(barInstance.method_without_async_calls() === 40);
    assert(barInstance.void_method_without_async_calls() === undefined);

    barMethodResult = barInstance.void_method_with_async_calls();
    assert(barMethodResult instanceof Promise);
    assert(await barMethodResult === undefined);

    let barStaticMethodResult = Module["Bar"].static_method();
    assert(barStaticMethodResult instanceof Promise);
    assert(await barStaticMethodResult === 50);

    if (ASSERTIONS) {
      let err = '';
      try {
        barInstance.method();
        barInstance.method();
      } catch (e) {
        err = e.message;
      }
      assert(err.includes('Assertion failed: Cannot have multiple async operations in flight at once)'), `"${err}" doesn't contain the assertion error`);
    }

    console.log('ok');
  } catch (e) {
    console.log('error: ' + e.stack);
  }
};