diff options
Diffstat (limited to 'src/bun.js/api')
-rw-r--r-- | src/bun.js/api/bun/socket.zig | 16 | ||||
-rw-r--r-- | src/bun.js/api/bun/subprocess.zig | 22 | ||||
-rw-r--r-- | src/bun.js/api/html_rewriter.zig | 2 |
3 files changed, 11 insertions, 29 deletions
diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index 77b4a266f..5bc1629c0 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -112,12 +112,15 @@ const Handlers = struct { pub fn callErrorHandler(this: *Handlers, thisValue: JSValue, err: []const JSValue) bool { const onError = this.onError; if (onError == .zero) { + if (err.len > 0) + this.vm.onUnhandledError(this.globalObject, err[0]); + return false; } const result = onError.callWithThis(this.globalObject, thisValue, err); if (!result.isEmptyOrUndefinedOrNull() and result.isAnyError(this.globalObject)) { - this.vm.runErrorHandler(result, null); + this.vm.onUnhandledError(this.globalObject, result); } return true; @@ -827,8 +830,6 @@ fn NewSocket(comptime ssl: bool) type { if (handlers.callErrorHandler(this_value, &[_]JSC.JSValue{ this_value, result })) { return; } - - handlers.vm.runErrorHandler(result, null); } } pub fn onTimeout( @@ -857,8 +858,6 @@ fn NewSocket(comptime ssl: bool) type { if (handlers.callErrorHandler(this_value, &[_]JSC.JSValue{ this_value, result })) { return; } - - handlers.vm.runErrorHandler(result, null); } } pub fn onConnectError(this: *This, socket: Socket, errno: c_int) void { @@ -948,7 +947,6 @@ fn NewSocket(comptime ssl: bool) type { return; } - handlers.vm.runErrorHandler(result, null); return; } } @@ -984,8 +982,6 @@ fn NewSocket(comptime ssl: bool) type { if (handlers.callErrorHandler(this_value, &[_]JSC.JSValue{ this_value, result })) { return; } - - handlers.vm.runErrorHandler(result, null); } } @@ -1015,8 +1011,6 @@ fn NewSocket(comptime ssl: bool) type { if (handlers.callErrorHandler(this_value, &[_]JSC.JSValue{ this_value, result })) { return; } - - handlers.vm.runErrorHandler(result, null); } } @@ -1046,8 +1040,6 @@ fn NewSocket(comptime ssl: bool) type { if (handlers.callErrorHandler(this_value, &[_]JSC.JSValue{ this_value, result })) { return; } - - handlers.vm.runErrorHandler(result, null); } } diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index dcfa88a40..2d8127901 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -30,7 +30,6 @@ pub const Subprocess = struct { stderr: Readable, killed: bool = false, - reffer: JSC.Ref = JSC.Ref.init(), poll_ref: ?*JSC.FilePoll = null, exit_promise: JSC.Strong = .{}, @@ -55,13 +54,14 @@ pub const Subprocess = struct { globalThis: *JSC.JSGlobalObject, pub fn ref(this: *Subprocess) void { - this.reffer.ref(this.globalThis.bunVM()); - if (this.poll_ref) |poll| poll.ref(this.globalThis.bunVM()); + var vm = this.globalThis.bunVM(); + if (this.poll_ref) |poll| poll.enableKeepingProcessAlive(vm); } pub fn unref(this: *Subprocess) void { this.this_jsvalue.clear(); - this.unrefWithoutGC(this.globalThis.bunVM()); + var vm = this.globalThis.bunVM(); + if (this.poll_ref) |poll| poll.disableKeepingProcessAlive(vm); } pub fn constructor( @@ -182,8 +182,6 @@ pub const Subprocess = struct { .pipe => { defer this.close(); - // TODO: handle when there's pending unread data in the pipe - // For some reason, this currently hangs forever if (!this.pipe.buffer.received_eof and this.pipe.buffer.fd != JSC.Node.invalid_fd) { if (this.pipe.buffer.canRead()) this.pipe.buffer.readIfPossible(true); @@ -1301,7 +1299,6 @@ pub const Subprocess = struct { if (!sync) { var vm = this.globalThis.bunVM(); - this.reffer.unref(vm); // prevent duplicate notifications if (this.poll_ref) |poll| { @@ -1309,17 +1306,10 @@ pub const Subprocess = struct { poll.deinitWithVM(vm); } - this.waitpid_task = JSC.AnyTask.New(Subprocess, onExit).init(this); - this.has_waitpid_task = true; - vm.eventLoop().enqueueTask(JSC.Task.init(&this.waitpid_task)); + this.onExit(); } } - pub fn unrefWithoutGC(this: *Subprocess, vm: *JSC.VirtualMachine) void { - if (this.poll_ref) |poll| poll.unref(vm); - this.reffer.unref(vm); - } - fn onExit(this: *Subprocess) void { this.closePorts(); @@ -1348,7 +1338,7 @@ pub const Subprocess = struct { ); if (result.isAnyError(this.globalThis)) { - this.globalThis.bunVM().runErrorHandler(result, null); + this.globalThis.bunVM().onUnhandledError(this.globalThis, result); } } diff --git a/src/bun.js/api/html_rewriter.zig b/src/bun.js/api/html_rewriter.zig index eb602223b..9ab424491 100644 --- a/src/bun.js/api/html_rewriter.zig +++ b/src/bun.js/api/html_rewriter.zig @@ -850,7 +850,7 @@ fn HandlerCallback( switch (promise.status(this.global.vm())) { JSC.JSPromise.Status.Pending => unreachable, JSC.JSPromise.Status.Rejected => { - JavaScript.VirtualMachine.vm.runErrorHandler(promise.result(this.global.vm()), null); + JavaScript.VirtualMachine.vm.onUnhandledError(this.global, promise.result(this.global.vm())); @field(zig_element, field_name) = null; return false; }, |