Updated Blazor macOS Catalina/iOS 13 workaround (#14576)
* MacOSX Catalina Beta wasm workaround for booting mono wasm from Blazor. * Address review comments * Address review comments * Make it clear why global scope is used. * Stylistic tweaks for Catalina workaround * Further streamlining * Update js binaries
This commit is contained in:
parent
ff095ddf55
commit
b14db5700f
File diff suppressed because one or more lines are too long
|
|
@ -25,10 +25,14 @@ export const monoPlatform: Platform = {
|
|||
window['Browser'] = {
|
||||
init: () => { },
|
||||
};
|
||||
// Emscripten works by expecting the module config to be a global
|
||||
window['Module'] = createEmscriptenModuleInstance(loadAssemblyUrls, resolve, reject);
|
||||
|
||||
addScriptTagsToDocument();
|
||||
// Emscripten works by expecting the module config to be a global
|
||||
// For compatibility with macOS Catalina, we have to assign a temporary value to window.Module
|
||||
// before we start loading the WebAssembly files
|
||||
addGlobalModuleScriptTagsToDocument(() => {
|
||||
window['Module'] = createEmscriptenModuleInstance(loadAssemblyUrls, resolve, reject);
|
||||
addScriptTagsToDocument();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -205,6 +209,23 @@ function addScriptTagsToDocument() {
|
|||
document.body.appendChild(scriptElem);
|
||||
}
|
||||
|
||||
// Due to a strange behavior in macOS Catalina, we have to delay loading the WebAssembly files
|
||||
// until after it finishes evaluating a <script> element that assigns a value to window.Module.
|
||||
// This may be fixed in a later version of macOS/iOS, or even if not it may be possible to reduce
|
||||
// this to a smaller workaround.
|
||||
function addGlobalModuleScriptTagsToDocument(callback: () => void) {
|
||||
const scriptElem = document.createElement('script');
|
||||
|
||||
// This pollutes global but is needed so it can be called from the script.
|
||||
// The callback is put in the global scope so that it can be run after the script is loaded.
|
||||
// onload cannot be used in this case for non-file scripts.
|
||||
window['__wasmmodulecallback__'] = callback;
|
||||
scriptElem.type = 'text/javascript';
|
||||
scriptElem.text = 'var Module; window.__wasmmodulecallback__(); delete window.__wasmmodulecallback__;';
|
||||
|
||||
document.body.appendChild(scriptElem);
|
||||
}
|
||||
|
||||
function createEmscriptenModuleInstance(loadAssemblyUrls: string[], onReady: () => void, onError: (reason?: any) => void) {
|
||||
const module = {} as typeof Module;
|
||||
const wasmBinaryFile = '_framework/wasm/mono.wasm';
|
||||
|
|
|
|||
Loading…
Reference in New Issue