2020-10-13 14:10:47 +00:00
|
|
|
|
|
|
|
module.exports = loadWebAssembly
|
|
|
|
|
|
|
|
loadWebAssembly.supported = typeof WebAssembly !== 'undefined'
|
|
|
|
|
|
|
|
function loadWebAssembly (opts) {
|
|
|
|
if (!loadWebAssembly.supported) return null
|
|
|
|
|
|
|
|
var imp = opts && opts.imports
|
2020-10-17 20:42:56 +00:00
|
|
|
var wasm = toUint8Array('AGFzbQEAAAABZg1gFX5+fn5+fn5+fn5+fn5+fn5+fn5+fwBgDX5+fn5+fn5+fn5/f38AYAt+fn5+fn5+fn5+fwBgAX8AYAF/AX9gAn9/AGABfQBgAX0BfWABfABgAXwBfGABfgBgAX4BfmADf39/AAJ4CQJqcwV0YWJsZQFwAAMCanMDbWVtAgABBWRlYnVnA2xvZwADBWRlYnVnB2xvZ190ZWUABAVkZWJ1ZwNsb2cABQVkZWJ1ZwNsb2cABgVkZWJ1Zwdsb2dfdGVlAAcFZGVidWcDbG9nAAgFZGVidWcHbG9nX3RlZQAJAwQDCgsMBw4BCnNjYWxhcm11bHQACQqLGQMNACAAQiCHpyAApxACCwkAIAAQByAADwvwGAIHf0x+QZADIQZBuAMhB0HgAyEIQYgEIQkgAikDACEMIAIpAwghDSACKQMQIQ4gAikDGCEPIAE1AgAhECABNQIEIREgATUCCCESIAE1AgwhEyABNQIQIRQgATUCFCEVIAE1AhghFiABNQIcIRcgATUCICEYIAE1AiQhGUIBIRpCACEbQgAhHEIAIR1CACEeQgAhH0IAISBCACEhQgAhIkIAISMgATUCACEuIAE1AgQhLyABNQIIITAgATUCDCExIAE1AhAhMiABNQIUITMgATUCGCE0IAE1AhwhNSABNQIgITYgATUCJCE3QgAhJEIAISVCACEmQgAhJ0IAIShCACEpQgAhKkIAIStCACEsQgAhLUIBIThCACE5QgAhOkIAITtCACE8QgAhPUIAIT5CACE/QgAhQEIAIUFB/gEhBQJAA0AgBUEASA0BAkACQAJAAkACQAJAIAVBwABuDgMEAwIBCwsgDyELDAMLIA4hCwwC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
|
|
|
|
|
|
|
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)
|
|
|
|
}
|