diff options
author | 2023-09-21 20:02:51 -0700 | |
---|---|---|
committer | 2023-09-21 20:02:51 -0700 | |
commit | 09d6e8553b0af7ab36655b48c53b7031feee5eaf (patch) | |
tree | 7d4868ecb518055f4c94275c5c969b69c759802e /src | |
parent | 0502c134e8547f83a6301b31daed3a47dfe9cfd8 (diff) | |
download | bun-09d6e8553b0af7ab36655b48c53b7031feee5eaf.tar.gz bun-09d6e8553b0af7ab36655b48c53b7031feee5eaf.tar.zst bun-09d6e8553b0af7ab36655b48c53b7031feee5eaf.zip |
ref and deinit (#5883)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/node/node_fs.zig | 14 | ||||
-rw-r--r-- | src/bun.js/node/types.zig | 21 |
2 files changed, 33 insertions, 2 deletions
diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index a07e75ee2..dab438628 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -191,7 +191,11 @@ pub const Async = struct { } this.ref.unref(this.globalObject.bunVM()); - this.args.deinit(); + if (@hasDecl(ArgumentType, "deinitAndUnprotect")) { + this.args.deinitAndUnprotect(); + } else { + this.args.deinit(); + } this.promise.strong.deinit(); bun.default_allocator.destroy(this); } @@ -1936,7 +1940,13 @@ pub const Arguments = struct { position: ?ReadPosition = null, encoding: Encoding = Encoding.buffer, - pub fn deinit(_: Write) void {} + pub fn deinit(this: *const @This()) void { + this.buffer.deinit(); + } + + pub fn deinitAndUnprotect(this: *@This()) void { + this.buffer.deinitAndUnprotect(); + } pub fn toThreadSafe(self: *@This()) void { self.buffer.toThreadSafe(); diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 4a650dbaf..96d1a00ef 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -348,11 +348,32 @@ pub const SliceWithUnderlyingStringOrBuffer = union(enum) { }; } + pub fn deinit(this: *const SliceWithUnderlyingStringOrBuffer) void { + switch (this.*) { + .SliceWithUnderlyingString => |*str| { + str.deinit(); + }, + else => {}, + } + } + + pub fn deinitAndUnprotect(this: *const SliceWithUnderlyingStringOrBuffer) void { + switch (this.*) { + .SliceWithUnderlyingString => |*str| { + str.deinit(); + }, + .buffer => |buffer| { + buffer.buffer.value.unprotect(); + }, + } + } + pub fn fromJS(global: *JSC.JSGlobalObject, allocator: std.mem.Allocator, value: JSC.JSValue, exception: JSC.C.ExceptionRef) ?SliceWithUnderlyingStringOrBuffer { _ = exception; return switch (value.jsType()) { JSC.JSValue.JSType.String, JSC.JSValue.JSType.StringObject, JSC.JSValue.JSType.DerivedStringObject, JSC.JSValue.JSType.Object => { var str = bun.String.tryFromJS(value, global) orelse return null; + str.ref(); return SliceWithUnderlyingStringOrBuffer{ .SliceWithUnderlyingString = str.toSlice(allocator) }; }, |