diff --git a/.cursor/rules/zig-javascriptcore-classes.mdc b/.cursor/rules/zig-javascriptcore-classes.mdc index 4c99f4929a..965932a988 100644 --- a/.cursor/rules/zig-javascriptcore-classes.mdc +++ b/.cursor/rules/zig-javascriptcore-classes.mdc @@ -65,21 +65,27 @@ The Zig files implement the native functionality: ```zig // Example: TextDecoder.zig pub const TextDecoder = struct { + // Expose generated bindings as `js` namespace with trait conversion methods + pub const js = JSC.Codegen.JSTextDecoder; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + // Internal state encoding: []const u8, fatal: bool, ignoreBOM: bool, - - // Use generated bindings - pub usingnamespace JSC.Codegen.JSTextDecoder; - pub usingnamespace bun.New(@This()); - + // Constructor implementation - note use of globalObject pub fn constructor( globalObject: *JSGlobalObject, callFrame: *JSC.CallFrame, ) bun.JSError!*TextDecoder { // Implementation + + return bun.new(TextDecoder, .{ + // Fields + }); } // Prototype methods - note return type includes JSError @@ -101,22 +107,22 @@ pub const TextDecoder = struct { } // Cleanup - note standard pattern of using deinit/deref - pub fn deinit(this: *TextDecoder) void { + fn deinit(this: *TextDecoder) void { // Release any retained resources + // Free the pointer at the end. + bun.destroy(this); } + // Finalize - called by JS garbage collector. This should call deinit, or deref if reference counted. pub fn finalize(this: *TextDecoder) void { this.deinit(); - // Or sometimes this is used to free memory instead - bun.default_allocator.destroy(this); } }; ``` Key components in the Zig file: - The struct containing native state -- `usingnamespace JSC.Codegen.JS` to include generated code -- `usingnamespace bun.New(@This())` for object creation helpers +- `pub const js = JSC.Codegen.JS` to include generated code - Constructor and methods using `bun.JSError!JSValue` return type for proper error handling - Consistent use of `globalObject` parameter name instead of `ctx` - Methods matching the JavaScript interface @@ -395,12 +401,16 @@ To create a new class binding in Bun: 2. **Implement the native functionality** in a `.zig` file: ```zig pub const MyClass = struct { + // Generated bindings + pub const js = JSC.Codegen.JSMyClass; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + // State value: []const u8, - // Generated bindings - pub usingnamespace JSC.Codegen.JSMyClass; - pub usingnamespace bun.New(@This()); + pub const new = bun.TrivialNew(@This()); // Constructor pub fn constructor( @@ -432,7 +442,7 @@ To create a new class binding in Bun: pub fn finalize(this: *MyClass) void { this.deinit(); - bun.default_allocator.destroy(this); + bun.destroy(this); } }; ``` @@ -485,4 +495,4 @@ For each Zig class, the system generates: - **Child Visitor Methods**: `visitChildrenImpl` and `visitAdditionalChildren` - **Heap Analysis**: `analyzeHeap` for debugging memory issues -This architecture makes it possible to implement high-performance native functionality in Zig while exposing a clean, idiomatic JavaScript API to users. \ No newline at end of file +This architecture makes it possible to implement high-performance native functionality in Zig while exposing a clean, idiomatic JavaScript API to users. diff --git a/src/bake/FrameworkRouter.zig b/src/bake/FrameworkRouter.zig index 00ada78cba..93d643c8dd 100644 --- a/src/bake/FrameworkRouter.zig +++ b/src/bake/FrameworkRouter.zig @@ -1080,9 +1080,9 @@ fn scanInner( /// production usage. It uses a slower but easier to use pattern for object /// creation. A production-grade JS api would be able to re-use objects. pub const JSFrameworkRouter = struct { - pub const codegen = JSC.Codegen.JSFrameworkFileSystemRouter; - pub const toJS = codegen.toJS; - pub const fromJS = codegen.fromJS; + pub const js = JSC.Codegen.JSFrameworkFileSystemRouter; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; files: std.ArrayListUnmanaged(bun.String), router: FrameworkRouter, @@ -1097,7 +1097,7 @@ pub const JSFrameworkRouter = struct { pub fn getBindings(global: *JSC.JSGlobalObject) JSC.JSValue { return JSC.JSObject.create(.{ .parseRoutePattern = global.createHostFunction("parseRoutePattern", parseRoutePattern, 1), - .FrameworkRouter = codegen.getConstructor(global), + .FrameworkRouter = js.getConstructor(global), }, global).toJS(); } diff --git a/src/bun.js/BuildMessage.zig b/src/bun.js/BuildMessage.zig index 64d21b80ca..98a35a9015 100644 --- a/src/bun.js/BuildMessage.zig +++ b/src/bun.js/BuildMessage.zig @@ -12,13 +12,16 @@ const ZigString = JSC.ZigString; const JSValue = JSC.JSValue; pub const BuildMessage = struct { + pub const js = JSC.Codegen.JSBuildMessage; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + msg: logger.Msg, // resolve_result: Resolver.Result, allocator: std.mem.Allocator, logged: bool = false, - pub usingnamespace JSC.Codegen.JSBuildMessage; - pub fn constructor(globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!*BuildMessage { return globalThis.throw("BuildMessage is not constructable", .{}); } diff --git a/src/bun.js/ResolveMessage.zig b/src/bun.js/ResolveMessage.zig index bcbb5c70a9..712a0f03d2 100644 --- a/src/bun.js/ResolveMessage.zig +++ b/src/bun.js/ResolveMessage.zig @@ -11,13 +11,16 @@ const default_allocator = bun.default_allocator; const ZigString = JSC.ZigString; pub const ResolveMessage = struct { + pub const js = JSC.Codegen.JSResolveMessage; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + msg: logger.Msg, allocator: std.mem.Allocator, referrer: ?Fs.Path = null, logged: bool = false, - pub usingnamespace JSC.Codegen.JSResolveMessage; - pub fn constructor(globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!*ResolveMessage { return globalThis.throw("ResolveMessage is not constructable", .{}); } diff --git a/src/bun.js/api/BunObject.zig b/src/bun.js/api/BunObject.zig index 88776ac62f..0f5889b5b7 100644 --- a/src/bun.js/api/BunObject.zig +++ b/src/bun.js/api/BunObject.zig @@ -625,7 +625,7 @@ pub fn getArgv(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { const Editor = @import("../../open.zig").Editor; -pub fn openInEditor(globalThis: js.JSContextRef, callframe: *JSC.CallFrame) bun.JSError!JSValue { +pub fn openInEditor(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue { var edit = &VirtualMachine.get().rareData().editor_context; const args = callframe.arguments_old(4); var arguments = JSC.Node.ArgumentsSlice.init(globalThis.bunVM(), args.slice()); @@ -818,7 +818,7 @@ fn doResolve(globalThis: *JSC.JSGlobalObject, arguments: []const JSValue) bun.JS ); } -fn doResolveWithArgs(ctx: js.JSContextRef, specifier: bun.String, from: bun.String, is_esm: bool, comptime is_file_path: bool, is_user_require_resolve: bool) bun.JSError!JSC.JSValue { +fn doResolveWithArgs(ctx: *JSC.JSGlobalObject, specifier: bun.String, from: bun.String, is_esm: bool, comptime is_file_path: bool, is_user_require_resolve: bool) bun.JSError!JSC.JSValue { var errorable: ErrorableString = undefined; var query_string = ZigString.Empty; @@ -1242,11 +1242,11 @@ pub fn mmapFile(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun. } pub fn getTranspilerConstructor(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { - return JSC.API.JSTranspiler.getConstructor(globalThis); + return JSC.API.JSTranspiler.js.getConstructor(globalThis); } pub fn getFileSystemRouter(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { - return JSC.API.FileSystemRouter.getConstructor(globalThis); + return JSC.API.FileSystemRouter.js.getConstructor(globalThis); } pub fn getHashObject(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { @@ -1258,10 +1258,10 @@ pub fn getTOMLObject(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSVa } pub fn getGlobConstructor(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { - return JSC.API.Glob.getConstructor(globalThis); + return JSC.API.Glob.js.getConstructor(globalThis); } pub fn getS3ClientConstructor(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { - return JSC.WebCore.S3Client.getConstructor(globalThis); + return JSC.WebCore.S3Client.js.getConstructor(globalThis); } pub fn getS3DefaultClient(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { @@ -1281,7 +1281,7 @@ pub fn getValkeyDefaultClient(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) } pub fn getValkeyClientConstructor(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { - return JSC.API.Valkey.getConstructor(globalThis); + return JSC.API.Valkey.js.getConstructor(globalThis); } pub fn getEmbeddedFiles(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue { @@ -1793,7 +1793,6 @@ const Request = WebCore.Request; const Response = WebCore.Response; const Headers = WebCore.Headers; const Fetch = WebCore.Fetch; -const js = bun.JSC.C; const JSC = bun.JSC; const JSError = @import("../base.zig").JSError; @@ -1802,7 +1801,6 @@ const getAllocator = @import("../base.zig").getAllocator; const JSValue = bun.JSC.JSValue; const JSGlobalObject = bun.JSC.JSGlobalObject; -const ExceptionValueRef = bun.JSC.ExceptionValueRef; const JSPrivateDataPtr = bun.JSC.JSPrivateDataPtr; const ConsoleObject = bun.JSC.ConsoleObject; const Node = bun.JSC.Node; diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig index f06803a94b..65922a5b42 100644 --- a/src/bun.js/api/JSBundler.zig +++ b/src/bun.js/api/JSBundler.zig @@ -5,7 +5,6 @@ const CombinedScanner = @import("../../url.zig").CombinedScanner; const bun = @import("root").bun; const string = bun.string; const JSC = bun.JSC; -const js = JSC.C; const WebCore = @import("../webcore/response.zig"); const Transpiler = bun.transpiler; const options = @import("../../options.zig"); @@ -1090,7 +1089,10 @@ pub const JSBundler = struct { const Blob = JSC.WebCore.Blob; pub const BuildArtifact = struct { - pub usingnamespace JSC.Codegen.JSBuildArtifact; + pub const js = JSC.Codegen.JSBuildArtifact; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; blob: JSC.WebCore.Blob, loader: options.Loader = .file, diff --git a/src/bun.js/api/JSTranspiler.zig b/src/bun.js/api/JSTranspiler.zig index 673b76d7d7..c965f980ff 100644 --- a/src/bun.js/api/JSTranspiler.zig +++ b/src/bun.js/api/JSTranspiler.zig @@ -5,7 +5,6 @@ const CombinedScanner = @import("../../url.zig").CombinedScanner; const bun = @import("root").bun; const string = bun.string; const JSC = bun.JSC; -const js = JSC.C; const WebCore = @import("../webcore/response.zig"); const Transpiler = bun.transpiler; const options = @import("../../options.zig"); @@ -40,7 +39,10 @@ const JSLexer = bun.js_lexer; const Expr = JSAst.Expr; const JSTranspiler = @This(); -pub usingnamespace JSC.Codegen.JSTranspiler; +pub const js = JSC.Codegen.JSTranspiler; +pub const toJS = js.toJS; +pub const fromJS = js.fromJS; +pub const fromJSDirect = js.fromJSDirect; transpiler: bun.transpiler.Transpiler, arena: bun.ArenaAllocator, @@ -304,7 +306,7 @@ fn exportReplacementValue(value: JSValue, globalThis: *JSGlobalObject) bun.JSErr return null; } -fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std.mem.Allocator, args: *JSC.Node.ArgumentsSlice) (bun.JSError || bun.OOM)!TranspilerOptions { +fn transformOptionsFromJSC(globalObject: *JSC.JSGlobalObject, temp_allocator: std.mem.Allocator, args: *JSC.Node.ArgumentsSlice) (bun.JSError || bun.OOM)!TranspilerOptions { const globalThis = globalObject; const object = args.next() orelse return TranspilerOptions{ .log = logger.Log.init(temp_allocator) }; if (object.isUndefinedOrNull()) return TranspilerOptions{ .log = logger.Log.init(temp_allocator) }; diff --git a/src/bun.js/api/Timer.zig b/src/bun.js/api/Timer.zig index 2c572940ca..0656a08f6e 100644 --- a/src/bun.js/api/Timer.zig +++ b/src/bun.js/api/Timer.zig @@ -565,7 +565,10 @@ pub const TimeoutObject = struct { pub const ref = RefCount.ref; pub const deref = RefCount.deref; - pub usingnamespace JSC.Codegen.JSTimeout; + pub const js = JSC.Codegen.JSTimeout; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; ref_count: RefCount, event_loop_timer: EventLoopTimer = .{ @@ -584,10 +587,10 @@ pub const TimeoutObject = struct { ) JSValue { // internals are initialized by init() const timeout = bun.new(TimeoutObject, .{ .ref_count = .init(), .internals = undefined }); - const js = timeout.toJS(globalThis); - defer js.ensureStillAlive(); + const js_value = timeout.toJS(globalThis); + defer js_value.ensureStillAlive(); timeout.internals.init( - js, + js_value, globalThis, id, kind, @@ -595,7 +598,7 @@ pub const TimeoutObject = struct { callback, arguments_array_or_zero, ); - return js; + return js_value; } fn deinit(this: *TimeoutObject) void { @@ -654,7 +657,10 @@ pub const ImmediateObject = struct { pub const ref = RefCount.ref; pub const deref = RefCount.deref; - pub usingnamespace JSC.Codegen.JSImmediate; + pub const js = JSC.Codegen.JSImmediate; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; ref_count: RefCount, event_loop_timer: EventLoopTimer = .{ @@ -671,10 +677,10 @@ pub const ImmediateObject = struct { ) JSValue { // internals are initialized by init() const immediate = bun.new(ImmediateObject, .{ .ref_count = .init(), .internals = undefined }); - const js = immediate.toJS(globalThis); - defer js.ensureStillAlive(); + const js_value = immediate.toJS(globalThis); + defer js_value.ensureStillAlive(); immediate.internals.init( - js, + js_value, globalThis, id, .setImmediate, @@ -682,7 +688,7 @@ pub const ImmediateObject = struct { callback, arguments_array_or_zero, ); - return js; + return js_value; } fn deinit(this: *ImmediateObject) void { @@ -951,8 +957,8 @@ const TimerObjectInternals = struct { if (kind == .setImmediate) { if (arguments != .zero) - ImmediateObject.argumentsSetCached(timer_js, globalThis, arguments); - ImmediateObject.callbackSetCached(timer_js, globalThis, callback); + ImmediateObject.js.argumentsSetCached(timer_js, globalThis, arguments); + ImmediateObject.js.callbackSetCached(timer_js, globalThis, callback); const parent: *ImmediateObject = @fieldParentPtr("internals", this); vm.enqueueImmediateTask(parent); this.setEnableKeepingEventLoopAlive(vm, true); @@ -960,8 +966,8 @@ const TimerObjectInternals = struct { parent.ref(); } else { if (arguments != .zero) - TimeoutObject.argumentsSetCached(timer_js, globalThis, arguments); - TimeoutObject.callbackSetCached(timer_js, globalThis, callback); + TimeoutObject.js.argumentsSetCached(timer_js, globalThis, arguments); + TimeoutObject.js.callbackSetCached(timer_js, globalThis, callback); // this increments the refcount this.reschedule(vm); } diff --git a/src/bun.js/api/bun/dns_resolver.zig b/src/bun.js/api/bun/dns_resolver.zig index 27f486877c..f1d0ddb2a3 100644 --- a/src/bun.js/api/bun/dns_resolver.zig +++ b/src/bun.js/api/bun/dns_resolver.zig @@ -1809,7 +1809,10 @@ pub const DNSResolver = struct { pending_addr_cache_cares: AddrPendingCache, pending_nameinfo_cache_cares: NameInfoPendingCache, - pub usingnamespace JSC.Codegen.JSDNSResolver; + pub const js = JSC.Codegen.JSDNSResolver; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; const PollsMap = std.AutoArrayHashMap(c_ares.ares_socket_t, *PollType); diff --git a/src/bun.js/api/bun/h2_frame_parser.zig b/src/bun.js/api/bun/h2_frame_parser.zig index f9e65dd6b0..b912aade10 100644 --- a/src/bun.js/api/bun/h2_frame_parser.zig +++ b/src/bun.js/api/bun/h2_frame_parser.zig @@ -654,7 +654,11 @@ const Handlers = struct { pub const H2FrameParser = struct { pub const log = Output.scoped(.H2FrameParser, false); const Self = @This(); - pub usingnamespace JSC.Codegen.JSH2FrameParser; + pub const js = JSC.Codegen.JSH2FrameParser; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + const RefCount = bun.ptr.RefCount(@This(), "ref_count", deinit, .{}); pub const ref = RefCount.ref; pub const deref = RefCount.deref; @@ -4230,9 +4234,7 @@ pub const H2FrameParser = struct { this.detach(true); } - pub fn finalize( - this: *H2FrameParser, - ) void { + pub fn finalize(this: *H2FrameParser) void { log("finalize", .{}); this.deref(); } @@ -4240,7 +4242,7 @@ pub const H2FrameParser = struct { pub fn createNodeHttp2Binding(global: *JSC.JSGlobalObject) JSC.JSValue { return JSC.JSArray.create(global, &.{ - H2FrameParser.getConstructor(global), + H2FrameParser.js.getConstructor(global), JSC.JSFunction.create(global, "assertSettings", jsAssertSettings, 1, .{}), JSC.JSFunction.create(global, "getPackedSettings", jsGetPackedSettings, 1, .{}), JSC.JSFunction.create(global, "getUnpackedSettings", jsGetUnpackedSettings, 1, .{}), diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index 258fd03de3..3ffa9f84b5 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -524,7 +524,10 @@ pub const Listener = struct { strong_data: JSC.Strong = .empty, strong_self: JSC.Strong = .empty, - pub usingnamespace JSC.Codegen.JSListener; + pub const js = JSC.Codegen.JSListener; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub const ListenerType = union(enum) { uws: *uws.ListenSocket, diff --git a/src/bun.js/api/bun/socket/SocketAddress.zig b/src/bun.js/api/bun/socket/SocketAddress.zig index cb4ad1fe4c..02d9c2740a 100644 --- a/src/bun.js/api/bun/socket/SocketAddress.zig +++ b/src/bun.js/api/bun/socket/SocketAddress.zig @@ -5,7 +5,11 @@ //! TODO: add a inspect method (under `Symbol.for("nodejs.util.inspect.custom")`). //! Requires updating bindgen. const SocketAddress = @This(); -pub usingnamespace JSC.Codegen.JSSocketAddress; +pub const js = JSC.Codegen.JSSocketAddress; +pub const toJS = js.toJS; +pub const fromJS = js.fromJS; +pub const fromJSDirect = js.fromJSDirect; + pub const new = bun.TrivialNew(SocketAddress); // NOTE: not std.net.Address b/c .un is huge and we don't use it. diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index 2a031f59c9..0b868bafcf 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -1,7 +1,11 @@ //! The Subprocess object is returned by `Bun.spawn`. This file also holds the //! code for `Bun.spawnSync` -pub usingnamespace JSC.Codegen.JSSubprocess; +pub const js = JSC.Codegen.JSSubprocess; +pub const toJS = js.toJS; +pub const fromJS = js.fromJS; +pub const fromJSDirect = js.fromJSDirect; + const RefCount = bun.ptr.RefCount(@This(), "ref_count", deinit, .{}); pub const ref = RefCount.ref; pub const deref = RefCount.deref; @@ -78,7 +82,11 @@ pub inline fn assertStdioResult(result: StdioResult) void { } pub const ResourceUsage = struct { - pub usingnamespace JSC.Codegen.JSResourceUsage; + pub const js = JSC.Codegen.JSResourceUsage; + pub const toJS = ResourceUsage.js.toJS; + pub const fromJS = ResourceUsage.js.fromJS; + pub const fromJSDirect = ResourceUsage.js.fromJSDirect; + rusage: Rusage, pub fn getCPUTime( @@ -1290,7 +1298,7 @@ const Writable = union(enum) { const process: *Subprocess = @fieldParentPtr("stdin", this); if (process.this_jsvalue != .zero) { - if (Subprocess.stdinGetCached(process.this_jsvalue)) |existing_value| { + if (js.stdinGetCached(process.this_jsvalue)) |existing_value| { JSC.WebCore.FileSink.JSSink.setDestroyCallback(existing_value, 0); } } diff --git a/src/bun.js/api/bun/udp_socket.zig b/src/bun.js/api/bun/udp_socket.zig index 144d5a30ef..04a9f57a97 100644 --- a/src/bun.js/api/bun/udp_socket.zig +++ b/src/bun.js/api/bun/udp_socket.zig @@ -290,7 +290,10 @@ pub const UDPSocket = struct { port: u16, }; - pub usingnamespace JSC.Codegen.JSUDPSocket; + pub const js = JSC.Codegen.JSUDPSocket; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub fn hasPendingActivity(this: *This) callconv(.C) bool { return this.js_refcount.load(.monotonic) > 0; @@ -944,8 +947,8 @@ pub const UDPSocket = struct { .port = port, }; - UDPSocket.addressSetCached(callFrame.this(), globalThis, .zero); - UDPSocket.remoteAddressSetCached(callFrame.this(), globalThis, .zero); + js.addressSetCached(callFrame.this(), globalThis, .zero); + js.remoteAddressSetCached(callFrame.this(), globalThis, .zero); return .undefined; } diff --git a/src/bun.js/api/crypto/CryptoHasher.zig b/src/bun.js/api/crypto/CryptoHasher.zig index 3190217847..ae1ab34bbf 100644 --- a/src/bun.js/api/crypto/CryptoHasher.zig +++ b/src/bun.js/api/crypto/CryptoHasher.zig @@ -7,7 +7,11 @@ pub const CryptoHasher = union(enum) { const Digest = EVP.Digest; - pub usingnamespace JSC.Codegen.JSCryptoHasher; + pub const js = JSC.Codegen.JSCryptoHasher; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + pub const new = bun.TrivialNew(@This()); // For using only CryptoHasherZig in c++ @@ -307,7 +311,7 @@ pub const CryptoHasher = union(enum) { globalObject: *JSC.JSGlobalObject, _: *JSC.JSObject, ) JSC.JSValue { - return CryptoHasher.getConstructor(globalObject); + return CryptoHasher.js.getConstructor(globalObject); } pub fn update(this: *CryptoHasher, globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue { diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig index fa96c42682..72afbcf2e1 100644 --- a/src/bun.js/api/ffi.zig +++ b/src/bun.js/api/ffi.zig @@ -14,7 +14,6 @@ const Fs = @import("../../fs.zig"); const options = @import("../../options.zig"); const ZigString = bun.JSC.ZigString; -const js = bun.JSC.C; const JSC = bun.JSC; const JSError = @import("../base.zig").JSError; @@ -60,14 +59,17 @@ const Offsets = extern struct { }; pub const FFI = struct { + pub const js = JSC.Codegen.JSFFI; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + dylib: ?std.DynLib = null, relocated_bytes_to_free: ?[]u8 = null, functions: bun.StringArrayHashMapUnmanaged(Function) = .{}, closed: bool = false, shared_state: ?*TCC.State = null, - pub usingnamespace JSC.Codegen.JSFFI; - pub fn finalize(_: *FFI) callconv(.C) void {} const CompileC = struct { diff --git a/src/bun.js/api/filesystem_router.zig b/src/bun.js/api/filesystem_router.zig index 35bb81aece..90c83d164f 100644 --- a/src/bun.js/api/filesystem_router.zig +++ b/src/bun.js/api/filesystem_router.zig @@ -5,7 +5,6 @@ const CombinedScanner = @import("../../url.zig").CombinedScanner; const bun = @import("root").bun; const string = bun.string; const JSC = bun.JSC; -const js = JSC.C; const WebCore = JSC.WebCore; const Transpiler = bun.transpiler; const ScriptSrcStream = std.io.FixedBufferStream([]u8); @@ -44,7 +43,10 @@ pub const FileSystemRouter = struct { allocator: std.mem.Allocator = undefined, asset_prefix: ?*JSC.RefString = null, - pub usingnamespace JSC.Codegen.JSFileSystemRouter; + pub const js = JSC.Codegen.JSFileSystemRouter; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub fn constructor(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!*FileSystemRouter { const argument_ = callframe.arguments_old(1); @@ -278,7 +280,7 @@ pub const FileSystemRouter = struct { globalThis.allocator().destroy(this.arena); this.arena = arena; - @This().routesSetCached(this_value, globalThis, JSC.JSValue.zero); + js.routesSetCached(this_value, globalThis, JSC.JSValue.zero); this.allocator = allocator; this.router = router; return this_value; @@ -418,7 +420,10 @@ pub const MatchedRoute = struct { needs_deinit: bool = true, base_dir: ?*JSC.RefString = null, - pub usingnamespace JSC.Codegen.JSMatchedRoute; + pub const js = JSC.Codegen.JSMatchedRoute; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub fn getName(this: *MatchedRoute, globalThis: *JSC.JSGlobalObject) JSValue { return ZigString.init(this.route.name).withEncoding().toJS(globalThis); @@ -537,7 +542,7 @@ pub const MatchedRoute = struct { threadlocal var query_string_values_buf: [256]string = undefined; threadlocal var query_string_value_refs_buf: [256]ZigString = undefined; - pub fn createQueryObject(ctx: js.JSContextRef, map: *QueryStringMap) JSValue { + pub fn createQueryObject(ctx: *JSC.JSGlobalObject, map: *QueryStringMap) JSValue { const QueryObjectCreator = struct { query: *QueryStringMap, pub fn create(this: *@This(), obj: *JSObject, global: *JSGlobalObject) void { diff --git a/src/bun.js/api/glob.zig b/src/bun.js/api/glob.zig index f4911965e4..bf10f3ea64 100644 --- a/src/bun.js/api/glob.zig +++ b/src/bun.js/api/glob.zig @@ -23,7 +23,10 @@ const CodepointIterator = @import("../../string_immutable.zig").UnsignedCodepoin const Arena = std.heap.ArenaAllocator; -pub usingnamespace JSC.Codegen.JSGlob; +pub const js = JSC.Codegen.JSGlob; +pub const toJS = js.toJS; +pub const fromJS = js.fromJS; +pub const fromJSDirect = js.fromJSDirect; pattern: []const u8, pattern_codepoints: ?std.ArrayList(u32) = null, diff --git a/src/bun.js/api/html_rewriter.zig b/src/bun.js/api/html_rewriter.zig index 289d1d1ff5..490cc0a750 100644 --- a/src/bun.js/api/html_rewriter.zig +++ b/src/bun.js/api/html_rewriter.zig @@ -48,7 +48,10 @@ pub const HTMLRewriter = struct { builder: *LOLHTML.HTMLRewriter.Builder, context: *LOLHTMLContext, - pub usingnamespace JSC.Codegen.JSHTMLRewriter; + pub const js = JSC.Codegen.JSHTMLRewriter; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub fn constructor(_: *JSGlobalObject, _: *JSC.CallFrame) bun.JSError!*HTMLRewriter { const rewriter = bun.default_allocator.create(HTMLRewriter) catch bun.outOfMemory(); @@ -215,7 +218,7 @@ pub const HTMLRewriter = struct { var blob = out_response.body.value.useAsAnyBlobAllowNonUTF8String(); defer { - _ = Response.dangerouslySetPtr(out_response_value, null); + _ = Response.js.dangerouslySetPtr(out_response_value, null); // Manually invoke the finalizer to ensure it does what we want out_response.finalize(); } @@ -1077,7 +1080,10 @@ pub const TextChunk = struct { ref_count: RefCount, text_chunk: ?*LOLHTML.TextChunk = null, - pub usingnamespace JSC.Codegen.JSTextChunk; + pub const js = JSC.Codegen.JSTextChunk; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub fn init(text_chunk: *LOLHTML.TextChunk) *TextChunk { return bun.new(TextChunk, .{ @@ -1197,7 +1203,10 @@ pub const DocType = struct { }); } - pub usingnamespace JSC.Codegen.JSDocType; + pub const js = JSC.Codegen.JSDocType; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; /// The doctype name. pub fn name( @@ -1267,7 +1276,10 @@ pub const DocEnd = struct { ref_count: RefCount, doc_end: ?*LOLHTML.DocEnd, - pub usingnamespace JSC.Codegen.JSDocEnd; + pub const js = JSC.Codegen.JSDocEnd; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub fn init(doc_end: *LOLHTML.DocEnd) *DocEnd { return bun.new(DocEnd, .{ @@ -1322,7 +1334,10 @@ pub const Comment = struct { ref_count: RefCount, comment: ?*LOLHTML.Comment = null, - pub usingnamespace JSC.Codegen.JSComment; + pub const js = JSC.Codegen.JSComment; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub fn init(comment: *LOLHTML.Comment) *Comment { return bun.new(Comment, .{ @@ -1475,7 +1490,10 @@ pub const EndTag = struct { pub const onEndTagHandler = LOLHTML.DirectiveHandler(LOLHTML.EndTag, Handler, onEndTag); }; - pub usingnamespace JSC.Codegen.JSEndTag; + pub const js = JSC.Codegen.JSEndTag; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; fn contentHandler(this: *EndTag, comptime Callback: (fn (*LOLHTML.EndTag, []const u8, bool) LOLHTML.Error!void), thisObject: JSValue, globalObject: *JSGlobalObject, content: ZigString, contentOptions: ?ContentOptions) JSValue { if (this.end_tag == null) @@ -1599,7 +1617,10 @@ pub const AttributeIterator = struct { bun.destroy(this); } - pub usingnamespace JSC.Codegen.JSAttributeIterator; + pub const js = JSC.Codegen.JSAttributeIterator; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub fn next(this: *AttributeIterator, globalObject: *JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue { const done_label = JSC.ZigString.static("done"); @@ -1639,7 +1660,10 @@ pub const Element = struct { ref_count: RefCount, element: ?*LOLHTML.Element = null, - pub usingnamespace JSC.Codegen.JSElement; + pub const js = JSC.Codegen.JSElement; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub fn init(element: *LOLHTML.Element) *Element { return bun.new(Element, .{ diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index a378add093..518138fab3 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -42,14 +42,12 @@ const Headers = WebCore.Headers; const Fetch = WebCore.Fetch; const HTTP = bun.http; const FetchEvent = WebCore.FetchEvent; -const js = bun.JSC.C; const JSC = bun.JSC; const MarkedArrayBuffer = @import("../base.zig").MarkedArrayBuffer; const getAllocator = @import("../base.zig").getAllocator; const JSValue = bun.JSC.JSValue; const JSGlobalObject = bun.JSC.JSGlobalObject; -const ExceptionValueRef = bun.JSC.ExceptionValueRef; const JSPrivateDataPtr = bun.JSC.JSPrivateDataPtr; const ConsoleObject = bun.JSC.ConsoleObject; const Node = bun.JSC.Node; @@ -5821,7 +5819,7 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp false, ); } else { - const fetch_error = JSC.WebCore.Fetch.fetch_type_error_strings.get(js.JSValueGetType(ctx, first_arg.asRef())); + const fetch_error = JSC.WebCore.Fetch.fetch_type_error_strings.get(bun.JSC.C.JSValueGetType(ctx, first_arg.asRef())); const err = JSC.toTypeError(.ERR_INVALID_ARG_TYPE, "{s}", .{fetch_error}, ctx); return JSPromise.dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM(ctx, err); diff --git a/src/bun.js/api/server/HTMLBundle.zig b/src/bun.js/api/server/HTMLBundle.zig index d3bc6d45b6..ab6742f767 100644 --- a/src/bun.js/api/server/HTMLBundle.zig +++ b/src/bun.js/api/server/HTMLBundle.zig @@ -2,7 +2,11 @@ //! HTML file, and can be passed to the `static` option in `Bun.serve`. The build //! is done lazily (state held in HTMLBundle.Route or DevServer.RouteBundle.HTML). pub const HTMLBundle = @This(); -pub usingnamespace JSC.Codegen.JSHTMLBundle; +pub const js = JSC.Codegen.JSHTMLBundle; +pub const toJS = js.toJS; +pub const fromJS = js.fromJS; +pub const fromJSDirect = js.fromJSDirect; + /// HTMLBundle can be owned by JavaScript as well as any number of Server instances. const RefCount = bun.ptr.RefCount(@This(), "ref_count", deinit, .{}); pub const ref = RefCount.ref; diff --git a/src/bun.js/api/server/NodeHTTPResponse.zig b/src/bun.js/api/server/NodeHTTPResponse.zig index ee76728f08..6ca8fdf57c 100644 --- a/src/bun.js/api/server/NodeHTTPResponse.zig +++ b/src/bun.js/api/server/NodeHTTPResponse.zig @@ -1,7 +1,11 @@ const NodeHTTPResponse = @This(); const log = bun.Output.scoped(.NodeHTTPResponse, false); -pub usingnamespace JSC.Codegen.JSNodeHTTPResponse; +pub const js = JSC.Codegen.JSNodeHTTPResponse; +pub const toJS = js.toJS; +pub const fromJS = js.fromJS; +pub const fromJSDirect = js.fromJSDirect; + const RefCount = bun.ptr.RefCount(@This(), "ref_count", deinit, .{}); pub const ref = RefCount.ref; pub const deref = RefCount.deref; @@ -138,7 +142,7 @@ pub fn upgrade(this: *NodeHTTPResponse, data_value: JSValue, sec_websocket_proto defer if (new_socket) |socket| { this.flags.upgraded = true; Bun__setNodeHTTPServerSocketUsSocketValue(socketValue, socket); - ServerWebSocket.socketSetCached(ws.getThisValue(), ws_handler.globalObject, socketValue); + ServerWebSocket.js.socketSetCached(ws.getThisValue(), ws_handler.globalObject, socketValue); defer this.js_ref.unref(JSC.VirtualMachine.get()); switch (this.raw_response) { .SSL => this.raw_response = uws.AnyResponse.init(uws.NewApp(true).Response.castRes(@alignCast(@ptrCast(socket)))), @@ -219,7 +223,10 @@ pub fn upgrade(this: *NodeHTTPResponse, data_value: JSValue, sec_websocket_proto pub fn maybeStopReadingBody(this: *NodeHTTPResponse, vm: *JSC.VirtualMachine, thisValue: JSC.JSValue) void { this.upgrade_context.deinit(); // we can discard the upgrade context now - if ((this.flags.socket_closed or this.flags.ended) and (this.body_read_ref.has or this.body_read_state == .pending) and (!this.flags.hasCustomOnData or NodeHTTPResponse.onDataGetCached(thisValue) == null)) { + if ((this.flags.socket_closed or this.flags.ended) and + (this.body_read_ref.has or this.body_read_state == .pending) and + (!this.flags.hasCustomOnData or js.onDataGetCached(thisValue) == null)) + { const had_ref = this.body_read_ref.has; this.raw_response.clearOnData(); this.body_read_ref.unref(vm); @@ -517,11 +524,11 @@ fn handleAbortOrTimeout(this: *NodeHTTPResponse, comptime event: AbortEvent, js_ defer if (event == .abort) this.markRequestAsDoneIfNecessary(); const js_this: JSValue = if (js_value == .zero) this.getThisValue() else js_value; - if (NodeHTTPResponse.onAbortedGetCached(js_this)) |on_aborted| { + if (js.onAbortedGetCached(js_this)) |on_aborted| { const globalThis = JSC.VirtualMachine.get().global; defer { if (event == .abort) { - NodeHTTPResponse.onAbortedSetCached(js_this, globalThis, .zero); + js.onAbortedSetCached(js_this, globalThis, .zero); } } @@ -553,7 +560,7 @@ pub fn doPause(this: *NodeHTTPResponse, _: *JSC.JSGlobalObject, _: *JSC.CallFram if (this.flags.request_has_completed or this.flags.socket_closed or this.flags.ended) { return .false; } - if (this.body_read_ref.has and NodeHTTPResponse.onDataGetCached(thisValue) == null) { + if (this.body_read_ref.has and js.onDataGetCached(thisValue) == null) { this.flags.is_data_buffered_during_pause = true; this.raw_response.onData(*NodeHTTPResponse, onBufferRequestBodyWhilePaused, this); } @@ -620,7 +627,7 @@ pub export fn Bun__NodeHTTPRequest__onResolve(globalObject: *JSC.JSGlobalObject, if (!this.flags.request_has_completed and !this.flags.socket_closed) { const this_value = this.getThisValue(); if (this_value != .zero) { - NodeHTTPResponse.onAbortedSetCached(this_value, globalObject, .zero); + js.onAbortedSetCached(this_value, globalObject, .zero); } this.raw_response.clearOnData(); this.raw_response.clearOnWritable(); @@ -646,7 +653,7 @@ pub export fn Bun__NodeHTTPRequest__onReject(globalObject: *JSC.JSGlobalObject, if (!this.flags.request_has_completed and !this.flags.socket_closed) { const this_value = this.getThisValue(); if (this_value != .zero) { - NodeHTTPResponse.onAbortedSetCached(this_value, globalObject, .zero); + js.onAbortedSetCached(this_value, globalObject, .zero); } this.raw_response.clearOnData(); this.raw_response.clearOnWritable(); @@ -710,7 +717,7 @@ fn onDataOrAborted(this: *NodeHTTPResponse, chunk: []const u8, last: bool, event } } - if (NodeHTTPResponse.onDataGetCached(thisValue)) |callback| { + if (js.onDataGetCached(thisValue)) |callback| { if (callback == .undefined) { return; } @@ -764,9 +771,9 @@ fn onDrain(this: *NodeHTTPResponse, offset: u64, response: uws.AnyResponse) bool return false; } const thisValue = this.getThisValue(); - const on_writable = NodeHTTPResponse.onWritableGetCached(thisValue) orelse return false; + const on_writable = js.onWritableGetCached(thisValue) orelse return false; const globalThis = JSC.VirtualMachine.get().global; - NodeHTTPResponse.onWritableSetCached(thisValue, globalThis, .undefined); // TODO(@heimskr): is this necessary? + js.onWritableSetCached(thisValue, globalThis, .undefined); // TODO(@heimskr): is this necessary? const vm = globalThis.bunVM(); response.corked(JSC.EventLoop.runCallback, .{ vm.eventLoop(), on_writable, globalThis, .undefined, &.{JSC.JSValue.jsNumberFromUint64(offset)} }); @@ -847,13 +854,13 @@ fn writeOrEnd( if (is_end) { // Discard the body read ref if it's pending and no onData callback is set at this point. // This is the equivalent of req._dump(). - if (this.body_read_ref.has and this.body_read_state == .pending and (!this.flags.hasCustomOnData or NodeHTTPResponse.onDataGetCached(this_value) == null)) { + if (this.body_read_ref.has and this.body_read_state == .pending and (!this.flags.hasCustomOnData or js.onDataGetCached(this_value) == null)) { this.body_read_ref.unref(JSC.VirtualMachine.get()); this.body_read_state = .none; } if (this_value != .zero) { - NodeHTTPResponse.onAbortedSetCached(this_value, globalObject, .zero); + js.onAbortedSetCached(this_value, globalObject, .zero); } this.raw_response.clearAborted(); @@ -873,12 +880,12 @@ fn writeOrEnd( switch (this.raw_response.write(bytes)) { .want_more => |written| { this.raw_response.clearOnWritable(); - NodeHTTPResponse.onWritableSetCached(js_this, globalObject, .undefined); + js.onWritableSetCached(js_this, globalObject, .undefined); return JSC.JSValue.jsNumberFromUint64(written); }, .backpressure => |written| { if (callback_value != .undefined) { - NodeHTTPResponse.onWritableSetCached(js_this, globalObject, callback_value.withAsyncContextIfNeeded(globalObject)); + js.onWritableSetCached(js_this, globalObject, callback_value.withAsyncContextIfNeeded(globalObject)); this.raw_response.onWritable(*NodeHTTPResponse, onDrain, this); } @@ -890,23 +897,23 @@ fn writeOrEnd( pub fn setOnWritable(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSValue) bool { if (this.isDone() or value == .undefined) { - NodeHTTPResponse.onWritableSetCached(thisValue, globalObject, .undefined); + js.onWritableSetCached(thisValue, globalObject, .undefined); } else { - NodeHTTPResponse.onWritableSetCached(thisValue, globalObject, value.withAsyncContextIfNeeded(globalObject)); + js.onWritableSetCached(thisValue, globalObject, value.withAsyncContextIfNeeded(globalObject)); } return true; } pub fn getOnWritable(_: *NodeHTTPResponse, thisValue: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue { - return NodeHTTPResponse.onWritableGetCached(thisValue) orelse .undefined; + return js.onWritableGetCached(thisValue) orelse .undefined; } pub fn getOnAbort(this: *NodeHTTPResponse, thisValue: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue { if (this.flags.socket_closed) { return .undefined; } - return NodeHTTPResponse.onAbortedGetCached(thisValue) orelse .undefined; + return js.onAbortedGetCached(thisValue) orelse .undefined; } pub fn setOnAbort(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSValue) bool { @@ -915,16 +922,16 @@ pub fn setOnAbort(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalObject: } if (this.isDone() or value == .undefined) { - NodeHTTPResponse.onAbortedSetCached(thisValue, globalObject, .zero); + js.onAbortedSetCached(thisValue, globalObject, .zero); } else { - NodeHTTPResponse.onAbortedSetCached(thisValue, globalObject, value.withAsyncContextIfNeeded(globalObject)); + js.onAbortedSetCached(thisValue, globalObject, value.withAsyncContextIfNeeded(globalObject)); } return true; } pub fn getOnData(_: *NodeHTTPResponse, thisValue: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue { - return NodeHTTPResponse.onDataGetCached(thisValue) orelse .undefined; + return js.onDataGetCached(thisValue) orelse .undefined; } pub fn getHasCustomOnData(this: *NodeHTTPResponse, _: *JSC.JSGlobalObject) JSC.JSValue { @@ -943,7 +950,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) { - NodeHTTPResponse.onDataSetCached(thisValue, globalObject, .undefined); + js.onDataSetCached(thisValue, globalObject, .undefined); } if (!this.flags.socket_closed) this.raw_response.clearOnData(); @@ -955,7 +962,7 @@ fn clearOnDataCallback(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalOb pub fn setOnData(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSValue) bool { 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) { - NodeHTTPResponse.onDataSetCached(thisValue, globalObject, .undefined); + js.onDataSetCached(thisValue, globalObject, .undefined); defer { if (this.body_read_ref.has) { this.body_read_ref.unref(globalObject.bunVM()); @@ -973,7 +980,7 @@ pub fn setOnData(this: *NodeHTTPResponse, thisValue: JSC.JSValue, globalObject: return true; } - NodeHTTPResponse.onDataSetCached(thisValue, globalObject, value.withAsyncContextIfNeeded(globalObject)); + js.onDataSetCached(thisValue, globalObject, value.withAsyncContextIfNeeded(globalObject)); this.flags.hasCustomOnData = true; this.raw_response.onData(*NodeHTTPResponse, onData, this); this.flags.is_data_buffered_during_pause = false; diff --git a/src/bun.js/api/server/ServerWebSocket.zig b/src/bun.js/api/server/ServerWebSocket.zig index 04c9c7664d..72eb4f372e 100644 --- a/src/bun.js/api/server/ServerWebSocket.zig +++ b/src/bun.js/api/server/ServerWebSocket.zig @@ -27,7 +27,11 @@ inline fn websocket(this: *const ServerWebSocket) uws.AnyWebSocket { return this.flags.websocket(); } -pub usingnamespace JSC.Codegen.JSServerWebSocket; +pub const js = JSC.Codegen.JSServerWebSocket; +pub const toJS = js.toJS; +pub const fromJS = js.fromJS; +pub const fromJSDirect = js.fromJSDirect; + pub const new = bun.TrivialNew(ServerWebSocket); pub fn memoryCost(this: *const ServerWebSocket) usize { @@ -64,7 +68,7 @@ pub fn onOpen(this: *ServerWebSocket, ws: uws.AnyWebSocket) void { this.flags.opened = false; if (value_to_cache != .zero) { const current_this = this.getThisValue(); - ServerWebSocket.dataSetCached(current_this, globalObject, value_to_cache); + js.dataSetCached(current_this, globalObject, value_to_cache); } if (onOpenHandler.isEmptyOrUndefinedOrNull()) return; @@ -289,7 +293,7 @@ pub fn onClose(this: *ServerWebSocket, _: uws.AnyWebSocket, code: i32, message: const signal = this.signal; this.signal = null; - if (ServerWebSocket.socketGetCached(this.getThisValue())) |socket| { + if (js.socketGetCached(this.getThisValue())) |socket| { Bun__callNodeHTTPServerSocketOnClose(socket); } @@ -1032,7 +1036,7 @@ pub fn setData( value: JSC.JSValue, ) callconv(.C) bool { log("setData()", .{}); - ServerWebSocket.dataSetCached(this.this_value, globalObject, value); + js.dataSetCached(this.this_value, globalObject, value); return true; } diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig index f0eee24a4a..8b70ccce71 100644 --- a/src/bun.js/base.zig +++ b/src/bun.js/base.zig @@ -1,4 +1,3 @@ -pub const js = bun.JSC.C; const std = @import("std"); const bun = @import("root").bun; const string = bun.string; @@ -18,8 +17,7 @@ const TaggedPointerTypes = @import("../ptr.zig"); const TaggedPointerUnion = TaggedPointerTypes.TaggedPointerUnion; const JSError = bun.JSError; -pub const ExceptionValueRef = [*c]js.JSValueRef; -pub const JSValueRef = js.JSValueRef; +pub const JSValueRef = bun.JSC.C.JSValueRef; pub const Lifetime = enum { allocated, @@ -151,15 +149,6 @@ pub const Properties = struct { pub const navigate = "navigate"; pub const follow = "follow"; }; - - pub const Refs = struct { - pub var empty_string_ptr = [_]u8{0}; - pub var empty_string: js.JSStringRef = undefined; - }; - - pub fn init() void { - Refs.empty_string = js.JSStringCreateWithUTF8CString(&Refs.empty_string_ptr); - } }; pub const PathString = bun.PathString; @@ -194,7 +183,7 @@ fn toTypeErrorWithCode( code: []const u8, comptime fmt: string, args: anytype, - ctx: js.JSContextRef, + ctx: *JSC.JSGlobalObject, ) JSC.JSValue { @branchHint(.cold); var zig_str: JSC.ZigString = undefined; @@ -215,31 +204,21 @@ pub fn toTypeError( code: JSC.Error, comptime fmt: [:0]const u8, args: anytype, - ctx: js.JSContextRef, + ctx: *JSC.JSGlobalObject, ) JSC.JSValue { return code.fmt(ctx, fmt, args); } -pub fn throwInvalidArguments( - comptime fmt: [:0]const u8, - args: anytype, - ctx: js.JSContextRef, - exception: ExceptionValueRef, -) void { - @branchHint(.cold); - exception.* = JSC.Error.ERR_INVALID_ARG_TYPE.fmt(ctx, fmt, args).asObjectRef(); -} - pub fn toInvalidArguments( comptime fmt: [:0]const u8, args: anytype, - ctx: js.JSContextRef, + ctx: *JSC.JSGlobalObject, ) JSC.JSValue { @branchHint(.cold); return JSC.Error.ERR_INVALID_ARG_TYPE.fmt(ctx, fmt, args); } -pub fn getAllocator(_: js.JSContextRef) std.mem.Allocator { +pub fn getAllocator(_: *JSC.JSGlobalObject) std.mem.Allocator { return default_allocator; } @@ -251,7 +230,7 @@ pub fn dump(value: JSC.WebCore.JSValue, globalObject: *JSC.JSGlobalObject) !void Output.flush(); } -pub const JSStringList = std.ArrayList(js.JSStringRef); +pub const JSStringList = std.ArrayList(JSC.C.JSStringRef); pub const ArrayBuffer = extern struct { ptr: [*]u8 = undefined, @@ -445,7 +424,7 @@ pub const ArrayBuffer = extern struct { extern "c" fn Bun__createUint8ArrayForCopy(*JSC.JSGlobalObject, ptr: ?*const anyopaque, len: usize, buffer: bool) JSC.JSValue; extern "c" fn Bun__createArrayBufferForCopy(*JSC.JSGlobalObject, ptr: ?*const anyopaque, len: usize) JSC.JSValue; - pub fn fromTypedArray(ctx: JSC.C.JSContextRef, value: JSC.JSValue) ArrayBuffer { + pub fn fromTypedArray(ctx: *JSC.JSGlobalObject, value: JSC.JSValue) ArrayBuffer { var out = std.mem.zeroes(ArrayBuffer); const was = value.asArrayBuffer_(ctx, &out); bun.assert(was); @@ -470,7 +449,7 @@ pub const ArrayBuffer = extern struct { return ArrayBuffer{ .offset = 0, .len = @as(u32, @intCast(bytes.len)), .byte_len = @as(u32, @intCast(bytes.len)), .typed_array_type = typed_array_type, .ptr = bytes.ptr }; } - pub fn toJSUnchecked(this: ArrayBuffer, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.JSValue { + pub fn toJSUnchecked(this: ArrayBuffer, ctx: *JSC.JSGlobalObject, exception: JSC.C.ExceptionRef) JSC.JSValue { // The reason for this is // JSC C API returns a detached arraybuffer @@ -513,7 +492,7 @@ pub const ArrayBuffer = extern struct { const log = Output.scoped(.ArrayBuffer, false); - pub fn toJS(this: ArrayBuffer, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.JSValue { + pub fn toJS(this: ArrayBuffer, ctx: *JSC.JSGlobalObject, exception: JSC.C.ExceptionRef) JSC.JSValue { if (this.value != .zero) { return this.value; } @@ -549,7 +528,7 @@ pub const ArrayBuffer = extern struct { pub fn toJSWithContext( this: ArrayBuffer, - ctx: JSC.C.JSContextRef, + ctx: *JSC.JSGlobalObject, deallocator: ?*anyopaque, callback: JSC.C.JSTypedArrayBytesDeallocator, exception: JSC.C.ExceptionRef, @@ -621,14 +600,14 @@ pub const MarkedArrayBuffer = struct { return this.buffer.stream(); } - pub fn fromTypedArray(ctx: JSC.C.JSContextRef, value: JSC.JSValue) MarkedArrayBuffer { + pub fn fromTypedArray(ctx: *JSC.JSGlobalObject, value: JSC.JSValue) MarkedArrayBuffer { return MarkedArrayBuffer{ .allocator = null, .buffer = ArrayBuffer.fromTypedArray(ctx, value), }; } - pub fn fromArrayBuffer(ctx: JSC.C.JSContextRef, value: JSC.JSValue) MarkedArrayBuffer { + pub fn fromArrayBuffer(ctx: *JSC.JSGlobalObject, value: JSC.JSValue) MarkedArrayBuffer { return MarkedArrayBuffer{ .allocator = null, .buffer = ArrayBuffer.fromArrayBuffer(ctx, value), @@ -677,16 +656,16 @@ pub const MarkedArrayBuffer = struct { return container; } - pub fn toNodeBuffer(this: *const MarkedArrayBuffer, ctx: js.JSContextRef) JSC.JSValue { + pub fn toNodeBuffer(this: *const MarkedArrayBuffer, ctx: *JSC.JSGlobalObject) JSC.JSValue { return JSC.JSValue.createBufferWithCtx(ctx, this.buffer.byteSlice(), this.buffer.ptr, MarkedArrayBuffer_deallocator); } - pub fn toJSObjectRef(this: *const MarkedArrayBuffer, ctx: js.JSContextRef, exception: js.ExceptionRef) js.JSObjectRef { + pub fn toJSObjectRef(this: *const MarkedArrayBuffer, ctx: *JSC.JSGlobalObject, exception: JSC.C.ExceptionRef) bun.JSC.C.JSObjectRef { if (!this.buffer.value.isEmptyOrUndefinedOrNull()) { return this.buffer.value.asObjectRef(); } if (this.buffer.byte_len == 0) { - return js.JSObjectMakeTypedArray( + return JSC.C.JSObjectMakeTypedArray( ctx, this.buffer.typed_array_type.toC(), 0, @@ -694,7 +673,7 @@ pub const MarkedArrayBuffer = struct { ); } - return js.JSObjectMakeTypedArrayWithBytesNoCopy( + return JSC.C.JSObjectMakeTypedArrayWithBytesNoCopy( ctx, this.buffer.typed_array_type.toC(), this.buffer.ptr, @@ -829,16 +808,16 @@ const MD5_SHA1 = JSC.API.Bun.Crypto.MD5_SHA1; const FFI = JSC.FFI; pub const JSPropertyNameIterator = struct { - array: js.JSPropertyNameArrayRef, + array: JSC.C.JSPropertyNameArrayRef, count: u32, i: u32 = 0, - pub fn next(this: *JSPropertyNameIterator) ?js.JSStringRef { + pub fn next(this: *JSPropertyNameIterator) ?JSC.C.JSStringRef { if (this.i >= this.count) return null; const i = this.i; this.i += 1; - return js.JSPropertyNameArrayGetNameAtIndex(this.array, i); + return JSC.C.JSPropertyNameArrayGetNameAtIndex(this.array, i); } }; diff --git a/src/bun.js/bindings/JSGlobalObject.zig b/src/bun.js/bindings/JSGlobalObject.zig index 85fc040329..9e3b34b511 100644 --- a/src/bun.js/bindings/JSGlobalObject.zig +++ b/src/bun.js/bindings/JSGlobalObject.zig @@ -426,8 +426,9 @@ pub const JSGlobalObject = opaque { return error.JSError; } - pub fn ref(this: *JSGlobalObject) C_API.JSContextRef { - return @as(C_API.JSContextRef, @ptrCast(this)); + // TODO: delete these two fns + pub fn ref(this: *JSGlobalObject) *JSGlobalObject { + return this; } pub const ctx = ref; diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index b9d3fa55e7..529467a664 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -50,7 +50,6 @@ const JSValue = bun.JSC.JSValue; const NewClass = @import("./base.zig").NewClass; const JSGlobalObject = bun.JSC.JSGlobalObject; -const ExceptionValueRef = bun.JSC.ExceptionValueRef; const JSPrivateDataPtr = bun.JSC.JSPrivateDataPtr; const ConsoleObject = bun.JSC.ConsoleObject; const Node = bun.JSC.Node; diff --git a/src/bun.js/javascript_core_c_api.zig b/src/bun.js/javascript_core_c_api.zig index b2345047db..951ce8a788 100644 --- a/src/bun.js/javascript_core_c_api.zig +++ b/src/bun.js/javascript_core_c_api.zig @@ -7,6 +7,7 @@ const bun = @import("root").bun; const std = @import("std"); const cpp = @import("./bindings/bindings.zig"); +const JSC = bun.JSC; const generic = opaque { pub fn value(this: *const generic) cpp.JSValue { return @as(cpp.JSValue, @enumFromInt(@as(cpp.JSValueReprInt, @bitCast(@intFromPtr(this))))); @@ -16,7 +17,6 @@ pub const Private = anyopaque; pub const struct_OpaqueJSContextGroup = generic; pub const JSContextGroupRef = ?*const struct_OpaqueJSContextGroup; pub const struct_OpaqueJSContext = generic; -pub const JSContextRef = *cpp.JSGlobalObject; pub const JSGlobalContextRef = ?*cpp.JSGlobalObject; pub const struct_OpaqueJSPropertyNameAccumulator = generic; @@ -25,7 +25,7 @@ pub const JSTypedArrayBytesDeallocator = ?*const fn (*anyopaque, *anyopaque) cal pub const OpaqueJSValue = generic; pub const JSValueRef = ?*OpaqueJSValue; pub const JSObjectRef = ?*OpaqueJSValue; -pub extern fn JSGarbageCollect(ctx: JSContextRef) void; +pub extern fn JSGarbageCollect(ctx: *JSC.JSGlobalObject) void; pub const JSType = enum(c_uint) { kJSTypeUndefined, kJSTypeNull, @@ -70,15 +70,15 @@ pub const kJSTypedArrayTypeFloat32Array = @intFromEnum(JSTypedArrayType.kJSTyped pub const kJSTypedArrayTypeFloat64Array = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeFloat64Array); pub const kJSTypedArrayTypeArrayBuffer = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeArrayBuffer); pub const kJSTypedArrayTypeNone = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeNone); -pub extern fn JSValueGetType(ctx: JSContextRef, value: JSValueRef) JSType; -pub extern fn JSValueMakeNull(ctx: JSContextRef) JSValueRef; -pub extern fn JSValueToNumber(ctx: JSContextRef, value: JSValueRef, exception: ExceptionRef) f64; -pub extern fn JSValueToObject(ctx: JSContextRef, value: JSValueRef, exception: ExceptionRef) JSObjectRef; +pub extern fn JSValueGetType(ctx: *JSC.JSGlobalObject, value: JSValueRef) JSType; +pub extern fn JSValueMakeNull(ctx: *JSC.JSGlobalObject) JSValueRef; +pub extern fn JSValueToNumber(ctx: *JSC.JSGlobalObject, value: JSValueRef, exception: ExceptionRef) f64; +pub extern fn JSValueToObject(ctx: *JSC.JSGlobalObject, value: JSValueRef, exception: ExceptionRef) JSObjectRef; const log_protection = bun.Environment.allow_assert and false; -pub inline fn JSValueUnprotect(ctx: JSContextRef, value: JSValueRef) void { +pub inline fn JSValueUnprotect(ctx: *JSC.JSGlobalObject, value: JSValueRef) void { const Wrapped = struct { - pub extern fn JSValueUnprotect(ctx: JSContextRef, value: JSValueRef) void; + pub extern fn JSValueUnprotect(ctx: *JSC.JSGlobalObject, value: JSValueRef) void; }; if (comptime log_protection) { const Output = bun.Output; @@ -88,9 +88,9 @@ pub inline fn JSValueUnprotect(ctx: JSContextRef, value: JSValueRef) void { Wrapped.JSValueUnprotect(ctx, value); } -pub inline fn JSValueProtect(ctx: JSContextRef, value: JSValueRef) void { +pub inline fn JSValueProtect(ctx: *JSC.JSGlobalObject, value: JSValueRef) void { const Wrapped = struct { - pub extern fn JSValueProtect(ctx: JSContextRef, value: JSValueRef) void; + pub extern fn JSValueProtect(ctx: *JSC.JSGlobalObject, value: JSValueRef) void; }; if (comptime log_protection) { const Output = bun.Output; @@ -119,42 +119,42 @@ pub const JSClassAttributes = enum(c_uint) { pub const kJSClassAttributeNone = @intFromEnum(JSClassAttributes.kJSClassAttributeNone); pub const kJSClassAttributeNoAutomaticPrototype = @intFromEnum(JSClassAttributes.kJSClassAttributeNoAutomaticPrototype); -pub const JSObjectInitializeCallback = *const fn (JSContextRef, JSObjectRef) callconv(.C) void; +pub const JSObjectInitializeCallback = *const fn (*JSC.JSGlobalObject, JSObjectRef) callconv(.C) void; pub const JSObjectFinalizeCallback = *const fn (JSObjectRef) callconv(.C) void; -pub const JSObjectGetPropertyNamesCallback = *const fn (JSContextRef, JSObjectRef, JSPropertyNameAccumulatorRef) callconv(.C) void; +pub const JSObjectGetPropertyNamesCallback = *const fn (*JSC.JSGlobalObject, JSObjectRef, JSPropertyNameAccumulatorRef) callconv(.C) void; pub const ExceptionRef = [*c]JSValueRef; pub const JSObjectCallAsFunctionCallback = *const fn ( - ctx: JSContextRef, + ctx: *JSC.JSGlobalObject, function: JSObjectRef, thisObject: JSObjectRef, argumentCount: usize, arguments: [*c]const JSValueRef, exception: ExceptionRef, ) callconv(.C) JSValueRef; -pub const JSObjectCallAsConstructorCallback = *const fn (JSContextRef, JSObjectRef, usize, [*c]const JSValueRef, ExceptionRef) callconv(.C) JSObjectRef; -pub const JSObjectHasInstanceCallback = *const fn (JSContextRef, JSObjectRef, JSValueRef, ExceptionRef) callconv(.C) bool; -pub const JSObjectConvertToTypeCallback = *const fn (JSContextRef, JSObjectRef, JSType, ExceptionRef) callconv(.C) JSValueRef; +pub const JSObjectCallAsConstructorCallback = *const fn (*JSC.JSGlobalObject, JSObjectRef, usize, [*c]const JSValueRef, ExceptionRef) callconv(.C) JSObjectRef; +pub const JSObjectHasInstanceCallback = *const fn (*JSC.JSGlobalObject, JSObjectRef, JSValueRef, ExceptionRef) callconv(.C) bool; +pub const JSObjectConvertToTypeCallback = *const fn (*JSC.JSGlobalObject, JSObjectRef, JSType, ExceptionRef) callconv(.C) JSValueRef; -pub extern "c" fn JSObjectGetPrototype(ctx: JSContextRef, object: JSObjectRef) JSValueRef; -pub extern "c" fn JSObjectGetPropertyAtIndex(ctx: JSContextRef, object: JSObjectRef, propertyIndex: c_uint, exception: ExceptionRef) JSValueRef; -pub extern "c" fn JSObjectSetPropertyAtIndex(ctx: JSContextRef, object: JSObjectRef, propertyIndex: c_uint, value: JSValueRef, exception: ExceptionRef) void; -pub extern "c" fn JSObjectCallAsFunction(ctx: JSContextRef, object: JSObjectRef, thisObject: JSObjectRef, argumentCount: usize, arguments: [*c]const JSValueRef, exception: ExceptionRef) JSValueRef; -pub extern "c" fn JSObjectIsConstructor(ctx: JSContextRef, object: JSObjectRef) bool; -pub extern "c" fn JSObjectCallAsConstructor(ctx: JSContextRef, object: JSObjectRef, argumentCount: usize, arguments: [*c]const JSValueRef, exception: ExceptionRef) JSObjectRef; -pub extern "c" fn JSObjectMakeDate(ctx: JSContextRef, argumentCount: usize, arguments: [*c]const JSValueRef, exception: ExceptionRef) JSObjectRef; +pub extern "c" fn JSObjectGetPrototype(ctx: *JSC.JSGlobalObject, object: JSObjectRef) JSValueRef; +pub extern "c" fn JSObjectGetPropertyAtIndex(ctx: *JSC.JSGlobalObject, object: JSObjectRef, propertyIndex: c_uint, exception: ExceptionRef) JSValueRef; +pub extern "c" fn JSObjectSetPropertyAtIndex(ctx: *JSC.JSGlobalObject, object: JSObjectRef, propertyIndex: c_uint, value: JSValueRef, exception: ExceptionRef) void; +pub extern "c" fn JSObjectCallAsFunction(ctx: *JSC.JSGlobalObject, object: JSObjectRef, thisObject: JSObjectRef, argumentCount: usize, arguments: [*c]const JSValueRef, exception: ExceptionRef) JSValueRef; +pub extern "c" fn JSObjectIsConstructor(ctx: *JSC.JSGlobalObject, object: JSObjectRef) bool; +pub extern "c" fn JSObjectCallAsConstructor(ctx: *JSC.JSGlobalObject, object: JSObjectRef, argumentCount: usize, arguments: [*c]const JSValueRef, exception: ExceptionRef) JSObjectRef; +pub extern "c" fn JSObjectMakeDate(ctx: *JSC.JSGlobalObject, argumentCount: usize, arguments: [*c]const JSValueRef, exception: ExceptionRef) JSObjectRef; pub const JSChar = u16; -pub extern fn JSObjectMakeTypedArray(ctx: JSContextRef, arrayType: JSTypedArrayType, length: usize, exception: ExceptionRef) JSObjectRef; -pub extern fn JSObjectMakeTypedArrayWithBytesNoCopy(ctx: JSContextRef, arrayType: JSTypedArrayType, bytes: ?*anyopaque, byteLength: usize, bytesDeallocator: JSTypedArrayBytesDeallocator, deallocatorContext: ?*anyopaque, exception: ExceptionRef) JSObjectRef; -pub extern fn JSObjectMakeTypedArrayWithArrayBuffer(ctx: JSContextRef, arrayType: JSTypedArrayType, buffer: JSObjectRef, exception: ExceptionRef) JSObjectRef; -pub extern fn JSObjectMakeTypedArrayWithArrayBufferAndOffset(ctx: JSContextRef, arrayType: JSTypedArrayType, buffer: JSObjectRef, byteOffset: usize, length: usize, exception: ExceptionRef) JSObjectRef; -pub extern fn JSObjectGetTypedArrayBytesPtr(ctx: JSContextRef, object: JSObjectRef, exception: ExceptionRef) ?*anyopaque; -pub extern fn JSObjectGetTypedArrayLength(ctx: JSContextRef, object: JSObjectRef, exception: ExceptionRef) usize; -pub extern fn JSObjectGetTypedArrayByteLength(ctx: JSContextRef, object: JSObjectRef, exception: ExceptionRef) usize; -pub extern fn JSObjectGetTypedArrayByteOffset(ctx: JSContextRef, object: JSObjectRef, exception: ExceptionRef) usize; -pub extern fn JSObjectGetTypedArrayBuffer(ctx: JSContextRef, object: JSObjectRef, exception: ExceptionRef) JSObjectRef; -pub extern fn JSObjectMakeArrayBufferWithBytesNoCopy(ctx: JSContextRef, bytes: ?*anyopaque, byteLength: usize, bytesDeallocator: JSTypedArrayBytesDeallocator, deallocatorContext: ?*anyopaque, exception: ExceptionRef) JSObjectRef; -pub extern fn JSObjectGetArrayBufferBytesPtr(ctx: JSContextRef, object: JSObjectRef, exception: ExceptionRef) ?*anyopaque; -pub extern fn JSObjectGetArrayBufferByteLength(ctx: JSContextRef, object: JSObjectRef, exception: ExceptionRef) usize; +pub extern fn JSObjectMakeTypedArray(ctx: *JSC.JSGlobalObject, arrayType: JSTypedArrayType, length: usize, exception: ExceptionRef) JSObjectRef; +pub extern fn JSObjectMakeTypedArrayWithBytesNoCopy(ctx: *JSC.JSGlobalObject, arrayType: JSTypedArrayType, bytes: ?*anyopaque, byteLength: usize, bytesDeallocator: JSTypedArrayBytesDeallocator, deallocatorContext: ?*anyopaque, exception: ExceptionRef) JSObjectRef; +pub extern fn JSObjectMakeTypedArrayWithArrayBuffer(ctx: *JSC.JSGlobalObject, arrayType: JSTypedArrayType, buffer: JSObjectRef, exception: ExceptionRef) JSObjectRef; +pub extern fn JSObjectMakeTypedArrayWithArrayBufferAndOffset(ctx: *JSC.JSGlobalObject, arrayType: JSTypedArrayType, buffer: JSObjectRef, byteOffset: usize, length: usize, exception: ExceptionRef) JSObjectRef; +pub extern fn JSObjectGetTypedArrayBytesPtr(ctx: *JSC.JSGlobalObject, object: JSObjectRef, exception: ExceptionRef) ?*anyopaque; +pub extern fn JSObjectGetTypedArrayLength(ctx: *JSC.JSGlobalObject, object: JSObjectRef, exception: ExceptionRef) usize; +pub extern fn JSObjectGetTypedArrayByteLength(ctx: *JSC.JSGlobalObject, object: JSObjectRef, exception: ExceptionRef) usize; +pub extern fn JSObjectGetTypedArrayByteOffset(ctx: *JSC.JSGlobalObject, object: JSObjectRef, exception: ExceptionRef) usize; +pub extern fn JSObjectGetTypedArrayBuffer(ctx: *JSC.JSGlobalObject, object: JSObjectRef, exception: ExceptionRef) JSObjectRef; +pub extern fn JSObjectMakeArrayBufferWithBytesNoCopy(ctx: *JSC.JSGlobalObject, bytes: ?*anyopaque, byteLength: usize, bytesDeallocator: JSTypedArrayBytesDeallocator, deallocatorContext: ?*anyopaque, exception: ExceptionRef) JSObjectRef; +pub extern fn JSObjectGetArrayBufferBytesPtr(ctx: *JSC.JSGlobalObject, object: JSObjectRef, exception: ExceptionRef) ?*anyopaque; +pub extern fn JSObjectGetArrayBufferByteLength(ctx: *JSC.JSGlobalObject, object: JSObjectRef, exception: ExceptionRef) usize; pub const OpaqueJSContextGroup = struct_OpaqueJSContextGroup; pub const OpaqueJSContext = struct_OpaqueJSContext; pub const OpaqueJSPropertyNameAccumulator = struct_OpaqueJSPropertyNameAccumulator; @@ -162,7 +162,7 @@ pub const OpaqueJSPropertyNameAccumulator = struct_OpaqueJSPropertyNameAccumulat // This is a workaround for not receiving a JSException* object // This function lets us use the C API but returns a plain old JSValue // allowing us to have exceptions that include stack traces -pub extern "c" fn JSObjectCallAsFunctionReturnValueHoldingAPILock(ctx: JSContextRef, object: JSObjectRef, thisObject: JSObjectRef, argumentCount: usize, arguments: [*c]const JSValueRef) cpp.JSValue; +pub extern "c" fn JSObjectCallAsFunctionReturnValueHoldingAPILock(ctx: *JSC.JSGlobalObject, object: JSObjectRef, thisObject: JSObjectRef, argumentCount: usize, arguments: [*c]const JSValueRef) cpp.JSValue; pub extern fn JSRemoteInspectorDisableAutoStart() void; pub extern fn JSRemoteInspectorStart() void; diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index a64b65fac9..80e9186236 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -37,7 +37,6 @@ const ImportRecord = ast.ImportRecord; const DotEnv = @import("../env_loader.zig"); const PackageJSON = @import("../resolver/package_json.zig").PackageJSON; const MacroRemap = @import("../resolver/package_json.zig").MacroMap; -const js = bun.JSC.C; const JSC = bun.JSC; const MarkedArrayBuffer = @import("./base.zig").MarkedArrayBuffer; const getAllocator = @import("./base.zig").getAllocator; @@ -45,7 +44,6 @@ const JSValue = bun.JSC.JSValue; const node_module_module = @import("./bindings/NodeModuleModule.zig"); const JSGlobalObject = bun.JSC.JSGlobalObject; -const ExceptionValueRef = bun.JSC.ExceptionValueRef; const ConsoleObject = bun.JSC.ConsoleObject; const ZigException = bun.JSC.ZigException; const ZigStackTrace = bun.JSC.ZigStackTrace; diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index 5b4e40f36a..ec4bd29970 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -1335,7 +1335,7 @@ pub const Arguments = struct { this.new_path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Rename { + 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); }; @@ -1366,7 +1366,7 @@ pub const Arguments = struct { this.path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Truncate { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Truncate { const path = try PathOrFileDescriptor.fromJS(ctx, arguments, bun.default_allocator) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -1400,7 +1400,7 @@ pub const Arguments = struct { this.buffers.buffers.allocator = bun.default_allocator; } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Writev { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Writev { const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); @@ -1454,7 +1454,7 @@ pub const Arguments = struct { this.buffers.buffers.allocator = bun.default_allocator; } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Readv { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Readv { const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); @@ -1500,7 +1500,7 @@ pub const Arguments = struct { _ = this; } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!FTruncate { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!FTruncate { const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); @@ -1535,7 +1535,7 @@ pub const Arguments = struct { this.path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Chown { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Chown { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -1571,7 +1571,7 @@ pub const Arguments = struct { pub fn toThreadSafe(_: *const @This()) void {} - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Fchown { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Fchown { const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); @@ -1622,7 +1622,7 @@ pub const Arguments = struct { this.path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Lutimes { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Lutimes { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -1664,7 +1664,7 @@ pub const Arguments = struct { this.path.deinitAndUnprotect(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Chmod { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Chmod { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -1689,7 +1689,7 @@ pub const Arguments = struct { pub fn toThreadSafe(_: *const @This()) void {} - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!FChmod { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!FChmod { const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); @@ -1724,7 +1724,7 @@ pub const Arguments = struct { this.path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Arguments.StatFS { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Arguments.StatFS { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -1765,7 +1765,7 @@ pub const Arguments = struct { this.path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Stat { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Stat { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -1803,7 +1803,7 @@ pub const Arguments = struct { pub fn toThreadSafe(_: *@This()) void {} - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Fstat { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Fstat { const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); @@ -1848,7 +1848,7 @@ pub const Arguments = struct { this.new_path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Link { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Link { const old_path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("oldPath must be a string or TypedArray", .{}); }; @@ -1891,7 +1891,7 @@ pub const Arguments = struct { this.new_path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Symlink { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Symlink { const old_path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("target must be a string or TypedArray", .{}); }; @@ -1952,7 +1952,7 @@ pub const Arguments = struct { this.path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Readlink { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Readlink { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -1994,7 +1994,7 @@ pub const Arguments = struct { this.path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Realpath { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Realpath { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -2046,7 +2046,7 @@ pub const Arguments = struct { this.path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Unlink { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Unlink { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -2081,7 +2081,7 @@ pub const Arguments = struct { this.path.deinit(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!RmDir { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!RmDir { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -2209,7 +2209,7 @@ pub const Arguments = struct { this.prefix.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!MkdirTemp { + 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); }; @@ -2267,7 +2267,7 @@ pub const Arguments = struct { }; } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Readdir { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Readdir { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -2318,7 +2318,7 @@ pub const Arguments = struct { pub fn deinit(_: Close) void {} pub fn toThreadSafe(_: Close) void {} - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Close { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Close { const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); @@ -2345,7 +2345,7 @@ pub const Arguments = struct { this.path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Open { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Open { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -2405,7 +2405,7 @@ pub const Arguments = struct { _ = self; } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Futimes { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Futimes { const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); @@ -2477,7 +2477,7 @@ pub const Arguments = struct { self.buffer.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Write { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Write { const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); @@ -2578,7 +2578,7 @@ pub const Arguments = struct { this.buffer.buffer.value.unprotect(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Read { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Read { // About half of the normalization has already been done. The second half is done in the native code. // fs_binding.read(fd, buffer, offset, length, position) @@ -2719,7 +2719,7 @@ pub const Arguments = struct { self.path.toThreadSafe(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!ReadFile { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!ReadFile { const path = try PathOrFileDescriptor.fromJS(ctx, arguments, bun.default_allocator) orelse { return ctx.throwInvalidArguments("path must be a string or a file descriptor", .{}); }; @@ -2812,7 +2812,7 @@ pub const Arguments = struct { signal.unref(); } } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!WriteFile { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!WriteFile { const path = try PathOrFileDescriptor.fromJS(ctx, arguments, bun.default_allocator) orelse { return ctx.throwInvalidArguments("path must be a string or a file descriptor", .{}); }; @@ -2913,7 +2913,7 @@ pub const Arguments = struct { self.path.deinit(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!OpenDir { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!OpenDir { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -2969,7 +2969,7 @@ pub const Arguments = struct { } } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Exists { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Exists { return Exists{ .path = try PathLike.fromJS(ctx, arguments), }; @@ -2992,7 +2992,7 @@ pub const Arguments = struct { this.path.deinitAndUnprotect(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Access { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Access { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("path must be a string or TypedArray", .{}); }; @@ -3020,7 +3020,7 @@ pub const Arguments = struct { _ = self; } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!FdataSync { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!FdataSync { const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); @@ -3050,7 +3050,7 @@ pub const Arguments = struct { this.dest.deinitAndUnprotect(); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!CopyFile { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!CopyFile { const src = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("src must be a string or TypedArray", .{}); }; @@ -3095,7 +3095,7 @@ pub const Arguments = struct { } } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Cp { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Cp { const src = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("src must be a string or TypedArray", .{}); }; @@ -3170,7 +3170,7 @@ pub const Arguments = struct { pub fn deinit(_: Fsync) void {} pub fn toThreadSafe(_: *const @This()) void {} - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Fsync { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Fsync { const fd_value = arguments.nextEat() orelse JSC.JSValue.undefined; const fd = try bun.FD.fromJSValidated(fd_value, ctx) orelse { return throwInvalidFdError(ctx, fd_value); @@ -3248,7 +3248,7 @@ const Return = struct { pub const Read = struct { bytes_read: u52, - pub fn toJS(this: Read, _: JSC.C.JSContextRef) JSC.JSValue { + pub fn toJS(this: Read, _: *JSC.JSGlobalObject) JSC.JSValue { return JSC.JSValue.jsNumberFromUint64(this.bytes_read); } }; @@ -3282,7 +3282,7 @@ const Return = struct { }; // Excited for the issue that's like "cannot read file bigger than 2 GB" - pub fn toJS(this: *const WritePromise, globalObject: JSC.C.JSContextRef) JSC.C.JSValueRef { + pub fn toJS(this: *const WritePromise, globalObject: *JSC.JSGlobalObject) JSC.C.JSValueRef { defer if (!this.buffer_val.isEmptyOrUndefinedOrNull()) this.buffer_val.unprotect(); diff --git a/src/bun.js/node/node_fs_binding.zig b/src/bun.js/node/node_fs_binding.zig index e8e527e5eb..8d3a6c703c 100644 --- a/src/bun.js/node/node_fs_binding.zig +++ b/src/bun.js/node/node_fs_binding.zig @@ -96,7 +96,11 @@ fn callSync(comptime FunctionEnum: NodeFSFunctionEnum) NodeFSFunction { pub const NodeJSFS = struct { node_fs: JSC.Node.NodeFS = .{}, - pub usingnamespace JSC.Codegen.JSNodeJSFS; + pub const js = JSC.Codegen.JSNodeJSFS; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + pub const new = bun.TrivialNew(@This()); pub fn finalize(this: *JSC.Node.NodeJSFS) void { diff --git a/src/bun.js/node/node_fs_stat_watcher.zig b/src/bun.js/node/node_fs_stat_watcher.zig index 3e979b1207..cf87bacbcb 100644 --- a/src/bun.js/node/node_fs_stat_watcher.zig +++ b/src/bun.js/node/node_fs_stat_watcher.zig @@ -197,7 +197,10 @@ pub const StatWatcher = struct { last_stat: bun.Stat, last_jsvalue: JSC.Strong, - pub usingnamespace JSC.Codegen.JSStatWatcher; + pub const js = JSC.Codegen.JSStatWatcher; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub fn eventLoop(this: StatWatcher) *EventLoop { return this.ctx.eventLoop(); @@ -230,7 +233,7 @@ pub const StatWatcher = struct { bigint: bool, interval: i32, - global_this: JSC.C.JSContextRef, + global_this: *JSC.JSGlobalObject, pub fn fromJS(global: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Arguments { const path = try PathLike.fromJSWithAllocator(global, arguments, bun.default_allocator) orelse { @@ -390,7 +393,7 @@ pub const StatWatcher = struct { const vm = this.globalThis.bunVM(); - _ = StatWatcher.listenerGetCached(this.js_this).?.call( + _ = js.listenerGetCached(this.js_this).?.call( this.globalThis, .undefined, &[2]JSC.JSValue{ @@ -427,7 +430,7 @@ pub const StatWatcher = struct { const current_jsvalue = statToJSStats(this.globalThis, &this.last_stat, this.bigint); this.last_jsvalue.set(this.globalThis, current_jsvalue); - _ = StatWatcher.listenerGetCached(this.js_this).?.call( + _ = js.listenerGetCached(this.js_this).?.call( this.globalThis, .undefined, &[2]JSC.JSValue{ @@ -489,7 +492,7 @@ pub const StatWatcher = struct { const js_this = StatWatcher.toJS(this, this.globalThis); this.js_this = js_this; - StatWatcher.listenerSetCached(js_this, this.globalThis, args.listener); + js.listenerSetCached(js_this, this.globalThis, args.listener); InitialStatTask.createAndSchedule(this); return this; diff --git a/src/bun.js/node/node_fs_watcher.zig b/src/bun.js/node/node_fs_watcher.zig index 9bfc451873..e512dc3d02 100644 --- a/src/bun.js/node/node_fs_watcher.zig +++ b/src/bun.js/node/node_fs_watcher.zig @@ -19,7 +19,10 @@ const log = Output.scoped(.@"fs.watch", true); const PathWatcher = if (Environment.isWindows) @import("./win_watcher.zig") else @import("./path_watcher.zig"); pub const FSWatcher = struct { - pub usingnamespace JSC.Codegen.JSFSWatcher; + pub const js = JSC.Codegen.JSFSWatcher; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; ctx: *VirtualMachine, verbose: bool = false, @@ -333,14 +336,14 @@ pub const FSWatcher = struct { pub const Arguments = struct { path: PathLike, listener: JSC.JSValue, - global_this: JSC.C.JSContextRef, + global_this: *JSC.JSGlobalObject, signal: ?*JSC.AbortSignal, persistent: bool, recursive: bool, encoding: JSC.Node.Encoding, verbose: bool, - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!Arguments { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!Arguments { const path = try PathLike.fromJS(ctx, arguments) orelse { return ctx.throwInvalidArguments("filename must be a string or TypedArray", .{}); }; @@ -434,10 +437,10 @@ pub const FSWatcher = struct { _ = this.pending_activity_count.fetchAdd(1, .monotonic); } - const js_this = FSWatcher.toJS(this, this.globalThis); + const js_this = this.toJS(this.globalThis); js_this.ensureStillAlive(); this.js_this = js_this; - FSWatcher.listenerSetCached(js_this, this.globalThis, listener); + js.listenerSetCached(js_this, this.globalThis, listener); if (this.signal) |s| { // already aborted? @@ -473,7 +476,7 @@ pub const FSWatcher = struct { if (this.js_this != .zero) { const js_this = this.js_this; js_this.ensureStillAlive(); - if (FSWatcher.listenerGetCached(js_this)) |listener| { + if (js.listenerGetCached(js_this)) |listener| { listener.ensureStillAlive(); var args = [_]JSC.JSValue{ EventType.@"error".toJS(this.globalThis), @@ -493,7 +496,7 @@ pub const FSWatcher = struct { if (this.js_this != .zero) { const js_this = this.js_this; js_this.ensureStillAlive(); - if (FSWatcher.listenerGetCached(js_this)) |listener| { + if (js.listenerGetCached(js_this)) |listener| { listener.ensureStillAlive(); const globalObject = this.globalThis; var args = [_]JSC.JSValue{ @@ -511,7 +514,7 @@ pub const FSWatcher = struct { pub fn emitWithFilename(this: *FSWatcher, file_name: JSC.JSValue, comptime eventType: EventType) void { const js_this = this.js_this; if (js_this == .zero) return; - const listener = FSWatcher.listenerGetCached(js_this) orelse return; + const listener = js.listenerGetCached(js_this) orelse return; emitJS(listener, this.globalThis, file_name, eventType); } @@ -519,7 +522,7 @@ pub const FSWatcher = struct { bun.assert(event_type != .@"error"); const js_this = this.js_this; if (js_this == .zero) return; - const listener = FSWatcher.listenerGetCached(js_this) orelse return; + const listener = js.listenerGetCached(js_this) orelse return; const globalObject = this.globalThis; var filename: JSC.JSValue = .undefined; if (file_name.len > 0) { @@ -598,7 +601,7 @@ pub const FSWatcher = struct { this.detach(); if (js_this != .zero) { - if (FSWatcher.listenerGetCached(js_this)) |listener| { + if (FSWatcher.js.listenerGetCached(js_this)) |listener| { _ = this.refTask(); log("emit('close')", .{}); emitJS(listener, this.globalThis, .undefined, .close); diff --git a/src/bun.js/node/node_net_binding.zig b/src/bun.js/node/node_net_binding.zig index eb038a8511..9c7b01bb4f 100644 --- a/src/bun.js/node/node_net_binding.zig +++ b/src/bun.js/node/node_net_binding.zig @@ -81,7 +81,7 @@ pub fn createBinding(global: *JSC.JSGlobalObject) JSC.JSValue { const SocketAddress = bun.JSC.GeneratedClassesList.SocketAddress; const net = JSC.JSValue.createEmptyObjectWithNullPrototype(global); - net.put(global, "SocketAddress", SocketAddress.getConstructor(global)); + net.put(global, "SocketAddress", SocketAddress.js.getConstructor(global)); return net; } diff --git a/src/bun.js/node/node_zlib_binding.zig b/src/bun.js/node/node_zlib_binding.zig index 8e4ae02afe..f977ca6716 100644 --- a/src/bun.js/node/node_zlib_binding.zig +++ b/src/bun.js/node/node_zlib_binding.zig @@ -156,7 +156,7 @@ pub fn CompressionStream(comptime T: type) type { this.stream.updateWriteResult(&this.write_result.?[1], &this.write_result.?[0]); this_value.ensureStillAlive(); - const write_callback: JSC.JSValue = T.writeCallbackGetCached(this_value).?; + const write_callback: JSC.JSValue = T.js.writeCallbackGetCached(this_value).?; vm.eventLoop().runCallback(write_callback, global, this_value, &.{}); @@ -248,13 +248,13 @@ pub fn CompressionStream(comptime T: type) type { pub fn setOnError(_: *T, this_value: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) bool { if (value.isFunction()) { - T.errorCallbackSetCached(this_value, globalObject, value); + T.js.errorCallbackSetCached(this_value, globalObject, value); } return true; } pub fn getOnError(_: *T, this_value: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue { - return T.errorCallbackGetCached(this_value) orelse .undefined; + return T.js.errorCallbackGetCached(this_value) orelse .undefined; } /// returns true if no error was detected/emitted @@ -272,7 +272,8 @@ pub fn CompressionStream(comptime T: type) type { var code_str = bun.String.createFormat("{s}", .{std.mem.sliceTo(err_.code, 0) orelse ""}) catch bun.outOfMemory(); const code_value = code_str.transferToJS(globalThis); - const callback: JSC.JSValue = T.errorCallbackGetCached(this_value) orelse Output.panic("Assertion failure: cachedErrorCallback is null in node:zlib binding", .{}); + const callback: JSC.JSValue = T.js.errorCallbackGetCached(this_value) orelse + Output.panic("Assertion failure: cachedErrorCallback is null in node:zlib binding", .{}); _ = try callback.call(globalThis, this_value, &.{ msg_value, err_value, code_value }); this.write_in_progress = false; @@ -315,7 +316,11 @@ pub const SNativeZlib = struct { pub const ref = RefCount.ref; pub const deref = RefCount.deref; - pub usingnamespace JSC.Codegen.JSNativeZlib; + pub const js = JSC.Codegen.JSNativeZlib; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + pub usingnamespace CompressionStream(@This()); ref_count: RefCount, @@ -379,11 +384,11 @@ pub const SNativeZlib = struct { const dictionary = if (arguments[6].isUndefined()) null else arguments[6].asArrayBuffer(globalThis).?.byteSlice(); this.write_result = writeResult; - SNativeZlib.writeCallbackSetCached(this_value, globalThis, writeCallback); + js.writeCallbackSetCached(this_value, globalThis, writeCallback); // Keep the dictionary alive by keeping a reference to it in the JS object. if (dictionary != null) { - SNativeZlib.dictionarySetCached(this_value, globalThis, arguments[6]); + js.dictionarySetCached(this_value, globalThis, arguments[6]); } this.stream.init(level, windowBits, memLevel, strategy, dictionary); @@ -685,7 +690,11 @@ pub const SNativeBrotli = struct { pub const ref = RefCount.ref; pub const deref = RefCount.deref; - pub usingnamespace JSC.Codegen.JSNativeBrotli; + pub const js = JSC.Codegen.JSNativeBrotli; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + pub usingnamespace CompressionStream(@This()); ref_count: RefCount, @@ -751,7 +760,7 @@ pub const SNativeBrotli = struct { this.write_result = writeResult; - SNativeBrotli.writeCallbackSetCached(this_value, globalThis, writeCallback); + js.writeCallbackSetCached(this_value, globalThis, writeCallback); var err = this.stream.init(); if (err.isError()) { diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index bfd32981fe..cec29acf90 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -497,7 +497,7 @@ pub const StringOrBuffer = union(enum) { return result; } - pub fn toJS(this: *StringOrBuffer, ctx: JSC.C.JSContextRef) JSC.JSValue { + pub fn toJS(this: *StringOrBuffer, ctx: *JSC.JSGlobalObject) JSC.JSValue { return switch (this.*) { inline .threadsafe_string, .string => |*str| { return str.transferToJS(ctx); @@ -962,11 +962,11 @@ pub const PathLike = union(enum) { return sliceZWithForceCopy(this, buf, false); } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice) bun.JSError!?PathLike { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice) bun.JSError!?PathLike { return fromJSWithAllocator(ctx, arguments, bun.default_allocator); } - pub fn fromJSWithAllocator(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, allocator: std.mem.Allocator) bun.JSError!?PathLike { + pub fn fromJSWithAllocator(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice, allocator: std.mem.Allocator) bun.JSError!?PathLike { const arg = arguments.next() orelse return null; switch (arg.jsType()) { .Uint8Array, @@ -1063,7 +1063,7 @@ pub const PathLike = union(enum) { }; pub const Valid = struct { - pub fn pathSlice(zig_str: JSC.ZigString.Slice, ctx: JSC.C.JSContextRef) bun.JSError!void { + pub fn pathSlice(zig_str: JSC.ZigString.Slice, ctx: *JSC.JSGlobalObject) bun.JSError!void { switch (zig_str.len) { 0...bun.MAX_PATH_BYTES => return, else => { @@ -1075,7 +1075,7 @@ pub const Valid = struct { comptime unreachable; } - pub fn pathStringLength(len: usize, ctx: JSC.C.JSContextRef) bun.JSError!void { + pub fn pathStringLength(len: usize, ctx: *JSC.JSGlobalObject) bun.JSError!void { switch (len) { 0...bun.MAX_PATH_BYTES => return, else => { @@ -1087,11 +1087,11 @@ pub const Valid = struct { comptime unreachable; } - pub fn pathString(zig_str: JSC.ZigString, ctx: JSC.C.JSContextRef) bun.JSError!void { + pub fn pathString(zig_str: JSC.ZigString, ctx: *JSC.JSGlobalObject) bun.JSError!void { return pathStringLength(zig_str.len, ctx); } - pub fn pathBuffer(buffer: Buffer, ctx: JSC.C.JSContextRef) bun.JSError!void { + pub fn pathBuffer(buffer: Buffer, ctx: *JSC.JSGlobalObject) bun.JSError!void { const slice = buffer.slice(); switch (slice.len) { 0 => { @@ -1332,7 +1332,7 @@ fn timeLikeFromNow() TimeLike { }; } -pub fn modeFromJS(ctx: JSC.C.JSContextRef, value: JSC.JSValue) bun.JSError!?Mode { +pub fn modeFromJS(ctx: *JSC.JSGlobalObject, value: JSC.JSValue) bun.JSError!?Mode { const mode_int = if (value.isNumber()) brk: { const m = try validators.validateUint32(ctx, value, "mode", .{}, false); break :brk @as(Mode, @truncate(m)); @@ -1417,7 +1417,7 @@ pub const PathOrFileDescriptor = union(Tag) { } } - pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, allocator: std.mem.Allocator) bun.JSError!?JSC.Node.PathOrFileDescriptor { + pub fn fromJS(ctx: *JSC.JSGlobalObject, arguments: *ArgumentsSlice, allocator: std.mem.Allocator) bun.JSError!?JSC.Node.PathOrFileDescriptor { const first = arguments.next() orelse return null; if (try bun.FD.fromJSValidated(first, ctx)) |fd| { @@ -1522,7 +1522,7 @@ pub const FileSystemFlags = enum(c_int) { .{ "SA+", O.APPEND | O.CREAT | O.RDWR | O.SYNC }, }); - pub fn fromJS(ctx: JSC.C.JSContextRef, val: JSC.JSValue) bun.JSError!?FileSystemFlags { + pub fn fromJS(ctx: *JSC.JSGlobalObject, val: JSC.JSValue) bun.JSError!?FileSystemFlags { if (val.isNumber()) { if (!val.isInt32()) { return ctx.throwValue(ctx.ERR_OUT_OF_RANGE("The value of \"flags\" is out of range. It must be an integer. Received {d}", .{val.asNumber()}).toJS()); diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index 86cd055e9b..af35d08a8e 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -57,7 +57,11 @@ pub fn getMatcherFlags(comptime T: type, value: JSValue) Expect.Flags { /// https://jestjs.io/docs/expect // To support async tests, we need to track the test ID pub const Expect = struct { - pub usingnamespace JSC.Codegen.JSExpect; + pub const js = JSC.Codegen.JSExpect; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + flags: Flags = .{}, parent: ParentScope = .{ .global = {} }, custom_label: bun.String = bun.String.empty, @@ -188,7 +192,7 @@ pub const Expect = struct { } pub fn getValue(this: *Expect, globalThis: *JSGlobalObject, thisValue: JSValue, matcher_name: string, comptime matcher_params_fmt: string) bun.JSError!JSValue { - const value = Expect.capturedValueGetCached(thisValue) orelse { + const value = js.capturedValueGetCached(thisValue) orelse { return globalThis.throw("Internal error: the expect(value) was garbage collected but it should not have been!", .{}); }; value.ensureStillAlive(); @@ -389,7 +393,7 @@ pub const Expect = struct { }; const expect_js_value = expect.toJS(globalThis); expect_js_value.ensureStillAlive(); - Expect.capturedValueSetCached(expect_js_value, globalThis, value); + js.capturedValueSetCached(expect_js_value, globalThis, value); expect_js_value.ensureStillAlive(); expect.postMatch(globalThis); @@ -2197,7 +2201,7 @@ pub const Expect = struct { } if (value.isObject()) { if (ExpectAny.fromJSDirect(value)) |_| { - if (ExpectAny.constructorValueGetCached(value)) |innerConstructorValue| { + if (ExpectAny.js.constructorValueGetCached(value)) |innerConstructorValue| { break :brk innerConstructorValue; } } @@ -3857,7 +3861,7 @@ pub const Expect = struct { const countAsNum = count.toU32(); - const expect_string = Expect.capturedValueGetCached(thisValue) orelse { + const expect_string = js.capturedValueGetCached(thisValue) orelse { return globalThis.throw("Internal consistency error: the expect(value) was garbage collected but it should not have been!", .{}); }; @@ -3950,7 +3954,7 @@ pub const Expect = struct { return globalThis.throw("toSatisfy() argument must be a function", .{}); } - const value = Expect.capturedValueGetCached(thisValue) orelse { + const value = js.capturedValueGetCached(thisValue) orelse { return globalThis.throw("Internal consistency error: the expect(value) was garbage collected but it should not have been!", .{}); }; value.ensureStillAlive(); @@ -4682,7 +4686,7 @@ pub const Expect = struct { } var expect_proto = Expect__getPrototype(globalThis); - var expect_constructor = Expect.getConstructor(globalThis); + var expect_constructor = Expect.js.getConstructor(globalThis); var expect_static_proto = ExpectStatic__getPrototype(globalThis); // SAFETY: already checked that args[0] is an object @@ -4904,10 +4908,10 @@ pub const Expect = struct { }; // retrieve the captured expected value - var value = Expect.capturedValueGetCached(thisValue) orelse { + var value = js.capturedValueGetCached(thisValue) orelse { return globalThis.throw("Internal consistency error: failed to retrieve the captured value", .{}); }; - value = try Expect.processPromise(expect.custom_label, expect.flags, globalThis, value, matcher_name, matcher_params, false); + value = try processPromise(expect.custom_label, expect.flags, globalThis, value, matcher_name, matcher_params, false); value.ensureStillAlive(); incrementExpectCallCounter(); @@ -5009,7 +5013,10 @@ pub const Expect = struct { /// Static instance of expect, holding a set of flags. /// Returned for example when executing `expect.not` pub const ExpectStatic = struct { - pub usingnamespace JSC.Codegen.JSExpectStatic; + pub const js = JSC.Codegen.JSExpectStatic; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; flags: Expect.Flags = .{}, @@ -5102,7 +5109,10 @@ pub const ExpectStatic = struct { }; pub const ExpectAnything = struct { - pub usingnamespace JSC.Codegen.JSExpectAnything; + pub const js = JSC.Codegen.JSExpectAnything; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; flags: Expect.Flags = .{}, @@ -5127,7 +5137,10 @@ pub const ExpectAnything = struct { }; pub const ExpectStringMatching = struct { - pub usingnamespace JSC.Codegen.JSExpectStringMatching; + pub const js = JSC.Codegen.JSExpectStringMatching; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; flags: Expect.Flags = .{}, @@ -5138,7 +5151,7 @@ pub const ExpectStringMatching = struct { } pub fn call(globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { - const args = callFrame.arguments_old(1).slice(); + const args = callFrame.arguments(); if (args.len == 0 or (!args[0].isString() and !args[0].isRegExp())) { const fmt = "expect.stringContaining(string)\n\nExpected a string or regular expression\n"; @@ -5151,7 +5164,7 @@ pub const ExpectStringMatching = struct { string_matching.* = .{}; const string_matching_js_value = string_matching.toJS(globalThis); - ExpectStringMatching.testValueSetCached(string_matching_js_value, globalThis, test_value); + js.testValueSetCached(string_matching_js_value, globalThis, test_value); var vm = globalThis.bunVM(); vm.autoGarbageCollect(); @@ -5160,7 +5173,10 @@ pub const ExpectStringMatching = struct { }; pub const ExpectCloseTo = struct { - pub usingnamespace JSC.Codegen.JSExpectCloseTo; + pub const js = JSC.Codegen.JSExpectCloseTo; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; flags: Expect.Flags = .{}, @@ -5192,8 +5208,8 @@ pub const ExpectCloseTo = struct { const instance_jsvalue = instance.toJS(globalThis); number_value.ensureStillAlive(); precision_value.ensureStillAlive(); - ExpectCloseTo.numberValueSetCached(instance_jsvalue, globalThis, number_value); - ExpectCloseTo.digitsValueSetCached(instance_jsvalue, globalThis, precision_value); + ExpectCloseTo.js.numberValueSetCached(instance_jsvalue, globalThis, number_value); + ExpectCloseTo.js.digitsValueSetCached(instance_jsvalue, globalThis, precision_value); var vm = globalThis.bunVM(); vm.autoGarbageCollect(); @@ -5202,7 +5218,10 @@ pub const ExpectCloseTo = struct { }; pub const ExpectObjectContaining = struct { - pub usingnamespace JSC.Codegen.JSExpectObjectContaining; + pub const js = JSC.Codegen.JSExpectObjectContaining; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; flags: Expect.Flags = .{}, @@ -5226,7 +5245,7 @@ pub const ExpectObjectContaining = struct { instance.* = .{}; const instance_jsvalue = instance.toJS(globalThis); - ExpectObjectContaining.objectValueSetCached(instance_jsvalue, globalThis, object_value); + ExpectObjectContaining.js.objectValueSetCached(instance_jsvalue, globalThis, object_value); var vm = globalThis.bunVM(); vm.autoGarbageCollect(); @@ -5235,7 +5254,10 @@ pub const ExpectObjectContaining = struct { }; pub const ExpectStringContaining = struct { - pub usingnamespace JSC.Codegen.JSExpectStringContaining; + pub const js = JSC.Codegen.JSExpectStringContaining; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; flags: Expect.Flags = .{}, @@ -5259,7 +5281,7 @@ pub const ExpectStringContaining = struct { string_containing.* = .{}; const string_containing_js_value = string_containing.toJS(globalThis); - ExpectStringContaining.stringValueSetCached(string_containing_js_value, globalThis, string_value); + ExpectStringContaining.js.stringValueSetCached(string_containing_js_value, globalThis, string_value); var vm = globalThis.bunVM(); vm.autoGarbageCollect(); @@ -5268,7 +5290,10 @@ pub const ExpectStringContaining = struct { }; pub const ExpectAny = struct { - pub usingnamespace JSC.Codegen.JSExpectAny; + pub const js = JSC.Codegen.JSExpectAny; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; flags: Expect.Flags = .{}, @@ -5307,7 +5332,7 @@ pub const ExpectAny = struct { const any_js_value = any.toJS(globalThis); any_js_value.ensureStillAlive(); - ExpectAny.constructorValueSetCached(any_js_value, globalThis, constructor); + ExpectAny.js.constructorValueSetCached(any_js_value, globalThis, constructor); any_js_value.ensureStillAlive(); var vm = globalThis.bunVM(); @@ -5318,7 +5343,10 @@ pub const ExpectAny = struct { }; pub const ExpectArrayContaining = struct { - pub usingnamespace JSC.Codegen.JSExpectArrayContaining; + pub const js = JSC.Codegen.JSExpectArrayContaining; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; flags: Expect.Flags = .{}, @@ -5342,7 +5370,7 @@ pub const ExpectArrayContaining = struct { array_containing.* = .{}; const array_containing_js_value = array_containing.toJS(globalThis); - ExpectArrayContaining.arrayValueSetCached(array_containing_js_value, globalThis, array_value); + ExpectArrayContaining.js.arrayValueSetCached(array_containing_js_value, globalThis, array_value); var vm = globalThis.bunVM(); vm.autoGarbageCollect(); @@ -5355,7 +5383,10 @@ pub const ExpectArrayContaining = struct { /// Reference: `AsymmetricMatcher` in https://github.com/jestjs/jest/blob/main/packages/expect/src/types.ts /// (but only created for *custom* matchers, as built-ins have their own classes) pub const ExpectCustomAsymmetricMatcher = struct { - pub usingnamespace JSC.Codegen.JSExpectCustomAsymmetricMatcher; + pub const js = JSC.Codegen.JSExpectCustomAsymmetricMatcher; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; flags: Expect.Flags = .{}, @@ -5390,7 +5421,7 @@ pub const ExpectCustomAsymmetricMatcher = struct { instance.flags = flags; // store the user-provided matcher function into the instance - ExpectCustomAsymmetricMatcher.matcherFnSetCached(instance_jsvalue, globalThis, matcher_fn); + js.matcherFnSetCached(instance_jsvalue, globalThis, matcher_fn); // capture the args as a JS array saved in the instance, so the matcher can be executed later on with them const args = callFrame.arguments(); @@ -5398,7 +5429,7 @@ pub const ExpectCustomAsymmetricMatcher = struct { for (args, 0..) |arg, i| { array.putIndex(globalThis, @truncate(i), arg); } - ExpectCustomAsymmetricMatcher.capturedArgsSetCached(instance_jsvalue, globalThis, array); + js.capturedArgsSetCached(instance_jsvalue, globalThis, array); array.ensureStillAlive(); // return the same instance, now fully initialized including the captured args (previously it was incomplete) @@ -5408,7 +5439,7 @@ pub const ExpectCustomAsymmetricMatcher = struct { /// Function called by c++ function "matchAsymmetricMatcher" to execute the custom matcher against the provided leftValue pub fn execute(this: *ExpectCustomAsymmetricMatcher, thisValue: JSValue, globalThis: *JSGlobalObject, received: JSValue) callconv(.C) bool { // retrieve the user-provided matcher implementation function (the function passed to expect.extend({ ... })) - const matcher_fn: JSValue = ExpectCustomAsymmetricMatcher.matcherFnGetCached(thisValue) orelse { + const matcher_fn: JSValue = js.matcherFnGetCached(thisValue) orelse { globalThis.throw("Internal consistency error: the ExpectCustomAsymmetricMatcher(matcherFn) was garbage collected but it should not have been!", .{}) catch {}; return false; }; @@ -5423,7 +5454,7 @@ pub const ExpectCustomAsymmetricMatcher = struct { // retrieve the asymmetric matcher args // if null, it means the function has not yet been called to capture the args, which is a misuse of the matcher - const captured_args: JSValue = ExpectCustomAsymmetricMatcher.capturedArgsGetCached(thisValue) orelse { + const captured_args: JSValue = js.capturedArgsGetCached(thisValue) orelse { globalThis.throw("expect.{s} misused, it needs to be instantiated by calling it with 0 or more arguments", .{matcher_name}) catch {}; return false; }; @@ -5453,10 +5484,10 @@ pub const ExpectCustomAsymmetricMatcher = struct { /// Calls a custom implementation (if provided) to stringify this asymmetric matcher, and returns true if it was provided and it succeed pub fn customPrint(_: *ExpectCustomAsymmetricMatcher, thisValue: JSValue, globalThis: *JSGlobalObject, writer: anytype, comptime dontThrow: bool) !bool { - const matcher_fn: JSValue = ExpectCustomAsymmetricMatcher.matcherFnGetCached(thisValue) orelse return false; + const matcher_fn: JSValue = js.matcherFnGetCached(thisValue) orelse return false; if (matcher_fn.get_unsafe(globalThis, "toAsymmetricMatcher")) |fn_value| { if (fn_value.jsType().isFunction()) { - const captured_args: JSValue = ExpectCustomAsymmetricMatcher.capturedArgsGetCached(thisValue) orelse return false; + const captured_args: JSValue = js.capturedArgsGetCached(thisValue) orelse return false; var stack_fallback = std.heap.stackFallback(256, globalThis.allocator()); const args_len = captured_args.getLength(globalThis); var args = try std.ArrayList(JSValue).initCapacity(stack_fallback.get(), args_len); @@ -5499,7 +5530,10 @@ pub const ExpectCustomAsymmetricMatcher = struct { /// Reference: `MatcherContext` in https://github.com/jestjs/jest/blob/main/packages/expect/src/types.ts pub const ExpectMatcherContext = struct { - pub usingnamespace JSC.Codegen.JSExpectMatcherContext; + pub const js = JSC.Codegen.JSExpectMatcherContext; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; flags: Expect.Flags = .{}, @@ -5543,7 +5577,10 @@ pub const ExpectMatcherContext = struct { /// Reference: `MatcherUtils` in https://github.com/jestjs/jest/blob/main/packages/expect/src/types.ts pub const ExpectMatcherUtils = struct { - pub usingnamespace JSC.Codegen.JSExpectMatcherUtils; + pub const js = JSC.Codegen.JSExpectMatcherUtils; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; fn createSingleton(globalThis: *JSGlobalObject) callconv(.C) JSValue { var instance = globalThis.bunVM().allocator.create(ExpectMatcherUtils) catch { diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 533c3eebb3..9db12e28c0 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -16,7 +16,6 @@ const Expect = expect.Expect; const DiffFormatter = @import("./diff_format.zig").DiffFormatter; const JSC = bun.JSC; -const js = JSC.C; const logger = bun.logger; const Method = @import("../../http/method.zig").Method; @@ -403,7 +402,7 @@ pub const Jest = struct { module.put( globalObject, ZigString.static("expect"), - Expect.getConstructor(globalObject), + Expect.js.getConstructor(globalObject), ); createMockObjects(globalObject, module); @@ -458,7 +457,7 @@ pub const Jest = struct { module.put( globalObject, ZigString.static("expect"), - Expect.getConstructor(globalObject), + Expect.js.getConstructor(globalObject), ); const vi = JSValue.createEmptyObject(globalObject, 3); @@ -904,7 +903,7 @@ pub const DescribeScope = struct { } pub fn onDone( - ctx: js.JSContextRef, + ctx: *JSC.JSGlobalObject, callframe: *CallFrame, ) bun.JSError!JSValue { const function = callframe.callee(); diff --git a/src/bun.js/test/pretty_format.zig b/src/bun.js/test/pretty_format.zig index ae97bc5081..72249e8f70 100644 --- a/src/bun.js/test/pretty_format.zig +++ b/src/bun.js/test/pretty_format.zig @@ -2063,7 +2063,7 @@ pub const JestPrettyFormat = struct { writer.writeAll("Anything"); } } else if (value.as(expect.ExpectAny)) |matcher| { - const constructor_value = expect.ExpectAny.constructorValueGetCached(value) orelse return true; + const constructor_value = expect.ExpectAny.js.constructorValueGetCached(value) orelse return true; printAsymmetricMatcherPromisePrefix(matcher.flags, this, writer); if (matcher.flags.not) { @@ -2081,8 +2081,8 @@ pub const JestPrettyFormat = struct { this.addForNewLine(1); writer.writeAll(">"); } else if (value.as(expect.ExpectCloseTo)) |matcher| { - const number_value = expect.ExpectCloseTo.numberValueGetCached(value) orelse return true; - const digits_value = expect.ExpectCloseTo.digitsValueGetCached(value) orelse return true; + const number_value = expect.ExpectCloseTo.js.numberValueGetCached(value) orelse return true; + const digits_value = expect.ExpectCloseTo.js.digitsValueGetCached(value) orelse return true; const number = number_value.toInt32(); const digits = digits_value.toInt32(); @@ -2097,7 +2097,7 @@ pub const JestPrettyFormat = struct { } writer.print("{d} ({d} digit{s})", .{ number, digits, if (digits == 1) "" else "s" }); } else if (value.as(expect.ExpectObjectContaining)) |matcher| { - const object_value = expect.ExpectObjectContaining.objectValueGetCached(value) orelse return true; + const object_value = expect.ExpectObjectContaining.js.objectValueGetCached(value) orelse return true; printAsymmetricMatcherPromisePrefix(matcher.flags, this, writer); if (matcher.flags.not) { @@ -2109,7 +2109,7 @@ pub const JestPrettyFormat = struct { } this.printAs(.Object, @TypeOf(writer_), writer_, object_value, .Object, enable_ansi_colors) catch {}; // TODO: } else if (value.as(expect.ExpectStringContaining)) |matcher| { - const substring_value = expect.ExpectStringContaining.stringValueGetCached(value) orelse return true; + const substring_value = expect.ExpectStringContaining.js.stringValueGetCached(value) orelse return true; printAsymmetricMatcherPromisePrefix(matcher.flags, this, writer); if (matcher.flags.not) { @@ -2121,7 +2121,7 @@ pub const JestPrettyFormat = struct { } this.printAs(.String, @TypeOf(writer_), writer_, substring_value, .String, enable_ansi_colors) catch {}; // TODO: } else if (value.as(expect.ExpectStringMatching)) |matcher| { - const test_value = expect.ExpectStringMatching.testValueGetCached(value) orelse return true; + const test_value = expect.ExpectStringMatching.js.testValueGetCached(value) orelse return true; printAsymmetricMatcherPromisePrefix(matcher.flags, this, writer); if (matcher.flags.not) { @@ -2140,8 +2140,8 @@ pub const JestPrettyFormat = struct { const printed = instance.customPrint(value, this.globalThis, writer_, true) catch unreachable; if (!printed) { // default print (non-overridden by user) const flags = instance.flags; - const args_value = expect.ExpectCustomAsymmetricMatcher.capturedArgsGetCached(value) orelse return true; - const matcher_fn = expect.ExpectCustomAsymmetricMatcher.matcherFnGetCached(value) orelse return true; + const args_value = expect.ExpectCustomAsymmetricMatcher.js.capturedArgsGetCached(value) orelse return true; + const matcher_fn = expect.ExpectCustomAsymmetricMatcher.js.matcherFnGetCached(value) orelse return true; const matcher_name = matcher_fn.getName(this.globalThis); printAsymmetricMatcherPromisePrefix(flags, this, writer); diff --git a/src/bun.js/webcore.zig b/src/bun.js/webcore.zig index 81be0163df..c1d94eedb4 100644 --- a/src/bun.js/webcore.zig +++ b/src/bun.js/webcore.zig @@ -361,7 +361,13 @@ pub const Prompt = struct { }; pub const Crypto = struct { + pub const js = JSC.Codegen.JSCrypto; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + garbage: i32 = 0, + const BoringSSL = bun.BoringSSL.c; fn throwInvalidParameter(globalThis: *JSC.JSGlobalObject) bun.JSError { @@ -542,8 +548,6 @@ pub const Crypto = struct { return ptr.toJS(globalThis); } - pub usingnamespace JSC.Codegen.JSCrypto; - comptime { _ = CryptoObject__create; } diff --git a/src/bun.js/webcore/S3Client.zig b/src/bun.js/webcore/S3Client.zig index dc9d349c8f..be3231ecdc 100644 --- a/src/bun.js/webcore/S3Client.zig +++ b/src/bun.js/webcore/S3Client.zig @@ -88,7 +88,10 @@ pub fn writeFormatCredentials(credentials: *S3Credentials, options: bun.S3.Multi pub const S3Client = struct { const log = bun.Output.scoped(.S3Client, false); - pub usingnamespace JSC.Codegen.JSS3Client; + pub const js = JSC.Codegen.JSS3Client; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; pub const new = bun.TrivialNew(@This()); credentials: *S3Credentials, diff --git a/src/bun.js/webcore/S3Stat.zig b/src/bun.js/webcore/S3Stat.zig index 6c33ac785c..a1b189ca89 100644 --- a/src/bun.js/webcore/S3Stat.zig +++ b/src/bun.js/webcore/S3Stat.zig @@ -3,7 +3,11 @@ const JSC = bun.JSC; pub const S3Stat = struct { const log = bun.Output.scoped(.S3Stat, false); - pub usingnamespace JSC.Codegen.JSS3Stat; + pub const js = JSC.Codegen.JSS3Stat; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + pub const new = bun.TrivialNew(@This()); size: u64, diff --git a/src/bun.js/webcore/TextDecoder.zig b/src/bun.js/webcore/TextDecoder.zig index 6c9222e4d6..fb33bf4a45 100644 --- a/src/bun.js/webcore/TextDecoder.zig +++ b/src/bun.js/webcore/TextDecoder.zig @@ -16,7 +16,10 @@ ignore_bom: bool = false, fatal: bool = false, encoding: EncodingLabel = EncodingLabel.@"UTF-8", -pub usingnamespace JSC.Codegen.JSTextDecoder; +pub const js = JSC.Codegen.JSTextDecoder; +pub const toJS = js.toJS; +pub const fromJS = js.fromJS; +pub const fromJSDirect = js.fromJSDirect; pub const new = bun.TrivialNew(TextDecoder); diff --git a/src/bun.js/webcore/TextEncoderStreamEncoder.zig b/src/bun.js/webcore/TextEncoderStreamEncoder.zig index a921ff962e..e5cfd7e7cb 100644 --- a/src/bun.js/webcore/TextEncoderStreamEncoder.zig +++ b/src/bun.js/webcore/TextEncoderStreamEncoder.zig @@ -2,7 +2,11 @@ pending_lead_surrogate: ?u16 = null, const log = Output.scoped(.TextEncoderStreamEncoder, false); -pub usingnamespace JSC.Codegen.JSTextEncoderStreamEncoder; +pub const js = JSC.Codegen.JSTextEncoderStreamEncoder; +pub const toJS = js.toJS; +pub const fromJS = js.fromJS; +pub const fromJSDirect = js.fromJSDirect; + pub const new = bun.TrivialNew(TextEncoderStreamEncoder); pub fn finalize(this: *TextEncoderStreamEncoder) void { diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index c9b04722fd..2ee58ec11e 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -5,7 +5,6 @@ const MimeType = http.MimeType; const ZigURL = @import("../../url.zig").URL; const http = bun.http; const JSC = bun.JSC; -const js = JSC.C; const io = bun.io; const Method = @import("../../http/method.zig").Method; const FetchHeaders = JSC.FetchHeaders; @@ -58,7 +57,10 @@ pub const Blob = struct { const bloblog = Output.scoped(.Blob, false); pub const new = bun.TrivialNew(@This()); - pub usingnamespace JSC.Codegen.JSBlob; + pub const js = JSC.Codegen.JSBlob; + // NOTE: toJS is overridden + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; const rf = @import("blob/ReadFile.zig"); pub const ReadFile = rf.ReadFile; @@ -866,7 +868,7 @@ pub const Blob = struct { /// - doesn't exist and is created /// - exists and is truncated fn writeFileWithEmptySourceToDestination( - ctx: JSC.C.JSContextRef, + ctx: *JSC.JSGlobalObject, destination_blob: *Blob, options: WriteFileOptions, ) JSC.JSValue { @@ -1011,7 +1013,7 @@ pub const Blob = struct { } pub fn writeFileWithSourceDestination( - ctx: JSC.C.JSContextRef, + ctx: *JSC.JSGlobalObject, source_blob: *Blob, destination_blob: *Blob, options: WriteFileOptions, @@ -3891,7 +3893,7 @@ pub const Blob = struct { callframe: *JSC.CallFrame, ) bun.JSError!JSC.JSValue { const thisValue = callframe.this(); - if (Blob.streamGetCached(thisValue)) |cached| { + if (js.streamGetCached(thisValue)) |cached| { return cached; } var recommended_chunk_size: SizeType = 0; @@ -3917,7 +3919,7 @@ pub const Blob = struct { // in the case we have a file descriptor store, we want to de-duplicate // readable streams. in every other case we want `.stream()` to be it's // own stream. - Blob.streamSetCached(thisValue, globalThis, stream); + js.streamSetCached(thisValue, globalThis, stream); }, else => {}, }, @@ -4858,7 +4860,7 @@ pub const Blob = struct { if (value.isEmptyOrUndefinedOrNull()) { this.name.deref(); this.name = bun.String.dead; - Blob.nameSetCached(jsThis, globalThis, value); + js.nameSetCached(jsThis, globalThis, value); return true; } if (value.isString()) { @@ -4875,7 +4877,7 @@ pub const Blob = struct { return false; }; // We don't need to increment the reference count since tryFromJS already did it. - Blob.nameSetCached(jsThis, globalThis, value); + js.nameSetCached(jsThis, globalThis, value); old_name.deref(); return true; } @@ -5312,7 +5314,7 @@ pub const Blob = struct { return S3File.toJSUnchecked(globalObject, this); } - return Blob.toJSUnchecked(globalObject, this); + return js.toJSUnchecked(globalObject, this); } pub fn deinit(this: *Blob) void { diff --git a/src/bun.js/webcore/body.zig b/src/bun.js/webcore/body.zig index b48011f7da..40c077dea0 100644 --- a/src/bun.js/webcore/body.zig +++ b/src/bun.js/webcore/body.zig @@ -5,7 +5,6 @@ const MimeType = bun.http.MimeType; const ZigURL = @import("../../url.zig").URL; const HTTPClient = bun.http; const JSC = bun.JSC; -const js = JSC.C; const Method = @import("../../http/method.zig").Method; const FetchHeaders = JSC.FetchHeaders; @@ -144,7 +143,7 @@ pub const Body = struct { return true; } - if (T.bodyGetCached(this_value)) |body_value| { + if (T.js.bodyGetCached(this_value)) |body_value| { if (JSC.WebCore.ReadableStream.isDisturbedValue(body_value, globalObject)) { return true; } diff --git a/src/bun.js/webcore/encoding.zig b/src/bun.js/webcore/encoding.zig index 600b704fc4..136946deaa 100644 --- a/src/bun.js/webcore/encoding.zig +++ b/src/bun.js/webcore/encoding.zig @@ -5,7 +5,6 @@ const ZigURL = @import("../../url.zig").URL; const HTTPClient = bun.http; const JSC = bun.JSC; -const js = JSC.C; const Method = @import("../../http/method.zig").Method; diff --git a/src/bun.js/webcore/fetch.zig b/src/bun.js/webcore/fetch.zig index 187d05d6c8..d7e69e6e2f 100644 --- a/src/bun.js/webcore/fetch.zig +++ b/src/bun.js/webcore/fetch.zig @@ -1,7 +1,7 @@ const headers_string = "headers"; const method_string = "method"; -const JSType = js.JSType; +const JSType = JSC.C.JSType; pub const fetch_error_no_args = "fetch() expects a string but received no arguments."; pub const fetch_error_blank_url = "fetch() URL must not be a blank string."; @@ -1132,7 +1132,7 @@ pub const FetchTasklet = struct { pub fn onResolve(this: *FetchTasklet) JSValue { log("onResolve", .{}); const response = bun.new(Response, this.toResponse()); - const response_js = Response.makeMaybePooled(@as(js.JSContextRef, this.global_this), response); + const response_js = Response.makeMaybePooled(@as(*JSC.JSGlobalObject, this.global_this), response); response_js.ensureStillAlive(); this.response = JSC.Weak(FetchTasklet).create(response_js, this.global_this, .FetchResponse, this); this.native_response = response.ref(); @@ -2537,7 +2537,7 @@ pub fn Bun__fetch_( .init = .{ .method = .PUT, .status_code = 200 }, .url = bun.String.createAtomIfPossible(self.url.href), }); - const response_js = Response.makeMaybePooled(@as(js.JSContextRef, global), response); + const response_js = Response.makeMaybePooled(@as(*JSC.JSGlobalObject, global), response); response_js.ensureStillAlive(); self.promise.resolve(global, response_js); }, @@ -2559,7 +2559,7 @@ pub fn Bun__fetch_( }, .url = bun.String.createAtomIfPossible(self.url.href), }); - const response_js = Response.makeMaybePooled(@as(js.JSContextRef, global), response); + const response_js = Response.makeMaybePooled(@as(*JSC.JSGlobalObject, global), response); response_js.ensureStillAlive(); self.promise.resolve(global, response_js); }, @@ -2734,7 +2734,6 @@ fn setHeaders(headers: *?Headers, new_headers: []const picohttp.Header, allocato const std = @import("std"); const bun = @import("root").bun; const JSC = bun.JSC; -const js = JSC.C; const DataURL = @import("../../resolver/data_url.zig").DataURL; const string = bun.string; const strings = bun.strings; diff --git a/src/bun.js/webcore/request.zig b/src/bun.js/webcore/request.zig index fb97c4aad5..c207720bfa 100644 --- a/src/bun.js/webcore/request.zig +++ b/src/bun.js/webcore/request.zig @@ -5,7 +5,6 @@ const MimeType = bun.http.MimeType; const ZigURL = @import("../../url.zig").URL; const HTTPClient = bun.http; const JSC = bun.JSC; -const js = JSC.C; const Method = @import("../../http/method.zig").Method; const FetchHeaders = JSC.FetchHeaders; @@ -63,7 +62,11 @@ pub const Request = struct { internal_event_callback: InternalJSEventCallback = .{}, const RequestMixin = BodyMixin(@This()); - pub usingnamespace JSC.Codegen.JSRequest; + pub const js = JSC.Codegen.JSRequest; + // NOTE: toJS is overridden + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + pub const new = bun.TrivialNew(@This()); pub const getText = RequestMixin.getText; @@ -212,7 +215,7 @@ pub const Request = struct { pub fn toJS(this: *Request, globalObject: *JSGlobalObject) JSValue { this.calculateEstimatedByteSize(); - return Request.toJSUnchecked(globalObject, this); + return js.toJSUnchecked(globalObject, this); } extern "JS" fn Bun__getParamsIfBunRequest(this_value: JSValue) JSValue; @@ -827,10 +830,9 @@ pub const Request = struct { // value to point to the new readable stream // We must do this on both the original and cloned request // but especially the original request since it will have a stale .body value now. - Request.bodySetCached(js_wrapper, globalThis, readable.value); - + js.bodySetCached(js_wrapper, globalThis, readable.value); if (this.body.value.Locked.readable.get(globalThis)) |other_readable| { - Request.bodySetCached(this_value, globalThis, other_readable.value); + js.bodySetCached(this_value, globalThis, other_readable.value); } } } diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index 6f01aeccc5..df085ce77b 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -6,7 +6,6 @@ const ZigURL = @import("../../url.zig").URL; const http = bun.http; const FetchRedirect = http.FetchRedirect; const JSC = bun.JSC; -const js = JSC.C; const Method = @import("../../http/method.zig").Method; const FetchHeaders = JSC.FetchHeaders; @@ -59,7 +58,10 @@ const s3 = bun.S3; pub const Response = struct { const ResponseMixin = BodyMixin(@This()); - pub usingnamespace JSC.Codegen.JSResponse; + pub const js = JSC.Codegen.JSResponse; + // NOTE: toJS is overridden + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; body: Body, init: Init, @@ -102,7 +104,7 @@ pub const Response = struct { pub fn toJS(this: *Response, globalObject: *JSGlobalObject) JSValue { this.calculateEstimatedByteSize(); - return Response.toJSUnchecked(globalObject, this); + return js.toJSUnchecked(globalObject, this); } pub fn getBodyValue( @@ -330,9 +332,9 @@ pub const Response = struct { // value to point to the new readable stream // We must do this on both the original and cloned response // but especially the original response since it will have a stale .body value now. - Response.bodySetCached(js_wrapper, globalThis, readable.value); + js.bodySetCached(js_wrapper, globalThis, readable.value); if (this.body.value.Locked.readable.get(globalThis)) |other_readable| { - Response.bodySetCached(this_value, globalThis, other_readable.value); + js.bodySetCached(this_value, globalThis, other_readable.value); } } } diff --git a/src/codegen/generate-classes.ts b/src/codegen/generate-classes.ts index 2488dfce89..36a49f6e23 100644 --- a/src/codegen/generate-classes.ts +++ b/src/codegen/generate-classes.ts @@ -2329,7 +2329,12 @@ const ZIG_GENERATED_CLASSES_HEADER = ` /// - C++: ZigGeneratedClasses.h, ZigGeneratedClasses.cpp /// 4. For the Zig code to successfully compile: /// - Add it to generated_classes_list.zig -/// - pub usingnamespace JSC.Codegen.JSMyClassName; +/// - \`\`\` +/// pub const js = JSC.Codegen.JSMyClassName; +/// pub const toJS = js.toJS; +/// pub const fromJS = js.fromJS; +/// pub const fromJSDirect = js.fromJSDirect; +/// \`\`\` /// 5. bun run build /// const bun = @import("root").bun; diff --git a/src/js_ast.zig b/src/js_ast.zig index 11da3a4ae3..6498640158 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -1566,7 +1566,7 @@ pub const E = struct { pub const Boolean = struct { value: bool, - pub fn toJS(this: @This(), ctx: JSC.C.JSContextRef) JSC.C.JSValueRef { + pub fn toJS(this: @This(), ctx: *JSC.JSGlobalObject) JSC.C.JSValueRef { return JSC.C.JSValueMakeBoolean(ctx, this.value); } }; diff --git a/src/jsc.zig b/src/jsc.zig index 718f26fca8..9770f47ba9 100644 --- a/src/jsc.zig +++ b/src/jsc.zig @@ -101,12 +101,18 @@ pub const Subprocess = API.Bun.Subprocess; /// 1. `bun src/bun.js/scripts/generate-classes.ts` /// 2. Scan for **/*.classes.ts files in src/bun.js/src /// 3. Generate a JS wrapper for each class in: -/// - Zig: generated_classes.zig -/// - C++: ZigGeneratedClasses.h, ZigGeneratedClasses.cpp +/// - Zig: generated_classes.zig +/// - C++: ZigGeneratedClasses.h, ZigGeneratedClasses.cpp /// 4. For the Zig code to successfully compile: -/// - Add it to generated_classes_list.zig -/// - pub usingnamespace JSC.Codegen.JSMyClassName; -/// 5. make clean-bindings && make bindings -j10 +/// - Add it to generated_classes_list.zig +/// - Expose the generated methods: +/// ```zig +/// pub const js = JSC.Codegen.JSMyClassName; +/// pub const toJS = js.toJS; +/// pub const fromJS = js.fromJS; +/// pub const fromJSDirect = js.fromJSDirect; +/// ``` +/// 5. `bun run build` /// pub const Codegen = @import("ZigGeneratedClasses"); pub const GeneratedClassesList = @import("./bun.js/bindings/generated_classes_list.zig").Classes; diff --git a/src/shell/ParsedShellScript.zig b/src/shell/ParsedShellScript.zig index 4aeac11bb0..5ee016cee1 100644 --- a/src/shell/ParsedShellScript.zig +++ b/src/shell/ParsedShellScript.zig @@ -1,4 +1,7 @@ -pub usingnamespace JSC.Codegen.JSParsedShellScript; +pub const js = JSC.Codegen.JSParsedShellScript; +pub const toJS = js.toJS; +pub const fromJS = js.fromJS; +pub const fromJSDirect = js.fromJSDirect; args: ?*ShellArgs = null, /// allocated with arena in jsobjs diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index d6ae4a69bd..defd345fae 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -350,7 +350,11 @@ pub const ShellArgs = struct { /// This interpreter works by basically turning the AST into a state machine so /// that execution can be suspended and resumed to support async. pub const Interpreter = struct { - pub usingnamespace JSC.Codegen.JSShellInterpreter; + pub const js = JSC.Codegen.JSShellInterpreter; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + command_ctx: bun.CLI.Command.Context, event_loop: JSC.EventLoopHandle, /// This is the allocator used to allocate interpreter state @@ -665,8 +669,6 @@ pub const Interpreter = struct { } }; - pub usingnamespace JSC.Codegen.JSShellInterpreter; - const ThisInterpreter = @This(); const ShellErrorKind = error{ @@ -2031,11 +2033,11 @@ pub const Interpreter = struct { fn expandVarArgv(this: *const Expansion, original_int: u8) []const u8 { var int = original_int; switch (this.base.interpreter.event_loop) { - .js => |js| { + .js => |event_loop| { if (int == 0) return bun.selfExePath() catch ""; int -= 1; - const vm = js.virtual_machine; + const vm = event_loop.virtual_machine; if (vm.main.len > 0) { if (int == 0) return vm.main; int -= 1; diff --git a/src/sql/postgres.zig b/src/sql/postgres.zig index 4b1871b575..031d31ed00 100644 --- a/src/sql/postgres.zig +++ b/src/sql/postgres.zig @@ -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, diff --git a/src/sys.zig b/src/sys.zig index 08181c272a..57ab45c6a5 100644 --- a/src/sys.zig +++ b/src/sys.zig @@ -602,7 +602,7 @@ pub const Error = struct { return Error{ .errno = todo_errno, .syscall = .TODO }; } - pub fn toJS(this: Error, ctx: JSC.C.JSContextRef) JSC.C.JSObjectRef { + pub fn toJS(this: Error, ctx: *JSC.JSGlobalObject) JSC.C.JSObjectRef { return this.toSystemError().toErrorInstance(ctx).asObjectRef(); } diff --git a/src/valkey/js_valkey.zig b/src/valkey/js_valkey.zig index e7820b04aa..e7af53cf7b 100644 --- a/src/valkey/js_valkey.zig +++ b/src/valkey/js_valkey.zig @@ -20,7 +20,11 @@ pub const JSValkeyClient = struct { }, ref_count: RefCount, - pub usingnamespace JSC.Codegen.JSRedisClient; + pub const js = JSC.Codegen.JSRedisClient; + pub const toJS = js.toJS; + pub const fromJS = js.fromJS; + pub const fromJSDirect = js.fromJSDirect; + const RefCount = bun.ptr.RefCount(@This(), "ref_count", deinit, .{}); pub const ref = RefCount.ref; pub const deref = RefCount.deref; @@ -161,16 +165,16 @@ pub const JSValkeyClient = struct { // If already connected, resolve immediately if (this.client.status == .connected) { - return JSC.JSPromise.resolvedPromiseValue(globalObject, JSValkeyClient.helloGetCached(this_value) orelse .undefined); + return JSC.JSPromise.resolvedPromiseValue(globalObject, js.helloGetCached(this_value) orelse .undefined); } - if (JSValkeyClient.connectionPromiseGetCached(this_value)) |promise| { + if (js.connectionPromiseGetCached(this_value)) |promise| { return promise; } const promise_ptr = JSC.JSPromise.create(globalObject); const promise = promise_ptr.asValue(globalObject); - JSValkeyClient.connectionPromiseSetCached(this_value, globalObject, promise); + js.connectionPromiseSetCached(this_value, globalObject, promise); // If was manually closed, reset that flag this.client.flags.is_manually_closed = false; @@ -222,26 +226,26 @@ pub const JSValkeyClient = struct { } pub fn getOnConnect(_: *JSValkeyClient, thisValue: JSValue, _: *JSC.JSGlobalObject) JSValue { - if (JSValkeyClient.onconnectGetCached(thisValue)) |value| { + if (js.onconnectGetCached(thisValue)) |value| { return value; } return .undefined; } pub fn setOnConnect(_: *JSValkeyClient, thisValue: JSValue, globalObject: *JSC.JSGlobalObject, value: JSValue) bool { - JSValkeyClient.onconnectSetCached(thisValue, globalObject, value); + js.onconnectSetCached(thisValue, globalObject, value); return true; } pub fn getOnClose(_: *JSValkeyClient, thisValue: JSValue, _: *JSC.JSGlobalObject) JSValue { - if (JSValkeyClient.oncloseGetCached(thisValue)) |value| { + if (js.oncloseGetCached(thisValue)) |value| { return value; } return .undefined; } pub fn setOnClose(_: *JSValkeyClient, thisValue: JSValue, globalObject: *JSC.JSGlobalObject, value: JSValue) bool { - JSValkeyClient.oncloseSetCached(thisValue, globalObject, value); + js.oncloseSetCached(thisValue, globalObject, value); return true; } @@ -405,16 +409,16 @@ pub const JSValkeyClient = struct { if (this.this_value.tryGet()) |this_value| { const hello_value = value.toJS(globalObject) catch .undefined; - JSValkeyClient.helloSetCached(this_value, globalObject, hello_value); + js.helloSetCached(this_value, globalObject, hello_value); // Call onConnect callback if defined by the user - if (JSValkeyClient.onconnectGetCached(this_value)) |on_connect| { + if (js.onconnectGetCached(this_value)) |on_connect| { const js_value = this_value; js_value.ensureStillAlive(); globalObject.queueMicrotask(on_connect, &[_]JSValue{ js_value, hello_value }); } - if (JSValkeyClient.connectionPromiseGetCached(this_value)) |promise| { - JSValkeyClient.connectionPromiseSetCached(this_value, globalObject, .zero); + if (js.connectionPromiseGetCached(this_value)) |promise| { + js.connectionPromiseSetCached(this_value, globalObject, .zero); promise.asPromise().?.resolve(globalObject, hello_value); } } @@ -455,14 +459,14 @@ pub const JSValkeyClient = struct { defer loop.exit(); if (this_jsvalue != .undefined) { - if (JSValkeyClient.connectionPromiseGetCached(this_jsvalue)) |promise| { - JSValkeyClient.connectionPromiseSetCached(this_jsvalue, globalObject, .zero); + if (js.connectionPromiseGetCached(this_jsvalue)) |promise| { + js.connectionPromiseSetCached(this_jsvalue, globalObject, .zero); promise.asPromise().?.reject(globalObject, error_value); } } // Call onClose callback if it exists - if (JSValkeyClient.oncloseGetCached(this_jsvalue)) |on_close| { + if (js.oncloseGetCached(this_jsvalue)) |on_close| { _ = on_close.call( globalObject, this_jsvalue, @@ -483,7 +487,7 @@ pub const JSValkeyClient = struct { pub fn failWithJSValue(this: *JSValkeyClient, value: JSValue) void { const this_value = this.this_value.tryGet() orelse return; const globalObject = this.globalObject; - if (JSValkeyClient.oncloseGetCached(this_value)) |on_close| { + if (js.oncloseGetCached(this_value)) |on_close| { const loop = this.client.vm.eventLoop(); loop.enter(); defer loop.exit(); diff --git a/test/internal/ban-words.test.ts b/test/internal/ban-words.test.ts index 13efd3e0c9..22760d897e 100644 --- a/test/internal/ban-words.test.ts +++ b/test/internal/ban-words.test.ts @@ -30,8 +30,7 @@ const words: Record "!= alloc.ptr": { reason: "The std.mem.Allocator context pointer can be undefined, which makes this comparison undefined behavior" }, [String.raw`: [a-zA-Z0-9_\.\*\?\[\]\(\)]+ = undefined,`]: { reason: "Do not default a struct field to undefined", limit: 242, regex: true }, - - "usingnamespace": { reason: "Zig deprecates this, and will not support it in incremental compilation.", limit: 370 }, + "usingnamespace": { reason: "Zig deprecates this, and will not support it in incremental compilation.", limit: 310 }, "std.fs.Dir": { reason: "Prefer bun.sys + bun.FD instead of std.fs", limit: 180 }, "std.fs.cwd": { reason: "Prefer bun.FD.cwd()", limit: 103 },