Skip to content

Commit

Permalink
js-polyfill: support Safari, which doesn't have instantiateStreaming
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuowei authored and sunfishcode committed May 10, 2019
1 parent 072b2e8 commit ca8c8b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion wasmtime-wasi/js-polyfill/polyfill.c
Expand Up @@ -26,7 +26,7 @@ void handleFiles(void) {
let file = document.getElementById('input').files[0]; \
let file_with_mime_type = file.slice(0, file.size, 'application/wasm'); \
let response = new Response(file_with_mime_type); \
WebAssembly.instantiateStreaming(response, imports) \
wasi_instantiateStreaming(response, imports) \
.then(obj => { \
setInstance(obj.instance); \
try { \
Expand Down
11 changes: 11 additions & 0 deletions wasmtime-wasi/js-polyfill/wasi.js
Expand Up @@ -31,6 +31,17 @@ function handleWASIExit(e) {
}
}

// Safari doesn't have instantiateStreaming
function wasi_instantiateStreaming(response, imports) {
if (WebAssembly && WebAssembly.instantiateStreaming) {
return WebAssembly.instantiateStreaming(response, imports);
}
return response.arrayBuffer()
.then(function(buffer) {
return WebAssembly.instantiate(buffer, imports);
});
}

// The current guest wasm instance.
var currentInstance;

Expand Down

0 comments on commit ca8c8b3

Please sign in to comment.