9 imports.wasi_snapshot_preview1 = {
13 "random_get" : () => {
16 "environ_sizes_get" : () => {
17 console.log("wasi_snapshot_preview1:environ_sizes_get");
20 console.log("wasi_snapshot_preview1:proc_exit");
22 "environ_get" : () => {
23 console.log("wasi_snapshot_preview1:environ_get");
28 const memory = new WebAssembly.Memory({initial: 256});
29 imports.env.memoryBase = 0;
30 imports.env.memory = memory;
31 imports.env.tableBase = 0;
32 imports.env.table = new WebAssembly.Table({ initial: 4, element: 'anyfunc' });
34 imports.env["abort"] = function() {
35 console.error("ABORT");
37 imports.env["js_free"] = function(argument) {
38 console.log('integer passed from wasm:', argument);
40 imports.env["js_invoke_function"] = function(fn, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) {
41 console.log('integer passed from wasm:', argument);
44 const stream = fetch('../../liblightningjs.wasm');
45 const { instance: wasmInstance } = await WebAssembly.instantiateStreaming(stream, imports);
46 const wasm = wasmInstance.exports;
48 const result = wasm.TS_CResult_boolLightningErrorZ_ok(true);
49 console.assert(wasm.TS_LDKCResult_boolLightningErrorZ_result_ok(result));
50 console.assert(wasm.TS_LDKCResult_boolLightningErrorZ_get_ok(result));
51 wasm.TS_CResult_boolLightningErrorZ_free(result);
52 console.assert(wasm.TS_CResult_boolLightningErrorZ_ok(false) == result); // malloc doesn't need to guarantee this, but currently does
53 console.assert(wasm.TS_LDKCResult_boolLightningErrorZ_result_ok(result));
54 console.assert(!wasm.TS_LDKCResult_boolLightningErrorZ_get_ok(result));
55 wasm.TS_CResult_boolLightningErrorZ_free(result);