diff options
author | 2022-10-01 01:46:02 -0700 | |
---|---|---|
committer | 2022-10-01 01:46:02 -0700 | |
commit | 43c22b44118695407d87cc102be067eceee786fc (patch) | |
tree | feb4208809706bb6a507e3873ea8c27076ae4fbb | |
parent | bee72be733950231c46d09c6bd8f1958bac6bfff (diff) | |
download | bun-43c22b44118695407d87cc102be067eceee786fc.tar.gz bun-43c22b44118695407d87cc102be067eceee786fc.tar.zst bun-43c22b44118695407d87cc102be067eceee786fc.zip |
Fix release mode value semantics bug
-rw-r--r-- | src/bun.js/webcore/response.zig | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index ff5ad7fcd..b3111e81f 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -612,6 +612,7 @@ pub const Fetch = struct { const http_response = this.result.response; var response = allocator.create(Response) catch unreachable; var internal_blob = this.response_buffer.list.toManaged(this.response_buffer.allocator); + this.response_buffer = .{ .allocator = default_allocator, .list = .{ @@ -4802,27 +4803,26 @@ pub const Body = struct { } pub fn useAsAnyBlob(this: *Value) AnyBlob { - switch (this.*) { - .Blob => { - var new_blob = this.Blob; - std.debug.assert(new_blob.allocator == null); // owned by Body - this.* = .{ .Used = .{} }; - return .{ .Blob = new_blob }; - }, - .InternalBlob => { - const data = this.InternalBlob; - this.* = .{ .Used = .{} }; - return .{ .InternalBlob = data }; - }, - .InlineBlob => { - const data = this.InlineBlob; - this.* = .{ .Used = .{} }; - return .{ .InlineBlob = data }; - }, - else => { - return .{ .Blob = Blob.initEmpty(undefined) }; - }, + const any_blob: AnyBlob = switch (this.*) { + .Blob => .{ .Blob = this.Blob }, + .InternalBlob => .{ .InternalBlob = this.InternalBlob }, + .InlineBlob => .{ .InlineBlob = this.InlineBlob }, + else => .{ .Blob = Blob.initEmpty(undefined) }, + }; + + if (this.* == .Locked) { + if (this.Locked.promise) |prom| { + prom.unprotect(); + } + + if (this.Locked.readable) |readable| { + readable.done(); + // TODO: convert the known streams back into blobs + } } + + this.* = .{ .Used = {} }; + return any_blob; } pub fn toErrorInstance(this: *Value, error_instance: JSC.JSValue, global: *JSGlobalObject) void { |