wasm: improve the HTML debugger's WASI syscall implementations

This commit is contained in:
Brian Carroll 2022-02-10 10:15:59 +00:00
parent 55465d15a0
commit 2af4016f34

View file

@ -258,6 +258,7 @@
function fd_write(fd, iovs_ptr, iovs_len, nwritten_mut_ptr) {
let string_buffer = "";
let nwritten = 0;
const STDOUT = 1;
for (let i = 0; i < iovs_len; i++) {
const index32 = iovs_ptr >> 2;
@ -282,16 +283,18 @@
}
wasiLinkObject.memory32[nwritten_mut_ptr >> 2] = nwritten;
if (string_buffer) {
console.log(string_buffer);
if (fd === STDOUT) {
console.log(string_buffer);
} else {
console.error(string_buffer);
}
}
return 0;
}
// proc_exit : (i32) -> nil
function proc_exit(exit_code) {
if (exit_code) {
throw new Error(`Wasm exited with code ${exit_code}`);
}
throw new Error(`Wasm exited with code ${exit_code}`);
}
// Signatures from wasm_test_platform.o