Created
May 20, 2019 04:59
-
-
Save icculus/369126fc3c1b5aeb8c79b6e6c2472f79 to your computer and use it in GitHub Desktop.
Choose WebAssembly or asm.js at runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hasWebAssembly = false; | |
if (typeof WebAssembly==="object" && typeof WebAssembly.Memory==="function") { | |
hasWebAssembly = true; | |
} | |
//console.log("Do we have WebAssembly? " + ((hasWebAssembly) ? "YES" : "NO")); | |
var buildtype = hasWebAssembly ? "wasm" : "asmjs"; | |
var module = "dragonruby-" + buildtype + ".js"; | |
//console.log("Our main module is: " + module); | |
var script = document.createElement('script'); | |
script.src = module; | |
if (hasWebAssembly) { | |
script.async = true; | |
} else { | |
script.async = false; // !!! FIXME: can this be async? | |
(function() { | |
var memoryInitializer = module + '.mem'; | |
if (typeof Module['locateFile'] === 'function') { | |
memoryInitializer = Module['locateFile'](memoryInitializer); | |
} else if (Module['memoryInitializerPrefixURL']) { | |
memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer; | |
} | |
var meminitXHR = Module['memoryInitializerRequest'] = new XMLHttpRequest(); | |
meminitXHR.open('GET', memoryInitializer, true); | |
meminitXHR.responseType = 'arraybuffer'; | |
meminitXHR.send(null); | |
})(); | |
} | |
document.body.appendChild(script); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment