公司想尝试用 wasm 作为 js 代码保护的一种方式
如果确实不可行请敲醒我,我知道 wasm 本身不应该是这么用的
目前试了一下: https://github.com/Shopify/javy
按照他的教程编译后用 wasmtime 确实可以运行,但是用 JS 的 WebAssembly 接口调用就会报错:
WebAssembly.instantiateStreaming(fetch("xxxxxxx/index.wasm"), { wasi_snapshot_preview1: { fd_close: (e) => { console.log("fd_close", e); }, fd_write: (e) => { console.log("fd_write", e); }, fd_read: (e) => { console.log("fd_read", e); }, fd_seek: (e) => { console.log("fd_seek", e); }, environ_get: (e) => { console.log("fd_environ_get", e); }, environ_sizes_get: (e) => { console.log("fd_environ_sizes_get", e); }, clock_time_get: (e) => { console.log("clock_time_get", e); }, fd_fdstat_get: (e) => { console.log("fd_fdstat_get", e); }, proc_exit: (e) => { console.log("proc_exit", e); }, }, env: {}, }).then((obj) => { console.log(obj.instance.exports.main({ n: 100, bar: "test" })); }); RuntimeError: unreachable at xxxxxxx/index.wasm:wasm-function[193]:0x110ec at xxxxxxx/index.wasm:wasm-function[318]:0x1a4fc at xxxxxxx/index.wasm:wasm-function[28]:0x1489 at xxxxxxx/index.wasm:wasm-function[88]:0x728f at xxxxxxx/index.wasm:wasm-function[57]:0x38ab at xxxxxxx/index.wasm:wasm-function[287]:0x18880 at xxxxxxx/index.wasm:wasm-function[39]:0x1cb6 at xxxxxxx/index.wasm:wasm-function[193]:0x11422 at xxxxxxx/index.wasm:wasm-function[318]:0x1a4fc at xxxxxxx/index.wasm:wasm-function[28]:0x1489 