zig: prefer .jsUndefined() over .undefined for JSValue (#20332)

This commit is contained in:
Meghan Denny
2025-06-12 12:18:46 -08:00
committed by GitHub
parent d6590c4bfa
commit dedd433cbf
84 changed files with 569 additions and 574 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 };
}

View File

@@ -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) {

View File

@@ -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,

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -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:

View File

@@ -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{

View File

@@ -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,