From ca80e070deee47ae544a67a7621123d803058b51 Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Wed, 10 Sep 2025 22:05:27 -0700 Subject: [PATCH] remove .zero from JSref --- src/bun.js/bindings/JSRef.zig | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/bun.js/bindings/JSRef.zig b/src/bun.js/bindings/JSRef.zig index ee8f697f38..c76a4056eb 100644 --- a/src/bun.js/bindings/JSRef.zig +++ b/src/bun.js/bindings/JSRef.zig @@ -4,26 +4,28 @@ pub const JSRef = union(enum) { finalized: void, pub fn initWeak(value: jsc.JSValue) @This() { + bun.assert(!value.isEmptyOrUndefinedOrNull()); return .{ .weak = value }; } pub fn initStrong(value: jsc.JSValue, globalThis: *jsc.JSGlobalObject) @This() { - bun.assert(value != .zero); + bun.assert(!value.isEmptyOrUndefinedOrNull()); return .{ .strong = .create(value, globalThis) }; } pub fn empty() @This() { - return .{ .weak = .zero }; + return .{ .weak = .js_undefined }; } pub fn tryGet(this: *const @This()) ?jsc.JSValue { return switch (this.*) { - .weak => if (this.weak != .zero) this.weak else null, + .weak => if (this.weak.isEmptyOrUndefinedOrNull()) null else this.weak, .strong => this.strong.get(), .finalized => null, }; } pub fn setWeak(this: *@This(), value: jsc.JSValue) void { + bun.assert(!value.isEmptyOrUndefinedOrNull()); switch (this.*) { .weak => {}, .strong => { @@ -37,7 +39,7 @@ pub const JSRef = union(enum) { } pub fn setStrong(this: *@This(), value: jsc.JSValue, globalThis: *jsc.JSGlobalObject) void { - bun.assert(value != .zero); + bun.assert(!value.isEmptyOrUndefinedOrNull()); if (this.* == .strong) { this.strong.set(globalThis, value); return; @@ -48,7 +50,7 @@ pub const JSRef = union(enum) { pub fn upgrade(this: *@This(), globalThis: *jsc.JSGlobalObject) void { switch (this.*) { .weak => { - bun.assert(this.weak != .zero); + bun.assert(!this.weak.isEmptyOrUndefinedOrNull()); this.* = .{ .strong = .create(this.weak, globalThis) }; }, .strong => {}, @@ -62,7 +64,7 @@ pub const JSRef = union(enum) { switch (this.*) { .weak => {}, .strong => |*strong| { - const value = strong.get() orelse .zero; + const value = strong.trySwap() orelse .js_undefined; value.ensureStillAlive(); strong.deinit(); this.* = .{ .weak = value }; @@ -75,7 +77,7 @@ pub const JSRef = union(enum) { pub fn isEmpty(this: *const @This()) bool { return switch (this.*) { - .weak => this.weak == .zero, + .weak => this.weak.isEmptyOrUndefinedOrNull(), .strong => !this.strong.has(), .finalized => true, }; @@ -83,7 +85,7 @@ pub const JSRef = union(enum) { pub fn isNotEmpty(this: *const @This()) bool { return switch (this.*) { - .weak => this.weak != .zero, + .weak => !this.weak.isEmptyOrUndefinedOrNull(), .strong => this.strong.has(), .finalized => false, }; @@ -92,7 +94,7 @@ pub const JSRef = union(enum) { pub fn deinit(this: *@This()) void { switch (this.*) { .weak => { - this.weak = .zero; + this.weak = .js_undefined; }, .strong => { this.strong.deinit();