provide roc_panic from javascript

This commit is contained in:
Folkert 2021-09-20 23:11:24 +02:00
parent 8bab0f4637
commit a25d6c82b5
2 changed files with 3 additions and 12 deletions

View file

@ -11,12 +11,9 @@ async function roc_web_platform_run(wasm_filename, callback) {
const importObj = {
wasi_snapshot_preview1: {
proc_exit: (code) => {
if (code !== 0) {
console.error(`Exited with code ${code}`);
roc_panic: (_pointer, _tag_id) => {
throw 'Roc panicked!';
}
exit_code = code;
},
},
env: {
js_display_roc_string,

View file

@ -43,13 +43,7 @@ export fn roc_dealloc(c_ptr: *c_void, alignment: u32) callconv(.C) void {
free(@alignCast(@alignOf(Align), @ptrCast([*]u8, c_ptr)));
}
export fn roc_panic(c_ptr: *c_void, tag_id: u32) callconv(.C) void {
_ = tag_id;
const stderr = std.io.getStdErr().writer();
const msg = @ptrCast([*:0]const u8, c_ptr);
stderr.print("Application crashed with message\n\n {s}\n\nShutting down\n", .{msg}) catch unreachable;
std.process.exit(0);
}
// NOTE roc_panic is provided in the JS file, so it can throw an exception
const mem = std.mem;
const Allocator = mem.Allocator;