rework assert, wasm_alert, wasm_clear, expect

This commit is contained in:
krzosa
2024-12-30 19:48:40 +01:00
parent 578fa33605
commit 46084a3412
16 changed files with 150 additions and 95 deletions

View File

@@ -104,6 +104,9 @@ const mem = new memory_t(new WebAssembly['Memory']({ initial: 2000, maximum: 655
ctx2d.fillStyle = `rgba(${r}, ${g}, ${b}, ${a})`;
ctx2d.fill();
},
wasm_clear: () => {
ctx2d.clearRect(0, 0, canvas.width, canvas.height);
},
wasm_set_clip: (x, y, w, h) => {
ctx2d.restore();
ctx2d.save();
@@ -115,6 +118,11 @@ const mem = new memory_t(new WebAssembly['Memory']({ initial: 2000, maximum: 655
return parseFloat(mem.read_cstr(str, len));
},
wasm_trap: () => { throw new Error() },
wasm_alert: (str, len) => {
const string = mem.read_cstr(str,len);
console.log(string);
alert(string);
},
};
const program = await WebAssembly['instantiate'](binary, { "env": wasm_imports });