diff options
author | 2022-11-07 14:57:47 -0800 | |
---|---|---|
committer | 2022-11-07 14:57:47 -0800 | |
commit | 8189f78eed9b904b6441b623116b962b0792ce4b (patch) | |
tree | 7c1bfb69f7da6be8fbef050f4e97eddf751722de /src/bun.js | |
parent | 2eb19a96b11b75e65cde00d6ac1c358b30020ef6 (diff) | |
download | bun-8189f78eed9b904b6441b623116b962b0792ce4b.tar.gz bun-8189f78eed9b904b6441b623116b962b0792ce4b.tar.zst bun-8189f78eed9b904b6441b623116b962b0792ce4b.zip |
Maybe fix bug with onExit callback?
Diffstat (limited to 'src/bun.js')
-rw-r--r-- | src/bun.js/api/bun/subprocess.zig | 24 | ||||
-rw-r--r-- | src/bun.js/bindings/bindings.zig | 11 |
2 files changed, 21 insertions, 14 deletions
diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index 4e2a0cc94..9baee4e92 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -1240,14 +1240,26 @@ pub const Subprocess = struct { this.has_waitpid_task = false; - const callback = this.on_exit_callback.swap(); - if (callback != .zero) { + if (this.on_exit_callback.trySwap()) |callback| { + const exit_value: JSValue = if (this.exit_code) |code| + JSC.JSValue.jsNumber(code) + else + JSC.JSValue.jsNumber(@as(i32, -1)); + + const waitpid_value: JSValue = + if (this.waitpid_err) |err| + err.toJSC(this.globalThis) + else + JSC.JSValue.jsUndefined(); + + const args = [_]JSValue{ + exit_value, + waitpid_value, + }; + const result = callback.call( this.globalThis, - &[_]JSValue{ - if (this.exit_code != null) JSC.JSValue.jsNumber(this.exit_code.?) else JSC.JSValue.jsNumber(@as(i32, -1)), - if (this.waitpid_err != null) this.waitpid_err.?.toJSC(this.globalThis) else JSC.JSValue.jsUndefined(), - }, + args[0 .. @as(usize, @boolToInt(this.exit_code != null)) + @as(usize, @boolToInt(this.waitpid_err != null))], ); if (result.isAnyError(this.globalThis)) { diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 813a222ef..c374ff0ec 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -2961,14 +2961,9 @@ pub const JSValue = enum(JSValueReprInt) { return switch (comptime Number) { JSValue => number, f32, f64 => jsNumberFromDouble(@as(f64, number)), - u8 => jsNumberFromChar(number), - i16, i32, c_int, i8, u16 => jsNumberFromInt32(@intCast(i32, number)), - i64 => jsNumberFromInt64(@intCast(i64, number)), - c_uint => jsNumberFromUint64(@intCast(u64, number)), - u64 => jsNumberFromUint64(@intCast(u64, number)), - u32 => if (number <= std.math.maxInt(i32)) jsNumberFromInt32(@intCast(i32, number)) else jsNumberFromUint64(@as(u64, number)), - u52 => jsNumberFromUint64(@as(u64, number)), - usize => jsNumberFromUint64(@as(u64, number)), + u8, i16, i32, c_int, i8, u16 => jsNumberFromInt32(@intCast(i32, number)), + u32, u52, c_uint, i64 => jsNumberFromInt64(@intCast(i64, number)), + usize, u64 => jsNumberFromUint64(@intCast(u64, number)), comptime_int => switch (number) { 0...std.math.maxInt(i32) => jsNumberFromInt32(@intCast(i32, number)), else => jsNumberFromInt64(@intCast(i64, number)), |