File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
Plugins/PackageToJS/Templates Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ export declare const MODULE_PATH: string;
5050 * @param options - The options
5151 */
5252export declare function instantiate (
53- moduleSource : WebAssembly . Module | Response | PromiseLike < Response > ,
53+ moduleSource : WebAssembly . Module | ArrayBufferView | ArrayBuffer | Response | PromiseLike < Response > ,
5454 imports : Import ,
5555 options : { } | undefined
5656) : Promise < {
Original file line number Diff line number Diff line change @@ -48,10 +48,20 @@ export async function instantiate(
4848 if ( moduleSource instanceof WebAssembly . Module ) {
4949 module = moduleSource ;
5050 instance = await WebAssembly . instantiate ( module , importObject ) ;
51+ } else if ( typeof Response === "function" && ( moduleSource instanceof Response || moduleSource instanceof Promise ) ) {
52+ if ( typeof WebAssembly . instantiateStreaming === "function" ) {
53+ const result = await WebAssembly . instantiateStreaming ( moduleSource , importObject ) ;
54+ module = result . module ;
55+ instance = result . instance ;
56+ } else {
57+ const moduleBytes = await ( await moduleSource ) . arrayBuffer ( ) ;
58+ module = await WebAssembly . compile ( moduleBytes ) ;
59+ instance = await WebAssembly . instantiate ( module , importObject ) ;
60+ }
5161 } else {
52- const result = await WebAssembly . instantiateStreaming ( moduleSource , importObject ) ;
53- module = result . module ;
54- instance = result . instance ;
62+ // @ts -expect-error: Type 'Response' is not assignable to type 'BufferSource'
63+ module = await WebAssembly . compile ( moduleSource ) ;
64+ instance = await WebAssembly . instantiate ( module , importObject ) ;
5565 }
5666
5767 swift . setInstance ( instance ) ;
You can’t perform that action at this time.
0 commit comments