js-polyfill: support Safari, which doesn't have instantiateStreaming
This commit is contained in:
committed by
Dan Gohman
parent
072b2e8697
commit
ca8c8b3370
@@ -26,7 +26,7 @@ void handleFiles(void) {
|
|||||||
let file = document.getElementById('input').files[0]; \
|
let file = document.getElementById('input').files[0]; \
|
||||||
let file_with_mime_type = file.slice(0, file.size, 'application/wasm'); \
|
let file_with_mime_type = file.slice(0, file.size, 'application/wasm'); \
|
||||||
let response = new Response(file_with_mime_type); \
|
let response = new Response(file_with_mime_type); \
|
||||||
WebAssembly.instantiateStreaming(response, imports) \
|
wasi_instantiateStreaming(response, imports) \
|
||||||
.then(obj => { \
|
.then(obj => { \
|
||||||
setInstance(obj.instance); \
|
setInstance(obj.instance); \
|
||||||
try { \
|
try { \
|
||||||
|
|||||||
@@ -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.
|
// The current guest wasm instance.
|
||||||
var currentInstance;
|
var currentInstance;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user