From a25d6c82b5aec2bd2049f24f6822bca8622d7a43 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 20 Sep 2021 23:11:24 +0200 Subject: [PATCH] provide roc_panic from javascript --- examples/hello-web/platform/host.js | 7 ++----- examples/hello-web/platform/host.zig | 8 +------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/examples/hello-web/platform/host.js b/examples/hello-web/platform/host.js index 9e3548aa26..0d953eabff 100644 --- a/examples/hello-web/platform/host.js +++ b/examples/hello-web/platform/host.js @@ -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, diff --git a/examples/hello-web/platform/host.zig b/examples/hello-web/platform/host.zig index 961619340e..5d588d6912 100644 --- a/examples/hello-web/platform/host.zig +++ b/examples/hello-web/platform/host.zig @@ -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;