From 5875d1419b49b97a78dfeeb9d6f1bd9f00d2eaeb Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Mon, 26 Sep 2022 20:35:26 -0700 Subject: Make `Bun.spawn`, FileSink and FileBlobLoader a little more reliable --- src/bun.js/api/bun.zig | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'src/bun.js/api/bun.zig') diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig index d62b1e9b8..0b4f62c39 100644 --- a/src/bun.js/api/bun.zig +++ b/src/bun.js/api/bun.zig @@ -3384,7 +3384,8 @@ pub const Subprocess = struct { stderr: Readable, killed: bool = false, - has_ref: bool = false, + reffer: JSC.Ref = JSC.Ref.init(), + poll_ref: JSC.PollRef = JSC.PollRef.init(), exit_promise: JSValue = JSValue.zero, this_jsvalue: JSValue = JSValue.zero, @@ -3402,6 +3403,16 @@ pub const Subprocess = struct { globalThis: *JSC.JSGlobalObject, + pub fn ref(this: *Subprocess) void { + this.reffer.ref(this.globalThis.bunVM()); + this.poll_ref.ref(this.globalThis.bunVM()); + } + + pub fn unref(this: *Subprocess) void { + this.reffer.unref(this.globalThis.bunVM()); + this.poll_ref.unref(this.globalThis.bunVM()); + } + pub fn constructor( _: *JSC.JSGlobalObject, _: *JSC.CallFrame, @@ -3425,8 +3436,9 @@ pub const Subprocess = struct { defer blob.detach(); var stream = JSC.WebCore.ReadableStream.fromBlob(globalThis, &blob, 0); - - break :brk Readable{ .pipe = JSC.WebCore.ReadableStream.fromJS(stream, globalThis).? }; + var out = JSC.WebCore.ReadableStream.fromJS(stream, globalThis).?; + out.ptr.File.stored_global_this_ = globalThis; + break :brk Readable{ .pipe = out }; }, .callback, .fd, .path, .blob => Readable{ .fd = @intCast(JSC.Node.FileDescriptor, fd) }, }; @@ -3559,20 +3571,6 @@ pub const Subprocess = struct { this.stderr.close(); } - pub fn unref(this: *Subprocess) void { - if (!this.has_ref) - return; - this.has_ref = false; - this.globalThis.bunVM().active_tasks -= 1; - } - - pub fn ref(this: *Subprocess) void { - if (this.has_ref) - return; - this.has_ref = true; - this.globalThis.bunVM().active_tasks += 1; - } - pub fn doRef(this: *Subprocess, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSValue { this.ref(); return JSC.JSValue.jsUndefined(); @@ -3608,7 +3606,7 @@ pub const Subprocess = struct { .path, .pipe, .callback => { var sink = try globalThis.bunVM().allocator.create(JSC.WebCore.FileSink); sink.* = .{ - .opened_fd = fd, + .fd = fd, .buffer = bun.ByteList.init(&.{}), .allocator = globalThis.bunVM().allocator, }; @@ -3659,7 +3657,7 @@ pub const Subprocess = struct { bun.default_allocator.destroy(this); } - pub fn getExitStatus( + pub fn getExited( this: *Subprocess, globalThis: *JSGlobalObject, ) callconv(.C) JSValue { @@ -3674,6 +3672,16 @@ pub const Subprocess = struct { return this.exit_promise; } + pub fn getExitCode( + this: *Subprocess, + _: *JSGlobalObject, + ) callconv(.C) JSValue { + if (this.exit_code) |code| { + return JSC.JSValue.jsNumber(code); + } + return JSC.JSValue.jsNull(); + } + pub fn spawn(globalThis: *JSC.JSGlobalObject, args: JSValue) JSValue { var arena = std.heap.ArenaAllocator.init(bun.default_allocator); defer arena.deinit(); -- cgit v1.2.3 ption> Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/os.exports.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-12-04content-range is inclusiveGravatar Jarred Sumner 1-1/+1
2022-12-04Update README.mdGravatar Jarred Sumner 1-6/+33
2022-12-04[Bun.serve] Implement `Content-Range` support with `Bun.file()`Gravatar Jarred Sumner 5-16/+286
2022-12-04[may revert later] Coerce Infinity to max int 64, -Infinity & NaN to min int64Gravatar Jarred Sumner 1-2/+22
2022-12-03Update .gitignoreGravatar Jarred Sumner 1-0/+1
2022-12-03[test] Add a couple tests for subarray toEqualGravatar Jarred Sumner 1-0/+3
2022-12-03[fetch] Fix bug where .arrayBuffer() on an empty Response body returned a `Ui...Gravatar Jarred Sumner 1-1/+1
2022-12-03Don't invalidate previous file descriptro to avoid tripping assertionGravatar Jarred Sumner 1-5/+0
2022-12-03miscGravatar Jarred Sumner 3-1/+31
2022-12-03Add missing typeGravatar Jarred Sumner 1-0/+5
2022-12-03`process.stdout` and `process.stderr`Gravatar Jarred Sumner 15-564/+1537
2022-12-03simdutf ascii validation is about 20% faster on arm64 than our zig simd @Vect...Gravatar Jarred Sumner 1-0/+3
2022-12-03typo in readme (#1576)Gravatar Reed Jones 1-2/+2