修复构建脚本和WASM测试问题

This commit is contained in:
zhangshun
2026-06-01 16:24:38 +08:00
parent 40f9bdb590
commit 9b14dec67c
4 changed files with 182 additions and 128 deletions

View File

@@ -76,9 +76,16 @@ async function loadModule(modulePath) {
throw new Error(`Unsupported WASM loader type: ${typeof required}`);
}
function allocString(module, value) {
const size = module.lengthBytesUTF8(value) + 1;
const ptr = module._malloc(size);
module.stringToUTF8(value, ptr, size);
return ptr;
}
function callJsonFunction(module, exportName, payload) {
const requestText = typeof payload === "string" ? payload : JSON.stringify(payload);
const requestPtr = module.allocateUTF8(requestText);
const requestPtr = allocString(module, requestText);
let responsePtr = 0;
try {
@@ -343,7 +350,7 @@ const suite = [
assertions: [
{ path: "success", equals: true },
{ path: "res_data.success", equals: true },
{ path: "res_data.OPERATION.frames", lengthEquals: 2 },
{ path: "res_data.OPERATION.OPERATION.frames", lengthEquals: 2 },
],
},
{
@@ -435,7 +442,8 @@ async function main() {
ensure(typeof module._init_func === "function", "_init_func is not exported");
ensure(typeof module._func === "function", "_func is not exported");
ensure(typeof module.allocateUTF8 === "function", "allocateUTF8 is not exported");
ensure(typeof module.lengthBytesUTF8 === "function", "lengthBytesUTF8 is not exported");
ensure(typeof module.stringToUTF8 === "function", "stringToUTF8 is not exported");
ensure(typeof module.UTF8ToString === "function", "UTF8ToString is not exported");
const initResponse = callNoArgJsonFunction(module, "_init_func");