File tree 2 files changed +14
-4
lines changed
Plugins/PackageToJS/Templates
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;
50
50
* @param options - The options
51
51
*/
52
52
export declare function instantiate (
53
- moduleSource : WebAssembly . Module | Response | PromiseLike < Response > ,
53
+ moduleSource : WebAssembly . Module | ArrayBufferView | ArrayBuffer | Response | PromiseLike < Response > ,
54
54
imports : Import ,
55
55
options : { } | undefined
56
56
) : Promise < {
Original file line number Diff line number Diff line change @@ -48,10 +48,20 @@ export async function instantiate(
48
48
if ( moduleSource instanceof WebAssembly . Module ) {
49
49
module = moduleSource ;
50
50
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
+ }
51
61
} 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 ) ;
55
65
}
56
66
57
67
swift . setInstance ( instance ) ;
You can’t perform that action at this time.
0 commit comments