diff --git a/src/bun.js/api/BunObject.zig b/src/bun.js/api/BunObject.zig index c6f78502bd4a63..72109e96fcfa8f 100644 --- a/src/bun.js/api/BunObject.zig +++ b/src/bun.js/api/BunObject.zig @@ -533,17 +533,18 @@ pub fn inspect(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.J return ret; } -export fn Bun__inspect(globalThis: *JSGlobalObject, value: JSValue) ZigString { +export fn Bun__inspect(globalThis: *JSGlobalObject, value: JSValue) bun.String { // very stable memory address var array = MutableString.init(getAllocator(globalThis), 0) catch unreachable; + defer array.deinit(); var buffered_writer = MutableString.BufferedWriter{ .context = &array }; const writer = buffered_writer.writer(); var formatter = ConsoleObject.Formatter{ .globalThis = globalThis }; - writer.print("{}", .{value.toFmt(&formatter)}) catch return ZigString.Empty; - buffered_writer.flush() catch return ZigString.Empty; - - return ZigString.init(array.slice()).withEncoding(); + defer formatter.deinit(); + writer.print("{}", .{value.toFmt(&formatter)}) catch return .empty; + buffered_writer.flush() catch return .empty; + return bun.String.createUTF8(array.slice()); } pub fn getInspect(globalObject: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { diff --git a/src/bun.js/api/bun/spawn/stdio.zig b/src/bun.js/api/bun/spawn/stdio.zig index 8a989d1ab0e35d..2488f41b8d3f5b 100644 --- a/src/bun.js/api/bun/spawn/stdio.zig +++ b/src/bun.js/api/bun/spawn/stdio.zig @@ -324,6 +324,7 @@ pub const Stdio = union(enum) { if (file_fd >= std.math.maxInt(i32)) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); return globalThis.throwInvalidArguments("file descriptor must be a valid integer, received: {}", .{value.toFmt(&formatter)}); } diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 91137a4f35a085..14c8dd0cf7d66c 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -1970,6 +1970,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp .globalThis = globalThis, .quote_strings = true, }; + defer formatter.deinit(); Output.errGeneric("Expected a Response object, but received '{}'", .{value.toFmt(&formatter)}); } else { Output.errGeneric("Expected a Response object", .{}); diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig index 01c099782e2fa2..bdb1a7d92bd78c 100644 --- a/src/bun.js/base.zig +++ b/src/bun.js/base.zig @@ -245,6 +245,7 @@ pub fn getAllocator(_: js.JSContextRef) std.mem.Allocator { /// Print a JSValue to stdout; this is only meant for debugging purposes pub fn dump(value: JSC.WebCore.JSValue, globalObject: *JSC.JSGlobalObject) !void { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalObject }; + defer formatter.deinit(); try Output.errorWriter().print("{}\n", .{value.toFmt(globalObject, &formatter)}); Output.flush(); } diff --git a/src/bun.js/bindings/ErrorCode.cpp b/src/bun.js/bindings/ErrorCode.cpp index 32d9e1b3b14fbd..cb47ef719853d2 100644 --- a/src/bun.js/bindings/ErrorCode.cpp +++ b/src/bun.js/bindings/ErrorCode.cpp @@ -202,8 +202,8 @@ JSObject* createError(Zig::JSGlobalObject* globalObject, ErrorCode code, JSC::JS return createError(vm, globalObject, code, message, isDOMExceptionPrototype); } -// export fn Bun__inspect(globalThis: *JSGlobalObject, value: JSValue) ZigString -extern "C" ZigString Bun__inspect(JSC::JSGlobalObject* globalObject, JSValue value); +// export fn Bun__inspect(globalThis: *JSGlobalObject, value: JSValue) bun.String +extern "C" BunString Bun__inspect(JSC::JSGlobalObject* globalObject, JSValue value); // WTF::String JSValueToStringSafe(JSC::JSGlobalObject* globalObject, JSValue arg) @@ -247,9 +247,7 @@ WTF::String JSValueToStringSafe(JSC::JSGlobalObject* globalObject, JSValue arg) } } - ZigString zstring = Bun__inspect(globalObject, arg); - BunString bstring(BunStringTag::ZigString, BunStringImpl(zstring)); - return bstring.toWTFString(); + return Bun__inspect(globalObject, arg).transferToWTFString(); } WTF::String determineSpecificType(JSC::JSGlobalObject* globalObject, JSValue value) diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 9c7fcd478d225d..9442bf9d1a9a00 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -6647,6 +6647,7 @@ pub fn toJSHostFunction(comptime Function: JSHostZigFunction) JSC.JSHostFunction if (value != .zero) { if (globalThis.hasException()) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); bun.Output.err("Assertion failed", \\Native function returned a non-zero JSValue while an exception is pending \\ @@ -6683,6 +6684,7 @@ pub fn toJSHostFunctionWithContext(comptime ContextType: type, comptime Function if (value != .zero) { if (globalThis.hasException()) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); bun.Output.err("Assertion failed", \\Native function returned a non-zero JSValue while an exception is pending \\ diff --git a/src/bun.js/node/node_cluster_binding.zig b/src/bun.js/node/node_cluster_binding.zig index bf930e8e84dcae..0169fea34fd380 100644 --- a/src/bun.js/node/node_cluster_binding.zig +++ b/src/bun.js/node/node_cluster_binding.zig @@ -51,6 +51,7 @@ pub fn sendHelperChild(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFram // similar code as Bun__Process__send var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); if (Environment.isDebug) log("child: {}", .{message.toFmt(&formatter)}); const ipc_instance = vm.getIPCInstance().?; @@ -205,6 +206,7 @@ pub fn sendHelperPrimary(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFr // similar code as bun.JSC.Subprocess.doSend var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); if (Environment.isDebug) log("primary: {}", .{message.toFmt(&formatter)}); _ = handle; diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index a065cf635f1842..afbe7201d72d7d 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -1366,6 +1366,7 @@ pub fn modeFromJS(ctx: JSC.C.JSContextRef, value: JSC.JSValue) bun.JSError!?Mode break :brk std.fmt.parseInt(Mode, slice, 8) catch { var formatter = bun.JSC.ConsoleObject.Formatter{ .globalThis = ctx }; + defer formatter.deinit(); return ctx.throwValue(ctx.ERR_INVALID_ARG_VALUE("The argument 'mode' must be a 32-bit unsigned integer or an octal string. Received {}", .{value.toFmt(&formatter)}).toJS()); }; }; diff --git a/src/bun.js/node/util/validators.zig b/src/bun.js/node/util/validators.zig index e6c003ef59da8c..4c4693e3dda29c 100644 --- a/src/bun.js/node/util/validators.zig +++ b/src/bun.js/node/util/validators.zig @@ -112,12 +112,14 @@ pub fn validateInt32(globalThis: *JSGlobalObject, value: JSValue, comptime name_ } if (!value.isAnyInt()) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); return throwRangeError(globalThis, "The value of \"" ++ name_fmt ++ "\" is out of range. It must be an integer. Received {}", name_args ++ .{value.toFmt(&formatter)}); } const num = value.asNumber(); // Use floating point comparison here to ensure values out of i32 range get caught instead of clamp/truncated. if (num < @as(f64, @floatFromInt(min)) or num > @as(f64, @floatFromInt(max))) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); return throwRangeError(globalThis, "The value of \"" ++ name_fmt ++ "\" is out of range. It must be >= {d} and <= {d}. Received {}", name_args ++ .{ min, max, value.toFmt(&formatter) }); } return @intFromFloat(num); @@ -129,6 +131,7 @@ pub fn validateUint32(globalThis: *JSGlobalObject, value: JSValue, comptime name } if (!value.isAnyInt()) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); return throwRangeError(globalThis, "The value of \"" ++ name_fmt ++ "\" is out of range. It must be an integer. Received {}", name_args ++ .{value.toFmt(&formatter)}); } const num: i64 = value.asInt52(); @@ -136,6 +139,7 @@ pub fn validateUint32(globalThis: *JSGlobalObject, value: JSValue, comptime name const max: i64 = @intCast(std.math.maxInt(u32)); if (num < min or num > max) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); return throwRangeError(globalThis, "The value of \"" ++ name_fmt ++ "\" is out of range. It must be >= {d} and <= {d}. Received {}", name_args ++ .{ min, max, value.toFmt(&formatter) }); } return @truncate(@as(u63, @intCast(num))); diff --git a/src/bun.js/test/diff_format.zig b/src/bun.js/test/diff_format.zig index e198e474cda160..c6e832088a5924 100644 --- a/src/bun.js/test/diff_format.zig +++ b/src/bun.js/test/diff_format.zig @@ -146,6 +146,7 @@ pub const DiffFormatter = struct { .none => { const fmt = "Expected: {any}\nReceived: {any}"; var formatter = ConsoleObject.Formatter{ .globalThis = this.globalThis, .quote_strings = true }; + defer formatter.deinit(); if (Output.enable_ansi_colors) { try writer.print(Output.prettyFmt(fmt, true), .{ expected.toFmt(&formatter), diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index 66ed282c532714..2f641836dcd443 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -218,6 +218,7 @@ pub const Expect = struct { .rejects => { if (!silent) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const message = "Expected promise that rejects\nReceived promise that resolved: {any}\n"; return throwPrettyMatcherError(globalThis, custom_label, matcher_name, matcher_params, flags, message, .{value.toFmt(&formatter)}); } @@ -230,6 +231,7 @@ pub const Expect = struct { .resolves => { if (!silent) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const message = "Expected promise that resolves\nReceived promise that rejected: {any}\n"; return throwPrettyMatcherError(globalThis, custom_label, matcher_name, matcher_params, flags, message, .{value.toFmt(&formatter)}); } @@ -245,6 +247,7 @@ pub const Expect = struct { } else { if (!silent) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const message = "Expected promise\nReceived: {any}\n"; return throwPrettyMatcherError(globalThis, custom_label, matcher_name, matcher_params, flags, message, .{value.toFmt(&formatter)}); } @@ -519,6 +522,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); switch (this.custom_label.isEmpty()) { inline else => |has_custom_label| { @@ -688,6 +692,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = list_value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); if (not) { @@ -782,6 +787,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); if (not) { @@ -817,6 +823,7 @@ pub const Expect = struct { expected.ensureStillAlive(); const value: JSValue = try this.getValue(globalThis, thisValue, "toContainKey", "expected"); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const not = this.flags.not; if (!value.isObject()) { @@ -903,6 +910,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); if (not) { @@ -967,6 +975,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = keys.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); if (not) { @@ -1031,6 +1040,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); if (not) { @@ -1085,6 +1095,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); if (not) { @@ -1148,6 +1159,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); if (not) { @@ -1217,6 +1229,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); if (not) { @@ -1280,6 +1293,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); if (not) { @@ -1383,6 +1397,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); if (not) { @@ -1415,6 +1430,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); if (not) { const received_line = "Received: {any}\n"; @@ -1443,6 +1459,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); if (not) { const received_line = "Received: {any}\n"; @@ -1475,6 +1492,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); if (not) { const received_line = "Received: {any}\n"; @@ -1502,6 +1520,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); if (not) { const received_line = "Received: {any}\n"; @@ -1529,6 +1548,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); if (not) { const received_line = "Received: {any}\n"; @@ -1561,6 +1581,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); if (not) { const received_line = "Received: {any}\n"; @@ -1691,6 +1712,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); if (not) { if (expected_property != null) { const signature = comptime getSignature("toHaveProperty", "path, value", true); @@ -1774,6 +1796,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); if (not) { const received_line = "Received: {any}\n"; @@ -1830,6 +1853,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = other_value.toFmt(&formatter); if (not) { @@ -1889,6 +1913,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = other_value.toFmt(&formatter); if (not) { @@ -1948,6 +1973,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = other_value.toFmt(&formatter); if (not) { @@ -2007,6 +2033,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = other_value.toFmt(&formatter); if (not) { @@ -2078,6 +2105,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const expected_fmt = expected_.toFmt(&formatter); const received_fmt = received_.toFmt(&formatter); @@ -2137,6 +2165,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); if (not) { const received_line = "Received: {any}\n"; @@ -2194,6 +2223,7 @@ pub const Expect = struct { const result: JSValue = result_.?; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); if (expected_value == .zero or expected_value.isUndefined()) { const signature_no_args = comptime getSignature("toThrow", "", true); @@ -2309,6 +2339,7 @@ pub const Expect = struct { // error: message from received error does not match expected string var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const signature = comptime getSignature("toThrow", "expected", false); @@ -2334,6 +2365,7 @@ pub const Expect = struct { // error: message from received error does not match expected pattern var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); if (_received_message) |received_message| { const expected_value_fmt = expected_value.toFmt(&formatter); @@ -2362,6 +2394,7 @@ pub const Expect = struct { } var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received_fmt = result.toFmt(&formatter); const expected_fmt = expected_value.toFmt(&formatter); return this.throw(globalThis, signature, "\n\nExpected value: {any}\nReceived value: {any}\n", .{ expected_fmt, received_fmt }); @@ -2379,6 +2412,7 @@ pub const Expect = struct { // error: message from received error does not match expected error message. var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); if (_received_message) |received_message| { const expected_fmt = expected_message.toFmt(&formatter); @@ -2395,6 +2429,7 @@ pub const Expect = struct { // error: received error not instance of received error constructor var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); var expected_class = ZigString.Empty; var received_class = ZigString.Empty; expected_value.getClassName(globalThis, &expected_class); @@ -2426,6 +2461,7 @@ pub const Expect = struct { // did not throw const result = return_value_from_function; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received_line = "Received function did not throw\nReceived value: {any}\n"; if (expected_value == .zero or expected_value.isUndefined()) { @@ -2896,12 +2932,14 @@ pub const Expect = struct { "\n\nReceived: {any}\n"; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); return globalThis.throwPretty(fmt, .{value.toFmt(&formatter)}); } } value.jestSnapshotPrettyFormat(pretty_value, globalThis) catch { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); return globalThis.throw("Failed to pretty format value: {s}", .{value.toFmt(&formatter)}); }; } @@ -2912,6 +2950,7 @@ pub const Expect = struct { const existing_value = Jest.runner.?.snapshots.getOrPut(this, pretty_value.slice(), hint) catch |err| { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; + defer formatter.deinit(); const test_file_path = Jest.runner.?.files.get(this.testScope().?.describe.file_id).source.path.text; return switch (err) { error.FailedToOpenSnapshotFile => globalThis.throw("Failed to open snapshot file for test file: {s}", .{test_file_path}), @@ -2954,6 +2993,7 @@ pub const Expect = struct { const not = this.flags.not; var pass = false; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const actual_length = value.getLengthIfPropertyExistsInternal(globalThis); @@ -3031,6 +3071,7 @@ pub const Expect = struct { if (pass) return thisValue; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3056,6 +3097,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3081,6 +3123,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3121,6 +3164,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3146,6 +3190,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3216,6 +3261,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); const expected_str = expected.toFmt(&formatter); @@ -3242,6 +3288,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3267,6 +3314,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3292,6 +3340,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3317,6 +3366,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3342,6 +3392,7 @@ pub const Expect = struct { if (pass) return thisValue; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3373,6 +3424,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3404,6 +3456,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3435,6 +3488,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3487,6 +3541,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const start_fmt = startValue.toFmt(&formatter); const end_fmt = endValue.toFmt(&formatter); const received_fmt = value.toFmt(&formatter); @@ -3570,6 +3625,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const expected_fmt = expected.toFmt(&formatter); const value_fmt = value.toFmt(&formatter); @@ -3596,6 +3652,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3621,6 +3678,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3646,6 +3704,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3672,6 +3731,7 @@ pub const Expect = struct { if (pass) return thisValue; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3697,6 +3757,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received = value.toFmt(&formatter); if (not) { @@ -3745,6 +3806,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); @@ -3825,6 +3887,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const expect_string_fmt = expect_string.toFmt(&formatter); const substring_fmt = substring.toFmt(&formatter); const times_fmt = count.toFmt(&formatter); @@ -3899,6 +3962,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); if (not) { const signature = comptime getSignature("toSatisfy", "expected", true); @@ -3950,6 +4014,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); @@ -4003,6 +4068,7 @@ pub const Expect = struct { if (pass) return .undefined; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = value.toFmt(&formatter); const expected_fmt = expected.toFmt(&formatter); @@ -4032,6 +4098,7 @@ pub const Expect = struct { incrementExpectCallCounter(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const expected_value = arguments[0]; if (!expected_value.isConstructor()) { @@ -4078,6 +4145,7 @@ pub const Expect = struct { incrementExpectCallCounter(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const expected_value = arguments[0]; if (!expected_value.isString() and !expected_value.isRegExp()) { @@ -4385,6 +4453,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received_fmt = lastCallValue.toFmt(&formatter); if (not) { @@ -4448,6 +4517,7 @@ pub const Expect = struct { // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const received_fmt = nthCallValue.toFmt(&formatter); if (not) { @@ -4535,10 +4605,8 @@ pub const Expect = struct { if (!pass and return_status == ReturnStatus.throw) { const signature = comptime getSignature(name, "expected", false); const fmt = signature ++ "\n\n" ++ "Function threw an exception\n{any}\n"; - var formatter = JSC.ConsoleObject.Formatter{ - .globalThis = globalThis, - .quote_strings = true, - }; + var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); return globalThis.throwPretty(fmt, .{(try times_value.get(globalThis, "value")).?.toFmt(&formatter)}); } @@ -4698,10 +4766,8 @@ pub const Expect = struct { fn throwInvalidMatcherError(globalThis: *JSGlobalObject, matcher_name: bun.String, result: JSValue) bun.JSError { @branchHint(.cold); - var formatter = JSC.ConsoleObject.Formatter{ - .globalThis = globalThis, - .quote_strings = true, - }; + var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const fmt = "Unexpected return from matcher function `{s}`.\n" ++ @@ -5496,10 +5562,8 @@ pub const ExpectMatcherUtils = struct { } } - var formatter = JSC.ConsoleObject.Formatter{ - .globalThis = globalThis, - .quote_strings = true, - }; + var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); try writer.print("{}", .{value.toFmt(&formatter)}); if (comptime color_or_null) |_| { diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 137c286a0e6327..a37bf81fed17ed 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -1944,10 +1944,8 @@ fn formatLabel(globalThis: *JSGlobalObject, label: string, function_args: []JSVa args_idx += 1; }, 'p' => { - var formatter = JSC.ConsoleObject.Formatter{ - .globalThis = globalThis, - .quote_strings = true, - }; + var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; + defer formatter.deinit(); const value_fmt = current_arg.toFmt(&formatter); const test_index_str = std.fmt.allocPrint(allocator, "{}", .{value_fmt}) catch bun.outOfMemory(); defer allocator.free(test_index_str);