From dedd433cbf2e2fe38e51bc166e08fbcc601ad42b Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 12 Jun 2025 12:18:46 -0800 Subject: [PATCH] zig: prefer .jsUndefined() over .undefined for JSValue (#20332) --- src/OutputFile.zig | 2 +- src/bake/DevServer.zig | 16 +- src/bake/FrameworkRouter.zig | 2 +- src/bake/bake.zig | 6 +- src/bake/production.zig | 4 +- src/bun.js/ConsoleObject.zig | 14 +- src/bun.js/ResolveMessage.zig | 2 +- src/bun.js/VirtualMachine.zig | 4 +- src/bun.js/api/BunObject.zig | 28 +-- src/bun.js/api/JSBundler.zig | 4 +- src/bun.js/api/Timer.zig | 17 +- src/bun.js/api/UnsafeObject.zig | 2 +- src/bun.js/api/bun/dns_resolver.zig | 14 +- src/bun.js/api/bun/h2_frame_parser.zig | 58 +++--- src/bun.js/api/bun/socket.zig | 22 +-- src/bun.js/api/bun/spawn/stdio.zig | 14 +- src/bun.js/api/bun/subprocess.zig | 16 +- src/bun.js/api/bun/udp_socket.zig | 22 +-- src/bun.js/api/ffi.zig | 12 +- src/bun.js/api/glob.zig | 4 +- src/bun.js/api/html_rewriter.zig | 2 +- src/bun.js/api/server.zig | 30 ++-- src/bun.js/api/server/NodeHTTPResponse.zig | 92 +++++----- src/bun.js/api/server/RequestContext.zig | 4 +- src/bun.js/api/server/ServerWebSocket.zig | 16 +- .../api/server/WebSocketServerContext.zig | 2 +- src/bun.js/bindings/AbortSignal.zig | 2 +- src/bun.js/bindings/CallFrame.zig | 10 +- src/bun.js/bindings/JSGlobalObject.zig | 7 +- src/bun.js/bindings/JSValue.zig | 27 +-- src/bun.js/ipc.zig | 24 +-- src/bun.js/jsc/host_fn.zig | 2 +- src/bun.js/node.zig | 2 +- src/bun.js/node/node_cluster_binding.zig | 10 +- src/bun.js/node/node_crypto_binding.zig | 28 +-- src/bun.js/node/node_fs.zig | 44 ++--- src/bun.js/node/node_fs_binding.zig | 2 +- src/bun.js/node/node_fs_stat_watcher.zig | 12 +- src/bun.js/node/node_fs_watcher.zig | 10 +- src/bun.js/node/node_zlib_binding.zig | 18 +- src/bun.js/node/path.zig | 22 +-- src/bun.js/node/types.zig | 4 +- src/bun.js/node/util/parse_args.zig | 16 +- src/bun.js/test/expect.zig | 170 +++++++++--------- src/bun.js/test/jest.zig | 24 +-- src/bun.js/test/pretty_format.zig | 8 +- src/bun.js/virtual_machine_exports.zig | 2 +- src/bun.js/webcore/Blob.zig | 6 +- src/bun.js/webcore/Body.zig | 2 +- src/bun.js/webcore/Crypto.zig | 12 +- src/bun.js/webcore/FileReader.zig | 2 +- src/bun.js/webcore/FileSink.zig | 4 +- src/bun.js/webcore/ObjectURLRegistry.zig | 12 +- src/bun.js/webcore/ReadableStream.zig | 14 +- src/bun.js/webcore/Request.zig | 4 +- src/bun.js/webcore/Response.zig | 10 +- src/bun.js/webcore/S3File.zig | 7 +- src/bun.js/webcore/Sink.zig | 2 +- src/bun.js/webcore/TextEncoder.zig | 2 +- src/bun.js/webcore/fetch.zig | 4 +- src/bun.js/webcore/prompt.zig | 6 +- src/bun.js/webcore/streams.zig | 4 +- src/bun_js.zig | 8 +- src/cli/upgrade_command.zig | 10 +- src/crash_handler.zig | 6 +- src/css/css_internals.zig | 2 +- src/css/values/color_js.zig | 2 +- src/deps/c_ares.zig | 14 +- src/deps/uws/Response.zig | 5 +- src/ini.zig | 2 +- src/install/dependency.zig | 14 +- src/install/install.zig | 6 +- src/js_ast.zig | 2 +- src/logger.zig | 4 +- src/napi/napi.zig | 8 +- src/patch.zig | 10 +- src/s3/client.zig | 4 +- src/shell/ParsedShellScript.zig | 8 +- src/shell/interpreter.zig | 20 +-- src/shell/subproc.zig | 2 +- src/sql/postgres.zig | 54 +++--- src/valkey/js_valkey.zig | 14 +- src/valkey/js_valkey_functions.zig | 2 +- test/internal/ban-words.test.ts | 2 +- 84 files changed, 569 insertions(+), 574 deletions(-) diff --git a/src/OutputFile.zig b/src/OutputFile.zig index db5290d047..00c269d7df 100644 --- a/src/OutputFile.zig +++ b/src/OutputFile.zig @@ -321,7 +321,7 @@ pub fn toJS( ) bun.JSC.JSValue { return switch (this.value) { .move, .pending => @panic("Unexpected pending output file"), - .noop => JSC.JSValue.undefined, + .noop => .jsUndefined(), .copy => |copy| brk: { const file_blob = JSC.WebCore.Blob.Store.initFile( if (copy.fd.isValid()) diff --git a/src/bake/DevServer.zig b/src/bake/DevServer.zig index 9d749e6918..78bedb78ba 100644 --- a/src/bake/DevServer.zig +++ b/src/bake/DevServer.zig @@ -1143,20 +1143,20 @@ pub fn setRoutes(dev: *DevServer, server: anytype) !bool { } } -fn onNotFound(_: *DevServer, _: *Request, resp: anytype) void { +fn onNotFound(_: *DevServer, _: *Request, resp: AnyResponse) void { notFound(resp); } -fn notFound(resp: anytype) void { +fn notFound(resp: AnyResponse) void { resp.corked(onNotFoundCorked, .{resp}); } -fn onNotFoundCorked(resp: anytype) void { +fn onNotFoundCorked(resp: AnyResponse) void { resp.writeStatus("404 Not Found"); resp.end("Not Found", false); } -fn onOutdatedJSCorked(resp: anytype) void { +fn onOutdatedJSCorked(resp: AnyResponse) void { // Send a payload to instantly reload the page. This only happens when the // client bundle is invalidated while the page is loading, aka when you // perform many file updates that cannot be hot-updated. @@ -1276,11 +1276,11 @@ inline fn redirectHandler(comptime path: []const u8, comptime is_ssl: bool) fn ( }.handle; } -fn onIncrementalVisualizer(_: *DevServer, _: *Request, resp: anytype) void { +fn onIncrementalVisualizer(_: *DevServer, _: *Request, resp: AnyResponse) void { resp.corked(onIncrementalVisualizerCorked, .{resp}); } -fn onIncrementalVisualizerCorked(resp: anytype) void { +fn onIncrementalVisualizerCorked(resp: AnyResponse) void { const code = if (Environment.codegen_embed) @embedFile("incremental_visualizer.html") else @@ -1288,11 +1288,11 @@ fn onIncrementalVisualizerCorked(resp: anytype) void { resp.end(code, false); } -fn onMemoryVisualizer(_: *DevServer, _: *Request, resp: anytype) void { +fn onMemoryVisualizer(_: *DevServer, _: *Request, resp: AnyResponse) void { resp.corked(onMemoryVisualizerCorked, .{resp}); } -fn onMemoryVisualizerCorked(resp: anytype) void { +fn onMemoryVisualizerCorked(resp: AnyResponse) void { const code = if (Environment.codegen_embed) @embedFile("memory_visualizer.html") else diff --git a/src/bake/FrameworkRouter.zig b/src/bake/FrameworkRouter.zig index a342db0317..6e5f92a95a 100644 --- a/src/bake/FrameworkRouter.zig +++ b/src/bake/FrameworkRouter.zig @@ -1110,7 +1110,7 @@ pub const JSFrameworkRouter = struct { return global.throwInvalidArguments("Missing options.root", .{}); defer root.deinit(); - var style = try Style.fromJS(try opts.getOptional(global, "style", JSValue) orelse .undefined, global); + var style = try Style.fromJS(try opts.getOptional(global, "style", JSValue) orelse .jsUndefined(), global); errdefer style.deinit(); const abs_root = try bun.default_allocator.dupe(u8, bun.strings.withoutTrailingSlash( diff --git a/src/bake/bake.zig b/src/bake/bake.zig index 834ca1ff27..39a665251b 100644 --- a/src/bake/bake.zig +++ b/src/bake/bake.zig @@ -391,7 +391,7 @@ pub const Framework = struct { break :brk null; if (rfr == .true) break :brk .{}; - if (rfr == .false or rfr == .null or rfr == .undefined) break :brk null; + if (rfr == .false or rfr.isUndefinedOrNull()) break :brk null; if (!rfr.isObject()) { return global.throwInvalidArguments("'framework.reactFastRefresh' must be an object or 'true'", .{}); @@ -411,7 +411,7 @@ pub const Framework = struct { const server_components: ?ServerComponents = sc: { const sc: JSValue = try opts.get(global, "serverComponents") orelse break :sc null; - if (sc == .false or sc == .null or sc == .undefined) break :sc null; + if (sc == .false or sc.isUndefinedOrNull()) break :sc null; if (!sc.isObject()) { return global.throwInvalidArguments("'framework.serverComponents' must be an object or 'undefined'", .{}); @@ -719,7 +719,7 @@ fn getOptionalString( ) !?[]const u8 { const value = try target.get(global, property) orelse return null; - if (value == .undefined or value == .null) + if (value.isUndefinedOrNull()) return null; const str = try value.toBunString(global); return allocations.track(str.toUTF8(arena)); diff --git a/src/bake/production.zig b/src/bake/production.zig index 5d3d3e569c..b4c1ed10f7 100644 --- a/src/bake/production.zig +++ b/src/bake/production.zig @@ -141,7 +141,7 @@ pub fn buildWithVm(ctx: bun.CLI.Command.Context, cwd: []const u8, vm: *VirtualMa var options = switch (config_promise.unwrap(vm.jsc, .mark_handled)) { .pending => unreachable, .fulfilled => |resolved| config: { - bun.assert(resolved == .undefined); + bun.assert(resolved.isUndefined()); const default = BakeGetDefaultExportFromModule(vm.global, config_entry_point_string.toJS(vm.global)); if (!default.isObject()) { @@ -572,7 +572,7 @@ fn loadModule(vm: *VirtualMachine, global: *JSC.JSGlobalObject, key: JSValue) !J switch (promise.unwrap(vm.jsc, .mark_handled)) { .pending => unreachable, .fulfilled => |val| { - bun.assert(val == .undefined); + bun.assert(val.isUndefined()); return BakeGetModuleNamespace(global, key); }, .rejected => |err| { diff --git a/src/bun.js/ConsoleObject.zig b/src/bun.js/ConsoleObject.zig index b3156ce3d9..ebff5fa752 100644 --- a/src/bun.js/ConsoleObject.zig +++ b/src/bun.js/ConsoleObject.zig @@ -184,7 +184,7 @@ fn messageWithTypeAndLevel_( // if value is not an object/array/iterable, don't print a table and just print it var tabular_data = vals[0]; if (tabular_data.isObject()) { - const properties = if (len >= 2 and vals[1].jsType().isArray()) vals[1] else JSValue.undefined; + const properties: JSValue = if (len >= 2 and vals[1].jsType().isArray()) vals[1] else .jsUndefined(); var table_printer = TablePrinter.init( global, level, @@ -1339,7 +1339,7 @@ pub const Formatter = struct { .ProxyObject => tag: { const handler = value.getProxyInternalField(.handler); - if (handler == .zero or handler == .undefined or handler == .null) { + if (handler == .zero or handler.isUndefinedOrNull()) { break :tag .RevokedProxy; } break :tag .Proxy; @@ -2606,7 +2606,7 @@ pub const Formatter = struct { } // this case should never happen - return try this.printAs(.Undefined, Writer, writer_, .undefined, .Cell, enable_ansi_colors); + return try this.printAs(.Undefined, Writer, writer_, .jsUndefined(), .Cell, enable_ansi_colors); } else if (value.as(bun.api.Timer.TimeoutObject)) |timer| { this.addForNewLine("Timeout(# ) ".len + bun.fmt.fastDigitCount(@as(u64, @intCast(@max(timer.internals.id, 0))))); if (timer.internals.flags.kind == .setInterval) { @@ -2895,13 +2895,13 @@ pub const Formatter = struct { writer.print("{}", .{str}); }, .Event => { - const event_type_value = brk: { - const value_ = value.get_unsafe(this.globalThis, "type") orelse break :brk JSValue.undefined; + const event_type_value: JSValue = brk: { + const value_ = value.get_unsafe(this.globalThis, "type") orelse break :brk .jsUndefined(); if (value_.isString()) { break :brk value_; } - break :brk JSValue.undefined; + break :brk .jsUndefined(); }; const event_type = switch (try EventType.map.fromJS(this.globalThis, event_type_value) orelse .unknown) { @@ -2972,7 +2972,7 @@ pub const Formatter = struct { comptime Output.prettyFmt("data: ", enable_ansi_colors), .{}, ); - const data = (try value.fastGet(this.globalThis, .data)) orelse JSValue.undefined; + const data: JSValue = (try value.fastGet(this.globalThis, .data)) orelse .jsUndefined(); const tag = Tag.getAdvanced(data, this.globalThis, .{ .hide_global = true, .disable_inspect_custom = this.disable_inspect_custom, diff --git a/src/bun.js/ResolveMessage.zig b/src/bun.js/ResolveMessage.zig index 0dbd055f67..8d059517db 100644 --- a/src/bun.js/ResolveMessage.zig +++ b/src/bun.js/ResolveMessage.zig @@ -61,7 +61,7 @@ pub const ResolveMessage = struct { defer atom.deref(); return atom.toJS(globalObject); }, - else => return .undefined, + else => return .jsUndefined(), } } diff --git a/src/bun.js/VirtualMachine.zig b/src/bun.js/VirtualMachine.zig index 82c1badd9c..ea609ac8c1 100644 --- a/src/bun.js/VirtualMachine.zig +++ b/src/bun.js/VirtualMachine.zig @@ -1686,7 +1686,7 @@ pub const main_file_name: string = "bun:main"; pub export fn Bun__drainMicrotasksFromJS(globalObject: *JSGlobalObject, callframe: *JSC.CallFrame) callconv(JSC.conv) JSValue { _ = callframe; // autofix globalObject.bunVM().drainMicrotasks(); - return .undefined; + return .jsUndefined(); } pub fn drainMicrotasks(this: *VirtualMachine) void { @@ -2345,7 +2345,7 @@ fn printErrorFromMaybePrivateData( pub fn reportUncaughtException(globalObject: *JSGlobalObject, exception: *Exception) JSValue { var jsc_vm = globalObject.bunVM(); _ = jsc_vm.uncaughtException(globalObject, exception.value(), false); - return .undefined; + return .jsUndefined(); } pub fn printStackTrace(comptime Writer: type, writer: Writer, trace: ZigStackTrace, comptime allow_ansi_colors: bool) !void { diff --git a/src/bun.js/api/BunObject.zig b/src/bun.js/api/BunObject.zig index dc8ee6f85b..be6a5d5a07 100644 --- a/src/bun.js/api/BunObject.zig +++ b/src/bun.js/api/BunObject.zig @@ -356,7 +356,7 @@ pub fn inspectTable(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) if (!arguments[1].isArray()) { arguments[2] = arguments[1]; - arguments[1] = .undefined; + arguments[1] = .jsUndefined(); } var formatOptions = ConsoleObject.FormatOptions{ @@ -380,7 +380,7 @@ pub fn inspectTable(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) const writer = buffered_writer.writer(); const Writer = @TypeOf(writer); - const properties = if (arguments[1].jsType().isArray()) arguments[1] else JSValue.undefined; + const properties: JSValue = if (arguments[1].jsType().isArray()) arguments[1] else .jsUndefined(); var table_printer = ConsoleObject.TablePrinter.init( globalThis, .Log, @@ -527,7 +527,7 @@ pub fn registerMacro(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFram arguments[1].protect(); get_or_put_result.value_ptr.* = arguments[1].asObjectRef(); - return .undefined; + return .jsUndefined(); } pub fn getCWD(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { @@ -694,7 +694,7 @@ pub fn openInEditor(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) return globalThis.throw("Opening editor failed {s}", .{@errorName(err)}); }; - return .undefined; + return .jsUndefined(); } pub fn getPublicPath(to: string, origin: URL, comptime Writer: type, writer: Writer) void { @@ -768,7 +768,7 @@ pub fn sleepSync(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) b } std.time.sleep(@as(u64, @intCast(milliseconds)) * std.time.ns_per_ms); - return .undefined; + return .jsUndefined(); } pub fn gc(vm: *JSC.VirtualMachine, sync: bool) usize { @@ -780,7 +780,7 @@ export fn Bun__gc(vm: *JSC.VirtualMachine, sync: bool) callconv(.C) usize { pub fn shrink(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { globalObject.vm().shrinkFootprint(); - return .undefined; + return .jsUndefined(); } fn doResolve(globalThis: *JSC.JSGlobalObject, arguments: []const JSValue) bun.JSError!JSC.JSValue { @@ -1043,22 +1043,22 @@ pub fn serve(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.J @field(@TypeOf(entry.tag()), @typeName(JSC.API.HTTPServer)) => { var server: *JSC.API.HTTPServer = entry.as(JSC.API.HTTPServer); server.onReloadFromZig(&config, globalObject); - return server.js_value.get() orelse .undefined; + return server.js_value.get() orelse .jsUndefined(); }, @field(@TypeOf(entry.tag()), @typeName(JSC.API.DebugHTTPServer)) => { var server: *JSC.API.DebugHTTPServer = entry.as(JSC.API.DebugHTTPServer); server.onReloadFromZig(&config, globalObject); - return server.js_value.get() orelse .undefined; + return server.js_value.get() orelse .jsUndefined(); }, @field(@TypeOf(entry.tag()), @typeName(JSC.API.DebugHTTPSServer)) => { var server: *JSC.API.DebugHTTPSServer = entry.as(JSC.API.DebugHTTPSServer); server.onReloadFromZig(&config, globalObject); - return server.js_value.get() orelse .undefined; + return server.js_value.get() orelse .jsUndefined(); }, @field(@TypeOf(entry.tag()), @typeName(JSC.API.HTTPSServer)) => { var server: *JSC.API.HTTPSServer = entry.as(JSC.API.HTTPSServer); server.onReloadFromZig(&config, globalObject); - return server.js_value.get() orelse .undefined; + return server.js_value.get() orelse .jsUndefined(); }, else => {}, } @@ -1288,7 +1288,7 @@ pub fn getS3DefaultClient(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC } pub fn getValkeyDefaultClient(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { - const valkey = JSC.API.Valkey.create(globalThis, &[_]JSValue{.undefined}) catch |err| { + const valkey = JSC.API.Valkey.create(globalThis, &.{.jsUndefined()}) catch |err| { if (err != error.JSError) { _ = globalThis.throwError(err, "Failed to create Redis client") catch {}; return .zero; @@ -1459,7 +1459,7 @@ pub const JSZlib = struct { // This has to be `inline` due to the callframe. inline fn getOptions(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!struct { JSC.Node.StringOrBuffer, ?JSValue } { const arguments = callframe.arguments_old(2).slice(); - const buffer_value = if (arguments.len > 0) arguments[0] else .undefined; + const buffer_value: JSValue = if (arguments.len > 0) arguments[0] else .jsUndefined(); const options_val: ?JSValue = if (arguments.len > 1 and arguments[1].isObject()) arguments[1] @@ -1731,7 +1731,7 @@ pub const JSZstd = struct { inline fn getOptions(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!struct { JSC.Node.StringOrBuffer, ?JSValue } { const arguments = callframe.arguments(); - const buffer_value = if (arguments.len > 0) arguments[0] else .undefined; + const buffer_value: JSValue = if (arguments.len > 0) arguments[0] else .jsUndefined(); const options_val: ?JSValue = if (arguments.len > 1 and arguments[1].isObject()) arguments[1] @@ -1765,7 +1765,7 @@ pub const JSZstd = struct { inline fn getOptionsAsync(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!struct { JSC.Node.StringOrBuffer, ?JSValue, i32 } { const arguments = callframe.arguments(); - const buffer_value = if (arguments.len > 0) arguments[0] else .undefined; + const buffer_value: JSValue = if (arguments.len > 0) arguments[0] else .jsUndefined(); const options_val: ?JSValue = if (arguments.len > 1 and arguments[1].isObject()) arguments[1] diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig index 1ea0de22c4..eed081bb05 100644 --- a/src/bun.js/api/JSBundler.zig +++ b/src/bun.js/api/JSBundler.zig @@ -88,7 +88,7 @@ pub const JSBundler = struct { if (try config.getArray(globalThis, "plugins")) |array| { const length = array.getLength(globalThis); var iter = array.arrayIterator(globalThis); - var onstart_promise_array: JSValue = JSValue.undefined; + var onstart_promise_array: JSValue = .jsUndefined(); var i: usize = 0; while (iter.next()) |plugin| : (i += 1) { if (!plugin.isObject()) { @@ -201,7 +201,7 @@ pub const JSBundler = struct { } if (try config.get(globalThis, "env")) |env| { - if (env != .undefined) { + if (!env.isUndefined()) { if (env == .null or env == .false or (env.isNumber() and env.asNumber() == 0)) { this.env_behavior = .disable; } else if (env == .true or (env.isNumber() and env.asNumber() == 1)) { diff --git a/src/bun.js/api/Timer.zig b/src/bun.js/api/Timer.zig index 71b9f443b5..41429661c7 100644 --- a/src/bun.js/api/Timer.zig +++ b/src/bun.js/api/Timer.zig @@ -330,8 +330,8 @@ pub const All = struct { globalThis.emitWarning( warning_string.transferToJS(globalThis), warning_type_string.transferToJS(globalThis), - .undefined, - .undefined, + .jsUndefined(), + .jsUndefined(), ) catch unreachable; } @@ -390,7 +390,7 @@ pub const All = struct { const countdown_int = try vm.timer.jsValueToCountdown(global, countdown, .clamp, true); const wrapped_promise = promise.withAsyncContextIfNeeded(global); - return TimeoutObject.init(global, id, .setTimeout, countdown_int, wrapped_promise, .undefined); + return TimeoutObject.init(global, id, .setTimeout, countdown_int, wrapped_promise, .jsUndefined()); } pub fn setImmediate( @@ -671,7 +671,7 @@ pub const TimeoutObject = struct { pub fn dispose(this: *TimeoutObject, globalThis: *JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { this.internals.cancel(globalThis.bunVM()); - return .undefined; + return .jsUndefined(); } }; @@ -766,7 +766,7 @@ pub const ImmediateObject = struct { pub fn dispose(this: *ImmediateObject, globalThis: *JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { this.internals.cancel(globalThis.bunVM()); - return .undefined; + return .jsUndefined(); } }; @@ -887,13 +887,12 @@ pub const TimerObjectInternals = struct { const globalThis = vm.global; const this_object = this.strong_this.get().?; - const callback, const arguments, var idle_timeout, var repeat = switch (kind) { + const callback: JSValue, const arguments: JSValue, var idle_timeout: JSValue, var repeat: JSValue = switch (kind) { .setImmediate => .{ ImmediateObject.js.callbackGetCached(this_object).?, ImmediateObject.js.argumentsGetCached(this_object).?, - - .undefined, - .undefined, + .jsUndefined(), + .jsUndefined(), }, .setTimeout, .setInterval => .{ TimeoutObject.js.callbackGetCached(this_object).?, diff --git a/src/bun.js/api/UnsafeObject.zig b/src/bun.js/api/UnsafeObject.zig index baee7761fe..1f7dcddaef 100644 --- a/src/bun.js/api/UnsafeObject.zig +++ b/src/bun.js/api/UnsafeObject.zig @@ -64,7 +64,7 @@ fn dump_mimalloc(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSErr if (bun.heap_breakdown.enabled) { dump_zone_malloc_stats(); } - return .undefined; + return .jsUndefined(); } const JSC = bun.JSC; diff --git a/src/bun.js/api/bun/dns_resolver.zig b/src/bun.js/api/bun/dns_resolver.zig index ec937a5259..4b071ae9f4 100644 --- a/src/bun.js/api/bun/dns_resolver.zig +++ b/src/bun.js/api/bun/dns_resolver.zig @@ -1787,7 +1787,7 @@ pub const InternalDNS = struct { }; prefetch(JSC.VirtualMachine.get().uwsLoop(), hostname_z, port); - return .undefined; + return .jsUndefined(); } pub fn prefetch(loop: *bun.uws.Loop, hostname: ?[:0]const u8, port: u16) void { @@ -2762,7 +2762,7 @@ pub const DNSResolver = struct { options = GetAddrInfo.Options.fromJS(optionsObject, globalThis) catch |err| { return switch (err) { - error.InvalidFlags => globalThis.throwInvalidArgumentValue("flags", try optionsObject.getTruthy(globalThis, "flags") orelse .undefined), + error.InvalidFlags => globalThis.throwInvalidArgumentValue("flags", try optionsObject.getTruthy(globalThis, "flags") orelse .jsUndefined()), error.JSError => |exception| exception, error.OutOfMemory => |oom| oom, @@ -3245,13 +3245,13 @@ pub const DNSResolver = struct { const first_af = try setChannelLocalAddress(channel, globalThis, arguments[0]); if (arguments.len < 2 or arguments[1].isUndefined()) { - return .undefined; + return .jsUndefined(); } const second_af = try setChannelLocalAddress(channel, globalThis, arguments[1]); if (first_af != second_af) { - return .undefined; + return .jsUndefined(); } switch (first_af) { @@ -3311,7 +3311,7 @@ pub const DNSResolver = struct { const err = c_ares.Error.get(r).?; return globalThis.throwValue(globalThis.createErrorInstance("ares_set_servers_ports error: {s}", .{err.label()})); } - return .undefined; + return .jsUndefined(); } const allocator = bun.default_allocator; @@ -3370,7 +3370,7 @@ pub const DNSResolver = struct { return globalThis.throwValue(globalThis.createErrorInstance("ares_set_servers_ports error: {s}", .{err.label()})); } - return .undefined; + return .jsUndefined(); } pub fn setGlobalServers(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -3402,7 +3402,7 @@ pub const DNSResolver = struct { _ = callframe; const channel = try this.getChannelOrError(globalThis); c_ares.ares_cancel(channel); - return .undefined; + return .jsUndefined(); } // Resolves the given address and port into a host name and service using the operating system's underlying getnameinfo implementation. diff --git a/src/bun.js/api/bun/h2_frame_parser.zig b/src/bun.js/api/bun/h2_frame_parser.zig index 69019ade3c..40362f34c2 100644 --- a/src/bun.js/api/bun/h2_frame_parser.zig +++ b/src/bun.js/api/bun/h2_frame_parser.zig @@ -419,7 +419,7 @@ pub fn jsAssertSettings(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallF } } } - return .undefined; + return .jsUndefined(); } pub fn jsGetPackedSettings(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -556,7 +556,7 @@ const Handlers = struct { pub fn callWriteCallback(this: *Handlers, callback: JSC.JSValue, data: []const JSValue) bool { if (!callback.isCallable()) return false; - this.vm.eventLoop().runCallback(callback, this.globalObject, .undefined, data); + this.vm.eventLoop().runCallback(callback, this.globalObject, .jsUndefined(), data); return true; } @@ -2609,7 +2609,7 @@ pub const H2FrameParser = struct { return globalObject.throwValue(err); }; - return .undefined; + return .jsUndefined(); } pub fn loadSettingsFromJSValue(this: *H2FrameParser, globalObject: *JSC.JSGlobalObject, options: JSC.JSValue) bun.JSError!void { @@ -2739,7 +2739,7 @@ pub const H2FrameParser = struct { } stream.windowSize = windowSizeValue; } - return .undefined; + return .jsUndefined(); } pub fn getCurrentState(this: *H2FrameParser, globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { @@ -2794,14 +2794,14 @@ pub const H2FrameParser = struct { if (opaque_data_arg.asArrayBuffer(globalObject)) |array_buffer| { const slice = array_buffer.byteSlice(); this.sendGoAway(0, @enumFromInt(errorCode), slice, lastStreamID, false); - return .undefined; + return .jsUndefined(); } } } } this.sendGoAway(0, @enumFromInt(errorCode), "", lastStreamID, false); - return .undefined; + return .jsUndefined(); } pub fn ping(this: *H2FrameParser, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { @@ -2819,7 +2819,7 @@ pub const H2FrameParser = struct { if (args_list.ptr[0].asArrayBuffer(globalObject)) |array_buffer| { const slice = array_buffer.slice(); this.sendPing(false, slice); - return .undefined; + return .jsUndefined(); } return globalObject.throw("Expected payload to be a Buffer", .{}); @@ -2843,7 +2843,7 @@ pub const H2FrameParser = struct { }; _ = frame.write(@TypeOf(writer), writer); _ = this.write(&buffer); - return .undefined; + return .jsUndefined(); } if (origin_arg.isString()) { @@ -2909,7 +2909,7 @@ pub const H2FrameParser = struct { _ = frame.write(@TypeOf(writer), writer); _ = this.write(buffer[0..total_length]); } - return .undefined; + return .jsUndefined(); } pub fn altsvc(this: *H2FrameParser, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { @@ -2957,11 +2957,11 @@ pub const H2FrameParser = struct { if (stream_id > 0) { // dont error but dont send frame to invalid stream id _ = this.streams.getPtr(stream_id) orelse { - return .undefined; + return .jsUndefined(); }; } this.sendAltSvc(stream_id, origin_str, value_str); - return .undefined; + return .jsUndefined(); } pub fn getEndAfterHeaders(this: *H2FrameParser, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { @@ -3332,7 +3332,7 @@ pub const H2FrameParser = struct { stream.state = .HALF_CLOSED_LOCAL; } this.dispatchWithExtra(.onStreamEnd, identifier, JSC.JSValue.jsNumber(@intFromEnum(stream.state))); - return .undefined; + return .jsUndefined(); } /// validate header name and convert to lowecase if needed fn toValidHeaderName(in: []const u8, out: []u8) ![]const u8 { @@ -3488,7 +3488,7 @@ pub const H2FrameParser = struct { JSC.JSValue.jsNumber(@intFromEnum(ErrorCode.FRAME_SIZE_ERROR)), ); this.dispatchWithExtra(.onStreamError, identifier, JSC.JSValue.jsNumber(stream.rstCode)); - return .undefined; + return .jsUndefined(); }; } } else { @@ -3527,7 +3527,7 @@ pub const H2FrameParser = struct { this.dispatchWithExtra(.onStreamError, identifier, JSC.JSValue.jsNumber(stream.rstCode)); - return .undefined; + return .jsUndefined(); }; } } @@ -3552,7 +3552,7 @@ pub const H2FrameParser = struct { stream.state = .HALF_CLOSED_LOCAL; } this.dispatchWithExtra(.onStreamEnd, identifier, JSC.JSValue.jsNumber(@intFromEnum(stream.state))); - return .undefined; + return .jsUndefined(); } pub fn writeStream(this: *H2FrameParser, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { JSC.markBinding(@src()); @@ -3578,7 +3578,7 @@ pub const H2FrameParser = struct { } const encoding: JSC.Node.Encoding = brk: { - if (encoding_arg == .undefined) { + if (encoding_arg.isUndefined()) { break :brk .utf8; } @@ -3649,7 +3649,7 @@ pub const H2FrameParser = struct { this.lastStreamID -= 2; } } - return .undefined; + return .jsUndefined(); } pub fn hasNativeRead(this: *H2FrameParser, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { @@ -3686,7 +3686,7 @@ pub const H2FrameParser = struct { return globalObject.throw("Invalid stream id", .{}); }; - return stream.jsContext.get() orelse .undefined; + return stream.jsContext.get() orelse .jsUndefined(); } pub fn setStreamContext(this: *H2FrameParser, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -3709,17 +3709,17 @@ pub const H2FrameParser = struct { } stream.setContext(context_arg, globalObject); - return .undefined; + return .jsUndefined(); } pub fn forEachStream(this: *H2FrameParser, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { JSC.markBinding(@src()); const args = callframe.arguments(); if (args.len < 1 or !args[0].isCallable()) { - return .undefined; + return .jsUndefined(); } const callback = args[0]; - const thisValue = if (args.len > 1) args[1] else .undefined; + const thisValue: JSValue = if (args.len > 1) args[1] else .jsUndefined(); var count: u32 = 0; var it = this.streams.valueIterator(); while (it.next()) |stream| { @@ -3727,7 +3727,7 @@ pub const H2FrameParser = struct { this.handlers.vm.eventLoop().runCallback(callback, globalObject, thisValue, &[_]JSC.JSValue{value}); count += 1; } - return .undefined; + return .jsUndefined(); } pub fn emitAbortToAllStreams(this: *H2FrameParser, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -3746,10 +3746,10 @@ pub const H2FrameParser = struct { const identifier = stream.getIdentifier(); identifier.ensureStillAlive(); stream.freeResources(this, false); - this.dispatchWith2Extra(.onAborted, identifier, .undefined, JSC.JSValue.jsNumber(@intFromEnum(old_state))); + this.dispatchWith2Extra(.onAborted, identifier, .jsUndefined(), JSC.JSValue.jsNumber(@intFromEnum(old_state))); } } - return .undefined; + return .jsUndefined(); } pub fn emitErrorToAllStreams(this: *H2FrameParser, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -3774,7 +3774,7 @@ pub const H2FrameParser = struct { this.dispatchWithExtra(.onStreamError, identifier, args_list.ptr[0]); } } - return .undefined; + return .jsUndefined(); } pub fn flushFromJS(this: *H2FrameParser, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { @@ -3932,7 +3932,7 @@ pub const H2FrameParser = struct { stream.state = .CLOSED; stream.rstCode = @intFromEnum(ErrorCode.COMPRESSION_ERROR); this.dispatchWithExtra(.onStreamError, stream.getIdentifier(), JSC.JSValue.jsNumber(stream.rstCode)); - return .undefined; + return .jsUndefined(); }; } } else if (!js_value.isEmptyOrUndefinedOrNull()) { @@ -4205,7 +4205,7 @@ pub const H2FrameParser = struct { const result = try this.readBytes(bytes); bytes = bytes[result..]; } - return .undefined; + return .jsUndefined(); } return globalObject.throw("Expected data to be a Buffer or ArrayBuffer", .{}); } @@ -4266,7 +4266,7 @@ pub const H2FrameParser = struct { // if we started with non native and go to native we now control the backpressure internally this.has_nonnative_backpressure = false; } - return .undefined; + return .jsUndefined(); } pub fn detachNativeSocket(this: *H2FrameParser) void { @@ -4441,7 +4441,7 @@ pub const H2FrameParser = struct { stream.freeResources(this, false); } this.detach(); - return .undefined; + return .jsUndefined(); } /// be careful when calling detach be sure that the socket is closed and the parser not accesible anymore /// this function can be called multiple times, it will erase stream info diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index c7df493d4d..28e8cf32f3 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -926,7 +926,7 @@ pub const Listener = struct { pub fn dispose(this: *Listener, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { this.doStop(true); - return .undefined; + return .jsUndefined(); } pub fn stop(this: *Listener, _: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { @@ -935,7 +935,7 @@ pub const Listener = struct { this.doStop(if (arguments.len > 0 and arguments.ptr[0].isBoolean()) arguments.ptr[0].toBoolean() else false); - return .undefined; + return .jsUndefined(); } fn doStop(this: *Listener, force_close: bool) void { @@ -1501,19 +1501,19 @@ fn NewSocket(comptime ssl: bool) type { pub fn resumeFromJS(this: *This, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { JSC.markBinding(@src()); - if (this.socket.isDetached()) return .undefined; + if (this.socket.isDetached()) return .jsUndefined(); log("resume", .{}); // we should not allow pausing/resuming a wrapped socket because a wrapped socket is 2 sockets and this can cause issues if (this.wrapped == .none and this.flags.is_paused) { this.flags.is_paused = !this.socket.resumeStream(); } - return .undefined; + return .jsUndefined(); } pub fn pauseFromJS(this: *This, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { JSC.markBinding(@src()); - if (this.socket.isDetached()) return .undefined; + if (this.socket.isDetached()) return .jsUndefined(); log("pause", .{}); // we should not allow pausing/resuming a wrapped socket because a wrapped socket is 2 sockets and this can cause issues @@ -1521,7 +1521,7 @@ fn NewSocket(comptime ssl: bool) type { this.flags.is_paused = this.socket.pauseStream(); } - return .undefined; + return .jsUndefined(); } pub fn setKeepAlive(this: *This, globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { @@ -1972,7 +1972,7 @@ fn NewSocket(comptime ssl: bool) type { const globalObject = handlers.globalObject; const this_value = this.getThisValue(globalObject); - var js_error: JSValue = .undefined; + var js_error: JSValue = .jsUndefined(); if (err != 0) { // errors here are always a read error js_error = bun.sys.Error.fromCodeInt(err, .read).toJSC(globalObject); @@ -2257,7 +2257,7 @@ fn NewSocket(comptime ssl: bool) type { fn writeOrEndBuffered(this: *This, globalObject: *JSC.JSGlobalObject, data_value: JSC.JSValue, encoding_value: JSC.JSValue, comptime is_end: bool) WriteResult { if (this.buffered_data_for_node_net.len == 0) { - var values = [4]JSC.JSValue{ data_value, .undefined, .undefined, encoding_value }; + var values = [4]JSC.JSValue{ data_value, .jsUndefined(), .jsUndefined(), encoding_value }; return this.writeOrEnd(globalObject, &values, true, is_end); } @@ -2387,16 +2387,16 @@ fn NewSocket(comptime ssl: bool) type { var encoding_value: JSC.JSValue = args[3]; if (args[2].isString()) { encoding_value = args[2]; - args[2] = .undefined; + args[2] = .jsUndefined(); } else if (args[1].isString()) { encoding_value = args[1]; - args[1] = .undefined; + args[1] = .jsUndefined(); } const offset_value = args[1]; const length_value = args[2]; - if (encoding_value != .undefined and (offset_value != .undefined or length_value != .undefined)) { + if (!encoding_value.isUndefined() and (!offset_value.isUndefined() or !length_value.isUndefined())) { return globalObject.throwTODO("Support encoding with offset and length altogether. Only either encoding or offset, length is supported, but not both combinations yet.") catch .fail; } diff --git a/src/bun.js/api/bun/spawn/stdio.zig b/src/bun.js/api/bun/spawn/stdio.zig index 0c01a06fe6..1d640e532a 100644 --- a/src/bun.js/api/bun/spawn/stdio.zig +++ b/src/bun.js/api/bun/spawn/stdio.zig @@ -284,15 +284,11 @@ pub const Stdio = union(enum) { } pub fn extract(out_stdio: *Stdio, globalThis: *JSC.JSGlobalObject, i: i32, value: JSValue) bun.JSError!void { - switch (value) { - // undefined: default - .undefined, .zero => return, - // null: ignore - .null => { - out_stdio.* = Stdio{ .ignore = {} }; - return; - }, - else => {}, + if (value == .zero) return; + if (value.isUndefined()) return; + if (value.isNull()) { + out_stdio.* = Stdio{ .ignore = {} }; + return; } if (value.isString()) { diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index defdc134e6..676463d32c 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -179,7 +179,7 @@ pub fn appendEnvpFromJS(globalThis: *JSC.JSGlobalObject, object: *JSC.JSObject, 2); while (try object_iter.next()) |key| { var value = object_iter.value; - if (value == .undefined) continue; + if (value.isUndefined()) continue; const line = try std.fmt.allocPrintZ(envp.allocator, "{}={}", .{ key, try value.getZigString(globalThis) }); @@ -591,7 +591,7 @@ pub fn asyncDispose( ) bun.JSError!JSValue { if (this.process.hasExited()) { // rely on GC to clean everything up in this case - return .undefined; + return .jsUndefined(); } const this_jsvalue = callframe.this(); @@ -726,12 +726,12 @@ fn closeProcess(this: *Subprocess) void { pub fn doRef(this: *Subprocess, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { this.jsRef(); - return .undefined; + return .jsUndefined(); } pub fn doUnref(this: *Subprocess, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { this.jsUnref(); - return .undefined; + return .jsUndefined(); } pub fn onStdinDestroyed(this: *Subprocess) void { @@ -761,7 +761,7 @@ pub fn disconnect(this: *Subprocess, globalThis: *JSGlobalObject, callframe: *JS _ = globalThis; _ = callframe; this.disconnectIPC(true); - return .undefined; + return .jsUndefined(); } pub fn getConnected(this: *Subprocess, globalThis: *JSGlobalObject) JSValue { @@ -1133,7 +1133,7 @@ pub const PipeReader = struct { return JSC.MarkedArrayBuffer.fromBytes(bytes, bun.default_allocator, .Uint8Array).toNodeBuffer(globalThis); }, else => { - return JSC.JSValue.undefined; + return .jsUndefined(); }, } } @@ -1597,9 +1597,9 @@ pub fn onProcessExit(this: *Subprocess, process: *Process, status: bun.spawn.Sta if (status == .err) status.err.toJSC(globalThis) else - .undefined; + .jsUndefined(); - const this_value = if (this_jsvalue.isEmptyOrUndefinedOrNull()) .undefined else this_jsvalue; + const this_value: JSValue = if (this_jsvalue.isEmptyOrUndefinedOrNull()) .jsUndefined() else this_jsvalue; this_value.ensureStillAlive(); const args = [_]JSValue{ diff --git a/src/bun.js/api/bun/udp_socket.zig b/src/bun.js/api/bun/udp_socket.zig index 987065e9bf..47a15e7266 100644 --- a/src/bun.js/api/bun/udp_socket.zig +++ b/src/bun.js/api/bun/udp_socket.zig @@ -801,13 +801,13 @@ pub const UDPSocket = struct { this.poll_ref.ref(globalThis.bunVM()); } - return .undefined; + return .jsUndefined(); } pub fn unref(this: *This, globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { this.poll_ref.unref(globalThis.bunVM()); - return .undefined; + return .jsUndefined(); } pub fn close( @@ -817,7 +817,7 @@ pub const UDPSocket = struct { ) bun.JSError!JSValue { if (!this.closed) this.socket.close(); - return .undefined; + return .jsUndefined(); } pub fn reload(this: *This, globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSValue { @@ -835,7 +835,7 @@ pub const UDPSocket = struct { previous_config.unprotect(); this.config = config; - return .undefined; + return .jsUndefined(); } pub fn getClosed(this: *This, _: *JSGlobalObject) JSValue { @@ -848,17 +848,17 @@ pub const UDPSocket = struct { } pub fn getPort(this: *This, _: *JSGlobalObject) JSValue { - if (this.closed) return .undefined; + if (this.closed) return .jsUndefined(); return JSValue.jsNumber(this.socket.boundPort()); } fn createSockAddr(globalThis: *JSGlobalObject, address_bytes: []const u8, port: u16) JSValue { - var sockaddr = SocketAddress.init(address_bytes, port) catch return .undefined; + var sockaddr = SocketAddress.init(address_bytes, port) catch return .jsUndefined(); return sockaddr.intoDTO(globalThis); } pub fn getAddress(this: *This, globalThis: *JSGlobalObject) JSValue { - if (this.closed) return .undefined; + if (this.closed) return .jsUndefined(); var buf: [64]u8 = [_]u8{0} ** 64; var length: i32 = 64; this.socket.boundIp(&buf, &length); @@ -869,8 +869,8 @@ pub const UDPSocket = struct { } pub fn getRemoteAddress(this: *This, globalThis: *JSC.JSGlobalObject) JSC.JSValue { - if (this.closed) return .undefined; - const connect_info = this.connect_info orelse return .undefined; + if (this.closed) return .jsUndefined(); + const connect_info = this.connect_info orelse return .jsUndefined(); var buf: [64]u8 = [_]u8{0} ** 64; var length: i32 = 64; this.socket.remoteIp(&buf, &length); @@ -948,7 +948,7 @@ pub const UDPSocket = struct { js.addressSetCached(callFrame.this(), globalThis, .zero); js.remoteAddressSetCached(callFrame.this(), globalThis, .zero); - return .undefined; + return .jsUndefined(); } pub fn jsDisconnect(globalObject: *JSC.JSGlobalObject, callFrame: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -969,6 +969,6 @@ pub const UDPSocket = struct { } this.connect_info = null; - return .undefined; + return .jsUndefined(); } }; diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig index 6b0f2320dd..bb8c24f763 100644 --- a/src/bun.js/api/ffi.zig +++ b/src/bun.js/api/ffi.zig @@ -558,7 +558,7 @@ pub const FFI = struct { } pub fn fromJSString(globalThis: *JSC.JSGlobalObject, value: JSC.JSValue, comptime property: []const u8) bun.JSError!StringArray { - if (value == .undefined) return .{}; + if (value.isUndefined()) return .{}; if (!value.isString()) { return globalThis.throwInvalidArgumentTypeValue(property, "array of strings", value); } @@ -595,7 +595,7 @@ pub const FFI = struct { } } - const symbols_object = object.getOwn(globalThis, "symbols") orelse .undefined; + const symbols_object: JSValue = object.getOwn(globalThis, "symbols") orelse .jsUndefined(); if (!globalThis.hasException() and (symbols_object == .zero or !symbols_object.isObject())) { return globalThis.throwInvalidArgumentTypeValue("symbols", "object", symbols_object); } @@ -668,7 +668,7 @@ pub const FFI = struct { while (try iter.next()) |entry| { const key = entry.toOwnedSliceZ(allocator) catch bun.outOfMemory(); var owned_value: [:0]const u8 = ""; - if (iter.value != .zero and iter.value != .undefined) { + if (!iter.value.isUndefinedOrNull()) { if (iter.value.isString()) { const value = try iter.value.getZigString(globalThis); if (value.len > 0) { @@ -866,7 +866,7 @@ pub const FFI = struct { ) bun.JSError!JSValue { JSC.markBinding(@src()); if (this.closed) { - return .undefined; + return .jsUndefined(); } this.closed = true; if (this.dylib) |*dylib| { @@ -894,7 +894,7 @@ pub const FFI = struct { // bun.default_allocator.free(relocated_bytes_to_free); // } - return .undefined; + return .jsUndefined(); } pub fn printCallback(global: *JSGlobalObject, object: JSC.JSValue) JSValue { @@ -1143,7 +1143,7 @@ pub const FFI = struct { pub fn getSymbols(_: *FFI, _: *JSC.JSGlobalObject) JSC.JSValue { // This shouldn't be called. The cachedValue is what should be called. - return .undefined; + return .jsUndefined(); } pub fn linkSymbols(global: *JSGlobalObject, object_value: JSC.JSValue) JSC.JSValue { diff --git a/src/bun.js/api/glob.zig b/src/bun.js/api/glob.zig index 151c7c1f54..aa063d5d45 100644 --- a/src/bun.js/api/glob.zig +++ b/src/bun.js/api/glob.zig @@ -331,7 +331,7 @@ pub fn __scan(this: *Glob, globalThis: *JSGlobalObject, callframe: *JSC.CallFram var arena = std.heap.ArenaAllocator.init(alloc); const globWalker = try this.makeGlobWalker(globalThis, &arguments, "scan", alloc, &arena) orelse { arena.deinit(); - return .undefined; + return .jsUndefined(); }; incrPendingActivityFlag(&this.has_pending_activity); @@ -354,7 +354,7 @@ pub fn __scanSync(this: *Glob, globalThis: *JSGlobalObject, callframe: *JSC.Call var arena = std.heap.ArenaAllocator.init(alloc); var globWalker = try this.makeGlobWalker(globalThis, &arguments, "scanSync", alloc, &arena) orelse { arena.deinit(); - return .undefined; + return .jsUndefined(); }; defer globWalker.deinit(true); diff --git a/src/bun.js/api/html_rewriter.zig b/src/bun.js/api/html_rewriter.zig index 805abb8fde..2e3578c882 100644 --- a/src/bun.js/api/html_rewriter.zig +++ b/src/bun.js/api/html_rewriter.zig @@ -1093,7 +1093,7 @@ pub const TextChunk = struct { fn contentHandler(this: *TextChunk, comptime Callback: (fn (*LOLHTML.TextChunk, []const u8, bool) LOLHTML.Error!void), thisObject: JSValue, globalObject: *JSGlobalObject, content: ZigString, contentOptions: ?ContentOptions) JSValue { if (this.text_chunk == null) - return .undefined; + return .jsUndefined(); var content_slice = content.toSlice(bun.default_allocator); defer content_slice.deinit(); diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 81c3c5c9d0..ed925c30fd 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -552,7 +552,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d bun.debugAssert(server.listener != null); // this assertion is only valid while listening return server.js_value.get() orelse brk: { bun.debugAssert(false); - break :brk .undefined; // safe-ish + break :brk .jsUndefined(); // safe-ish }; } @@ -936,7 +936,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d this.app.?.clearRoutes(); // only reload those two, but ignore if they're not specified. - if (this.config.onRequest != new_config.onRequest and (new_config.onRequest != .zero and new_config.onRequest != .undefined)) { + if (this.config.onRequest != new_config.onRequest and (new_config.onRequest != .zero and !new_config.onRequest.isUndefined())) { this.config.onRequest.unprotect(); this.config.onRequest = new_config.onRequest; } @@ -944,7 +944,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d this.config.onNodeHTTPRequest.unprotect(); this.config.onNodeHTTPRequest = new_config.onNodeHTTPRequest; } - if (this.config.onError != new_config.onError and (new_config.onError != .zero and new_config.onError != .undefined)) { + if (this.config.onError != new_config.onError and (new_config.onError != .zero and !new_config.onError.isUndefined())) { this.config.onError.unprotect(); this.config.onError = new_config.onError; } @@ -1048,7 +1048,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d this.onReloadFromZig(&new_config, globalThis); - return this.js_value.get() orelse .undefined; + return this.js_value.get() orelse .jsUndefined(); } pub fn onFetch( @@ -1196,7 +1196,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d this.stop(true); } - return .undefined; + return .jsUndefined(); } pub fn getPort( @@ -1204,7 +1204,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d _: *JSC.JSGlobalObject, ) JSC.JSValue { switch (this.config.address) { - .unix => return .undefined, + .unix => return .jsUndefined(), else => {}, } @@ -1303,7 +1303,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d pub fn getHostname(this: *ThisServer, globalThis: *JSGlobalObject) JSC.JSValue { switch (this.config.address) { - .unix => return .undefined, + .unix => return .jsUndefined(), else => {}, } @@ -1376,7 +1376,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d pub fn getAllClosedPromise(this: *ThisServer, globalThis: *JSC.JSGlobalObject) JSC.JSValue { if (this.listener == null and this.pending_requests == 0) { - return JSC.JSPromise.resolvedPromise(globalThis, .undefined).toJS(); + return JSC.JSPromise.resolvedPromise(globalThis, .jsUndefined()).toJS(); } const prom = &this.all_closed_promise; if (prom.strong.has()) { @@ -1789,7 +1789,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d resp.timeout(this.config.idleTimeout); const globalThis = this.globalThis; - const thisObject = this.js_value.get() orelse .undefined; + const thisObject: JSValue = this.js_value.get() orelse .jsUndefined(); const vm = this.vm; var node_http_response: ?*NodeHTTPResponse = null; @@ -1810,7 +1810,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d if (bun.http.Method.find(req.method())) |method| method.toJS(globalThis) else - .undefined, + .jsUndefined(), req, resp, upgrade_ctx, @@ -2795,7 +2795,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d const loop = this.globalThis.bunVM().eventLoop(); loop.enter(); defer loop.exit(); - _ = callback.call(this.globalThis, .undefined, &.{ JSValue.jsBoolean(is_ssl), node_socket, error_code_value, raw_packet_value }) catch |err| { + _ = callback.call(this.globalThis, .jsUndefined(), &.{ JSValue.jsBoolean(is_ssl), node_socket, error_code_value, raw_packet_value }) catch |err| { this.globalThis.reportActiveExceptionAsUnhandled(err); }; } @@ -2843,7 +2843,7 @@ pub const ServerAllConnectionsClosedTask = struct { bun.destroy(this); if (!vm.isShuttingDown()) { - promise.resolve(globalObject, .undefined); + promise.resolve(globalObject, .jsUndefined()); } } }; @@ -3215,7 +3215,7 @@ pub fn Server__setOnClientError_(globalThis: *JSC.JSGlobalObject, server: JSC.JS } else { bun.debugAssert(false); } - return .undefined; + return .jsUndefined(); } pub fn Server__setAppFlags_(globalThis: *JSC.JSGlobalObject, server: JSC.JSValue, require_host_header: bool, use_strict_method_validation: bool) bun.JSError!JSC.JSValue { @@ -3234,7 +3234,7 @@ pub fn Server__setAppFlags_(globalThis: *JSC.JSGlobalObject, server: JSC.JSValue } else { return globalThis.throw("Failed to set timeout: The 'this' value is not a Server.", .{}); } - return .undefined; + return .jsUndefined(); } pub fn Server__setMaxHTTPHeaderSize_(globalThis: *JSC.JSGlobalObject, server: JSC.JSValue, max_header_size: u64) bun.JSError!JSC.JSValue { @@ -3253,7 +3253,7 @@ pub fn Server__setMaxHTTPHeaderSize_(globalThis: *JSC.JSGlobalObject, server: JS } else { return globalThis.throw("Failed to set maxHeaderSize: The 'this' value is not a Server.", .{}); } - return .undefined; + return .jsUndefined(); } comptime { _ = Server__setIdleTimeout; diff --git a/src/bun.js/api/server/NodeHTTPResponse.zig b/src/bun.js/api/server/NodeHTTPResponse.zig index 426c8b90ec..8862dc9e18 100644 --- a/src/bun.js/api/server/NodeHTTPResponse.zig +++ b/src/bun.js/api/server/NodeHTTPResponse.zig @@ -259,7 +259,7 @@ pub fn dumpRequestBody(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObjec this.clearOnDataCallback(thisValue, globalObject); } - return .undefined; + return .jsUndefined(); } fn markRequestAsDone(this: *NodeHTTPResponse) void { @@ -394,14 +394,14 @@ pub fn jsRef(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObject, _: *JSC if (!this.isDone()) { this.js_ref.ref(globalObject.bunVM()); } - return .undefined; + return .jsUndefined(); } pub fn jsUnref(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { if (!this.isDone()) { this.js_ref.unref(globalObject.bunVM()); } - return .undefined; + return .jsUndefined(); } fn handleEndedIfNecessary(state: uws.State, globalObject: *JSC.JSGlobalObject) bun.JSError!void { @@ -436,12 +436,12 @@ pub fn writeHead(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObject, cal const state = this.raw_response.state(); try handleEndedIfNecessary(state, globalObject); - const status_code_value = if (arguments.len > 0) arguments[0] else .undefined; - const status_message_value = if (arguments.len > 1 and arguments[1] != .null) arguments[1] else .undefined; - const headers_object_value = if (arguments.len > 2 and arguments[2] != .null) arguments[2] else .undefined; + const status_code_value: JSValue = if (arguments.len > 0) arguments[0] else .jsUndefined(); + const status_message_value: JSValue = if (arguments.len > 1 and arguments[1] != .null) arguments[1] else .jsUndefined(); + const headers_object_value: JSValue = if (arguments.len > 2 and arguments[2] != .null) arguments[2] else .jsUndefined(); const status_code: i32 = brk: { - if (status_code_value != .undefined) { + if (!status_code_value.isUndefined()) { break :brk globalObject.validateIntegerRange(status_code_value, i32, 200, .{ .min = 100, .max = 999, @@ -454,7 +454,7 @@ pub fn writeHead(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObject, cal var stack_fallback = std.heap.stackFallback(256, bun.default_allocator); const allocator = stack_fallback.get(); - const status_message_slice = if (status_message_value != .undefined) + const status_message_slice = if (!status_message_value.isUndefined()) try status_message_value.toSlice(globalObject, allocator) else ZigString.Slice.empty; @@ -483,7 +483,7 @@ pub fn writeHead(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObject, cal break :do_it; } - return .undefined; + return .jsUndefined(); } fn writeHeadInternal(response: uws.AnyResponse, globalObject: *JSC.JSGlobalObject, status_message: []const u8, headers: JSC.JSValue) void { @@ -496,14 +496,14 @@ fn writeHeadInternal(response: uws.AnyResponse, globalObject: *JSC.JSGlobalObjec pub fn writeContinue(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { if (this.isDone()) { - return .undefined; + return .jsUndefined(); } const state = this.raw_response.state(); try handleEndedIfNecessary(state, globalObject); this.raw_response.writeContinue(); - return .undefined; + return .jsUndefined(); } pub const AbortEvent = enum(u8) { @@ -575,7 +575,7 @@ pub fn doPause(this: *NodeHTTPResponse, _: *JSC.JSGlobalObject, _: *JSC.CallFram } pub fn drainRequestBody(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { - return this.drainBufferedRequestBodyFromPause(globalObject) orelse .undefined; + return this.drainBufferedRequestBodyFromPause(globalObject) orelse .jsUndefined(); } fn drainBufferedRequestBodyFromPause(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObject) ?JSC.JSValue { @@ -640,7 +640,7 @@ pub export fn Bun__NodeHTTPRequest__onResolve(globalObject: *JSC.JSGlobalObject, this.onRequestComplete(); } - return .undefined; + return .jsUndefined(); } pub export fn Bun__NodeHTTPRequest__onReject(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(JSC.conv) JSC.JSValue { @@ -668,18 +668,18 @@ pub export fn Bun__NodeHTTPRequest__onReject(globalObject: *JSC.JSGlobalObject, } _ = globalObject.bunVM().uncaughtException(globalObject, err, true); - return .undefined; + return .jsUndefined(); } pub fn abort(this: *NodeHTTPResponse, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { if (this.isDone()) { - return .undefined; + return .jsUndefined(); } this.flags.socket_closed = true; const state = this.raw_response.state(); if (state.isHttpEndCalled()) { - return .undefined; + return .jsUndefined(); } resumeSocket(this); this.raw_response.clearOnData(); @@ -687,7 +687,7 @@ pub fn abort(this: *NodeHTTPResponse, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) this.raw_response.clearTimeout(); this.raw_response.endWithoutBody(true); this.onRequestComplete(); - return .undefined; + return .jsUndefined(); } fn onBufferRequestBodyWhilePaused(this: *NodeHTTPResponse, chunk: []const u8, last: bool) void { @@ -720,7 +720,7 @@ fn onDataOrAborted(this: *NodeHTTPResponse, chunk: []const u8, last: bool, event } if (js.onDataGetCached(thisValue)) |callback| { - if (callback == .undefined) { + if (callback.isUndefined()) { return; } @@ -746,10 +746,10 @@ fn onDataOrAborted(this: *NodeHTTPResponse, chunk: []const u8, last: bool, event if (chunk.len > 0) { break :brk JSC.ArrayBuffer.createBuffer(globalThis, chunk); } - break :brk .undefined; + break :brk .jsUndefined(); }; - event_loop.runCallback(callback, globalThis, .undefined, &.{ + event_loop.runCallback(callback, globalThis, .jsUndefined(), &.{ bytes, JSC.JSValue.jsBoolean(last), JSC.JSValue.jsNumber(@intFromEnum(event)), @@ -775,10 +775,10 @@ fn onDrain(this: *NodeHTTPResponse, offset: u64, response: uws.AnyResponse) bool const thisValue = this.getThisValue(); const on_writable = js.onWritableGetCached(thisValue) orelse return false; const globalThis = JSC.VirtualMachine.get().global; - js.onWritableSetCached(thisValue, globalThis, .undefined); // TODO(@heimskr): is this necessary? + js.onWritableSetCached(thisValue, globalThis, .jsUndefined()); // TODO(@heimskr): is this necessary? const vm = globalThis.bunVM(); - response.corked(JSC.EventLoop.runCallback, .{ vm.eventLoop(), on_writable, globalThis, .undefined, &.{JSC.JSValue.jsNumberFromUint64(offset)} }); + response.corked(JSC.EventLoop.runCallback, .{ vm.eventLoop(), on_writable, globalThis, .jsUndefined(), &.{JSC.JSValue.jsNumberFromUint64(offset)} }); // return true means we may have something to drain return true; } @@ -799,15 +799,15 @@ fn writeOrEnd( return globalObject.ERR(.STREAM_WRITE_AFTER_END, "Stream already ended", .{}).throw(); } - const input_value = if (arguments.len > 0) arguments[0] else .undefined; - var encoding_value = if (arguments.len > 1) arguments[1] else .undefined; - const callback_value = brk: { - if ((encoding_value != .null and encoding_value != .undefined) and encoding_value.isCallable()) { - encoding_value = .undefined; + const input_value: JSValue = if (arguments.len > 0) arguments[0] else .jsUndefined(); + var encoding_value: JSValue = if (arguments.len > 1) arguments[1] else .jsUndefined(); + const callback_value: JSValue = brk: { + if (!encoding_value.isUndefinedOrNull() and encoding_value.isCallable()) { + encoding_value = .jsUndefined(); break :brk arguments[1]; } - if (arguments.len > 2 and arguments[2] != .undefined) { + if (arguments.len > 2 and !arguments[2].isUndefined()) { if (!arguments[2].isCallable()) { return globalObject.throwInvalidArgumentTypeValue("callback", "function", arguments[2]); } @@ -815,7 +815,7 @@ fn writeOrEnd( break :brk arguments[2]; } - break :brk .undefined; + break :brk .jsUndefined(); }; const strict_content_length: ?u64 = brk: { @@ -826,12 +826,12 @@ fn writeOrEnd( }; const string_or_buffer: JSC.Node.StringOrBuffer = brk: { - if (input_value == .null or input_value == .undefined) { + if (input_value.isUndefinedOrNull()) { break :brk JSC.Node.StringOrBuffer.empty; } var encoding: JSC.Node.Encoding = .utf8; - if (encoding_value != .undefined and encoding_value != .null) { + if (!encoding_value.isUndefinedOrNull()) { if (!encoding_value.isString()) { return globalObject.throwInvalidArgumentTypeValue("encoding", "string", encoding_value); } @@ -903,11 +903,11 @@ fn writeOrEnd( switch (this.raw_response.write(bytes)) { .want_more => |written| { this.raw_response.clearOnWritable(); - js.onWritableSetCached(js_this, globalObject, .undefined); + js.onWritableSetCached(js_this, globalObject, .jsUndefined()); return JSC.JSValue.jsNumberFromUint64(written); }, .backpressure => |written| { - if (callback_value != .undefined) { + if (!callback_value.isUndefined()) { js.onWritableSetCached(js_this, globalObject, callback_value.withAsyncContextIfNeeded(globalObject)); this.raw_response.onWritable(*NodeHTTPResponse, onDrain, this); } @@ -919,22 +919,22 @@ fn writeOrEnd( } pub fn setOnWritable(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSValue) void { - if (this.isDone() or value == .undefined) { - js.onWritableSetCached(thisValue, globalObject, .undefined); + if (this.isDone() or value.isUndefined()) { + js.onWritableSetCached(thisValue, globalObject, .jsUndefined()); } else { js.onWritableSetCached(thisValue, globalObject, value.withAsyncContextIfNeeded(globalObject)); } } pub fn getOnWritable(_: *NodeHTTPResponse, thisValue: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue { - return js.onWritableGetCached(thisValue) orelse .undefined; + return js.onWritableGetCached(thisValue) orelse .jsUndefined(); } pub fn getOnAbort(this: *NodeHTTPResponse, thisValue: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue { if (this.flags.socket_closed) { - return .undefined; + return .jsUndefined(); } - return js.onAbortedGetCached(thisValue) orelse .undefined; + return js.onAbortedGetCached(thisValue) orelse .jsUndefined(); } pub fn setOnAbort(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSValue) void { @@ -942,7 +942,7 @@ pub fn setOnAbort(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalObject: return; } - if (this.isDone() or value == .undefined) { + if (this.isDone() or value.isUndefined()) { js.onAbortedSetCached(thisValue, globalObject, .zero); } else { js.onAbortedSetCached(thisValue, globalObject, value.withAsyncContextIfNeeded(globalObject)); @@ -950,7 +950,7 @@ pub fn setOnAbort(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalObject: } pub fn getOnData(_: *NodeHTTPResponse, thisValue: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue { - return js.onDataGetCached(thisValue) orelse .undefined; + return js.onDataGetCached(thisValue) orelse .jsUndefined(); } pub fn getHasCustomOnData(this: *NodeHTTPResponse, _: *JSC.JSGlobalObject) JSC.JSValue { @@ -968,7 +968,7 @@ pub fn setHasCustomOnData(this: *NodeHTTPResponse, _: *JSC.JSGlobalObject, value fn clearOnDataCallback(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject) void { if (this.body_read_state != .none) { if (thisValue != .zero) { - js.onDataSetCached(thisValue, globalObject, .undefined); + js.onDataSetCached(thisValue, globalObject, .jsUndefined()); } if (!this.flags.socket_closed) this.raw_response.clearOnData(); @@ -979,8 +979,8 @@ fn clearOnDataCallback(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalOb } pub fn setOnData(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSValue) void { - if (value == .undefined or this.flags.ended or this.flags.socket_closed or this.body_read_state == .none or this.flags.is_data_buffered_during_pause_last) { - js.onDataSetCached(thisValue, globalObject, .undefined); + if (value.isUndefined() or this.flags.ended or this.flags.socket_closed or this.body_read_state == .none or this.flags.is_data_buffered_during_pause_last) { + js.onDataSetCached(thisValue, globalObject, .jsUndefined()); defer { if (this.body_read_ref.has) { this.body_read_ref.unref(globalObject.bunVM()); @@ -1017,7 +1017,7 @@ pub fn write(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObject, callfra pub fn flushHeaders(this: *NodeHTTPResponse, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { this.raw_response.flushHeaders(); - return .undefined; + return .jsUndefined(); } pub fn end(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -1032,7 +1032,7 @@ pub fn getBytesWritten(this: *NodeHTTPResponse, _: *JSC.JSGlobalObject, _: *JSC. } fn handleCorked(globalObject: *JSC.JSGlobalObject, function: JSC.JSValue, result: *JSValue, is_exception: *bool) void { - result.* = function.call(globalObject, .undefined, &.{}) catch |err| { + result.* = function.call(globalObject, .jsUndefined(), &.{}) catch |err| { result.* = globalObject.takeException(err); is_exception.* = true; return; @@ -1091,7 +1091,7 @@ pub fn cork(this: *NodeHTTPResponse, globalObject: *JSC.JSGlobalObject, callfram } if (result == .zero) { - return .undefined; + return .jsUndefined(); } return result; diff --git a/src/bun.js/api/server/RequestContext.zig b/src/bun.js/api/server/RequestContext.zig index 44a52e611d..c9de993852 100644 --- a/src/bun.js/api/server/RequestContext.zig +++ b/src/bun.js/api/server/RequestContext.zig @@ -254,7 +254,7 @@ pub fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, const ctx = arguments.ptr[1].asPromisePtr(@This()); const err = arguments.ptr[0]; defer ctx.deref(); - handleReject(ctx, if (!err.isEmptyOrUndefinedOrNull()) err else .undefined); + handleReject(ctx, if (!err.isEmptyOrUndefinedOrNull()) err else .jsUndefined()); return JSValue.jsUndefined(); } @@ -1978,7 +1978,7 @@ pub fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, this.flags.has_called_error_handler = true; const result = server.config.onError.call( server.globalThis, - server.js_value.get() orelse .undefined, + server.js_value.get() orelse .jsUndefined(), &.{value}, ) catch |err| server.globalThis.takeException(err); defer result.ensureStillAlive(); diff --git a/src/bun.js/api/server/ServerWebSocket.zig b/src/bun.js/api/server/ServerWebSocket.zig index ef13bb044b..fed7652abd 100644 --- a/src/bun.js/api/server/ServerWebSocket.zig +++ b/src/bun.js/api/server/ServerWebSocket.zig @@ -243,7 +243,7 @@ pub fn onPing(this: *ServerWebSocket, _: uws.AnyWebSocket, data: []const u8) voi _ = cb.call( globalThis, - .undefined, + .jsUndefined(), &[_]JSC.JSValue{ this.getThisValue(), this.binaryToJS(globalThis, data) }, ) catch |e| { const err = globalThis.takeException(e); @@ -271,7 +271,7 @@ pub fn onPong(this: *ServerWebSocket, _: uws.AnyWebSocket, data: []const u8) voi _ = cb.call( globalThis, - .undefined, + .jsUndefined(), &[_]JSC.JSValue{ this.getThisValue(), this.binaryToJS(globalThis, data) }, ) catch |e| { const err = globalThis.takeException(e); @@ -324,7 +324,7 @@ pub fn onClose(this: *ServerWebSocket, _: uws.AnyWebSocket, code: i32, message: _ = handler.onClose.call( globalObject, - .undefined, + .jsUndefined(), &[_]JSC.JSValue{ this.getThisValue(), JSValue.jsNumber(code), bun.String.createUTF8ForJS(globalObject, message) }, ) catch |e| { const err = globalObject.takeException(e); @@ -1064,7 +1064,7 @@ pub fn close( this.this_value = this_value; if (this.isClosed()) { - return .undefined; + return .jsUndefined(); } const code = brk: { @@ -1089,7 +1089,7 @@ pub fn close( this.flags.closed = true; this.websocket().end(code, message_value.slice()); - return .undefined; + return .jsUndefined(); } pub fn terminate( @@ -1107,14 +1107,14 @@ pub fn terminate( this.this_value = this_value; if (this.isClosed()) { - return .undefined; + return .jsUndefined(); } this.flags.closed = true; this.this_value.unprotect(); this.websocket().close(); - return .undefined; + return .jsUndefined(); } pub fn getBinaryType( @@ -1272,7 +1272,7 @@ const Corker = struct { const this_value = this.this_value; this.result = this.callback.call( this.globalObject, - if (this_value == .zero) .undefined else this_value, + if (this_value == .zero) .jsUndefined() else this_value, this.args, ) catch |err| this.globalObject.takeException(err); } diff --git a/src/bun.js/api/server/WebSocketServerContext.zig b/src/bun.js/api/server/WebSocketServerContext.zig index db0b9196f4..fcd21dbe96 100644 --- a/src/bun.js/api/server/WebSocketServerContext.zig +++ b/src/bun.js/api/server/WebSocketServerContext.zig @@ -37,7 +37,7 @@ pub const Handler = struct { pub fn runErrorCallback(this: *const Handler, vm: *JSC.VirtualMachine, globalObject: *JSC.JSGlobalObject, error_value: JSC.JSValue) void { const onError = this.onError; if (!onError.isEmptyOrUndefinedOrNull()) { - _ = onError.call(globalObject, .undefined, &.{error_value}) catch |err| + _ = onError.call(globalObject, .jsUndefined(), &.{error_value}) catch |err| this.globalObject.reportActiveExceptionAsUnhandled(err); return; } diff --git a/src/bun.js/bindings/AbortSignal.zig b/src/bun.js/bindings/AbortSignal.zig index a7fbac8de2..6a36f61197 100644 --- a/src/bun.js/bindings/AbortSignal.zig +++ b/src/bun.js/bindings/AbortSignal.zig @@ -104,7 +104,7 @@ pub const AbortSignal = opaque { var reason: u8 = 0; const js_reason = WebCore__AbortSignal__reasonIfAborted(this, global, &reason); if (reason > 0) { - bun.debugAssert(js_reason == .undefined); + bun.debugAssert(js_reason.isUndefined()); return .{ .common = @enumFromInt(reason) }; } if (js_reason == .zero) { diff --git a/src/bun.js/bindings/CallFrame.zig b/src/bun.js/bindings/CallFrame.zig index ccaf58ef4c..8723874caa 100644 --- a/src/bun.js/bindings/CallFrame.zig +++ b/src/bun.js/bindings/CallFrame.zig @@ -17,15 +17,15 @@ pub const CallFrame = opaque { /// Usage: `const arg1, const arg2 = call_frame.argumentsAsArray(2);` pub fn argumentsAsArray(call_frame: *const CallFrame, comptime count: usize) [count]JSValue { const slice = call_frame.arguments(); - var value: [count]JSValue = .{.undefined} ** count; + var value: [count]JSValue = @splat(.jsUndefined()); const n = @min(call_frame.argumentsCount(), count); @memcpy(value[0..n], slice[0..n]); return value; } - /// This function protects out-of-bounds access by returning `JSValue.undefined` + /// This function protects out-of-bounds access by returning undefined pub fn argument(self: *const CallFrame, i: usize) JSC.JSValue { - return if (self.argumentsCount() > i) self.arguments()[i] else .undefined; + return if (self.argumentsCount() > i) self.arguments()[i] else .jsUndefined(); } pub fn argumentsCount(self: *const CallFrame) u32 { @@ -134,7 +134,7 @@ pub const CallFrame = opaque { } pub inline fn initUndef(comptime i: usize, ptr: [*]const JSC.JSValue) @This() { - var args = [1]JSC.JSValue{.undefined} ** max; + var args: [max]JSC.JSValue = @splat(.jsUndefined()); args[0..i].* = ptr[0..i].*; return @This(){ .ptr = args, .len = i }; } @@ -168,7 +168,7 @@ pub const CallFrame = opaque { const slice = self.arguments(); comptime bun.assert(max <= 9); return switch (@as(u4, @min(slice.len, max))) { - 0 => .{ .ptr = .{.undefined} ** max, .len = 0 }, + 0 => .{ .ptr = @splat(.jsUndefined()), .len = 0 }, inline 1...9 => |count| Arguments(max).initUndef(@min(count, max), slice.ptr), else => unreachable, }; diff --git a/src/bun.js/bindings/JSGlobalObject.zig b/src/bun.js/bindings/JSGlobalObject.zig index d747d1f6dc..aa8dc11bb0 100644 --- a/src/bun.js/bindings/JSGlobalObject.zig +++ b/src/bun.js/bindings/JSGlobalObject.zig @@ -481,9 +481,8 @@ pub const JSGlobalObject = opaque { message: bun.String, error_array: JSValue, ) JSValue { - if (bun.Environment.allow_assert) - bun.assert(error_array.isArray()); - return JSC__JSGlobalObject__createAggregateErrorWithArray(globalObject, error_array, message, .undefined); + if (bun.Environment.allow_assert) bun.assert(error_array.isArray()); + return JSC__JSGlobalObject__createAggregateErrorWithArray(globalObject, error_array, message, .jsUndefined()); } extern fn JSC__JSGlobalObject__generateHeapSnapshot(*JSGlobalObject) JSValue; @@ -686,7 +685,7 @@ pub const JSGlobalObject = opaque { }; pub fn validateIntegerRange(this: *JSGlobalObject, value: JSValue, comptime T: type, default: T, comptime range: IntegerRange) bun.JSError!T { - if (value == .undefined or value == .zero) { + if (value.isUndefined() or value == .zero) { return default; } diff --git a/src/bun.js/bindings/JSValue.zig b/src/bun.js/bindings/JSValue.zig index 93e1fa5eca..66ca74d22a 100644 --- a/src/bun.js/bindings/JSValue.zig +++ b/src/bun.js/bindings/JSValue.zig @@ -1,7 +1,6 @@ /// ABI-compatible with EncodedJSValue /// In the future, this type will exclude `zero`, encoding it as `error.JSError` instead. pub const JSValue = enum(i64) { - undefined = 0xa, null = 0x2, true = FFI.TrueI64, false = 0x6, @@ -21,6 +20,10 @@ pub const JSValue = enum(i64) { property_does_not_exist_on_object = 0x4, _, + /// not `pub` on purpose. + /// use .jsUndefined() so as to not be accidentally confused/typo'd with Zig undefined. + const @"undefined": JSValue = @enumFromInt(0xa); + /// When JavaScriptCore throws something, it returns a null cell (0). The /// exception is set on the global object. ABI-compatible with EncodedJSValue. pub const MaybeException = enum(backing_int) { @@ -700,7 +703,7 @@ pub const JSValue = enum(i64) { } pub inline fn jsUndefined() JSValue { - return JSValue.undefined; + return @enumFromInt(0xa); } pub fn className(this: JSValue, globalThis: *JSGlobalObject) ZigString { @@ -891,7 +894,7 @@ pub const JSValue = enum(i64) { } pub inline fn isUndefined(this: JSValue) bool { - return this == .undefined; + return @intFromEnum(this) == 0xa; } pub inline fn isNull(this: JSValue) bool { return this == .null; @@ -1094,7 +1097,7 @@ pub const JSValue = enum(i64) { pub inline fn isCell(this: JSValue) bool { return switch (this) { - .zero, .undefined, .null, .true, .false => false, + .zero, JSValue.undefined, .null, .true, .false => false, else => (@as(u64, @bitCast(@intFromEnum(this))) & FFI.NotCellMask) == 0, }; } @@ -1370,7 +1373,7 @@ pub const JSValue = enum(i64) { return switch (JSC__JSValue__fastGet(this, global, @intFromEnum(builtin_name))) { .zero => error.JSError, - .undefined, .property_does_not_exist_on_object => null, + JSValue.undefined, .property_does_not_exist_on_object => null, else => |val| val, }; } @@ -1455,7 +1458,7 @@ pub const JSValue = enum(i64) { } return switch (JSC__JSValue__getIfPropertyExistsImpl(this, global, property.ptr, @intCast(property.len))) { - .undefined, .zero, .property_does_not_exist_on_object => null, + JSValue.undefined, .zero, .property_does_not_exist_on_object => null, else => |val| val, }; } @@ -1491,7 +1494,7 @@ pub const JSValue = enum(i64) { // since there are false positives, the better path is to make them // negatives, as the number of places that desire throwing on // existing undefined is extremely small, but non-zero. - .undefined => null, + JSValue.undefined => null, else => |val| val, }; } @@ -1511,7 +1514,7 @@ pub const JSValue = enum(i64) { return switch (JSC__JSValue__getPropertyValue(target, global, property_name.ptr, @intCast(property_name.len))) { .zero => error.JSError, .property_does_not_exist_on_object => null, - .undefined => null, + JSValue.undefined => null, else => |val| val, }; } @@ -1534,7 +1537,7 @@ pub const JSValue = enum(i64) { pub fn getOwnTruthy(this: JSValue, global: *JSGlobalObject, property_name: anytype) ?JSValue { if (getOwn(this, global, property_name)) |prop| { - if (prop == .undefined) return null; + if (prop.isUndefined()) return null; return prop; } @@ -1564,7 +1567,7 @@ pub const JSValue = enum(i64) { .zero => unreachable, // Treat undefined and null as unspecified - .null, .undefined => null, + .null, JSValue.undefined => null, // false, 0, are deliberately not included in this list. // That would prevent you from passing `0` or `false` to various Bun APIs. @@ -1810,7 +1813,7 @@ pub const JSValue = enum(i64) { const prop = try this.get(global, property_name) orelse return null; return switch (prop) { - .undefined => null, + JSValue.undefined => null, .false, .true => prop == .true, else => { return JSC.Node.validators.throwErrInvalidArgType(global, property_name, .{}, "boolean", prop); @@ -2346,7 +2349,7 @@ pub const JSValue = enum(i64) { } switch (comptime Type) { - void => return .undefined, + void => return .jsUndefined(), bool => return JSC.JSValue.jsBoolean(if (comptime Type != T) value.* else value), *JSC.JSGlobalObject => return value.toJSValue(), []const u8, [:0]const u8, [*:0]const u8, []u8, [:0]u8, [*:0]u8 => { diff --git a/src/bun.js/ipc.zig b/src/bun.js/ipc.zig index caaec23e3c..d62e9c0529 100644 --- a/src/bun.js/ipc.zig +++ b/src/bun.js/ipc.zig @@ -644,8 +644,8 @@ pub const SendQueue = struct { global.emitWarning( warning.transferToJS(global), warning_name.transferToJS(global), - .undefined, - .undefined, + .jsUndefined(), + .jsUndefined(), ) catch |e| { _ = global.takeException(e); }; @@ -927,7 +927,7 @@ const MAX_HANDLE_RETRANSMISSIONS = 3; fn emitProcessErrorEvent(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { const ex = callframe.argumentsAsArray(1)[0]; JSC.VirtualMachine.Process__emitErrorEvent(globalThis, ex); - return .undefined; + return .jsUndefined(); } const FromEnum = enum { subprocess_exited, subprocess, process }; fn doSendErr(globalObject: *JSC.JSGlobalObject, callback: JSC.JSValue, ex: JSC.JSValue, from: FromEnum) bun.JSError!JSC.JSValue { @@ -948,11 +948,11 @@ pub fn doSend(ipc: ?*SendQueue, globalObject: *JSC.JSGlobalObject, callFrame: *J if (handle.isCallable()) { callback = handle; - handle = .undefined; - options_ = .undefined; + handle = .jsUndefined(); + options_ = .jsUndefined(); } else if (options_.isCallable()) { callback = options_; - options_ = .undefined; + options_ = .jsUndefined(); } else if (!options_.isUndefined()) { try globalObject.validateObject("options", options_, .{}); } @@ -979,7 +979,7 @@ pub fn doSend(ipc: ?*SendQueue, globalObject: *JSC.JSGlobalObject, callFrame: *J if (!handle.isUndefinedOrNull()) { const serialized_array: JSC.JSValue = try ipcSerialize(globalObject, message, handle); if (serialized_array.isUndefinedOrNull()) { - handle = .undefined; + handle = .jsUndefined(); } else { const serialized_handle = serialized_array.getIndex(globalObject, 0); const serialized_message = serialized_array.getIndex(globalObject, 1); @@ -1023,14 +1023,14 @@ pub fn doSend(ipc: ?*SendQueue, globalObject: *JSC.JSGlobalObject, callFrame: *J pub fn emitHandleIPCMessage(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { const target, const message, const handle = callframe.argumentsAsArray(3); if (target.isNull()) { - const ipc = globalThis.bunVM().getIPCInstance() orelse return .undefined; + const ipc = globalThis.bunVM().getIPCInstance() orelse return .jsUndefined(); ipc.handleIPCMessage(.{ .data = message }, handle); } else { - if (!target.isCell()) return .undefined; - const subprocess = bun.JSC.Subprocess.fromJSDirect(target) orelse return .undefined; + if (!target.isCell()) return .jsUndefined(); + const subprocess = bun.JSC.Subprocess.fromJSDirect(target) orelse return .jsUndefined(); subprocess.handleIPCMessage(.{ .data = message }, handle); } - return .undefined; + return .jsUndefined(); } const IPCCommand = union(enum) { @@ -1131,7 +1131,7 @@ fn handleIPCMessage(send_queue: *SendQueue, message: DecodedIPCMessage, globalTh } else { switch (send_queue.owner) { inline else => |owner| { - owner.handleIPCMessage(message, .undefined); + owner.handleIPCMessage(message, .jsUndefined()); }, } } diff --git a/src/bun.js/jsc/host_fn.zig b/src/bun.js/jsc/host_fn.zig index 74c5167e99..a563783e63 100644 --- a/src/bun.js/jsc/host_fn.zig +++ b/src/bun.js/jsc/host_fn.zig @@ -694,7 +694,7 @@ pub fn wrapStaticMethod( ?jsc.Node.StringOrBuffer => { if (iter.nextEat()) |arg| { args[i] = try jsc.Node.StringOrBuffer.fromJS(globalThis, iter.arena.allocator(), arg) orelse brk: { - if (arg == .undefined) { + if (arg.isUndefined()) { break :brk null; } diff --git a/src/bun.js/node.zig b/src/bun.js/node.zig index d20ade3803..55182c946b 100644 --- a/src/bun.js/node.zig +++ b/src/bun.js/node.zig @@ -198,7 +198,7 @@ pub fn Maybe(comptime ReturnTypeT: type, comptime ErrorTypeT: type) type { .result => |r| switch (ReturnType) { JSC.JSValue => r, - void => .undefined, + void => .jsUndefined(), bool => JSC.JSValue.jsBoolean(r), JSC.ArrayBuffer => r.toJS(globalObject, null), diff --git a/src/bun.js/node/node_cluster_binding.zig b/src/bun.js/node/node_cluster_binding.zig index 9d86e05cf1..1aa1c72e6a 100644 --- a/src/bun.js/node/node_cluster_binding.zig +++ b/src/bun.js/node/node_cluster_binding.zig @@ -60,7 +60,7 @@ pub fn sendHelperChild(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFram const arguments_ = callframe_.arguments_old(1).slice(); const ex = arguments_[0]; Process__emitErrorEvent(globalThis_, ex.toError() orelse ex); - return .undefined; + return .jsUndefined(); } }; @@ -84,7 +84,7 @@ pub fn onInternalMessageChild(globalThis: *JSC.JSGlobalObject, callframe: *JSC.C child_singleton.worker = .create(arguments[0], globalThis); child_singleton.cb = .create(arguments[1], globalThis); try child_singleton.flush(globalThis); - return .undefined; + return .jsUndefined(); } pub fn handleInternalMessageChild(globalThis: *JSC.JSGlobalObject, message: JSC.JSValue) bun.JSError!void { @@ -216,11 +216,11 @@ pub fn sendHelperPrimary(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFr pub fn onInternalMessagePrimary(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { const arguments = callframe.arguments_old(3).ptr; const subprocess = arguments[0].as(bun.JSC.Subprocess).?; - const ipc_data = subprocess.ipc() orelse return .undefined; + const ipc_data = subprocess.ipc() orelse return .jsUndefined(); // TODO: remove these strongs. ipc_data.internal_msg_queue.worker = .create(arguments[1], globalThis); ipc_data.internal_msg_queue.cb = .create(arguments[2], globalThis); - return .undefined; + return .jsUndefined(); } pub fn handleInternalMessagePrimary(globalThis: *JSC.JSGlobalObject, subprocess: *JSC.Subprocess, message: JSC.JSValue) bun.JSError!void { @@ -275,7 +275,7 @@ pub fn setRef(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun. } else { vm.channel_ref.unref(vm); } - return .undefined; + return .jsUndefined(); } export fn Bun__refChannelUnlessOverridden(globalObject: *JSC.JSGlobalObject) void { diff --git a/src/bun.js/node/node_crypto_binding.zig b/src/bun.js/node/node_crypto_binding.zig index b75c51de1e..28f6d1dbfb 100644 --- a/src/bun.js/node/node_crypto_binding.zig +++ b/src/bun.js/node/node_crypto_binding.zig @@ -211,7 +211,7 @@ const random = struct { fn runFromJS(this: *JobCtx, global: *JSGlobalObject, callback: JSValue) void { const vm = global.bunVM(); - vm.eventLoop().runCallback(callback, global, .undefined, &.{ .null, this.value }); + vm.eventLoop().runCallback(callback, global, .jsUndefined(), &.{ .null, this.value }); } fn deinit(this: *JobCtx) void { @@ -266,7 +266,7 @@ const random = struct { const res = std.crypto.random.intRangeLessThan(i64, min, max); if (!callback.isUndefined()) { - callback.callNextTick(global, [2]JSValue{ .undefined, JSValue.jsNumber(res) }); + callback.callNextTick(global, [2]JSValue{ .jsUndefined(), JSValue.jsNumber(res) }); return JSValue.jsUndefined(); } @@ -279,7 +279,7 @@ const random = struct { var disable_entropy_cache = false; if (args.len > 0) { const options = args[0]; - if (options != .undefined) { + if (!options.isUndefined()) { try validators.validateObject(global, options, "options", .{}, .{}); if (try options.get(global, "disableEntropyCache")) |disable_entropy_cache_value| { disable_entropy_cache = try validators.validateBoolean(global, disable_entropy_cache_value, "options.disableEntropyCache", .{}); @@ -351,7 +351,7 @@ const random = struct { }; try Job.initAndSchedule(global, callback, &ctx); - return .undefined; + return .jsUndefined(); } fn randomFillSync(global: *JSGlobalObject, callFrame: *JSC.CallFrame) JSError!JSValue { @@ -414,8 +414,8 @@ const random = struct { try assertSize(global, size_value, element_size, offset, buf.byte_len); if (size == 0) { - _ = try callback.call(global, .undefined, &.{ .null, JSValue.jsNumber(0) }); - return .undefined; + _ = try callback.call(global, .jsUndefined(), &.{ .null, JSValue.jsNumber(0) }); + return .jsUndefined(); } const ctx: JobCtx = .{ @@ -426,7 +426,7 @@ const random = struct { }; try Job.initAndSchedule(global, callback, &ctx); - return .undefined; + return .jsUndefined(); } }; @@ -481,7 +481,7 @@ pub fn timingSafeEqual(global: *JSGlobalObject, callFrame: *JSC.CallFrame) JSErr } pub fn secureHeapUsed(_: *JSGlobalObject, _: *JSC.CallFrame) JSError!JSValue { - return .undefined; + return .jsUndefined(); } pub fn getFips(_: *JSGlobalObject, _: *JSC.CallFrame) JSError!JSValue { @@ -489,7 +489,7 @@ pub fn getFips(_: *JSGlobalObject, _: *JSC.CallFrame) JSError!JSValue { } pub fn setFips(_: *JSGlobalObject, _: *JSC.CallFrame) JSError!JSValue { - return .undefined; + return .jsUndefined(); } pub fn setEngine(global: *JSGlobalObject, _: *JSC.CallFrame) JSError!JSValue { @@ -540,7 +540,7 @@ const Scrypt = struct { callFrame.argumentsAsArray(5); if (is_async) { - if (callback == .undefined) { + if (callback.isUndefined()) { callback = maybe_options_value.?; maybe_options_value = null; } @@ -718,17 +718,17 @@ const Scrypt = struct { var buf: [256]u8 = undefined; const msg = BoringSSL.ERR_error_string_n(err, &buf, buf.len); const exception = global.ERR(.CRYPTO_OPERATION_FAILED, "Scrypt failed: {s}", .{msg}).toJS(); - vm.eventLoop().runCallback(callback, global, .undefined, &.{exception}); + vm.eventLoop().runCallback(callback, global, .jsUndefined(), &.{exception}); return; } const exception = global.ERR(.CRYPTO_OPERATION_FAILED, "Scrypt failed", .{}).toJS(); - vm.eventLoop().runCallback(callback, global, .undefined, &.{exception}); + vm.eventLoop().runCallback(callback, global, .jsUndefined(), &.{exception}); return; } const buf = this.buf.swap(); - vm.eventLoop().runCallback(callback, global, .undefined, &.{ .undefined, buf }); + vm.eventLoop().runCallback(callback, global, .jsUndefined(), &.{ .jsUndefined(), buf }); } fn deinit(this: *Scrypt) void { @@ -739,7 +739,7 @@ const Scrypt = struct { fn scrypt(global: *JSGlobalObject, callFrame: *JSC.CallFrame) JSError!JSValue { const ctx, const callback = try Scrypt.fromJS(global, callFrame, true); try Scrypt.Job.initAndSchedule(global, callback, &ctx); - return .undefined; + return .jsUndefined(); } fn scryptSync(global: *JSGlobalObject, callFrame: *JSC.CallFrame) JSError!JSValue { diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index c1688a73cb..24fc6688c7 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -1286,11 +1286,11 @@ pub const Arguments = struct { pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Rename { const old_path = try PathLike.fromJS(ctx, arguments) orelse { - return ctx.throwInvalidArgumentTypeValue("oldPath", "string or an instance of Buffer or URL", arguments.next() orelse .undefined); + return ctx.throwInvalidArgumentTypeValue("oldPath", "string or an instance of Buffer or URL", arguments.next() orelse .jsUndefined()); }; const new_path = try PathLike.fromJS(ctx, arguments) orelse { - return ctx.throwInvalidArgumentTypeValue("newPath", "string or an instance of Buffer or URL", arguments.next() orelse .undefined); + return ctx.throwInvalidArgumentTypeValue("newPath", "string or an instance of Buffer or URL", arguments.next() orelse .jsUndefined()); }; return Rename{ .old_path = old_path, .new_path = new_path }; @@ -1350,7 +1350,7 @@ pub const Arguments = struct { } pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Writev { - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; @@ -1404,7 +1404,7 @@ pub const Arguments = struct { } pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Readv { - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; @@ -1450,7 +1450,7 @@ pub const Arguments = struct { } pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!FTruncate { - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; @@ -1521,7 +1521,7 @@ pub const Arguments = struct { pub fn toThreadSafe(_: *const @This()) void {} pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Fchown { - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; @@ -1619,7 +1619,7 @@ pub const Arguments = struct { }; errdefer path.deinit(); - const mode_arg = arguments.next() orelse .undefined; + const mode_arg: JSC.JSValue = arguments.next() orelse .jsUndefined(); const mode: Mode = try JSC.Node.modeFromJS(ctx, mode_arg) orelse { return JSC.Node.validators.throwErrInvalidArgType(ctx, "mode", .{}, "number", mode_arg); }; @@ -1639,12 +1639,12 @@ pub const Arguments = struct { pub fn toThreadSafe(_: *const @This()) void {} pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!FChmod { - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; - const mode_arg = arguments.next() orelse .undefined; + const mode_arg: JSC.JSValue = arguments.next() orelse .jsUndefined(); const mode: Mode = try JSC.Node.modeFromJS(ctx, mode_arg) orelse { return JSC.Node.validators.throwErrInvalidArgType(ctx, "mode", .{}, "number", mode_arg); }; @@ -1753,7 +1753,7 @@ pub const Arguments = struct { pub fn toThreadSafe(_: *@This()) void {} pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Fstat { - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; @@ -2067,7 +2067,7 @@ pub const Arguments = struct { if (try val.get(ctx, "maxRetries")) |retries| { max_retries = @intCast(try JSC.Node.validators.validateInteger(ctx, retries, "options.maxRetries", 0, std.math.maxInt(u32))); } - } else if (val != .undefined) { + } else if (!val.isUndefined()) { return ctx.throwInvalidArguments("The \"options\" argument must be of type object.", .{}); } } @@ -2160,7 +2160,7 @@ pub const Arguments = struct { pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!MkdirTemp { const prefix = try PathLike.fromJS(ctx, arguments) orelse { - return ctx.throwInvalidArgumentTypeValue("prefix", "string, Buffer, or URL", arguments.next() orelse .undefined); + return ctx.throwInvalidArgumentTypeValue("prefix", "string, Buffer, or URL", arguments.next() orelse .jsUndefined()); }; errdefer prefix.deinit(); @@ -2268,7 +2268,7 @@ pub const Arguments = struct { pub fn toThreadSafe(_: Close) void {} pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Close { - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; @@ -2355,7 +2355,7 @@ pub const Arguments = struct { } pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Futimes { - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; @@ -2427,7 +2427,7 @@ pub const Arguments = struct { } pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Write { - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; @@ -2532,7 +2532,7 @@ pub const Arguments = struct { // fs_binding.read(fd, buffer, offset, length, position) // fd = getValidatedFd(fd); - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; @@ -2977,7 +2977,7 @@ pub const Arguments = struct { } pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!FdataSync { - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; @@ -3127,7 +3127,7 @@ pub const Arguments = struct { pub fn toThreadSafe(_: *const @This()) void {} pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Fsync { - const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; + const fd_value: JSC.JSValue = arguments.nextEat() orelse .jsUndefined(); const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); }; @@ -3144,14 +3144,14 @@ pub const StatOrNotFound = union(enum) { pub fn toJS(this: *StatOrNotFound, globalObject: *JSC.JSGlobalObject) JSC.JSValue { return switch (this.*) { .stats => this.stats.toJS(globalObject), - .not_found => JSC.JSValue.undefined, + .not_found => .jsUndefined(), }; } pub fn toJSNewlyCreated(this: *const StatOrNotFound, globalObject: *JSC.JSGlobalObject) JSC.JSValue { return switch (this.*) { .stats => this.stats.toJSNewlyCreated(globalObject), - .not_found => JSC.JSValue.undefined, + .not_found => .jsUndefined(), }; } }; @@ -3163,7 +3163,7 @@ pub const StringOrUndefined = union(enum) { pub fn toJS(this: *const StringOrUndefined, globalObject: *JSC.JSGlobalObject) JSC.JSValue { return switch (this.*) { .string => this.string.toJS(globalObject), - .none => JSC.JSValue.undefined, + .none => .jsUndefined(), }; } }; @@ -5876,7 +5876,7 @@ pub const NodeFS = struct { .code = bun.String.init(@errorName(err)), .path = bun.String.init(args.path.slice()), }).toErrorInstance(args.global_this)) catch {}; - return Maybe(Return.Watch){ .result = JSC.JSValue.undefined }; + return Maybe(Return.Watch){ .result = .jsUndefined() }; }; return Maybe(Return.Watch){ .result = watcher }; } diff --git a/src/bun.js/node/node_fs_binding.zig b/src/bun.js/node/node_fs_binding.zig index 538bcf7661..ee9a788f27 100644 --- a/src/bun.js/node/node_fs_binding.zig +++ b/src/bun.js/node/node_fs_binding.zig @@ -218,7 +218,7 @@ pub fn createMemfdForTesting(globalObject: *JSC.JSGlobalObject, callFrame: *JSC. const arguments = callFrame.arguments_old(1); if (arguments.len < 1) { - return .undefined; + return .jsUndefined(); } if (comptime !bun.Environment.isLinux) { diff --git a/src/bun.js/node/node_fs_stat_watcher.zig b/src/bun.js/node/node_fs_stat_watcher.zig index ba51540eba..a3ff4453c6 100644 --- a/src/bun.js/node/node_fs_stat_watcher.zig +++ b/src/bun.js/node/node_fs_stat_watcher.zig @@ -309,7 +309,7 @@ pub const StatWatcher = struct { if (obj.js_this != .zero) { return obj.js_this; } - return .undefined; + return .jsUndefined(); } }; @@ -318,7 +318,7 @@ pub const StatWatcher = struct { this.persistent = true; this.poll_ref.ref(this.ctx); } - return .undefined; + return .jsUndefined(); } pub fn doUnref(this: *StatWatcher, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -326,7 +326,7 @@ pub const StatWatcher = struct { this.persistent = false; this.poll_ref.unref(this.ctx); } - return .undefined; + return .jsUndefined(); } /// Stops file watching but does not free the instance. @@ -341,7 +341,7 @@ pub const StatWatcher = struct { pub fn doClose(this: *StatWatcher, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { this.close(); - return .undefined; + return .jsUndefined(); } /// If the scheduler is not using this, free instantly, otherwise mark for being freed. @@ -408,7 +408,7 @@ pub const StatWatcher = struct { _ = js.listenerGetCached(this.js_this).?.call( this.globalThis, - .undefined, + .jsUndefined(), &[2]JSC.JSValue{ jsvalue, jsvalue, @@ -444,7 +444,7 @@ pub const StatWatcher = struct { _ = js.listenerGetCached(this.js_this).?.call( this.globalThis, - .undefined, + .jsUndefined(), &[2]JSC.JSValue{ current_jsvalue, prev_jsvalue, diff --git a/src/bun.js/node/node_fs_watcher.zig b/src/bun.js/node/node_fs_watcher.zig index 0b84b4e776..72c8b9d5e5 100644 --- a/src/bun.js/node/node_fs_watcher.zig +++ b/src/bun.js/node/node_fs_watcher.zig @@ -524,7 +524,7 @@ pub const FSWatcher = struct { if (js_this == .zero) return; const listener = js.listenerGetCached(js_this) orelse return; const globalObject = this.globalThis; - var filename: JSC.JSValue = .undefined; + var filename: JSC.JSValue = .jsUndefined(); if (file_name.len > 0) { if (this.encoding == .buffer) filename = JSC.ArrayBuffer.createBuffer(globalObject, file_name) @@ -556,7 +556,7 @@ pub const FSWatcher = struct { this.persistent = true; this.poll_ref.ref(this.ctx); } - return .undefined; + return .jsUndefined(); } pub fn doUnref(this: *FSWatcher, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -564,7 +564,7 @@ pub const FSWatcher = struct { this.persistent = false; this.poll_ref.unref(this.ctx); } - return .undefined; + return .jsUndefined(); } pub fn hasRef(this: *FSWatcher, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -604,7 +604,7 @@ pub const FSWatcher = struct { if (FSWatcher.js.listenerGetCached(js_this)) |listener| { _ = this.refTask(); log("emit('close')", .{}); - emitJS(listener, this.globalThis, .undefined, .close); + emitJS(listener, this.globalThis, .jsUndefined(), .close); this.unrefTask(); } } @@ -637,7 +637,7 @@ pub const FSWatcher = struct { pub fn doClose(this: *FSWatcher, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { this.close(); - return .undefined; + return .jsUndefined(); } pub fn init(args: Arguments) bun.JSC.Maybe(*FSWatcher) { diff --git a/src/bun.js/node/node_zlib_binding.zig b/src/bun.js/node/node_zlib_binding.zig index 9d9886a99f..9b5f02b76b 100644 --- a/src/bun.js/node/node_zlib_binding.zig +++ b/src/bun.js/node/node_zlib_binding.zig @@ -15,7 +15,7 @@ pub fn crc32(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSE const data: JSC.JSValue = arguments[0]; if (data == .zero) { - return globalThis.throwInvalidArgumentTypeValue("data", "string or an instance of Buffer, TypedArray, or DataView", .undefined); + return globalThis.throwInvalidArgumentTypeValue("data", "string or an instance of Buffer, TypedArray, or DataView", .jsUndefined()); } if (data.isString()) { break :blk data.asString().toSlice(globalThis, bun.default_allocator); @@ -114,7 +114,7 @@ pub fn CompressionStream(comptime T: type) type { this.poll_ref.ref(vm); JSC.WorkPool.schedule(&this.task); - return .undefined; + return .jsUndefined(); } const AsyncJob = struct { @@ -217,7 +217,7 @@ pub fn CompressionStream(comptime T: type) type { } this.deref(); - return .undefined; + return .jsUndefined(); } pub fn reset(this: *T, globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -225,14 +225,14 @@ pub fn CompressionStream(comptime T: type) type { if (err.isError()) { try emitError(this, globalThis, callframe.this(), err); } - return .undefined; + return .jsUndefined(); } pub fn close(this: *T, globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { _ = globalThis; _ = callframe; closeInternal(this); - return .undefined; + return .jsUndefined(); } fn closeInternal(this: *T) void { @@ -253,7 +253,7 @@ pub fn CompressionStream(comptime T: type) type { } pub fn getOnError(_: *T, this_value: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue { - return T.js.errorCallbackGetCached(this_value) orelse .undefined; + return T.js.errorCallbackGetCached(this_value) orelse .jsUndefined(); } /// returns true if no error was detected/emitted @@ -400,7 +400,7 @@ pub const SNativeZlib = struct { this.stream.init(level, windowBits, memLevel, strategy, dictionary); - return .undefined; + return .jsUndefined(); } pub fn params(this: *SNativeZlib, globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -417,7 +417,7 @@ pub const SNativeZlib = struct { if (err.isError()) { try impl.emitError(this, globalThis, callframe.this(), err); } - return .undefined; + return .jsUndefined(); } fn deinit(this: *@This()) void { @@ -804,7 +804,7 @@ pub const SNativeBrotli = struct { _ = globalThis; _ = callframe; // intentionally left empty - return .undefined; + return .jsUndefined(); } fn deinit(this: *@This()) void { diff --git a/src/bun.js/node/path.zig b/src/bun.js/node/path.zig index ce2243e077..aca01dadec 100644 --- a/src/bun.js/node/path.zig +++ b/src/bun.js/node/path.zig @@ -433,7 +433,7 @@ pub inline fn basenameJS_T(comptime T: type, globalObject: *JSC.JSGlobalObject, } pub fn basename(globalObject: *JSC.JSGlobalObject, isWindows: bool, args_ptr: [*]JSC.JSValue, args_len: u16) callconv(JSC.conv) JSC.JSValue { - const suffix_ptr: ?JSC.JSValue = if (args_len > 1 and args_ptr[1] != .undefined) args_ptr[1] else null; + const suffix_ptr: ?JSC.JSValue = if (args_len > 1 and !args_ptr[1].isUndefined()) args_ptr[1] else null; if (suffix_ptr) |_suffix_ptr| { // Supress exeption in zig. It does globalThis.vm().throwError() in JS land. @@ -443,7 +443,7 @@ pub fn basename(globalObject: *JSC.JSGlobalObject, isWindows: bool, args_ptr: [* }; } - const path_ptr = if (args_len > 0) args_ptr[0] else .undefined; + const path_ptr: JSC.JSValue = if (args_len > 0) args_ptr[0] else .jsUndefined(); // Supress exeption in zig. It does globalThis.vm().throwError() in JS land. validateString(globalObject, path_ptr, "path", .{}) catch { return .zero; @@ -634,7 +634,7 @@ pub inline fn dirnameJS_T(comptime T: type, globalObject: *JSC.JSGlobalObject, i } pub fn dirname(globalObject: *JSC.JSGlobalObject, isWindows: bool, args_ptr: [*]JSC.JSValue, args_len: u16) callconv(JSC.conv) JSC.JSValue { - const path_ptr = if (args_len > 0) args_ptr[0] else .undefined; + const path_ptr: JSC.JSValue = if (args_len > 0) args_ptr[0] else .jsUndefined(); // Supress exeption in zig. It does globalThis.vm().throwError() in JS land. validateString(globalObject, path_ptr, "path", .{}) catch { // Returning .zero translates to a nullprt JSC.JSValue. @@ -833,7 +833,7 @@ pub inline fn extnameJS_T(comptime T: type, globalObject: *JSC.JSGlobalObject, i } pub fn extname(globalObject: *JSC.JSGlobalObject, isWindows: bool, args_ptr: [*]JSC.JSValue, args_len: u16) callconv(JSC.conv) JSC.JSValue { - const path_ptr = if (args_len > 0) args_ptr[0] else .undefined; + const path_ptr: JSC.JSValue = if (args_len > 0) args_ptr[0] else .jsUndefined(); // Supress exeption in zig. It does globalThis.vm().throwError() in JS land. validateString(globalObject, path_ptr, "path", .{}) catch { // Returning .zero translates to a nullprt JSC.JSValue. @@ -947,7 +947,7 @@ pub fn formatJS_T(comptime T: type, globalObject: *JSC.JSGlobalObject, allocator } pub fn format(globalObject: *JSC.JSGlobalObject, isWindows: bool, args_ptr: [*]JSC.JSValue, args_len: u16) bun.JSError!JSC.JSValue { - const pathObject_ptr = if (args_len > 0) args_ptr[0] else .undefined; + const pathObject_ptr: JSC.JSValue = if (args_len > 0) args_ptr[0] else .jsUndefined(); // Supress exeption in zig. It does globalThis.vm().throwError() in JS land. validateObject(globalObject, pathObject_ptr, "pathObject", .{}, .{}) catch { // Returning .zero translates to a nullprt JSC.JSValue. @@ -1040,7 +1040,7 @@ pub fn isAbsoluteWindowsZigString(pathZStr: JSC.ZigString) bool { } pub fn isAbsolute(globalObject: *JSC.JSGlobalObject, isWindows: bool, args_ptr: [*]JSC.JSValue, args_len: u16) callconv(JSC.conv) JSC.JSValue { - const path_ptr = if (args_len > 0) args_ptr[0] else .undefined; + const path_ptr: JSC.JSValue = if (args_len > 0) args_ptr[0] else .jsUndefined(); // Supress exeption in zig. It does globalThis.vm().throwError() in JS land. validateString(globalObject, path_ptr, "path", .{}) catch { // Returning .zero translates to a nullprt JSC.JSValue. @@ -1664,7 +1664,7 @@ pub fn normalizeJS_T(comptime T: type, globalObject: *JSC.JSGlobalObject, alloca } pub fn normalize(globalObject: *JSC.JSGlobalObject, isWindows: bool, args_ptr: [*]JSC.JSValue, args_len: u16) callconv(JSC.conv) JSC.JSValue { - const path_ptr = if (args_len > 0) args_ptr[0] else .undefined; + const path_ptr: JSC.JSValue = if (args_len > 0) args_ptr[0] else .jsUndefined(); // Supress exeption in zig. It does globalThis.vm().throwError() in JS land. validateString(globalObject, path_ptr, "path", .{}) catch { // Returning .zero translates to a nullprt JSC.JSValue. @@ -1987,7 +1987,7 @@ pub inline fn parseJS_T(comptime T: type, globalObject: *JSC.JSGlobalObject, isW } pub fn parse(globalObject: *JSC.JSGlobalObject, isWindows: bool, args_ptr: [*]JSC.JSValue, args_len: u16) callconv(JSC.conv) JSC.JSValue { - const path_ptr = if (args_len > 0) args_ptr[0] else .undefined; + const path_ptr: JSC.JSValue = if (args_len > 0) args_ptr[0] else .jsUndefined(); // Supress exeption in zig. It does globalThis.vm().throwError() in JS land. validateString(globalObject, path_ptr, "path", .{}) catch { // Returning .zero translates to a nullprt JSC.JSValue. @@ -2348,13 +2348,13 @@ pub fn relativeJS_T(comptime T: type, globalObject: *JSC.JSGlobalObject, allocat } pub fn relative(globalObject: *JSC.JSGlobalObject, isWindows: bool, args_ptr: [*]JSC.JSValue, args_len: u16) callconv(JSC.conv) JSC.JSValue { - const from_ptr = if (args_len > 0) args_ptr[0] else .undefined; + const from_ptr: JSC.JSValue = if (args_len > 0) args_ptr[0] else .jsUndefined(); // Supress exeption in zig. It does globalThis.vm().throwError() in JS land. validateString(globalObject, from_ptr, "from", .{}) catch { // Returning .zero translates to a nullprt JSC.JSValue. return .zero; }; - const to_ptr = if (args_len > 1) args_ptr[1] else .undefined; + const to_ptr: JSC.JSValue = if (args_len > 1) args_ptr[1] else .jsUndefined(); // Supress exeption in zig. It does globalThis.vm().throwError() in JS land. validateString(globalObject, to_ptr, "to", .{}) catch { return .zero; @@ -2940,7 +2940,7 @@ pub fn toNamespacedPathJS_T(comptime T: type, globalObject: *JSC.JSGlobalObject, } pub fn toNamespacedPath(globalObject: *JSC.JSGlobalObject, isWindows: bool, args_ptr: [*]JSC.JSValue, args_len: u16) callconv(JSC.conv) JSC.JSValue { - if (args_len == 0) return .undefined; + if (args_len == 0) return .jsUndefined(); var path_ptr = args_ptr[0]; // Based on Node v21.6.1 path.win32.toNamespacedPath and path.posix.toNamespacedPath: diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index a085793b45..5de1f07220 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -477,7 +477,7 @@ pub const Encoding = enum(u8) { pub fn jsAssertEncodingValid(global: *JSC.JSGlobalObject, call_frame: *JSC.CallFrame) bun.JSError!JSC.JSValue { const value = call_frame.argument(0); _ = try Encoding.assert(value, global, .utf8); - return .undefined; + return .jsUndefined(); } const PathOrBuffer = union(Tag) { @@ -1174,7 +1174,7 @@ pub const PathOrBlob = union(enum) { } const arg = args.nextEat() orelse { - return ctx.throwInvalidArgumentTypeValue("destination", "path, file descriptor, or Blob", .undefined); + return ctx.throwInvalidArgumentTypeValue("destination", "path, file descriptor, or Blob", .jsUndefined()); }; if (arg.as(Blob)) |blob| { return PathOrBlob{ diff --git a/src/bun.js/node/util/parse_args.zig b/src/bun.js/node/util/parse_args.zig index 3384e12438..f14dab555b 100644 --- a/src/bun.js/node/util/parse_args.zig +++ b/src/bun.js/node/util/parse_args.zig @@ -175,7 +175,7 @@ fn getDefaultArgs(globalThis: *JSGlobalObject) !ArgsSlice { } return .{ - .array = .undefined, + .array = .jsUndefined(), .start = 0, .end = 0, }; @@ -316,7 +316,7 @@ fn parseOptionDefinitions(globalThis: *JSGlobalObject, options_obj: JSValue, opt try validators.validateObject(globalThis, obj, "options.{s}", .{option.long_name}, .{}); // type field is required - const option_type = obj.getOwn(globalThis, "type") orelse JSValue.undefined; + const option_type: JSValue = obj.getOwn(globalThis, "type") orelse .jsUndefined(); option.type = try validators.validateStringEnum(OptionValueType, globalThis, option_type, "options.{s}.type", .{option.long_name}); if (obj.getOwn(globalThis, "short")) |short_option| { @@ -413,7 +413,7 @@ fn tokenizeArgs( const short_option = arg.substringWithLen(1, 2); const option_idx = findOptionByShortName(short_option, options); const option_type: OptionValueType = if (option_idx) |idx| options[idx].type else .boolean; - var value = ValueRef{ .jsvalue = JSValue.undefined }; + var value = ValueRef{ .jsvalue = .jsUndefined() }; var has_inline_value = true; if (option_type == .string and index + 1 < num_args) { // e.g. '-f', "bar" @@ -447,7 +447,7 @@ fn tokenizeArgs( // Boolean option, or last short in group. Well formed. // Immediately process as a lone_short_option (e.g. from input -abc, process -a -b -c) - var value = ValueRef{ .jsvalue = JSValue.undefined }; + var value = ValueRef{ .jsvalue = .jsUndefined() }; var has_inline_value = true; if (option_type == .string and index + 1 < num_args) { // e.g. '-f', "bar" @@ -635,7 +635,7 @@ const ParseArgsState = struct { // value exists only for string options, otherwise the property exists with "undefined" as value var value = token.value.asJSValue(globalThis); obj.put(globalThis, ZigString.static("value"), value); - obj.put(globalThis, ZigString.static("inlineValue"), if (value.isUndefined()) JSValue.undefined else JSValue.jsBoolean(token.inline_value)); + obj.put(globalThis, ZigString.static("inlineValue"), if (value.isUndefined()) .jsUndefined() else JSValue.jsBoolean(token.inline_value)); }, .positional => |token| { obj.put(globalThis, ZigString.static("index"), JSValue.jsNumber(token.index)); @@ -665,7 +665,7 @@ pub fn parseArgs(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSE const config = if (config_value.isUndefined()) null else config_value; // Phase 0.A: Get and validate type of input args - const config_args: JSValue = if (config) |c| c.getOwn(globalThis, "args") orelse .undefined else .undefined; + const config_args: JSValue = if (config) |c| c.getOwn(globalThis, "args") orelse .jsUndefined() else .jsUndefined(); const args: ArgsSlice = if (!config_args.isUndefinedOrNull()) args: { try validators.validateArray(globalThis, config_args, "args", .{}, null); break :args .{ @@ -681,7 +681,7 @@ pub fn parseArgs(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSE var config_allow_positionals: JSValue = if (config) |c| c.getOwn(globalThis, "allowPositionals") orelse JSC.jsBoolean(!config_strict.toBoolean()) else JSC.jsBoolean(!config_strict.toBoolean()); const config_return_tokens: JSValue = (if (config) |c| c.getOwn(globalThis, "tokens") else null) orelse JSValue.jsBoolean(false); const config_allow_negative: JSValue = if (config) |c| c.getOwn(globalThis, "allowNegative") orelse .false else .false; - const config_options: JSValue = if (config) |c| c.getOwn(globalThis, "options") orelse .undefined else .undefined; + const config_options: JSValue = if (config) |c| c.getOwn(globalThis, "options") orelse .jsUndefined() else .jsUndefined(); const strict = try validators.validateBoolean(globalThis, config_strict, "strict", .{}); @@ -714,7 +714,7 @@ pub fn parseArgs(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSE // note that "values" needs to have a null prototype instead of Object, to avoid issues such as "values.toString"` being defined const values = JSValue.createEmptyObjectWithNullPrototype(globalThis); const positionals = try JSC.JSValue.createEmptyArray(globalThis, 0); - const tokens = if (return_tokens) try JSC.JSValue.createEmptyArray(globalThis, 0) else JSValue.undefined; + const tokens: JSValue = if (return_tokens) try JSC.JSValue.createEmptyArray(globalThis, 0) else .jsUndefined(); var state = ParseArgsState{ .globalThis = globalThis, diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index ce8e15d419..65f76eb456 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -438,7 +438,7 @@ pub const Expect = struct { var pass = true; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var msg = _msg.toSlice(default_allocator); defer msg.deinit(); @@ -483,7 +483,7 @@ pub const Expect = struct { var pass = false; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var msg = _msg.toSlice(default_allocator); defer msg.deinit(); @@ -516,7 +516,7 @@ pub const Expect = struct { var pass = right.isSameValue(left, globalThis); if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -608,7 +608,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure if (not) { @@ -686,7 +686,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -781,7 +781,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -1424,7 +1424,7 @@ pub const Expect = struct { if (truthy) pass = true; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -1453,7 +1453,7 @@ pub const Expect = struct { if (value.isUndefined()) pass = true; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -1486,7 +1486,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -1514,7 +1514,7 @@ pub const Expect = struct { const not = this.flags.not; var pass = value.isNull(); if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -1542,7 +1542,7 @@ pub const Expect = struct { const not = this.flags.not; var pass = !value.isUndefined(); if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -1575,7 +1575,7 @@ pub const Expect = struct { if (!truthy) pass = true; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -1612,7 +1612,7 @@ pub const Expect = struct { var pass = try value.jestDeepEquals(expected, globalThis); if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure const diff_formatter = DiffFormatter{ @@ -1651,7 +1651,7 @@ pub const Expect = struct { var pass = try value.jestStrictDeepEquals(expected, globalThis); if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure const diff_formatter = DiffFormatter{ .received = value, .expected = expected, .globalThis = globalThis, .not = not }; @@ -1706,7 +1706,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -1790,7 +1790,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -1847,7 +1847,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -1907,7 +1907,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -1967,7 +1967,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -2027,7 +2027,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -2090,7 +2090,7 @@ pub const Expect = struct { } if (std.math.isPositiveInf(expected) and std.math.isPositiveInf(received)) { - return .undefined; + return .jsUndefined(); } const expected_diff = bun.pow(10, -precision) / 2; @@ -2100,7 +2100,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -2159,7 +2159,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -2217,7 +2217,7 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toThrow", "expected", true); - if (!did_throw) return .undefined; + if (!did_throw) return .jsUndefined(); const result: JSValue = result_.?; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -2226,8 +2226,8 @@ pub const Expect = struct { if (expected_value == .zero or expected_value.isUndefined()) { const signature_no_args = comptime getSignature("toThrow", "", true); if (result.toError()) |err| { - const name = try err.getTruthyComptime(globalThis, "name") orelse JSValue.undefined; - const message = try err.getTruthyComptime(globalThis, "message") orelse JSValue.undefined; + const name: JSValue = try err.getTruthyComptime(globalThis, "name") orelse .jsUndefined(); + const message: JSValue = try err.getTruthyComptime(globalThis, "message") orelse .jsUndefined(); const fmt = signature_no_args ++ "\n\nError name: {any}\nError message: {any}\n"; return globalThis.throwPretty(fmt, .{ name.toFmt(&formatter), @@ -2254,7 +2254,7 @@ pub const Expect = struct { defer expected_slice.deinit(); const received_slice = try received_message.toSliceOrNull(globalThis); defer received_slice.deinit(); - if (!strings.contains(received_slice.slice(), expected_slice.slice())) return .undefined; + if (!strings.contains(received_slice.slice(), expected_slice.slice())) return .jsUndefined(); } return this.throw(globalThis, signature, "\n\nExpected substring: not {any}\nReceived message: {any}\n", .{ @@ -2273,7 +2273,7 @@ pub const Expect = struct { // TODO: REMOVE THIS GETTER! Expose a binding to call .test on the RegExp object directly. if (try expected_value.get(globalThis, "test")) |test_fn| { const matches = test_fn.call(globalThis, expected_value, &.{received_message}) catch |err| globalThis.takeException(err); - if (!matches.toBoolean()) return .undefined; + if (!matches.toBoolean()) return .jsUndefined(); } return this.throw(globalThis, signature, "\n\nExpected pattern: not {any}\nReceived message: {any}\n", .{ @@ -2290,21 +2290,21 @@ pub const Expect = struct { if (globalThis.hasException()) return .zero; // no partial match for this case - if (!expected_message.isSameValue(received_message, globalThis)) return .undefined; + if (!expected_message.isSameValue(received_message, globalThis)) return .jsUndefined(); return this.throw(globalThis, signature, "\n\nExpected message: not {any}\n", .{expected_message.toFmt(&formatter)}); } - if (!result.isInstanceOf(globalThis, expected_value)) return .undefined; + if (!result.isInstanceOf(globalThis, expected_value)) return .jsUndefined(); var expected_class = ZigString.Empty; expected_value.getClassName(globalThis, &expected_class); - const received_message = (try result.fastGet(globalThis, .message)) orelse .undefined; + const received_message: JSValue = (try result.fastGet(globalThis, .message)) orelse .jsUndefined(); return this.throw(globalThis, signature, "\n\nExpected constructor: not {s}\n\nReceived message: {any}\n", .{ expected_class, received_message.toFmt(&formatter) }); } if (did_throw) { - if (expected_value == .zero or expected_value.isUndefined()) return .undefined; + if (expected_value == .zero or expected_value.isUndefined()) return .jsUndefined(); const result: JSValue = if (result_.?.toError()) |r| r @@ -2324,7 +2324,7 @@ pub const Expect = struct { defer expected_slice.deinit(); const received_slice = try received_message.toSlice(globalThis, globalThis.allocator()); defer received_slice.deinit(); - if (strings.contains(received_slice.slice(), expected_slice.slice())) return .undefined; + if (strings.contains(received_slice.slice(), expected_slice.slice())) return .jsUndefined(); } // error: message from received error does not match expected string @@ -2349,7 +2349,7 @@ pub const Expect = struct { // TODO: REMOVE THIS GETTER! Expose a binding to call .test on the RegExp object directly. if (try expected_value.get(globalThis, "test")) |test_fn| { const matches = test_fn.call(globalThis, expected_value, &.{received_message}) catch |err| globalThis.takeException(err); - if (matches.toBoolean()) return .undefined; + if (matches.toBoolean()) return .jsUndefined(); } } @@ -2380,7 +2380,7 @@ pub const Expect = struct { } if (is_equal) { - return .undefined; + return .jsUndefined(); } var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -2397,7 +2397,7 @@ pub const Expect = struct { const signature = comptime getSignature("toThrow", "expected", false); if (_received_message) |received_message| { - if (received_message.isSameValue(expected_message, globalThis)) return .undefined; + if (received_message.isSameValue(expected_message, globalThis)) return .jsUndefined(); } // error: message from received error does not match expected error message. @@ -2415,7 +2415,7 @@ pub const Expect = struct { return this.throw(globalThis, signature, "\n\nExpected message: {any}\nReceived value: {any}\n", .{ expected_fmt, received_fmt }); } - if (result.isInstanceOf(globalThis, expected_value)) return .undefined; + if (result.isInstanceOf(globalThis, expected_value)) return .jsUndefined(); // error: received error not instance of received error constructor var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -2503,7 +2503,7 @@ pub const Expect = struct { const prev_unhandled_pending_rejection_to_capture = vm.unhandled_pending_rejection_to_capture; vm.unhandled_pending_rejection_to_capture = &return_value; vm.onUnhandledRejection = &VirtualMachine.onQuietUnhandledRejectionHandlerCaptureValue; - return_value_from_function = value.call(globalThis, .undefined, &.{}) catch |err| globalThis.takeException(err); + return_value_from_function = value.call(globalThis, .jsUndefined(), &.{}) catch |err| globalThis.takeException(err); vm.unhandled_pending_rejection_to_capture = prev_unhandled_pending_rejection_to_capture; vm.global.handleRejectedPromises(); @@ -2584,10 +2584,10 @@ pub const Expect = struct { var err_value_res = err_value orelse return null; if (err_value_res.isAnyError()) { - const message = try err_value_res.getTruthyComptime(globalThis, "message") orelse JSValue.undefined; + const message: JSValue = try err_value_res.getTruthyComptime(globalThis, "message") orelse .jsUndefined(); err_value_res = message; } else { - err_value_res = JSValue.undefined; + err_value_res = .jsUndefined(); } return err_value_res; } @@ -2787,7 +2787,7 @@ pub const Expect = struct { if (strings.eqlLong(pretty_value.slice(), trim_res.trimmed, true)) { Jest.runner.?.snapshots.passed += 1; - return .undefined; + return .jsUndefined(); } else if (update) { Jest.runner.?.snapshots.passed += 1; needs_write = true; @@ -2850,7 +2850,7 @@ pub const Expect = struct { }); } - return .undefined; + return .jsUndefined(); } pub fn toMatchSnapshot(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { defer this.postMatch(globalThis); @@ -2955,7 +2955,7 @@ pub const Expect = struct { if (existing_value) |saved_value| { if (strings.eqlLong(pretty_value.slice(), saved_value, true)) { Jest.runner.?.snapshots.passed += 1; - return .undefined; + return .jsUndefined(); } Jest.runner.?.snapshots.failed += 1; @@ -2970,7 +2970,7 @@ pub const Expect = struct { return globalThis.throwPretty(fmt, .{diff_format}); } - return .undefined; + return .jsUndefined(); } pub fn toBeEmpty(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3036,7 +3036,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); if (not) { const signature = comptime getSignature("toBeEmpty", "", true); @@ -3089,7 +3089,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = value.isUndefinedOrNull() != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3115,7 +3115,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = value.jsType().isArray() != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3156,7 +3156,7 @@ pub const Expect = struct { var pass = value.jsType().isArray() and @as(i32, @intCast(value.getLength(globalThis))) == size.toInt32(); if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3182,7 +3182,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = value.isBoolean() != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3253,7 +3253,7 @@ pub const Expect = struct { pass = strings.eql(typeof, whatIsTheType); if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3280,7 +3280,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = (value.isBoolean() and value.toBoolean()) != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3306,7 +3306,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = (value.isBoolean() and !value.toBoolean()) != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3332,7 +3332,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = value.isNumber() != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3358,7 +3358,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = value.isAnyInt() != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3416,7 +3416,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3448,7 +3448,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3480,7 +3480,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3533,7 +3533,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3616,7 +3616,7 @@ pub const Expect = struct { } if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -3644,7 +3644,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = value.isSymbol() != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3670,7 +3670,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = value.isCallable() != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3696,7 +3696,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = value.isDate() != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3749,7 +3749,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = value.isString() != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3798,7 +3798,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3879,7 +3879,7 @@ pub const Expect = struct { pass = std.mem.containsAtLeast(u8, expectStringAsStr, countAsNum, subStringAsStr); if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -3945,7 +3945,7 @@ pub const Expect = struct { }; value.ensureStillAlive(); - const result = predicate.call(globalThis, .undefined, &.{value}) catch |e| { + const result = predicate.call(globalThis, .jsUndefined(), &.{value}) catch |e| { const err = globalThis.takeException(e); const fmt = ZigString.init("toSatisfy() predicate threw an exception"); return globalThis.throwValue(globalThis.createAggregateError(&.{err}, &fmt)); @@ -3954,7 +3954,7 @@ pub const Expect = struct { const not = this.flags.not; const pass = (result.isBoolean() and result.toBoolean()) != not; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -4006,7 +4006,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -4060,7 +4060,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); @@ -4106,7 +4106,7 @@ pub const Expect = struct { const not = this.flags.not; var pass = value.isInstanceOf(globalThis, expected_value); if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure const expected_fmt = expected_value.toFmt(&formatter); @@ -4165,7 +4165,7 @@ pub const Expect = struct { }; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure const expected_fmt = expected_value.toFmt(&formatter); @@ -4202,7 +4202,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure if (not) { @@ -4233,7 +4233,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure if (not) { @@ -4272,7 +4272,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure if (not) { @@ -4323,7 +4323,7 @@ pub const Expect = struct { var pass = received_object.jestDeepMatch(property_matchers, globalThis, true); if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure const diff_formatter = DiffFormatter{ @@ -4389,7 +4389,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure if (not) { @@ -4444,7 +4444,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -4508,7 +4508,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); // handle failure var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -4593,7 +4593,7 @@ pub const Expect = struct { const not = this.flags.not; if (not) pass = !pass; - if (pass) return .undefined; + if (pass) return .jsUndefined(); if (!pass and return_status == ReturnStatus.throw) { const signature = comptime getSignature(name, "expected", false); @@ -4707,7 +4707,7 @@ pub const Expect = struct { globalThis.bunVM().autoGarbageCollect(); - return .undefined; + return .jsUndefined(); } const CustomMatcherParamsFormatter = struct { @@ -4823,7 +4823,7 @@ pub const Expect = struct { } message = message_value; } else { - message = JSValue.undefined; + message = .jsUndefined(); } break :valid true; @@ -4868,7 +4868,7 @@ pub const Expect = struct { // retrieve the user-provided matcher function (matcher_fn) const func: JSValue = callFrame.callee(); - var matcher_fn = getCustomMatcherFn(func, globalThis) orelse JSValue.undefined; + var matcher_fn: JSValue = getCustomMatcherFn(func, globalThis) orelse .jsUndefined(); if (!matcher_fn.jsType().isFunction()) { return globalThis.throw("Internal consistency error: failed to retrieve the matcher function for a custom matcher!", .{}); } @@ -4922,7 +4922,7 @@ pub const Expect = struct { is_expecting_assertions = true; - return .undefined; + return .jsUndefined(); } pub fn assertions(globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -4953,7 +4953,7 @@ pub const Expect = struct { is_expecting_assertions_count = true; active_test_expectation_counter.expected = unsigned_expected_assertions; - return .undefined; + return .jsUndefined(); } pub fn notImplementedJSCFn(_: *Expect, globalThis: *JSGlobalObject, _: *CallFrame) bun.JSError!JSValue { @@ -5178,7 +5178,7 @@ pub const ExpectCloseTo = struct { } const number_value = args[0]; - var precision_value = if (args.len > 1) args[1] else JSValue.undefined; + var precision_value: JSValue = if (args.len > 1) args[1] else .jsUndefined(); if (precision_value.isUndefined()) { precision_value = JSValue.jsNumberFromInt32(2); // default value from jest } diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index dfd721f058..e5e16aac96 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -285,7 +285,7 @@ pub const Jest = struct { function.protect(); @field(the_runner.global_callbacks, name).append(bun.default_allocator, function) catch unreachable; - return .undefined; + return .jsUndefined(); } }.appendGlobalFunctionCallback; } @@ -505,7 +505,7 @@ pub const Jest = struct { test_runner.default_timeout_override = timeout_ms; } - return .undefined; + return .jsUndefined(); } comptime { @@ -1083,7 +1083,7 @@ pub const DescribeScope = struct { if (callback == .zero) { this.runTests(globalObject); - return .undefined; + return .jsUndefined(); } { @@ -1096,17 +1096,17 @@ pub const DescribeScope = struct { .fulfilled => {}, else => { _ = globalObject.bunVM().unhandledRejection(globalObject, prom.result(globalObject.vm()), prom.asValue()); - return .undefined; + return .jsUndefined(); }, } } else if (result.toError()) |err| { _ = globalObject.bunVM().uncaughtException(globalObject, err, true); - return .undefined; + return .jsUndefined(); } } this.runTests(globalObject); - return .undefined; + return .jsUndefined(); } pub fn runTests(this: *DescribeScope, globalObject: *JSGlobalObject) void { @@ -1805,7 +1805,7 @@ inline fn createScope( Jest.runner.?.setOnly(); tag_to_use = .only; } else if (is_test and Jest.runner.?.only and parent.tag != .only) { - return .undefined; + return .jsUndefined(); } var is_skip = tag == .skip or @@ -2052,14 +2052,14 @@ fn eachBind(globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSVa const allocator = bun.default_allocator; const each_data = bun.cast(*EachData, data); JSC.host_fn.setFunctionData(callee, null); - const array = each_data.*.strong.get() orelse return .undefined; + const array = each_data.*.strong.get() orelse return .jsUndefined(); defer { each_data.*.strong.deinit(); allocator.destroy(each_data); } if (array.isUndefinedOrNull() or !array.jsType().isArray()) { - return .undefined; + return .jsUndefined(); } var iter = array.arrayIterator(globalThis); @@ -2138,7 +2138,7 @@ fn eachBind(globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSVa allocator.free(formattedLabel); } else if (each_data.is_test) { if (Jest.runner.?.only and tag != .only) { - return .undefined; + return .jsUndefined(); } else { function.protect(); parent.tests.append(allocator, TestScope{ @@ -2168,7 +2168,7 @@ fn eachBind(globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSVa } } - return .undefined; + return .jsUndefined(); } inline fn createEach( @@ -2207,7 +2207,7 @@ fn callJSFunctionForTestRunner(vm: *JSC.VirtualMachine, globalObject: *JSGlobalO defer vm.eventLoop().exit(); globalObject.clearTerminationException(); - return function.call(globalObject, .undefined, args) catch |err| globalObject.takeException(err); + return function.call(globalObject, .jsUndefined(), args) catch |err| globalObject.takeException(err); } const assert = bun.assert; diff --git a/src/bun.js/test/pretty_format.zig b/src/bun.js/test/pretty_format.zig index 68a3c95e97..129fe2e123 100644 --- a/src/bun.js/test/pretty_format.zig +++ b/src/bun.js/test/pretty_format.zig @@ -1420,13 +1420,13 @@ pub const JestPrettyFormat = struct { writer.print("{}", .{str}); }, .Event => { - const event_type_value = brk: { - const value_ = value.get_unsafe(this.globalThis, "type") orelse break :brk JSValue.undefined; + const event_type_value: JSValue = brk: { + const value_: JSValue = value.get_unsafe(this.globalThis, "type") orelse break :brk .jsUndefined(); if (value_.isString()) { break :brk value_; } - break :brk JSValue.undefined; + break :brk .jsUndefined(); }; const event_type = switch (try EventType.map.fromJS(this.globalThis, event_type_value) orelse .unknown) { @@ -1478,7 +1478,7 @@ pub const JestPrettyFormat = struct { comptime Output.prettyFmt("data: ", enable_ansi_colors), .{}, ); - const data = (try value.fastGet(this.globalThis, .data)) orelse JSValue.undefined; + const data: JSValue = (try value.fastGet(this.globalThis, .data)) orelse .jsUndefined(); const tag = Tag.get(data, this.globalThis); if (tag.cell.isStringLike()) { diff --git a/src/bun.js/virtual_machine_exports.zig b/src/bun.js/virtual_machine_exports.zig index cbc651479f..a6e52110d0 100644 --- a/src/bun.js/virtual_machine_exports.zig +++ b/src/bun.js/virtual_machine_exports.zig @@ -91,7 +91,7 @@ pub export fn Bun__reportUnhandledError(globalObject: *JSGlobalObject, value: JS if (!value.isTerminationException(vm.jsc)) { _ = vm.uncaughtException(globalObject, value, false); } - return .undefined; + return .jsUndefined(); } /// This function is called on another thread diff --git a/src/bun.js/webcore/Blob.zig b/src/bun.js/webcore/Blob.zig index bd364b445f..95b0f5fad9 100644 --- a/src/bun.js/webcore/Blob.zig +++ b/src/bun.js/webcore/Blob.zig @@ -2329,7 +2329,7 @@ pub fn onFileStreamResolveRequestStream(globalThis: *JSC.JSGlobalObject, callfra stream.done(globalThis); } this.promise.resolve(globalThis, JSC.JSValue.jsNumber(0)); - return .undefined; + return .jsUndefined(); } pub fn onFileStreamRejectRequestStream(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -2347,7 +2347,7 @@ pub fn onFileStreamRejectRequestStream(globalThis: *JSC.JSGlobalObject, callfram if (strong.get(globalThis)) |stream| { stream.cancel(globalThis); } - return .undefined; + return .jsUndefined(); } comptime { const jsonResolveRequestStream = JSC.toJSHostFn(onFileStreamResolveRequestStream); @@ -2911,7 +2911,7 @@ pub fn getName( _: JSC.JSValue, globalThis: *JSC.JSGlobalObject, ) JSValue { - return if (this.getNameString()) |name| name.toJS(globalThis) else .undefined; + return if (this.getNameString()) |name| name.toJS(globalThis) else .jsUndefined(); } pub fn setName( diff --git a/src/bun.js/webcore/Body.zig b/src/bun.js/webcore/Body.zig index 809d1f17f6..3283602367 100644 --- a/src/bun.js/webcore/Body.zig +++ b/src/bun.js/webcore/Body.zig @@ -175,7 +175,7 @@ pub const PendingValue = struct { break :brk globalThis.readableStreamToFormData(readable.value, switch (form_data.?.encoding) { .Multipart => |multipart| bun.String.init(multipart).toJS(globalThis), - .URLEncoded => .undefined, + .URLEncoded => .jsUndefined(), }); }, else => unreachable, diff --git a/src/bun.js/webcore/Crypto.zig b/src/bun.js/webcore/Crypto.zig index 5ef7edcf5d..bafe2e3290 100644 --- a/src/bun.js/webcore/Crypto.zig +++ b/src/bun.js/webcore/Crypto.zig @@ -114,11 +114,11 @@ comptime { pub fn Bun__randomUUIDv7_(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { const arguments = callframe.argumentsUndef(2).slice(); - var encoding_value: JSC.JSValue = .undefined; + var encoding_value: JSC.JSValue = .jsUndefined(); const encoding: JSC.Node.Encoding = brk: { if (arguments.len > 0) { - if (arguments[0] != .undefined) { + if (!arguments[0].isUndefined()) { if (arguments[0].isString()) { encoding_value = arguments[0]; break :brk try JSC.Node.Encoding.fromJS(encoding_value, globalThis) orelse { @@ -132,14 +132,14 @@ pub fn Bun__randomUUIDv7_(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallF }; const timestamp: u64 = brk: { - const timestamp_value: JSC.JSValue = if (encoding_value != .undefined and arguments.len > 1) + const timestamp_value: JSC.JSValue = if (!encoding_value.isUndefined() and arguments.len > 1) arguments[1] - else if (arguments.len == 1 and encoding_value == .undefined) + else if (arguments.len == 1 and encoding_value.isUndefined()) arguments[0] else - .undefined; + .jsUndefined(); - if (timestamp_value != .undefined) { + if (!timestamp_value.isUndefined()) { if (timestamp_value.isDate()) { const date = timestamp_value.getUnixTimestamp(); break :brk @intFromFloat(@max(0, date)); diff --git a/src/bun.js/webcore/FileReader.zig b/src/bun.js/webcore/FileReader.zig index ac494b6ecd..3e13641f63 100644 --- a/src/bun.js/webcore/FileReader.zig +++ b/src/bun.js/webcore/FileReader.zig @@ -611,7 +611,7 @@ pub fn onReaderDone(this: *FileReader) void { this.eventLoop().js.runCallback( cb, globalThis, - .undefined, + .jsUndefined(), &.{ JSC.ArrayBuffer.fromBytes( buffered.items, diff --git a/src/bun.js/webcore/FileSink.zig b/src/bun.js/webcore/FileSink.zig index 7265290831..1a121eba42 100644 --- a/src/bun.js/webcore/FileSink.zig +++ b/src/bun.js/webcore/FileSink.zig @@ -434,7 +434,7 @@ pub fn flushFromJS(this: *FileSink, globalThis: *JSGlobalObject, wait: bool) JSC } if (this.done) { - return .{ .result = .undefined }; + return .initResult(.jsUndefined()); } const rc = this.writer.flush(); @@ -454,7 +454,7 @@ pub fn flushFromJS(this: *FileSink, globalThis: *JSGlobalObject, wait: bool) JSC } return switch (this.toResult(rc)) { .err => unreachable, - else => |result| .{ .result = result.toJS(globalThis) }, + else => |result| .initResult(result.toJS(globalThis)), }; } diff --git a/src/bun.js/webcore/ObjectURLRegistry.zig b/src/bun.js/webcore/ObjectURLRegistry.zig index 41ff45069d..e9a6268a59 100644 --- a/src/bun.js/webcore/ObjectURLRegistry.zig +++ b/src/bun.js/webcore/ObjectURLRegistry.zig @@ -120,7 +120,7 @@ fn Bun__revokeObjectURL_(globalObject: *JSC.JSGlobalObject, callframe: *JSC.Call } const str = arguments.ptr[0].toBunString(globalObject) catch @panic("unreachable"); if (!str.hasPrefixComptime("blob:")) { - return JSC.JSValue.undefined; + return .jsUndefined(); } const slice = str.toUTF8WithoutRef(bun.default_allocator); @@ -129,10 +129,10 @@ fn Bun__revokeObjectURL_(globalObject: *JSC.JSGlobalObject, callframe: *JSC.Call const sliced = slice.slice(); if (sliced.len < "blob:".len + UUID.stringLength) { - return JSC.JSValue.undefined; + return .jsUndefined(); } ObjectURLRegistry.singleton().revoke(sliced["blob:".len..]); - return JSC.JSValue.undefined; + return .jsUndefined(); } comptime { @@ -146,7 +146,7 @@ fn jsFunctionResolveObjectURL_(globalObject: *JSC.JSGlobalObject, callframe: *JS // Not thrown. // https://github.com/nodejs/node/blob/2eff28fb7a93d3f672f80b582f664a7c701569fb/lib/internal/blob.js#L441 if (arguments.len < 1) { - return JSC.JSValue.undefined; + return .jsUndefined(); } const str = try arguments.ptr[0].toBunString(globalObject); defer str.deref(); @@ -156,7 +156,7 @@ fn jsFunctionResolveObjectURL_(globalObject: *JSC.JSGlobalObject, callframe: *JS } if (!str.hasPrefixComptime("blob:") or str.length() < specifier_len) { - return JSC.JSValue.undefined; + return .jsUndefined(); } const slice = str.toUTF8WithoutRef(bun.default_allocator); @@ -165,7 +165,7 @@ fn jsFunctionResolveObjectURL_(globalObject: *JSC.JSGlobalObject, callframe: *JS const registry = ObjectURLRegistry.singleton(); const blob = registry.resolveAndDupeToJS(sliced["blob:".len..], globalObject); - return blob orelse JSC.JSValue.undefined; + return blob orelse .jsUndefined(); } pub const specifier_len = "blob:".len + UUID.stringLength; diff --git a/src/bun.js/webcore/ReadableStream.zig b/src/bun.js/webcore/ReadableStream.zig index b9f4b0ba79..32a8d3c805 100644 --- a/src/bun.js/webcore/ReadableStream.zig +++ b/src/bun.js/webcore/ReadableStream.zig @@ -570,7 +570,7 @@ pub fn NewSource( bun.assert(flag.isBoolean()); } return switch (this.context.setRawMode(flag == .true)) { - .result => .undefined, + .result => .jsUndefined(), .err => |e| e.toJSC(global), }; } @@ -618,7 +618,7 @@ pub fn NewSource( const view = arguments.ptr[0]; view.ensureStillAlive(); this.this_jsvalue = this_jsvalue; - var buffer = view.asArrayBuffer(globalThis) orelse return .undefined; + var buffer = view.asArrayBuffer(globalThis) orelse return .jsUndefined(); return processResult( this_jsvalue, globalThis, @@ -679,7 +679,7 @@ pub fn NewSource( JSC.markBinding(@src()); this.this_jsvalue = callFrame.this(); this.cancel(); - return .undefined; + return .jsUndefined(); } pub fn setOnCloseFromJS(this: *ReadableStreamSourceType, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) bun.JSError!void { @@ -704,7 +704,7 @@ pub fn NewSource( this.globalThis = globalObject; if (value.isUndefined()) { - js.onDrainCallbackSetCached(this.this_jsvalue, globalObject, .undefined); + js.onDrainCallbackSetCached(this.this_jsvalue, globalObject, .jsUndefined()); return; } @@ -720,7 +720,7 @@ pub fn NewSource( JSC.markBinding(@src()); - return this.close_jsvalue.get() orelse .undefined; + return this.close_jsvalue.get() orelse .jsUndefined(); } pub fn getOnDrainFromJS(this: *ReadableStreamSourceType, globalObject: *JSC.JSGlobalObject) JSC.JSValue { @@ -732,7 +732,7 @@ pub fn NewSource( return val; } - return .undefined; + return .jsUndefined(); } pub fn updateRef(this: *ReadableStreamSourceType, globalObject: *JSGlobalObject, callFrame: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -742,7 +742,7 @@ pub fn NewSource( const ref_or_unref = callFrame.argument(0).toBoolean(); this.setRef(ref_or_unref); - return .undefined; + return .jsUndefined(); } fn onClose(ptr: ?*anyopaque) void { diff --git a/src/bun.js/webcore/Request.zig b/src/bun.js/webcore/Request.zig index 813530fc9b..e7c69edea5 100644 --- a/src/bun.js/webcore/Request.zig +++ b/src/bun.js/webcore/Request.zig @@ -555,10 +555,10 @@ pub fn constructInto(globalThis: *JSC.JSGlobalObject, arguments: []const JSC.JSV if (arguments.len > 1 and arguments[1].isObject()) arguments[1] else if (is_first_argument_a_url) - JSValue.undefined + .jsUndefined() else url_or_object, - if (is_first_argument_a_url) JSValue.undefined else url_or_object, + if (is_first_argument_a_url) .jsUndefined() else url_or_object, }; const values_to_try = values_to_try_[0 .. @as(usize, @intFromBool(!is_first_argument_a_url)) + @as(usize, @intFromBool(arguments.len > 1 and arguments[1].isObject()))]; diff --git a/src/bun.js/webcore/Response.zig b/src/bun.js/webcore/Response.zig index d2da8dae05..ca92028ea1 100644 --- a/src/bun.js/webcore/Response.zig +++ b/src/bun.js/webcore/Response.zig @@ -77,7 +77,7 @@ pub export fn jsFunctionGetCompleteRequestOrResponseBodyValueAsArrayBuffer(globa const arguments = callframe.arguments_old(1); const this_value = arguments.ptr[0]; if (this_value.isEmptyOrUndefinedOrNull()) { - return .undefined; + return .jsUndefined(); } const body: *Body.Value = brk: { @@ -87,15 +87,15 @@ pub export fn jsFunctionGetCompleteRequestOrResponseBodyValueAsArrayBuffer(globa break :brk &request.body.value; } - return .undefined; + return .jsUndefined(); }; // Get the body if it's available synchronously. switch (body.*) { - .Used, .Empty, .Null => return .undefined, + .Used, .Empty, .Null => return .jsUndefined(), .Blob => |*blob| { if (blob.isBunFile()) { - return .undefined; + return .jsUndefined(); } defer body.* = .{ .Used = {} }; return blob.toArrayBuffer(globalObject, .transfer) catch return .zero; @@ -104,7 +104,7 @@ pub export fn jsFunctionGetCompleteRequestOrResponseBodyValueAsArrayBuffer(globa var any_blob = body.useAsAnyBlob(); return any_blob.toArrayBufferTransfer(globalObject) catch return .zero; }, - .Error, .Locked => return .undefined, + .Error, .Locked => return .jsUndefined(), } } diff --git a/src/bun.js/webcore/S3File.zig b/src/bun.js/webcore/S3File.zig index 510da770c0..988734f58c 100644 --- a/src/bun.js/webcore/S3File.zig +++ b/src/bun.js/webcore/S3File.zig @@ -538,14 +538,11 @@ pub fn getBucketName( return bucket; } -pub fn getBucket( - this: *Blob, - globalThis: *JSC.JSGlobalObject, -) callconv(JSC.conv) JSValue { +pub fn getBucket(this: *Blob, globalThis: *JSC.JSGlobalObject) callconv(JSC.conv) JSValue { if (getBucketName(this)) |name| { return bun.String.createUTF8ForJS(globalThis, name); } - return .undefined; + return .jsUndefined(); } pub fn getPresignUrl(this: *Blob, globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { const args = callframe.arguments_old(1); diff --git a/src/bun.js/webcore/Sink.zig b/src/bun.js/webcore/Sink.zig index da816d6a90..3d46767777 100644 --- a/src/bun.js/webcore/Sink.zig +++ b/src/bun.js/webcore/Sink.zig @@ -463,7 +463,7 @@ pub fn JSSink(comptime SinkType: type, comptime abi_name: []const u8) type { pub fn close(globalThis: *JSGlobalObject, sink_ptr: ?*anyopaque) callconv(.C) JSValue { JSC.markBinding(@src()); - const this: *ThisSink = @ptrCast(@alignCast(sink_ptr orelse return .undefined)); + const this: *ThisSink = @ptrCast(@alignCast(sink_ptr orelse return .jsUndefined())); if (comptime @hasDecl(SinkType, "getPendingError")) { if (this.sink.getPendingError()) |err| { diff --git a/src/bun.js/webcore/TextEncoder.zig b/src/bun.js/webcore/TextEncoder.zig index 80b7510ff8..587db73801 100644 --- a/src/bun.js/webcore/TextEncoder.zig +++ b/src/bun.js/webcore/TextEncoder.zig @@ -200,7 +200,7 @@ pub export fn TextEncoder__encodeRopeString( array.ensureStillAlive(); if (encoder.any_non_ascii) { - return .undefined; + return .jsUndefined(); } if (array == .zero) { diff --git a/src/bun.js/webcore/fetch.zig b/src/bun.js/webcore/fetch.zig index 8ed7e72970..d4a6b35115 100644 --- a/src/bun.js/webcore/fetch.zig +++ b/src/bun.js/webcore/fetch.zig @@ -794,7 +794,7 @@ pub const FetchTasklet = struct { const js_hostname = hostname.toJS(globalObject); js_hostname.ensureStillAlive(); js_cert.ensureStillAlive(); - const check_result = check_server_identity.call(globalObject, .undefined, &.{ js_hostname, js_cert }) catch |err| globalObject.takeException(err); + const check_result = check_server_identity.call(globalObject, .jsUndefined(), &.{ js_hostname, js_cert }) catch |err| globalObject.takeException(err); // > Returns object [...] on failure if (check_result.isAnyError()) { @@ -1499,7 +1499,7 @@ pub fn Bun__fetchPreconnect_( } bun.http.AsyncHTTP.preconnect(url, true); - return .undefined; + return .jsUndefined(); } const StringOrURL = struct { diff --git a/src/bun.js/webcore/prompt.zig b/src/bun.js/webcore/prompt.zig index c1f2939b8b..e17eac62be 100644 --- a/src/bun.js/webcore/prompt.zig +++ b/src/bun.js/webcore/prompt.zig @@ -31,14 +31,14 @@ fn alert(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSErr // 5. Show message to the user, treating U+000A LF as a line break. output.writeAll(message.slice()) catch { // 1. If we cannot show simple dialogs for this, then return. - return .undefined; + return .jsUndefined(); }; } } output.writeAll(if (has_message) " [Enter] " else "Alert [Enter] ") catch { // 1. If we cannot show simple dialogs for this, then return. - return .undefined; + return .jsUndefined(); }; // 6. Invoke WebDriver BiDi user prompt opened with this, "alert", and message. @@ -56,7 +56,7 @@ fn alert(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSErr // 8. Invoke WebDriver BiDi user prompt closed with this and true. // * Again, not necessary in a server context. - return .undefined; + return .jsUndefined(); } fn confirm(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index 1923557441..101ab14b21 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -32,7 +32,7 @@ pub const Start = union(Tag) { pub fn toJS(this: Start, globalThis: *JSGlobalObject) JSC.JSValue { switch (this) { .empty, .ready => { - return .undefined; + return .jsUndefined(); }, .chunk_size => |chunk| { return JSC.JSValue.jsNumber(@as(Blob.SizeType, @intCast(chunk))); @@ -47,7 +47,7 @@ pub const Start = union(Tag) { return JSC.ArrayBuffer.create(globalThis, list.slice(), .Uint8Array); }, else => { - return .undefined; + return .jsUndefined(); }, } } diff --git a/src/bun_js.zig b/src/bun_js.zig index aa0a51cd8f..85bd025122 100644 --- a/src/bun_js.zig +++ b/src/bun_js.zig @@ -413,11 +413,11 @@ pub const Run = struct { if (this.ctx.runtime_options.eval.eval_and_print) { const to_print = brk: { - const result = vm.entry_point_result.value.get() orelse .undefined; + const result: JSC.JSValue = vm.entry_point_result.value.get() orelse .jsUndefined(); if (result.asAnyPromise()) |promise| { switch (promise.status(vm.jsc)) { .pending => { - result._then2(vm.global, .undefined, Bun__onResolveEntryPointResult, Bun__onRejectEntryPointResult); + result._then2(vm.global, .jsUndefined(), Bun__onResolveEntryPointResult, Bun__onRejectEntryPointResult); vm.tick(); vm.eventLoop().autoTickActive(); @@ -490,7 +490,7 @@ pub export fn Bun__onResolveEntryPointResult(global: *JSC.JSGlobalObject, callfr const result = arguments[0]; result.print(global, .Log, .Log); Global.exit(global.bunVM().exit_handler.exit_code); - return .undefined; + return .jsUndefined(); } pub export fn Bun__onRejectEntryPointResult(global: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(JSC.conv) noreturn { @@ -498,7 +498,7 @@ pub export fn Bun__onRejectEntryPointResult(global: *JSC.JSGlobalObject, callfra const result = arguments[0]; result.print(global, .Log, .Log); Global.exit(global.bunVM().exit_handler.exit_code); - return .undefined; + return .jsUndefined(); } noinline fn dumpBuildError(vm: *JSC.VirtualMachine) void { diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index 426d482384..f4ec3d51ae 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -939,13 +939,13 @@ pub const upgrade_js_bindings = struct { /// For testing upgrades when the temp directory has an open handle without FILE_SHARE_DELETE. /// Windows only pub fn jsOpenTempDirWithoutSharingDelete(_: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!bun.JSC.JSValue { - if (comptime !Environment.isWindows) return .undefined; + if (comptime !Environment.isWindows) return .jsUndefined(); const w = std.os.windows; var buf: bun.WPathBuffer = undefined; const tmpdir_path = fs.FileSystem.RealFS.getDefaultTempDir(); const path = switch (bun.sys.normalizePathWindows(u8, bun.invalid_fd, tmpdir_path, &buf, .{})) { - .err => return .undefined, + .err => return .jsUndefined(), .result => |norm| norm, }; @@ -989,17 +989,17 @@ pub const upgrade_js_bindings = struct { else => {}, } - return .undefined; + return .jsUndefined(); } pub fn jsCloseTempDirHandle(_: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { - if (comptime !Environment.isWindows) return .undefined; + if (comptime !Environment.isWindows) return .jsUndefined(); if (tempdir_fd) |fd| { fd.close(); } - return .undefined; + return .jsUndefined(); } }; diff --git a/src/crash_handler.zig b/src/crash_handler.zig index 1f35eab0df..e805f6545f 100644 --- a/src/crash_handler.zig +++ b/src/crash_handler.zig @@ -1779,9 +1779,9 @@ pub const js_bindings = struct { } pub fn jsGetMachOImageZeroOffset(_: *bun.JSC.JSGlobalObject, _: *bun.JSC.CallFrame) bun.JSError!JSValue { - if (!bun.Environment.isMac) return .undefined; + if (!bun.Environment.isMac) return .jsUndefined(); - const header = std.c._dyld_get_image_header(0) orelse return .undefined; + const header = std.c._dyld_get_image_header(0) orelse return .jsUndefined(); const base_address = @intFromPtr(header); const vmaddr_slide = std.c._dyld_get_image_vmaddr_slide(0); @@ -1793,7 +1793,7 @@ pub const js_bindings = struct { const ptr: [*]align(1) u64 = @ptrFromInt(0xDEADBEEF); ptr[0] = 0xDEADBEEF; std.mem.doNotOptimizeAway(&ptr); - return .undefined; + return .jsUndefined(); } pub fn jsPanic(_: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { diff --git a/src/css/css_internals.zig b/src/css/css_internals.zig index 86f7c0916a..53b076c09a 100644 --- a/src/css/css_internals.zig +++ b/src/css/css_internals.zig @@ -320,7 +320,7 @@ pub fn attrTest(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun. .initOutsideOfBundler(&import_records), ) catch |e| { bun.handleErrorReturnTrace(e, @errorReturnTrace()); - return .undefined; + return .jsUndefined(); }; return bun.String.fromBytes(result.code).toJS(globalThis); diff --git a/src/css/values/color_js.zig b/src/css/values/color_js.zig index 1d7c7f3d7d..4ac9e2c647 100644 --- a/src/css/values/color_js.zig +++ b/src/css/values/color_js.zig @@ -55,7 +55,7 @@ const OutputColorFormat = enum { }; fn colorIntFromJS(globalThis: *JSC.JSGlobalObject, input: JSC.JSValue, comptime property: []const u8) bun.JSError!i32 { - if (input == .zero or input == .undefined or !input.isNumber()) { + if (input == .zero or input.isUndefined() or !input.isNumber()) { return globalThis.throwInvalidArgumentType("color", property, "integer"); } diff --git a/src/deps/c_ares.zig b/src/deps/c_ares.zig index babce5612f..8265028723 100644 --- a/src/deps/c_ares.zig +++ b/src/deps/c_ares.zig @@ -332,7 +332,7 @@ pub const hostent_with_ttls = struct { bun.dns.addressToJS(&std.net.Address.initIp4(addr[0..4].*, 0), globalThis)) catch return globalThis.throwOutOfMemoryValue(); const ttl: ?c_int = if (count < this.ttls.len) this.ttls[count] else null; - const resultObject = JSC.JSValue.createObject2(globalThis, &addressKey, &ttlKey, addrString, if (ttl) |val| JSC.jsNumber(val) else .undefined); + const resultObject = JSC.JSValue.createObject2(globalThis, &addressKey, &ttlKey, addrString, if (ttl) |val| JSC.jsNumber(val) else .jsUndefined()); array.putIndex(globalThis, count, resultObject); } @@ -439,7 +439,7 @@ pub const struct_nameinfo = extern struct { const node_slice = this.node[0..node_len]; array.putIndex(globalThis, 0, JSC.ZigString.fromUTF8(node_slice).toJS(globalThis)); } else { - array.putIndex(globalThis, 0, .undefined); + array.putIndex(globalThis, 0, .jsUndefined()); } if (this.service != null) { @@ -447,7 +447,7 @@ pub const struct_nameinfo = extern struct { const service_slice = this.service[0..service_len]; array.putIndex(globalThis, 1, JSC.ZigString.fromUTF8(service_slice).toJS(globalThis)); } else { - array.putIndex(globalThis, 1, .undefined); + array.putIndex(globalThis, 1, .jsUndefined()); } return array; @@ -2021,9 +2021,9 @@ pub fn Bun__canonicalizeIP_(globalThis: *JSC.JSGlobalObject, callframe: *JSC.Cal const addr_slice = addr.toSlice(bun.default_allocator); const addr_str = addr_slice.slice(); if (addr_str.len >= INET6_ADDRSTRLEN) { - return .undefined; + return .jsUndefined(); } - for (addr_str) |char| if (char == '/') return .undefined; // CIDR not allowed + for (addr_str) |char| if (char == '/') return .jsUndefined(); // CIDR not allowed var ip_std_text: [INET6_ADDRSTRLEN + 1]u8 = undefined; // we need a null terminated string as input @@ -2036,12 +2036,12 @@ pub fn Bun__canonicalizeIP_(globalThis: *JSC.JSGlobalObject, callframe: *JSC.Cal if (ares_inet_pton(af, &ip_addr, &ip_std_text) != 1) { af = AF.INET6; if (ares_inet_pton(af, &ip_addr, &ip_std_text) != 1) { - return .undefined; + return .jsUndefined(); } } // ip_addr will contain the null-terminated string of the cannonicalized IP if (ares_inet_ntop(af, &ip_std_text, &ip_addr, @sizeOf(@TypeOf(ip_addr))) == null) { - return .undefined; + return .jsUndefined(); } // use the null-terminated size to return the string const size = bun.len(bun.cast([*:0]u8, &ip_addr)); diff --git a/src/deps/uws/Response.zig b/src/deps/uws/Response.zig index b679395faa..f6d7744696 100644 --- a/src/deps/uws/Response.zig +++ b/src/deps/uws/Response.zig @@ -249,7 +249,7 @@ pub fn NewResponse(ssl_flag: i32) type { pub fn corked( res: *Response, comptime handler: anytype, - args_tuple: anytype, + args_tuple: std.meta.ArgsTuple(@TypeOf(handler)), ) void { const Wrapper = struct { const handler_fn = handler; @@ -548,7 +548,7 @@ pub const AnyResponse = union(enum) { } } - pub fn corked(this: AnyResponse, comptime handler: anytype, args_tuple: anytype) void { + pub fn corked(this: AnyResponse, comptime handler: anytype, args_tuple: std.meta.ArgsTuple(@TypeOf(handler))) void { switch (this) { inline else => |resp| resp.corked(handler, args_tuple), } @@ -680,6 +680,7 @@ const c = struct { pub extern fn uws_res_cork(i32, res: *c.uws_res, ctx: *anyopaque, corker: *const (fn (?*anyopaque) callconv(.C) void)) void; }; +const std = @import("std"); const bun = @import("bun"); const uws = bun.uws; const Socket = uws.Socket; diff --git a/src/ini.zig b/src/ini.zig index 06b7bdfb6e..b72d81b497 100644 --- a/src/ini.zig +++ b/src/ini.zig @@ -539,7 +539,7 @@ pub const IniTestingAPIs = struct { while (try object_iter.next()) |key| { const keyslice = try key.toOwnedSlice(allocator); var value = object_iter.value; - if (value == .undefined) continue; + if (value.isUndefined()) continue; const value_str = try value.getZigString(globalThis); const slice = try value_str.toOwnedSlice(allocator); diff --git a/src/install/dependency.zig b/src/install/dependency.zig index 03c7939366..da371b5723 100644 --- a/src/install/dependency.zig +++ b/src/install/dependency.zig @@ -783,10 +783,10 @@ pub const Version = struct { pub fn inferFromJS(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { const arguments = callframe.arguments_old(1).slice(); if (arguments.len == 0 or !arguments[0].isString()) { - return .undefined; + return .jsUndefined(); } - const tag = try Tag.fromJS(globalObject, arguments[0]) orelse return .undefined; + const tag = try Tag.fromJS(globalObject, arguments[0]) orelse return .jsUndefined(); var str = bun.String.init(@tagName(tag)); return str.transferToJS(globalObject); } @@ -1284,19 +1284,19 @@ pub fn fromJS(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JS var stack = std.heap.stackFallback(1024, arena.allocator()); const allocator = stack.get(); - const alias_value = if (arguments.len > 0) arguments[0] else .undefined; + const alias_value: JSC.JSValue = if (arguments.len > 0) arguments[0] else .jsUndefined(); if (!alias_value.isString()) { - return .undefined; + return .jsUndefined(); } const alias_slice = try alias_value.toSlice(globalThis, allocator); defer alias_slice.deinit(); if (alias_slice.len == 0) { - return .undefined; + return .jsUndefined(); } - const name_value = if (arguments.len > 1) arguments[1] else .undefined; + const name_value: JSC.JSValue = if (arguments.len > 1) arguments[1] else .jsUndefined(); const name_slice = try name_value.toSlice(globalThis, allocator); defer name_slice.deinit(); @@ -1320,7 +1320,7 @@ pub fn fromJS(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JS return globalThis.throwValue(try log.toJS(globalThis, bun.default_allocator, "Failed to parse dependency")); } - return .undefined; + return .jsUndefined(); }; if (log.msgs.items.len > 0) { diff --git a/src/install/install.zig b/src/install/install.zig index db5740645a..7febf9b40b 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -8267,11 +8267,11 @@ pub const PackageManager = struct { } if (globalThis.hasException()) return .zero; } else { - return .undefined; + return .jsUndefined(); } if (all_positionals.items.len == 0) { - return .undefined; + return .jsUndefined(); } var array = Array{}; @@ -8279,7 +8279,7 @@ pub const PackageManager = struct { const update_requests = parseWithError(allocator, null, &log, all_positionals.items, &array, .add, false) catch { return globalThis.throwValue(try log.toJS(globalThis, bun.default_allocator, "Failed to parse dependencies")); }; - if (update_requests.len == 0) return .undefined; + if (update_requests.len == 0) return .jsUndefined(); if (log.msgs.items.len > 0) { return globalThis.throwValue(try log.toJS(globalThis, bun.default_allocator, "Failed to parse dependencies")); diff --git a/src/js_ast.zig b/src/js_ast.zig index 79af1fe750..42b4f9b1b4 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -6342,7 +6342,7 @@ pub const Expr = struct { .e_object => |e| e.toJS(allocator, globalObject), .e_string => |e| e.toJS(allocator, globalObject), .e_null => JSC.JSValue.null, - .e_undefined => JSC.JSValue.undefined, + .e_undefined => .jsUndefined(), .e_boolean => |boolean| if (boolean.value) JSC.JSValue.true else diff --git a/src/logger.zig b/src/logger.zig index 09802a763b..dfd532afb9 100644 --- a/src/logger.zig +++ b/src/logger.zig @@ -697,7 +697,7 @@ pub const Log = struct { }); pub fn fromJS(globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) JSError!?Level { - if (value == .zero or value == .undefined) { + if (value == .zero or value.isUndefined()) { return null; } @@ -748,7 +748,7 @@ pub const Log = struct { const count = @as(u16, @intCast(@min(msgs.len, errors_stack.len))); switch (count) { - 0 => return .undefined, + 0 => return .jsUndefined(), 1 => { const msg = msgs[0]; return switch (msg.metadata) { diff --git a/src/napi/napi.zig b/src/napi/napi.zig index 2fdfe7b16f..98c3d92e7f 100644 --- a/src/napi/napi.zig +++ b/src/napi/napi.zig @@ -674,7 +674,7 @@ pub export fn napi_make_callback(env_: napi_env, _: *anyopaque, recv_: napi_valu if (recv != .zero) recv else - .undefined, + .jsUndefined(), if (arg_count > 0 and args != null) @as([*]const JSC.JSValue, @ptrCast(args.?))[0..arg_count] else @@ -1616,16 +1616,16 @@ pub const ThreadSafeFunction = struct { switch (this.callback) { .js => |strong| { - const js = strong.get() orelse .undefined; + const js: JSValue = strong.get() orelse .jsUndefined(); if (js.isEmptyOrUndefinedOrNull()) { return; } - _ = js.call(globalObject, .undefined, &.{}) catch |err| + _ = js.call(globalObject, .jsUndefined(), &.{}) catch |err| globalObject.reportActiveExceptionAsUnhandled(err); }, .c => |cb| { - const js = cb.js.get() orelse .undefined; + const js: JSValue = cb.js.get() orelse .jsUndefined(); const handle_scope = NapiHandleScope.open(env, false); defer if (handle_scope) |scope| scope.close(env); diff --git a/src/patch.zig b/src/patch.zig index 7087d354ad..48aba3295c 100644 --- a/src/patch.zig +++ b/src/patch.zig @@ -1168,11 +1168,11 @@ pub const TestingAPIs = struct { const patchfile_js = arguments.nextEat() orelse { globalThis.throw("apply: expected at least 1 argument, got 0", .{}) catch {}; - return .{ .err = .undefined }; + return .initErr(.jsUndefined()); }; const dir_fd = if (arguments.nextEat()) |dir_js| brk: { - var bunstr = dir_js.toBunString(globalThis) catch return .initErr(.undefined); + var bunstr = dir_js.toBunString(globalThis) catch return .initErr(.jsUndefined()); defer bunstr.deref(); const path = bunstr.toOwnedSliceZ(bun.default_allocator) catch unreachable; defer bun.default_allocator.free(path); @@ -1180,13 +1180,13 @@ pub const TestingAPIs = struct { break :brk switch (bun.sys.open(path, bun.O.DIRECTORY | bun.O.RDONLY, 0)) { .err => |e| { globalThis.throwValue(e.withPath(path).toJSC(globalThis)) catch {}; - return .{ .err = .undefined }; + return .initErr(.jsUndefined()); }, .result => |fd| fd, }; } else bun.FileDescriptor.cwd(); - const patchfile_bunstr = patchfile_js.toBunString(globalThis) catch return .initErr(.undefined); + const patchfile_bunstr = patchfile_js.toBunString(globalThis) catch return .initErr(.jsUndefined()); defer patchfile_bunstr.deref(); const patchfile_src = patchfile_bunstr.toUTF8(bun.default_allocator); @@ -1198,7 +1198,7 @@ pub const TestingAPIs = struct { patchfile_src.deinit(); globalThis.throwError(e, "failed to parse patchfile") catch {}; - return .{ .err = .undefined }; + return .initErr(.jsUndefined()); }; return .{ diff --git a/src/s3/client.zig b/src/s3/client.zig index 371489af2e..32689279c7 100644 --- a/src/s3/client.zig +++ b/src/s3/client.zig @@ -376,7 +376,7 @@ pub fn onUploadStreamResolveRequestStream(globalThis: *JSC.JSGlobalObject, callf this.readable_stream_ref.deinit(); this.task.continueStream(); - return .undefined; + return .jsUndefined(); } pub fn onUploadStreamRejectRequestStream(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -403,7 +403,7 @@ pub fn onUploadStreamRejectRequestStream(globalThis: *JSC.JSGlobalObject, callfr } this.task.continueStream(); - return .undefined; + return .jsUndefined(); } comptime { const jsonResolveRequestStream = JSC.toJSHostFn(onUploadStreamResolveRequestStream); diff --git a/src/shell/ParsedShellScript.zig b/src/shell/ParsedShellScript.zig index b0f8f2a75c..e9c4a04790 100644 --- a/src/shell/ParsedShellScript.zig +++ b/src/shell/ParsedShellScript.zig @@ -54,12 +54,12 @@ pub fn setCwd(this: *ParsedShellScript, globalThis: *JSGlobalObject, callframe: }; const str = try bun.String.fromJS(str_js, globalThis); this.cwd = str; - return .undefined; + return .jsUndefined(); } pub fn setQuiet(this: *ParsedShellScript, _: *JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { this.quiet = true; - return .undefined; + return .jsUndefined(); } pub fn setEnv(this: *ParsedShellScript, globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -82,7 +82,7 @@ pub fn setEnv(this: *ParsedShellScript, globalThis: *JSGlobalObject, callframe: while (try object_iter.next()) |key| { const keyslice = key.toOwnedSlice(bun.default_allocator) catch bun.outOfMemory(); var value = object_iter.value; - if (value == .undefined) continue; + if (value.isUndefined()) continue; const value_str = try value.getZigString(globalThis); const slice = value_str.toOwnedSlice(bun.default_allocator) catch bun.outOfMemory(); @@ -97,7 +97,7 @@ pub fn setEnv(this: *ParsedShellScript, globalThis: *JSGlobalObject, callframe: previous.deinit(); } this.export_env = env; - return .undefined; + return .jsUndefined(); } pub fn createParsedShellScript(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index ed91a760a9..b4ebb4f0e5 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -1137,7 +1137,7 @@ pub const Interpreter = struct { root.start(); if (globalThis.hasException()) return error.JSError; - return .undefined; + return .jsUndefined(); } fn ioToJSValue(globalThis: *JSGlobalObject, buf: *bun.ByteList) JSValue { @@ -1185,13 +1185,13 @@ pub const Interpreter = struct { const loop = this.event_loop.js; this.keep_alive.disable(); loop.enter(); - _ = resolve.call(globalThis, .undefined, &.{ + _ = resolve.call(globalThis, .jsUndefined(), &.{ JSValue.jsNumberFromU16(exit_code), this.getBufferedStdout(globalThis), this.getBufferedStderr(globalThis), }) catch |err| globalThis.reportActiveExceptionAsUnhandled(err); - JSC.Codegen.JSShellInterpreter.resolveSetCached(this_jsvalue, globalThis, .undefined); - JSC.Codegen.JSShellInterpreter.rejectSetCached(this_jsvalue, globalThis, .undefined); + JSC.Codegen.JSShellInterpreter.resolveSetCached(this_jsvalue, globalThis, .jsUndefined()); + JSC.Codegen.JSShellInterpreter.rejectSetCached(this_jsvalue, globalThis, .jsUndefined()); loop.exit(); } } @@ -1220,8 +1220,8 @@ pub const Interpreter = struct { this.getBufferedStdout(globalThis), this.getBufferedStderr(globalThis), }) catch |err| globalThis.reportActiveExceptionAsUnhandled(err); - JSC.Codegen.JSShellInterpreter.resolveSetCached(this_jsvalue, globalThis, .undefined); - JSC.Codegen.JSShellInterpreter.rejectSetCached(this_jsvalue, globalThis, .undefined); + JSC.Codegen.JSShellInterpreter.resolveSetCached(this_jsvalue, globalThis, .jsUndefined()); + JSC.Codegen.JSShellInterpreter.rejectSetCached(this_jsvalue, globalThis, .jsUndefined()); loop.exit(); } @@ -1269,7 +1269,7 @@ pub const Interpreter = struct { pub fn setQuiet(this: *ThisInterpreter, _: *JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { log("Interpreter(0x{x}) setQuiet()", .{@intFromPtr(this)}); this.flags.quiet = true; - return .undefined; + return .jsUndefined(); } pub fn setCwd(this: *ThisInterpreter, globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -1284,7 +1284,7 @@ pub const Interpreter = struct { }, .result => {}, } - return .undefined; + return .jsUndefined(); } pub fn setEnv(this: *ThisInterpreter, globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { @@ -1308,7 +1308,7 @@ pub const Interpreter = struct { while (object_iter.next()) |key| { const keyslice = key.toOwnedSlice(bun.default_allocator) catch bun.outOfMemory(); var value = object_iter.value; - if (value == .undefined) continue; + if (value.isUndefined()) continue; const value_str = value.getZigString(globalThis); const slice = value_str.toOwnedSlice(bun.default_allocator) catch bun.outOfMemory(); @@ -1320,7 +1320,7 @@ pub const Interpreter = struct { this.root_shell.export_env.insert(keyref, valueref); } - return .undefined; + return .jsUndefined(); } pub fn isRunning( diff --git a/src/shell/subproc.zig b/src/shell/subproc.zig index 969e51df8b..dbde2688f8 100644 --- a/src/shell/subproc.zig +++ b/src/shell/subproc.zig @@ -1295,7 +1295,7 @@ pub const PipeReader = struct { return JSC.MarkedArrayBuffer.fromBytes(bytes, bun.default_allocator, .Uint8Array).toNodeBuffer(globalThis); }, else => { - return JSC.JSValue.undefined; + return .jsUndefined(); }, } } diff --git a/src/sql/postgres.zig b/src/sql/postgres.zig index dbbd07a74c..18374c608b 100644 --- a/src/sql/postgres.zig +++ b/src/sql/postgres.zig @@ -245,7 +245,7 @@ pub const PostgresSQLContext = struct { ctx.onQueryResolveFn.set(globalObject, callframe.argument(0)); ctx.onQueryRejectFn.set(globalObject, callframe.argument(1)); - return .undefined; + return .jsUndefined(); } comptime { @@ -541,10 +541,10 @@ pub const PostgresSQLQuery = struct { event_loop.runCallback(function, globalObject, thisValue, &.{ targetValue, - consumePendingValue(thisValue, globalObject) orelse .undefined, + consumePendingValue(thisValue, globalObject) orelse .jsUndefined(), tag.toJSTag(globalObject), tag.toJSNumber(), - if (connection == .zero) .undefined else PostgresSQLConnection.js.queriesGetCached(connection) orelse .undefined, + if (connection == .zero) .jsUndefined() else PostgresSQLConnection.js.queriesGetCached(connection) orelse .jsUndefined(), JSValue.jsBoolean(is_last), }); } @@ -578,10 +578,10 @@ pub const PostgresSQLQuery = struct { return globalThis.throw("values must be an array", .{}); } - const pending_value = args.nextEat() orelse .undefined; - const columns = args.nextEat() orelse .undefined; - const js_bigint = args.nextEat() orelse .false; - const js_simple = args.nextEat() orelse .false; + const pending_value: JSValue = args.nextEat() orelse .jsUndefined(); + const columns: JSValue = args.nextEat() orelse .jsUndefined(); + const js_bigint: JSValue = args.nextEat() orelse .false; + const js_simple: JSValue = args.nextEat() orelse .false; const bigint = js_bigint.isBoolean() and js_bigint.asBoolean(); const simple = js_simple.isBoolean() and js_simple.asBoolean(); @@ -613,7 +613,7 @@ pub const PostgresSQLQuery = struct { js.bindingSetCached(this_value, globalThis, values); js.pendingValueSetCached(this_value, globalThis, pending_value); - if (columns != .undefined) { + if (!columns.isUndefined()) { js.columnsSetCached(this_value, globalThis, columns); } @@ -628,12 +628,12 @@ pub const PostgresSQLQuery = struct { pub fn doDone(this: *@This(), globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { _ = globalObject; this.flags.is_done = true; - return .undefined; + return .jsUndefined(); } pub fn setPendingValue(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { const result = callframe.argument(0); js.pendingValueSetCached(this.thisValue.get(), globalObject, result); - return .undefined; + return .jsUndefined(); } pub fn setMode(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { const js_mode = callframe.argument(0); @@ -645,7 +645,7 @@ pub const PostgresSQLQuery = struct { this.flags.result_mode = std.meta.intToEnum(PostgresSQLQueryResultMode, mode) catch { return globalObject.throwInvalidArgumentTypeValue("mode", "Number", js_mode); }; - return .undefined; + return .jsUndefined(); } pub fn doRun(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { @@ -704,10 +704,10 @@ pub const PostgresSQLQuery = struct { } else { connection.resetConnectionTimeout(); } - return .undefined; + return .jsUndefined(); } - const columns_value = js.columnsGetCached(this_value) orelse .undefined; + const columns_value: JSValue = js.columnsGetCached(this_value) orelse .jsUndefined(); var signature = Signature.generate(globalObject, query_str.slice(), binding_value, columns_value, connection.prepared_statement_id, connection.flags.use_unnamed_prepared_statements) catch |err| { if (!globalObject.hasException()) @@ -821,7 +821,7 @@ pub const PostgresSQLQuery = struct { } else { connection.resetConnectionTimeout(); } - return .undefined; + return .jsUndefined(); } pub fn doCancel(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { @@ -829,7 +829,7 @@ pub const PostgresSQLQuery = struct { _ = globalObject; _ = this; - return .undefined; + return .jsUndefined(); } comptime { @@ -1182,7 +1182,7 @@ pub const PostgresSQLConnection = struct { statements: PreparedStatementsMap, prepared_statement_id: u64 = 0, pending_activity_count: std.atomic.Value(u32) = std.atomic.Value(u32).init(0), - js_value: JSValue = JSValue.undefined, + js_value: JSValue = .jsUndefined(), backend_parameters: bun.StringMap = bun.StringMap.init(bun.default_allocator, true), backend_key_data: protocol.BackendKeyData = .{}, @@ -1410,7 +1410,7 @@ pub const PostgresSQLConnection = struct { return value; } - return .undefined; + return .jsUndefined(); } pub fn setOnConnect(_: *PostgresSQLConnection, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { @@ -1422,7 +1422,7 @@ pub const PostgresSQLConnection = struct { return value; } - return .undefined; + return .jsUndefined(); } pub fn setOnClose(_: *PostgresSQLConnection, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { @@ -1685,7 +1685,7 @@ pub const PostgresSQLConnection = struct { } pub fn onTimeout(this: *PostgresSQLConnection) void { - _ = this; // autofix + _ = this; debug("onTimeout", .{}); } @@ -2046,17 +2046,17 @@ pub const PostgresSQLConnection = struct { pub fn doRef(this: *@This(), _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { this.poll_ref.ref(this.globalObject.bunVM()); this.updateHasPendingActivity(); - return .undefined; + return .jsUndefined(); } pub fn doUnref(this: *@This(), _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { this.poll_ref.unref(this.globalObject.bunVM()); this.updateHasPendingActivity(); - return .undefined; + return .jsUndefined(); } pub fn doFlush(this: *PostgresSQLConnection, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { this.flushData(); - return .undefined; + return .jsUndefined(); } pub fn deref(this: *@This()) void { @@ -2074,7 +2074,7 @@ pub const PostgresSQLConnection = struct { this.disconnect(); this.write_buffer.deinit(bun.default_allocator); - return .undefined; + return .jsUndefined(); } pub fn stopTimers(this: *PostgresSQLConnection) void { @@ -2378,13 +2378,13 @@ pub const PostgresSQLConnection = struct { .DataRow => { const request = this.current() orelse return error.ExpectedRequest; var statement = request.statement orelse return error.ExpectedStatement; - var structure: JSValue = .undefined; + var structure: JSValue = .jsUndefined(); var cached_structure: ?PostgresCachedStructure = null; // explicit use switch without else so if new modes are added, we don't forget to check for duplicate fields switch (request.flags.result_mode) { .objects => { cached_structure = statement.structure(this.js_value, this.globalObject); - structure = cached_structure.?.jsValue() orelse .undefined; + structure = cached_structure.?.jsValue() orelse .jsUndefined(); }, .raw, .values => { // no need to check for duplicate fields or structure @@ -3107,7 +3107,7 @@ const QueryBindingIterator = union(enum) { } const property = JSC.JSObject.getIndex(this.columns, globalObject, @intCast(cell_i)); - if (property == .zero or property == .undefined) { + if (property == .zero or property.isUndefined()) { if (!globalObject.hasException()) return globalObject.throw("Expected a column at index {d} in row {d}", .{ cell_i, row_i }) catch null; this.any_failed = true; @@ -3115,7 +3115,7 @@ const QueryBindingIterator = union(enum) { } const value = this.current_row.getOwnByValue(globalObject, property); - if (value == .zero or value == .undefined) { + if (value == .zero or (value != null and value.?.isUndefined())) { if (!globalObject.hasException()) return globalObject.throw("Expected a value at index {d} in row {d}", .{ cell_i, row_i }) catch null; this.any_failed = true; diff --git a/src/valkey/js_valkey.zig b/src/valkey/js_valkey.zig index 6f0a70e0cf..dd614e8fa5 100644 --- a/src/valkey/js_valkey.zig +++ b/src/valkey/js_valkey.zig @@ -165,7 +165,7 @@ pub const JSValkeyClient = struct { // If already connected, resolve immediately if (this.client.status == .connected) { - return JSC.JSPromise.resolvedPromiseValue(globalObject, js.helloGetCached(this_value) orelse .undefined); + return JSC.JSPromise.resolvedPromiseValue(globalObject, js.helloGetCached(this_value) orelse .jsUndefined()); } if (js.connectionPromiseGetCached(this_value)) |promise| { @@ -219,17 +219,17 @@ pub const JSValkeyClient = struct { pub fn jsDisconnect(this: *JSValkeyClient, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { if (this.client.status == .disconnected) { - return .undefined; + return .jsUndefined(); } this.client.disconnect(); - return .undefined; + return .jsUndefined(); } pub fn getOnConnect(_: *JSValkeyClient, thisValue: JSValue, _: *JSC.JSGlobalObject) JSValue { if (js.onconnectGetCached(thisValue)) |value| { return value; } - return .undefined; + return .jsUndefined(); } pub fn setOnConnect(_: *JSValkeyClient, thisValue: JSValue, globalObject: *JSC.JSGlobalObject, value: JSValue) void { @@ -240,7 +240,7 @@ pub const JSValkeyClient = struct { if (js.oncloseGetCached(thisValue)) |value| { return value; } - return .undefined; + return .jsUndefined(); } pub fn setOnClose(_: *JSValkeyClient, thisValue: JSValue, globalObject: *JSC.JSGlobalObject, value: JSValue) void { @@ -406,7 +406,7 @@ pub const JSValkeyClient = struct { defer event_loop.exit(); if (this.this_value.tryGet()) |this_value| { - const hello_value = value.toJS(globalObject) catch .undefined; + const hello_value: JSValue = value.toJS(globalObject) catch .jsUndefined(); js.helloSetCached(this_value, globalObject, hello_value); // Call onConnect callback if defined by the user if (js.onconnectGetCached(this_value)) |on_connect| { @@ -456,7 +456,7 @@ pub const JSValkeyClient = struct { loop.enter(); defer loop.exit(); - if (this_jsvalue != .undefined) { + if (!this_jsvalue.isUndefined()) { if (js.connectionPromiseGetCached(this_jsvalue)) |promise| { js.connectionPromiseSetCached(this_jsvalue, globalObject, .zero); promise.asPromise().?.reject(globalObject, error_value); diff --git a/src/valkey/js_valkey_functions.zig b/src/valkey/js_valkey_functions.zig index f3687fbac3..4abe8b7b1f 100644 --- a/src/valkey/js_valkey_functions.zig +++ b/src/valkey/js_valkey_functions.zig @@ -838,7 +838,7 @@ const Slice = JSC.ZigString.Slice; const JSArgument = JSC.Node.BlobOrStringOrBuffer; fn fromJS(globalObject: *JSC.JSGlobalObject, value: JSValue) !?JSArgument { - if (value == .undefined or value == .null) { + if (value.isUndefinedOrNull()) { return null; } diff --git a/test/internal/ban-words.test.ts b/test/internal/ban-words.test.ts index d8ba199180..07ba00f66c 100644 --- a/test/internal/ban-words.test.ts +++ b/test/internal/ban-words.test.ts @@ -42,7 +42,7 @@ const words: Record ".stdFile()": { reason: "Prefer bun.sys + bun.FD instead of std.fs.File. Zig hides 'errno' when Bun wants to match libuv", limit: 18 }, ".stdDir()": { reason: "Prefer bun.sys + bun.FD instead of std.fs.File. Zig hides 'errno' when Bun wants to match libuv", limit: 48 }, ".arguments_old(": { reason: "Please migrate to .argumentsAsArray() or another argument API", limit: 284 }, - "// autofix": { reason: "Evaluate if this variable should be deleted entirely or explicitly discarded.", limit: 176 }, + "// autofix": { reason: "Evaluate if this variable should be deleted entirely or explicitly discarded.", limit: 175 }, }; const words_keys = [...Object.keys(words)];