(wasm, string)
| 17 | }; |
| 18 | |
| 19 | export const string2ptr = (wasm, string) => { |
| 20 | if (typeof string !== "string") { |
| 21 | console.error("Expected string but got", typeof string); |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | const stringBuf = encoder.encode(string); |
| 26 | const offset = wasm.exports.allocStringMem(stringBuf.length); |
| 27 | const { buffer } = wasm.wasi.memory; |
| 28 | const outBuf = new Uint8Array(buffer, offset, stringBuf.length + 1); |
| 29 | outBuf.set(stringBuf); |
| 30 | return offset; |
| 31 | }; |
no test coverage detected