File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
packages/npm-packages/ruby-wasm-wasi/src Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ export const main = async (pkg: { name: string; version: string }) => {
4
4
const response = fetch (
5
5
`https://cdn.jsdelivr.net/npm/${ pkg . name } @${ pkg . version } /dist/ruby+stdlib.wasm` ,
6
6
) ;
7
- const module = await WebAssembly . compileStreaming ( response ) ;
7
+ const module = await compileWebAssemblyModule ( response ) ;
8
8
const { vm } = await DefaultRubyVM ( module ) ;
9
9
10
10
vm . printVersion ( ) ;
@@ -78,3 +78,18 @@ const loadScriptAsync = async (
78
78
79
79
return Promise . resolve ( { scriptContent : tag . innerHTML , evalStyle } ) ;
80
80
} ;
81
+
82
+ // WebAssembly.compileStreaming is a relatively new API.
83
+ // For example, it is not available in iOS Safari 14,
84
+ // so check whether WebAssembly.compileStreaming is available and
85
+ // fall back to the existing implementation using WebAssembly.compile if not.
86
+ const compileWebAssemblyModule = async function (
87
+ response : Promise < Response > ,
88
+ ) : Promise < WebAssembly . Module > {
89
+ if ( ! WebAssembly . compileStreaming ) {
90
+ const buffer = await ( await response ) . arrayBuffer ( ) ;
91
+ return WebAssembly . compile ( buffer ) ;
92
+ } else {
93
+ return WebAssembly . compileStreaming ( response ) ;
94
+ }
95
+ } ;
You can’t perform that action at this time.
0 commit comments