From bb5450fad0b45c42433c83c2af3a20876c3d4ead Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sun, 4 Dec 2022 08:11:44 -0800 Subject: [breaking] `onExit` callback in Bun.spawn sets the first property to be the Subprocess object Sometimes Bun.spawn calls the onExit callback before the Bun.spawn() callback is called. Instead of delaying a tick, we set the `Subprocess` to be the first argument to the `onExit` callback now. --- src/bun.js/api/bun/subprocess.zig | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index fe09746eb..53f0da03e 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -1571,14 +1571,20 @@ pub const Subprocess = struct { else JSC.JSValue.jsUndefined(); + const this_value = if (this_jsvalue.isEmptyOrUndefinedOrNull()) JSC.JSValue.jsUndefined() else this_jsvalue; + this_value.ensureStillAlive(); + const args = [_]JSValue{ - exit_value, + this_value, + this.getExitCode(globalThis), + this.getSignalCode(globalThis), waitpid_value, }; - const result = callback.call( + const result = callback.callWithThis( globalThis, - args[0 .. @as(usize, @boolToInt(this.exit_code != null)) + @as(usize, @boolToInt(this.waitpid_err != null))], + this_value, + &args, ); if (result.isAnyError(globalThis)) { -- cgit v1.2.3