lil helper method

This commit is contained in:
Jarred Sumner
2022-03-17 18:27:44 -07:00
parent 3d1259ea36
commit d5613308f9

View File

@@ -1888,6 +1888,10 @@ pub const RefString = struct {
pub const Hash = u32;
pub const Map = std.HashMap(Hash, *JSC.RefString, IdentityContext(Hash), 80);
pub fn toJS(this: *RefString, global: *JSC.JSGlobalObject) JSValue {
return JSC.ZigString.init(this.slice()).external(global, this, RefString__external);
}
pub const Callback = fn (ctx: *anyopaque, str: *RefString) void;
pub fn computeHash(input: []const u8) u32 {
@@ -1921,6 +1925,10 @@ pub const RefString = struct {
this.deref();
}
pub export fn RefString__external(this: ?*anyopaque, _: ?*anyopaque, _: usize) void {
bun.cast(*RefString, this.?).deref();
}
pub fn deinit(this: *RefString) void {
if (this.onBeforeDeinit) |onBeforeDeinit| {
onBeforeDeinit(this.ctx.?, this);