[JavaScript] 纯文本查看 复制代码 // WebAssembly 模块导出和相关方法
var o = function () {
return {
"./wasm_api_sign_bg.js": {
__wbg_now_513c8208bd94c09b: function () {
return Date.now();
},
__wbg_random_9f33d5bdc74069f8: function () {
return Math.random();
},
__wbg_floor_a68aa7c1b572044e: function (e) {
return Math.floor(e);
},
__wbindgen_throw: function (e, c) {
console.error("Throwing error: ", e, c);
}
}
};
};
// 使用 fetch 获取 WebAssembly 文件
let i = fetch("https://www.15ko4v.com:6002/_next/static/wasm/5bd33e776bcea985.wasm");
// 确保 f 变量初始化
let f = 0;
// 处理内存操作的函数
function a(n, e, t, rs) {
let r = n.length,
o = e(r);
const u = c(rs);
let i = 0;
for (; i < r; i++) {
const e = n.charCodeAt(i);
if (e > 127) break;
u[o + i] = e;
}
if (i !== r) {
0 !== i && (n = n.slice(i)),
o = t(o, r, r = i + 3 * n.length);
const e = c().subarray(o + i, o + r);
i += _(n, e).written;
}
f = i;
return o;
}
// 获取 WebAssembly 内存中的 Int32Array 数据
function w(r) {
let l = new Int32Array(r.memory.buffer);
return l;
}
// 获取 WebAssembly 内存中的 Uint8Array 数据
function c(r) {
return new Uint8Array(r.memory.buffer);
}
// 使用 TextDecoder 解码
let u = new (typeof TextDecoder === "undefined" ? require("util").TextDecoder : TextDecoder)("utf-8", {
ignoreBOM: true,
fatal: true
});
// 解码函数
function is(n, e, r) {
return u.decode(c(r).subarray(n, n + e));
}
// 主动调用的函数,封装 WebAssembly 加载与调用逻辑,并返回解码结果
function processWasm(apiPath) {
return i.then(function(response) {
return WebAssembly.instantiateStreaming(response, o()); // 使用 fetch 的返回值传给 instantiateStreaming
}).then(function (e) {
let r = e.instance.exports;
const u = r.__wbindgen_add_to_stack_pointer(-16); // 处理栈指针
const c = a(apiPath, r.__wbindgen_malloc, r.__wbindgen_realloc, r); // 处理数据
const d = f;
const _ = a("prod", r.__wbindgen_malloc, r.__wbindgen_realloc, r); // 处理生产环境数据
const l = f;
// 调用 WebAssembly 模块中的 `sign` 函数
r.sign(u, c, d, _, l);
// 获取 WebAssembly 内存中的数据
let t = w(r)[u / 4 + 0];
let o = w(r)[u / 4 + 1];
// 解码并返回结果
return is(t, o, r); // 返回解码后的字符串
}).catch(function (err) {
console.error("WebAssembly Instantiation Error:", err);
throw err; // 如果出错,抛出错误
});
}
// 调用 processWasm 函数,传入自定义的 API 路径
processWasm("/site/api").then(function(result) {
// 处理返回的解码结果
console.log("Decoded result: ", result);
}).catch(function(err) {
// 处理错误
console.error("Error in processing WebAssembly:", err);
});
|