delete usingnamespace in bindings generator (#19020)

This commit is contained in:
chloe caruso
2025-04-15 12:14:47 -07:00
committed by GitHub
parent 903706dccf
commit be77711a4e
58 changed files with 600 additions and 423 deletions

View File

@@ -281,15 +281,19 @@ pub const PostgresSQLQuery = struct {
_padding: u2 = 0,
} = .{},
pub usingnamespace JSC.Codegen.JSPostgresSQLQuery;
pub const js = JSC.Codegen.JSPostgresSQLQuery;
pub const toJS = js.toJS;
pub const fromJS = js.fromJS;
pub const fromJSDirect = js.fromJSDirect;
pub fn getTarget(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, clean_target: bool) JSC.JSValue {
const thisValue = this.thisValue.get();
if (thisValue == .zero) {
return .zero;
}
const target = PostgresSQLQuery.targetGetCached(thisValue) orelse return .zero;
const target = js.targetGetCached(thisValue) orelse return .zero;
if (clean_target) {
PostgresSQLQuery.targetSetCached(thisValue, globalObject, .zero);
js.targetSetCached(thisValue, globalObject, .zero);
}
return target;
}
@@ -500,14 +504,14 @@ pub const PostgresSQLQuery = struct {
}
defer thisValue.ensureStillAlive();
PostgresSQLQuery.bindingSetCached(thisValue, globalObject, .zero);
PostgresSQLQuery.pendingValueSetCached(thisValue, globalObject, .zero);
PostgresSQLQuery.targetSetCached(thisValue, globalObject, .zero);
js.bindingSetCached(thisValue, globalObject, .zero);
js.pendingValueSetCached(thisValue, globalObject, .zero);
js.targetSetCached(thisValue, globalObject, .zero);
}
fn consumePendingValue(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject) ?JSValue {
const pending_value = PostgresSQLQuery.pendingValueGetCached(thisValue) orelse return null;
PostgresSQLQuery.pendingValueSetCached(thisValue, globalObject, .zero);
const pending_value = js.pendingValueGetCached(thisValue) orelse return null;
js.pendingValueSetCached(thisValue, globalObject, .zero);
return pending_value;
}
@@ -540,7 +544,7 @@ pub const PostgresSQLQuery = struct {
consumePendingValue(thisValue, globalObject) orelse .undefined,
tag.toJSTag(globalObject),
tag.toJSNumber(),
if (connection == .zero) .undefined else PostgresSQLConnection.queriesGetCached(connection) orelse .undefined,
if (connection == .zero) .undefined else PostgresSQLConnection.js.queriesGetCached(connection) orelse .undefined,
JSValue.jsBoolean(is_last),
});
}
@@ -607,10 +611,10 @@ pub const PostgresSQLQuery = struct {
},
};
PostgresSQLQuery.bindingSetCached(this_value, globalThis, values);
PostgresSQLQuery.pendingValueSetCached(this_value, globalThis, pending_value);
js.bindingSetCached(this_value, globalThis, values);
js.pendingValueSetCached(this_value, globalThis, pending_value);
if (columns != .undefined) {
PostgresSQLQuery.columnsSetCached(this_value, globalThis, columns);
js.columnsSetCached(this_value, globalThis, columns);
}
return this_value;
@@ -628,7 +632,7 @@ pub const PostgresSQLQuery = struct {
}
pub fn setPendingValue(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue {
const result = callframe.argument(0);
PostgresSQLQuery.pendingValueSetCached(this.thisValue.get(), globalObject, result);
js.pendingValueSetCached(this.thisValue.get(), globalObject, result);
return .undefined;
}
pub fn setMode(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue {
@@ -659,7 +663,7 @@ pub const PostgresSQLQuery = struct {
}
const this_value = callframe.this();
const binding_value = PostgresSQLQuery.bindingGetCached(this_value) orelse .zero;
const binding_value = js.bindingGetCached(this_value) orelse .zero;
var query_str = this.query.toUTF8(bun.default_allocator);
defer query_str.deinit();
var writer = connection.writer();
@@ -694,7 +698,7 @@ pub const PostgresSQLQuery = struct {
this.ref();
this.thisValue.upgrade(globalObject);
PostgresSQLQuery.targetSetCached(this_value, globalObject, query);
js.targetSetCached(this_value, globalObject, query);
if (this.status == .running) {
connection.flushDataAndResetTimeout();
} else {
@@ -703,7 +707,7 @@ pub const PostgresSQLQuery = struct {
return .undefined;
}
const columns_value = PostgresSQLQuery.columnsGetCached(this_value) orelse .undefined;
const columns_value = js.columnsGetCached(this_value) orelse .undefined;
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())
@@ -811,7 +815,7 @@ pub const PostgresSQLQuery = struct {
this.ref();
this.thisValue.upgrade(globalObject);
PostgresSQLQuery.targetSetCached(this_value, globalObject, query);
js.targetSetCached(this_value, globalObject, query);
if (did_write) {
connection.flushDataAndResetTimeout();
} else {
@@ -1357,7 +1361,10 @@ pub const PostgresSQLConnection = struct {
failed,
};
pub usingnamespace JSC.Codegen.JSPostgresSQLConnection;
pub const js = JSC.Codegen.JSPostgresSQLConnection;
pub const toJS = js.toJS;
pub const fromJS = js.fromJS;
pub const fromJSDirect = js.fromJSDirect;
fn getTimeoutInterval(this: *const PostgresSQLConnection) u32 {
return switch (this.status) {
@@ -1388,18 +1395,18 @@ pub const PostgresSQLConnection = struct {
}
pub fn getQueries(_: *PostgresSQLConnection, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject) JSC.JSValue {
if (PostgresSQLConnection.queriesGetCached(thisValue)) |value| {
if (js.queriesGetCached(thisValue)) |value| {
return value;
}
const array = JSC.JSValue.createEmptyArray(globalObject, 0);
PostgresSQLConnection.queriesSetCached(thisValue, globalObject, array);
js.queriesSetCached(thisValue, globalObject, array);
return array;
}
pub fn getOnConnect(_: *PostgresSQLConnection, thisValue: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue {
if (PostgresSQLConnection.onconnectGetCached(thisValue)) |value| {
if (js.onconnectGetCached(thisValue)) |value| {
return value;
}
@@ -1407,12 +1414,12 @@ pub const PostgresSQLConnection = struct {
}
pub fn setOnConnect(_: *PostgresSQLConnection, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) bool {
PostgresSQLConnection.onconnectSetCached(thisValue, globalObject, value);
js.onconnectSetCached(thisValue, globalObject, value);
return true;
}
pub fn getOnClose(_: *PostgresSQLConnection, thisValue: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue {
if (PostgresSQLConnection.oncloseGetCached(thisValue)) |value| {
if (js.oncloseGetCached(thisValue)) |value| {
return value;
}
@@ -1420,7 +1427,7 @@ pub const PostgresSQLConnection = struct {
}
pub fn setOnClose(_: *PostgresSQLConnection, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) bool {
PostgresSQLConnection.oncloseSetCached(thisValue, globalObject, value);
js.oncloseSetCached(thisValue, globalObject, value);
return true;
}
@@ -1937,8 +1944,8 @@ pub const PostgresSQLConnection = struct {
js_value.ensureStillAlive();
ptr.js_value = js_value;
PostgresSQLConnection.onconnectSetCached(js_value, globalObject, on_connect);
PostgresSQLConnection.oncloseSetCached(js_value, globalObject, on_close);
js.onconnectSetCached(js_value, globalObject, on_connect);
js.oncloseSetCached(js_value, globalObject, on_close);
bun.analytics.Features.postgres_connections += 1;
{
@@ -2268,8 +2275,8 @@ pub const PostgresSQLConnection = struct {
.prepared => {
const thisValue = req.thisValue.get();
bun.assert(thisValue != .zero);
const binding_value = PostgresSQLQuery.bindingGetCached(thisValue) orelse .zero;
const columns_value = PostgresSQLQuery.columnsGetCached(thisValue) orelse .zero;
const binding_value = PostgresSQLQuery.js.bindingGetCached(thisValue) orelse .zero;
const columns_value = PostgresSQLQuery.js.columnsGetCached(thisValue) orelse .zero;
req.flags.binary = stmt.fields.len > 0;
PostgresRequest.bindAndExecute(this.globalObject, stmt, binding_value, columns_value, PostgresSQLConnection.Writer, this.writer()) catch |err| {
@@ -2293,7 +2300,7 @@ pub const PostgresSQLConnection = struct {
const thisValue = req.thisValue.get();
bun.assert(thisValue != .zero);
// prepareAndQueryWithSignature will write + bind + execute, it will change to running after binding is complete
const binding_value = PostgresSQLQuery.bindingGetCached(thisValue) orelse .zero;
const binding_value = PostgresSQLQuery.js.bindingGetCached(thisValue) orelse .zero;
PostgresRequest.prepareAndQueryWithSignature(this.globalObject, query_str.slice(), binding_value, PostgresSQLConnection.Writer, this.writer(), &stmt.signature) catch |err| {
stmt.status = .failed;
stmt.error_response = .{ .postgres_error = err };
@@ -2358,7 +2365,7 @@ pub const PostgresSQLConnection = struct {
}
pub fn getQueriesArray(this: *const PostgresSQLConnection) JSValue {
return PostgresSQLConnection.queriesGetCached(this.js_value) orelse .zero;
return js.queriesGetCached(this.js_value) orelse .zero;
}
pub const DataCell = @import("./DataCell.zig").DataCell;
@@ -2372,7 +2379,7 @@ pub const PostgresSQLConnection = struct {
var statement = request.statement orelse return error.ExpectedStatement;
var structure: JSValue = .undefined;
var cached_structure: ?PostgresCachedStructure = null;
// explict use switch without else so if new modes are added, we don't forget to check for duplicate fields
// 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);
@@ -2405,7 +2412,7 @@ pub const PostgresSQLConnection = struct {
cells = try bun.default_allocator.alloc(DataCell, statement.fields.len);
free_cells = true;
}
// make sure all cells are reseted if reader short breaks the fields will just be null with is better than undefined behavior
// make sure all cells are reset if reader short breaks the fields will just be null with is better than undefined behavior
@memset(cells, DataCell{ .tag = .null, .value = .{ .null = 0 } });
putter.list = cells;
@@ -2426,12 +2433,12 @@ pub const PostgresSQLConnection = struct {
}
const thisValue = request.thisValue.get();
bun.assert(thisValue != .zero);
const pending_value = PostgresSQLQuery.pendingValueGetCached(thisValue) orelse .zero;
const pending_value = PostgresSQLQuery.js.pendingValueGetCached(thisValue) orelse .zero;
pending_value.ensureStillAlive();
const result = putter.toJS(this.globalObject, pending_value, structure, statement.fields_flags, request.flags.result_mode, cached_structure);
if (pending_value == .zero) {
PostgresSQLQuery.pendingValueSetCached(thisValue, this.globalObject, result);
PostgresSQLQuery.js.pendingValueSetCached(thisValue, this.globalObject, result);
}
},
.CopyData => {
@@ -2819,18 +2826,18 @@ pub const PostgresSQLConnection = struct {
pub fn consumeOnConnectCallback(this: *const PostgresSQLConnection, globalObject: *JSC.JSGlobalObject) ?JSC.JSValue {
debug("consumeOnConnectCallback", .{});
const on_connect = PostgresSQLConnection.onconnectGetCached(this.js_value) orelse return null;
const on_connect = js.onconnectGetCached(this.js_value) orelse return null;
debug("consumeOnConnectCallback exists", .{});
PostgresSQLConnection.onconnectSetCached(this.js_value, globalObject, .zero);
js.onconnectSetCached(this.js_value, globalObject, .zero);
return on_connect;
}
pub fn consumeOnCloseCallback(this: *const PostgresSQLConnection, globalObject: *JSC.JSGlobalObject) ?JSC.JSValue {
debug("consumeOnCloseCallback", .{});
const on_close = PostgresSQLConnection.oncloseGetCached(this.js_value) orelse return null;
const on_close = js.oncloseGetCached(this.js_value) orelse return null;
debug("consumeOnCloseCallback exists", .{});
PostgresSQLConnection.oncloseSetCached(this.js_value, globalObject, .zero);
js.oncloseSetCached(this.js_value, globalObject, .zero);
return on_close;
}
};
@@ -3262,7 +3269,7 @@ const Signature = struct {
pub fn createBinding(globalObject: *JSC.JSGlobalObject) JSValue {
const binding = JSValue.createEmptyObjectWithNullPrototype(globalObject);
binding.put(globalObject, ZigString.static("PostgresSQLConnection"), PostgresSQLConnection.getConstructor(globalObject));
binding.put(globalObject, ZigString.static("PostgresSQLConnection"), PostgresSQLConnection.js.getConstructor(globalObject));
binding.put(globalObject, ZigString.static("init"), JSC.JSFunction.create(globalObject, "init", PostgresSQLContext.init, 0, .{}));
binding.put(
globalObject,