62 lines
7.1 KiB
JavaScript
62 lines
7.1 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('AGFzbQEAAAABCAFgBH9/f38AAwIBAAUDAQABBxsCBm1lbW9yeQIADnNjMjU1MTlfbXVsYWRkAAAK9SEB8iEBVH4gATUCACEFIAE1AgQhBiABNQIIIQcgATUCDCEIIAE1AhAhCSABNQIUIQogATUCGCELIAE1AhwhDCABNQIgIQ0gATUCJCEOIAE1AighDyABNQIsIRAgAjUCACERIAI1AgQhEiACNQIIIRMgAjUCDCEUIAI1AhAhFSACNQIUIRYgAjUCGCEXIAI1AhwhGCACNQIgIRkgAjUCJCEaIAI1AighGyACNQIsIRwgAzUCACEdIAM1AgQhHiADNQIIIR8gAzUCDCEgIAM1AhAhISADNQIUISIgAzUCGCEjIAM1AhwhJCADNQIgISUgAzUCJCEmIAM1AighJyADNQIsISggHSAFIBF+fCEpIB4gBSASfiAGIBF+fHwhKiAfIAUgE34gBiASfiAHIBF+fHx8ISsgICAFIBR+IAYgE34gByASfiAIIBF+fHx8fCEsICEgBSAVfiAGIBR+IAcgE34gCCASfiAJIBF+fHx8fHwhLSAiIAUgFn4gBiAVfiAHIBR+IAggE34gCSASfiAKIBF+fHx8fHx8IS4gIyAFIBd+IAYgFn4gByAVfiAIIBR+IAkgE34gCiASfiALIBF+fHx8fHx8fCEvICQgBSAYfiAGIBd+IAcgFn4gCCAVfiAJIBR+IAogE34gCyASfiAMIBF+fHx8fHx8fHwhMCAlIAUgGX4gBiAYfiAHIBd+IAggFn4gCSAVfiAKIBR+IAsgE34gDCASfiANIBF+fHx8fHx8fHx8ITEgJiAFIBp+IAYgGX4gByAYfiAIIBd+IAkgFn4gCiAVfiALIBR+IAwgE34gDSASfiAOIBF+fHx8fHx8fHx8f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QhWHIUggMSBIfCExIDAgSEIBQhWGfn0hMCAxQhWHIUkgMiBJfCEyIDEgSUIBQhWGfn0hMSAyQhWHIUogMyBKfCEzIDIgSkIBQhWGfn0hMiAzQhWHIUsgNCBLfCE0IDMgS0IBQhWGfn0hMyA0QhWHIUwgNSBMfCE1IDQgTEIBQhWGfn0hNCApIDVCk9gofnwhKSAqIDVCmNocfnwhKiArIDVC5/YnfnwhKyAsIDVCrfM8fn0hLCAtIDVC0asIfnwhLSAuIDVC/d4pfn0hLiApQhWHIUEgKiBBfCEqICkgQUIBQhWGfn0hKSAqQhWHIUIgKyBCfCErICogQkIBQhWGfn0hKiArQhWHIUMgLCBDfCEsICsgQ0IBQhWGfn0hKyAsQhWHIUQgLSBEfCEtICwgREIBQhWGfn0hLCAtQhWHIUUgLiBFfCEuIC0gRUIBQhWGfn0hLSAuQhWHIUYgLyBGfCEvIC4gRkIBQhWGfn0hLiAvQhWHIUcgMCBHfCEwIC8gR0IBQhWGfn0hLyAwQhWHIUggMSBIfCExIDAgSEIBQhWGfn0hMCAxQhWHIUkgMiBJfCEyIDEgSUIBQhWGfn0hMSAyQhWHIUogMyBKfCEzIDIgSkIBQhWGfn0hMiAzQhWHIUsgNCBLfCE0IDMgS0IBQhWGfn0hMws=')
|
|
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)
|
|
}
|