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);
}
};
|