wasm: Document (and rename) config.qt.module

This property can take a either a WebAssembly.Module
or a promise to a module, and we don't have to specify
the exact type in the property name.

Pick-to: 6.6
Change-Id: Iebaf52178253afe8c93cf78bbe0853461bf48b67
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
This commit is contained in:
Morten Sørvig 2023-06-09 11:19:52 +02:00
parent c2988de88d
commit bc340abe87
2 changed files with 22 additions and 7 deletions

View File

@ -21,6 +21,9 @@
* Called when the module has loaded.
* - entryFunction: (emscriptenConfig: object) => Promise<EmscriptenModule>
* Qt always uses emscripten's MODULARIZE option. This is the MODULARIZE entry function.
* - module: Promise<WebAssembly.Module>
* The module to create the instance from (optional). Specifying the module allows optimizing
* use cases where several instances are created from a single WebAssembly source.
*
* @return Promise<instance: EmscriptenModule>
* The promise is resolved when the module has been instantiated and its main function has been
@ -60,11 +63,11 @@ async function qtLoad(config)
const circuitBreaker = new Promise((_, reject) => { circuitBreakerReject = reject; });
// If module async getter is present, use it so that module reuse is possible.
if (config.qt.modulePromise) {
if (config.qt.module) {
config.instantiateWasm = async (imports, successCallback) =>
{
try {
const module = await config.qt.modulePromise;
const module = await config.qt.module;
successCallback(
await WebAssembly.instantiate(module, imports), module);
} catch (e) {

View File

@ -177,7 +177,7 @@ export class QtLoaderIntegrationTests
// Fetch/Compile the module once; reuse for each instance. This is also if the page wants to
// initiate the .wasm file download fetch as early as possible, before the browser has
// finished fetching and parsing testapp.js and qtloader.js
const modulePromise = WebAssembly.compileStreaming(fetch('tst_qtloader_integration.wasm'));
const module = WebAssembly.compileStreaming(fetch('tst_qtloader_integration.wasm'));
const instances = await Promise.all([1, 2, 3].map(i => qtLoad({
qt: {
@ -186,7 +186,7 @@ export class QtLoaderIntegrationTests
width: `${i * 10}px`,
height: `${i * 10}px`,
})],
modulePromise,
module,
}
})));
// Confirm the identity of instances by querying their screen widths and heights
@ -230,14 +230,26 @@ export class QtLoaderIntegrationTests
assert.equal('Sample output!', accumulatedStdout);
}
async modulePromiseProvided()
{
await qtLoad({
qt: {
entryFunction: createQtAppInstance,
containerElements: [this.#testScreenContainers[0]],
module: WebAssembly.compileStreaming(
fetch('tst_qtloader_integration.wasm'))
}
});
}
async moduleProvided()
{
await qtLoad({
qt: {
entryFunction: createQtAppInstance,
containerElements: [this.#testScreenContainers[0]],
modulePromise: WebAssembly.compileStreaming(
await fetch('tst_qtloader_integration.wasm'))
module: await WebAssembly.compileStreaming(
fetch('tst_qtloader_integration.wasm'))
}
});
}
@ -265,7 +277,7 @@ export class QtLoaderIntegrationTests
qt: {
entryFunction: createQtAppInstance,
containerElements: [this.#testScreenContainers[0]],
modulePromise: Promise.reject(new Error('Failed to load')),
module: Promise.reject(new Error('Failed to load')),
}
});
} catch (e) {