Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled rejection #8558

Merged
merged 10 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,6 @@ a license to everyone to use it as detailed in LICENSE.)
* Simon Cooper <[email protected]>
* Amir Rasouli <[email protected]>
* Nico Weber <[email protected]>
* Bas Doorn <[email protected]> (copyright owned by Keyn B.V.)
* Adam Bujalski <[email protected]> (copyright owner by Samsung Electronics)
* Guanzhong Chen <[email protected]> (copyright owned by Google, Inc.)
97 changes: 54 additions & 43 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -1019,22 +1019,6 @@ function createWasm(env) {
addRunDependency('wasm-instantiate');
#endif

// User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
// to manually instantiate the Wasm module themselves. This allows pages to run the instantiation parallel
// to any other async startup actions they are performing.
if (Module['instantiateWasm']) {
try {
return Module['instantiateWasm'](info, receiveInstance);
} catch(e) {
err('Module.instantiateWasm callback failed with error: ' + e);
return false;
}
}

#if WASM_ASYNC_COMPILATION
#if RUNTIME_LOGGING
err('asynchronously preparing wasm');
#endif
#if ASSERTIONS
// Async compilation can be confusing when an error on the page overwrites Module
// (for example, if the order of elements is wrong, and the one defining Module is
Expand All @@ -1056,45 +1040,72 @@ function createWasm(env) {
receiveInstance(output['instance']);
#endif
}

function instantiateArrayBuffer(receiver) {
getBinaryPromise().then(function(binary) {
return getBinaryPromise().then(function(binary) {
return WebAssembly.instantiate(binary, info);
}).then(receiver, function(reason) {
err('failed to asynchronously prepare wasm: ' + reason);
abort(reason);
});
}

// Prefer streaming instantiation if available.
if (!Module['wasmBinary'] &&
typeof WebAssembly.instantiateStreaming === 'function' &&
!isDataURI(wasmBinaryFile) &&
typeof fetch === 'function') {
WebAssembly.instantiateStreaming(fetch(wasmBinaryFile, { credentials: 'same-origin' }), info)
.then(receiveInstantiatedSource, function(reason) {
// We expect the most common failure cause to be a bad MIME type for the binary,
// in which case falling back to ArrayBuffer instantiation should work.
err('wasm streaming compile failed: ' + reason);
err('falling back to ArrayBuffer instantiation');
instantiateArrayBuffer(receiveInstantiatedSource);
});
} else {
instantiateArrayBuffer(receiveInstantiatedSource);
#if WASM_ASYNC_COMPILATION
function instantiateAsync() {
if (!Module['wasmBinary'] &&
typeof WebAssembly.instantiateStreaming === 'function' &&
!isDataURI(wasmBinaryFile) &&
typeof fetch === 'function') {
return WebAssembly.instantiateStreaming(fetch(wasmBinaryFile, { credentials: 'same-origin' }), info)
.then(receiveInstantiatedSource, function(reason) {
// We expect the most common failure cause to be a bad MIME type for the binary,
// in which case falling back to ArrayBuffer instantiation should work.
err('wasm streaming compile failed: ' + reason);
err('falling back to ArrayBuffer instantiation');
instantiateArrayBuffer(receiveInstantiatedSource);
});
} else {
return instantiateArrayBuffer(receiveInstantiatedSource);
}
}
return {}; // no exports yet; we'll fill them in later
#else
var instance;
var module;
try {
module = new WebAssembly.Module(getBinary());
instance = new WebAssembly.Instance(module, info)
} catch (e) {
err('failed to compile wasm module: ' + e);
if (e.toString().indexOf('imported Memory with incompatible size') >= 0) {
err('Memory size incompatibility issues may be due to changing TOTAL_MEMORY at runtime to something too large. Use ALLOW_MEMORY_GROWTH to allow any size memory (and also make sure not to set TOTAL_MEMORY at runtime to something smaller than it was at compile time).');
function instantiateSync() {
var instance;
var module;
try {
module = new WebAssembly.Module(getBinary());
instance = new WebAssembly.Instance(module, info);
} catch (e) {
err('failed to compile wasm module: ' + e);
if (e.toString().indexOf('imported Memory with incompatible size') >= 0) {
err('Memory size incompatibility issues may be due to changing TOTAL_MEMORY at runtime to something too large. Use ALLOW_MEMORY_GROWTH to allow any size memory (and also make sure not to set TOTAL_MEMORY at runtime to something smaller than it was at compile time).');
}
return false;
}
return false;
receiveInstance(instance, module);
}
receiveInstance(instance, module);
#endif
// User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
// to manually instantiate the Wasm module themselves. This allows pages to run the instantiation parallel
// to any other async startup actions they are performing.
if (Module['instantiateWasm']) {
try {
return Module['instantiateWasm'](info, receiveInstance);
} catch(e) {
err('Module.instantiateWasm callback failed with error: ' + e);
return false;
}
}

#if WASM_ASYNC_COMPILATION
#if RUNTIME_LOGGING
err('asynchronously preparing wasm');
#endif
instantiateAsync();
return {}; // no exports yet; we'll fill them in later
#else
instantiateSync();
return Module['asm']; // exports were assigned here
#endif
}
Expand Down