diff options
author | 2023-06-01 00:19:33 -0700 | |
---|---|---|
committer | 2023-06-01 00:19:33 -0700 | |
commit | a4ccd4e0b4cc19f534bf639f30b7e4218400e1e8 (patch) | |
tree | 250f89bddd6e6c920645db2ad39bb7edf576edf0 /src/bun.js/javascript.zig | |
parent | cb0f76aa73f6b85667b57015a77ac39d9c78aa0b (diff) | |
parent | 689434e012a47b9be897f6d90d6aa211b13dfc19 (diff) | |
download | bun-jarred/port.tar.gz bun-jarred/port.tar.zst bun-jarred/port.zip |
Merge branch 'main' into jarred/portjarred/port
Diffstat (limited to 'src/bun.js/javascript.zig')
-rw-r--r-- | src/bun.js/javascript.zig | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 5c158a4fb..e09b609cb 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -442,6 +442,8 @@ pub const VirtualMachine = struct { onUnhandledRejectionCtx: ?*anyopaque = null, unhandled_error_counter: usize = 0, + on_exception: ?*const OnException = null, + modules: ModuleLoader.AsyncModule.Queue = .{}, aggressive_garbage_collection: GCLevel = GCLevel.none, @@ -449,6 +451,16 @@ pub const VirtualMachine = struct { pub const OnUnhandledRejection = fn (*VirtualMachine, globalObject: *JSC.JSGlobalObject, JSC.JSValue) void; + pub const OnException = fn (*ZigException) void; + + pub fn setOnException(this: *VirtualMachine, callback: *const OnException) void { + this.on_exception = callback; + } + + pub fn clearOnException(this: *VirtualMachine) void { + this.on_exception = null; + } + const VMHolder = struct { pub threadlocal var vm: ?*VirtualMachine = null; }; @@ -2068,6 +2080,9 @@ pub const VirtualMachine = struct { var exception = exception_holder.zigException(); this.remapZigException(exception, error_instance, exception_list); this.had_errors = true; + defer if (this.on_exception) |cb| { + cb(exception); + }; var line_numbers = exception.stack.source_lines_numbers[0..exception.stack.source_lines_len]; var max_line: i32 = -1; @@ -2093,6 +2108,7 @@ pub const VirtualMachine = struct { var name = exception.name; const message = exception.message; + var did_print_name = false; if (source_lines.next()) |source| brk: { if (source.text.len == 0) break :brk; @@ -2228,7 +2244,7 @@ pub const VirtualMachine = struct { } if (show.syscall) { - try writer.print(comptime Output.prettyFmt("syscall<d>: <r><cyan>\"{s}\"<r>\n", allow_ansi_color), .{exception.syscall}); + try writer.print(comptime Output.prettyFmt(" syscall<d>: <r><cyan>\"{s}\"<r>\n", allow_ansi_color), .{exception.syscall}); add_extra_line = true; } @@ -2236,7 +2252,7 @@ pub const VirtualMachine = struct { if (show.syscall) { try writer.writeAll(" "); } - try writer.print(comptime Output.prettyFmt("errno<d>: <r><yellow>{d}<r>\n", allow_ansi_color), .{exception.errno}); + try writer.print(comptime Output.prettyFmt(" errno<d>: <r><yellow>{d}<r>\n", allow_ansi_color), .{exception.errno}); add_extra_line = true; } |