aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-07-01 13:30:33 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-07-01 13:30:33 -0700
commit583ec55d1d35254e034bb8403b9a7d9a2fd76781 (patch)
treece65df8b334308f5058c960f2c9fc024e4aa2d75
parent58c0e16b7af71309c8b36cefd68bf349d809a189 (diff)
downloadbun-jarred/strong.tar.gz
bun-jarred/strong.tar.zst
bun-jarred/strong.zip
💪jarred/strong
-rw-r--r--src/bun.js/webcore/blob.zig10
-rw-r--r--src/bun.js/webcore/body.zig48
2 files changed, 32 insertions, 26 deletions
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig
index faf503a3f..407a55fe4 100644
--- a/src/bun.js/webcore/blob.zig
+++ b/src/bun.js/webcore/blob.zig
@@ -436,11 +436,11 @@ pub const Blob = struct {
var globalThis = this.globalThis;
var file_blob = this.file_blob;
switch (value.*) {
- .Error => |err| {
+ .Error => |*err| {
file_blob.detach();
_ = value.use();
bun.default_allocator.destroy(this);
- promise.reject(globalThis, err);
+ promise.reject(globalThis, err.swap());
},
.Used => {
file_blob.detach();
@@ -701,8 +701,7 @@ pub const Blob = struct {
},
.Error => {
destination_blob.detach();
- const err = response.body.value.Error;
- JSC.C.JSValueUnprotect(ctx, err.asObjectRef());
+ const err = response.body.value.Error.swap();
_ = response.body.value.use();
return JSC.JSPromise.rejectedPromiseValue(ctx.ptr(), err).asObjectRef();
},
@@ -736,8 +735,7 @@ pub const Blob = struct {
},
.Error => {
destination_blob.detach();
- const err = request.body.value.Error;
- JSC.C.JSValueUnprotect(ctx, err.asObjectRef());
+ const err = request.body.value.Error.swap();
_ = request.body.value.use();
return JSC.JSPromise.rejectedPromiseValue(ctx.ptr(), err).asObjectRef();
},
diff --git a/src/bun.js/webcore/body.zig b/src/bun.js/webcore/body.zig
index 028b104b2..43ca55195 100644
--- a/src/bun.js/webcore/body.zig
+++ b/src/bun.js/webcore/body.zig
@@ -332,7 +332,7 @@ pub const Body = struct {
Locked: PendingValue,
Used: void,
Empty: void,
- Error: JSValue,
+ Error: JSC.Strong,
Null: void,
pub fn toBlobIfPossible(this: *Value) void {
@@ -624,7 +624,12 @@ pub const Body = struct {
pub fn fromReadableStream(readable: JSC.WebCore.ReadableStream, globalThis: *JSGlobalObject) Value {
if (readable.isLocked(globalThis)) {
- return .{ .Error = ZigString.init("Cannot use a locked ReadableStream").toErrorInstance(globalThis) };
+ return .{
+ .Error = JSC.Strong.create(
+ ZigString.init("Cannot use a locked ReadableStream").toErrorInstance(globalThis),
+ globalThis,
+ ),
+ };
}
readable.value.protect();
@@ -851,35 +856,38 @@ pub const Body = struct {
pub fn toErrorInstance(this: *Value, error_instance: JSC.JSValue, global: *JSGlobalObject) void {
if (this.* == .Locked) {
var locked = this.Locked;
- locked.deinit = true;
- if (locked.promise) |promise| {
+ const onReceiveValue_ = locked.onReceiveValue;
+ var task = locked.task;
+ var readable_ = locked.readable;
+ var promise_ = locked.promise;
+ error_instance.ensureStillAlive();
+ this.* = .{ .Error = JSC.Strong.create(error_instance, global) };
+
+ if (promise_) |promise| {
+ defer promise.unprotect();
if (promise.asAnyPromise()) |internal| {
internal.reject(global, error_instance);
}
- JSC.C.JSValueUnprotect(global, promise.asObjectRef());
- locked.promise = null;
}
- if (locked.readable) |readable| {
- readable.done();
- locked.readable = null;
+ if (readable_) |readable| {
+ readable.abort(global);
}
- this.* = .{ .Error = error_instance };
- if (locked.onReceiveValue) |onReceiveValue| {
- locked.onReceiveValue = null;
- onReceiveValue(locked.task.?, this);
+ if (onReceiveValue_) |onReceiveValue| {
+ onReceiveValue(task.?, this);
}
return;
}
- this.* = .{ .Error = error_instance };
- }
+ switch (this.*) {
+ .InternalBlob => this.InternalBlob.clearAndFree(),
+ .Blob => this.Blob.deinit(),
+ .WTFStringImpl => this.WTFStringImpl.deref(),
+ else => {},
+ }
- pub fn toErrorString(this: *Value, comptime err: string, global: *JSGlobalObject) void {
- var error_str = ZigString.init(err);
- var error_instance = error_str.toErrorInstance(global);
- return this.toErrorInstance(error_instance, global);
+ this.* = .{ .Error = JSC.Strong.create(error_instance, global) };
}
pub fn toError(this: *Value, err: anyerror, global: *JSGlobalObject) void {
@@ -923,7 +931,7 @@ pub const Body = struct {
}
if (tag == .Error) {
- JSC.C.JSValueUnprotect(VirtualMachine.get().global, this.Error.asObjectRef());
+ this.Error.deinit();
}
}
pub fn clone(this: *Value, globalThis: *JSC.JSGlobalObject) Value {