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 }) => {
44 const response = fetch (
55 `https://cdn.jsdelivr.net/npm/${ pkg . name } @${ pkg . version } /dist/ruby+stdlib.wasm` ,
66 ) ;
7- const module = await WebAssembly . compileStreaming ( response ) ;
7+ const module = await compileWebAssemblyModule ( response ) ;
88 const { vm } = await DefaultRubyVM ( module ) ;
99
1010 vm . printVersion ( ) ;
@@ -78,3 +78,18 @@ const loadScriptAsync = async (
7878
7979 return Promise . resolve ( { scriptContent : tag . innerHTML , evalStyle } ) ;
8080} ;
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