| 1 |
import { inflate } from "pako"; |
| 2 |
import wasmTransformerDataURI from "@wasmer/wasm-transformer/lib/wasm-transformer.wasm"; |
| 3 |
let wasm = null; |
| 4 |
let cachegetInt32Memory = null; |
| 5 |
|
| 6 |
function getInt32Memory() { |
| 7 |
if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.wasi.memory.buffer) { |
| 8 |
cachegetInt32Memory = new Int32Array(wasm.wasi.memory.buffer); |
| 9 |
} |
| 10 |
return cachegetInt32Memory; |
| 11 |
} |
| 12 |
|
| 13 |
let cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }); |
| 14 |
|
| 15 |
let cachegetUint8Memory = null; |
| 16 |
function getUint8Memory() { |
| 17 |
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.wasi.memory.buffer) { |
| 18 |
cachegetUint8Memory = new Uint8Array(wasm.wasi.memory.buffer); |
| 19 |
} |
| 20 |
return cachegetUint8Memory; |
| 21 |
} |
| 22 |
|
| 23 |
function getStringFromWasm(ptr, len) { |
| 24 |
return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len)); |
| 25 |
} |
| 26 |
/** |
| 27 |
* get the versioon of the package |
| 28 |
* @returns {string} |
| 29 |
*/ |
| 30 |
export function version() { |
| 31 |
const retptr = 8; |
| 32 |
const ret = wasm.exports.version(retptr); |
| 33 |
const memi32 = getInt32Memory(); |
| 34 |
const v0 = getStringFromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice(); |
| 35 |
wasm.exports.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1); |
| 36 |
return v0; |
| 37 |
} |
| 38 |
|
| 39 |
let WASM_VECTOR_LEN = 0; |
| 40 |
|
| 41 |
function passArray8ToWasm(arg) { |
| 42 |
const ptr = wasm.exports.__wbindgen_malloc(arg.length * 1); |
| 43 |
getUint8Memory().set(arg, ptr / 1); |
| 44 |
WASM_VECTOR_LEN = arg.length; |
| 45 |
return ptr; |
| 46 |
} |
| 47 |
|
| 48 |
function getArrayU8FromWasm(ptr, len) { |
| 49 |
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len); |
| 50 |
} |
| 51 |
/** |
| 52 |
* i64 lowering that can be done by the browser |
| 53 |
* @param {Uint8Array} wasm_binary |
| 54 |
* @returns {Uint8Array} |
| 55 |
*/ |
| 56 |
export async function lowerI64Imports(wasm_binary) { |
| 57 |
if (!wasm) { |
| 58 |
wasm = await init(wasmTransformerDataURI); |
| 59 |
} |
| 60 |
const retptr = 8; |
| 61 |
const ret = wasm.exports.lowerI64Imports(retptr, passArray8ToWasm(wasm_binary), WASM_VECTOR_LEN); |
| 62 |
const memi32 = getInt32Memory(); |
| 63 |
const v0 = getArrayU8FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice(); |
| 64 |
wasm.exports.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1); |
| 65 |
return v0; |
| 66 |
} |
| 67 |
|
| 68 |
async function init(module) { |
| 69 |
const imports = {}; |
| 70 |
imports.wbg = {}; |
| 71 |
imports.wbg.__wbindgen_throw = function (arg0, arg1) { |
| 72 |
throw new Error(getStringFromWasm(arg0, arg1)); |
| 73 |
}; |
| 74 |
|
| 75 |
const compiled = await WebAssembly.compile(module); |
| 76 |
wasm = await WebAssembly.instantiate(compiled, imports); |
| 77 |
return wasm; |
| 78 |
} |
| 79 |
|
| 80 |
export default init; |