mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
remove .zero from JSref
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user