62 lines
6.6 KiB
JavaScript
62 lines
6.6 KiB
JavaScript
|
|
||
|
module.exports = loadWebAssembly
|
||
|
|
||
|
loadWebAssembly.supported = typeof WebAssembly !== 'undefined'
|
||
|
|
||
|
function loadWebAssembly (opts) {
|
||
|
if (!loadWebAssembly.supported) return null
|
||
|
|
||
|
var imp = opts && opts.imports
|
||
|
var wasm = toUint8Array('AGFzbQEAAAABQQpgAX8AYAF/AX9gAn9/AGABfQBgAX0BfWABfABgAXwBfGABfgBgAX4BfmAUfn5+fn5+fn5+fn5+fn5+fn5+fn4AAmEHBWRlYnVnA2xvZwAABWRlYnVnB2xvZ190ZWUAAQVkZWJ1ZwNsb2cAAgVkZWJ1ZwNsb2cAAwVkZWJ1Zwdsb2dfdGVlAAQFZGVidWcDbG9nAAUFZGVidWcHbG9nX3RlZQAGAwUEBwgJAgUDAQABBjMKfgFCAAt+AUIAC34BQgALfgFCAAt+AUIAC34BQgALfgFCAAt+AUIAC34BQgALfgFCAAsHHQIGbWVtb3J5AgAQZmUyNTUxOV9wb3cyMjUyMwAKCocdBA0AIABCIIenIACnEAILCQAgABAHIAAPC7MPAXx+IACnrCEAIAGnrCEBIAKnrCECIAOnrCEDIASnrCEEIAWnrCEFIAanrCEGIAenrCEHIAinrCEIIAmnrCEJIAqnrCEKIAunrCELIAynrCEMIA2nrCENIA6nrCEOIA+nrCEPIBCnrCEQIBGnrCERIBKnrCESIBOnrCETQhMgC34gC0KAgICACINCAYZCE359IR5CEyAMfiAMQoCAgIAIg0IBhkITfn0hH0ITIA1+IA1CgICAgAiDQgGGQhN+fSEgQhMgDn4gDkKAgICACINCAYZCE359ISFCEyAPfiAPQoCAgIAIg0IBhkITfn0hIkITIBB+IBBCgICAgAiDQgGGQhN+fSEjQhMgEX4gEUKAgICACINCAYZCE359ISRCEyASfiASQoCAgIAIg0IBhkITfn0hJUITIBN+IBNCgICAgAiDQgGGQhN+fSEmQgIgAX4gAUKAgICACINCAYZCAn59ISdCAiADfiADQoCAgIAI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QIQYgATUCFCEHIAE1AhghCCABNQIcIQkgATUCICEKIAE1AiQhCyACp6whAiADp6whAyAEp6whBCAFp6whBSAGp6whBiAHp6whByAIp6whCCAJp6whCSAKp6whCiALp6whCyACIAMgBCAFIAYgByAIIAkgCiALIAIgAyAEIAUgBiAHIAggCSAKIAsQCSMAIQ0jASEPIwIhESMDIRMjBCEVIwUhFyMGIRkjByEbIwghHSMJIR8jACMBIwIjAyMEIwUjBiMHIwgjCSMAIwEjAiMDIwQjBSMGIwcjCCMJEAkjACMBIwIjAyMEIwUjBiMHIwgjCSMAIwEjAiMDIwQjBSMGIwcjCCMJEAkgAiADIAQgBSAGIAcgCCAJIAogCyMAIwEjAiMDIwQjBSMGIwcjCCMJEAkjACEOIwEhECMCIRIjAyEUIwQhFiMFIRgjBiEaIwchHCMIIR4jCSEgIA4gECASIBQgFiAYIBogHCAeICAgDSAPIBEgEyAVIBcgGSAbIB0gHxAJIwAjASMCIwMjBCMFIwYjByMIIwkjACMBIwIjAyMEIwUjBiMHIwgjCRAJIA4gECASIBQgFiAYIBogHCAeICAjACMBIwIjAyMEIwUjBiMHIwgjCRAJIwAhDSMBIQ8jAiERIwMhEyMEIRUjBSEXIwYhGSMHIRsjCCEdIwkhHwJAA0BBBSAMRg0BIAxBAWohDCMAIwEjAiMDIwQjBSMGIwcjCCMJIwAjASMCIwMjBCMFIwYjByMIIwkQCQwACwtBACEMIwAhDiMBIRAjAiESIwMhFCMEIRYjBSEYIwYhGiMHIRwjCCEeIwkhICANIA8gESATIBUgFyAZIBsgHSAfIwAjASMCIwMjBCMFIwYjByMIIwkQCSMAIQ0jASEPIwIhESMDIRMjBCEVIwUhFyMGIRkjByEbIwghHSMJIR8CQANAQQogDEYNASAMQQFqIQwjACMBIwIjAyMEIwUjBiMHIwgj
|
||
|
var ready = null
|
||
|
|
||
|
var mod = {
|
||
|
buffer: wasm,
|
||
|
memory: null,
|
||
|
exports: null,
|
||
|
realloc: realloc,
|
||
|
onload: onload
|
||
|
}
|
||
|
|
||
|
onload(function () {})
|
||
|
|
||
|
return mod
|
||
|
|
||
|
function realloc (size) {
|
||
|
mod.exports.memory.grow(Math.max(0, Math.ceil(Math.abs(size - mod.memory.length) / 65536)))
|
||
|
mod.memory = new Uint8Array(mod.exports.memory.buffer)
|
||
|
}
|
||
|
|
||
|
function onload (cb) {
|
||
|
if (mod.exports) return cb()
|
||
|
|
||
|
if (ready) {
|
||
|
ready.then(cb.bind(null, null)).catch(cb)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
if (opts && opts.async) throw new Error('async')
|
||
|
setup({instance: new WebAssembly.Instance(new WebAssembly.Module(wasm), imp)})
|
||
|
} catch (err) {
|
||
|
ready = WebAssembly.instantiate(wasm, imp).then(setup)
|
||
|
}
|
||
|
|
||
|
onload(cb)
|
||
|
}
|
||
|
|
||
|
function setup (w) {
|
||
|
mod.exports = w.instance.exports
|
||
|
mod.memory = mod.exports.memory && mod.exports.memory.buffer && new Uint8Array(mod.exports.memory.buffer)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function toUint8Array (s) {
|
||
|
if (typeof atob === 'function') return new Uint8Array(atob(s).split('').map(charCodeAt))
|
||
|
return (require('buf' + 'fer').Buffer).from(s, 'base64')
|
||
|
}
|
||
|
|
||
|
function charCodeAt (c) {
|
||
|
return c.charCodeAt(0)
|
||
|
}
|