aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/javascript.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/javascript.zig')
-rw-r--r--src/bun.js/javascript.zig28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index 410f3a776..c2c43cf81 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -429,7 +429,7 @@ pub const VirtualMachine = struct {
auto_install_dependencies: bool = false,
load_builtins_from_path: []const u8 = "",
- onUnhandledRejection: *const fn (*VirtualMachine, globalObject: *JSC.JSGlobalObject, JSC.JSValue) void = defaultOnUnhandledRejection,
+ onUnhandledRejection: *const OnUnhandledRejection = defaultOnUnhandledRejection,
onUnhandledRejectionCtx: ?*anyopaque = null,
unhandled_error_counter: usize = 0,
@@ -438,6 +438,8 @@ pub const VirtualMachine = struct {
gc_controller: JSC.GarbageCollectionController = .{},
+ pub const OnUnhandledRejection = fn (*VirtualMachine, globalObject: *JSC.JSGlobalObject, JSC.JSValue) void;
+
const VMHolder = struct {
pub threadlocal var vm: ?*VirtualMachine = null;
};
@@ -454,6 +456,30 @@ pub const VirtualMachine = struct {
pub threadlocal var is_main_thread_vm: bool = false;
+ pub const UnhandledRejectionScope = struct {
+ ctx: ?*anyopaque = null,
+ onUnhandledRejection: *const OnUnhandledRejection = undefined,
+ count: usize = 0,
+
+ pub fn apply(this: *UnhandledRejectionScope, vm: *JSC.VirtualMachine) void {
+ vm.onUnhandledRejection = this.onUnhandledRejection;
+ vm.onUnhandledRejectionCtx = this.ctx;
+ vm.unhandled_error_counter = this.count;
+ }
+ };
+
+ pub fn onQuietUnhandledRejectionHandler(this: *VirtualMachine, _: *JSC.JSGlobalObject, _: JSC.JSValue) void {
+ this.unhandled_error_counter += 1;
+ }
+
+ pub fn unhandledRejectionScope(this: *VirtualMachine) UnhandledRejectionScope {
+ return .{
+ .onUnhandledRejection = this.onUnhandledRejection,
+ .ctx = this.onUnhandledRejectionCtx,
+ .count = this.unhandled_error_counter,
+ };
+ }
+
pub fn resetUnhandledRejection(this: *VirtualMachine) void {
this.onUnhandledRejection = defaultOnUnhandledRejection;
}