diff --git a/src/bake/FrameworkRouter.zig b/src/bake/FrameworkRouter.zig index dc20ca4cd3..582a20c1e0 100644 --- a/src/bake/FrameworkRouter.zig +++ b/src/bake/FrameworkRouter.zig @@ -423,7 +423,7 @@ pub const Style = union(enum) { pub fn fromJS(value: JSValue, global: *JSC.JSGlobalObject) !Style { if (value.isString()) { - const bun_string = try value.toBunString2(global); + const bun_string = try value.toBunString(global); var sfa = std.heap.stackFallback(4096, bun.default_allocator); const utf8 = bun_string.toUTF8(sfa.get()); defer utf8.deinit(); @@ -1166,7 +1166,7 @@ pub const JSFrameworkRouter = struct { pub fn match(jsfr: *JSFrameworkRouter, global: *JSGlobalObject, callframe: *JSC.CallFrame) !JSValue { const path_js = callframe.argumentsAsArray(1)[0]; - const path_str = try path_js.toBunString2(global); + const path_str = try path_js.toBunString(global); defer path_str.deref(); const path_slice = path_str.toSlice(bun.default_allocator); defer path_slice.deinit(); diff --git a/src/bake/bake.zig b/src/bake/bake.zig index e1c77960af..c49c67c0d5 100644 --- a/src/bake/bake.zig +++ b/src/bake/bake.zig @@ -361,7 +361,7 @@ pub const Framework = struct { arena: Allocator, ) !Framework { if (opts.isString()) { - const str = try opts.toBunString2(global); + const str = try opts.toBunString(global); defer str.deref(); // Deprecated @@ -401,7 +401,7 @@ pub const Framework = struct { return global.throwInvalidArguments("'framework.reactFastRefresh' is missing 'importSource'", .{}); }; - const str = try prop.toBunString2(global); + const str = try prop.toBunString(global); defer str.deref(); break :brk .{ @@ -709,7 +709,7 @@ fn getOptionalString( return null; if (value == .undefined or value == .null) return null; - const str = try value.toBunString2(global); + const str = try value.toBunString(global); return allocations.track(str.toUTF8(arena)); } diff --git a/src/bun.js/ConsoleObject.zig b/src/bun.js/ConsoleObject.zig index d49ac41215..bc02ed107a 100644 --- a/src/bun.js/ConsoleObject.zig +++ b/src/bun.js/ConsoleObject.zig @@ -542,7 +542,7 @@ pub const TablePrinter = struct { var properties_iter = JSC.JSArrayIterator.init(this.properties, globalObject); while (properties_iter.next()) |value| { try columns.append(.{ - .name = value.toBunString(globalObject), + .name = try value.toBunString(globalObject), }); } } diff --git a/src/bun.js/api/BunObject.zig b/src/bun.js/api/BunObject.zig index 7ccf35fc93..8e594f6d33 100644 --- a/src/bun.js/api/BunObject.zig +++ b/src/bun.js/api/BunObject.zig @@ -258,7 +258,7 @@ pub fn shellEscape(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) b } const jsval = arguments.ptr[0]; - const bunstr = jsval.toBunString(globalThis); + const bunstr = try jsval.toBunString(globalThis); if (globalThis.hasException()) return .zero; defer bunstr.deref(); @@ -882,9 +882,9 @@ fn doResolve(globalThis: *JSC.JSGlobalObject, arguments: []const JSValue) bun.JS } } - const specifier_str = specifier.toBunString(globalThis); + const specifier_str = try specifier.toBunString(globalThis); defer specifier_str.deref(); - const from_str = from.toBunString(globalThis); + const from_str = try from.toBunString(globalThis); defer from_str.deref(); return doResolveWithArgs( globalThis, @@ -960,10 +960,10 @@ pub fn resolve(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun } export fn Bun__resolve(global: *JSGlobalObject, specifier: JSValue, source: JSValue, is_esm: bool) JSC.JSValue { - const specifier_str = specifier.toBunString2(global) catch return .zero; + const specifier_str = specifier.toBunString(global) catch return .zero; defer specifier_str.deref(); - const source_str = source.toBunString2(global) catch return .zero; + const source_str = source.toBunString(global) catch return .zero; defer source_str.deref(); const value = doResolveWithArgs(global, specifier_str, source_str, is_esm, true) catch { @@ -975,10 +975,10 @@ export fn Bun__resolve(global: *JSGlobalObject, specifier: JSValue, source: JSVa } export fn Bun__resolveSync(global: *JSGlobalObject, specifier: JSValue, source: JSValue, is_esm: bool) JSC.JSValue { - const specifier_str = specifier.toBunString2(global) catch return .zero; + const specifier_str = specifier.toBunString(global) catch return .zero; defer specifier_str.deref(); - const source_str = source.toBunString2(global) catch return .zero; + const source_str = source.toBunString(global) catch return .zero; defer source_str.deref(); return JSC.toJSHostValue(global, doResolveWithArgs(global, specifier_str, source_str, is_esm, true)); @@ -990,7 +990,7 @@ export fn Bun__resolveSyncWithStrings(global: *JSGlobalObject, specifier: *bun.S } export fn Bun__resolveSyncWithSource(global: *JSGlobalObject, specifier: JSValue, source: *bun.String, is_esm: bool) JSC.JSValue { - const specifier_str = specifier.toBunString2(global) catch return .zero; + const specifier_str = specifier.toBunString(global) catch return .zero; defer specifier_str.deref(); return JSC.toJSHostValue(global, doResolveWithArgs(global, specifier_str, source.*, is_esm, true)); } diff --git a/src/bun.js/api/JSTranspiler.zig b/src/bun.js/api/JSTranspiler.zig index f80ac02b1f..569c728b28 100644 --- a/src/bun.js/api/JSTranspiler.zig +++ b/src/bun.js/api/JSTranspiler.zig @@ -441,7 +441,7 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std if (!kind.isStringLike()) { tsconfig.jsonStringify(globalThis, 0, &out); } else { - out = tsconfig.toBunString(globalThis); + out = tsconfig.toBunString(globalThis) catch @panic("unexpected exception"); } if (out.isEmpty()) break :tsconfig; @@ -480,7 +480,7 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std if (is_object) { macros.jsonStringify(globalThis, 0, &out); } else { - out = macros.toBunString(globalThis); + out = try macros.toBunString(globalThis); } if (out.isEmpty()) break :macros; diff --git a/src/bun.js/api/bun/dns_resolver.zig b/src/bun.js/api/bun/dns_resolver.zig index 386b0e8f71..cd45d507e5 100644 --- a/src/bun.js/api/bun/dns_resolver.zig +++ b/src/bun.js/api/bun/dns_resolver.zig @@ -3175,7 +3175,7 @@ pub const DNSResolver = struct { } fn setChannelLocalAddress(channel: *c_ares.Channel, globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) bun.JSError!c_int { - const str = try value.toBunString2(globalThis); + const str = try value.toBunString(globalThis); defer str.deref(); const slice = str.toSlice(bun.default_allocator).slice(); @@ -3246,7 +3246,7 @@ pub const DNSResolver = struct { return globalThis.throwInvalidArguments("Invalid address family", .{}); } - const addressString = try JSValue.getIndex(triple, globalThis, 1).toBunString2(globalThis); + const addressString = try JSValue.getIndex(triple, globalThis, 1).toBunString(globalThis); defer addressString.deref(); const addressSlice = try addressString.toOwnedSlice(allocator); diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index c054229a5b..8f7bb686e0 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -1781,7 +1781,7 @@ pub const Subprocess = struct { argv.appendAssumeCapacity(argv0_result.arg0.ptr); while (cmds_array.next()) |value| { - const arg = try value.toBunString2(globalThis); + const arg = try value.toBunString(globalThis); defer arg.deref(); argv.appendAssumeCapacity(try arg.toOwnedSliceZ(allocator)); diff --git a/src/bun.js/api/bun/udp_socket.zig b/src/bun.js/api/bun/udp_socket.zig index 022155c4c8..42c7b4447c 100644 --- a/src/bun.js/api/bun/udp_socket.zig +++ b/src/bun.js/api/bun/udp_socket.zig @@ -152,7 +152,7 @@ pub const UDPSocketConfig = struct { if (!value.isString()) { return globalThis.throwInvalidArguments("Expected \"hostname\" to be a string", .{}); } - const str = value.toBunString(globalThis); + const str = value.toBunString(globalThis) catch @panic("unreachable"); defer str.deref(); break :brk str.toOwnedSliceZ(default_allocator) catch bun.outOfMemory(); } else { @@ -235,7 +235,7 @@ pub const UDPSocketConfig = struct { }; const connect_port = connect_port_js.coerceToInt32(globalThis); - const str = connect_host_js.toBunString(globalThis); + const str = try connect_host_js.toBunString(globalThis); defer str.deref(); const connect_host = str.toOwnedSliceZ(default_allocator) catch bun.outOfMemory(); @@ -743,7 +743,7 @@ pub const UDPSocket = struct { const number = port_val.coerceToInt32(globalThis); const port: u16 = if (number < 1 or number > 0xffff) 0 else @intCast(number); - const str = address_val.toBunString(globalThis); + const str = address_val.toBunString(globalThis) catch @panic("unexpected exception"); defer str.deref(); const address_slice = str.toOwnedSliceZ(default_allocator) catch bun.outOfMemory(); defer default_allocator.free(address_slice); @@ -927,7 +927,7 @@ pub const UDPSocket = struct { return globalThis.throwInvalidArguments("Expected 2 arguments", .{}); } - const str = args.ptr[0].toBunString(globalThis); + const str = try args.ptr[0].toBunString(globalThis); defer str.deref(); const connect_host = str.toOwnedSliceZ(default_allocator) catch bun.outOfMemory(); defer default_allocator.free(connect_host); diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig index 4dd7187c35..c2598e9850 100644 --- a/src/bun.js/base.zig +++ b/src/bun.js/base.zig @@ -1395,7 +1395,7 @@ pub const BinaryType = enum(u4) { pub fn fromJSValue(globalThis: *JSC.JSGlobalObject, input: JSC.JSValue) bun.JSError!?BinaryType { if (input.isString()) { - return Map.getWithEql(try input.toBunString2(globalThis), bun.String.eqlComptime); + return Map.getWithEql(try input.toBunString(globalThis), bun.String.eqlComptime); } return null; diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index a7c9e35af2..ffcb4afd54 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -4983,13 +4983,7 @@ pub const JSValue = enum(i64) { } /// Increments the reference count, you must call `.deref()` or it will leak memory. - /// Returns String.Dead on error. Deprecated in favor of `toBunString2` - pub fn toBunString(this: JSValue, globalObject: *JSC.JSGlobalObject) bun.String { - return bun.String.fromJS(this, globalObject); - } - - /// Increments the reference count, you must call `.deref()` or it will leak memory. - pub fn toBunString2(this: JSValue, globalObject: *JSC.JSGlobalObject) JSError!bun.String { + pub fn toBunString(this: JSValue, globalObject: *JSC.JSGlobalObject) JSError!bun.String { return bun.String.fromJS2(this, globalObject); } @@ -5045,7 +5039,7 @@ pub const JSValue = enum(i64) { }); } - /// Deprecated: replace with 'toBunString2' + /// Deprecated: replace with 'toBunString' pub fn getZigString(this: JSValue, global: *JSGlobalObject) bun.JSError!ZigString { var str = ZigString.init(""); try this.toZigString(&str, global); @@ -5417,7 +5411,7 @@ pub const JSValue = enum(i64) { return global.throwInvalidPropertyTypeValue(property, "string", prop); } - const str = prop.toBunString(global); + const str = try prop.toBunString(global); if (global.hasException()) { str.deref(); return error.JSError; @@ -5754,7 +5748,7 @@ pub const JSValue = enum(i64) { globalObject: *JSC.JSGlobalObject, pub fn format(this: StringFormatter, comptime text: []const u8, opts: std.fmt.FormatOptions, writer: anytype) !void { - const str = this.value.toBunString(this.globalObject); + const str = try this.value.toBunString(this.globalObject); defer str.deref(); try str.format(text, opts, writer); } diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 2fb08b78f4..b6cfc59ef5 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -1372,7 +1372,7 @@ pub const VirtualMachine = struct { pub fn specifierIsEvalEntryPoint(this: *VirtualMachine, specifier: JSValue) callconv(.C) bool { if (this.module_loader.eval_source) |eval_source| { - var specifier_str = specifier.toBunString(this.global); + var specifier_str = specifier.toBunString(this.global) catch @panic("unexpected exception"); defer specifier_str.deref(); return specifier_str.eqlUTF8(eval_source.path.text); } @@ -3940,7 +3940,7 @@ pub const VirtualMachine = struct { const code: ?[]const u8 = if (is_error_instance) code: { if (error_instance.uncheckedPtrCast(JSC.JSObject).getCodePropertyVMInquiry(this.global)) |code_value| { if (code_value.isString()) { - const code_string = code_value.toBunString2(this.global) catch { + const code_string = code_value.toBunString(this.global) catch { // JSC::JSString to WTF::String can only fail on out of memory. bun.outOfMemory(); }; diff --git a/src/bun.js/node/node_assert_binding.zig b/src/bun.js/node/node_assert_binding.zig index 824e06bb7c..ea1572e512 100644 --- a/src/bun.js/node/node_assert_binding.zig +++ b/src/bun.js/node/node_assert_binding.zig @@ -39,9 +39,9 @@ pub fn myersDiff(global: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSE if (!actual_arg.isString()) return global.throwInvalidArgumentTypeValue("actual", "string", actual_arg); if (!expected_arg.isString()) return global.throwInvalidArgumentTypeValue("expected", "string", expected_arg); - const actual_str = try actual_arg.toBunString2(global); + const actual_str = try actual_arg.toBunString(global); defer actual_str.deref(); - const expected_str = try expected_arg.toBunString2(global); + const expected_str = try expected_arg.toBunString(global); defer expected_str.deref(); bun.assertWithLocation(actual_str.tag != .Dead, @src()); diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index 528846d359..9e9291e66b 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -1916,7 +1916,7 @@ pub const Arguments = struct { } if (next_val.isString()) { arguments.eat(); - var str = try next_val.toBunString2(ctx); + var str = try next_val.toBunString(ctx); defer str.deref(); if (str.eqlComptime("dir")) break :link_type .dir; if (str.eqlComptime("file")) break :link_type .file; diff --git a/src/bun.js/node/node_util_binding.zig b/src/bun.js/node/node_util_binding.zig index 4c982e3f88..c2fe3a7288 100644 --- a/src/bun.js/node/node_util_binding.zig +++ b/src/bun.js/node/node_util_binding.zig @@ -120,7 +120,7 @@ pub fn extractedSplitNewLinesFastPathStringsOnly(globalThis: *JSC.JSGlobalObject const value = callframe.argument(0); bun.assert(value.isString()); - const str = try value.toBunString2(globalThis); + const str = try value.toBunString(globalThis); defer str.deref(); return switch (str.encoding()) { diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 330ff71f1e..22e4a9a06d 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -986,7 +986,7 @@ pub const PathLike = union(enum) { .StringObject, .DerivedStringObject, => { - var str = try arg.toBunString2(ctx); + var str = try arg.toBunString(ctx); defer str.deref(); arguments.eat(); diff --git a/src/bun.js/node/util/parse_args.zig b/src/bun.js/node/util/parse_args.zig index 599873d157..e78817f261 100644 --- a/src/bun.js/node/util/parse_args.zig +++ b/src/bun.js/node/util/parse_args.zig @@ -47,7 +47,7 @@ const ValueRef = union(Tag) { pub fn asBunString(this: ValueRef, globalObject: *JSGlobalObject) bun.String { return switch (this) { - .jsvalue => |str| str.toBunString(globalObject), + .jsvalue => |str| str.toBunString(globalObject) catch @panic("unexpected exception"), .bunstr => |str| return str, }; } @@ -320,7 +320,7 @@ fn parseOptionDefinitions(globalThis: *JSGlobalObject, options_obj: JSValue, opt if (obj.getOwn(globalThis, "short")) |short_option| { try validateString(globalThis, short_option, "options.{s}.short", .{option.long_name}); - var short_option_str = short_option.toBunString(globalThis); + var short_option_str = try short_option.toBunString(globalThis); if (short_option_str.length() != 1) { const err = JSC.toTypeError(.ERR_INVALID_ARG_VALUE, "options.{s}.short must be a single character", .{option.long_name}, globalThis); return globalThis.throwValue(err); diff --git a/src/bun.js/node/util/validators.zig b/src/bun.js/node/util/validators.zig index 4c4693e3dd..85d40370be 100644 --- a/src/bun.js/node/util/validators.zig +++ b/src/bun.js/node/util/validators.zig @@ -263,7 +263,7 @@ pub fn validateUndefined(globalThis: *JSGlobalObject, value: JSValue, comptime n } pub fn validateStringEnum(comptime T: type, globalThis: *JSGlobalObject, value: JSValue, comptime name_fmt: string, name_args: anytype) bun.JSError!T { - const str = try value.toBunString2(globalThis); + const str = try value.toBunString(globalThis); defer str.deref(); inline for (@typeInfo(T).@"enum".fields) |enum_field| { if (str.eqlComptime(enum_field.name)) diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index 075d8587d4..185d83c442 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -363,7 +363,7 @@ pub const Expect = struct { var custom_label = bun.String.empty; if (arguments.len > 1) { if (arguments[1].isString() or arguments[1].implementsToString(globalThis)) { - const label = arguments[1].toBunString(globalThis); + const label = try arguments[1].toBunString(globalThis); if (globalThis.hasException()) return .zero; custom_label = label; } @@ -3223,7 +3223,7 @@ pub const Expect = struct { return globalThis.throwInvalidArguments("toBeTypeOf() requires a string argument", .{}); } - const expected_type = expected.toBunString(globalThis); + const expected_type = try expected.toBunString(globalThis); defer expected_type.deref(); incrementExpectCallCounter(); @@ -4851,7 +4851,7 @@ pub const Expect = struct { if (message.isUndefined()) { message_text = bun.String.static("No message was specified for this matcher."); } else if (message.isString()) { - message_text = message.toBunString(globalThis); + message_text = try message.toBunString(globalThis); } else { if (comptime Environment.allow_assert) assert(message.isCallable(globalThis.vm())); // checked above @@ -4994,7 +4994,7 @@ pub const Expect = struct { } if (arg.isString()) { - const error_value = arg.toBunString(globalThis).toErrorInstance(globalThis); + const error_value = (try arg.toBunString(globalThis)).toErrorInstance(globalThis); error_value.put(globalThis, ZigString.static("name"), bun.String.init("UnreachableError").toJS(globalThis)); return globalThis.throwValue(error_value); } @@ -5469,7 +5469,13 @@ pub const ExpectCustomAsymmetricMatcher = struct { } return err; }; - try writer.print("{}", .{result.toBunString(globalThis)}); + try writer.print("{}", .{result.toBunString(globalThis) catch { + if (dontThrow) { + globalThis.clearException(); + return false; + } + return error.JSError; + }}); } } return false; @@ -5608,7 +5614,7 @@ pub const ExpectMatcherUtils = struct { if (arguments.len == 0 or !arguments[0].isString()) { return globalThis.throw("matcherHint: the first argument (matcher name) must be a string", .{}); } - const matcher_name = arguments[0].toBunString(globalThis); + const matcher_name = try arguments[0].toBunString(globalThis); defer matcher_name.deref(); const received = if (arguments.len > 1) arguments[1] else bun.String.static("received").toJS(globalThis); diff --git a/src/bun.js/test/pretty_format.zig b/src/bun.js/test/pretty_format.zig index e89cea3289..8c49631de9 100644 --- a/src/bun.js/test/pretty_format.zig +++ b/src/bun.js/test/pretty_format.zig @@ -1107,7 +1107,7 @@ pub const JestPrettyFormat = struct { defer message_string.deref(); if (value.fastGet(this.globalThis, .message)) |message_prop| { - message_string = message_prop.toBunString(this.globalThis); + message_string = try message_prop.toBunString(this.globalThis); } if (message_string.isEmpty()) { diff --git a/src/bun.js/web_worker.zig b/src/bun.js/web_worker.zig index 3cd99e7ebe..b50cb47cec 100644 --- a/src/bun.js/web_worker.zig +++ b/src/bun.js/web_worker.zig @@ -153,7 +153,10 @@ pub const WebWorker = struct { } var resolved_entry_point: bun.resolver.Result = parent.transpiler.resolveEntryPoint(str) catch { - const out = logger.toJS(parent.global, bun.default_allocator, "Error resolving Worker entry point").toBunString(parent.global); + const out = logger.toJS(parent.global, bun.default_allocator, "Error resolving Worker entry point").toBunString(parent.global) catch { + error_message.* = bun.String.static("unexpected exception"); + return null; + }; error_message.* = out; return null; }; @@ -328,7 +331,7 @@ pub const WebWorker = struct { var vm = this.vm orelse return; if (vm.log.msgs.items.len == 0) return; const err = vm.log.toJS(vm.global, bun.default_allocator, "Error in worker"); - const str = err.toBunString(vm.global); + const str = err.toBunString(vm.global) catch @panic("unexpected exception"); defer str.deref(); WebWorker__dispatchError(vm.global, this.cpp_worker, str, err); } diff --git a/src/bun.js/webcore/ObjectURLRegistry.zig b/src/bun.js/webcore/ObjectURLRegistry.zig index 65234b632a..47812dc2ea 100644 --- a/src/bun.js/webcore/ObjectURLRegistry.zig +++ b/src/bun.js/webcore/ObjectURLRegistry.zig @@ -119,7 +119,7 @@ fn Bun__revokeObjectURL_(globalObject: *JSC.JSGlobalObject, callframe: *JSC.Call if (!arguments.ptr[0].isString()) { return globalObject.throwInvalidArguments("revokeObjectURL expects a string", .{}); } - const str = arguments.ptr[0].toBunString(globalObject); + const str = arguments.ptr[0].toBunString(globalObject) catch @panic("unreachable"); if (!str.hasPrefixComptime("blob:")) { return JSC.JSValue.undefined; } @@ -149,7 +149,7 @@ fn jsFunctionResolveObjectURL_(globalObject: *JSC.JSGlobalObject, callframe: *JS if (arguments.len < 1) { return JSC.JSValue.undefined; } - const str = arguments.ptr[0].toBunString(globalObject); + const str = try arguments.ptr[0].toBunString(globalObject); defer str.deref(); if (globalObject.hasException()) { diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index 86c2e77945..973397354c 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -1205,7 +1205,7 @@ pub const Blob = struct { const len = data.getLength(globalThis); if (len < 256 * 1024) { - const str = try data.toBunString2(globalThis); + const str = try data.toBunString(globalThis); defer str.deref(); const pathlike: JSC.Node.PathOrFileDescriptor = if (path_or_blob == .path) @@ -5528,7 +5528,7 @@ pub const Blob = struct { JSC.JSValue.JSType.DerivedStringObject, => { if (!fail_if_top_value_is_not_typed_array_like) { - var str = try top_value.toBunString2(global); + var str = try top_value.toBunString(global); defer str.deref(); const bytes, const ascii = try str.toOwnedSliceReturningAllASCII(bun.default_allocator); return Blob.initWithAllASCII(bytes, bun.default_allocator, global, ascii); diff --git a/src/bun.js/webcore/body.zig b/src/bun.js/webcore/body.zig index 15e57c367b..b0aaf00551 100644 --- a/src/bun.js/webcore/body.zig +++ b/src/bun.js/webcore/body.zig @@ -564,7 +564,7 @@ pub const Body = struct { const js_type = value.jsType(); if (js_type.isStringLike()) { - var str = try value.toBunString2(globalThis); + var str = try value.toBunString(globalThis); if (str.length() == 0) { return Body.Value{ .Empty = {}, diff --git a/src/cli/pack_command.zig b/src/cli/pack_command.zig index 353100c933..15a171a543 100644 --- a/src/cli/pack_command.zig +++ b/src/cli/pack_command.zig @@ -2381,7 +2381,7 @@ pub const bindings = struct { return global.throw("expected tarball path string argument", .{}); } - const tarball_path_str = args[0].toBunString(global); + const tarball_path_str = try args[0].toBunString(global); defer tarball_path_str.deref(); const tarball_path = tarball_path_str.toUTF8(bun.default_allocator); diff --git a/src/css/css_internals.zig b/src/css/css_internals.zig index ad19fdbcd4..5521c2af72 100644 --- a/src/css/css_internals.zig +++ b/src/css/css_internals.zig @@ -67,7 +67,7 @@ pub fn testingImpl(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame, c if (!source_arg.isString()) { return globalThis.throw("minifyTestWithOptions: expected source to be a string", .{}); } - const source_bunstr = try source_arg.toBunString2(globalThis); + const source_bunstr = try source_arg.toBunString(globalThis); defer source_bunstr.deref(); const source = source_bunstr.toUTF8(bun.default_allocator); defer source.deinit(); @@ -78,7 +78,7 @@ pub fn testingImpl(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame, c if (!expected_arg.isString()) { return globalThis.throw("minifyTestWithOptions: expected `expected` arg to be a string", .{}); } - const expected_bunstr = try expected_arg.toBunString2(globalThis); + const expected_bunstr = try expected_arg.toBunString(globalThis); defer expected_bunstr.deref(); const expected = expected_bunstr.toUTF8(bun.default_allocator); defer expected.deinit(); @@ -159,7 +159,7 @@ fn parserOptionsFromJS(globalThis: *JSC.JSGlobalObject, allocator: Allocator, op if (val.isArray()) { var iter = val.arrayIterator(globalThis); while (iter.next()) |item| { - const bunstr = try item.toBunString2(globalThis); + const bunstr = try item.toBunString(globalThis); defer bunstr.deref(); const str = bunstr.toUTF8(bun.default_allocator); defer str.deinit(); @@ -273,7 +273,7 @@ pub fn attrTest(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun. if (!source_arg.isString()) { return globalThis.throw("attrTest: expected source to be a string", .{}); } - const source_bunstr = try source_arg.toBunString2(globalThis); + const source_bunstr = try source_arg.toBunString(globalThis); defer source_bunstr.deref(); const source = source_bunstr.toUTF8(bun.default_allocator); defer source.deinit(); @@ -284,7 +284,7 @@ pub fn attrTest(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun. if (!expected_arg.isString()) { return globalThis.throw("attrTest: expected `expected` arg to be a string", .{}); } - const expected_bunstr = try expected_arg.toBunString2(globalThis); + const expected_bunstr = try expected_arg.toBunString(globalThis); defer expected_bunstr.deref(); const expected = expected_bunstr.toUTF8(bun.default_allocator); defer expected.deinit(); diff --git a/src/ini.zig b/src/ini.zig index 5c8b1469ae..626835e9b7 100644 --- a/src/ini.zig +++ b/src/ini.zig @@ -509,12 +509,9 @@ pub const Parser = struct { pub const IniTestingAPIs = struct { const JSC = bun.JSC; - pub fn loadNpmrcFromJS( - globalThis: *JSC.JSGlobalObject, - callframe: *JSC.CallFrame, - ) bun.JSError!JSC.JSValue { + pub fn loadNpmrcFromJS(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { const arg = callframe.argument(0); - const npmrc_contents = arg.toBunString(globalThis); + const npmrc_contents = try arg.toBunString(globalThis); defer npmrc_contents.deref(); const npmrc_utf8 = npmrc_contents.toUTF8(bun.default_allocator); defer npmrc_utf8.deinit(); @@ -606,7 +603,7 @@ pub const IniTestingAPIs = struct { const arguments = arguments_.slice(); const jsstr = arguments[0]; - const bunstr = jsstr.toBunString(globalThis); + const bunstr = try jsstr.toBunString(globalThis); defer bunstr.deref(); const utf8str = bunstr.toUTF8(bun.default_allocator); defer utf8str.deinit(); diff --git a/src/install/npm.zig b/src/install/npm.zig index c83707863f..f6c4703121 100644 --- a/src/install/npm.zig +++ b/src/install/npm.zig @@ -1369,13 +1369,13 @@ pub const PackageManifest = struct { return global.throw("expected manifest filename and registry string arguments", .{}); } - const manifest_filename_str = args[0].toBunString(global); + const manifest_filename_str = try args[0].toBunString(global); defer manifest_filename_str.deref(); const manifest_filename = manifest_filename_str.toUTF8(bun.default_allocator); defer manifest_filename.deinit(); - const registry_str = args[1].toBunString(global); + const registry_str = try args[1].toBunString(global); defer registry_str.deref(); const registry = registry_str.toUTF8(bun.default_allocator); diff --git a/src/js_ast.zig b/src/js_ast.zig index 2c82eb23d8..e8f663e77f 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -8383,7 +8383,7 @@ pub const Macro = struct { return Expr.init(E.Number, E.Number{ .value = value.asNumber() }, this.caller.loc); }, .String => { - var bun_str = value.toBunString(this.global); + var bun_str = try value.toBunString(this.global); defer bun_str.deref(); // encode into utf16 so the printer escapes the string correctly diff --git a/src/logger.zig b/src/logger.zig index ecb5ca5a94..d0f1024d43 100644 --- a/src/logger.zig +++ b/src/logger.zig @@ -426,12 +426,12 @@ pub const Msg = struct { return cost; } - pub fn fromJS(allocator: std.mem.Allocator, globalObject: *bun.JSC.JSGlobalObject, file: string, err: bun.JSC.JSValue) OOM!Msg { + pub fn fromJS(allocator: std.mem.Allocator, globalObject: *bun.JSC.JSGlobalObject, file: string, err: bun.JSC.JSValue) bun.JSError!Msg { var zig_exception_holder: bun.JSC.ZigException.Holder = bun.JSC.ZigException.Holder.init(); if (err.toError()) |value| { value.toZigException(globalObject, zig_exception_holder.zigException()); } else { - zig_exception_holder.zig_exception.message = err.toBunString(globalObject); + zig_exception_holder.zig_exception.message = try err.toBunString(globalObject); } return Msg{ diff --git a/src/napi/napi.zig b/src/napi/napi.zig index 0dce7c9bda..c2980450c4 100644 --- a/src/napi/napi.zig +++ b/src/napi/napi.zig @@ -441,7 +441,7 @@ pub export fn napi_get_value_string_latin1(env: napi_env, value_: napi_value, bu defer value.ensureStillAlive(); const buf_ptr = @as(?[*:0]u8, @ptrCast(buf_ptr_)); - const str = value.toBunString(env.toJS()); + const str = value.toBunString(env.toJS()) catch @panic("unexpected exception"); defer str.deref(); var buf = buf_ptr orelse { @@ -497,7 +497,7 @@ pub export fn napi_get_value_string_utf16(env: napi_env, value_: napi_value, buf log("napi_get_value_string_utf16", .{}); const value = value_.get(); defer value.ensureStillAlive(); - const str = value.toBunString(env.toJS()); + const str = value.toBunString(env.toJS()) catch @panic("unexpected exception"); defer str.deref(); var buf = buf_ptr orelse { diff --git a/src/patch.zig b/src/patch.zig index 422d0d8a94..cd531c5caa 100644 --- a/src/patch.zig +++ b/src/patch.zig @@ -1085,13 +1085,13 @@ pub const TestingAPIs = struct { const old_folder_jsval = arguments.nextEat() orelse { return globalThis.throw("expected 2 strings", .{}); }; - const old_folder_bunstr = old_folder_jsval.toBunString(globalThis); + const old_folder_bunstr = try old_folder_jsval.toBunString(globalThis); defer old_folder_bunstr.deref(); const new_folder_jsval = arguments.nextEat() orelse { return globalThis.throw("expected 2 strings", .{}); }; - const new_folder_bunstr = new_folder_jsval.toBunString(globalThis); + const new_folder_bunstr = try new_folder_jsval.toBunString(globalThis); defer new_folder_bunstr.deref(); const old_folder = old_folder_bunstr.toUTF8(bun.default_allocator); @@ -1147,7 +1147,7 @@ pub const TestingAPIs = struct { const patchfile_src_js = arguments.nextEat() orelse { return globalThis.throw("TestingAPIs.parse: expected at least 1 argument, got 0", .{}); }; - const patchfile_src_bunstr = patchfile_src_js.toBunString(globalThis); + const patchfile_src_bunstr = try patchfile_src_js.toBunString(globalThis); const patchfile_src = patchfile_src_bunstr.toUTF8(bun.default_allocator); var patchfile = parsePatchFile(patchfile_src.slice()) catch |e| { @@ -1174,7 +1174,7 @@ pub const TestingAPIs = struct { }; const dir_fd = if (arguments.nextEat()) |dir_js| brk: { - var bunstr = dir_js.toBunString(globalThis); + var bunstr = dir_js.toBunString(globalThis) catch return .initErr(.undefined); defer bunstr.deref(); const path = bunstr.toOwnedSliceZ(bun.default_allocator) catch unreachable; defer bun.default_allocator.free(path); @@ -1188,7 +1188,7 @@ pub const TestingAPIs = struct { }; } else bun.FileDescriptor.cwd(); - const patchfile_bunstr = patchfile_js.toBunString(globalThis); + const patchfile_bunstr = patchfile_js.toBunString(globalThis) catch return .initErr(.undefined); defer patchfile_bunstr.deref(); const patchfile_src = patchfile_bunstr.toUTF8(bun.default_allocator); diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 09a277cf08..2c8a42806a 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -3380,7 +3380,7 @@ pub const Resolver = struct { return globalThis.throwInvalidArgumentType("nodeModulePaths", "path", "string"); } - const in_str = try argument.toBunString2(globalThis); + const in_str = try argument.toBunString(globalThis); defer in_str.deref(); const r = &globalThis.bunVM().transpiler.resolver; return nodeModulePathsJSValue(r, in_str, globalThis); diff --git a/src/shell/shell.zig b/src/shell/shell.zig index 757b57be98..3e2b66b17e 100644 --- a/src/shell/shell.zig +++ b/src/shell/shell.zig @@ -3859,7 +3859,7 @@ pub fn handleTemplateValue( if (template_value.isObject()) { if (template_value.getOwnTruthy(globalThis, "raw")) |maybe_str| { - const bunstr = try maybe_str.toBunString2(globalThis); + const bunstr = try maybe_str.toBunString(globalThis); defer bunstr.deref(); if (!try builder.appendBunStr(bunstr, false)) { return globalThis.throw("Shell script string contains invalid UTF-16", .{}); @@ -3907,7 +3907,7 @@ pub const ShellSrcBuilder = struct { } pub fn appendJSValueStr(this: *ShellSrcBuilder, jsval: JSValue, comptime allow_escape: bool) bun.JSError!bool { - const bunstr = try jsval.toBunString2(this.globalThis); + const bunstr = try jsval.toBunString(this.globalThis); defer bunstr.deref(); return try this.appendBunStr(bunstr, allow_escape); @@ -4316,7 +4316,7 @@ pub const TestingAPIs = struct { return globalThis.throw("shellInternals.disabledOnPosix: expected 1 arguments, got 0", .{}); }; - const bunstr = try string.toBunString2(globalThis); + const bunstr = try string.toBunString(globalThis); defer bunstr.deref(); const utf8str = bunstr.toUTF8(bun.default_allocator); defer utf8str.deinit(); diff --git a/src/sql/postgres.zig b/src/sql/postgres.zig index 7d7f204c2f..5e89dc5126 100644 --- a/src/sql/postgres.zig +++ b/src/sql/postgres.zig @@ -654,7 +654,7 @@ pub const PostgresSQLQuery = struct { this_value.ensureStillAlive(); ptr.* = .{ - .query = try query.toBunString2(globalThis), + .query = try query.toBunString(globalThis), .thisValue = JSRef.initWeak(this_value), .flags = .{ .bigint = bigint, @@ -1835,15 +1835,15 @@ pub const PostgresSQLConnection = struct { pub fn call(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { var vm = globalObject.bunVM(); const arguments = callframe.arguments_old(14).slice(); - const hostname_str = try arguments[0].toBunString2(globalObject); + const hostname_str = try arguments[0].toBunString(globalObject); defer hostname_str.deref(); const port = arguments[1].coerce(i32, globalObject); - const username_str = try arguments[2].toBunString2(globalObject); + const username_str = try arguments[2].toBunString(globalObject); defer username_str.deref(); - const password_str = try arguments[3].toBunString2(globalObject); + const password_str = try arguments[3].toBunString(globalObject); defer password_str.deref(); - const database_str = try arguments[4].toBunString2(globalObject); + const database_str = try arguments[4].toBunString(globalObject); defer database_str.deref(); const ssl_mode: SSLMode = switch (arguments[5].toInt32()) { 0 => .disable, @@ -1904,7 +1904,7 @@ pub const PostgresSQLConnection = struct { var database: []const u8 = ""; var options: []const u8 = ""; - const options_str = try arguments[7].toBunString2(globalObject); + const options_str = try arguments[7].toBunString(globalObject); defer options_str.deref(); const options_buf: []u8 = brk: { diff --git a/src/sql/postgres/postgres_types.zig b/src/sql/postgres/postgres_types.zig index bd0787199f..ebff7b2ed2 100644 --- a/src/sql/postgres/postgres_types.zig +++ b/src/sql/postgres/postgres_types.zig @@ -515,7 +515,7 @@ pub const date = struct { else if (value.isNumber()) value.asNumber() else if (value.isString()) brk: { - var str = value.toBunString(globalObject); + var str = value.toBunString(globalObject) catch @panic("unreachable"); defer str.deref(); break :brk str.parseDate(globalObject); } else return 0; diff --git a/src/string.zig b/src/string.zig index ed7cfb0e4f..7b5f8580a3 100644 --- a/src/string.zig +++ b/src/string.zig @@ -1094,7 +1094,7 @@ pub const String = extern struct { return JSC.jsNumber(@as(i32, 0)); } - const str = args[0].toBunString(globalObject); + const str = try args[0].toBunString(globalObject); defer str.deref(); if (str.isEmpty()) { diff --git a/src/transpiler.zig b/src/transpiler.zig index 1e8492a2c2..8cefe71501 100644 --- a/src/transpiler.zig +++ b/src/transpiler.zig @@ -164,7 +164,7 @@ pub const PluginRunner = struct { return null; } - const file_path = path_value.toBunString(global); + const file_path = try path_value.toBunString(global); defer file_path.deref(); if (file_path.length() == 0) { @@ -196,7 +196,7 @@ pub const PluginRunner = struct { return null; } - const namespace_str = namespace_value.toBunString(global); + const namespace_str = try namespace_value.toBunString(global); if (namespace_str.length() == 0) { namespace_str.deref(); break :brk bun.String.init("file"); @@ -260,7 +260,7 @@ pub const PluginRunner = struct { ); } - const file_path = path_value.toBunString(global); + const file_path = try path_value.toBunString(global); if (file_path.length() == 0) { return JSC.ErrorableString.err( @@ -289,7 +289,7 @@ pub const PluginRunner = struct { ); } - const namespace_str = namespace_value.toBunString(global); + const namespace_str = try namespace_value.toBunString(global); if (namespace_str.length() == 0) { break :brk bun.String.static("file"); } @@ -319,13 +319,10 @@ pub const PluginRunner = struct { defer user_namespace.deref(); // Our super slow way of cloning the string into memory owned by JSC - const combined_string = std.fmt.allocPrint( - this.allocator, - "{any}:{any}", - .{ user_namespace, file_path }, - ) catch unreachable; + const combined_string = std.fmt.allocPrint(this.allocator, "{any}:{any}", .{ user_namespace, file_path }) catch unreachable; var out_ = bun.String.init(combined_string); - const out = out_.toJS(this.global_object).toBunString(this.global_object); + const jsval = out_.toJS(this.global_object); + const out = jsval.toBunString(this.global_object) catch @panic("unreachable"); this.allocator.free(combined_string); return JSC.ErrorableString.ok(out); }