aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/webcore
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/webcore')
-rw-r--r--src/bun.js/webcore/response.zig53
-rw-r--r--src/bun.js/webcore/streams.zig4
2 files changed, 47 insertions, 10 deletions
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig
index 70a44fd60..6e0f92f9c 100644
--- a/src/bun.js/webcore/response.zig
+++ b/src/bun.js/webcore/response.zig
@@ -985,6 +985,7 @@ pub const Fetch = struct {
}
const promise = promise_value.asAnyPromise().?;
+ _ = promise;
const tracker = this.tracker;
tracker.willDispatch(globalThis);
defer {
@@ -1007,15 +1008,51 @@ pub const Fetch = struct {
result.ensureStillAlive();
promise_value.ensureStillAlive();
+ const Holder = struct {
+ held: JSC.Strong,
+ promise: JSC.Strong,
+ globalObject: *JSC.JSGlobalObject,
+ task: JSC.AnyTask,
+
+ pub fn resolve(held: *@This()) void {
+ var prom = held.promise.swap().asAnyPromise().?;
+ var globalObject = held.globalObject;
+ const res = held.held.swap();
+ held.held.deinit();
+ held.promise.deinit();
+ res.ensureStillAlive();
+
+ bun.default_allocator.destroy(held);
+ prom.resolve(globalObject, res);
+ }
- switch (success) {
- true => {
- promise.resolve(globalThis, result);
- },
- false => {
- promise.reject(globalThis, result);
- },
- }
+ pub fn reject(held: *@This()) void {
+ var prom = held.promise.swap().asAnyPromise().?;
+ var globalObject = held.globalObject;
+ const res = held.held.swap();
+ held.held.deinit();
+ held.promise.deinit();
+ res.ensureStillAlive();
+
+ bun.default_allocator.destroy(held);
+ prom.reject(globalObject, res);
+ }
+ };
+
+ var holder = bun.default_allocator.create(Holder) catch unreachable;
+ holder.* = .{
+ .held = JSC.Strong.create(result, globalThis),
+ .promise = ref.strong,
+ .globalObject = globalThis,
+ .task = undefined,
+ };
+ ref.strong = .{};
+ holder.task = switch (success) {
+ true => JSC.AnyTask.New(Holder, Holder.resolve).init(holder),
+ false => JSC.AnyTask.New(Holder, Holder.reject).init(holder),
+ };
+
+ globalThis.bunVM().enqueueTask(JSC.Task.init(&holder.task));
}
pub fn checkServerIdentity(this: *FetchTasklet, certificate_info: HTTPClient.CertificateInfo) bool {
diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig
index f40548eb8..a578313d7 100644
--- a/src/bun.js/webcore/streams.zig
+++ b/src/bun.js/webcore/streams.zig
@@ -109,7 +109,6 @@ pub const ReadableStream = struct {
blob.size = blobby.remain;
blob.store.?.ref();
stream.detachIfPossible(globalThis);
- blobby.deinit();
return AnyBlob{ .Blob = blob };
},
@@ -120,7 +119,6 @@ pub const ReadableStream = struct {
// it should be lazy, file shouldn't have opened yet.
std.debug.assert(!blobby.started);
stream.detachIfPossible(globalThis);
- blobby.deinit();
return AnyBlob{ .Blob = blob };
}
},
@@ -131,6 +129,8 @@ pub const ReadableStream = struct {
if (bytes.has_received_last_chunk) {
var blob: JSC.WebCore.AnyBlob = undefined;
blob.from(bytes.buffer);
+ bytes.buffer.items = &.{};
+ bytes.buffer.capacity = 0;
stream.detachIfPossible(globalThis);
return blob;
}