Refactor Zig imports and file structure (part 1) (#21270)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
taylor.fish
2025-07-22 17:51:38 -07:00
committed by GitHub
parent 73d92c7518
commit 07cd45deae
564 changed files with 9917 additions and 9697 deletions

View File

@@ -53,11 +53,11 @@ zig = `
// Generated by: src/codegen/generate-node-errors.ts
const std = @import("std");
const bun = @import("bun");
const JSC = bun.JSC;
const jsc = bun.jsc;
pub fn ErrorBuilder(comptime code: Error, comptime fmt: [:0]const u8, Args: type) type {
return struct {
global: *JSC.JSGlobalObject,
global: *jsc.JSGlobalObject,
args: Args,
// Throw this error as a JS exception
@@ -66,16 +66,16 @@ pub fn ErrorBuilder(comptime code: Error, comptime fmt: [:0]const u8, Args: type
}
/// Turn this into a JSValue
pub inline fn toJS(this: @This()) JSC.JSValue {
pub inline fn toJS(this: @This()) jsc.JSValue {
return code.fmt(this.global, fmt, this.args);
}
/// Turn this into a JSPromise that is already rejected.
pub inline fn reject(this: @This()) JSC.JSValue {
pub inline fn reject(this: @This()) jsc.JSValue {
if (comptime bun.FeatureFlags.breaking_changes_1_3) {
return JSC.JSPromise.rejectedPromise(this.globalThis, code.fmt(this.global, fmt, this.args)).toJS();
return jsc.JSPromise.rejectedPromise(this.globalThis, code.fmt(this.global, fmt, this.args)).toJS();
} else {
return JSC.JSPromise.dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM(this.global, code.fmt(this.global, fmt, this.args));
return jsc.JSPromise.dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM(this.global, code.fmt(this.global, fmt, this.args));
}
}
};
@@ -121,17 +121,17 @@ listHeader += `
zig += `
extern fn Bun__createErrorWithCode(globalThis: *JSC.JSGlobalObject, code: Error, message: *bun.String) JSC.JSValue;
extern fn Bun__createErrorWithCode(globalThis: *jsc.JSGlobalObject, code: Error, message: *bun.String) jsc.JSValue;
/// Creates an Error object with the given error code.
/// If an error is thrown while creating the Error object, returns that error instead.
/// Derefs the message string.
pub fn toJS(this: Error, globalThis: *JSC.JSGlobalObject, message: *bun.String) JSC.JSValue {
pub fn toJS(this: Error, globalThis: *jsc.JSGlobalObject, message: *bun.String) jsc.JSValue {
defer message.deref();
return Bun__createErrorWithCode(globalThis, this, message);
}
pub fn fmt(this: Error, globalThis: *JSC.JSGlobalObject, comptime fmt_str: [:0]const u8, args: anytype) JSC.JSValue {
pub fn fmt(this: Error, globalThis: *jsc.JSGlobalObject, comptime fmt_str: [:0]const u8, args: anytype) jsc.JSValue {
if (comptime std.meta.fieldNames(@TypeOf(args)).len == 0) {
var message = bun.String.static(fmt_str);
return toJS(this, globalThis, &message);
@@ -141,7 +141,7 @@ zig += `
return toJS(this, globalThis, &message);
}
pub fn throw(this: Error, globalThis: *JSC.JSGlobalObject, comptime fmt_str: [:0]const u8, args: anytype) bun.JSError {
pub fn throw(this: Error, globalThis: *jsc.JSGlobalObject, comptime fmt_str: [:0]const u8, args: anytype) bun.JSError {
return globalThis.throwValue(fmt(this, globalThis, fmt_str, args));
}