diff options
-rw-r--r-- | src/plugins/platforms/wasm/qtloader.js | 7 | ||||
-rw-r--r-- | tests/manual/wasm/qtloader_integration/test_body.js | 22 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/plugins/platforms/wasm/qtloader.js b/src/plugins/platforms/wasm/qtloader.js index 24f20b18d5..c62b3f8823 100644 --- a/src/plugins/platforms/wasm/qtloader.js +++ b/src/plugins/platforms/wasm/qtloader.js @@ -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) { diff --git a/tests/manual/wasm/qtloader_integration/test_body.js b/tests/manual/wasm/qtloader_integration/test_body.js index f23db3a978..d68c6ba8cc 100644 --- a/tests/manual/wasm/qtloader_integration/test_body.js +++ b/tests/manual/wasm/qtloader_integration/test_body.js @@ -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) { |