diff options
Diffstat (limited to 'src/bun.js')
51 files changed, 4776 insertions, 2065 deletions
diff --git a/src/bun.js/api/FFI.h b/src/bun.js/api/FFI.h index c218dc69a..8d450b65e 100644 --- a/src/bun.js/api/FFI.h +++ b/src/bun.js/api/FFI.h @@ -101,6 +101,7 @@ typedef void* JSContext; #ifdef IS_CALLBACK +void* callback_ctx; ZIG_REPR_TYPE FFI_Callback_call(void* ctx, size_t argCount, ZIG_REPR_TYPE* args); // We wrap static EncodedJSValue _FFI_Callback_call(void* ctx, size_t argCount, ZIG_REPR_TYPE* args) __attribute__((__always_inline__)); diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig index eb235da2f..ee2763d92 100644 --- a/src/bun.js/api/bun.zig +++ b/src/bun.js/api/bun.zig @@ -95,7 +95,7 @@ pub fn onImportCSS( ) void { if (!css_imports_buf_loaded) { css_imports_buf = std.ArrayList(u8).initCapacity( - VirtualMachine.vm.allocator, + VirtualMachine.get().allocator, import_record.path.text.len, ) catch unreachable; css_imports_buf_loaded = true; @@ -272,7 +272,7 @@ pub fn inspect( // // when it's a big thing, we will manage it // { // writer.context.flush() catch {}; - // var slice = writer.context.context.toOwnedSlice(); + // var slice =try writer.context.context.toOwnedSlice(); // var zig_str = ZigString.init(slice).withEncoding(); // if (!zig_str.isUTF8()) { @@ -310,7 +310,7 @@ pub fn registerMacro( return js.JSValueMakeUndefined(ctx); } - var get_or_put_result = VirtualMachine.vm.macros.getOrPut(id) catch unreachable; + var get_or_put_result = VirtualMachine.get().macros.getOrPut(id) catch unreachable; if (get_or_put_result.found_existing) { js.JSValueUnprotect(ctx, get_or_put_result.value_ptr.*); } @@ -328,7 +328,7 @@ pub fn getCWD( _: js.JSStringRef, _: js.ExceptionRef, ) js.JSValueRef { - return ZigString.init(VirtualMachine.vm.bundler.fs.top_level_dir).toValue(ctx.ptr()).asRef(); + return ZigString.init(VirtualMachine.get().bundler.fs.top_level_dir).toValue(ctx.ptr()).asRef(); } pub fn getOrigin( @@ -338,7 +338,7 @@ pub fn getOrigin( _: js.JSStringRef, _: js.ExceptionRef, ) js.JSValueRef { - return ZigString.init(VirtualMachine.vm.origin.origin).toValue(ctx.ptr()).asRef(); + return ZigString.init(VirtualMachine.get().origin.origin).toValue(ctx.ptr()).asRef(); } pub fn getStdin( @@ -350,7 +350,7 @@ pub fn getStdin( ) js.JSValueRef { var existing = ctx.ptr().getCachedObject(ZigString.static("BunSTDIN")); if (existing.isEmpty()) { - var rare_data = JSC.VirtualMachine.vm.rareData(); + var rare_data = JSC.VirtualMachine.get().rareData(); var store = rare_data.stdin(); var blob = bun.default_allocator.create(JSC.WebCore.Blob) catch unreachable; blob.* = JSC.WebCore.Blob.initWithStore(store, ctx.ptr()); @@ -373,7 +373,7 @@ pub fn getStderr( ) js.JSValueRef { var existing = ctx.ptr().getCachedObject(ZigString.static("BunSTDERR")); if (existing.isEmpty()) { - var rare_data = JSC.VirtualMachine.vm.rareData(); + var rare_data = JSC.VirtualMachine.get().rareData(); var store = rare_data.stderr(); var blob = bun.default_allocator.create(JSC.WebCore.Blob) catch unreachable; blob.* = JSC.WebCore.Blob.initWithStore(store, ctx.ptr()); @@ -396,7 +396,7 @@ pub fn getStdout( ) js.JSValueRef { var existing = ctx.ptr().getCachedObject(ZigString.static("BunSTDOUT")); if (existing.isEmpty()) { - var rare_data = JSC.VirtualMachine.vm.rareData(); + var rare_data = JSC.VirtualMachine.get().rareData(); var store = rare_data.stdout(); var blob = bun.default_allocator.create(JSC.WebCore.Blob) catch unreachable; blob.* = JSC.WebCore.Blob.initWithStore(store, ctx.ptr()); @@ -426,7 +426,7 @@ pub fn getMain( _: js.JSStringRef, _: js.ExceptionRef, ) js.JSValueRef { - return ZigString.init(VirtualMachine.vm.main).toValue(ctx.ptr()).asRef(); + return ZigString.init(VirtualMachine.get().main).toValue(ctx.ptr()).asRef(); } pub fn getAssetPrefix( @@ -436,7 +436,7 @@ pub fn getAssetPrefix( _: js.JSStringRef, _: js.ExceptionRef, ) js.JSValueRef { - return ZigString.init(VirtualMachine.vm.bundler.options.routes.asset_prefix_path).toValue(ctx.ptr()).asRef(); + return ZigString.init(VirtualMachine.get().bundler.options.routes.asset_prefix_path).toValue(ctx.ptr()).asRef(); } pub fn getArgv( @@ -468,11 +468,11 @@ pub fn getRoutesDir( _: js.JSStringRef, _: js.ExceptionRef, ) js.JSValueRef { - if (!VirtualMachine.vm.bundler.options.routes.routes_enabled or VirtualMachine.vm.bundler.options.routes.dir.len == 0) { + if (!VirtualMachine.get().bundler.options.routes.routes_enabled or VirtualMachine.get().bundler.options.routes.dir.len == 0) { return js.JSValueMakeUndefined(ctx); } - return ZigString.init(VirtualMachine.vm.bundler.options.routes.dir).toValue(ctx.ptr()).asRef(); + return ZigString.init(VirtualMachine.get().bundler.options.routes.dir).toValue(ctx.ptr()).asRef(); } pub fn getFilePath(ctx: js.JSContextRef, arguments: []const js.JSValueRef, buf: []u8, exception: js.ExceptionRef) ?string { @@ -495,7 +495,7 @@ pub fn getFilePath(ctx: js.JSContextRef, arguments: []const js.JSValueRef, buf: var parts = [_]string{out_slice}; // This does the equivalent of Node's path.normalize(path.join(cwd, out_slice)) - var res = VirtualMachine.vm.bundler.fs.absBuf(&parts, buf); + var res = VirtualMachine.get().bundler.fs.absBuf(&parts, buf); return res; } else if (js.JSValueIsArray(ctx, value)) { @@ -536,7 +536,7 @@ pub fn getFilePath(ctx: js.JSContextRef, arguments: []const js.JSValueRef, buf: return null; } - return VirtualMachine.vm.bundler.fs.absBuf(temp_strings_list[0..temp_strings_list_len], buf); + return VirtualMachine.get().bundler.fs.absBuf(temp_strings_list[0..temp_strings_list_len], buf); } else { JSError(getAllocator(ctx), "Expected a file path as a string or an array of strings to be part of a file path.", .{}, ctx, exception); return null; @@ -606,8 +606,8 @@ pub fn readFileAsStringCallback( return js.JSValueMakeUndefined(ctx); } - var contents_buf = VirtualMachine.vm.allocator.alloc(u8, stat.size + 2) catch unreachable; // OOM - defer VirtualMachine.vm.allocator.free(contents_buf); + var contents_buf = VirtualMachine.get().allocator.alloc(u8, stat.size + 2) catch unreachable; // OOM + defer VirtualMachine.get().allocator.free(contents_buf); const contents_len = file.readAll(contents_buf) catch |err| { JSError(getAllocator(ctx), "{s} reading file (\"{s}\")", .{ @errorName(err), path }, ctx, exception); return js.JSValueMakeUndefined(ctx); @@ -628,37 +628,37 @@ pub fn readFileAsBytesCallback( exception: js.ExceptionRef, ) js.JSValueRef { const path = buf_z.ptr[0..buf_z.len]; + const allocator = VirtualMachine.get().allocator; var file = std.fs.cwd().openFileZ(buf_z, .{ .mode = .read_only }) catch |err| { - JSError(getAllocator(ctx), "Opening file {s} for path: \"{s}\"", .{ @errorName(err), path }, ctx, exception); + JSError(allocator, "Opening file {s} for path: \"{s}\"", .{ @errorName(err), path }, ctx, exception); return js.JSValueMakeUndefined(ctx); }; defer file.close(); const stat = file.stat() catch |err| { - JSError(getAllocator(ctx), "Getting file size {s} for \"{s}\"", .{ @errorName(err), path }, ctx, exception); + JSError(allocator, "Getting file size {s} for \"{s}\"", .{ @errorName(err), path }, ctx, exception); return js.JSValueMakeUndefined(ctx); }; if (stat.kind != .File) { - JSError(getAllocator(ctx), "Can't read a {s} as a string (\"{s}\")", .{ @tagName(stat.kind), path }, ctx, exception); + JSError(allocator, "Can't read a {s} as a string (\"{s}\")", .{ @tagName(stat.kind), path }, ctx, exception); return js.JSValueMakeUndefined(ctx); } - var contents_buf = VirtualMachine.vm.allocator.alloc(u8, stat.size + 2) catch unreachable; // OOM - errdefer VirtualMachine.vm.allocator.free(contents_buf); + var contents_buf = allocator.alloc(u8, stat.size + 2) catch unreachable; // OOM const contents_len = file.readAll(contents_buf) catch |err| { - JSError(getAllocator(ctx), "{s} reading file (\"{s}\")", .{ @errorName(err), path }, ctx, exception); + JSError(allocator, "{s} reading file (\"{s}\")", .{ @errorName(err), path }, ctx, exception); return js.JSValueMakeUndefined(ctx); }; contents_buf[contents_len] = 0; - var marked_array_buffer = VirtualMachine.vm.allocator.create(MarkedArrayBuffer) catch unreachable; + var marked_array_buffer = allocator.create(MarkedArrayBuffer) catch unreachable; marked_array_buffer.* = MarkedArrayBuffer.fromBytes( contents_buf[0..contents_len], - VirtualMachine.vm.allocator, + allocator, .Uint8Array, ); @@ -673,12 +673,12 @@ pub fn getRouteFiles( _: []const js.JSValueRef, _: js.ExceptionRef, ) js.JSValueRef { - if (VirtualMachine.vm.bundler.router == null) return js.JSObjectMakeArray(ctx, 0, null, null); + if (VirtualMachine.get().bundler.router == null) return js.JSObjectMakeArray(ctx, 0, null, null); - const router = &VirtualMachine.vm.bundler.router.?; + const router = &VirtualMachine.get().bundler.router.?; const list = router.getPublicPaths() catch unreachable; - for (routes_list_strings[0..@minimum(list.len, routes_list_strings.len)]) |_, i| { + for (routes_list_strings[0..@min(list.len, routes_list_strings.len)]) |_, i| { routes_list_strings[i] = ZigString.init(list[i]); } @@ -694,12 +694,12 @@ pub fn getRouteNames( _: []const js.JSValueRef, _: js.ExceptionRef, ) js.JSValueRef { - if (VirtualMachine.vm.bundler.router == null) return js.JSObjectMakeArray(ctx, 0, null, null); + if (VirtualMachine.get().bundler.router == null) return js.JSObjectMakeArray(ctx, 0, null, null); - const router = &VirtualMachine.vm.bundler.router.?; + const router = &VirtualMachine.get().bundler.router.?; const list = router.getNames() catch unreachable; - for (routes_list_strings[0..@minimum(list.len, routes_list_strings.len)]) |_, i| { + for (routes_list_strings[0..@min(list.len, routes_list_strings.len)]) |_, i| { routes_list_strings[i] = ZigString.init(list[i]); } @@ -716,7 +716,7 @@ pub fn openInEditor( args: []const js.JSValueRef, exception: js.ExceptionRef, ) js.JSValueRef { - var edit = &VirtualMachine.vm.rareData().editor_context; + var edit = &VirtualMachine.get().rareData().editor_context; var arguments = JSC.Node.ArgumentsSlice.from(ctx.bunVM(), args); defer arguments.deinit(); @@ -738,7 +738,7 @@ pub fn openInEditor( if (!strings.eqlLong(prev_name, sliced.slice(), true)) { var prev = edit.*; edit.name = sliced.slice(); - edit.detectEditor(VirtualMachine.vm.bundler.env); + edit.detectEditor(VirtualMachine.get().bundler.env); editor_choice = edit.editor; if (editor_choice == null) { edit.* = prev; @@ -762,7 +762,7 @@ pub fn openInEditor( } const editor = editor_choice orelse edit.editor orelse brk: { - edit.autoDetectEditor(VirtualMachine.vm.bundler.env); + edit.autoDetectEditor(VirtualMachine.get().bundler.env); if (edit.editor == null) { JSC.JSError(bun.default_allocator, "Failed to auto-detect editor", .{}, ctx, exception); return null; @@ -819,14 +819,14 @@ pub fn readFileAsString( } pub fn getPublicPath(to: string, origin: URL, comptime Writer: type, writer: Writer) void { - return getPublicPathWithAssetPrefix(to, VirtualMachine.vm.bundler.fs.top_level_dir, origin, VirtualMachine.vm.bundler.options.routes.asset_prefix_path, comptime Writer, writer); + return getPublicPathWithAssetPrefix(to, VirtualMachine.get().bundler.fs.top_level_dir, origin, VirtualMachine.get().bundler.options.routes.asset_prefix_path, comptime Writer, writer); } pub fn getPublicPathWithAssetPrefix(to: string, dir: string, origin: URL, asset_prefix: string, comptime Writer: type, writer: Writer) void { const relative_path = if (strings.hasPrefix(to, dir)) strings.withoutTrailingSlash(to[dir.len..]) else - VirtualMachine.vm.bundler.fs.relative(dir, to); + VirtualMachine.get().bundler.fs.relative(dir, to); if (origin.isAbsolute()) { if (strings.hasPrefix(relative_path, "..") or strings.hasPrefix(relative_path, "./")) { writer.writeAll(origin.origin) catch return; @@ -834,7 +834,7 @@ pub fn getPublicPathWithAssetPrefix(to: string, dir: string, origin: URL, asset_ if (std.fs.path.isAbsolute(to)) { writer.writeAll(to) catch return; } else { - writer.writeAll(VirtualMachine.vm.bundler.fs.abs(&[_]string{to})) catch return; + writer.writeAll(VirtualMachine.get().bundler.fs.abs(&[_]string{to})) catch return; } } else { origin.joinWrite( @@ -875,10 +875,10 @@ pub fn createNodeFS( _: []const js.JSValueRef, _: js.ExceptionRef, ) js.JSValueRef { - return Node.NodeFSBindings.make( - ctx, - VirtualMachine.vm.nodeFS(), - ); + var module = ctx.allocator().create(JSC.Node.NodeJSFS) catch unreachable; + module.* = .{}; + + return module.toJS(ctx).asObjectRef(); } pub fn generateHeapSnapshot( @@ -1076,7 +1076,7 @@ pub fn getPublicPathJS( var stream = std.io.fixedBufferStream(&public_path_temp_str); var writer = stream.writer(); - getPublicPath(to, VirtualMachine.vm.origin, @TypeOf(&writer), &writer); + getPublicPath(to, VirtualMachine.get().origin, @TypeOf(&writer), &writer); return ZigString.init(stream.buffer[0..stream.pos]).toValueGC(ctx.ptr()).asObjectRef(); } @@ -1089,131 +1089,130 @@ pub const Class = NewClass( }, .{ .match = .{ - .rfn = Router.deprecatedBunGlobalMatch, + .rfn = &Router.deprecatedBunGlobalMatch, }, .sleepSync = .{ - .rfn = sleepSync, + .rfn = &sleepSync, }, .fetch = .{ - .rfn = Fetch.call, + .rfn = &Fetch.call, }, .getImportedStyles = .{ - .rfn = Bun.getImportedStyles, + .rfn = &Bun.getImportedStyles, }, .inspect = .{ - .rfn = Bun.inspect, + .rfn = &Bun.inspect, }, .getRouteFiles = .{ - .rfn = Bun.getRouteFiles, + .rfn = &Bun.getRouteFiles, }, ._Os = .{ - .rfn = Bun.newOs, + .rfn = &Bun.newOs, }, ._Path = .{ - .rfn = Bun.newPath, + .rfn = &Bun.newPath, }, .getRouteNames = .{ - .rfn = Bun.getRouteNames, + .rfn = &Bun.getRouteNames, }, .readFile = .{ - .rfn = Bun.readFileAsString, + .rfn = &Bun.readFileAsString, }, .resolveSync = .{ - .rfn = Bun.resolveSync, + .rfn = &Bun.resolveSync, }, .resolve = .{ - .rfn = Bun.resolve, + .rfn = &Bun.resolve, }, .readFileBytes = .{ - .rfn = Bun.readFileAsBytes, + .rfn = &Bun.readFileAsBytes, }, .getPublicPath = .{ - .rfn = Bun.getPublicPathJS, + .rfn = &Bun.getPublicPathJS, }, .registerMacro = .{ - .rfn = Bun.registerMacro, + .rfn = &Bun.registerMacro, .enumerable = false, }, .fs = .{ - .rfn = Bun.createNodeFS, + .rfn = &Bun.createNodeFS, .enumerable = false, }, .jest = .{ - .rfn = @import("../test/jest.zig").Jest.call, + .rfn = &@import("../test/jest.zig").Jest.call, .enumerable = false, }, .indexOfLine = .{ - .rfn = Bun.indexOfLine, - .enumerable = false, + .rfn = &Bun.indexOfLine, }, .gc = .{ - .rfn = Bun.runGC, + .rfn = &Bun.runGC, }, .allocUnsafe = .{ - .rfn = Bun.allocUnsafe, + .rfn = &Bun.allocUnsafe, }, .mmap = .{ - .rfn = Bun.mmapFile, + .rfn = &Bun.mmapFile, }, .generateHeapSnapshot = .{ - .rfn = Bun.generateHeapSnapshot, + .rfn = &Bun.generateHeapSnapshot, }, .shrink = .{ - .rfn = Bun.shrink, + .rfn = &Bun.shrink, }, .openInEditor = .{ - .rfn = Bun.openInEditor, + .rfn = &Bun.openInEditor, }, .readAllStdinSync = .{ - .rfn = Bun.readAllStdinSync, + .rfn = &Bun.readAllStdinSync, }, .serve = .{ - .rfn = Bun.serve, + .rfn = &Bun.serve, }, .file = .{ - .rfn = JSC.WebCore.Blob.constructFile, + .rfn = &JSC.WebCore.Blob.constructFile, }, .write = .{ - .rfn = JSC.WebCore.Blob.writeFile, + .rfn = &JSC.WebCore.Blob.writeFile, }, .sha = .{ - .rfn = JSC.wrapWithHasContainer(Crypto.SHA512_256, "hash_", false, false, true), + .rfn = &JSC.wrapWithHasContainer(Crypto.SHA512_256, "hash_", false, false, true), }, .nanoseconds = .{ - .rfn = nanoseconds, + .rfn = &nanoseconds, }, .DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump = .{ - .rfn = dump_mimalloc, + .rfn = &dump_mimalloc, }, .gzipSync = .{ - .rfn = JSC.wrapWithHasContainer(JSZlib, "gzipSync", false, false, true), + .rfn = &JSC.wrapWithHasContainer(JSZlib, "gzipSync", false, false, true), }, .deflateSync = .{ - .rfn = JSC.wrapWithHasContainer(JSZlib, "deflateSync", false, false, true), + .rfn = &JSC.wrapWithHasContainer(JSZlib, "deflateSync", false, false, true), }, .gunzipSync = .{ - .rfn = JSC.wrapWithHasContainer(JSZlib, "gunzipSync", false, false, true), + .rfn = &JSC.wrapWithHasContainer(JSZlib, "gunzipSync", false, false, true), }, .inflateSync = .{ - .rfn = JSC.wrapWithHasContainer(JSZlib, "inflateSync", false, false, true), + .rfn = &JSC.wrapWithHasContainer(JSZlib, "inflateSync", false, false, true), }, .which = .{ - .rfn = which, + .rfn = &which, }, .spawn = .{ - .rfn = JSC.wrapWithHasContainer(JSC.Subprocess, "spawn", false, false, false), + .rfn = &JSC.wrapWithHasContainer(JSC.Subprocess, "spawn", false, false, false), }, .spawnSync = .{ - .rfn = JSC.wrapWithHasContainer(JSC.Subprocess, "spawnSync", false, false, false), + .rfn = &JSC.wrapWithHasContainer(JSC.Subprocess, "spawnSync", false, false, false), }, .listen = .{ - .rfn = JSC.wrapWithHasContainer(JSC.API.Listener, "listen", false, false, false), + .rfn = &JSC.wrapWithHasContainer(JSC.API.Listener, "listen", false, false, false), }, .connect = .{ - .rfn = JSC.wrapWithHasContainer(JSC.API.Listener, "connect", false, false, false), + .rfn = &JSC.wrapWithHasContainer(JSC.API.Listener, "connect", false, false, false), }, }, .{ @@ -1325,7 +1324,7 @@ pub fn indexOfLine( if (arguments.len > 1) { offset = @intCast( usize, - @maximum( + @max( arguments[1].to(u32), 0, ), @@ -1340,7 +1339,7 @@ pub fn indexOfLine( if (strings.indexOfNewlineOrNonASCII(bytes, @truncate(u32, current_offset))) |i| { const byte = bytes[i]; if (byte > 0x7F) { - current_offset += @maximum(strings.wtf8ByteSequenceLength(byte), 1); + current_offset += @max(strings.wtf8ByteSequenceLength(byte), 1); continue; } @@ -1364,7 +1363,7 @@ pub fn indexOfLine( pub const Crypto = struct { const Hashers = @import("../../sha.zig"); - fn CryptoHasher(comptime Hasher: type, name: [:0]const u8) type { + fn CryptoHasher(comptime Hasher: type, comptime name: [:0]const u8) type { return struct { hashing: Hasher = Hasher{}, @@ -1397,7 +1396,7 @@ pub const Crypto = struct { ) JSC.JSValue { var output_digest_buf: Hasher.Digest = undefined; - Hasher.hash(input.slice(), &output_digest_buf, JSC.VirtualMachine.vm.rareData().boringEngine()); + Hasher.hash(input.slice(), &output_digest_buf, JSC.VirtualMachine.get().rareData().boringEngine()); return encoding.encodeWithSize(globalThis, Hasher.digest, &output_digest_buf); } @@ -1418,7 +1417,7 @@ pub const Crypto = struct { output_digest_slice = bytes[0..Hasher.digest]; } - Hasher.hash(input.slice(), output_digest_slice, JSC.VirtualMachine.vm.rareData().boringEngine()); + Hasher.hash(input.slice(), output_digest_slice, JSC.VirtualMachine.get().rareData().boringEngine()); if (output) |output_buf| { return output_buf.value; @@ -1559,7 +1558,7 @@ pub const Crypto = struct { } pub fn finalize(this: *@This()) callconv(.C) void { - VirtualMachine.vm.allocator.destroy(this); + VirtualMachine.get().allocator.destroy(this); } }; } @@ -1582,7 +1581,7 @@ pub fn nanoseconds( _: []const JSC.C.JSValueRef, _: JSC.C.ExceptionRef, ) JSC.C.JSValueRef { - const ns = JSC.VirtualMachine.vm.origin_timer.read(); + const ns = JSC.VirtualMachine.get().origin_timer.read(); return JSC.JSValue.jsNumberFromUint64(ns).asObjectRef(); } @@ -1767,8 +1766,8 @@ pub fn allocUnsafe( const length = @intCast( usize, - @minimum( - @maximum(1, (args.nextEat() orelse JSC.JSValue.jsNumber(@as(i32, 1))).toInt32()), + @min( + @max(1, (args.nextEat() orelse JSC.JSValue.jsNumber(@as(i32, 1))).toInt32()), std.math.maxInt(i32), ), ); @@ -1795,7 +1794,7 @@ pub fn mmapFile( var args = JSC.Node.ArgumentsSlice.from(ctx.bunVM(), arguments); var buf: [bun.MAX_PATH_BYTES]u8 = undefined; - const path = getFilePath(ctx, arguments[0..@minimum(1, arguments.len)], &buf, exception) orelse return null; + const path = getFilePath(ctx, arguments[0..@min(1, arguments.len)], &buf, exception) orelse return null; args.eat(); buf[path.len] = 0; @@ -2007,7 +2006,7 @@ pub const Hash = struct { function_args[0] = input; } - const value = @call(.{}, Function, function_args); + const value = @call(.auto, Function, function_args); if (@TypeOf(value) == u32) { return JSC.JSValue.jsNumber(@bitCast(i32, value)).asObjectRef(); @@ -2067,7 +2066,7 @@ pub const Unsafe = struct { .rfn = arrayBufferToString, }, .gcAggressionLevel = .{ - .rfn = JSC.wrapWithHasContainer(Unsafe, "gcAggressionLevel", false, false, false), + .rfn = &JSC.wrapWithHasContainer(Unsafe, "gcAggressionLevel", false, false, false), }, }, .{}, @@ -2146,7 +2145,7 @@ pub const Unsafe = struct { // }, // .{ // .load = .{ -// .rfn = BunLockfile.load, +// .rfn = &BunLockfile.load, // }, // }, // .{}, @@ -2160,10 +2159,10 @@ pub const Unsafe = struct { // }, // .{ // .findPackagesByName = .{ -// .rfn = BunLockfile.load, +// .rfn = &BunLockfile.load, // }, // .dependencies = .{ -// .rfn = BunLockfile.load, +// .rfn = &BunLockfile.load, // }, // }, // .{}, @@ -2326,8 +2325,8 @@ pub const Timer = struct { ); pub fn getNextID() callconv(.C) i32 { - VirtualMachine.vm.timer.last_id +%= 1; - return VirtualMachine.vm.timer.last_id; + VirtualMachine.get().timer.last_id +%= 1; + return VirtualMachine.get().timer.last_id; } const uws = @import("bun").uws; @@ -2476,7 +2475,7 @@ pub const Timer = struct { // use the threadlocal despite being slow on macOS // to handle the timeout being cancelled after already enqueued - var vm = JSC.VirtualMachine.vm; + var vm = JSC.VirtualMachine.get(); const repeats = timer_id.repeat > 0; @@ -2572,7 +2571,7 @@ pub const Timer = struct { // We don't deal with nesting levels directly // but we do set the minimum timeout to be 1ms for repeating timers - const interval: i32 = @maximum( + const interval: i32 = @max( countdown.coerce(i32, globalThis), if (repeat) @as(i32, 1) else 0, ); @@ -2673,7 +2672,7 @@ pub const Timer = struct { pub fn clearTimer(timer_id: JSValue, _: *JSGlobalObject, repeats: bool) void { JSC.markBinding(@src()); - var map = if (repeats) &VirtualMachine.vm.timer.interval_map else &VirtualMachine.vm.timer.timeout_map; + var map = if (repeats) &VirtualMachine.get().timer.interval_map else &VirtualMachine.get().timer.timeout_map; const id: Timeout.ID = .{ .id = timer_id.toInt32(), .repeat = @as(u32, @boolToInt(repeats)), @@ -2713,11 +2712,11 @@ pub const Timer = struct { pub const namespace = shim.namespace; pub const Export = shim.exportFunctions(.{ - .@"setTimeout" = setTimeout, - .@"setInterval" = setInterval, - .@"clearTimeout" = clearTimeout, - .@"clearInterval" = clearInterval, - .@"getNextID" = getNextID, + .setTimeout = setTimeout, + .setInterval = setInterval, + .clearTimeout = clearTimeout, + .clearInterval = clearInterval, + .getNextID = getNextID, }); comptime { @@ -2737,27 +2736,27 @@ pub const FFI = struct { .{ .name = "FFI", .has_dom_calls = true }, .{ .viewSource = .{ - .rfn = JSC.wrapWithHasContainer(JSC.FFI, "print", false, false, true), + .rfn = &JSC.wrapWithHasContainer(JSC.FFI, "print", false, false, true), }, .dlopen = .{ - .rfn = JSC.wrapWithHasContainer(JSC.FFI, "open", false, false, true), + .rfn = &JSC.wrapWithHasContainer(JSC.FFI, "open", false, false, true), }, .callback = .{ - .rfn = JSC.wrapWithHasContainer(JSC.FFI, "callback", false, false, false), + .rfn = &JSC.wrapWithHasContainer(JSC.FFI, "callback", false, false, false), }, .linkSymbols = .{ - .rfn = JSC.wrapWithHasContainer(JSC.FFI, "linkSymbols", false, false, false), + .rfn = &JSC.wrapWithHasContainer(JSC.FFI, "linkSymbols", false, false, false), }, .ptr = JSC.DOMCall("FFI", @This(), "ptr", f64, JSC.DOMEffect.forRead(.TypedArrayProperties)), .toBuffer = .{ - .rfn = JSC.wrapWithHasContainer(@This(), "toBuffer", false, false, true), + .rfn = &JSC.wrapWithHasContainer(@This(), "toBuffer", false, false, true), }, .toArrayBuffer = .{ - .rfn = JSC.wrapWithHasContainer(@This(), "toArrayBuffer", false, false, true), + .rfn = &JSC.wrapWithHasContainer(@This(), "toArrayBuffer", false, false, true), }, .closeCallback = .{ - .rfn = JSC.wrapWithHasContainer(JSC.FFI, "closeCallback", false, false, false), + .rfn = &JSC.wrapWithHasContainer(JSC.FFI, "closeCallback", false, false, false), }, }, .{ @@ -2775,18 +2774,18 @@ pub const FFI = struct { void, .{ .name = "FFI", .has_dom_calls = true }, .{ - .@"u8" = JSC.DOMCall("Reader", @This(), "u8", i32, JSC.DOMEffect.forRead(.World)), - .@"u16" = JSC.DOMCall("Reader", @This(), "u16", i32, JSC.DOMEffect.forRead(.World)), - .@"u32" = JSC.DOMCall("Reader", @This(), "u32", i32, JSC.DOMEffect.forRead(.World)), - .@"ptr" = JSC.DOMCall("Reader", @This(), "ptr", i52, JSC.DOMEffect.forRead(.World)), - .@"i8" = JSC.DOMCall("Reader", @This(), "i8", i32, JSC.DOMEffect.forRead(.World)), - .@"i16" = JSC.DOMCall("Reader", @This(), "i16", i32, JSC.DOMEffect.forRead(.World)), - .@"i32" = JSC.DOMCall("Reader", @This(), "i32", i32, JSC.DOMEffect.forRead(.World)), - .@"i64" = JSC.DOMCall("Reader", @This(), "i64", i64, JSC.DOMEffect.forRead(.World)), - .@"u64" = JSC.DOMCall("Reader", @This(), "u64", u64, JSC.DOMEffect.forRead(.World)), - .@"intptr" = JSC.DOMCall("Reader", @This(), "intptr", i52, JSC.DOMEffect.forRead(.World)), - .@"f32" = JSC.DOMCall("Reader", @This(), "f32", f64, JSC.DOMEffect.forRead(.World)), - .@"f64" = JSC.DOMCall("Reader", @This(), "f64", f64, JSC.DOMEffect.forRead(.World)), + .u8 = JSC.DOMCall("Reader", @This(), "u8", i32, JSC.DOMEffect.forRead(.World)), + .u16 = JSC.DOMCall("Reader", @This(), "u16", i32, JSC.DOMEffect.forRead(.World)), + .u32 = JSC.DOMCall("Reader", @This(), "u32", i32, JSC.DOMEffect.forRead(.World)), + .ptr = JSC.DOMCall("Reader", @This(), "ptr", i52, JSC.DOMEffect.forRead(.World)), + .i8 = JSC.DOMCall("Reader", @This(), "i8", i32, JSC.DOMEffect.forRead(.World)), + .i16 = JSC.DOMCall("Reader", @This(), "i16", i32, JSC.DOMEffect.forRead(.World)), + .i32 = JSC.DOMCall("Reader", @This(), "i32", i32, JSC.DOMEffect.forRead(.World)), + .i64 = JSC.DOMCall("Reader", @This(), "i64", i64, JSC.DOMEffect.forRead(.World)), + .u64 = JSC.DOMCall("Reader", @This(), "u64", u64, JSC.DOMEffect.forRead(.World)), + .intptr = JSC.DOMCall("Reader", @This(), "intptr", i52, JSC.DOMEffect.forRead(.World)), + .f32 = JSC.DOMCall("Reader", @This(), "f32", f64, JSC.DOMEffect.forRead(.World)), + .f64 = JSC.DOMCall("Reader", @This(), "f64", f64, JSC.DOMEffect.forRead(.World)), }, .{}, ); @@ -2818,7 +2817,7 @@ pub const FFI = struct { const value = @intToPtr(*align(1) u32, addr).*; return JSValue.jsNumber(value); } - pub fn @"ptr"( + pub fn ptr( _: *JSGlobalObject, _: JSValue, arguments: []const JSValue, @@ -2854,7 +2853,7 @@ pub const FFI = struct { const value = @intToPtr(*align(1) i32, addr).*; return JSValue.jsNumber(value); } - pub fn @"intptr"( + pub fn intptr( _: *JSGlobalObject, _: JSValue, arguments: []const JSValue, @@ -2904,7 +2903,7 @@ pub const FFI = struct { return JSValue.fromUInt64NoTruncate(global, value); } - pub fn @"u8WithoutTypeChecks"( + pub fn u8WithoutTypeChecks( _: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -2914,7 +2913,7 @@ pub const FFI = struct { const value = @intToPtr(*align(1) u8, addr).*; return JSValue.jsNumber(value); } - pub fn @"u16WithoutTypeChecks"( + pub fn u16WithoutTypeChecks( _: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -2924,7 +2923,7 @@ pub const FFI = struct { const value = @intToPtr(*align(1) u16, addr).*; return JSValue.jsNumber(value); } - pub fn @"u32WithoutTypeChecks"( + pub fn u32WithoutTypeChecks( _: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -2934,7 +2933,7 @@ pub const FFI = struct { const value = @intToPtr(*align(1) u32, addr).*; return JSValue.jsNumber(value); } - pub fn @"ptrWithoutTypeChecks"( + pub fn ptrWithoutTypeChecks( _: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -2944,7 +2943,7 @@ pub const FFI = struct { const value = @intToPtr(*align(1) u64, addr).*; return JSValue.jsNumber(value); } - pub fn @"i8WithoutTypeChecks"( + pub fn i8WithoutTypeChecks( _: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -2954,7 +2953,7 @@ pub const FFI = struct { const value = @intToPtr(*align(1) i8, addr).*; return JSValue.jsNumber(value); } - pub fn @"i16WithoutTypeChecks"( + pub fn i16WithoutTypeChecks( _: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -2964,7 +2963,7 @@ pub const FFI = struct { const value = @intToPtr(*align(1) i16, addr).*; return JSValue.jsNumber(value); } - pub fn @"i32WithoutTypeChecks"( + pub fn i32WithoutTypeChecks( _: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -2974,7 +2973,7 @@ pub const FFI = struct { const value = @intToPtr(*align(1) i32, addr).*; return JSValue.jsNumber(value); } - pub fn @"intptrWithoutTypeChecks"( + pub fn intptrWithoutTypeChecks( _: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -2985,7 +2984,7 @@ pub const FFI = struct { return JSValue.jsNumber(value); } - pub fn @"f32WithoutTypeChecks"( + pub fn f32WithoutTypeChecks( _: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -2996,7 +2995,7 @@ pub const FFI = struct { return JSValue.jsNumber(value); } - pub fn @"f64WithoutTypeChecks"( + pub fn f64WithoutTypeChecks( _: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -3007,7 +3006,7 @@ pub const FFI = struct { return JSValue.jsNumber(value); } - pub fn @"u64WithoutTypeChecks"( + pub fn u64WithoutTypeChecks( global: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -3018,7 +3017,7 @@ pub const FFI = struct { return JSValue.fromUInt64NoTruncate(global, value); } - pub fn @"i64WithoutTypeChecks"( + pub fn i64WithoutTypeChecks( global: *JSGlobalObject, _: *anyopaque, raw_addr: i64, @@ -3414,7 +3413,7 @@ pub const EnvironmentVariables = struct { pub fn getEnvNames(globalObject: *JSC.JSGlobalObject, names: []ZigString) usize { var vm = globalObject.bunVM(); const keys = vm.bundler.env.map.map.keys(); - const max = @minimum(names.len, keys.len); + const max = @min(names.len, keys.len); for (keys[0..max]) |key, i| { names[i] = ZigString.initUTF8(key); } @@ -3430,7 +3429,7 @@ pub const EnvironmentVariables = struct { }; export fn Bun__reportError(_: *JSGlobalObject, err: JSC.JSValue) void { - JSC.VirtualMachine.vm.runErrorHandler(err, null); + JSC.VirtualMachine.get().runErrorHandler(err, null); } comptime { @@ -3498,7 +3497,7 @@ pub const JSZlib = struct { } var compressed = buffer.slice(); - const allocator = JSC.VirtualMachine.vm.allocator; + const allocator = JSC.VirtualMachine.get().allocator; var list = std.ArrayListUnmanaged(u8).initCapacity(allocator, if (compressed.len > 512) compressed.len else 32) catch unreachable; var reader = zlib.ZlibCompressorArrayList.init(compressed, &list, allocator, opts) catch |err| { if (err == error.InvalidArgument) { @@ -3515,7 +3514,7 @@ pub const JSZlib = struct { } return ZigString.init("Zlib returned an error").toErrorInstance(globalThis); }; - reader.list = .{ .items = reader.list.toOwnedSlice(allocator) }; + reader.list = .{ .items = reader.list.toOwnedSlice(allocator) catch @panic("TODO") }; reader.list.capacity = reader.list.items.len; reader.list_ptr = &reader.list; @@ -3528,7 +3527,7 @@ pub const JSZlib = struct { buffer: JSC.Node.StringOrBuffer, ) JSValue { var compressed = buffer.slice(); - const allocator = JSC.VirtualMachine.vm.allocator; + const allocator = JSC.VirtualMachine.get().allocator; var list = std.ArrayListUnmanaged(u8).initCapacity(allocator, if (compressed.len > 512) compressed.len else 32) catch unreachable; var reader = zlib.ZlibReaderArrayList.initWithOptions(compressed, &list, allocator, .{ .windowBits = -15, @@ -3547,7 +3546,7 @@ pub const JSZlib = struct { } return ZigString.init("Zlib returned an error").toErrorInstance(globalThis); }; - reader.list = .{ .items = reader.list.toOwnedSlice(allocator) }; + reader.list = .{ .items = reader.list.toOwnedSlice(allocator) catch @panic("TODO") }; reader.list.capacity = reader.list.items.len; reader.list_ptr = &reader.list; @@ -3560,7 +3559,7 @@ pub const JSZlib = struct { buffer: JSC.Node.StringOrBuffer, ) JSValue { var compressed = buffer.slice(); - const allocator = JSC.VirtualMachine.vm.allocator; + const allocator = JSC.VirtualMachine.get().allocator; var list = std.ArrayListUnmanaged(u8).initCapacity(allocator, if (compressed.len > 512) compressed.len else 32) catch unreachable; var reader = zlib.ZlibReaderArrayList.init(compressed, &list, allocator) catch |err| { if (err == error.InvalidArgument) { @@ -3577,7 +3576,7 @@ pub const JSZlib = struct { } return ZigString.init("Zlib returned an error").toErrorInstance(globalThis); }; - reader.list = .{ .items = reader.list.toOwnedSlice(allocator) }; + reader.list = .{ .items = reader.list.toOwnedSlice(allocator) catch @panic("TODO") }; reader.list.capacity = reader.list.items.len; reader.list_ptr = &reader.list; diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index 8fd6621f2..cbee356f2 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -1169,7 +1169,7 @@ fn NewSocket(comptime ssl: bool) type { var buf: [512]u8 = undefined; var length: i32 = 512; this.socket.remoteAddress(&buf, &length); - const address = buf[0..@intCast(usize, @minimum(length, 0))]; + const address = buf[0..@intCast(usize, @min(length, 0))]; if (address.len == 0) { return JSValue.jsUndefined(); @@ -1202,7 +1202,7 @@ fn NewSocket(comptime ssl: bool) type { return .zero; } - const offset = @minimum(args.ptr[1].toUInt64NoTruncate(), slice.len); + const offset = @min(args.ptr[1].toUInt64NoTruncate(), slice.len); slice = slice[offset..]; if (args.len > 2) { @@ -1211,7 +1211,7 @@ fn NewSocket(comptime ssl: bool) type { return .zero; } - const length = @minimum(args.ptr[2].toUInt64NoTruncate(), slice.len); + const length = @min(args.ptr[2].toUInt64NoTruncate(), slice.len); slice = slice[0..length]; } } @@ -1257,7 +1257,7 @@ fn NewSocket(comptime ssl: bool) type { return .zero; } - const offset = @minimum(args.ptr[1].toUInt64NoTruncate(), slice.len); + const offset = @min(args.ptr[1].toUInt64NoTruncate(), slice.len); slice = slice[offset..]; if (args.len > 2) { @@ -1266,7 +1266,7 @@ fn NewSocket(comptime ssl: bool) type { return .zero; } - const length = @minimum(args.ptr[2].toUInt64NoTruncate(), slice.len); + const length = @min(args.ptr[2].toUInt64NoTruncate(), slice.len); slice = slice[0..length]; } } @@ -1292,7 +1292,7 @@ fn NewSocket(comptime ssl: bool) type { return .zero; } - const offset = @minimum(args.ptr[1].toUInt64NoTruncate(), slice.len); + const offset = @min(args.ptr[1].toUInt64NoTruncate(), slice.len); slice = slice[offset..]; if (args.len > 2) { @@ -1301,7 +1301,7 @@ fn NewSocket(comptime ssl: bool) type { return .zero; } - const length = @minimum(args.ptr[2].toUInt64NoTruncate(), slice.len); + const length = @min(args.ptr[2].toUInt64NoTruncate(), slice.len); slice = slice[0..length]; } } @@ -1405,7 +1405,7 @@ fn NewSocket(comptime ssl: bool) type { this.socket.close(0, null); } this.markInactive(); - if (this.poll_ref.isActive()) this.poll_ref.unref(JSC.VirtualMachine.vm); + if (this.poll_ref.isActive()) this.poll_ref.unref(JSC.VirtualMachine.get()); } pub fn reload(this: *This, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSValue { diff --git a/src/bun.js/api/bun/spawn.zig b/src/bun.js/api/bun/spawn.zig index 7ed36cf34..b71e49dbc 100644 --- a/src/bun.js/api/bun/spawn.zig +++ b/src/bun.js/api/bun/spawn.zig @@ -53,7 +53,7 @@ pub const PosixSpawn = struct { pub fn deinit(self: *Attr) void { if (comptime bun.Environment.isMac) { // https://github.com/ziglang/zig/issues/12964 - system.posix_spawnattr_destroy(&self.attr); + _ = system.posix_spawnattr_destroy(&self.attr); } else { _ = system.posix_spawnattr_destroy(&self.attr); } @@ -93,7 +93,7 @@ pub const PosixSpawn = struct { pub fn deinit(self: *Actions) void { if (comptime bun.Environment.isMac) { // https://github.com/ziglang/zig/issues/12964 - system.posix_spawn_file_actions_destroy(&self.actions); + _ = system.posix_spawn_file_actions_destroy(&self.actions); } else { _ = system.posix_spawn_file_actions_destroy(&self.actions); } diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index c4d6467a0..38141c34c 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -134,7 +134,7 @@ pub const Subprocess = struct { .pipe => { if (this.pipe == .buffer) { if (this.pipe.buffer.fifo.poll_ref) |poll| { - poll.enableKeepingProcessAlive(JSC.VirtualMachine.vm); + poll.enableKeepingProcessAlive(JSC.VirtualMachine.get()); } } }, @@ -147,7 +147,7 @@ pub const Subprocess = struct { .pipe => { if (this.pipe == .buffer) { if (this.pipe.buffer.fifo.poll_ref) |poll| { - poll.disableKeepingProcessAlive(JSC.VirtualMachine.vm); + poll.disableKeepingProcessAlive(JSC.VirtualMachine.get()); } } }, @@ -522,7 +522,7 @@ pub const Subprocess = struct { }, ); - this.remain = this.remain[@minimum(bytes_written, this.remain.len)..]; + this.remain = this.remain[@min(bytes_written, this.remain.len)..]; to_write = to_write[bytes_written..]; // we are done or it accepts no more input @@ -762,7 +762,7 @@ pub const Subprocess = struct { switch (this.*) { .pipe => { if (this.pipe.poll_ref) |poll| { - poll.enableKeepingProcessAlive(JSC.VirtualMachine.vm); + poll.enableKeepingProcessAlive(JSC.VirtualMachine.get()); } }, else => {}, @@ -773,7 +773,7 @@ pub const Subprocess = struct { switch (this.*) { .pipe => { if (this.pipe.poll_ref) |poll| { - poll.disableKeepingProcessAlive(JSC.VirtualMachine.vm); + poll.disableKeepingProcessAlive(JSC.VirtualMachine.get()); } }, else => {}, @@ -994,7 +994,7 @@ pub const Subprocess = struct { var cwd = jsc_vm.bundler.fs.top_level_dir; var stdio = [3]Stdio{ - .{ .ignore = .{} }, + .{ .ignore = {} }, .{ .pipe = null }, .{ .inherit = {} }, }; @@ -1133,7 +1133,7 @@ pub const Subprocess = struct { if (!stdio_val.isEmptyOrUndefinedOrNull()) { if (stdio_val.jsType().isArray()) { var stdio_iter = stdio_val.arrayIterator(globalThis); - stdio_iter.len = @minimum(stdio_iter.len, 3); + stdio_iter.len = @min(stdio_iter.len, 3); var i: usize = 0; while (stdio_iter.next()) |value| : (i += 1) { if (!extractStdio(globalThis, i, value, &stdio)) @@ -1195,17 +1195,17 @@ pub const Subprocess = struct { } const stdin_pipe = if (stdio[0].isPiped()) os.pipe2(0) catch |err| { - globalThis.throw("failed to create stdin pipe: {s}", .{err}); + globalThis.throw("failed to create stdin pipe: {s}", .{@errorName(err)}); return .zero; } else undefined; const stdout_pipe = if (stdio[1].isPiped()) os.pipe2(0) catch |err| { - globalThis.throw("failed to create stdout pipe: {s}", .{err}); + globalThis.throw("failed to create stdout pipe: {s}", .{@errorName(err)}); return .zero; } else undefined; const stderr_pipe = if (stdio[2].isPiped()) os.pipe2(0) catch |err| { - globalThis.throw("failed to create stderr pipe: {s}", .{err}); + globalThis.throw("failed to create stderr pipe: {s}", .{@errorName(err)}); return .zero; } else undefined; @@ -1728,7 +1728,8 @@ pub const Subprocess = struct { } else if (value.as(JSC.WebCore.Response)) |req| { req.getBodyValue().toBlobIfPossible(); return extractStdioBlob(globalThis, req.getBodyValue().useAsAnyBlob(), i, stdio_array); - } else if (JSC.WebCore.ReadableStream.fromJS(value, globalThis)) |*req| { + } else if (JSC.WebCore.ReadableStream.fromJS(value, globalThis)) |req_const| { + var req = req_const; if (i == std.os.STDIN_FILENO) { if (req.toAnyBlob(globalThis)) |blob| { return extractStdioBlob(globalThis, blob, i, stdio_array); @@ -1742,7 +1743,7 @@ pub const Subprocess = struct { return false; } - stdio_array[i] = .{ .pipe = req.* }; + stdio_array[i] = .{ .pipe = req }; return true; }, else => {}, diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig index 6ea141559..8ff86f04a 100644 --- a/src/bun.js/api/ffi.zig +++ b/src/bun.js/api/ffi.zig @@ -1,5 +1,6 @@ const Bun = @This(); -const default_allocator = @import("bun").default_allocator; +const root = @import("root"); +const default_allocator = bun.default_allocator; const bun = @import("bun"); const Environment = bun.Environment; const NetworkThread = @import("bun").HTTP.NetworkThread; @@ -105,7 +106,7 @@ pub const FFI = struct { return JSC.toInvalidArguments("Expected callback function", .{}, globalThis); } - const allocator = VirtualMachine.vm.allocator; + const allocator = VirtualMachine.get().allocator; var function: Function = .{}; var func = &function; @@ -158,7 +159,7 @@ pub const FFI = struct { this.dylib = null; } - const allocator = VirtualMachine.vm.allocator; + const allocator = VirtualMachine.get().allocator; for (this.functions.values()) |*val| { val.deinit(globalThis, allocator); @@ -170,7 +171,7 @@ pub const FFI = struct { pub fn printCallback(global: *JSGlobalObject, object: JSC.JSValue) JSValue { JSC.markBinding(@src()); - const allocator = VirtualMachine.vm.allocator; + const allocator = VirtualMachine.get().allocator; if (object.isEmptyOrUndefinedOrNull() or !object.isObject()) { return JSC.toInvalidArguments("Expected an object", .{}, global); @@ -194,7 +195,7 @@ pub const FFI = struct { } pub fn print(global: *JSGlobalObject, object: JSC.JSValue, is_callback_val: ?JSC.JSValue) JSValue { - const allocator = VirtualMachine.vm.allocator; + const allocator = VirtualMachine.get().allocator; if (is_callback_val) |is_callback| { if (is_callback.toBoolean()) { return printCallback(global, object); @@ -257,7 +258,7 @@ pub const FFI = struct { } // pub fn dlcompile(global: *JSGlobalObject, object: JSC.JSValue) JSValue { - // const allocator = VirtualMachine.vm.allocator; + // const allocator = VirtualMachine.get().allocator; // if (object.isEmptyOrUndefinedOrNull() or !object.isObject()) { // return JSC.toInvalidArguments("Expected an options object with symbol names", .{}, global); @@ -277,7 +278,7 @@ pub const FFI = struct { pub fn open(global: *JSGlobalObject, name_str: ZigString, object: JSC.JSValue) JSC.JSValue { JSC.markBinding(@src()); - const allocator = VirtualMachine.vm.allocator; + const allocator = VirtualMachine.get().allocator; var name_slice = name_str.toSlice(allocator); defer name_slice.deinit(); @@ -380,7 +381,7 @@ pub const FFI = struct { }, .compiled => |*compiled| { const str = ZigString.init(std.mem.span(function_name)); - const cb = JSC.NewFunction( + const cb = JSC.NewRuntimeFunction( global, &str, @intCast(u32, function.arg_types.items.len), @@ -406,7 +407,7 @@ pub const FFI = struct { pub fn linkSymbols(global: *JSGlobalObject, object: JSC.JSValue) JSC.JSValue { JSC.markBinding(@src()); - const allocator = VirtualMachine.vm.allocator; + const allocator = VirtualMachine.get().allocator; if (object.isEmptyOrUndefinedOrNull() or !object.isObject()) { return JSC.toInvalidArguments("Expected an options object with symbol names", .{}, global); @@ -476,7 +477,7 @@ pub const FFI = struct { .compiled => |*compiled| { const name = &ZigString.init(std.mem.span(function_name)); - const cb = JSC.NewFunction( + const cb = JSC.NewRuntimeFunction( global, name, @intCast(u32, function.arg_types.items.len), @@ -547,7 +548,7 @@ pub const FFI = struct { } } // var function - var return_type = ABIType.@"void"; + var return_type = ABIType.void; var threadsafe = false; @@ -578,7 +579,7 @@ pub const FFI = struct { }; } - if (function.threadsafe and return_type != ABIType.@"void") { + if (function.threadsafe and return_type != ABIType.void) { abi_types.clearAndFree(allocator); return ZigString.static("Threadsafe functions must return void").toErrorInstance(global); } @@ -607,7 +608,7 @@ pub const FFI = struct { } pub fn generateSymbols(global: *JSGlobalObject, symbols: *bun.StringArrayHashMapUnmanaged(Function), object: JSC.JSValue) !?JSValue { JSC.markBinding(@src()); - const allocator = VirtualMachine.vm.allocator; + const allocator = VirtualMachine.get().allocator; var symbols_iter = JSC.JSPropertyIterator(.{ .skip_empty_name = true, @@ -642,7 +643,7 @@ pub const FFI = struct { base_name: ?[:0]const u8 = null, state: ?*TCC.TCCState = null, - return_type: ABIType = ABIType.@"void", + return_type: ABIType = ABIType.void, arg_types: std.ArrayListUnmanaged(ABIType) = .{}, step: Step = Step{ .pending = {} }, threadsafe: bool = false, @@ -704,7 +705,7 @@ pub const FFI = struct { const FFI_HEADER: string = @embedFile("./FFI.h"); pub inline fn ffiHeader() string { if (comptime Environment.isDebug) { - var dirpath = std.fs.path.dirname(@src().file).?; + var dirpath = comptime bun.Environment.base_path ++ std.fs.path.dirname(@src().file).?; var env = std.process.getEnvMap(default_allocator) catch unreachable; const dir = std.mem.replaceOwned( @@ -736,16 +737,16 @@ pub const FFI = struct { msg = msg[offset..]; } - this.step = .{ .failed = .{ .msg = VirtualMachine.vm.allocator.dupe(u8, msg) catch unreachable, .allocated = true } }; + this.step = .{ .failed = .{ .msg = VirtualMachine.get().allocator.dupe(u8, msg) catch unreachable, .allocated = true } }; } extern fn pthread_jit_write_protect_np(enable: bool) callconv(.C) void; const MyFunctionSStructWorkAround = struct { - JSVALUE_TO_INT64: fn (JSValue0: JSC.JSValue) callconv(.C) i64, - JSVALUE_TO_UINT64: fn (JSValue0: JSC.JSValue) callconv(.C) u64, - INT64_TO_JSVALUE: fn (arg0: [*c]JSC.JSGlobalObject, arg1: i64) callconv(.C) JSC.JSValue, - UINT64_TO_JSVALUE: fn (arg0: [*c]JSC.JSGlobalObject, arg1: u64) callconv(.C) JSC.JSValue, + JSVALUE_TO_INT64: *const fn (JSValue0: JSC.JSValue) callconv(.C) i64, + JSVALUE_TO_UINT64: *const fn (JSValue0: JSC.JSValue) callconv(.C) u64, + INT64_TO_JSVALUE: *const fn (arg0: *JSC.JSGlobalObject, arg1: i64) callconv(.C) JSC.JSValue, + UINT64_TO_JSVALUE: *const fn (arg0: *JSC.JSGlobalObject, arg1: u64) callconv(.C) JSC.JSValue, bun_call: *const @TypeOf(JSC.C.JSObjectCallAsFunction), }; const headers = @import("../bindings/headers.zig"); @@ -831,7 +832,7 @@ pub const FFI = struct { return; } - var bytes: []u8 = try allocator.rawAlloc(@intCast(usize, relocation_size), 16, 16, 0); + var bytes: []u8 = try allocator.alloc(u8, @intCast(usize, relocation_size)); defer { if (this.step == .failed) { allocator.free(bytes); @@ -931,6 +932,16 @@ pub const FFI = struct { var source_code_writer = source_code.writer(); var ffi_wrapper = Bun__createFFICallbackFunction(js_context, js_function); try this.printCallbackSourceCode(js_context, ffi_wrapper, &source_code_writer); + + if (comptime Environment.allow_assert) { + debug_write: { + const fd = std.os.open("/tmp/bun-ffi-callback-source.c", std.os.O.WRONLY | std.os.O.CREAT, 0o644) catch break :debug_write; + _ = std.os.write(fd, source_code.items) catch break :debug_write; + std.os.ftruncate(fd, source_code.items.len) catch break :debug_write; + std.os.close(fd); + } + } + try source_code.append(0); // defer source_code.deinit(); var state = TCC.tcc_new() orelse return error.TCCMissing; @@ -991,7 +1002,7 @@ pub const FFI = struct { return; } - var bytes: []u8 = try allocator.rawAlloc(@intCast(usize, relocation_size), 16, 16, 0); + var bytes: []u8 = try allocator.alloc(u8, @intCast(usize, relocation_size)); defer { if (this.step == .failed) { allocator.free(bytes); @@ -1149,12 +1160,12 @@ pub const FFI = struct { try writer.writeAll(", "); } first = false; - try writer.writeAll(" "); + const lengthBuf = std.fmt.bufPrintIntToSlice(arg_buf["arg".len..], i, 10, .lower, .{}); const argName = arg_buf[0 .. 3 + lengthBuf.len]; if (arg.needsACastInC()) { - try writer.print("{}", .{arg.toC(argName)}); + try writer.print("{any}", .{arg.toC(argName)}); } else { try writer.writeAll(argName); } @@ -1168,7 +1179,7 @@ pub const FFI = struct { try writer.writeAll("return "); if (!(this.return_type == .void)) { - try writer.print("{}.asZigRepr", .{this.return_type.toJS("return_value")}); + try writer.print("{any}.asZigRepr", .{this.return_type.toJS("return_value")}); } else { try writer.writeAll("ValueUndefined.asZigRepr"); } @@ -1194,7 +1205,12 @@ pub const FFI = struct { context_ptr: ?*anyopaque, writer: anytype, ) !void { - try writer.print("#define JS_GLOBAL_OBJECT (void*)0x{X}UL\n", .{@ptrToInt(globalObject)}); + { + const ptr = @ptrToInt(globalObject); + const fmt = bun.fmt.hexIntUpper(ptr); + try writer.print("#define JS_GLOBAL_OBJECT (void*)0x{any}ULL\n", .{fmt}); + } + try writer.writeAll("#define IS_CALLBACK 1\n"); brk: { @@ -1266,28 +1282,35 @@ pub const FFI = struct { for (this.arg_types.items) |arg, i| { const printed = std.fmt.bufPrintIntToSlice(arg_buf["arg".len..], i, 10, .lower, .{}); const arg_name = arg_buf[0 .. "arg".len + printed.len]; - try writer.print("arguments[{d}] = {}.asZigRepr;\n", .{ i, arg.toJS(arg_name) }); + try writer.print("arguments[{d}] = {any}.asZigRepr;\n", .{ i, arg.toJS(arg_name) }); } } try writer.writeAll(" "); var inner_buf_: [372]u8 = undefined; var inner_buf: []u8 = &.{}; - if (this.arg_types.items.len > 0) { - inner_buf = try std.fmt.bufPrint( - inner_buf_[1..], - "FFI_Callback_call((void*)0x{X}UL, {d}, arguments)", - .{ @ptrToInt(context_ptr), this.arg_types.items.len }, - ); - } else { - inner_buf = try std.fmt.bufPrint( - inner_buf_[1..], - "FFI_Callback_call((void*)0x{X}UL, 0, (ZIG_REPR_TYPE*)0)", - .{ - @ptrToInt(context_ptr), - }, - ); + + { + const ptr = @ptrToInt(context_ptr); + const fmt = bun.fmt.hexIntUpper(ptr); + + if (this.arg_types.items.len > 0) { + inner_buf = try std.fmt.bufPrint( + inner_buf_[1..], + "FFI_Callback_call((void*)0x{any}ULL, {d}, arguments)", + .{ fmt, this.arg_types.items.len }, + ); + } else { + inner_buf = try std.fmt.bufPrint( + inner_buf_[1..], + "FFI_Callback_call((void*)0x{any}ULL, 0, (ZIG_REPR_TYPE*)0)", + .{ + fmt, + }, + ); + } } + if (this.return_type == .void) { try writer.writeAll(inner_buf); } else { @@ -1324,7 +1347,7 @@ pub const FFI = struct { ptr = 12, - @"void" = 13, + void = 13, cstring = 14, @@ -1375,8 +1398,8 @@ pub const FFI = struct { .{ "void*", ABIType.ptr }, .{ "ptr", ABIType.ptr }, .{ "pointer", ABIType.ptr }, - .{ "void", ABIType.@"void" }, - .{ "cstring", ABIType.@"cstring" }, + .{ "void", ABIType.void }, + .{ "cstring", ABIType.cstring }, .{ "i64_fast", ABIType.i64_fast }, .{ "u64_fast", ABIType.u64_fast }, .{ "function", ABIType.function }, diff --git a/src/bun.js/api/filesystem_router.zig b/src/bun.js/api/filesystem_router.zig index ab2ef4738..3271e3cc7 100644 --- a/src/bun.js/api/filesystem_router.zig +++ b/src/bun.js/api/filesystem_router.zig @@ -69,7 +69,7 @@ const DeprecatedGlobalRouter = struct { break :brk JSC.JSValue.fromRef(arguments[0]); }; - var router = JavaScript.VirtualMachine.vm.bundler.router orelse { + var router = JavaScript.VirtualMachine.get().bundler.router orelse { JSError(getAllocator(ctx), "Bun.match needs a framework configured with routes", .{}, ctx, exception); return null; }; @@ -140,9 +140,9 @@ const DeprecatedGlobalRouter = struct { var matched = MatchedRoute.init( getAllocator(ctx), route.*, - JSC.VirtualMachine.vm.refCountedString(JSC.VirtualMachine.vm.origin.href, null, false), - JSC.VirtualMachine.vm.refCountedString(JSC.VirtualMachine.vm.bundler.options.routes.asset_prefix_path, null, false), - JSC.VirtualMachine.vm.refCountedString(JSC.VirtualMachine.vm.bundler.fs.top_level_dir, null, false), + JSC.VirtualMachine.get().refCountedString(JSC.VirtualMachine.get().origin.href, null, false), + JSC.VirtualMachine.get().refCountedString(JSC.VirtualMachine.get().bundler.options.routes.asset_prefix_path, null, false), + JSC.VirtualMachine.get().refCountedString(JSC.VirtualMachine.get().bundler.fs.top_level_dir, null, false), ) catch unreachable; return matched.toJS(ctx).asObjectRef(); @@ -665,7 +665,7 @@ pub const MatchedRoute = struct { var writer = stream.writer(); JSC.API.Bun.getPublicPathWithAssetPrefix( this.route.file_path, - if (this.base_dir) |base_dir| base_dir.slice() else VirtualMachine.vm.bundler.fs.top_level_dir, + if (this.base_dir) |base_dir| base_dir.slice() else VirtualMachine.get().bundler.fs.top_level_dir, if (this.origin) |origin| URL.parse(origin.slice()) else URL{}, if (this.asset_prefix) |prefix| prefix.slice() else "", @TypeOf(&writer), diff --git a/src/bun.js/api/html_rewriter.zig b/src/bun.js/api/html_rewriter.zig index 8828ea8ff..05b110b90 100644 --- a/src/bun.js/api/html_rewriter.zig +++ b/src/bun.js/api/html_rewriter.zig @@ -307,7 +307,7 @@ pub const HTMLRewriter = struct { doc.ctx = this; } - const chunk_size = @maximum(size_hint orelse 16384, 1024); + const chunk_size = @max(size_hint orelse 16384, 1024); this.rewriter = builder.build( .UTF8, .{ @@ -417,7 +417,7 @@ pub const HTMLRewriter = struct { .preallocated_parsing_buffer_size = if (input_size == JSC.WebCore.Blob.max_size) 1024 else - @maximum(input_size, 1024), + @max(input_size, 1024), .max_allowed_memory_usage = std.math.maxInt(u32), }, false, @@ -476,7 +476,7 @@ pub const HTMLRewriter = struct { if (sink.response.body.value == .Locked and @ptrToInt(sink.response.body.value.Locked.task) == @ptrToInt(sink) and sink.response.body.value.Locked.promise == null) { - sink.response.body.value = .{ .Empty = .{} }; + sink.response.body.value = .{ .Empty = {} }; // is there a pending promise? // we will need to reject it } else if (sink.response.body.value == .Locked and @ptrToInt(sink.response.body.value.Locked.task) == @ptrToInt(sink) and @@ -593,7 +593,7 @@ pub const HTMLRewriter = struct { // sink.rewriter = builder.build( // .UTF8, // .{ - // .preallocated_parsing_buffer_size = @maximum(original.body.len(), 1024), + // .preallocated_parsing_buffer_size = @max(original.body.len(), 1024), // .max_allowed_memory_usage = std.math.maxInt(u32), // }, // false, diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 85918d320..3a50a472f 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -302,8 +302,8 @@ pub const ServerConfig = struct { if (arg.getTruthy(global, "port")) |port_| { args.port = @intCast( u16, - @minimum( - @maximum(0, port_.coerce(i32, global)), + @min( + @max(0, port_.coerce(i32, global)), std.math.maxInt(u16), ), ); @@ -356,7 +356,7 @@ pub const ServerConfig = struct { } if (arg.getTruthy(global, "maxRequestBodySize")) |max_request_body_size| { - args.max_request_body_size = @intCast(u64, @maximum(0, max_request_body_size.toInt64())); + args.max_request_body_size = @intCast(u64, @max(0, max_request_body_size.toInt64())); } if (arg.getTruthy(global, "error")) |onError| { @@ -552,26 +552,33 @@ pub fn NewRequestContextStackAllocator(comptime RequestContext: type, comptime c pub fn get(this: *@This()) std.mem.Allocator { this.unused = Set.initFull(); - return std.mem.Allocator.init(this, alloc, resize, free); + return .{ + .ptr = this, + .vtable = &.{ + .alloc = alloc, + .resize = resize, + .free = free, + }, + }; } - fn alloc(self: *@This(), a: usize, b: u29, c: u29, d: usize) ![]u8 { + fn alloc(self_: *anyopaque, a: usize, b: u8, d: usize) ?[*]u8 { + const self = @ptrCast(*@This(), @alignCast(@alignOf(@This()), self_)); if (self.unused.findFirstSet()) |i| { self.unused.unset(i); return std.mem.asBytes(&self.buf[i]); } - return try self.fallback_allocator.rawAlloc(a, b, c, d); + return self.fallback_allocator.rawAlloc(a, b, d); } fn resize( - _: *@This(), + _: *anyopaque, _: []u8, - _: u29, + _: u8, _: usize, - _: u29, _: usize, - ) ?usize { + ) bool { unreachable; } @@ -581,13 +588,12 @@ pub fn NewRequestContextStackAllocator(comptime RequestContext: type, comptime c } fn free( - self: *@This(), + self_: *anyopaque, buf: []u8, - buf_align: u29, + buf_align: u8, return_address: usize, ) void { - _ = buf_align; - _ = return_address; + const self = @ptrCast(*@This(), @alignCast(@alignOf(@This()), self_)); const bytes = std.mem.asBytes(&self.buf); if (sliceContainsSlice(bytes, buf)) { const index = if (bytes[0..buf.len].ptr != buf.ptr) @@ -800,7 +806,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp .message = std.fmt.allocPrint(allocator, comptime Output.prettyFmt(fmt, false), args) catch unreachable, .router = null, .reason = .fetch_event_handler, - .cwd = VirtualMachine.vm.bundler.fs.top_level_dir, + .cwd = VirtualMachine.get().bundler.fs.top_level_dir, .problems = Api.Problems{ .code = @truncate(u16, @errorToInt(err)), .name = @errorName(err), @@ -1127,8 +1133,8 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp return false; } - const adjusted_count_temporary = @minimum(@as(u64, this.sendfile.remain), @as(u63, std.math.maxInt(u63))); - // TODO we should not need this int cast; improve the return type of `@minimum` + const adjusted_count_temporary = @min(@as(u64, this.sendfile.remain), @as(u63, std.math.maxInt(u63))); + // TODO we should not need this int cast; improve the return type of `@min` const adjusted_count = @intCast(u63, adjusted_count_temporary); if (Environment.isLinux) { @@ -1205,7 +1211,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp pub fn sendWritableBytesForBlob(this: *RequestContext, bytes_: []const u8, write_offset: c_ulong, resp: *App.Response) bool { std.debug.assert(this.resp == resp); - var bytes = bytes_[@minimum(bytes_.len, @truncate(usize, write_offset))..]; + var bytes = bytes_[@min(bytes_.len, @truncate(usize, write_offset))..]; if (resp.tryEnd(bytes, bytes_.len, this.shouldCloseConnection())) { this.finalize(); return true; @@ -1218,7 +1224,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp pub fn sendWritableBytesForCompleteResponseBuffer(this: *RequestContext, bytes_: []const u8, write_offset: c_ulong, resp: *App.Response) bool { std.debug.assert(this.resp == resp); - var bytes = bytes_[@minimum(bytes_.len, @truncate(usize, write_offset))..]; + var bytes = bytes_[@min(bytes_.len, @truncate(usize, write_offset))..]; if (resp.tryEnd(bytes, bytes_.len, this.shouldCloseConnection())) { this.response_buf_owned.items.len = 0; this.finalize(); @@ -1306,7 +1312,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp this.blob.Blob.size = if (std.os.S.ISREG(stat.mode)) stat_size else - @minimum(original_size, stat_size); + @min(original_size, stat_size); this.needs_content_length = true; @@ -1327,8 +1333,8 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp // we know the bounds when we are sending a regular file if (std.os.S.ISREG(stat.mode)) { - this.sendfile.offset = @minimum(this.sendfile.offset, stat_size); - this.sendfile.remain = @minimum(@maximum(this.sendfile.remain, this.sendfile.offset), stat_size) -| this.sendfile.offset; + this.sendfile.offset = @min(this.sendfile.offset, stat_size); + this.sendfile.remain = @min(@max(this.sendfile.remain, this.sendfile.offset), stat_size) -| this.sendfile.offset; } this.resp.runCorkedWithType(*RequestContext, renderMetadataAndNewline, this); @@ -1386,7 +1392,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp this.blob.Blob.size = if (original_size == 0 or original_size == Blob.max_size) stat_size else - @minimum(original_size, stat_size); + @min(original_size, stat_size); if (!this.has_written_status) this.needs_content_range = true; @@ -1830,7 +1836,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp } } - streamLog("onReject({s})", .{wrote_anything}); + streamLog("onReject({any})", .{wrote_anything}); if (req.aborted) { req.finalizeForAbort(); @@ -2086,7 +2092,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp this.renderDefaultError( vm.log, error.ExceptionOcurred, - exception_list.toOwnedSlice(), + exception_list.toOwnedSlice() catch @panic("TODO"), "<r><red>{s}<r> - <b>{s}<r> failed", .{ @as(string, @tagName(this.method)), this.ensurePathname() }, ); @@ -2210,7 +2216,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp this.resp.writeHeader( "content-disposition", - std.fmt.bufPrint(&filename_buf, "filename=\"{s}\"", .{basename[0..@minimum(basename.len, 1024 - 32)]}) catch "", + std.fmt.bufPrint(&filename_buf, "filename=\"{s}\"", .{basename[0..@min(basename.len, 1024 - 32)]}) catch "", ); } } @@ -2345,7 +2351,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp } if (this.request_body_buf.capacity == 0) { - this.request_body_buf.ensureTotalCapacityPrecise(this.allocator, @minimum(this.request_body_content_len, max_request_body_preallocate_length)) catch @panic("Out of memory while allocating request body buffer"); + this.request_body_buf.ensureTotalCapacityPrecise(this.allocator, @min(this.request_body_content_len, max_request_body_preallocate_length)) catch @panic("Out of memory while allocating request body buffer"); } this.request_body_buf.appendSlice(this.allocator, chunk) catch @panic("Out of memory while allocating request body"); @@ -2391,7 +2397,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp if (request.as(Request)) |req| { var old = req.body; old.Locked.onReceiveValue = null; - req.body = .{ .Empty = .{} }; + req.body = .{ .Empty = {} }; old.resolve(&req.body, this.server.globalThis); return; } @@ -2402,7 +2408,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp if (request.as(Request)) |req| { var old = req.body; old.Locked.onReceiveValue = null; - req.body = .{ .Empty = .{} }; + req.body = .{ .Empty = {} }; old.toError(error.RequestBodyTooLarge, this.server.globalThis); return; } @@ -2419,7 +2425,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp if (request.as(Request)) |req| { var old = req.body; old.Locked.onReceiveValue = null; - req.body = .{ .Empty = .{} }; + req.body = .{ .Empty = {} }; old.resolve(&req.body, this.server.globalThis); return; } @@ -2683,7 +2689,7 @@ pub const WebSocketServer = struct { globalObject.throwInvalidArguments("websocket expects maxPayloadLength to be an integer", .{}); return null; } - server.maxPayloadLength = @intCast(u32, @truncate(i33, @maximum(value.toInt64(), 0))); + server.maxPayloadLength = @intCast(u32, @truncate(i33, @max(value.toInt64(), 0))); } } if (object.get(globalObject, "idleTimeout")) |value| { @@ -2703,7 +2709,7 @@ pub const WebSocketServer = struct { return null; } - server.backpressureLimit = @intCast(u32, @truncate(i33, @maximum(value.toInt64(), 0))); + server.backpressureLimit = @intCast(u32, @truncate(i33, @max(value.toInt64(), 0))); } } // if (object.get(globalObject, "sendPings")) |value| { @@ -4125,7 +4131,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type { var url: URL = undefined; var first_arg = args.nextEat().?; - var body: JSC.WebCore.Body.Value = .{ .Empty = .{} }; + var body: JSC.WebCore.Body.Value = .{ .Empty = {} }; var existing_request: ?WebCore.Request = null; // TODO: set Host header // TODO: set User-Agent header @@ -4329,7 +4335,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type { .globalThis = globalThis, .config = config, .base_url_string_for_joining = bun.default_allocator.dupe(u8, strings.trim(config.base_url.href, "/")) catch unreachable, - .vm = JSC.VirtualMachine.vm, + .vm = JSC.VirtualMachine.get(), .allocator = Arena.getThreadlocalDefault(), }; @@ -4402,7 +4408,8 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type { if (written > 0) { var message = output_buf[0..written]; zig_str = ZigString.init(std.fmt.allocPrint(bun.default_allocator, "OpenSSL {s}", .{message}) catch unreachable); - zig_str.withEncoding().mark(); + var encoded_str = zig_str.withEncoding(); + encoded_str.mark(); } } @@ -4457,7 +4464,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type { _ = js_printer.printJSON( *js_printer.BufferPrinter, &writer, - bun.Global.BunInfo.generate(*Bundler, &JSC.VirtualMachine.vm.bundler, allocator) catch unreachable, + bun.Global.BunInfo.generate(*Bundler, &JSC.VirtualMachine.get().bundler, allocator) catch unreachable, &source, ) catch unreachable; @@ -4480,8 +4487,8 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type { return; } - var ctx = &JSC.VirtualMachine.vm.rareData().editor_context; - ctx.autoDetectEditor(JSC.VirtualMachine.vm.bundler.env); + var ctx = &JSC.VirtualMachine.get().rareData().editor_context; + ctx.autoDetectEditor(JSC.VirtualMachine.get().bundler.env); var line: ?string = req.header("editor-line"); var column: ?string = req.header("editor-column"); @@ -4517,7 +4524,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type { .uws_request = req, .https = ssl_enabled, .body = .{ - .Empty = .{}, + .Empty = {}, }, }; @@ -4597,7 +4604,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type { .upgrader = ctx, .https = ssl_enabled, .body = .{ - .Empty = .{}, + .Empty = {}, }, }; ctx.upgrade_context = upgrade_ctx; diff --git a/src/bun.js/api/transpiler.zig b/src/bun.js/api/transpiler.zig index 24104c2b7..abcef8248 100644 --- a/src/bun.js/api/transpiler.zig +++ b/src/bun.js/api/transpiler.zig @@ -494,7 +494,7 @@ fn transformOptionsFromJSC(ctx: JSC.C.JSContextRef, temp_allocator: std.mem.Allo allocator, &transpiler.log, logger.Source.initPathString("tsconfig.json", transpiler.tsconfig_buf), - &VirtualMachine.vm.bundler.resolver.caches.json, + &VirtualMachine.get().bundler.resolver.caches.json, true, ) catch null) |parsed_tsconfig| { transpiler.tsconfig = parsed_tsconfig; @@ -529,7 +529,7 @@ fn transformOptionsFromJSC(ctx: JSC.C.JSContextRef, temp_allocator: std.mem.Allo if (out.len == 0) break :macros; transpiler.macros_buf = std.fmt.allocPrint(allocator, "{}", .{out}) catch unreachable; const source = logger.Source.initPathString("macros.json", transpiler.macros_buf); - const json = (VirtualMachine.vm.bundler.resolver.caches.json.parseJSON( + const json = (VirtualMachine.get().bundler.resolver.caches.json.parseJSON( &transpiler.log, source, allocator, @@ -639,7 +639,7 @@ fn transformOptionsFromJSC(ctx: JSC.C.JSContextRef, temp_allocator: std.mem.Allo }; buf.items.len += name.len; if (name.len > 0) { - replacements.putAssumeCapacity(name, .{ .delete = .{} }); + replacements.putAssumeCapacity(name, .{ .delete = {} }); } } } @@ -763,7 +763,7 @@ pub fn constructor( log, transpiler_options.transform, null, - JavaScript.VirtualMachine.vm.bundler.env, + JavaScript.VirtualMachine.get().bundler.env, ) catch |err| { if ((log.warnings + log.errors) > 0) { var out_exception = log.toJS(ctx.ptr(), getAllocator(ctx), "Failed to create transpiler"); diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig index f331dc8f5..79f1fe46a 100644 --- a/src/bun.js/base.zig +++ b/src/bun.js/base.zig @@ -190,9 +190,9 @@ pub const To = struct { JSC.C.JSValueRef => value, else => { - const Info: std.builtin.TypeInfo = comptime @typeInfo(Type); + const Info: std.builtin.Type = comptime @typeInfo(Type); if (comptime Info == .Enum) { - const Enum: std.builtin.TypeInfo.Enum = Info.Enum; + const Enum: std.builtin.Type.Enum = Info.Enum; if (comptime !std.meta.trait.isNumber(Enum.tag_type)) { zig_str = JSC.ZigString.init(@tagName(value)); return zig_str.toValue(context.ptr()).asObjectRef(); @@ -207,7 +207,7 @@ pub const To = struct { if (value.len <= prefill) { var array: [prefill]JSC.C.JSValueRef = undefined; var i: u8 = 0; - const len = @minimum(@intCast(u8, value.len), prefill); + const len = @min(@intCast(u8, value.len), prefill); while (i < len and exception.* == null) : (i += 1) { array[i] = if (comptime Child == JSC.C.JSValueRef) value[i] @@ -270,7 +270,7 @@ pub const To = struct { if (comptime Info == .Struct) { if (comptime @hasDecl(Type, "Class") and @hasDecl(Type.Class, "isJavaScriptCoreClass")) { if (comptime !@hasDecl(Type, "finalize")) { - @compileError(comptime std.fmt.comptimePrint("JSC class {s} must implement finalize to prevent memory leaks", .{Type.Class.name})); + @compileError(std.fmt.comptimePrint("JSC class {s} must implement finalize to prevent memory leaks", .{Type.Class.name})); } if (comptime !@hasDecl(Type, "toJS")) { @@ -281,6 +281,12 @@ pub const To = struct { } } + if (comptime @hasDecl(Type, "toJS") and @typeInfo(@TypeOf(@field(Type, "toJS"))).Fn.params.len == 2) { + var val = bun.default_allocator.create(Type) catch unreachable; + val.* = value; + return val.toJS(context).asObjectRef(); + } + const res = value.toJS(context, exception); if (@TypeOf(res) == JSC.C.JSValueRef) { @@ -313,11 +319,20 @@ pub const To = struct { _: js.JSStringRef, exception: js.ExceptionRef, ) js.JSValueRef { - return withType(std.meta.fieldInfo(Type, field).field_type, @field(this, @tagName(field)), ctx, exception); + return withType(std.meta.fieldInfo(Type, field).type, @field(this, @tagName(field)), ctx, exception); } }.rfn; } + pub const JSC_C_Function = fn ( + js.JSContextRef, + js.JSObjectRef, + js.JSObjectRef, + usize, + [*c]const js.JSValueRef, + js.ExceptionRef, + ) callconv(.C) js.JSValueRef; + pub fn Callback( comptime ZigContextType: type, comptime ctxfn: fn ( @@ -838,7 +853,7 @@ pub fn NewConstructor( ) type { return struct { pub usingnamespace NewClassWithInstanceType(void, InstanceType.Class.class_options, staticFunctions, properties, InstanceType); - const name_string = &ZigString.init(InstanceType.Class.class_options.name); + const name_string = ZigString.static(InstanceType.Class.class_options.name); pub fn constructor(ctx: js.JSContextRef) callconv(.C) js.JSObjectRef { return JSValue.makeWithNameAndPrototype( ctx.ptr(), @@ -907,7 +922,7 @@ pub fn NewClassWithInstanceType( arguments: [*c]const js.JSValueRef, exception: js.ExceptionRef, ) callconv(.C) js.JSValueRef { - return &complete_definition.callAsConstructor.?(ctx, function, argumentCount, arguments, exception); + return getClassDefinition().callAsConstructor.?(ctx, function, argumentCount, arguments, exception); } }; @@ -929,14 +944,60 @@ pub fn NewClassWithInstanceType( } pub const Constructor = ConstructorWrapper.rfn; - const class_definition_ptr = &complete_definition; + + var class_definition: js.JSClassDefinition = undefined; + var class_definition_set: bool = false; + const static_functions__: [function_name_literals.len + 1]js.JSStaticFunction = if (function_name_literals.len > 0) generateDef([function_name_literals.len + 1]js.JSStaticFunction) else undefined; + const static_values_ptr = &static_properties; + + fn generateClassDefinition() void { + class_definition = comptime brk: { + var def = generateDef(JSC.C.JSClassDefinition); + if (function_name_literals.len > 0) + def.staticFunctions = &static_functions__; + if (options.no_inheritance) { + def.attributes = JSC.C.JSClassAttributes.kJSClassAttributeNoAutomaticPrototype; + } + if (property_names.len > 0) { + def.staticValues = static_values_ptr; + } + + def.className = options.name.ptr; + // def.getProperty = getPropertyCallback; + + if (def.callAsConstructor == null) { + def.callAsConstructor = &throwInvalidConstructorError; + } + + if (def.callAsFunction == null) { + def.callAsFunction = &throwInvalidFunctionError; + } + + if (def.getPropertyNames == null) { + def.getPropertyNames = &getPropertyNames; + } + + if (!singleton and def.hasInstance == null) + def.hasInstance = &customHasInstance; + break :brk def; + }; + } + + fn getClassDefinition() *const JSC.C.JSClassDefinition { + if (!class_definition_set) { + class_definition_set = true; + generateClassDefinition(); + } + + return &class_definition; + } pub fn get() callconv(.C) [*c]js.JSClassRef { var lazy = lazy_ref; if (!lazy.loaded) { lazy = .{ - .ref = js.JSClassCreate(class_definition_ptr), + .ref = js.JSClassCreate(getClassDefinition()), .loaded = true, }; lazy_ref = lazy; @@ -1064,7 +1125,7 @@ pub fn NewClassWithInstanceType( js.ExceptionRef, ) js.JSValueRef; - if (Func.Fn.args.len == @typeInfo(WithPropFn).Fn.args.len) { + if (Func.Fn.params.len == @typeInfo(WithPropFn).Fn.params.len) { return func( this, ctx, @@ -1120,43 +1181,45 @@ pub fn NewClassWithInstanceType( }; } - pub inline fn getDefinition() js.JSClassDefinition { - var definition = complete_definition; - definition.className = options.name; - return definition; - } - pub fn getPropertyNames( _: js.JSContextRef, _: js.JSObjectRef, props: js.JSPropertyNameAccumulatorRef, ) callconv(.C) void { if (comptime property_name_refs.len > 0) { - comptime var i: usize = 0; if (!property_name_refs_set) { + comptime var i: usize = 0; property_name_refs_set = true; - inline while (i < property_name_refs.len) : (i += 1) { + inline while (i < comptime property_name_refs.len) : (i += 1) { property_name_refs[i] = js.JSStringCreateStatic(property_names[i].ptr, property_names[i].len); } comptime i = 0; - } - inline while (i < property_name_refs.len) : (i += 1) { - js.JSPropertyNameAccumulatorAddName(props, property_name_refs[i]); + } else { + comptime var i: usize = 0; + inline while (i < property_name_refs.len) : (i += 1) { + js.JSPropertyNameAccumulatorAddName(props, property_name_refs[i]); + } } } + const ref_len = comptime function_name_refs.len; if (comptime function_name_refs.len > 0) { - comptime var j: usize = 0; if (!function_name_refs_set) { + comptime var j: usize = 0; function_name_refs_set = true; - inline while (j < function_name_refs.len) : (j += 1) { + inline while (j < ref_len) : (j += 1) { function_name_refs[j] = js.JSStringCreateStatic(function_names[j].ptr, function_names[j].len); } comptime j = 0; - } - inline while (j < function_name_refs.len) : (j += 1) { - js.JSPropertyNameAccumulatorAddName(props, function_name_refs[j]); + inline while (j < ref_len) : (j += 1) { + js.JSPropertyNameAccumulatorAddName(props, function_name_refs[j]); + } + } else { + comptime var j: usize = 0; + inline while (j < ref_len) : (j += 1) { + js.JSPropertyNameAccumulatorAddName(props, function_name_refs[j]); + } } } } @@ -1173,10 +1236,10 @@ pub fn NewClassWithInstanceType( .attributes = js.JSPropertyAttributes.kJSPropertyAttributeNone, }, ); - for (property_name_literals) |_, i| { + for (property_name_literals) |lit, i| { props[i] = brk2: { var static_prop = JSC.C.JSStaticValue{ - .name = property_names[i][0.. :0].ptr, + .name = lit.ptr[0..lit.len :0], .getProperty = null, .setProperty = null, .attributes = @intToEnum(js.JSPropertyAttributes, 0), @@ -1196,7 +1259,7 @@ pub fn NewClassWithInstanceType( // this madness is a workaround for stage1 compiler bugs fn generateDef(comptime ReturnType: type) ReturnType { - var count = 0; + var count: usize = 0; var def: js.JSClassDefinition = js.JSClassDefinition{ .version = 0, .attributes = js.JSClassAttributes.kJSClassAttributeNone, @@ -1216,80 +1279,80 @@ pub fn NewClassWithInstanceType( .hasInstance = null, .convertToType = null, }; - var __static_functions: [function_name_literals.len + 1]js.JSStaticFunction = undefined; for (__static_functions) |_, i| { __static_functions[i] = js.JSStaticFunction{ - .name = @intToPtr([*c]const u8, 0), + .name = "", .callAsFunction = null, .attributes = js.JSPropertyAttributes.kJSPropertyAttributeNone, }; } - for (function_name_literals) |function_name_literal, i| { - const is_read_only = options.read_only; + @setEvalBranchQuota(50_000); + const is_read_only = options.read_only; + + inline for (comptime function_name_literals) |function_name_literal| { + const CtxField = comptime @field(staticFunctions, function_name_literal); - _ = i; - switch (@typeInfo(@TypeOf(@field(staticFunctions, function_name_literal)))) { + switch (comptime @typeInfo(@TypeOf(CtxField))) { .Struct => { - const CtxField = @field(staticFunctions, function_name_literals[i]); - - if (strings.eqlComptime(function_name_literal, "constructor")) { - def.callAsConstructor = To.JS.Constructor(staticFunctions.constructor.rfn).rfn; - } else if (strings.eqlComptime(function_name_literal, "finalize")) { - def.finalize = To.JS.Finalize(ZigType, staticFunctions.finalize.rfn).rfn; - } else if (strings.eqlComptime(function_name_literal, "call")) { - def.callAsFunction = To.JS.Callback(ZigType, staticFunctions.call.rfn).rfn; - } else if (strings.eqlComptime(function_name_literal, "callAsFunction")) { + if (comptime strings.eqlComptime(function_name_literal, "constructor")) { + def.callAsConstructor = &To.JS.Constructor(staticFunctions.constructor.rfn).rfn; + } else if (comptime strings.eqlComptime(function_name_literal, "finalize")) { + def.finalize = &To.JS.Finalize(ZigType, staticFunctions.finalize.rfn).rfn; + } else if (comptime strings.eqlComptime(function_name_literal, "call")) { + def.callAsFunction = &To.JS.Callback(ZigType, staticFunctions.call.rfn).rfn; + } else if (comptime strings.eqlComptime(function_name_literal, "callAsFunction")) { const ctxfn = @field(staticFunctions, function_name_literal).rfn; - const Func: std.builtin.TypeInfo.Fn = @typeInfo(@TypeOf(ctxfn)).Fn; + const Func: std.builtin.Type.Fn = @typeInfo(@TypeOf(if (@typeInfo(@TypeOf(ctxfn)) == .Pointer) ctxfn.* else ctxfn)).Fn; - const PointerType = std.meta.Child(Func.args[0].arg_type.?); + const PointerType = std.meta.Child(Func.params[0].type.?); - def.callAsFunction = if (Func.calling_convention == .C) ctxfn else To.JS.Callback( + def.callAsFunction = &(if (Func.calling_convention == .C) ctxfn else To.JS.Callback( PointerType, ctxfn, - ).rfn; - } else if (strings.eqlComptime(function_name_literal, "hasProperty")) { + ).rfn); + } else if (comptime strings.eqlComptime(function_name_literal, "hasProperty")) { def.hasProperty = @field(staticFunctions, "hasProperty").rfn; - } else if (strings.eqlComptime(function_name_literal, "getProperty")) { + } else if (comptime strings.eqlComptime(function_name_literal, "getProperty")) { def.getProperty = @field(staticFunctions, "getProperty").rfn; - } else if (strings.eqlComptime(function_name_literal, "setProperty")) { + } else if (comptime strings.eqlComptime(function_name_literal, "setProperty")) { def.setProperty = @field(staticFunctions, "setProperty").rfn; - } else if (strings.eqlComptime(function_name_literal, "deleteProperty")) { - def.deleteProperty = @field(staticFunctions, "deleteProperty").rfn; - } else if (strings.eqlComptime(function_name_literal, "getPropertyNames")) { + } else if (comptime strings.eqlComptime(function_name_literal, "deleteProperty")) { + def.deleteProperty = &@field(staticFunctions, "deleteProperty").rfn; + } else if (comptime strings.eqlComptime(function_name_literal, "getPropertyNames")) { def.getPropertyNames = @field(staticFunctions, "getPropertyNames").rfn; - } else if (strings.eqlComptime(function_name_literal, "convertToType")) { + } else if (comptime strings.eqlComptime(function_name_literal, "convertToType")) { def.convertToType = @field(staticFunctions, "convertToType").rfn; - } else if (!@hasField(@TypeOf(CtxField), "is_dom_call")) { + } else if (comptime !@hasField(@TypeOf(CtxField), "is_dom_call")) { if (!@hasField(@TypeOf(CtxField), "rfn")) { @compileError("Expected " ++ options.name ++ "." ++ function_name_literal ++ " to have .rfn"); } const ctxfn = CtxField.rfn; - const Func: std.builtin.TypeInfo.Fn = @typeInfo(@TypeOf(ctxfn)).Fn; + const Func: std.builtin.Type.Fn = @typeInfo(@TypeOf(if (@typeInfo(@TypeOf(ctxfn)) == .Pointer) ctxfn.* else ctxfn)).Fn; var attributes: c_uint = @enumToInt(js.JSPropertyAttributes.kJSPropertyAttributeNone); - if (is_read_only or hasReadOnly(@TypeOf(CtxField))) { + if (comptime is_read_only or hasReadOnly(@TypeOf(CtxField))) { attributes |= @enumToInt(js.JSPropertyAttributes.kJSPropertyAttributeReadOnly); } - if (hasEnumerable(@TypeOf(CtxField)) and !CtxField.enumerable) { + if (comptime hasEnumerable(@TypeOf(CtxField)) and !CtxField.enumerable) { attributes |= @enumToInt(js.JSPropertyAttributes.kJSPropertyAttributeDontEnum); } - var PointerType = void; - - if (Func.args[0].arg_type.? != void) { - PointerType = std.meta.Child(Func.args[0].arg_type.?); - } + const PointerType = comptime brk: { + if (Func.params[0].type.? != void) { + break :brk std.meta.Child(Func.params[0].type.?); + } + break :brk void; + }; __static_functions[count] = js.JSStaticFunction{ - .name = @ptrCast([*c]const u8, function_names[i].ptr), - .callAsFunction = if (Func.calling_convention == .C) ctxfn else To.JS.Callback( + .name = std.meta.assumeSentinel(function_name_literal ++ [_]u8{0}, 0), + .callAsFunction = if (Func.calling_convention == .C) &CtxField.rfn else &To.JS.Callback( PointerType, - ctxfn, + if (@typeInfo(@TypeOf(ctxfn)) == .Pointer) ctxfn.* else ctxfn, ).rfn, .attributes = @intToEnum(js.JSPropertyAttributes, attributes), }; @@ -1298,16 +1361,16 @@ pub fn NewClassWithInstanceType( } }, .Fn => { - if (strings.eqlComptime(function_name_literal, "constructor")) { - def.callAsConstructor = To.JS.Constructor(staticFunctions.constructor).rfn; - } else if (strings.eqlComptime(function_name_literal, "finalize")) { - def.finalize = To.JS.Finalize(ZigType, staticFunctions.finalize).rfn; - } else if (strings.eqlComptime(function_name_literal, "call")) { - def.callAsFunction = To.JS.Callback(ZigType, staticFunctions.call).rfn; - } else if (strings.eqlComptime(function_name_literal, "getPropertyNames")) { - def.getPropertyNames = To.JS.Callback(ZigType, staticFunctions.getPropertyNames).rfn; - } else if (strings.eqlComptime(function_name_literal, "hasInstance")) { - def.hasInstance = staticFunctions.hasInstance; + if (comptime strings.eqlComptime(function_name_literal, "constructor")) { + def.callAsConstructor = &To.JS.Constructor(staticFunctions.constructor).rfn; + } else if (comptime strings.eqlComptime(function_name_literal, "finalize")) { + def.finalize = &To.JS.Finalize(ZigType, staticFunctions.finalize).rfn; + } else if (comptime strings.eqlComptime(function_name_literal, "call")) { + def.callAsFunction = &To.JS.Callback(ZigType, staticFunctions.call).rfn; + } else if (comptime strings.eqlComptime(function_name_literal, "getPropertyNames")) { + def.getPropertyNames = &To.JS.Callback(ZigType, staticFunctions.getPropertyNames).rfn; + } else if (comptime strings.eqlComptime(function_name_literal, "hasInstance")) { + def.hasInstance = &staticFunctions.hasInstance; } else { const attributes: js.JSPropertyAttributes = brk: { var base = @enumToInt(js.JSPropertyAttributes.kJSPropertyAttributeNone); @@ -1319,8 +1382,8 @@ pub fn NewClassWithInstanceType( }; __static_functions[count] = js.JSStaticFunction{ - .name = @ptrCast([*c]const u8, function_names[i].ptr), - .callAsFunction = To.JS.Callback( + .name = std.meta.assumeSentinel(function_name_literal ++ [_]u8{0}, 0), + .callAsFunction = &To.JS.Callback( ZigType, @field(staticFunctions, function_name_literal), ).rfn, @@ -1334,48 +1397,12 @@ pub fn NewClassWithInstanceType( } } - if (ReturnType == JSC.C.JSClassDefinition) { + if (comptime ReturnType == JSC.C.JSClassDefinition) { return def; } else { return __static_functions; } } - - const base_def_ = generateDef(JSC.C.JSClassDefinition); - const static_functions__: [function_name_literals.len + 1]js.JSStaticFunction = generateDef([function_name_literals.len + 1]js.JSStaticFunction); - const static_functions_ptr = &static_functions__; - const static_values_ptr = &static_properties; - const class_name_str: stringZ = options.name; - - const complete_definition = brk: { - var def = base_def_; - def.staticFunctions = static_functions_ptr; - if (options.no_inheritance) { - def.attributes = JSC.C.JSClassAttributes.kJSClassAttributeNoAutomaticPrototype; - } - if (property_names.len > 0) { - def.staticValues = static_values_ptr; - } - - def.className = class_name_str; - // def.getProperty = getPropertyCallback; - - if (def.callAsConstructor == null) { - def.callAsConstructor = throwInvalidConstructorError; - } - - if (def.callAsFunction == null) { - def.callAsFunction = throwInvalidFunctionError; - } - - if (def.getPropertyNames == null) { - def.getPropertyNames = getPropertyNames; - } - - if (!singleton and def.hasInstance == null) - def.hasInstance = customHasInstance; - break :brk def; - }; }; } @@ -1923,7 +1950,7 @@ pub const RefString = struct { allocator: std.mem.Allocator, ctx: ?*anyopaque = null, - onBeforeDeinit: ?Callback = null, + onBeforeDeinit: ?*const Callback = null, pub const Hash = u32; pub const Map = std.HashMap(Hash, *JSC.RefString, IdentityContext(Hash), 80); @@ -2077,14 +2104,11 @@ const FFI = JSC.FFI; pub const JSPrivateDataPtr = TaggedPointerUnion(.{ AttributeIterator, BigIntStats, - Blob, - Body, BuildError, Comment, DebugServer, DebugSSLServer, DescribeScope, - DirEnt, DocEnd, DocType, Element, @@ -2095,10 +2119,7 @@ pub const JSPrivateDataPtr = TaggedPointerUnion(.{ LazyPropertiesObject, ModuleNamespace, - NodeFS, - Request, ResolveError, - Response, Router, Server, @@ -2130,7 +2151,7 @@ pub const JSPropertyNameIterator = struct { pub fn getterWrap(comptime Container: type, comptime name: string) GetterType(Container) { return struct { const FunctionType = @TypeOf(@field(Container, name)); - const FunctionTypeInfo: std.builtin.TypeInfo.Fn = @typeInfo(FunctionType).Fn; + const FunctionTypeInfo: std.builtin.Type.Fn = @typeInfo(FunctionType).Fn; const ArgsTuple = std.meta.ArgsTuple(FunctionType); pub fn callback( @@ -2141,11 +2162,11 @@ pub fn getterWrap(comptime Container: type, comptime name: string) GetterType(Co exception: js.ExceptionRef, ) js.JSObjectRef { const result: JSValue = if (comptime std.meta.fields(ArgsTuple).len == 1) - @call(.{}, @field(Container, name), .{ + @call(.auto, @field(Container, name), .{ this, }) else - @call(.{}, @field(Container, name), .{ this, ctx.ptr() }); + @call(.auto, @field(Container, name), .{ this, ctx.ptr() }); if (!result.isUndefinedOrNull() and result.isError()) { exception.* = result.asObjectRef(); return null; @@ -2159,7 +2180,7 @@ pub fn getterWrap(comptime Container: type, comptime name: string) GetterType(Co pub fn setterWrap(comptime Container: type, comptime name: string) SetterType(Container) { return struct { const FunctionType = @TypeOf(@field(Container, name)); - const FunctionTypeInfo: std.builtin.TypeInfo.Fn = @typeInfo(FunctionType).Fn; + const FunctionTypeInfo: std.builtin.Type.Fn = @typeInfo(FunctionType).Fn; pub fn callback( this: *Container, @@ -2169,7 +2190,7 @@ pub fn setterWrap(comptime Container: type, comptime name: string) SetterType(Co value: js.JSValueRef, exception: js.ExceptionRef, ) bool { - @call(.{}, @field(Container, name), .{ this, JSC.JSValue.fromRef(value), exception, ctx.ptr() }); + @call(.auto, @field(Container, name), .{ this, JSC.JSValue.fromRef(value), exception, ctx.ptr() }); return exception.* == null; } }.callback; @@ -2370,7 +2391,7 @@ pub fn DOMCall( arguments_ptr: [*]const JSC.JSValue, arguments_len: usize, ) callconv(.C) JSValue { - return @call(.{}, @field(Container, functionName), .{ + return @call(.auto, @field(Container, functionName), .{ globalObject, thisValue, arguments_ptr[0..arguments_len], @@ -2382,8 +2403,8 @@ pub fn DOMCall( pub const Arguments = std.meta.ArgsTuple(Fastpath); pub const Export = shim.exportFunctions(.{ - .@"slowpath" = slowpath, - .@"fastpath" = fastpath, + .slowpath = slowpath, + .fastpath = fastpath, }); pub fn put(globalObject: *JSC.JSGlobalObject, value: JSValue) void { @@ -2421,14 +2442,14 @@ pub fn DOMCall( }, 1 => { try writer.writeAll(", "); - try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].field_type)); + try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].type)); try writer.writeAll("));\n"); }, 2 => { try writer.writeAll(", "); - try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].field_type)); + try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].type)); try writer.writeAll(", "); - try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[3].field_type)); + try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[3].type)); try writer.writeAll("));\n"); }, else => @compileError("Must be <= 3 arguments"), @@ -2449,14 +2470,14 @@ pub fn DOMCall( }, 1 => { try writer.writeAll(", "); - try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].field_type)); + try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].type)); try writer.writeAll(" arg1)) {\n"); }, 2 => { try writer.writeAll(", "); - try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].field_type)); + try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].type)); try writer.writeAll(" arg1, "); - try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[3].field_type)); + try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[3].type)); try writer.writeAll(" arg2)) {\n"); }, else => @compileError("Must be <= 3 arguments"), @@ -2543,14 +2564,14 @@ pub fn DOMCall( 0 => {}, 1 => { try writer.writeAll(",\n "); - try writer.writeAll(DOMCallArgumentType(Fields[2].field_type)); + try writer.writeAll(DOMCallArgumentType(Fields[2].type)); try writer.writeAll("\n "); }, 2 => { try writer.writeAll(",\n "); - try writer.writeAll(DOMCallArgumentType(Fields[2].field_type)); + try writer.writeAll(DOMCallArgumentType(Fields[2].type)); try writer.writeAll(",\n "); - try writer.writeAll(DOMCallArgumentType(Fields[3].field_type)); + try writer.writeAll(DOMCallArgumentType(Fields[3].type)); try writer.writeAll("\n "); }, else => @compileError("Must be <= 3 arguments"), @@ -2608,7 +2629,7 @@ pub fn wrapWithHasContainer( ) MethodType(Container, has_container) { return struct { const FunctionType = @TypeOf(@field(Container, name)); - const FunctionTypeInfo: std.builtin.TypeInfo.Fn = @typeInfo(FunctionType).Fn; + const FunctionTypeInfo: std.builtin.Type.Fn = @typeInfo(FunctionType).Fn; const Args = std.meta.ArgsTuple(FunctionType); const eater = if (auto_protect) JSC.Node.ArgumentsSlice.protectEatNext else JSC.Node.ArgumentsSlice.nextEat; @@ -2624,8 +2645,8 @@ pub fn wrapWithHasContainer( var args: Args = undefined; comptime var i: usize = 0; - inline while (i < FunctionTypeInfo.args.len) : (i += 1) { - const ArgType = comptime FunctionTypeInfo.args[i].arg_type.?; + inline while (i < FunctionTypeInfo.params.len) : (i += 1) { + const ArgType = comptime FunctionTypeInfo.params[i].type.?; switch (comptime ArgType) { *Container => { @@ -2753,7 +2774,7 @@ pub fn wrapWithHasContainer( } } - var result: JSValue = @call(.{}, @field(Container, name), args); + var result: JSValue = @call(.auto, @field(Container, name), args); if (!result.isEmptyOrUndefinedOrNull() and result.isError()) { exception.* = result.asObjectRef(); iter.deinit(); @@ -2796,7 +2817,7 @@ pub fn wrapInstanceMethod( ) InstanceMethodType(Container) { return struct { const FunctionType = @TypeOf(@field(Container, name)); - const FunctionTypeInfo: std.builtin.TypeInfo.Fn = @typeInfo(FunctionType).Fn; + const FunctionTypeInfo: std.builtin.Type.Fn = @typeInfo(FunctionType).Fn; const Args = std.meta.ArgsTuple(FunctionType); const eater = if (auto_protect) JSC.Node.ArgumentsSlice.protectEatNext else JSC.Node.ArgumentsSlice.nextEat; @@ -2805,13 +2826,13 @@ pub fn wrapInstanceMethod( globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame, ) callconv(.C) JSC.JSValue { - const arguments = callframe.arguments(FunctionTypeInfo.args.len); + const arguments = callframe.arguments(FunctionTypeInfo.params.len); var iter = JSC.Node.ArgumentsSlice.init(globalThis.bunVM(), arguments.ptr[0..arguments.len]); var args: Args = undefined; comptime var i: usize = 0; - inline while (i < FunctionTypeInfo.args.len) : (i += 1) { - const ArgType = comptime FunctionTypeInfo.args[i].arg_type.?; + inline while (i < FunctionTypeInfo.params.len) : (i += 1) { + const ArgType = comptime FunctionTypeInfo.params[i].type.?; switch (comptime ArgType) { *Container => { @@ -2930,7 +2951,7 @@ pub fn wrapInstanceMethod( defer iter.deinit(); - return @call(.{}, @field(Container, name), args); + return @call(.auto, @field(Container, name), args); } }.method; } @@ -2942,7 +2963,7 @@ pub fn wrapStaticMethod( ) JSC.Codegen.StaticCallbackType { return struct { const FunctionType = @TypeOf(@field(Container, name)); - const FunctionTypeInfo: std.builtin.TypeInfo.Fn = @typeInfo(FunctionType).Fn; + const FunctionTypeInfo: std.builtin.Type.Fn = @typeInfo(FunctionType).Fn; const Args = std.meta.ArgsTuple(FunctionType); const eater = if (auto_protect) JSC.Node.ArgumentsSlice.protectEatNext else JSC.Node.ArgumentsSlice.nextEat; @@ -2950,13 +2971,13 @@ pub fn wrapStaticMethod( globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame, ) callconv(.C) JSC.JSValue { - const arguments = callframe.arguments(FunctionTypeInfo.args.len); + const arguments = callframe.arguments(FunctionTypeInfo.params.len); var iter = JSC.Node.ArgumentsSlice.init(globalThis.bunVM(), arguments.ptr[0..arguments.len]); var args: Args = undefined; comptime var i: usize = 0; - inline while (i < FunctionTypeInfo.args.len) : (i += 1) { - const ArgType = comptime FunctionTypeInfo.args[i].arg_type.?; + inline while (i < FunctionTypeInfo.params.len) : (i += 1) { + const ArgType = comptime FunctionTypeInfo.params[i].type.?; switch (comptime ArgType) { *JSC.JSGlobalObject => { @@ -3072,59 +3093,11 @@ pub fn wrapStaticMethod( defer iter.deinit(); - return @call(.{}, @field(Container, name), args); + return @call(.auto, @field(Container, name), args); } }.method; } -pub fn cachedBoundFunction(comptime name: [:0]const u8, comptime callback: anytype) (fn ( - _: void, - ctx: js.JSContextRef, - _: js.JSValueRef, - _: js.JSStringRef, - _: js.ExceptionRef, -) js.JSValueRef) { - return struct { - const name_ = name; - pub fn call( - arg2: js.JSContextRef, - arg3: js.JSObjectRef, - arg4: js.JSObjectRef, - arg5: usize, - arg6: [*c]const js.JSValueRef, - arg7: js.ExceptionRef, - ) callconv(.C) js.JSObjectRef { - return callback( - {}, - arg2, - arg3, - arg4, - arg6[0..arg5], - arg7, - ); - } - - pub fn getter( - _: void, - ctx: js.JSContextRef, - _: js.JSValueRef, - _: js.JSStringRef, - _: js.ExceptionRef, - ) js.JSValueRef { - const name_slice = std.mem.span(name_); - var existing = ctx.ptr().getCachedObject(&ZigString.init(name_slice)); - if (existing.isEmpty()) { - return ctx.ptr().putCachedObject( - &ZigString.init(name_slice), - JSValue.fromRef(JSC.C.JSObjectMakeFunctionWithCallback(ctx, JSC.C.JSStringCreateStatic(name_slice.ptr, name_slice.len), call)), - ).asObjectRef(); - } - - return existing.asObjectRef(); - } - }.getter; -} - /// Track whether an object should keep the event loop alive pub const Ref = struct { has: bool = false, @@ -3163,7 +3136,7 @@ pub const PollRef = struct { /// Make calling ref() on this poll into a no-op. pub fn disable(this: *PollRef) void { - this.unref(JSC.VirtualMachine.vm); + this.unref(JSC.VirtualMachine.get()); this.status = .done; } @@ -3218,7 +3191,7 @@ pub const FilePoll = struct { fd: u32 = invalid_fd, flags: Flags.Set = Flags.Set{}, - owner: Owner = Deactivated.owner, + owner: Owner = undefined, /// We re-use FilePoll objects to avoid allocating new ones. /// @@ -3234,7 +3207,7 @@ pub const FilePoll = struct { const BufferedInput = Subprocess.BufferedInput; const BufferedOutput = Subprocess.BufferedOutput; const Deactivated = opaque { - pub var owner = Owner.init(@intToPtr(*Deactivated, @as(usize, 0xDEADBEEF))); + pub var owner: Owner = Owner.init(@intToPtr(*Deactivated, @as(usize, 0xDEADBEEF))); }; pub const Owner = bun.TaggedPointerUnion(.{ @@ -3300,7 +3273,7 @@ pub const FilePoll = struct { } pub fn deinit(this: *FilePoll) void { - var vm = JSC.VirtualMachine.vm; + var vm = JSC.VirtualMachine.get(); this.deinitWithVM(vm); } diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h index 21e6d1185..15a1d9111 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h @@ -18,4 +18,6 @@ std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForExpectConstructor;std: std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForTextDecoderConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForRequest; std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForRequestConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForResponse; std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForResponseConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBlob; -std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBlobConstructor;
\ No newline at end of file +std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBlobConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForDirent; +std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForDirentConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForNodeJSFS; +std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForNodeJSFSConstructor;
\ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h index f8e81b0c1..273a699c5 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h @@ -18,4 +18,6 @@ std::unique_ptr<IsoSubspace> m_subspaceForExpectConstructor;std::unique_ptr<IsoS std::unique_ptr<IsoSubspace> m_subspaceForTextDecoderConstructor;std::unique_ptr<IsoSubspace> m_subspaceForRequest; std::unique_ptr<IsoSubspace> m_subspaceForRequestConstructor;std::unique_ptr<IsoSubspace> m_subspaceForResponse; std::unique_ptr<IsoSubspace> m_subspaceForResponseConstructor;std::unique_ptr<IsoSubspace> m_subspaceForBlob; -std::unique_ptr<IsoSubspace> m_subspaceForBlobConstructor;
\ No newline at end of file +std::unique_ptr<IsoSubspace> m_subspaceForBlobConstructor;std::unique_ptr<IsoSubspace> m_subspaceForDirent; +std::unique_ptr<IsoSubspace> m_subspaceForDirentConstructor;std::unique_ptr<IsoSubspace> m_subspaceForNodeJSFS; +std::unique_ptr<IsoSubspace> m_subspaceForNodeJSFSConstructor;
\ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h index f2d881bb5..cefb58178 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h @@ -117,4 +117,16 @@ JSC::Structure* JSBlobStructure() { return m_JSBlob.getInitializedOnMainThread(t JSC::JSValue JSBlobPrototype() { return m_JSBlob.prototypeInitializedOnMainThread(this); } JSC::LazyClassStructure m_JSBlob; bool hasJSBlobSetterValue { false }; - mutable JSC::WriteBarrier<JSC::Unknown> m_JSBlobSetterValue;
\ No newline at end of file + mutable JSC::WriteBarrier<JSC::Unknown> m_JSBlobSetterValue; +JSC::Structure* JSDirentStructure() { return m_JSDirent.getInitializedOnMainThread(this); } + JSC::JSObject* JSDirentConstructor() { return m_JSDirent.constructorInitializedOnMainThread(this); } + JSC::JSValue JSDirentPrototype() { return m_JSDirent.prototypeInitializedOnMainThread(this); } + JSC::LazyClassStructure m_JSDirent; + bool hasJSDirentSetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSDirentSetterValue; +JSC::Structure* JSNodeJSFSStructure() { return m_JSNodeJSFS.getInitializedOnMainThread(this); } + JSC::JSObject* JSNodeJSFSConstructor() { return m_JSNodeJSFS.constructorInitializedOnMainThread(this); } + JSC::JSValue JSNodeJSFSPrototype() { return m_JSNodeJSFS.prototypeInitializedOnMainThread(this); } + JSC::LazyClassStructure m_JSNodeJSFS; + bool hasJSNodeJSFSSetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSNodeJSFSSetterValue;
\ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h index ade20e72a..64e0bb9b2 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h @@ -119,6 +119,18 @@ void GlobalObject::initGeneratedLazyClasses() { init.setStructure(WebCore::JSBlob::createStructure(init.vm, init.global, init.prototype)); init.setConstructor(WebCore::JSBlob::createConstructor(init.vm, init.global, init.prototype)); }); + m_JSDirent.initLater( + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSDirent::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSDirent::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSDirent::createConstructor(init.vm, init.global, init.prototype)); + }); + m_JSNodeJSFS.initLater( + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSNodeJSFS::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSNodeJSFS::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSNodeJSFS::createConstructor(init.vm, init.global, init.prototype)); + }); } template<typename Visitor> void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& visitor) @@ -143,4 +155,6 @@ void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& thisObject->m_JSRequest.visit(visitor); visitor.append(thisObject->m_JSRequestSetterValue); thisObject->m_JSResponse.visit(visitor); visitor.append(thisObject->m_JSResponseSetterValue); thisObject->m_JSBlob.visit(visitor); visitor.append(thisObject->m_JSBlobSetterValue); + thisObject->m_JSDirent.visit(visitor); visitor.append(thisObject->m_JSDirentSetterValue); + thisObject->m_JSNodeJSFS.visit(visitor); visitor.append(thisObject->m_JSNodeJSFSSetterValue); }
\ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp index e3fb6123f..c80251c13 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.cpp +++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp @@ -8961,5 +8961,2307 @@ extern "C" EncodedJSValue Blob__create(Zig::GlobalObject* globalObject, void* pt return JSValue::encode(instance); } +class JSDirentPrototype final : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + + static JSDirentPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure) + { + JSDirentPrototype* ptr = new (NotNull, JSC::allocateCell<JSDirentPrototype>(vm)) JSDirentPrototype(vm, globalObject, structure); + ptr->finishCreation(vm, globalObject); + return ptr; + } + + DECLARE_INFO; + template<typename CellType, JSC::SubspaceAccess> + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + return &vm.plainObjectSpace(); + } + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); + } + +private: + JSDirentPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) + : Base(vm, structure) + { + } + + void finishCreation(JSC::VM&, JSC::JSGlobalObject*); +}; + +class JSDirentConstructor final : public JSC::InternalFunction { +public: + using Base = JSC::InternalFunction; + static JSDirentConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSDirentPrototype* prototype); + + static constexpr unsigned StructureFlags = Base::StructureFlags; + static constexpr bool needsDestruction = false; + + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info()); + } + + template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl<JSDirentConstructor, WebCore::UseCustomHeapCellType::No>( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForDirentConstructor.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForDirentConstructor = WTFMove(space); }, + [](auto& spaces) { return spaces.m_subspaceForDirentConstructor.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForDirentConstructor = WTFMove(space); }); + } + + void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSDirentPrototype* prototype); + + // Must be defined for each specialization class. + static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*); + + DECLARE_EXPORT_INFO; + +private: + JSDirentConstructor(JSC::VM& vm, JSC::Structure* structure); + void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSDirentPrototype* prototype); +}; + +extern "C" void* DirentClass__construct(JSC::JSGlobalObject*, JSC::CallFrame*); +JSC_DECLARE_CUSTOM_GETTER(jsDirentConstructor); +extern "C" void DirentClass__finalize(void*); + +extern "C" EncodedJSValue DirentPrototype__isBlockDevice(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(DirentPrototype__isBlockDeviceCallback); + +extern "C" EncodedJSValue DirentPrototype__isCharacterDevice(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(DirentPrototype__isCharacterDeviceCallback); + +extern "C" EncodedJSValue DirentPrototype__isDirectory(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(DirentPrototype__isDirectoryCallback); + +extern "C" EncodedJSValue DirentPrototype__isFIFO(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(DirentPrototype__isFIFOCallback); + +extern "C" EncodedJSValue DirentPrototype__isFile(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(DirentPrototype__isFileCallback); + +extern "C" EncodedJSValue DirentPrototype__isSocket(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(DirentPrototype__isSocketCallback); + +extern "C" EncodedJSValue DirentPrototype__isSymbolicLink(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(DirentPrototype__isSymbolicLinkCallback); + +extern "C" JSC::EncodedJSValue DirentPrototype__getName(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(DirentPrototype__nameGetterWrap); + +STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSDirentPrototype, JSDirentPrototype::Base); + +static const HashTableValue JSDirentPrototypeTableValues[] = { + { "isBlockDevice"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, DirentPrototype__isBlockDeviceCallback, 0 } }, + { "isCharacterDevice"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, DirentPrototype__isCharacterDeviceCallback, 0 } }, + { "isDirectory"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, DirentPrototype__isDirectoryCallback, 0 } }, + { "isFIFO"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, DirentPrototype__isFIFOCallback, 0 } }, + { "isFile"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, DirentPrototype__isFileCallback, 0 } }, + { "isSocket"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, DirentPrototype__isSocketCallback, 0 } }, + { "isSymbolicLink"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, DirentPrototype__isSymbolicLinkCallback, 0 } }, + { "name"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, DirentPrototype__nameGetterWrap, 0 } } +}; + +const ClassInfo JSDirentPrototype::s_info = { "Dirent"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDirentPrototype) }; + +JSC_DEFINE_CUSTOM_GETTER(jsDirentConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto* prototype = jsDynamicCast<JSDirentPrototype*>(JSValue::decode(thisValue)); + + if (UNLIKELY(!prototype)) + return throwVMTypeError(lexicalGlobalObject, throwScope); + return JSValue::encode(globalObject->JSDirentConstructor()); +} + +JSC_DEFINE_HOST_FUNCTION(DirentPrototype__isBlockDeviceCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSDirent* thisObject = jsDynamicCast<JSDirent*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return DirentPrototype__isBlockDevice(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(DirentPrototype__isCharacterDeviceCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSDirent* thisObject = jsDynamicCast<JSDirent*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return DirentPrototype__isCharacterDevice(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(DirentPrototype__isDirectoryCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSDirent* thisObject = jsDynamicCast<JSDirent*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return DirentPrototype__isDirectory(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(DirentPrototype__isFIFOCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSDirent* thisObject = jsDynamicCast<JSDirent*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return DirentPrototype__isFIFO(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(DirentPrototype__isFileCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSDirent* thisObject = jsDynamicCast<JSDirent*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return DirentPrototype__isFile(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(DirentPrototype__isSocketCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSDirent* thisObject = jsDynamicCast<JSDirent*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return DirentPrototype__isSocket(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(DirentPrototype__isSymbolicLinkCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSDirent* thisObject = jsDynamicCast<JSDirent*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return DirentPrototype__isSymbolicLink(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_CUSTOM_GETTER(DirentPrototype__nameGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSDirent* thisObject = jsCast<JSDirent*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + if (JSValue cachedValue = thisObject->m_name.get()) + return JSValue::encode(cachedValue); + + JSC::JSValue result = JSC::JSValue::decode( + DirentPrototype__getName(thisObject->wrapped(), globalObject)); + RETURN_IF_EXCEPTION(throwScope, {}); + thisObject->m_name.set(vm, thisObject, result); + RELEASE_AND_RETURN(throwScope, JSValue::encode(result)); +} + +extern "C" void DirentPrototype__nameSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + auto& vm = globalObject->vm(); + auto* thisObject = jsCast<JSDirent*>(JSValue::decode(thisValue)); + thisObject->m_name.set(vm, thisObject, JSValue::decode(value)); +} + +extern "C" EncodedJSValue DirentPrototype__nameGetCachedValue(JSC::EncodedJSValue thisValue) +{ + auto* thisObject = jsCast<JSDirent*>(JSValue::decode(thisValue)); + return JSValue::encode(thisObject->m_name.get()); +} + +void JSDirentPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) +{ + Base::finishCreation(vm); + reifyStaticProperties(vm, JSDirent::info(), JSDirentPrototypeTableValues, *this); + JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); +} + +void JSDirentConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSDirentPrototype* prototype) +{ + Base::finishCreation(vm, 0, "Dirent"_s, PropertyAdditionMode::WithoutStructureTransition); + + putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); + ASSERT(inherits(info())); +} + +JSDirentConstructor::JSDirentConstructor(JSC::VM& vm, JSC::Structure* structure) + : Base(vm, structure, construct, construct) +{ +} + +JSDirentConstructor* JSDirentConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSDirentPrototype* prototype) +{ + JSDirentConstructor* ptr = new (NotNull, JSC::allocateCell<JSDirentConstructor>(vm)) JSDirentConstructor(vm, structure); + ptr->finishCreation(vm, globalObject, prototype); + return ptr; +} + +JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDirentConstructor::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + JSC::VM& vm = globalObject->vm(); + JSObject* newTarget = asObject(callFrame->newTarget()); + auto* constructor = globalObject->JSDirentConstructor(); + Structure* structure = globalObject->JSDirentStructure(); + if (constructor != newTarget) { + auto scope = DECLARE_THROW_SCOPE(vm); + + auto* functionGlobalObject = reinterpret_cast<Zig::GlobalObject*>( + // ShadowRealm functions belong to a different global object. + getFunctionRealm(globalObject, newTarget)); + RETURN_IF_EXCEPTION(scope, {}); + structure = InternalFunction::createSubclassStructure( + globalObject, + newTarget, + functionGlobalObject->JSDirentStructure()); + } + + void* ptr = DirentClass__construct(globalObject, callFrame); + + if (UNLIKELY(!ptr)) { + return JSValue::encode(JSC::jsUndefined()); + } + + JSDirent* instance = JSDirent::create(vm, globalObject, structure, ptr); + + return JSValue::encode(instance); +} + +void JSDirentConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSDirentPrototype* prototype) +{ +} + +const ClassInfo JSDirentConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDirentConstructor) }; + +extern "C" EncodedJSValue Dirent__getConstructor(Zig::GlobalObject* globalObject) +{ + return JSValue::encode(globalObject->JSDirentConstructor()); +} + +JSDirent::~JSDirent() +{ + if (m_ctx) { + DirentClass__finalize(m_ctx); + } +} +void JSDirent::destroy(JSCell* cell) +{ + static_cast<JSDirent*>(cell)->JSDirent::~JSDirent(); +} + +const ClassInfo JSDirent::s_info = { "Dirent"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDirent) }; + +void JSDirent::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + ASSERT(inherits(info())); +} + +JSDirent* JSDirent::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) +{ + JSDirent* ptr = new (NotNull, JSC::allocateCell<JSDirent>(vm)) JSDirent(vm, structure, ctx); + ptr->finishCreation(vm); + return ptr; +} + +extern "C" void* Dirent__fromJS(JSC::EncodedJSValue value) +{ + JSC::JSValue decodedValue = JSC::JSValue::decode(value); + if (!decodedValue || decodedValue.isUndefinedOrNull()) + return nullptr; + + JSDirent* object = JSC::jsDynamicCast<JSDirent*>(decodedValue); + + if (!object) + return nullptr; + + return object->wrapped(); +} + +extern "C" bool Dirent__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr) +{ + JSDirent* object = JSC::jsDynamicCast<JSDirent*>(JSValue::decode(value)); + if (!object) + return false; + + object->m_ctx = ptr; + return true; +} + +extern "C" const size_t Dirent__ptrOffset = JSDirent::offsetOfWrapped(); + +void JSDirent::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) +{ + auto* thisObject = jsCast<JSDirent*>(cell); + if (void* wrapped = thisObject->wrapped()) { + // if (thisObject->scriptExecutionContext()) + // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); + } + Base::analyzeHeap(cell, analyzer); +} + +JSObject* JSDirent::createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype) +{ + return WebCore::JSDirentConstructor::create(vm, globalObject, WebCore::JSDirentConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()), jsCast<WebCore::JSDirentPrototype*>(prototype)); +} + +JSObject* JSDirent::createPrototype(VM& vm, JSDOMGlobalObject* globalObject) +{ + return JSDirentPrototype::create(vm, globalObject, JSDirentPrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); +} + +extern "C" EncodedJSValue Dirent__create(Zig::GlobalObject* globalObject, void* ptr) +{ + auto& vm = globalObject->vm(); + JSC::Structure* structure = globalObject->JSDirentStructure(); + JSDirent* instance = JSDirent::create(vm, globalObject, structure, ptr); + + return JSValue::encode(instance); +} + +template<typename Visitor> +void JSDirent::visitChildrenImpl(JSCell* cell, Visitor& visitor) +{ + JSDirent* thisObject = jsCast<JSDirent*>(cell); + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + Base::visitChildren(thisObject, visitor); + + visitor.append(thisObject->m_name); +} + +DEFINE_VISIT_CHILDREN(JSDirent); + +template<typename Visitor> +void JSDirent::visitAdditionalChildren(Visitor& visitor) +{ + JSDirent* thisObject = this; + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + + visitor.append(thisObject->m_name); + ; +} + +DEFINE_VISIT_ADDITIONAL_CHILDREN(JSDirent); + +template<typename Visitor> +void JSDirent::visitOutputConstraintsImpl(JSCell* cell, Visitor& visitor) +{ + JSDirent* thisObject = jsCast<JSDirent*>(cell); + ASSERT_GC_OBJECT_INHERITS(thisObject, info()); + thisObject->visitAdditionalChildren<Visitor>(visitor); +} + +DEFINE_VISIT_OUTPUT_CONSTRAINTS(JSDirent); +class JSNodeJSFSPrototype final : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + + static JSNodeJSFSPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure) + { + JSNodeJSFSPrototype* ptr = new (NotNull, JSC::allocateCell<JSNodeJSFSPrototype>(vm)) JSNodeJSFSPrototype(vm, globalObject, structure); + ptr->finishCreation(vm, globalObject); + return ptr; + } + + DECLARE_INFO; + template<typename CellType, JSC::SubspaceAccess> + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + return &vm.plainObjectSpace(); + } + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); + } + +private: + JSNodeJSFSPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) + : Base(vm, structure) + { + } + + void finishCreation(JSC::VM&, JSC::JSGlobalObject*); +}; + +class JSNodeJSFSConstructor final : public JSC::InternalFunction { +public: + using Base = JSC::InternalFunction; + static JSNodeJSFSConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSNodeJSFSPrototype* prototype); + + static constexpr unsigned StructureFlags = Base::StructureFlags; + static constexpr bool needsDestruction = false; + + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info()); + } + + template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl<JSNodeJSFSConstructor, WebCore::UseCustomHeapCellType::No>( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForNodeJSFSConstructor.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForNodeJSFSConstructor = WTFMove(space); }, + [](auto& spaces) { return spaces.m_subspaceForNodeJSFSConstructor.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForNodeJSFSConstructor = WTFMove(space); }); + } + + void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSNodeJSFSPrototype* prototype); + + // Must be defined for each specialization class. + static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*); + + DECLARE_EXPORT_INFO; + +private: + JSNodeJSFSConstructor(JSC::VM& vm, JSC::Structure* structure); + void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSNodeJSFSPrototype* prototype); +}; + +extern "C" void* NodeJSFSClass__construct(JSC::JSGlobalObject*, JSC::CallFrame*); +JSC_DECLARE_CUSTOM_GETTER(jsNodeJSFSConstructor); +extern "C" void NodeJSFSClass__finalize(void*); + +extern "C" EncodedJSValue NodeJSFSPrototype__access(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__accessCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__accessSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__accessSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__appendFile(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__appendFileCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__appendFileSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__appendFileSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__chmod(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__chmodCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__chmodSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__chmodSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__chown(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__chownCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__chownSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__chownSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__close(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__closeCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__closeSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__closeSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__copyFile(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__copyFileCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__copyFileSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__copyFileSyncCallback); + +extern "C" JSC::EncodedJSValue NodeJSFSPrototype__getDirent(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(NodeJSFSPrototype__DirentGetterWrap); + +extern "C" EncodedJSValue NodeJSFSPrototype__exists(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__existsCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__existsSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__existsSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__fchmod(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__fchmodCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__fchmodSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__fchmodSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__fchown(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__fchownCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__fchownSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__fchownSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__fdatasync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__fdatasyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__fdatasyncSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__fdatasyncSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__fstat(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__fstatCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__fstatSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__fstatSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__fsync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__fsyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__fsyncSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__fsyncSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__ftruncate(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__ftruncateCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__ftruncateSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__ftruncateSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__futimes(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__futimesCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__futimesSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__futimesSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__lchmod(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__lchmodCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__lchmodSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__lchmodSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__lchown(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__lchownCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__lchownSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__lchownSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__link(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__linkCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__linkSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__linkSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__lstat(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__lstatCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__lstatSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__lstatSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__lutimes(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__lutimesCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__lutimesSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__lutimesSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__mkdir(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__mkdirCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__mkdirSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__mkdirSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__mkdtemp(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__mkdtempCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__mkdtempSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__mkdtempSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__open(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__openCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__opendir(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__opendirCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__opendirSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__opendirSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__openSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__openSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__read(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__readCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__readdir(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__readdirCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__readdirSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__readdirSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__readFile(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__readFileCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__readFileSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__readFileSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__readlink(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__readlinkCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__readlinkSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__readlinkSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__readSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__readSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__readv(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__readvCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__readvSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__readvSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__realpath(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__realpathCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__realpathSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__realpathSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__rename(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__renameCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__renameSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__renameSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__rm(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__rmCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__rmdir(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__rmdirCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__rmdirSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__rmdirSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__rmSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__rmSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__stat(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__statCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__statSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__statSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__symlink(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__symlinkCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__symlinkSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__symlinkSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__truncate(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__truncateCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__truncateSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__truncateSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__unlink(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__unlinkCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__unlinkSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__unlinkSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__utimes(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__utimesCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__utimesSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__utimesSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__write(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__writeCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__writeFile(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__writeFileCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__writeFileSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__writeFileSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__writeSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__writeSyncCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__writev(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__writevCallback); + +extern "C" EncodedJSValue NodeJSFSPrototype__writevSync(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); +JSC_DECLARE_HOST_FUNCTION(NodeJSFSPrototype__writevSyncCallback); + +STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSNodeJSFSPrototype, JSNodeJSFSPrototype::Base); + +static const HashTableValue JSNodeJSFSPrototypeTableValues[] = { + { "access"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__accessCallback, 3 } }, + { "accessSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__accessSyncCallback, 2 } }, + { "appendFile"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__appendFileCallback, 4 } }, + { "appendFileSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__appendFileSyncCallback, 3 } }, + { "chmod"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__chmodCallback, 3 } }, + { "chmodSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__chmodSyncCallback, 2 } }, + { "chown"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__chownCallback, 4 } }, + { "chownSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__chownSyncCallback, 3 } }, + { "close"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__closeCallback, 1 } }, + { "closeSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__closeSyncCallback, 1 } }, + { "copyFile"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__copyFileCallback, 4 } }, + { "copyFileSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__copyFileSyncCallback, 3 } }, + { "Dirent"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, NodeJSFSPrototype__DirentGetterWrap, 0 } }, + { "exists"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__existsCallback, 2 } }, + { "existsSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__existsSyncCallback, 1 } }, + { "fchmod"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__fchmodCallback, 3 } }, + { "fchmodSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__fchmodSyncCallback, 2 } }, + { "fchown"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__fchownCallback, 4 } }, + { "fchownSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__fchownSyncCallback, 3 } }, + { "fdatasync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__fdatasyncCallback, 2 } }, + { "fdatasyncSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__fdatasyncSyncCallback, 1 } }, + { "fstat"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__fstatCallback, 1 } }, + { "fstatSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__fstatSyncCallback, 1 } }, + { "fsync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__fsyncCallback, 2 } }, + { "fsyncSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__fsyncSyncCallback, 1 } }, + { "ftruncate"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__ftruncateCallback, 1 } }, + { "ftruncateSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__ftruncateSyncCallback, 1 } }, + { "futimes"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__futimesCallback, 4 } }, + { "futimesSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__futimesSyncCallback, 3 } }, + { "lchmod"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__lchmodCallback, 3 } }, + { "lchmodSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__lchmodSyncCallback, 2 } }, + { "lchown"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__lchownCallback, 4 } }, + { "lchownSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__lchownSyncCallback, 3 } }, + { "link"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__linkCallback, 3 } }, + { "linkSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__linkSyncCallback, 2 } }, + { "lstat"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__lstatCallback, 1 } }, + { "lstatSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__lstatSyncCallback, 1 } }, + { "lutimes"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__lutimesCallback, 4 } }, + { "lutimesSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__lutimesSyncCallback, 3 } }, + { "mkdir"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__mkdirCallback, 3 } }, + { "mkdirSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__mkdirSyncCallback, 2 } }, + { "mkdtemp"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__mkdtempCallback, 3 } }, + { "mkdtempSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__mkdtempSyncCallback, 2 } }, + { "open"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__openCallback, 4 } }, + { "opendir"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__opendirCallback, 3 } }, + { "opendirSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__opendirSyncCallback, 2 } }, + { "openSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__openSyncCallback, 3 } }, + { "read"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__readCallback, 6 } }, + { "readdir"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__readdirCallback, 3 } }, + { "readdirSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__readdirSyncCallback, 2 } }, + { "readFile"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__readFileCallback, 3 } }, + { "readFileSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__readFileSyncCallback, 2 } }, + { "readlink"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__readlinkCallback, 3 } }, + { "readlinkSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__readlinkSyncCallback, 2 } }, + { "readSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__readSyncCallback, 5 } }, + { "readv"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__readvCallback, 4 } }, + { "readvSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__readvSyncCallback, 3 } }, + { "realpath"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__realpathCallback, 3 } }, + { "realpathSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__realpathSyncCallback, 2 } }, + { "rename"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__renameCallback, 3 } }, + { "renameSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__renameSyncCallback, 2 } }, + { "rm"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__rmCallback, 3 } }, + { "rmdir"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__rmdirCallback, 3 } }, + { "rmdirSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__rmdirSyncCallback, 2 } }, + { "rmSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__rmSyncCallback, 2 } }, + { "stat"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__statCallback, 1 } }, + { "statSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__statSyncCallback, 1 } }, + { "symlink"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__symlinkCallback, 4 } }, + { "symlinkSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__symlinkSyncCallback, 3 } }, + { "truncate"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__truncateCallback, 3 } }, + { "truncateSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__truncateSyncCallback, 2 } }, + { "unlink"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__unlinkCallback, 2 } }, + { "unlinkSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__unlinkSyncCallback, 1 } }, + { "utimes"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__utimesCallback, 4 } }, + { "utimesSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__utimesSyncCallback, 3 } }, + { "write"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__writeCallback, 6 } }, + { "writeFile"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__writeFileCallback, 4 } }, + { "writeFileSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__writeFileSyncCallback, 3 } }, + { "writeSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__writeSyncCallback, 5 } }, + { "writev"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__writevCallback, 4 } }, + { "writevSync"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, NodeJSFSPrototype__writevSyncCallback, 3 } } +}; + +const ClassInfo JSNodeJSFSPrototype::s_info = { "NodeJSFS"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSNodeJSFSPrototype) }; + +JSC_DEFINE_CUSTOM_GETTER(jsNodeJSFSConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName)) +{ + VM& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + auto* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto* prototype = jsDynamicCast<JSNodeJSFSPrototype*>(JSValue::decode(thisValue)); + + if (UNLIKELY(!prototype)) + return throwVMTypeError(lexicalGlobalObject, throwScope); + return JSValue::encode(globalObject->JSNodeJSFSConstructor()); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__accessCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__access(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__accessSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__accessSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__appendFileCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__appendFile(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__appendFileSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__appendFileSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__chmodCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__chmod(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__chmodSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__chmodSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__chownCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__chown(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__chownSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__chownSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__closeCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__close(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__closeSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__closeSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__copyFileCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__copyFile(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__copyFileSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__copyFileSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_CUSTOM_GETTER(NodeJSFSPrototype__DirentGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSNodeJSFS* thisObject = jsCast<JSNodeJSFS*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = NodeJSFSPrototype__getDirent(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__existsCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__exists(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__existsSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__existsSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__fchmodCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__fchmod(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__fchmodSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__fchmodSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__fchownCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__fchown(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__fchownSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__fchownSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__fdatasyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__fdatasync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__fdatasyncSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__fdatasyncSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__fstatCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__fstat(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__fstatSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__fstatSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__fsyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__fsync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__fsyncSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__fsyncSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__ftruncateCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__ftruncate(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__ftruncateSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__ftruncateSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__futimesCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__futimes(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__futimesSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__futimesSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__lchmodCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__lchmod(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__lchmodSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__lchmodSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__lchownCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__lchown(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__lchownSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__lchownSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__linkCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__link(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__linkSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__linkSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__lstatCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__lstat(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__lstatSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__lstatSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__lutimesCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__lutimes(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__lutimesSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__lutimesSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__mkdirCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__mkdir(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__mkdirSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__mkdirSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__mkdtempCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__mkdtemp(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__mkdtempSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__mkdtempSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__openCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__open(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__opendirCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__opendir(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__opendirSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__opendirSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__openSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__openSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__readCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__read(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__readdirCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__readdir(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__readdirSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__readdirSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__readFileCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__readFile(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__readFileSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__readFileSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__readlinkCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__readlink(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__readlinkSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__readlinkSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__readSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__readSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__readvCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__readv(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__readvSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__readvSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__realpathCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__realpath(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__realpathSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__realpathSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__renameCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__rename(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__renameSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__renameSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__rmCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__rm(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__rmdirCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__rmdir(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__rmdirSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__rmdirSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__rmSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__rmSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__statCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__stat(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__statSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__statSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__symlinkCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__symlink(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__symlinkSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__symlinkSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__truncateCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__truncate(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__truncateSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__truncateSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__unlinkCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__unlink(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__unlinkSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__unlinkSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__utimesCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__utimes(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__utimesSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__utimesSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__writeCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__write(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__writeFileCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__writeFile(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__writeFileSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__writeFileSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__writeSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__writeSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__writevCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__writev(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +JSC_DEFINE_HOST_FUNCTION(NodeJSFSPrototype__writevSyncCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = lexicalGlobalObject->vm(); + + JSNodeJSFS* thisObject = jsDynamicCast<JSNodeJSFS*>(callFrame->thisValue()); + + if (UNLIKELY(!thisObject)) { + auto throwScope = DECLARE_THROW_SCOPE(vm); + return throwVMTypeError(lexicalGlobalObject, throwScope); + } + + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + return NodeJSFSPrototype__writevSync(thisObject->wrapped(), lexicalGlobalObject, callFrame); +} + +void JSNodeJSFSPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) +{ + Base::finishCreation(vm); + reifyStaticProperties(vm, JSNodeJSFS::info(), JSNodeJSFSPrototypeTableValues, *this); + JSC_TO_STRING_TAG_WITHOUT_TRANSITION(); +} + +void JSNodeJSFSConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSNodeJSFSPrototype* prototype) +{ + Base::finishCreation(vm, 0, "NodeJSFS"_s, PropertyAdditionMode::WithoutStructureTransition); + + putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); + ASSERT(inherits(info())); +} + +JSNodeJSFSConstructor::JSNodeJSFSConstructor(JSC::VM& vm, JSC::Structure* structure) + : Base(vm, structure, construct, construct) +{ +} + +JSNodeJSFSConstructor* JSNodeJSFSConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSNodeJSFSPrototype* prototype) +{ + JSNodeJSFSConstructor* ptr = new (NotNull, JSC::allocateCell<JSNodeJSFSConstructor>(vm)) JSNodeJSFSConstructor(vm, structure); + ptr->finishCreation(vm, globalObject, prototype); + return ptr; +} + +JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSNodeJSFSConstructor::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + JSC::VM& vm = globalObject->vm(); + JSObject* newTarget = asObject(callFrame->newTarget()); + auto* constructor = globalObject->JSNodeJSFSConstructor(); + Structure* structure = globalObject->JSNodeJSFSStructure(); + if (constructor != newTarget) { + auto scope = DECLARE_THROW_SCOPE(vm); + + auto* functionGlobalObject = reinterpret_cast<Zig::GlobalObject*>( + // ShadowRealm functions belong to a different global object. + getFunctionRealm(globalObject, newTarget)); + RETURN_IF_EXCEPTION(scope, {}); + structure = InternalFunction::createSubclassStructure( + globalObject, + newTarget, + functionGlobalObject->JSNodeJSFSStructure()); + } + + void* ptr = NodeJSFSClass__construct(globalObject, callFrame); + + if (UNLIKELY(!ptr)) { + return JSValue::encode(JSC::jsUndefined()); + } + + JSNodeJSFS* instance = JSNodeJSFS::create(vm, globalObject, structure, ptr); + + return JSValue::encode(instance); +} + +void JSNodeJSFSConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSNodeJSFSPrototype* prototype) +{ +} + +const ClassInfo JSNodeJSFSConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSNodeJSFSConstructor) }; + +extern "C" EncodedJSValue NodeJSFS__getConstructor(Zig::GlobalObject* globalObject) +{ + return JSValue::encode(globalObject->JSNodeJSFSConstructor()); +} + +JSNodeJSFS::~JSNodeJSFS() +{ +} +void JSNodeJSFS::destroy(JSCell* cell) +{ + static_cast<JSNodeJSFS*>(cell)->JSNodeJSFS::~JSNodeJSFS(); +} + +const ClassInfo JSNodeJSFS::s_info = { "NodeJSFS"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSNodeJSFS) }; + +void JSNodeJSFS::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + ASSERT(inherits(info())); +} + +JSNodeJSFS* JSNodeJSFS::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) +{ + JSNodeJSFS* ptr = new (NotNull, JSC::allocateCell<JSNodeJSFS>(vm)) JSNodeJSFS(vm, structure, ctx); + ptr->finishCreation(vm); + return ptr; +} + +extern "C" void* NodeJSFS__fromJS(JSC::EncodedJSValue value) +{ + JSC::JSValue decodedValue = JSC::JSValue::decode(value); + if (!decodedValue || decodedValue.isUndefinedOrNull()) + return nullptr; + + JSNodeJSFS* object = JSC::jsDynamicCast<JSNodeJSFS*>(decodedValue); + + if (!object) + return nullptr; + + return object->wrapped(); +} + +extern "C" bool NodeJSFS__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr) +{ + JSNodeJSFS* object = JSC::jsDynamicCast<JSNodeJSFS*>(JSValue::decode(value)); + if (!object) + return false; + + object->m_ctx = ptr; + return true; +} + +extern "C" const size_t NodeJSFS__ptrOffset = JSNodeJSFS::offsetOfWrapped(); + +void JSNodeJSFS::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) +{ + auto* thisObject = jsCast<JSNodeJSFS*>(cell); + if (void* wrapped = thisObject->wrapped()) { + // if (thisObject->scriptExecutionContext()) + // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); + } + Base::analyzeHeap(cell, analyzer); +} + +JSObject* JSNodeJSFS::createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype) +{ + return WebCore::JSNodeJSFSConstructor::create(vm, globalObject, WebCore::JSNodeJSFSConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()), jsCast<WebCore::JSNodeJSFSPrototype*>(prototype)); +} + +JSObject* JSNodeJSFS::createPrototype(VM& vm, JSDOMGlobalObject* globalObject) +{ + return JSNodeJSFSPrototype::create(vm, globalObject, JSNodeJSFSPrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); +} + +extern "C" EncodedJSValue NodeJSFS__create(Zig::GlobalObject* globalObject, void* ptr) +{ + auto& vm = globalObject->vm(); + JSC::Structure* structure = globalObject->JSNodeJSFSStructure(); + JSNodeJSFS* instance = JSNodeJSFS::create(vm, globalObject, structure, ptr); + + return JSValue::encode(instance); +} } // namespace WebCore diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h index 700d7bab3..3f34fc978 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.h +++ b/src/bun.js/bindings/ZigGeneratedClasses.h @@ -1182,4 +1182,110 @@ public: void finishCreation(JSC::VM&); }; +class JSDirent final : public JSC::JSDestructibleObject { +public: + using Base = JSC::JSDestructibleObject; + static JSDirent* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx); + + DECLARE_EXPORT_INFO; + template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl<JSDirent, WebCore::UseCustomHeapCellType::No>( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForDirent.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForDirent = WTFMove(space); }, + [](auto& spaces) { return spaces.m_subspaceForDirent.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForDirent = WTFMove(space); }); + } + + static void destroy(JSC::JSCell*); + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast<JSC::JSType>(ObjectType), StructureFlags), info()); + } + + static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject); + static JSObject* createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype); + + ~JSDirent(); + + void* wrapped() const { return m_ctx; } + + void detach() + { + m_ctx = nullptr; + } + + static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); + static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSDirent, m_ctx); } + + void* m_ctx { nullptr }; + + JSDirent(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr) + : Base(vm, structure) + { + m_ctx = sinkPtr; + } + + void finishCreation(JSC::VM&); + + DECLARE_VISIT_CHILDREN; + template<typename Visitor> void visitAdditionalChildren(Visitor&); + DECLARE_VISIT_OUTPUT_CONSTRAINTS; + + mutable JSC::WriteBarrier<JSC::Unknown> m_name; +}; + +class JSNodeJSFS final : public JSC::JSDestructibleObject { +public: + using Base = JSC::JSDestructibleObject; + static JSNodeJSFS* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx); + + DECLARE_EXPORT_INFO; + template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + if constexpr (mode == JSC::SubspaceAccess::Concurrently) + return nullptr; + return WebCore::subspaceForImpl<JSNodeJSFS, WebCore::UseCustomHeapCellType::No>( + vm, + [](auto& spaces) { return spaces.m_clientSubspaceForNodeJSFS.get(); }, + [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForNodeJSFS = WTFMove(space); }, + [](auto& spaces) { return spaces.m_subspaceForNodeJSFS.get(); }, + [](auto& spaces, auto&& space) { spaces.m_subspaceForNodeJSFS = WTFMove(space); }); + } + + static void destroy(JSC::JSCell*); + static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast<JSC::JSType>(ObjectType), StructureFlags), info()); + } + + static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject); + static JSObject* createConstructor(VM& vm, JSGlobalObject* globalObject, JSValue prototype); + + ~JSNodeJSFS(); + + void* wrapped() const { return m_ctx; } + + void detach() + { + m_ctx = nullptr; + } + + static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&); + static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSNodeJSFS, m_ctx); } + + void* m_ctx { nullptr }; + + JSNodeJSFS(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr) + : Base(vm, structure) + { + m_ctx = sinkPtr; + } + + void finishCreation(JSC::VM&); +}; + } diff --git a/src/bun.js/bindings/bindings-generator.zig b/src/bun.js/bindings/bindings-generator.zig index 893e808d4..7168585de 100644 --- a/src/bun.js/bindings/bindings-generator.zig +++ b/src/bun.js/bindings/bindings-generator.zig @@ -22,10 +22,11 @@ const Classes = JSC.GlobalClasses; pub fn main() anyerror!void { var allocator = std.heap.c_allocator; const src: std.builtin.SourceLocation = @src(); + const src_path = comptime @import("bun").Environment.base_path ++ std.fs.path.dirname(src.file).?; { - const paths = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "headers.h" }; - const paths2 = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "headers-cpp.h" }; - const paths4 = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "ZigGeneratedCode.cpp" }; + const paths = [_][]const u8{ src_path, "headers.h" }; + const paths2 = [_][]const u8{ src_path, "headers-cpp.h" }; + const paths4 = [_][]const u8{ src_path, "ZigGeneratedCode.cpp" }; const cpp = try std.fs.createFileAbsolute(try std.fs.path.join(allocator, &paths2), .{}); const file = try std.fs.createFileAbsolute(try std.fs.path.join(allocator, &paths), .{}); @@ -44,7 +45,7 @@ pub fn main() anyerror!void { comptime var i: usize = 0; inline while (i < Classes.len) : (i += 1) { const Class = Classes[i]; - const paths = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, Class.name ++ ".generated.h" }; + const paths = [_][]const u8{ src_path, Class.name ++ ".generated.h" }; var headerFilePath = try std.fs.path.join( allocator, &paths, diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 1ce48da90..2226d0fb5 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -32,7 +32,7 @@ pub const JSObject = extern struct { }); } - const InitializeCallback = fn (ctx: ?*anyopaque, obj: [*c]JSObject, global: [*c]JSGlobalObject) callconv(.C) void; + const InitializeCallback = *const fn (ctx: ?*anyopaque, obj: [*c]JSObject, global: [*c]JSGlobalObject) callconv(.C) void; pub fn create(global_object: *JSGlobalObject, length: usize, ctx: *anyopaque, initializer: InitializeCallback) JSValue { return cppFn("create", .{ global_object, @@ -45,7 +45,7 @@ pub const JSObject = extern struct { pub fn Initializer(comptime Ctx: type, comptime func: fn (*Ctx, obj: *JSObject, global: *JSGlobalObject) void) type { return struct { pub fn call(this: ?*anyopaque, obj: [*c]JSObject, global: [*c]JSGlobalObject) callconv(.C) void { - @call(.{ .modifier = .always_inline }, func, .{ @ptrCast(*Ctx, @alignCast(@alignOf(*Ctx), this.?)), obj.?, global.? }); + @call(.always_inline, func, .{ @ptrCast(*Ctx, @alignCast(@alignOf(*Ctx), this.?)), obj.?, global.? }); } }; } @@ -111,10 +111,10 @@ pub const ZigString = extern struct { pub fn substring(this: ZigString, offset: usize) ZigString { if (this.is16Bit()) { - return ZigString.from16Slice(this.utf16SliceAligned()[@minimum(this.len, offset)..]); + return ZigString.from16Slice(this.utf16SliceAligned()[@min(this.len, offset)..]); } - var out = ZigString.init(this.slice()[@minimum(this.len, offset)..]); + var out = ZigString.init(this.slice()[@min(this.len, offset)..]); if (this.isUTF8()) { out.markUTF8(); } @@ -184,7 +184,7 @@ pub const ZigString = extern struct { } pub fn trunc(this: ZigString, len: usize) ZigString { - return .{ .ptr = this.ptr, .len = @minimum(len, this.len) }; + return .{ .ptr = this.ptr, .len = @min(len, this.len) }; } pub fn eqlComptime(this: ZigString, comptime other: []const u8) bool { @@ -463,7 +463,7 @@ pub const ZigString = extern struct { } pub fn slice(this: *const ZigString) []const u8 { - return untagged(this.ptr)[0..@minimum(this.len, std.math.maxInt(u32))]; + return untagged(this.ptr)[0..@min(this.len, std.math.maxInt(u32))]; } pub fn dupe(this: ZigString, allocator: std.mem.Allocator) ![]const u8 { @@ -566,7 +566,7 @@ pub const ZigString = extern struct { inline fn assertGlobal(this: *const ZigString) void { if (comptime bun.Environment.allow_assert) { - std.debug.assert(bun.Mimalloc.mi_is_in_heap_region(untagged(this.ptr)) or bun.Mimalloc.mi_check_owned(untagged(this.ptr))); + std.debug.assert(this.len == 0 or bun.Mimalloc.mi_is_in_heap_region(untagged(this.ptr)) or bun.Mimalloc.mi_check_owned(untagged(this.ptr))); } } @@ -583,7 +583,7 @@ pub const ZigString = extern struct { pub fn toExternalValueWithCallback( this: *const ZigString, global: *JSGlobalObject, - callback: fn (ctx: ?*anyopaque, ptr: ?*anyopaque, len: usize) callconv(.C) void, + callback: *const fn (ctx: ?*anyopaque, ptr: ?*anyopaque, len: usize) callconv(.C) void, ) JSValue { return shim.cppFn("toExternalValueWithCallback", .{ this, global, callback }); } @@ -592,7 +592,7 @@ pub const ZigString = extern struct { this: *const ZigString, global: *JSGlobalObject, ctx: ?*anyopaque, - callback: fn (ctx: ?*anyopaque, ptr: ?*anyopaque, len: usize) callconv(.C) void, + callback: *const fn (ctx: ?*anyopaque, ptr: ?*anyopaque, len: usize) callconv(.C) void, ) JSValue { return shim.cppFn("external", .{ this, global, ctx, callback }); } @@ -641,7 +641,7 @@ pub const DOMURL = opaque { } pub fn cast(value: JSValue) ?*DOMURL { - return cast_(value, JSC.VirtualMachine.vm.global.vm()); + return cast_(value, JSC.VirtualMachine.get().global.vm()); } pub fn href_(this: *DOMURL, out: *ZigString) void { @@ -1018,7 +1018,7 @@ pub const FetchHeaders = opaque { } pub fn cast(value: JSValue) ?*FetchHeaders { - return cast_(value, JSC.VirtualMachine.vm.global.vm()); + return cast_(value, JSC.VirtualMachine.get().global.vm()); } pub fn toJS(this: *FetchHeaders, globalThis: *JSGlobalObject) JSValue { @@ -1219,10 +1219,10 @@ pub const JSString = extern struct { }); } - pub const JStringIteratorAppend8Callback = fn (*Iterator, [*]const u8, u32) callconv(.C) void; - pub const JStringIteratorAppend16Callback = fn (*Iterator, [*]const u16, u32) callconv(.C) void; - pub const JStringIteratorWrite8Callback = fn (*Iterator, [*]const u8, u32, u32) callconv(.C) void; - pub const JStringIteratorWrite16Callback = fn (*Iterator, [*]const u16, u32, u32) callconv(.C) void; + pub const JStringIteratorAppend8Callback = *const fn (*Iterator, [*]const u8, u32) callconv(.C) void; + pub const JStringIteratorAppend16Callback = *const fn (*Iterator, [*]const u16, u32) callconv(.C) void; + pub const JStringIteratorWrite8Callback = *const fn (*Iterator, [*]const u8, u32, u32) callconv(.C) void; + pub const JStringIteratorWrite16Callback = *const fn (*Iterator, [*]const u16, u32, u32) callconv(.C) void; pub const Iterator = extern struct { data: ?*anyopaque, stop: u8, @@ -1247,41 +1247,41 @@ pub fn NewGlobalObject(comptime Type: type) type { const moduleNotImpl = "Module fetch not implemented"; pub fn import(global: *JSGlobalObject, specifier: *ZigString, source: *ZigString) callconv(.C) ErrorableZigString { if (comptime @hasDecl(Type, "import")) { - return @call(.{ .modifier = .always_inline }, Type.import, .{ global, specifier.*, source.* }); + return @call(.always_inline, Type.import, .{ global, specifier.*, source.* }); } return ErrorableZigString.err(error.ImportFailed, ZigString.init(importNotImpl).toErrorInstance(global).asVoid()); } pub fn resolve(res: *ErrorableZigString, global: *JSGlobalObject, specifier: *ZigString, source: *ZigString) callconv(.C) void { if (comptime @hasDecl(Type, "resolve")) { - @call(.{ .modifier = .always_inline }, Type.resolve, .{ res, global, specifier.*, source.* }); + @call(.always_inline, Type.resolve, .{ res, global, specifier.*, source.* }); return; } res.* = ErrorableZigString.err(error.ResolveFailed, ZigString.init(resolveNotImpl).toErrorInstance(global).asVoid()); } pub fn fetch(ret: *ErrorableResolvedSource, global: *JSGlobalObject, specifier: *ZigString, source: *ZigString) callconv(.C) void { if (comptime @hasDecl(Type, "fetch")) { - @call(.{ .modifier = .always_inline }, Type.fetch, .{ ret, global, specifier.*, source.* }); + @call(.always_inline, Type.fetch, .{ ret, global, specifier.*, source.* }); return; } ret.* = ErrorableResolvedSource.err(error.FetchFailed, ZigString.init(moduleNotImpl).toErrorInstance(global).asVoid()); } pub fn promiseRejectionTracker(global: *JSGlobalObject, promise: *JSPromise, rejection: JSPromiseRejectionOperation) callconv(.C) JSValue { if (comptime @hasDecl(Type, "promiseRejectionTracker")) { - return @call(.{ .modifier = .always_inline }, Type.promiseRejectionTracker, .{ global, promise, rejection }); + return @call(.always_inline, Type.promiseRejectionTracker, .{ global, promise, rejection }); } return JSValue.jsUndefined(); } pub fn reportUncaughtException(global: *JSGlobalObject, exception: *Exception) callconv(.C) JSValue { if (comptime @hasDecl(Type, "reportUncaughtException")) { - return @call(.{ .modifier = .always_inline }, Type.reportUncaughtException, .{ global, exception }); + return @call(.always_inline, Type.reportUncaughtException, .{ global, exception }); } return JSValue.jsUndefined(); } pub fn onCrash() callconv(.C) void { if (comptime @hasDecl(Type, "onCrash")) { - return @call(.{ .modifier = .always_inline }, Type.onCrash, .{}); + return @call(.always_inline, Type.onCrash, .{}); } Output.flush(); @@ -1537,7 +1537,7 @@ pub const JSInternalPromise = extern struct { pub fn rejectAsHandledException(this: *JSInternalPromise, globalThis: *JSGlobalObject, value: *Exception) void { cppFn("rejectAsHandledException", .{ this, globalThis, value }); } - // pub const PromiseCallbackPrimitive = fn ( + // pub const PromiseCallbackPrimitive = *const fn ( // ctx: ?*anyopaque, // globalThis: *JSGlobalObject, // arguments: [*]const JSValue, @@ -1960,7 +1960,7 @@ pub const JSGlobalObject = extern struct { // you most likely need to run // make clean-jsc-bindings // make bindings -j10 - const assertion = this.bunVM_() == @ptrCast(*anyopaque, JSC.VirtualMachine.vm); + const assertion = this.bunVM_() == @ptrCast(*anyopaque, JSC.VirtualMachine.get()); if (!assertion) @breakpoint(); std.debug.assert(assertion); } @@ -1969,7 +1969,7 @@ pub const JSGlobalObject = extern struct { /// We can't do the threadlocal check when queued from another thread pub fn bunVMConcurrently(this: *JSGlobalObject) *JSC.VirtualMachine { - return @ptrCast(*JSC.VirtualMachine, @alignCast(std.meta.alignment(JSC.VirtualMachine), this.bunVM_())); + return @ptrCast(*JSC.VirtualMachine, @alignCast(@alignOf(JSC.VirtualMachine), this.bunVM_())); } pub fn handleRejectedPromises(this: *JSGlobalObject) void { @@ -2024,7 +2024,7 @@ pub const JSGlobalObject = extern struct { }; }; -pub const JSNativeFn = fn (*JSGlobalObject, *CallFrame) callconv(.C) JSValue; +pub const JSNativeFn = *const fn (*JSGlobalObject, *CallFrame) callconv(.C) JSValue; pub const JSArrayIterator = struct { i: u32 = 0, @@ -2053,10 +2053,10 @@ pub const JSArrayIterator = struct { pub const JSValueReprInt = i64; pub const JSValue = enum(JSValueReprInt) { zero = 0, - @"undefined" = @bitCast(JSValueReprInt, @as(i64, 0xa)), - @"null" = @bitCast(JSValueReprInt, @as(i64, 0x2)), - @"true" = @bitCast(JSValueReprInt, @as(i64, 0x4)), - @"false" = @bitCast(JSValueReprInt, @as(i64, 0x6)), + undefined = @bitCast(JSValueReprInt, @as(i64, 0xa)), + null = @bitCast(JSValueReprInt, @as(i64, 0x2)), + true = @bitCast(JSValueReprInt, @as(i64, 0x4)), + false = @bitCast(JSValueReprInt, @as(i64, 0x6)), _, pub const Type = JSValueReprInt; @@ -2357,10 +2357,10 @@ pub const JSValue = enum(JSValueReprInt) { return cppFn("coerceToInt32", .{ this, globalThis }); } - const PropertyIteratorFn = fn ( - globalObject_: [*c]JSGlobalObject, + const PropertyIteratorFn = *const fn ( + globalObject_: *JSGlobalObject, ctx_ptr: ?*anyopaque, - key: *ZigString, + key: [*c]ZigString, value: JSValue, is_symbol: bool, ) callconv(.C) void; @@ -2404,7 +2404,7 @@ pub const JSValue = enum(JSValueReprInt) { ?*JSInternalPromise => asInternalPromise(this), ?*JSPromise => asPromise(this), - u52 => @truncate(u52, @intCast(u64, @maximum(this.toInt64(), 0))), + u52 => @truncate(u52, @intCast(u64, @max(this.toInt64(), 0))), u64 => toUInt64NoTruncate(this), u8 => @truncate(u8, toU32(this)), i16 => @truncate(i16, toInt32(this)), @@ -2512,12 +2512,12 @@ pub const JSValue = enum(JSValueReprInt) { pub fn protect(this: JSValue) void { if (this.isEmptyOrUndefinedOrNull() or this.isNumber()) return; - JSC.C.JSValueProtect(JSC.VirtualMachine.vm.global, this.asObjectRef()); + JSC.C.JSValueProtect(JSC.VirtualMachine.get().global, this.asObjectRef()); } pub fn unprotect(this: JSValue) void { if (this.isEmptyOrUndefinedOrNull() or this.isNumber()) return; - JSC.C.JSValueUnprotect(JSC.VirtualMachine.vm.global, this.asObjectRef()); + JSC.C.JSValueUnprotect(JSC.VirtualMachine.get().global, this.asObjectRef()); } pub fn JSONValueFromString( @@ -2615,10 +2615,10 @@ pub const JSValue = enum(JSValueReprInt) { } pub inline fn jsNull() JSValue { - return JSValue.@"null"; + return JSValue.null; } pub inline fn jsUndefined() JSValue { - return JSValue.@"undefined"; + return JSValue.undefined; } pub inline fn jsBoolean(i: bool) JSValue { const out = cppFn("jsBoolean", .{i}); @@ -3171,7 +3171,7 @@ pub const JSValue = enum(JSValueReprInt) { } pub inline fn toU32(this: JSValue) u32 { - return @intCast(u32, @maximum(this.toInt32(), 0)); + return @intCast(u32, @max(this.toInt32(), 0)); } pub fn getLengthOfArray(this: JSValue, globalThis: *JSGlobalObject) u64 { @@ -3189,7 +3189,7 @@ pub const JSValue = enum(JSValueReprInt) { this: JSValue, globalObject: *JSGlobalObject, ctx: ?*anyopaque, - callback: fn (vm: [*c]VM, globalObject: [*c]JSGlobalObject, ctx: ?*anyopaque, nextValue: JSValue) callconv(.C) void, + callback: *const fn (vm: *VM, globalObject: *JSGlobalObject, ctx: ?*anyopaque, nextValue: JSValue) callconv(.C) void, ) void { return cppFn("forEach", .{ this, globalObject, ctx, callback }); } @@ -3339,11 +3339,11 @@ pub const VM = extern struct { return cppFn("isJITEnabled", .{}); } - pub fn holdAPILock(this: *VM, ctx: ?*anyopaque, callback: fn (ctx: ?*anyopaque) callconv(.C) void) void { + pub fn holdAPILock(this: *VM, ctx: ?*anyopaque, callback: *const fn (ctx: ?*anyopaque) callconv(.C) void) void { cppFn("holdAPILock", .{ this, ctx, callback }); } - pub fn deferGC(this: *VM, ctx: ?*anyopaque, callback: fn (ctx: ?*anyopaque) callconv(.C) void) void { + pub fn deferGC(this: *VM, ctx: ?*anyopaque, callback: *const fn (ctx: ?*anyopaque) callconv(.C) void) void { cppFn("deferGC", .{ this, ctx, callback }); } @@ -3354,9 +3354,9 @@ pub const VM = extern struct { return cppFn("deleteAllCode", .{ vm, global_object }); } - extern fn Bun__setOnEachMicrotaskTick(vm: *VM, ptr: ?*anyopaque, callback: ?(fn (*anyopaque) callconv(.C) void)) void; + extern fn Bun__setOnEachMicrotaskTick(vm: *VM, ptr: ?*anyopaque, callback: ?*const fn (*anyopaque) callconv(.C) void) void; - pub fn onEachMicrotask(vm: *VM, comptime Ptr: type, ptr: *Ptr, comptime callback: fn (*Ptr) void) void { + pub fn onEachMicrotask(vm: *VM, comptime Ptr: type, ptr: *Ptr, comptime callback: *const fn (*Ptr) void) void { if (comptime is_bindgen) { return; } @@ -3382,7 +3382,7 @@ pub const VM = extern struct { pub fn whenIdle( vm: *VM, - callback: fn (...) callconv(.C) void, + callback: *const fn (...) callconv(.C) void, ) void { return cppFn("whenIdle", .{ vm, callback }); } @@ -3569,47 +3569,37 @@ pub const CallFrame = opaque { return (@ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + Sizes.Bun_CallFrame__callee)[0]; } - pub fn arguments(self: *const CallFrame, comptime max: usize) struct { ptr: [max]JSC.JSValue, len: usize } { - var buf: [max]JSC.JSValue = std.mem.zeroes([max]JSC.JSValue); + fn Arguments(comptime max: usize) type { + return struct { + ptr: [max]JSC.JSValue, + len: usize, + pub inline fn init(comptime i: usize, ptr: [*]const JSC.JSValue) @This() { + var args: [max]JSC.JSValue = std.mem.zeroes([max]JSC.JSValue); + args[0..comptime i].* = ptr[0..i].*; + + return @This(){ + .ptr = args, + .len = i, + }; + } + }; + } + + pub fn arguments(self: *const CallFrame, comptime max: usize) Arguments(max) { const len = self.argumentsCount(); var ptr = self.argumentsPtr(); - switch (@minimum(len, max)) { - 0 => { - return .{ .ptr = buf, .len = 0 }; - }, - 1 => { - buf[0..1].* = ptr[0..1].*; - return .{ .ptr = buf, .len = 1 }; - }, - 2 => { - buf[0..2].* = ptr[0..2].*; - return .{ .ptr = buf, .len = 2 }; - }, - 3 => { - buf[0..3].* = ptr[0..3].*; - return .{ .ptr = buf, .len = 3 }; - }, - 4 => { - buf[0..4].* = ptr[0..4].*; - return .{ .ptr = buf, .len = 4 }; - }, - 5 => { - buf[0..5].* = ptr[0..5].*; - return .{ .ptr = buf, .len = 5 }; - }, - 6 => { - buf[0..6].* = ptr[0..6].*; - return .{ .ptr = buf, .len = 6 }; - }, - 7 => { - buf[0..7].* = ptr[0..7].*; - return .{ .ptr = buf, .len = 7 }; - }, - else => { - buf[0..8].* = ptr[0..8].*; - return .{ .ptr = buf, .len = 8 }; - }, - } + return switch (@min(len, max)) { + 0 => .{ .ptr = undefined, .len = 0 }, + 1 => Arguments(max).init(1, ptr), + 2 => Arguments(max).init(@min(2, max), ptr), + 3 => Arguments(max).init(@min(3, max), ptr), + 4 => Arguments(max).init(@min(4, max), ptr), + 5 => Arguments(max).init(@min(5, max), ptr), + 6 => Arguments(max).init(@min(6, max), ptr), + 7 => Arguments(max).init(@min(7, max), ptr), + 8 => Arguments(max).init(@min(8, max), ptr), + else => unreachable, + }; } pub fn argument(self: *const CallFrame, comptime i: comptime_int) JSC.JSValue { @@ -3659,7 +3649,7 @@ pub const EncodedJSValue = extern union { asDouble: f64, }; -const DeinitFunction = fn (ctx: *anyopaque, buffer: [*]u8, len: usize) callconv(.C) void; +const DeinitFunction = *const fn (ctx: *anyopaque, buffer: [*]u8, len: usize) callconv(.C) void; pub const JSArray = struct { pub fn from(globalThis: *JSGlobalObject, arguments: []const JSC.JSValue) JSValue { @@ -3701,15 +3691,25 @@ const private = struct { pub extern fn Bun__FFIFunction_setDataPtr(JSValue, ?*anyopaque) void; }; -pub fn NewFunctionPtr(globalObject: *JSGlobalObject, symbolName: ?*const ZigString, argCount: u32, functionPointer: anytype, strong: bool) *anyopaque { +pub fn NewFunctionPtr(globalObject: *JSGlobalObject, symbolName: ?*const ZigString, argCount: u32, comptime functionPointer: anytype, strong: bool) *anyopaque { JSC.markBinding(@src()); - return private.Bun__CreateFFIFunction(globalObject, symbolName, argCount, @ptrCast(*const anyopaque, functionPointer), strong); + return private.Bun__CreateFFIFunction(globalObject, symbolName, argCount, @ptrCast(*const anyopaque, &functionPointer), strong); } pub fn NewFunction( globalObject: *JSGlobalObject, symbolName: ?*const ZigString, argCount: u32, + comptime functionPointer: anytype, + strong: bool, +) JSValue { + return NewRuntimeFunction(globalObject, symbolName, argCount, &functionPointer, strong); +} + +pub fn NewRuntimeFunction( + globalObject: *JSGlobalObject, + symbolName: ?*const ZigString, + argCount: u32, functionPointer: anytype, strong: bool, ) JSValue { @@ -3731,7 +3731,7 @@ pub fn NewFunctionWithData( globalObject: *JSGlobalObject, symbolName: ?*const ZigString, argCount: u32, - functionPointer: anytype, + comptime functionPointer: anytype, strong: bool, data: *anyopaque, ) JSValue { @@ -3740,7 +3740,7 @@ pub fn NewFunctionWithData( globalObject, symbolName, argCount, - @ptrCast(*const anyopaque, functionPointer), + @ptrCast(*const anyopaque, &functionPointer), strong, data, ); @@ -3931,21 +3931,21 @@ pub fn JSPropertyIterator(comptime options: JSPropertyIteratorOptions) type { // DOMCall Fields pub const __DOMCall_ptr = @import("../api/bun.zig").FFI.Class.functionDefinitions.ptr; -pub const __DOMCall__reader_u8 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"u8"; -pub const __DOMCall__reader_u16 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"u16"; -pub const __DOMCall__reader_u32 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"u32"; -pub const __DOMCall__reader_ptr = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"ptr"; -pub const __DOMCall__reader_i8 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"i8"; -pub const __DOMCall__reader_i16 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"i16"; -pub const __DOMCall__reader_i32 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"i32"; -pub const __DOMCall__reader_f32 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"f32"; -pub const __DOMCall__reader_f64 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"f64"; -pub const __DOMCall__reader_i64 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"i64"; -pub const __DOMCall__reader_u64 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"u64"; -pub const __DOMCall__reader_intptr = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.@"intptr"; -pub const __Crypto_getRandomValues = @import("../webcore.zig").Crypto.Class.functionDefinitions.@"getRandomValues"; -pub const __Crypto_randomUUID = @import("../webcore.zig").Crypto.Class.functionDefinitions.@"randomUUID"; -pub const __Crypto_timingSafeEqual = @import("../webcore.zig").Crypto.Class.functionDefinitions.@"timingSafeEqual"; +pub const __DOMCall__reader_u8 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.u8; +pub const __DOMCall__reader_u16 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.u16; +pub const __DOMCall__reader_u32 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.u32; +pub const __DOMCall__reader_ptr = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.ptr; +pub const __DOMCall__reader_i8 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.i8; +pub const __DOMCall__reader_i16 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.i16; +pub const __DOMCall__reader_i32 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.i32; +pub const __DOMCall__reader_f32 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.f32; +pub const __DOMCall__reader_f64 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.f64; +pub const __DOMCall__reader_i64 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.i64; +pub const __DOMCall__reader_u64 = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.u64; +pub const __DOMCall__reader_intptr = @import("../api/bun.zig").FFI.Reader.Class.functionDefinitions.intptr; +pub const __Crypto_getRandomValues = @import("../webcore.zig").Crypto.Class.functionDefinitions.getRandomValues; +pub const __Crypto_randomUUID = @import("../webcore.zig").Crypto.Class.functionDefinitions.randomUUID; +pub const __Crypto_timingSafeEqual = @import("../webcore.zig").Crypto.Class.functionDefinitions.timingSafeEqual; pub const DOMCalls = .{ @import("../api/bun.zig").FFI, @import("../api/bun.zig").FFI.Reader, diff --git a/src/bun.js/bindings/c-bindings.cpp b/src/bun.js/bindings/c-bindings.cpp new file mode 100644 index 000000000..8ed868c77 --- /dev/null +++ b/src/bun.js/bindings/c-bindings.cpp @@ -0,0 +1,13 @@ +// when we don't want to use @cInclude, we can just stick wrapper functions here +#include <sys/resource.h> +#include <cstdint> + +extern "C" int32_t get_process_priority(uint32_t pid) +{ + return getpriority(PRIO_PROCESS, pid); +} + +extern "C" int32_t set_process_priority(uint32_t pid, int32_t priority) +{ + return setpriority(PRIO_PROCESS, pid, priority); +}
\ No newline at end of file diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig index 2e187e302..b2460cc0d 100644 --- a/src/bun.js/bindings/exports.zig +++ b/src/bun.js/bindings/exports.zig @@ -58,51 +58,51 @@ pub const ZigGlobalObject = extern struct { unreachable; } - return @call(.{ .modifier = .always_inline }, Interface.import, .{ global, specifier, source }); + return @call(.always_inline, Interface.import, .{ global, specifier, source }); } pub fn resolve(res: *ErrorableZigString, global: *JSGlobalObject, specifier: *ZigString, source: *ZigString) callconv(.C) void { if (comptime is_bindgen) { unreachable; } - @call(.{ .modifier = .always_inline }, Interface.resolve, .{ res, global, specifier, source }); + @call(.always_inline, Interface.resolve, .{ res, global, specifier, source }); } pub fn fetch(ret: *ErrorableResolvedSource, global: *JSGlobalObject, specifier: *ZigString, source: *ZigString) callconv(.C) void { if (comptime is_bindgen) { unreachable; } - @call(.{ .modifier = .always_inline }, Interface.fetch, .{ ret, global, specifier, source }); + @call(.always_inline, Interface.fetch, .{ ret, global, specifier, source }); } pub fn promiseRejectionTracker(global: *JSGlobalObject, promise: *JSPromise, rejection: JSPromiseRejectionOperation) callconv(.C) JSValue { if (comptime is_bindgen) { unreachable; } - return @call(.{ .modifier = .always_inline }, Interface.promiseRejectionTracker, .{ global, promise, rejection }); + return @call(.always_inline, Interface.promiseRejectionTracker, .{ global, promise, rejection }); } pub fn reportUncaughtException(global: *JSGlobalObject, exception: *Exception) callconv(.C) JSValue { if (comptime is_bindgen) { unreachable; } - return @call(.{ .modifier = .always_inline }, Interface.reportUncaughtException, .{ global, exception }); + return @call(.always_inline, Interface.reportUncaughtException, .{ global, exception }); } pub fn onCrash() callconv(.C) void { if (comptime is_bindgen) { unreachable; } - return @call(.{ .modifier = .always_inline }, Interface.onCrash, .{}); + return @call(.always_inline, Interface.onCrash, .{}); } pub const Export = shim.exportFunctions( .{ - .@"import" = import, - .@"resolve" = resolve, - .@"fetch" = fetch, + .import = import, + .resolve = resolve, + .fetch = fetch, // .@"eval" = eval, - .@"promiseRejectionTracker" = promiseRejectionTracker, - .@"reportUncaughtException" = reportUncaughtException, - .@"onCrash" = onCrash, + .promiseRejectionTracker = promiseRejectionTracker, + .reportUncaughtException = reportUncaughtException, + .onCrash = onCrash, }, ); @@ -146,7 +146,7 @@ pub const ZigErrorType = extern struct { } pub const Export = shim.exportFunctions(.{ - .@"isPrivateData" = isPrivateData, + .isPrivateData = isPrivateData, }); comptime { @@ -399,14 +399,14 @@ pub const Process = extern struct { pub const getExecPath = JSC.Node.Process.getExecPath; pub const Export = shim.exportFunctions(.{ - .@"getTitle" = getTitle, - .@"setTitle" = setTitle, - .@"getArgv" = getArgv, - .@"getCwd" = getCwd, - .@"setCwd" = setCwd, - .@"exit" = exit, - .@"getArgv0" = getArgv0, - .@"getExecPath" = getExecPath, + .getTitle = getTitle, + .setTitle = setTitle, + .getArgv = getArgv, + .getCwd = getCwd, + .setCwd = setCwd, + .exit = exit, + .getArgv0 = getArgv0, + .getExecPath = getExecPath, }); comptime { @@ -992,7 +992,7 @@ pub const ZigConsoleClient = struct { var exception = holder.zigException(); var err = ZigString.init("trace output").toErrorInstance(global); err.toZigException(global, exception); - JS.VirtualMachine.vm.remapZigException(exception, err, null); + JS.VirtualMachine.get().remapZigException(exception, err, null); if (Output.enable_ansi_colors_stderr) JS.VirtualMachine.printStackTrace( @@ -1498,7 +1498,7 @@ pub const ZigConsoleClient = struct { else writer.writeAll(end); any_non_ascii = false; - slice = slice[@minimum(slice.len, i + 1)..]; + slice = slice[@min(slice.len, i + 1)..]; i = 0; len = @truncate(u32, slice.len); const next_value = this.remaining_values[0]; @@ -1589,11 +1589,11 @@ pub const ZigConsoleClient = struct { comptime Writer: type, writer: Writer, ) !void { - const indent = @minimum(this.indent, 8); + const indent = @min(this.indent, 8); var buf = [_]u8{' '} ** 32; var total_remain: usize = indent; while (total_remain > 0) { - const written = @minimum(16, total_remain); + const written = @min(16, total_remain); try writer.writeAll(buf[0 .. written * 2]); total_remain -|= written; } @@ -1698,16 +1698,16 @@ pub const ZigConsoleClient = struct { } pub fn forEach( - globalObject_: [*c]JSGlobalObject, + globalThis: *JSGlobalObject, ctx_ptr: ?*anyopaque, - key: *ZigString, + key_: [*c]ZigString, value: JSValue, is_symbol: bool, ) callconv(.C) void { + const key = key_.?[0]; if (key.eqlComptime("constructor")) return; if (key.eqlComptime("call")) return; - var globalThis = globalObject_.?; var ctx: *@This() = bun.cast(*@This(), ctx_ptr orelse return); var this = ctx.formatter; var writer_ = ctx.writer; @@ -1790,7 +1790,7 @@ pub const ZigConsoleClient = struct { writer.print( comptime Output.prettyFmt("<r><d>[<r><blue>Symbol({any})<r><d>]:<r> ", enable_ansi_colors), .{ - key.*, + key, }, ); } @@ -1969,7 +1969,7 @@ pub const ZigConsoleClient = struct { } }, .Error => { - JS.VirtualMachine.vm.printErrorlikeObject( + JS.VirtualMachine.get().printErrorlikeObject( value, null, null, @@ -2660,7 +2660,7 @@ pub const ZigConsoleClient = struct { writer.print(comptime Output.prettyFmt(fmt_, enable_ansi_colors), .{slice[0]}); var leftover = slice[1..]; const max = 512; - leftover = leftover[0..@minimum(leftover.len, max)]; + leftover = leftover[0..@min(leftover.len, max)]; for (leftover) |el| { this.printComma(@TypeOf(&writer.ctx), &writer.ctx, enable_ansi_colors) catch return; writer.writeAll(" "); @@ -2906,19 +2906,19 @@ pub const ZigConsoleClient = struct { ) callconv(.C) void {} pub const Export = shim.exportFunctions(.{ - .@"messageWithTypeAndLevel" = messageWithTypeAndLevel, - .@"count" = count, - .@"countReset" = countReset, - .@"time" = time, - .@"timeLog" = timeLog, - .@"timeEnd" = timeEnd, - .@"profile" = profile, - .@"profileEnd" = profileEnd, - .@"takeHeapSnapshot" = takeHeapSnapshot, - .@"timeStamp" = timeStamp, - .@"record" = record, - .@"recordEnd" = recordEnd, - .@"screenshot" = screenshot, + .messageWithTypeAndLevel = messageWithTypeAndLevel, + .count = count, + .countReset = countReset, + .time = time, + .timeLog = timeLog, + .timeEnd = timeEnd, + .profile = profile, + .profileEnd = profileEnd, + .takeHeapSnapshot = takeHeapSnapshot, + .timeStamp = timeStamp, + .record = record, + .recordEnd = recordEnd, + .screenshot = screenshot, }); comptime { diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig index 0099d2c9f..e38870229 100644 --- a/src/bun.js/bindings/generated_classes.zig +++ b/src/bun.js/bindings/generated_classes.zig @@ -108,9 +108,9 @@ pub const JSTCPSocket = struct { if (@TypeOf(TCPSocket.setData) != SetterType) @compileLog("Expected TCPSocket.setData to be a setter"); if (@TypeOf(TCPSocket.end) != CallbackType) - @compileLog("Expected TCPSocket.end to be a callback"); + @compileLog("Expected TCPSocket.end to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.end))); if (@TypeOf(TCPSocket.flush) != CallbackType) - @compileLog("Expected TCPSocket.flush to be a callback"); + @compileLog("Expected TCPSocket.flush to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.flush))); if (@TypeOf(TCPSocket.getListener) != GetterType) @compileLog("Expected TCPSocket.getListener to be a getter"); @@ -121,20 +121,20 @@ pub const JSTCPSocket = struct { @compileLog("Expected TCPSocket.getReadyState to be a getter"); if (@TypeOf(TCPSocket.ref) != CallbackType) - @compileLog("Expected TCPSocket.ref to be a callback"); + @compileLog("Expected TCPSocket.ref to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.ref))); if (@TypeOf(TCPSocket.reload) != CallbackType) - @compileLog("Expected TCPSocket.reload to be a callback"); + @compileLog("Expected TCPSocket.reload to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.reload))); if (@TypeOf(TCPSocket.getRemoteAddress) != GetterType) @compileLog("Expected TCPSocket.getRemoteAddress to be a getter"); if (@TypeOf(TCPSocket.shutdown) != CallbackType) - @compileLog("Expected TCPSocket.shutdown to be a callback"); + @compileLog("Expected TCPSocket.shutdown to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.shutdown))); if (@TypeOf(TCPSocket.timeout) != CallbackType) - @compileLog("Expected TCPSocket.timeout to be a callback"); + @compileLog("Expected TCPSocket.timeout to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.timeout))); if (@TypeOf(TCPSocket.unref) != CallbackType) - @compileLog("Expected TCPSocket.unref to be a callback"); + @compileLog("Expected TCPSocket.unref to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.unref))); if (@TypeOf(TCPSocket.write) != CallbackType) - @compileLog("Expected TCPSocket.write to be a callback"); + @compileLog("Expected TCPSocket.write to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.write))); if (!JSC.is_bindgen) { @export(TCPSocket.end, .{ .name = "TCPSocketPrototype__end" }); @export(TCPSocket.finalize, .{ .name = "TCPSocketClass__finalize" }); @@ -256,9 +256,9 @@ pub const JSTLSSocket = struct { if (@TypeOf(TLSSocket.setData) != SetterType) @compileLog("Expected TLSSocket.setData to be a setter"); if (@TypeOf(TLSSocket.end) != CallbackType) - @compileLog("Expected TLSSocket.end to be a callback"); + @compileLog("Expected TLSSocket.end to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.end))); if (@TypeOf(TLSSocket.flush) != CallbackType) - @compileLog("Expected TLSSocket.flush to be a callback"); + @compileLog("Expected TLSSocket.flush to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.flush))); if (@TypeOf(TLSSocket.getListener) != GetterType) @compileLog("Expected TLSSocket.getListener to be a getter"); @@ -269,20 +269,20 @@ pub const JSTLSSocket = struct { @compileLog("Expected TLSSocket.getReadyState to be a getter"); if (@TypeOf(TLSSocket.ref) != CallbackType) - @compileLog("Expected TLSSocket.ref to be a callback"); + @compileLog("Expected TLSSocket.ref to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.ref))); if (@TypeOf(TLSSocket.reload) != CallbackType) - @compileLog("Expected TLSSocket.reload to be a callback"); + @compileLog("Expected TLSSocket.reload to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.reload))); if (@TypeOf(TLSSocket.getRemoteAddress) != GetterType) @compileLog("Expected TLSSocket.getRemoteAddress to be a getter"); if (@TypeOf(TLSSocket.shutdown) != CallbackType) - @compileLog("Expected TLSSocket.shutdown to be a callback"); + @compileLog("Expected TLSSocket.shutdown to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.shutdown))); if (@TypeOf(TLSSocket.timeout) != CallbackType) - @compileLog("Expected TLSSocket.timeout to be a callback"); + @compileLog("Expected TLSSocket.timeout to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.timeout))); if (@TypeOf(TLSSocket.unref) != CallbackType) - @compileLog("Expected TLSSocket.unref to be a callback"); + @compileLog("Expected TLSSocket.unref to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.unref))); if (@TypeOf(TLSSocket.write) != CallbackType) - @compileLog("Expected TLSSocket.write to be a callback"); + @compileLog("Expected TLSSocket.write to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.write))); if (!JSC.is_bindgen) { @export(TLSSocket.end, .{ .name = "TLSSocketPrototype__end" }); @export(TLSSocket.finalize, .{ .name = "TLSSocketClass__finalize" }); @@ -410,16 +410,16 @@ pub const JSListener = struct { @compileLog("Expected Listener.getPort to be a getter"); if (@TypeOf(Listener.ref) != CallbackType) - @compileLog("Expected Listener.ref to be a callback"); + @compileLog("Expected Listener.ref to be a callback but received " ++ @typeName(@TypeOf(Listener.ref))); if (@TypeOf(Listener.reload) != CallbackType) - @compileLog("Expected Listener.reload to be a callback"); + @compileLog("Expected Listener.reload to be a callback but received " ++ @typeName(@TypeOf(Listener.reload))); if (@TypeOf(Listener.stop) != CallbackType) - @compileLog("Expected Listener.stop to be a callback"); + @compileLog("Expected Listener.stop to be a callback but received " ++ @typeName(@TypeOf(Listener.stop))); if (@TypeOf(Listener.getUnix) != GetterType) @compileLog("Expected Listener.getUnix to be a getter"); if (@TypeOf(Listener.unref) != CallbackType) - @compileLog("Expected Listener.unref to be a callback"); + @compileLog("Expected Listener.unref to be a callback but received " ++ @typeName(@TypeOf(Listener.unref))); if (!JSC.is_bindgen) { @export(Listener.finalize, .{ .name = "ListenerClass__finalize" }); @export(Listener.getData, .{ .name = "ListenerPrototype__getData" }); @@ -558,7 +558,7 @@ pub const JSSubprocess = struct { @compileLog("Expected Subprocess.getExited to be a getter"); if (@TypeOf(Subprocess.kill) != CallbackType) - @compileLog("Expected Subprocess.kill to be a callback"); + @compileLog("Expected Subprocess.kill to be a callback but received " ++ @typeName(@TypeOf(Subprocess.kill))); if (@TypeOf(Subprocess.getKilled) != GetterType) @compileLog("Expected Subprocess.getKilled to be a getter"); @@ -569,7 +569,7 @@ pub const JSSubprocess = struct { @compileLog("Expected Subprocess.getStdout to be a getter"); if (@TypeOf(Subprocess.doRef) != CallbackType) - @compileLog("Expected Subprocess.doRef to be a callback"); + @compileLog("Expected Subprocess.doRef to be a callback but received " ++ @typeName(@TypeOf(Subprocess.doRef))); if (@TypeOf(Subprocess.getSignalCode) != GetterType) @compileLog("Expected Subprocess.getSignalCode to be a getter"); @@ -583,7 +583,7 @@ pub const JSSubprocess = struct { @compileLog("Expected Subprocess.getStdout to be a getter"); if (@TypeOf(Subprocess.doUnref) != CallbackType) - @compileLog("Expected Subprocess.doUnref to be a callback"); + @compileLog("Expected Subprocess.doUnref to be a callback but received " ++ @typeName(@TypeOf(Subprocess.doUnref))); if (@TypeOf(Subprocess.getStdin) != GetterType) @compileLog("Expected Subprocess.getStdin to be a getter"); @@ -670,9 +670,9 @@ pub const JSSHA1 = struct { @compileLog("Expected SHA1.getByteLength to be a getter"); if (@TypeOf(SHA1.digest) != CallbackType) - @compileLog("Expected SHA1.digest to be a callback"); + @compileLog("Expected SHA1.digest to be a callback but received " ++ @typeName(@TypeOf(SHA1.digest))); if (@TypeOf(SHA1.update) != CallbackType) - @compileLog("Expected SHA1.update to be a callback"); + @compileLog("Expected SHA1.update to be a callback but received " ++ @typeName(@TypeOf(SHA1.update))); if (@TypeOf(SHA1.getByteLengthStatic) != StaticGetterType) @compileLog("Expected SHA1.getByteLengthStatic to be a static getter"); @@ -755,9 +755,9 @@ pub const JSMD5 = struct { @compileLog("Expected MD5.getByteLength to be a getter"); if (@TypeOf(MD5.digest) != CallbackType) - @compileLog("Expected MD5.digest to be a callback"); + @compileLog("Expected MD5.digest to be a callback but received " ++ @typeName(@TypeOf(MD5.digest))); if (@TypeOf(MD5.update) != CallbackType) - @compileLog("Expected MD5.update to be a callback"); + @compileLog("Expected MD5.update to be a callback but received " ++ @typeName(@TypeOf(MD5.update))); if (@TypeOf(MD5.getByteLengthStatic) != StaticGetterType) @compileLog("Expected MD5.getByteLengthStatic to be a static getter"); @@ -840,9 +840,9 @@ pub const JSMD4 = struct { @compileLog("Expected MD4.getByteLength to be a getter"); if (@TypeOf(MD4.digest) != CallbackType) - @compileLog("Expected MD4.digest to be a callback"); + @compileLog("Expected MD4.digest to be a callback but received " ++ @typeName(@TypeOf(MD4.digest))); if (@TypeOf(MD4.update) != CallbackType) - @compileLog("Expected MD4.update to be a callback"); + @compileLog("Expected MD4.update to be a callback but received " ++ @typeName(@TypeOf(MD4.update))); if (@TypeOf(MD4.getByteLengthStatic) != StaticGetterType) @compileLog("Expected MD4.getByteLengthStatic to be a static getter"); @@ -925,9 +925,9 @@ pub const JSSHA224 = struct { @compileLog("Expected SHA224.getByteLength to be a getter"); if (@TypeOf(SHA224.digest) != CallbackType) - @compileLog("Expected SHA224.digest to be a callback"); + @compileLog("Expected SHA224.digest to be a callback but received " ++ @typeName(@TypeOf(SHA224.digest))); if (@TypeOf(SHA224.update) != CallbackType) - @compileLog("Expected SHA224.update to be a callback"); + @compileLog("Expected SHA224.update to be a callback but received " ++ @typeName(@TypeOf(SHA224.update))); if (@TypeOf(SHA224.getByteLengthStatic) != StaticGetterType) @compileLog("Expected SHA224.getByteLengthStatic to be a static getter"); @@ -1010,9 +1010,9 @@ pub const JSSHA512 = struct { @compileLog("Expected SHA512.getByteLength to be a getter"); if (@TypeOf(SHA512.digest) != CallbackType) - @compileLog("Expected SHA512.digest to be a callback"); + @compileLog("Expected SHA512.digest to be a callback but received " ++ @typeName(@TypeOf(SHA512.digest))); if (@TypeOf(SHA512.update) != CallbackType) - @compileLog("Expected SHA512.update to be a callback"); + @compileLog("Expected SHA512.update to be a callback but received " ++ @typeName(@TypeOf(SHA512.update))); if (@TypeOf(SHA512.getByteLengthStatic) != StaticGetterType) @compileLog("Expected SHA512.getByteLengthStatic to be a static getter"); @@ -1095,9 +1095,9 @@ pub const JSSHA384 = struct { @compileLog("Expected SHA384.getByteLength to be a getter"); if (@TypeOf(SHA384.digest) != CallbackType) - @compileLog("Expected SHA384.digest to be a callback"); + @compileLog("Expected SHA384.digest to be a callback but received " ++ @typeName(@TypeOf(SHA384.digest))); if (@TypeOf(SHA384.update) != CallbackType) - @compileLog("Expected SHA384.update to be a callback"); + @compileLog("Expected SHA384.update to be a callback but received " ++ @typeName(@TypeOf(SHA384.update))); if (@TypeOf(SHA384.getByteLengthStatic) != StaticGetterType) @compileLog("Expected SHA384.getByteLengthStatic to be a static getter"); @@ -1180,9 +1180,9 @@ pub const JSSHA256 = struct { @compileLog("Expected SHA256.getByteLength to be a getter"); if (@TypeOf(SHA256.digest) != CallbackType) - @compileLog("Expected SHA256.digest to be a callback"); + @compileLog("Expected SHA256.digest to be a callback but received " ++ @typeName(@TypeOf(SHA256.digest))); if (@TypeOf(SHA256.update) != CallbackType) - @compileLog("Expected SHA256.update to be a callback"); + @compileLog("Expected SHA256.update to be a callback but received " ++ @typeName(@TypeOf(SHA256.update))); if (@TypeOf(SHA256.getByteLengthStatic) != StaticGetterType) @compileLog("Expected SHA256.getByteLengthStatic to be a static getter"); @@ -1265,9 +1265,9 @@ pub const JSSHA512_256 = struct { @compileLog("Expected SHA512_256.getByteLength to be a getter"); if (@TypeOf(SHA512_256.digest) != CallbackType) - @compileLog("Expected SHA512_256.digest to be a callback"); + @compileLog("Expected SHA512_256.digest to be a callback but received " ++ @typeName(@TypeOf(SHA512_256.digest))); if (@TypeOf(SHA512_256.update) != CallbackType) - @compileLog("Expected SHA512_256.update to be a callback"); + @compileLog("Expected SHA512_256.update to be a callback but received " ++ @typeName(@TypeOf(SHA512_256.update))); if (@TypeOf(SHA512_256.getByteLengthStatic) != StaticGetterType) @compileLog("Expected SHA512_256.getByteLengthStatic to be a static getter"); @@ -1396,28 +1396,28 @@ pub const JSServerWebSocket = struct { if (@TypeOf(ServerWebSocket.setBinaryType) != SetterType) @compileLog("Expected ServerWebSocket.setBinaryType to be a setter"); if (@TypeOf(ServerWebSocket.close) != CallbackType) - @compileLog("Expected ServerWebSocket.close to be a callback"); + @compileLog("Expected ServerWebSocket.close to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.close))); if (@TypeOf(ServerWebSocket.cork) != CallbackType) - @compileLog("Expected ServerWebSocket.cork to be a callback"); + @compileLog("Expected ServerWebSocket.cork to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.cork))); if (@TypeOf(ServerWebSocket.getData) != GetterType) @compileLog("Expected ServerWebSocket.getData to be a getter"); if (@TypeOf(ServerWebSocket.setData) != SetterType) @compileLog("Expected ServerWebSocket.setData to be a setter"); if (@TypeOf(ServerWebSocket.getBufferedAmount) != CallbackType) - @compileLog("Expected ServerWebSocket.getBufferedAmount to be a callback"); + @compileLog("Expected ServerWebSocket.getBufferedAmount to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.getBufferedAmount))); if (@TypeOf(ServerWebSocket.isSubscribed) != CallbackType) - @compileLog("Expected ServerWebSocket.isSubscribed to be a callback"); + @compileLog("Expected ServerWebSocket.isSubscribed to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.isSubscribed))); if (@TypeOf(ServerWebSocket.publish) != CallbackType) - @compileLog("Expected ServerWebSocket.publish to be a callback"); + @compileLog("Expected ServerWebSocket.publish to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.publish))); if (@TypeOf(ServerWebSocket.publishBinaryWithoutTypeChecks) != fn (*ServerWebSocket, *JSC.JSGlobalObject, *JSC.JSString, *JSC.JSUint8Array) callconv(.C) JSC.JSValue) @compileLog("Expected ServerWebSocket.publishBinaryWithoutTypeChecks to be a DOMJIT function"); if (@TypeOf(ServerWebSocket.publishBinary) != CallbackType) - @compileLog("Expected ServerWebSocket.publishBinary to be a callback"); + @compileLog("Expected ServerWebSocket.publishBinary to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.publishBinary))); if (@TypeOf(ServerWebSocket.publishTextWithoutTypeChecks) != fn (*ServerWebSocket, *JSC.JSGlobalObject, *JSC.JSString, *JSC.JSString) callconv(.C) JSC.JSValue) @compileLog("Expected ServerWebSocket.publishTextWithoutTypeChecks to be a DOMJIT function"); if (@TypeOf(ServerWebSocket.publishText) != CallbackType) - @compileLog("Expected ServerWebSocket.publishText to be a callback"); + @compileLog("Expected ServerWebSocket.publishText to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.publishText))); if (@TypeOf(ServerWebSocket.getReadyState) != GetterType) @compileLog("Expected ServerWebSocket.getReadyState to be a getter"); @@ -1425,19 +1425,19 @@ pub const JSServerWebSocket = struct { @compileLog("Expected ServerWebSocket.getRemoteAddress to be a getter"); if (@TypeOf(ServerWebSocket.send) != CallbackType) - @compileLog("Expected ServerWebSocket.send to be a callback"); + @compileLog("Expected ServerWebSocket.send to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.send))); if (@TypeOf(ServerWebSocket.sendBinaryWithoutTypeChecks) != fn (*ServerWebSocket, *JSC.JSGlobalObject, *JSC.JSUint8Array, bool) callconv(.C) JSC.JSValue) @compileLog("Expected ServerWebSocket.sendBinaryWithoutTypeChecks to be a DOMJIT function"); if (@TypeOf(ServerWebSocket.sendBinary) != CallbackType) - @compileLog("Expected ServerWebSocket.sendBinary to be a callback"); + @compileLog("Expected ServerWebSocket.sendBinary to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.sendBinary))); if (@TypeOf(ServerWebSocket.sendTextWithoutTypeChecks) != fn (*ServerWebSocket, *JSC.JSGlobalObject, *JSC.JSString, bool) callconv(.C) JSC.JSValue) @compileLog("Expected ServerWebSocket.sendTextWithoutTypeChecks to be a DOMJIT function"); if (@TypeOf(ServerWebSocket.sendText) != CallbackType) - @compileLog("Expected ServerWebSocket.sendText to be a callback"); + @compileLog("Expected ServerWebSocket.sendText to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.sendText))); if (@TypeOf(ServerWebSocket.subscribe) != CallbackType) - @compileLog("Expected ServerWebSocket.subscribe to be a callback"); + @compileLog("Expected ServerWebSocket.subscribe to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.subscribe))); if (@TypeOf(ServerWebSocket.unsubscribe) != CallbackType) - @compileLog("Expected ServerWebSocket.unsubscribe to be a callback"); + @compileLog("Expected ServerWebSocket.unsubscribe to be a callback but received " ++ @typeName(@TypeOf(ServerWebSocket.unsubscribe))); if (!JSC.is_bindgen) { @export(ServerWebSocket.close, .{ .name = "ServerWebSocketPrototype__close" }); @export(ServerWebSocket.constructor, .{ .name = "ServerWebSocketClass__construct" }); @@ -1595,12 +1595,12 @@ pub const JSFileSystemRouter = struct { } if (@TypeOf(FileSystemRouter.match) != CallbackType) - @compileLog("Expected FileSystemRouter.match to be a callback"); + @compileLog("Expected FileSystemRouter.match to be a callback but received " ++ @typeName(@TypeOf(FileSystemRouter.match))); if (@TypeOf(FileSystemRouter.getOrigin) != GetterType) @compileLog("Expected FileSystemRouter.getOrigin to be a getter"); if (@TypeOf(FileSystemRouter.reload) != CallbackType) - @compileLog("Expected FileSystemRouter.reload to be a callback"); + @compileLog("Expected FileSystemRouter.reload to be a callback but received " ++ @typeName(@TypeOf(FileSystemRouter.reload))); if (@TypeOf(FileSystemRouter.getRoutes) != GetterType) @compileLog("Expected FileSystemRouter.getRoutes to be a getter"); @@ -1972,73 +1972,73 @@ pub const JSExpect = struct { if (@TypeOf(Expect.getResolves) != GetterTypeWithThisValue) @compileLog("Expected Expect.getResolves to be a getter with thisValue"); if (@TypeOf(Expect.toBe) != CallbackType) - @compileLog("Expected Expect.toBe to be a callback"); + @compileLog("Expected Expect.toBe to be a callback but received " ++ @typeName(@TypeOf(Expect.toBe))); if (@TypeOf(Expect.toBeCloseTo) != CallbackType) - @compileLog("Expected Expect.toBeCloseTo to be a callback"); + @compileLog("Expected Expect.toBeCloseTo to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeCloseTo))); if (@TypeOf(Expect.toBeDefined) != CallbackType) - @compileLog("Expected Expect.toBeDefined to be a callback"); + @compileLog("Expected Expect.toBeDefined to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeDefined))); if (@TypeOf(Expect.toBeFalsy) != CallbackType) - @compileLog("Expected Expect.toBeFalsy to be a callback"); + @compileLog("Expected Expect.toBeFalsy to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeFalsy))); if (@TypeOf(Expect.toBeGreaterThan) != CallbackType) - @compileLog("Expected Expect.toBeGreaterThan to be a callback"); + @compileLog("Expected Expect.toBeGreaterThan to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeGreaterThan))); if (@TypeOf(Expect.toBeGreaterThanOrEqual) != CallbackType) - @compileLog("Expected Expect.toBeGreaterThanOrEqual to be a callback"); + @compileLog("Expected Expect.toBeGreaterThanOrEqual to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeGreaterThanOrEqual))); if (@TypeOf(Expect.toBeInstanceOf) != CallbackType) - @compileLog("Expected Expect.toBeInstanceOf to be a callback"); + @compileLog("Expected Expect.toBeInstanceOf to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeInstanceOf))); if (@TypeOf(Expect.toBeLessThan) != CallbackType) - @compileLog("Expected Expect.toBeLessThan to be a callback"); + @compileLog("Expected Expect.toBeLessThan to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeLessThan))); if (@TypeOf(Expect.toBeLessThanOrEqual) != CallbackType) - @compileLog("Expected Expect.toBeLessThanOrEqual to be a callback"); + @compileLog("Expected Expect.toBeLessThanOrEqual to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeLessThanOrEqual))); if (@TypeOf(Expect.toBeNaN) != CallbackType) - @compileLog("Expected Expect.toBeNaN to be a callback"); + @compileLog("Expected Expect.toBeNaN to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeNaN))); if (@TypeOf(Expect.toBeNull) != CallbackType) - @compileLog("Expected Expect.toBeNull to be a callback"); + @compileLog("Expected Expect.toBeNull to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeNull))); if (@TypeOf(Expect.toBeTruthy) != CallbackType) - @compileLog("Expected Expect.toBeTruthy to be a callback"); + @compileLog("Expected Expect.toBeTruthy to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeTruthy))); if (@TypeOf(Expect.toBeUndefined) != CallbackType) - @compileLog("Expected Expect.toBeUndefined to be a callback"); + @compileLog("Expected Expect.toBeUndefined to be a callback but received " ++ @typeName(@TypeOf(Expect.toBeUndefined))); if (@TypeOf(Expect.toContain) != CallbackType) - @compileLog("Expected Expect.toContain to be a callback"); + @compileLog("Expected Expect.toContain to be a callback but received " ++ @typeName(@TypeOf(Expect.toContain))); if (@TypeOf(Expect.toContainEqual) != CallbackType) - @compileLog("Expected Expect.toContainEqual to be a callback"); + @compileLog("Expected Expect.toContainEqual to be a callback but received " ++ @typeName(@TypeOf(Expect.toContainEqual))); if (@TypeOf(Expect.toEqual) != CallbackType) - @compileLog("Expected Expect.toEqual to be a callback"); + @compileLog("Expected Expect.toEqual to be a callback but received " ++ @typeName(@TypeOf(Expect.toEqual))); if (@TypeOf(Expect.toHaveBeenCalledTimes) != CallbackType) - @compileLog("Expected Expect.toHaveBeenCalledTimes to be a callback"); + @compileLog("Expected Expect.toHaveBeenCalledTimes to be a callback but received " ++ @typeName(@TypeOf(Expect.toHaveBeenCalledTimes))); if (@TypeOf(Expect.toHaveBeenCalledWith) != CallbackType) - @compileLog("Expected Expect.toHaveBeenCalledWith to be a callback"); + @compileLog("Expected Expect.toHaveBeenCalledWith to be a callback but received " ++ @typeName(@TypeOf(Expect.toHaveBeenCalledWith))); if (@TypeOf(Expect.toHaveBeenLastCalledWith) != CallbackType) - @compileLog("Expected Expect.toHaveBeenLastCalledWith to be a callback"); + @compileLog("Expected Expect.toHaveBeenLastCalledWith to be a callback but received " ++ @typeName(@TypeOf(Expect.toHaveBeenLastCalledWith))); if (@TypeOf(Expect.toHaveBeenNthCalledWith) != CallbackType) - @compileLog("Expected Expect.toHaveBeenNthCalledWith to be a callback"); + @compileLog("Expected Expect.toHaveBeenNthCalledWith to be a callback but received " ++ @typeName(@TypeOf(Expect.toHaveBeenNthCalledWith))); if (@TypeOf(Expect.toHaveLastReturnedWith) != CallbackType) - @compileLog("Expected Expect.toHaveLastReturnedWith to be a callback"); + @compileLog("Expected Expect.toHaveLastReturnedWith to be a callback but received " ++ @typeName(@TypeOf(Expect.toHaveLastReturnedWith))); if (@TypeOf(Expect.toHaveLength) != CallbackType) - @compileLog("Expected Expect.toHaveLength to be a callback"); + @compileLog("Expected Expect.toHaveLength to be a callback but received " ++ @typeName(@TypeOf(Expect.toHaveLength))); if (@TypeOf(Expect.toHaveNthReturnedWith) != CallbackType) - @compileLog("Expected Expect.toHaveNthReturnedWith to be a callback"); + @compileLog("Expected Expect.toHaveNthReturnedWith to be a callback but received " ++ @typeName(@TypeOf(Expect.toHaveNthReturnedWith))); if (@TypeOf(Expect.toHaveProperty) != CallbackType) - @compileLog("Expected Expect.toHaveProperty to be a callback"); + @compileLog("Expected Expect.toHaveProperty to be a callback but received " ++ @typeName(@TypeOf(Expect.toHaveProperty))); if (@TypeOf(Expect.toHaveReturnedTimes) != CallbackType) - @compileLog("Expected Expect.toHaveReturnedTimes to be a callback"); + @compileLog("Expected Expect.toHaveReturnedTimes to be a callback but received " ++ @typeName(@TypeOf(Expect.toHaveReturnedTimes))); if (@TypeOf(Expect.toHaveReturnedWith) != CallbackType) - @compileLog("Expected Expect.toHaveReturnedWith to be a callback"); + @compileLog("Expected Expect.toHaveReturnedWith to be a callback but received " ++ @typeName(@TypeOf(Expect.toHaveReturnedWith))); if (@TypeOf(Expect.toMatch) != CallbackType) - @compileLog("Expected Expect.toMatch to be a callback"); + @compileLog("Expected Expect.toMatch to be a callback but received " ++ @typeName(@TypeOf(Expect.toMatch))); if (@TypeOf(Expect.toMatchInlineSnapshot) != CallbackType) - @compileLog("Expected Expect.toMatchInlineSnapshot to be a callback"); + @compileLog("Expected Expect.toMatchInlineSnapshot to be a callback but received " ++ @typeName(@TypeOf(Expect.toMatchInlineSnapshot))); if (@TypeOf(Expect.toMatchObject) != CallbackType) - @compileLog("Expected Expect.toMatchObject to be a callback"); + @compileLog("Expected Expect.toMatchObject to be a callback but received " ++ @typeName(@TypeOf(Expect.toMatchObject))); if (@TypeOf(Expect.toMatchSnapshot) != CallbackType) - @compileLog("Expected Expect.toMatchSnapshot to be a callback"); + @compileLog("Expected Expect.toMatchSnapshot to be a callback but received " ++ @typeName(@TypeOf(Expect.toMatchSnapshot))); if (@TypeOf(Expect.toStrictEqual) != CallbackType) - @compileLog("Expected Expect.toStrictEqual to be a callback"); + @compileLog("Expected Expect.toStrictEqual to be a callback but received " ++ @typeName(@TypeOf(Expect.toStrictEqual))); if (@TypeOf(Expect.toThrow) != CallbackType) - @compileLog("Expected Expect.toThrow to be a callback"); + @compileLog("Expected Expect.toThrow to be a callback but received " ++ @typeName(@TypeOf(Expect.toThrow))); if (@TypeOf(Expect.toThrowErrorMatchingInlineSnapshot) != CallbackType) - @compileLog("Expected Expect.toThrowErrorMatchingInlineSnapshot to be a callback"); + @compileLog("Expected Expect.toThrowErrorMatchingInlineSnapshot to be a callback but received " ++ @typeName(@TypeOf(Expect.toThrowErrorMatchingInlineSnapshot))); if (@TypeOf(Expect.toThrowErrorMatchingSnapshot) != CallbackType) - @compileLog("Expected Expect.toThrowErrorMatchingSnapshot to be a callback"); + @compileLog("Expected Expect.toThrowErrorMatchingSnapshot to be a callback but received " ++ @typeName(@TypeOf(Expect.toThrowErrorMatchingSnapshot))); if (@TypeOf(Expect.addSnapshotSerializer) != StaticCallbackType) @compileLog("Expected Expect.addSnapshotSerializer to be a static callback"); if (@TypeOf(Expect.any) != StaticCallbackType) @@ -2214,7 +2214,7 @@ pub const JSTextDecoder = struct { if (@TypeOf(TextDecoder.decodeWithoutTypeChecks) != fn (*TextDecoder, *JSC.JSGlobalObject, *JSC.JSUint8Array) callconv(.C) JSC.JSValue) @compileLog("Expected TextDecoder.decodeWithoutTypeChecks to be a DOMJIT function"); if (@TypeOf(TextDecoder.decode) != CallbackType) - @compileLog("Expected TextDecoder.decode to be a callback"); + @compileLog("Expected TextDecoder.decode to be a callback but received " ++ @typeName(@TypeOf(TextDecoder.decode))); if (@TypeOf(TextDecoder.getEncoding) != GetterType) @compileLog("Expected TextDecoder.getEncoding to be a getter"); @@ -2364,9 +2364,9 @@ pub const JSRequest = struct { } if (@TypeOf(Request.getArrayBuffer) != CallbackType) - @compileLog("Expected Request.getArrayBuffer to be a callback"); + @compileLog("Expected Request.getArrayBuffer to be a callback but received " ++ @typeName(@TypeOf(Request.getArrayBuffer))); if (@TypeOf(Request.getBlob) != CallbackType) - @compileLog("Expected Request.getBlob to be a callback"); + @compileLog("Expected Request.getBlob to be a callback but received " ++ @typeName(@TypeOf(Request.getBlob))); if (@TypeOf(Request.getBody) != GetterType) @compileLog("Expected Request.getBody to be a getter"); @@ -2377,7 +2377,7 @@ pub const JSRequest = struct { @compileLog("Expected Request.getCache to be a getter"); if (@TypeOf(Request.doClone) != CallbackType) - @compileLog("Expected Request.doClone to be a callback"); + @compileLog("Expected Request.doClone to be a callback but received " ++ @typeName(@TypeOf(Request.doClone))); if (@TypeOf(Request.getCredentials) != GetterType) @compileLog("Expected Request.getCredentials to be a getter"); @@ -2391,7 +2391,7 @@ pub const JSRequest = struct { @compileLog("Expected Request.getIntegrity to be a getter"); if (@TypeOf(Request.getJSON) != CallbackType) - @compileLog("Expected Request.getJSON to be a callback"); + @compileLog("Expected Request.getJSON to be a callback but received " ++ @typeName(@TypeOf(Request.getJSON))); if (@TypeOf(Request.getMethod) != GetterType) @compileLog("Expected Request.getMethod to be a getter"); @@ -2408,7 +2408,7 @@ pub const JSRequest = struct { @compileLog("Expected Request.getReferrerPolicy to be a getter"); if (@TypeOf(Request.getText) != CallbackType) - @compileLog("Expected Request.getText to be a callback"); + @compileLog("Expected Request.getText to be a callback but received " ++ @typeName(@TypeOf(Request.getText))); if (@TypeOf(Request.getUrl) != GetterType) @compileLog("Expected Request.getUrl to be a getter"); @@ -2592,9 +2592,9 @@ pub const JSResponse = struct { } if (@TypeOf(Response.getArrayBuffer) != CallbackType) - @compileLog("Expected Response.getArrayBuffer to be a callback"); + @compileLog("Expected Response.getArrayBuffer to be a callback but received " ++ @typeName(@TypeOf(Response.getArrayBuffer))); if (@TypeOf(Response.getBlob) != CallbackType) - @compileLog("Expected Response.getBlob to be a callback"); + @compileLog("Expected Response.getBlob to be a callback but received " ++ @typeName(@TypeOf(Response.getBlob))); if (@TypeOf(Response.getBody) != GetterType) @compileLog("Expected Response.getBody to be a getter"); @@ -2602,12 +2602,12 @@ pub const JSResponse = struct { @compileLog("Expected Response.getBodyUsed to be a getter"); if (@TypeOf(Response.doClone) != CallbackType) - @compileLog("Expected Response.doClone to be a callback"); + @compileLog("Expected Response.doClone to be a callback but received " ++ @typeName(@TypeOf(Response.doClone))); if (@TypeOf(Response.getHeaders) != GetterType) @compileLog("Expected Response.getHeaders to be a getter"); if (@TypeOf(Response.getJSON) != CallbackType) - @compileLog("Expected Response.getJSON to be a callback"); + @compileLog("Expected Response.getJSON to be a callback but received " ++ @typeName(@TypeOf(Response.getJSON))); if (@TypeOf(Response.getOK) != GetterType) @compileLog("Expected Response.getOK to be a getter"); @@ -2621,7 +2621,7 @@ pub const JSResponse = struct { @compileLog("Expected Response.getStatusText to be a getter"); if (@TypeOf(Response.getText) != CallbackType) - @compileLog("Expected Response.getText to be a callback"); + @compileLog("Expected Response.getText to be a callback but received " ++ @typeName(@TypeOf(Response.getText))); if (@TypeOf(Response.getResponseType) != GetterType) @compileLog("Expected Response.getResponseType to be a getter"); @@ -2721,25 +2721,25 @@ pub const JSBlob = struct { } if (@TypeOf(Blob.getArrayBuffer) != CallbackType) - @compileLog("Expected Blob.getArrayBuffer to be a callback"); + @compileLog("Expected Blob.getArrayBuffer to be a callback but received " ++ @typeName(@TypeOf(Blob.getArrayBuffer))); if (@TypeOf(Blob.getJSON) != CallbackType) - @compileLog("Expected Blob.getJSON to be a callback"); + @compileLog("Expected Blob.getJSON to be a callback but received " ++ @typeName(@TypeOf(Blob.getJSON))); if (@TypeOf(Blob.getSize) != GetterType) @compileLog("Expected Blob.getSize to be a getter"); if (@TypeOf(Blob.getSlice) != CallbackType) - @compileLog("Expected Blob.getSlice to be a callback"); + @compileLog("Expected Blob.getSlice to be a callback but received " ++ @typeName(@TypeOf(Blob.getSlice))); if (@TypeOf(Blob.getStream) != CallbackType) - @compileLog("Expected Blob.getStream to be a callback"); + @compileLog("Expected Blob.getStream to be a callback but received " ++ @typeName(@TypeOf(Blob.getStream))); if (@TypeOf(Blob.getText) != CallbackType) - @compileLog("Expected Blob.getText to be a callback"); + @compileLog("Expected Blob.getText to be a callback but received " ++ @typeName(@TypeOf(Blob.getText))); if (@TypeOf(Blob.getType) != GetterType) @compileLog("Expected Blob.getType to be a getter"); if (@TypeOf(Blob.setType) != SetterType) @compileLog("Expected Blob.setType to be a setter"); if (@TypeOf(Blob.getWriter) != CallbackType) - @compileLog("Expected Blob.getWriter to be a callback"); + @compileLog("Expected Blob.getWriter to be a callback but received " ++ @typeName(@TypeOf(Blob.getWriter))); if (!JSC.is_bindgen) { @export(Blob.constructor, .{ .name = "BlobClass__construct" }); @export(Blob.finalize, .{ .name = "BlobClass__finalize" }); @@ -2755,6 +2755,428 @@ pub const JSBlob = struct { } } }; +pub const JSDirent = struct { + const Dirent = Classes.Dirent; + const GetterType = fn (*Dirent, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; + const GetterTypeWithThisValue = fn (*Dirent, JSC.JSValue, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; + const SetterType = fn (*Dirent, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; + const SetterTypeWithThisValue = fn (*Dirent, JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; + const CallbackType = fn (*Dirent, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue; + + /// Return the pointer to the wrapped object. + /// If the object does not match the type, return null. + pub fn fromJS(value: JSC.JSValue) ?*Dirent { + JSC.markBinding(@src()); + return Dirent__fromJS(value); + } + + extern fn DirentPrototype__nameSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void; + + extern fn DirentPrototype__nameGetCachedValue(JSC.JSValue) JSC.JSValue; + + /// `Dirent.name` setter + /// This value will be visited by the garbage collector. + pub fn nameSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { + JSC.markBinding(@src()); + DirentPrototype__nameSetCachedValue(thisValue, globalObject, value); + } + + /// `Dirent.name` getter + /// This value will be visited by the garbage collector. + pub fn nameGetCached(thisValue: JSC.JSValue) ?JSC.JSValue { + JSC.markBinding(@src()); + const result = DirentPrototype__nameGetCachedValue(thisValue); + if (result == .zero) + return null; + + return result; + } + + /// Get the Dirent constructor value. + /// This loads lazily from the global object. + pub fn getConstructor(globalObject: *JSC.JSGlobalObject) JSC.JSValue { + JSC.markBinding(@src()); + return Dirent__getConstructor(globalObject); + } + + /// Create a new instance of Dirent + pub fn toJS(this: *Dirent, globalObject: *JSC.JSGlobalObject) JSC.JSValue { + JSC.markBinding(@src()); + if (comptime Environment.allow_assert) { + const value__ = Dirent__create(globalObject, this); + std.debug.assert(value__.as(Dirent).? == this); // If this fails, likely a C ABI issue. + return value__; + } else { + return Dirent__create(globalObject, this); + } + } + + /// Modify the internal ptr to point to a new instance of Dirent. + pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*Dirent) bool { + JSC.markBinding(@src()); + return Dirent__dangerouslySetPtr(value, ptr); + } + + /// Detach the ptr from the thisValue + pub fn detachPtr(_: *Dirent, value: JSC.JSValue) void { + JSC.markBinding(@src()); + std.debug.assert(Dirent__dangerouslySetPtr(value, null)); + } + + extern fn Dirent__fromJS(JSC.JSValue) ?*Dirent; + extern fn Dirent__getConstructor(*JSC.JSGlobalObject) JSC.JSValue; + + extern fn Dirent__create(globalObject: *JSC.JSGlobalObject, ptr: ?*Dirent) JSC.JSValue; + + extern fn Dirent__dangerouslySetPtr(JSC.JSValue, ?*Dirent) bool; + + comptime { + if (@TypeOf(Dirent.constructor) != (fn (*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) ?*Dirent)) { + @compileLog("Dirent.constructor is not a constructor"); + } + + if (@TypeOf(Dirent.finalize) != (fn (*Dirent) callconv(.C) void)) { + @compileLog("Dirent.finalize is not a finalizer"); + } + + if (@TypeOf(Dirent.isBlockDevice) != CallbackType) + @compileLog("Expected Dirent.isBlockDevice to be a callback but received " ++ @typeName(@TypeOf(Dirent.isBlockDevice))); + if (@TypeOf(Dirent.isCharacterDevice) != CallbackType) + @compileLog("Expected Dirent.isCharacterDevice to be a callback but received " ++ @typeName(@TypeOf(Dirent.isCharacterDevice))); + if (@TypeOf(Dirent.isDirectory) != CallbackType) + @compileLog("Expected Dirent.isDirectory to be a callback but received " ++ @typeName(@TypeOf(Dirent.isDirectory))); + if (@TypeOf(Dirent.isFIFO) != CallbackType) + @compileLog("Expected Dirent.isFIFO to be a callback but received " ++ @typeName(@TypeOf(Dirent.isFIFO))); + if (@TypeOf(Dirent.isFile) != CallbackType) + @compileLog("Expected Dirent.isFile to be a callback but received " ++ @typeName(@TypeOf(Dirent.isFile))); + if (@TypeOf(Dirent.isSocket) != CallbackType) + @compileLog("Expected Dirent.isSocket to be a callback but received " ++ @typeName(@TypeOf(Dirent.isSocket))); + if (@TypeOf(Dirent.isSymbolicLink) != CallbackType) + @compileLog("Expected Dirent.isSymbolicLink to be a callback but received " ++ @typeName(@TypeOf(Dirent.isSymbolicLink))); + if (@TypeOf(Dirent.getName) != GetterType) + @compileLog("Expected Dirent.getName to be a getter"); + + if (!JSC.is_bindgen) { + @export(Dirent.constructor, .{ .name = "DirentClass__construct" }); + @export(Dirent.finalize, .{ .name = "DirentClass__finalize" }); + @export(Dirent.getName, .{ .name = "DirentPrototype__getName" }); + @export(Dirent.isBlockDevice, .{ .name = "DirentPrototype__isBlockDevice" }); + @export(Dirent.isCharacterDevice, .{ .name = "DirentPrototype__isCharacterDevice" }); + @export(Dirent.isDirectory, .{ .name = "DirentPrototype__isDirectory" }); + @export(Dirent.isFIFO, .{ .name = "DirentPrototype__isFIFO" }); + @export(Dirent.isFile, .{ .name = "DirentPrototype__isFile" }); + @export(Dirent.isSocket, .{ .name = "DirentPrototype__isSocket" }); + @export(Dirent.isSymbolicLink, .{ .name = "DirentPrototype__isSymbolicLink" }); + } + } +}; +pub const JSNodeJSFS = struct { + const NodeJSFS = Classes.NodeJSFS; + const GetterType = fn (*NodeJSFS, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; + const GetterTypeWithThisValue = fn (*NodeJSFS, JSC.JSValue, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue; + const SetterType = fn (*NodeJSFS, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; + const SetterTypeWithThisValue = fn (*NodeJSFS, JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool; + const CallbackType = fn (*NodeJSFS, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue; + + /// Return the pointer to the wrapped object. + /// If the object does not match the type, return null. + pub fn fromJS(value: JSC.JSValue) ?*NodeJSFS { + JSC.markBinding(@src()); + return NodeJSFS__fromJS(value); + } + + /// Get the NodeJSFS constructor value. + /// This loads lazily from the global object. + pub fn getConstructor(globalObject: *JSC.JSGlobalObject) JSC.JSValue { + JSC.markBinding(@src()); + return NodeJSFS__getConstructor(globalObject); + } + + /// Create a new instance of NodeJSFS + pub fn toJS(this: *NodeJSFS, globalObject: *JSC.JSGlobalObject) JSC.JSValue { + JSC.markBinding(@src()); + if (comptime Environment.allow_assert) { + const value__ = NodeJSFS__create(globalObject, this); + std.debug.assert(value__.as(NodeJSFS).? == this); // If this fails, likely a C ABI issue. + return value__; + } else { + return NodeJSFS__create(globalObject, this); + } + } + + /// Modify the internal ptr to point to a new instance of NodeJSFS. + pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*NodeJSFS) bool { + JSC.markBinding(@src()); + return NodeJSFS__dangerouslySetPtr(value, ptr); + } + + /// Detach the ptr from the thisValue + pub fn detachPtr(_: *NodeJSFS, value: JSC.JSValue) void { + JSC.markBinding(@src()); + std.debug.assert(NodeJSFS__dangerouslySetPtr(value, null)); + } + + extern fn NodeJSFS__fromJS(JSC.JSValue) ?*NodeJSFS; + extern fn NodeJSFS__getConstructor(*JSC.JSGlobalObject) JSC.JSValue; + + extern fn NodeJSFS__create(globalObject: *JSC.JSGlobalObject, ptr: ?*NodeJSFS) JSC.JSValue; + + extern fn NodeJSFS__dangerouslySetPtr(JSC.JSValue, ?*NodeJSFS) bool; + + comptime { + if (@TypeOf(NodeJSFS.constructor) != (fn (*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) ?*NodeJSFS)) { + @compileLog("NodeJSFS.constructor is not a constructor"); + } + + if (@TypeOf(NodeJSFS.access) != CallbackType) + @compileLog("Expected NodeJSFS.access to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.access))); + if (@TypeOf(NodeJSFS.accessSync) != CallbackType) + @compileLog("Expected NodeJSFS.accessSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.accessSync))); + if (@TypeOf(NodeJSFS.appendFile) != CallbackType) + @compileLog("Expected NodeJSFS.appendFile to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.appendFile))); + if (@TypeOf(NodeJSFS.appendFileSync) != CallbackType) + @compileLog("Expected NodeJSFS.appendFileSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.appendFileSync))); + if (@TypeOf(NodeJSFS.chmod) != CallbackType) + @compileLog("Expected NodeJSFS.chmod to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.chmod))); + if (@TypeOf(NodeJSFS.chmodSync) != CallbackType) + @compileLog("Expected NodeJSFS.chmodSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.chmodSync))); + if (@TypeOf(NodeJSFS.chown) != CallbackType) + @compileLog("Expected NodeJSFS.chown to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.chown))); + if (@TypeOf(NodeJSFS.chownSync) != CallbackType) + @compileLog("Expected NodeJSFS.chownSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.chownSync))); + if (@TypeOf(NodeJSFS.close) != CallbackType) + @compileLog("Expected NodeJSFS.close to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.close))); + if (@TypeOf(NodeJSFS.closeSync) != CallbackType) + @compileLog("Expected NodeJSFS.closeSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.closeSync))); + if (@TypeOf(NodeJSFS.copyFile) != CallbackType) + @compileLog("Expected NodeJSFS.copyFile to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.copyFile))); + if (@TypeOf(NodeJSFS.copyFileSync) != CallbackType) + @compileLog("Expected NodeJSFS.copyFileSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.copyFileSync))); + if (@TypeOf(NodeJSFS.getDirent) != GetterType) + @compileLog("Expected NodeJSFS.getDirent to be a getter"); + + if (@TypeOf(NodeJSFS.exists) != CallbackType) + @compileLog("Expected NodeJSFS.exists to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.exists))); + if (@TypeOf(NodeJSFS.existsSync) != CallbackType) + @compileLog("Expected NodeJSFS.existsSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.existsSync))); + if (@TypeOf(NodeJSFS.fchmod) != CallbackType) + @compileLog("Expected NodeJSFS.fchmod to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.fchmod))); + if (@TypeOf(NodeJSFS.fchmodSync) != CallbackType) + @compileLog("Expected NodeJSFS.fchmodSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.fchmodSync))); + if (@TypeOf(NodeJSFS.fchown) != CallbackType) + @compileLog("Expected NodeJSFS.fchown to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.fchown))); + if (@TypeOf(NodeJSFS.fchownSync) != CallbackType) + @compileLog("Expected NodeJSFS.fchownSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.fchownSync))); + if (@TypeOf(NodeJSFS.fdatasync) != CallbackType) + @compileLog("Expected NodeJSFS.fdatasync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.fdatasync))); + if (@TypeOf(NodeJSFS.fdatasyncSync) != CallbackType) + @compileLog("Expected NodeJSFS.fdatasyncSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.fdatasyncSync))); + if (@TypeOf(NodeJSFS.fstat) != CallbackType) + @compileLog("Expected NodeJSFS.fstat to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.fstat))); + if (@TypeOf(NodeJSFS.fstatSync) != CallbackType) + @compileLog("Expected NodeJSFS.fstatSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.fstatSync))); + if (@TypeOf(NodeJSFS.fsync) != CallbackType) + @compileLog("Expected NodeJSFS.fsync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.fsync))); + if (@TypeOf(NodeJSFS.fsyncSync) != CallbackType) + @compileLog("Expected NodeJSFS.fsyncSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.fsyncSync))); + if (@TypeOf(NodeJSFS.ftruncate) != CallbackType) + @compileLog("Expected NodeJSFS.ftruncate to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.ftruncate))); + if (@TypeOf(NodeJSFS.ftruncateSync) != CallbackType) + @compileLog("Expected NodeJSFS.ftruncateSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.ftruncateSync))); + if (@TypeOf(NodeJSFS.futimes) != CallbackType) + @compileLog("Expected NodeJSFS.futimes to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.futimes))); + if (@TypeOf(NodeJSFS.futimesSync) != CallbackType) + @compileLog("Expected NodeJSFS.futimesSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.futimesSync))); + if (@TypeOf(NodeJSFS.lchmod) != CallbackType) + @compileLog("Expected NodeJSFS.lchmod to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.lchmod))); + if (@TypeOf(NodeJSFS.lchmodSync) != CallbackType) + @compileLog("Expected NodeJSFS.lchmodSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.lchmodSync))); + if (@TypeOf(NodeJSFS.lchown) != CallbackType) + @compileLog("Expected NodeJSFS.lchown to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.lchown))); + if (@TypeOf(NodeJSFS.lchownSync) != CallbackType) + @compileLog("Expected NodeJSFS.lchownSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.lchownSync))); + if (@TypeOf(NodeJSFS.link) != CallbackType) + @compileLog("Expected NodeJSFS.link to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.link))); + if (@TypeOf(NodeJSFS.linkSync) != CallbackType) + @compileLog("Expected NodeJSFS.linkSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.linkSync))); + if (@TypeOf(NodeJSFS.lstat) != CallbackType) + @compileLog("Expected NodeJSFS.lstat to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.lstat))); + if (@TypeOf(NodeJSFS.lstatSync) != CallbackType) + @compileLog("Expected NodeJSFS.lstatSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.lstatSync))); + if (@TypeOf(NodeJSFS.lutimes) != CallbackType) + @compileLog("Expected NodeJSFS.lutimes to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.lutimes))); + if (@TypeOf(NodeJSFS.lutimesSync) != CallbackType) + @compileLog("Expected NodeJSFS.lutimesSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.lutimesSync))); + if (@TypeOf(NodeJSFS.mkdir) != CallbackType) + @compileLog("Expected NodeJSFS.mkdir to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.mkdir))); + if (@TypeOf(NodeJSFS.mkdirSync) != CallbackType) + @compileLog("Expected NodeJSFS.mkdirSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.mkdirSync))); + if (@TypeOf(NodeJSFS.mkdtemp) != CallbackType) + @compileLog("Expected NodeJSFS.mkdtemp to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.mkdtemp))); + if (@TypeOf(NodeJSFS.mkdtempSync) != CallbackType) + @compileLog("Expected NodeJSFS.mkdtempSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.mkdtempSync))); + if (@TypeOf(NodeJSFS.open) != CallbackType) + @compileLog("Expected NodeJSFS.open to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.open))); + if (@TypeOf(NodeJSFS.opendir) != CallbackType) + @compileLog("Expected NodeJSFS.opendir to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.opendir))); + if (@TypeOf(NodeJSFS.opendirSync) != CallbackType) + @compileLog("Expected NodeJSFS.opendirSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.opendirSync))); + if (@TypeOf(NodeJSFS.openSync) != CallbackType) + @compileLog("Expected NodeJSFS.openSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.openSync))); + if (@TypeOf(NodeJSFS.read) != CallbackType) + @compileLog("Expected NodeJSFS.read to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.read))); + if (@TypeOf(NodeJSFS.readdir) != CallbackType) + @compileLog("Expected NodeJSFS.readdir to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.readdir))); + if (@TypeOf(NodeJSFS.readdirSync) != CallbackType) + @compileLog("Expected NodeJSFS.readdirSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.readdirSync))); + if (@TypeOf(NodeJSFS.readFile) != CallbackType) + @compileLog("Expected NodeJSFS.readFile to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.readFile))); + if (@TypeOf(NodeJSFS.readFileSync) != CallbackType) + @compileLog("Expected NodeJSFS.readFileSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.readFileSync))); + if (@TypeOf(NodeJSFS.readlink) != CallbackType) + @compileLog("Expected NodeJSFS.readlink to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.readlink))); + if (@TypeOf(NodeJSFS.readlinkSync) != CallbackType) + @compileLog("Expected NodeJSFS.readlinkSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.readlinkSync))); + if (@TypeOf(NodeJSFS.readSync) != CallbackType) + @compileLog("Expected NodeJSFS.readSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.readSync))); + if (@TypeOf(NodeJSFS.readv) != CallbackType) + @compileLog("Expected NodeJSFS.readv to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.readv))); + if (@TypeOf(NodeJSFS.readvSync) != CallbackType) + @compileLog("Expected NodeJSFS.readvSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.readvSync))); + if (@TypeOf(NodeJSFS.realpath) != CallbackType) + @compileLog("Expected NodeJSFS.realpath to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.realpath))); + if (@TypeOf(NodeJSFS.realpathSync) != CallbackType) + @compileLog("Expected NodeJSFS.realpathSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.realpathSync))); + if (@TypeOf(NodeJSFS.rename) != CallbackType) + @compileLog("Expected NodeJSFS.rename to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.rename))); + if (@TypeOf(NodeJSFS.renameSync) != CallbackType) + @compileLog("Expected NodeJSFS.renameSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.renameSync))); + if (@TypeOf(NodeJSFS.rm) != CallbackType) + @compileLog("Expected NodeJSFS.rm to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.rm))); + if (@TypeOf(NodeJSFS.rmdir) != CallbackType) + @compileLog("Expected NodeJSFS.rmdir to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.rmdir))); + if (@TypeOf(NodeJSFS.rmdirSync) != CallbackType) + @compileLog("Expected NodeJSFS.rmdirSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.rmdirSync))); + if (@TypeOf(NodeJSFS.rmSync) != CallbackType) + @compileLog("Expected NodeJSFS.rmSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.rmSync))); + if (@TypeOf(NodeJSFS.stat) != CallbackType) + @compileLog("Expected NodeJSFS.stat to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.stat))); + if (@TypeOf(NodeJSFS.statSync) != CallbackType) + @compileLog("Expected NodeJSFS.statSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.statSync))); + if (@TypeOf(NodeJSFS.symlink) != CallbackType) + @compileLog("Expected NodeJSFS.symlink to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.symlink))); + if (@TypeOf(NodeJSFS.symlinkSync) != CallbackType) + @compileLog("Expected NodeJSFS.symlinkSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.symlinkSync))); + if (@TypeOf(NodeJSFS.truncate) != CallbackType) + @compileLog("Expected NodeJSFS.truncate to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.truncate))); + if (@TypeOf(NodeJSFS.truncateSync) != CallbackType) + @compileLog("Expected NodeJSFS.truncateSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.truncateSync))); + if (@TypeOf(NodeJSFS.unlink) != CallbackType) + @compileLog("Expected NodeJSFS.unlink to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.unlink))); + if (@TypeOf(NodeJSFS.unlinkSync) != CallbackType) + @compileLog("Expected NodeJSFS.unlinkSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.unlinkSync))); + if (@TypeOf(NodeJSFS.utimes) != CallbackType) + @compileLog("Expected NodeJSFS.utimes to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.utimes))); + if (@TypeOf(NodeJSFS.utimesSync) != CallbackType) + @compileLog("Expected NodeJSFS.utimesSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.utimesSync))); + if (@TypeOf(NodeJSFS.write) != CallbackType) + @compileLog("Expected NodeJSFS.write to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.write))); + if (@TypeOf(NodeJSFS.writeFile) != CallbackType) + @compileLog("Expected NodeJSFS.writeFile to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.writeFile))); + if (@TypeOf(NodeJSFS.writeFileSync) != CallbackType) + @compileLog("Expected NodeJSFS.writeFileSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.writeFileSync))); + if (@TypeOf(NodeJSFS.writeSync) != CallbackType) + @compileLog("Expected NodeJSFS.writeSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.writeSync))); + if (@TypeOf(NodeJSFS.writev) != CallbackType) + @compileLog("Expected NodeJSFS.writev to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.writev))); + if (@TypeOf(NodeJSFS.writevSync) != CallbackType) + @compileLog("Expected NodeJSFS.writevSync to be a callback but received " ++ @typeName(@TypeOf(NodeJSFS.writevSync))); + if (!JSC.is_bindgen) { + @export(NodeJSFS.access, .{ .name = "NodeJSFSPrototype__access" }); + @export(NodeJSFS.accessSync, .{ .name = "NodeJSFSPrototype__accessSync" }); + @export(NodeJSFS.appendFile, .{ .name = "NodeJSFSPrototype__appendFile" }); + @export(NodeJSFS.appendFileSync, .{ .name = "NodeJSFSPrototype__appendFileSync" }); + @export(NodeJSFS.chmod, .{ .name = "NodeJSFSPrototype__chmod" }); + @export(NodeJSFS.chmodSync, .{ .name = "NodeJSFSPrototype__chmodSync" }); + @export(NodeJSFS.chown, .{ .name = "NodeJSFSPrototype__chown" }); + @export(NodeJSFS.chownSync, .{ .name = "NodeJSFSPrototype__chownSync" }); + @export(NodeJSFS.close, .{ .name = "NodeJSFSPrototype__close" }); + @export(NodeJSFS.closeSync, .{ .name = "NodeJSFSPrototype__closeSync" }); + @export(NodeJSFS.constructor, .{ .name = "NodeJSFSClass__construct" }); + @export(NodeJSFS.copyFile, .{ .name = "NodeJSFSPrototype__copyFile" }); + @export(NodeJSFS.copyFileSync, .{ .name = "NodeJSFSPrototype__copyFileSync" }); + @export(NodeJSFS.exists, .{ .name = "NodeJSFSPrototype__exists" }); + @export(NodeJSFS.existsSync, .{ .name = "NodeJSFSPrototype__existsSync" }); + @export(NodeJSFS.fchmod, .{ .name = "NodeJSFSPrototype__fchmod" }); + @export(NodeJSFS.fchmodSync, .{ .name = "NodeJSFSPrototype__fchmodSync" }); + @export(NodeJSFS.fchown, .{ .name = "NodeJSFSPrototype__fchown" }); + @export(NodeJSFS.fchownSync, .{ .name = "NodeJSFSPrototype__fchownSync" }); + @export(NodeJSFS.fdatasync, .{ .name = "NodeJSFSPrototype__fdatasync" }); + @export(NodeJSFS.fdatasyncSync, .{ .name = "NodeJSFSPrototype__fdatasyncSync" }); + @export(NodeJSFS.fstat, .{ .name = "NodeJSFSPrototype__fstat" }); + @export(NodeJSFS.fstatSync, .{ .name = "NodeJSFSPrototype__fstatSync" }); + @export(NodeJSFS.fsync, .{ .name = "NodeJSFSPrototype__fsync" }); + @export(NodeJSFS.fsyncSync, .{ .name = "NodeJSFSPrototype__fsyncSync" }); + @export(NodeJSFS.ftruncate, .{ .name = "NodeJSFSPrototype__ftruncate" }); + @export(NodeJSFS.ftruncateSync, .{ .name = "NodeJSFSPrototype__ftruncateSync" }); + @export(NodeJSFS.futimes, .{ .name = "NodeJSFSPrototype__futimes" }); + @export(NodeJSFS.futimesSync, .{ .name = "NodeJSFSPrototype__futimesSync" }); + @export(NodeJSFS.getDirent, .{ .name = "NodeJSFSPrototype__getDirent" }); + @export(NodeJSFS.lchmod, .{ .name = "NodeJSFSPrototype__lchmod" }); + @export(NodeJSFS.lchmodSync, .{ .name = "NodeJSFSPrototype__lchmodSync" }); + @export(NodeJSFS.lchown, .{ .name = "NodeJSFSPrototype__lchown" }); + @export(NodeJSFS.lchownSync, .{ .name = "NodeJSFSPrototype__lchownSync" }); + @export(NodeJSFS.link, .{ .name = "NodeJSFSPrototype__link" }); + @export(NodeJSFS.linkSync, .{ .name = "NodeJSFSPrototype__linkSync" }); + @export(NodeJSFS.lstat, .{ .name = "NodeJSFSPrototype__lstat" }); + @export(NodeJSFS.lstatSync, .{ .name = "NodeJSFSPrototype__lstatSync" }); + @export(NodeJSFS.lutimes, .{ .name = "NodeJSFSPrototype__lutimes" }); + @export(NodeJSFS.lutimesSync, .{ .name = "NodeJSFSPrototype__lutimesSync" }); + @export(NodeJSFS.mkdir, .{ .name = "NodeJSFSPrototype__mkdir" }); + @export(NodeJSFS.mkdirSync, .{ .name = "NodeJSFSPrototype__mkdirSync" }); + @export(NodeJSFS.mkdtemp, .{ .name = "NodeJSFSPrototype__mkdtemp" }); + @export(NodeJSFS.mkdtempSync, .{ .name = "NodeJSFSPrototype__mkdtempSync" }); + @export(NodeJSFS.open, .{ .name = "NodeJSFSPrototype__open" }); + @export(NodeJSFS.opendir, .{ .name = "NodeJSFSPrototype__opendir" }); + @export(NodeJSFS.opendirSync, .{ .name = "NodeJSFSPrototype__opendirSync" }); + @export(NodeJSFS.openSync, .{ .name = "NodeJSFSPrototype__openSync" }); + @export(NodeJSFS.read, .{ .name = "NodeJSFSPrototype__read" }); + @export(NodeJSFS.readdir, .{ .name = "NodeJSFSPrototype__readdir" }); + @export(NodeJSFS.readdirSync, .{ .name = "NodeJSFSPrototype__readdirSync" }); + @export(NodeJSFS.readFile, .{ .name = "NodeJSFSPrototype__readFile" }); + @export(NodeJSFS.readFileSync, .{ .name = "NodeJSFSPrototype__readFileSync" }); + @export(NodeJSFS.readlink, .{ .name = "NodeJSFSPrototype__readlink" }); + @export(NodeJSFS.readlinkSync, .{ .name = "NodeJSFSPrototype__readlinkSync" }); + @export(NodeJSFS.readSync, .{ .name = "NodeJSFSPrototype__readSync" }); + @export(NodeJSFS.readv, .{ .name = "NodeJSFSPrototype__readv" }); + @export(NodeJSFS.readvSync, .{ .name = "NodeJSFSPrototype__readvSync" }); + @export(NodeJSFS.realpath, .{ .name = "NodeJSFSPrototype__realpath" }); + @export(NodeJSFS.realpathSync, .{ .name = "NodeJSFSPrototype__realpathSync" }); + @export(NodeJSFS.rename, .{ .name = "NodeJSFSPrototype__rename" }); + @export(NodeJSFS.renameSync, .{ .name = "NodeJSFSPrototype__renameSync" }); + @export(NodeJSFS.rm, .{ .name = "NodeJSFSPrototype__rm" }); + @export(NodeJSFS.rmdir, .{ .name = "NodeJSFSPrototype__rmdir" }); + @export(NodeJSFS.rmdirSync, .{ .name = "NodeJSFSPrototype__rmdirSync" }); + @export(NodeJSFS.rmSync, .{ .name = "NodeJSFSPrototype__rmSync" }); + @export(NodeJSFS.stat, .{ .name = "NodeJSFSPrototype__stat" }); + @export(NodeJSFS.statSync, .{ .name = "NodeJSFSPrototype__statSync" }); + @export(NodeJSFS.symlink, .{ .name = "NodeJSFSPrototype__symlink" }); + @export(NodeJSFS.symlinkSync, .{ .name = "NodeJSFSPrototype__symlinkSync" }); + @export(NodeJSFS.truncate, .{ .name = "NodeJSFSPrototype__truncate" }); + @export(NodeJSFS.truncateSync, .{ .name = "NodeJSFSPrototype__truncateSync" }); + @export(NodeJSFS.unlink, .{ .name = "NodeJSFSPrototype__unlink" }); + @export(NodeJSFS.unlinkSync, .{ .name = "NodeJSFSPrototype__unlinkSync" }); + @export(NodeJSFS.utimes, .{ .name = "NodeJSFSPrototype__utimes" }); + @export(NodeJSFS.utimesSync, .{ .name = "NodeJSFSPrototype__utimesSync" }); + @export(NodeJSFS.write, .{ .name = "NodeJSFSPrototype__write" }); + @export(NodeJSFS.writeFile, .{ .name = "NodeJSFSPrototype__writeFile" }); + @export(NodeJSFS.writeFileSync, .{ .name = "NodeJSFSPrototype__writeFileSync" }); + @export(NodeJSFS.writeSync, .{ .name = "NodeJSFSPrototype__writeSync" }); + @export(NodeJSFS.writev, .{ .name = "NodeJSFSPrototype__writev" }); + @export(NodeJSFS.writevSync, .{ .name = "NodeJSFSPrototype__writevSync" }); + } + } +}; comptime { _ = JSTCPSocket; @@ -2777,4 +3199,6 @@ comptime { _ = JSRequest; _ = JSResponse; _ = JSBlob; + _ = JSDirent; + _ = JSNodeJSFS; } diff --git a/src/bun.js/bindings/generated_classes_list.zig b/src/bun.js/bindings/generated_classes_list.zig index 1c7dfc5ad..53019d178 100644 --- a/src/bun.js/bindings/generated_classes_list.zig +++ b/src/bun.js/bindings/generated_classes_list.zig @@ -21,4 +21,6 @@ pub const Classes = struct { pub const Expect = JSC.Jest.Expect; pub const FileSystemRouter = JSC.API.FileSystemRouter; pub const MatchedRoute = JSC.API.MatchedRoute; + pub const Dirent = JSC.Node.Dirent; + pub const NodeJSFS = JSC.Node.NodeJSFS; }; diff --git a/src/bun.js/bindings/header-gen.zig b/src/bun.js/bindings/header-gen.zig index 57f0189d9..fcc0f60fd 100644 --- a/src/bun.js/bindings/header-gen.zig +++ b/src/bun.js/bindings/header-gen.zig @@ -1,10 +1,10 @@ const std = @import("std"); const Dir = std.fs.Dir; -const FnMeta = std.builtin.TypeInfo.Fn; -const FnDecl = std.builtin.TypeInfo.Declaration.Data.FnDecl; -const StructMeta = std.builtin.TypeInfo.Struct; -const EnumMeta = std.builtin.TypeInfo.Enum; -const UnionMeta = std.builtin.TypeInfo.Union; +const FnMeta = std.builtin.Type.Fn; +const FnDecl = std.builtin.Type.Declaration.Data.FnDecl; +const StructMeta = std.builtin.Type.Struct; +const EnumMeta = std.builtin.Type.Enum; +const UnionMeta = std.builtin.Type.Union; const warn = std.debug.warn; const StaticExport = @import("./static_export.zig"); const typeBaseName = @import("../../meta.zig").typeBaseName; @@ -43,28 +43,28 @@ pub fn cTypeLabel(comptime Type: type) ?[]const u8 { f32 => "float", *anyopaque => "void*", *const anyopaque => "const void*", - [*]bool => "bool*", - [*]usize => "size_t*", - [*]isize => "int*", + [*c]bool, [*]bool => "bool*", + [*c]usize, [*]usize => "size_t*", + [*c]isize, [*]isize => "int*", [*]u8 => "unsigned char*", - [*]u16 => "uint16_t*", - [*]u32 => "uint32_t*", - [*]u64 => "uint64_t*", - [*]i8 => "int8_t*", - [*]i16 => "int16_t*", - [*]i32 => "int32_t*", - [*]i64 => "int64_t*", - [*]const bool => "const bool*", - [*]const usize => "const size_t*", - [*]const isize => "const int*", + [*c]u16, [*]u16 => "uint16_t*", + [*c]u32, [*]u32 => "uint32_t*", + [*c]u64, [*]u64 => "uint64_t*", + [*c]i8, [*]i8 => "int8_t*", + [*c]i16, [*]i16 => "int16_t*", + [*c]i32, [*]i32 => "int32_t*", + [*c]i64, [*]i64 => "int64_t*", + [*c]const bool, [*]const bool => "const bool*", + [*c]const usize, [*]const usize => "const size_t*", + [*c]const isize, [*]const isize => "const int*", [*c]const u8, [*]const u8 => "const unsigned char*", - [*]const u16 => "const uint16_t*", - [*]const u32 => "const uint32_t*", - [*]const u64 => "const uint64_t*", - [*]const i8 => "const int8_t*", - [*]const i16 => "const int16_t*", - [*]const i32 => "const int32_t*", - [*]const i64 => "const int64_t*", + [*c]const u16, [*]const u16 => "const uint16_t*", + [*c]const u32, [*]const u32 => "const uint32_t*", + [*c]const u64, [*]const u64 => "const uint64_t*", + [*c]const i8, [*]const i8 => "const int8_t*", + [*c]const i16, [*]const i16 => "const int16_t*", + [*c]const i32, [*]const i32 => "const int32_t*", + [*c]const i64, [*]const i64 => "const int64_t*", else => null, }; } @@ -145,24 +145,32 @@ pub const C_Generator = struct { } } - inline for (meta.args) |arg, i| { - const ArgType = comptime arg.arg_type.?; + comptime var nonnull = std.BoundedArray(u8, 32).init(0) catch unreachable; - switch (@typeInfo(ArgType)) { + inline for (meta.params) |arg, i| { + const ArgType = comptime arg.type.?; + + switch (comptime @typeInfo(ArgType)) { .Fn => { - self.gen_closure(comptime arg.arg_type.?, comptime std.fmt.comptimePrint(" ArgFn{d}", .{i})); + self.gen_closure(comptime arg.type.?, comptime std.fmt.comptimePrint(" ArgFn{d}", .{i})); + comptime nonnull.append(i) catch unreachable; }, - else => { - self.writeType(comptime arg.arg_type.?); + else => |info| { + if (comptime info == .Pointer and @typeInfo(info.Pointer.child) == .Fn) { + self.gen_closure(comptime info.Pointer.child, comptime std.fmt.comptimePrint(" ArgFn{d}", .{i})); + comptime nonnull.append(i) catch unreachable; + } else { + self.writeType(comptime arg.type.?); - switch (@typeInfo(ArgType)) { - .Enum => { - self.write(comptime std.fmt.comptimePrint(" {s}{d}", .{ typeBaseName(@typeName(ArgType)), i })); - }, + switch (@typeInfo(ArgType)) { + .Enum => { + self.write(comptime std.fmt.comptimePrint(" {s}{d}", .{ typeBaseName(@typeName(ArgType)), i })); + }, - else => { - self.write(comptime std.fmt.comptimePrint(" arg{d}", .{i})); - }, + else => { + self.write(comptime std.fmt.comptimePrint(" arg{d}", .{i})); + }, + } } }, } @@ -172,13 +180,23 @@ pub const C_Generator = struct { // } else { //TODO: Figure out how to get arg names; for now just do arg0..argN - if (i != meta.args.len - 1) + if (i != meta.params.len - 1) self.write(", "); } self.write(")"); + const nonnull_slice = comptime nonnull.slice(); + if (comptime nonnull_slice.len > 0) { + self.write(" __attribute__((nonnull ("); + inline for (comptime nonnull_slice) |i, j| { + self.write(comptime std.fmt.comptimePrint("{d}", .{i})); + if (j != nonnull_slice.len - 1) + self.write(", "); + } + self.write(")))"); + } defer self.write(";\n"); - // const ReturnTypeInfo: std.builtin.TypeInfo = comptime @typeInfo(func.return_type); + // const ReturnTypeInfo: std.builtin.Type = comptime @typeInfo(func.return_type); // switch (comptime ReturnTypeInfo) { // .Pointer => |Pointer| { // self.write(" __attribute__((returns_nonnull))"); @@ -193,15 +211,15 @@ pub const C_Generator = struct { comptime Function: type, comptime name: []const u8, ) void { - const func: std.builtin.TypeInfo.Fn = @typeInfo(Function).Fn; + const func: std.builtin.Type.Fn = @typeInfo(Function).Fn; self.writeType(func.return_type orelse void); - self.write(" (*" ++ name ++ ")("); - inline for (func.args) |arg, i| { - self.writeType(arg.arg_type.?); + self.write("(*" ++ name ++ ")("); + inline for (func.params) |arg, i| { + self.writeType(arg.type.?); // if (comptime func.arg_names.len > 0 and func.arg_names.len > i) { // self.write(comptime arg_names[i]); // } else { - const ArgType = arg.arg_type.?; + const ArgType = arg.type.?; if (@typeInfo(ArgType) == .Enum) { self.write(comptime std.fmt.comptimePrint(" {s}{d}", .{ typeBaseName(@typeName(ArgType)), i })); } else { @@ -210,12 +228,12 @@ pub const C_Generator = struct { // } //TODO: Figure out how to get arg names; for now just do arg0..argN - if (i != func.args.len - 1) + if (i != func.params.len - 1) self.write(", "); } self.write(")"); - // const ReturnTypeInfo: std.builtin.TypeInfo = comptime @typeInfo(func.return_type); + // const ReturnTypeInfo: std.builtin.Type = comptime @typeInfo(func.return_type); // switch (comptime ReturnTypeInfo) { // .Pointer => |Pointer| { // self.write(" __attribute__((returns_nonnull))"); @@ -241,7 +259,7 @@ pub const C_Generator = struct { inline for (meta.fields) |field| { self.write(" "); - const info = @typeInfo(field.field_type); + const info = @typeInfo(field.type); if (info == .Array) { const PrintType = comptime brk: { @@ -257,12 +275,12 @@ pub const C_Generator = struct { } else { const PrintType = comptime brk: { for (static_types) |static_type| { - if (static_type.Type == field.field_type) { + if (static_type.Type == field.type) { break :brk static_type.Type; } } - break :brk field.field_type; + break :brk field.type; }; self.writeType(PrintType); } @@ -554,7 +572,7 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp _: anytype, gen: *C_Generator, comptime ParentType: type, - comptime _: std.builtin.TypeInfo.Declaration, + comptime _: std.builtin.Type.Declaration, comptime name: []const u8, comptime prefix: []const u8, ) void { @@ -722,7 +740,7 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp @setEvalBranchQuota(99999); const Type = @field(BaseType, _decls.name); if (@TypeOf(Type) == type) { - const TypeTypeInfo: std.builtin.TypeInfo = @typeInfo(@field(BaseType, _decls.name)); + const TypeTypeInfo: std.builtin.Type = @typeInfo(@field(BaseType, _decls.name)); const is_container_type = switch (TypeTypeInfo) { .Opaque, .Struct, .Enum => true, else => false, diff --git a/src/bun.js/bindings/headers-cpp.h b/src/bun.js/bindings/headers-cpp.h index 0e43e86de..1c2fe28e5 100644 --- a/src/bun.js/bindings/headers-cpp.h +++ b/src/bun.js/bindings/headers-cpp.h @@ -1,4 +1,4 @@ -//-- AUTOGENERATED FILE -- 1671518642 +//-- AUTOGENERATED FILE -- 1672085644 // clang-format off #pragma once diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h index 31f5dc22a..6bb3a6fb5 100644 --- a/src/bun.js/bindings/headers.h +++ b/src/bun.js/bindings/headers.h @@ -1,5 +1,5 @@ // clang-format off -//-- AUTOGENERATED FILE -- 1671518642 +//-- AUTOGENERATED FILE -- 1672085644 #pragma once #include <stddef.h> @@ -128,18 +128,18 @@ typedef void* JSClassRef; #pragma mark - JSC::JSObject -CPP_DECL JSC__JSValue JSC__JSObject__create(JSC__JSGlobalObject* arg0, size_t arg1, void* arg2, void (* ArgFn3)(void* arg0, JSC__JSObject* arg1, JSC__JSGlobalObject* arg2)); +CPP_DECL JSC__JSValue JSC__JSObject__create(JSC__JSGlobalObject* arg0, size_t arg1, void* arg2, void(* ArgFn3)(void* arg0, JSC__JSObject* arg1, JSC__JSGlobalObject* arg2)) __attribute__((nonnull (3))); CPP_DECL size_t JSC__JSObject__getArrayLength(JSC__JSObject* arg0); CPP_DECL JSC__JSValue JSC__JSObject__getDirect(JSC__JSObject* arg0, JSC__JSGlobalObject* arg1, const ZigString* arg2); CPP_DECL JSC__JSValue JSC__JSObject__getIndex(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, uint32_t arg2); CPP_DECL void JSC__JSObject__putRecord(JSC__JSObject* arg0, JSC__JSGlobalObject* arg1, ZigString* arg2, ZigString* arg3, size_t arg4); -CPP_DECL JSC__JSValue ZigString__external(const ZigString* arg0, JSC__JSGlobalObject* arg1, void* arg2, void (* ArgFn3)(void* arg0, void* arg1, size_t arg2)); +CPP_DECL JSC__JSValue ZigString__external(const ZigString* arg0, JSC__JSGlobalObject* arg1, void* arg2, void(* ArgFn3)(void* arg0, void* arg1, size_t arg2)) __attribute__((nonnull (3))); CPP_DECL JSC__JSValue ZigString__to16BitValue(const ZigString* arg0, JSC__JSGlobalObject* arg1); CPP_DECL JSC__JSValue ZigString__toAtomicValue(const ZigString* arg0, JSC__JSGlobalObject* arg1); CPP_DECL JSC__JSValue ZigString__toErrorInstance(const ZigString* arg0, JSC__JSGlobalObject* arg1); CPP_DECL JSC__JSValue ZigString__toExternalU16(const uint16_t* arg0, size_t arg1, JSC__JSGlobalObject* arg2); CPP_DECL JSC__JSValue ZigString__toExternalValue(const ZigString* arg0, JSC__JSGlobalObject* arg1); -CPP_DECL JSC__JSValue ZigString__toExternalValueWithCallback(const ZigString* arg0, JSC__JSGlobalObject* arg1, void (* ArgFn2)(void* arg0, void* arg1, size_t arg2)); +CPP_DECL JSC__JSValue ZigString__toExternalValueWithCallback(const ZigString* arg0, JSC__JSGlobalObject* arg1, void(* ArgFn2)(void* arg0, void* arg1, size_t arg2)) __attribute__((nonnull (2))); CPP_DECL JSC__JSValue ZigString__toValue(const ZigString* arg0, JSC__JSGlobalObject* arg1); CPP_DECL JSC__JSValue ZigString__toValueGC(const ZigString* arg0, JSC__JSGlobalObject* arg1); CPP_DECL WebCore__DOMURL* WebCore__DOMURL__cast_(JSC__JSValue JSValue0, JSC__VM* arg1); @@ -241,7 +241,7 @@ CPP_DECL JSC__VM* JSC__JSGlobalObject__vm(JSC__JSGlobalObject* arg0); #pragma mark - JSC::JSValue -CPP_DECL void JSC__JSValue___then(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2, JSC__JSValue (* ArgFn3)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1), JSC__JSValue (* ArgFn4)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1)); +CPP_DECL void JSC__JSValue___then(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2, JSC__JSValue(* ArgFn3)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1), JSC__JSValue(* ArgFn4)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1)) __attribute__((nonnull (3, 4))); CPP_DECL bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, Bun__ArrayBuffer* arg2); CPP_DECL unsigned char JSC__JSValue__asBigIntCompare(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2); CPP_DECL JSC__JSCell* JSC__JSValue__asCell(JSC__JSValue JSValue0); @@ -264,8 +264,8 @@ CPP_DECL bool JSC__JSValue__deepEquals(JSC__JSValue JSValue0, JSC__JSValue JSVal CPP_DECL bool JSC__JSValue__eqlCell(JSC__JSValue JSValue0, JSC__JSCell* arg1); CPP_DECL bool JSC__JSValue__eqlValue(JSC__JSValue JSValue0, JSC__JSValue JSValue1); CPP_DECL JSC__JSValue JSC__JSValue__fastGet_(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, unsigned char arg2); -CPP_DECL void JSC__JSValue__forEach(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, void* arg2, void (* ArgFn3)(JSC__VM* arg0, JSC__JSGlobalObject* arg1, void* arg2, JSC__JSValue JSValue3)); -CPP_DECL void JSC__JSValue__forEachProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, void* arg2, void (* ArgFn3)(JSC__JSGlobalObject* arg0, void* arg1, ZigString* arg2, JSC__JSValue JSValue3, bool arg4)); +CPP_DECL void JSC__JSValue__forEach(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, void* arg2, void(* ArgFn3)(JSC__VM* arg0, JSC__JSGlobalObject* arg1, void* arg2, JSC__JSValue JSValue3)) __attribute__((nonnull (3))); +CPP_DECL void JSC__JSValue__forEachProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, void* arg2, void(* ArgFn3)(JSC__JSGlobalObject* arg0, void* arg1, ZigString* arg2, JSC__JSValue JSValue3, bool arg4)) __attribute__((nonnull (3))); CPP_DECL JSC__JSValue JSC__JSValue__fromEntries(JSC__JSGlobalObject* arg0, ZigString* arg1, ZigString* arg2, size_t arg3, bool arg4); CPP_DECL JSC__JSValue JSC__JSValue__fromInt64NoTruncate(JSC__JSGlobalObject* arg0, int64_t arg1); CPP_DECL JSC__JSValue JSC__JSValue__fromUInt64NoTruncate(JSC__JSGlobalObject* arg0, uint64_t arg1); @@ -344,7 +344,7 @@ CPP_DECL size_t JSC__VM__blockBytesAllocated(JSC__VM* arg0); CPP_DECL void JSC__VM__clearExecutionTimeLimit(JSC__VM* arg0); CPP_DECL void JSC__VM__collectAsync(JSC__VM* arg0); CPP_DECL JSC__VM* JSC__VM__create(unsigned char HeapType0); -CPP_DECL void JSC__VM__deferGC(JSC__VM* arg0, void* arg1, void (* ArgFn2)(void* arg0)); +CPP_DECL void JSC__VM__deferGC(JSC__VM* arg0, void* arg1, void(* ArgFn2)(void* arg0)) __attribute__((nonnull (2))); CPP_DECL void JSC__VM__deinit(JSC__VM* arg0, JSC__JSGlobalObject* arg1); CPP_DECL void JSC__VM__deleteAllCode(JSC__VM* arg0, JSC__JSGlobalObject* arg1); CPP_DECL void JSC__VM__doWork(JSC__VM* arg0); @@ -352,7 +352,7 @@ CPP_DECL void JSC__VM__drainMicrotasks(JSC__VM* arg0); CPP_DECL bool JSC__VM__executionForbidden(JSC__VM* arg0); CPP_DECL size_t JSC__VM__externalMemorySize(JSC__VM* arg0); CPP_DECL size_t JSC__VM__heapSize(JSC__VM* arg0); -CPP_DECL void JSC__VM__holdAPILock(JSC__VM* arg0, void* arg1, void (* ArgFn2)(void* arg0)); +CPP_DECL void JSC__VM__holdAPILock(JSC__VM* arg0, void* arg1, void(* ArgFn2)(void* arg0)) __attribute__((nonnull (2))); CPP_DECL bool JSC__VM__isEntered(JSC__VM* arg0); CPP_DECL bool JSC__VM__isJITEnabled(); CPP_DECL void JSC__VM__releaseWeakRefs(JSC__VM* arg0); @@ -362,7 +362,7 @@ CPP_DECL void JSC__VM__setExecutionTimeLimit(JSC__VM* arg0, double arg1); CPP_DECL void JSC__VM__shrinkFootprint(JSC__VM* arg0); CPP_DECL void JSC__VM__throwError(JSC__VM* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2); CPP_DECL void JSC__VM__throwError(JSC__VM* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2); -CPP_DECL void JSC__VM__whenIdle(JSC__VM* arg0, void (* ArgFn1)()); +CPP_DECL void JSC__VM__whenIdle(JSC__VM* arg0, void(* ArgFn1)()) __attribute__((nonnull (1))); #pragma mark - JSC::ThrowScope diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig index 7e5dca6e2..61f6c6612 100644 --- a/src/bun.js/bindings/headers.zig +++ b/src/bun.js/bindings/headers.zig @@ -80,34 +80,34 @@ pub const JSC__JSCell = bJSC__JSCell; pub const JSC__JSInternalPromise = bJSC__JSInternalPromise; pub const JSC__Exception = bJSC__Exception; pub const JSC__JSString = bJSC__JSString; -pub extern fn JSC__JSObject__create(arg0: ?*JSC__JSGlobalObject, arg1: usize, arg2: ?*anyopaque, ArgFn3: ?fn (?*anyopaque, [*c]JSC__JSObject, ?*JSC__JSGlobalObject) callconv(.C) void) JSC__JSValue; -pub extern fn JSC__JSObject__getArrayLength(arg0: [*c]JSC__JSObject) usize; -pub extern fn JSC__JSObject__getDirect(arg0: [*c]JSC__JSObject, arg1: ?*JSC__JSGlobalObject, arg2: [*c]const ZigString) JSC__JSValue; -pub extern fn JSC__JSObject__getIndex(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: u32) JSC__JSValue; -pub extern fn JSC__JSObject__putRecord(arg0: [*c]JSC__JSObject, arg1: ?*JSC__JSGlobalObject, arg2: [*c]ZigString, arg3: [*c]ZigString, arg4: usize) void; -pub extern fn ZigString__external(arg0: [*c]const ZigString, arg1: ?*JSC__JSGlobalObject, arg2: ?*anyopaque, ArgFn3: ?fn (?*anyopaque, ?*anyopaque, usize) callconv(.C) void) JSC__JSValue; -pub extern fn ZigString__to16BitValue(arg0: [*c]const ZigString, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn ZigString__toAtomicValue(arg0: [*c]const ZigString, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn ZigString__toErrorInstance(arg0: [*c]const ZigString, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn ZigString__toExternalU16(arg0: [*c]const u16, arg1: usize, arg2: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn ZigString__toExternalValue(arg0: [*c]const ZigString, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn ZigString__toExternalValueWithCallback(arg0: [*c]const ZigString, arg1: ?*JSC__JSGlobalObject, ArgFn2: ?fn (?*anyopaque, ?*anyopaque, usize) callconv(.C) void) JSC__JSValue; -pub extern fn ZigString__toValue(arg0: [*c]const ZigString, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn ZigString__toValueGC(arg0: [*c]const ZigString, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn WebCore__DOMURL__cast_(JSValue0: JSC__JSValue, arg1: [*c]JSC__VM) ?*bindings.DOMURL; +pub extern fn JSC__JSObject__create(arg0: *bindings.JSGlobalObject, arg1: usize, arg2: ?*anyopaque, ArgFn3: ?*const fn (?*anyopaque, [*c]bindings.JSObject, *bindings.JSGlobalObject) callconv(.C) void) JSC__JSValue; +pub extern fn JSC__JSObject__getArrayLength(arg0: [*c]bindings.JSObject) usize; +pub extern fn JSC__JSObject__getDirect(arg0: [*c]bindings.JSObject, arg1: *bindings.JSGlobalObject, arg2: [*c]const ZigString) JSC__JSValue; +pub extern fn JSC__JSObject__getIndex(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: u32) JSC__JSValue; +pub extern fn JSC__JSObject__putRecord(arg0: [*c]bindings.JSObject, arg1: *bindings.JSGlobalObject, arg2: [*c]ZigString, arg3: [*c]ZigString, arg4: usize) void; +pub extern fn ZigString__external(arg0: [*c]const ZigString, arg1: *bindings.JSGlobalObject, arg2: ?*anyopaque, ArgFn3: ?*const fn (?*anyopaque, ?*anyopaque, usize) callconv(.C) void) JSC__JSValue; +pub extern fn ZigString__to16BitValue(arg0: [*c]const ZigString, arg1: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn ZigString__toAtomicValue(arg0: [*c]const ZigString, arg1: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn ZigString__toErrorInstance(arg0: [*c]const ZigString, arg1: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn ZigString__toExternalU16(arg0: [*c]const u16, arg1: usize, arg2: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn ZigString__toExternalValue(arg0: [*c]const ZigString, arg1: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn ZigString__toExternalValueWithCallback(arg0: [*c]const ZigString, arg1: *bindings.JSGlobalObject, ArgFn2: ?*const fn (?*anyopaque, ?*anyopaque, usize) callconv(.C) void) JSC__JSValue; +pub extern fn ZigString__toValue(arg0: [*c]const ZigString, arg1: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn ZigString__toValueGC(arg0: [*c]const ZigString, arg1: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn WebCore__DOMURL__cast_(JSValue0: JSC__JSValue, arg1: *bindings.VM) ?*bindings.DOMURL; pub extern fn WebCore__DOMURL__href_(arg0: ?*bindings.DOMURL, arg1: [*c]ZigString) void; pub extern fn WebCore__DOMURL__pathname_(arg0: ?*bindings.DOMURL, arg1: [*c]ZigString) void; pub extern fn WebCore__FetchHeaders__append(arg0: ?*bindings.FetchHeaders, arg1: [*c]const ZigString, arg2: [*c]const ZigString) void; -pub extern fn WebCore__FetchHeaders__cast_(JSValue0: JSC__JSValue, arg1: [*c]JSC__VM) ?*bindings.FetchHeaders; -pub extern fn WebCore__FetchHeaders__clone(arg0: ?*bindings.FetchHeaders, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; +pub extern fn WebCore__FetchHeaders__cast_(JSValue0: JSC__JSValue, arg1: *bindings.VM) ?*bindings.FetchHeaders; +pub extern fn WebCore__FetchHeaders__clone(arg0: ?*bindings.FetchHeaders, arg1: *bindings.JSGlobalObject) JSC__JSValue; pub extern fn WebCore__FetchHeaders__cloneThis(arg0: ?*bindings.FetchHeaders) ?*bindings.FetchHeaders; pub extern fn WebCore__FetchHeaders__copyTo(arg0: ?*bindings.FetchHeaders, arg1: [*c]StringPointer, arg2: [*c]StringPointer, arg3: [*c]u8) void; pub extern fn WebCore__FetchHeaders__count(arg0: ?*bindings.FetchHeaders, arg1: [*c]u32, arg2: [*c]u32) void; pub extern fn WebCore__FetchHeaders__createEmpty(...) ?*bindings.FetchHeaders; -pub extern fn WebCore__FetchHeaders__createFromJS(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) ?*bindings.FetchHeaders; +pub extern fn WebCore__FetchHeaders__createFromJS(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*bindings.FetchHeaders; pub extern fn WebCore__FetchHeaders__createFromPicoHeaders_(arg0: ?*const anyopaque) ?*bindings.FetchHeaders; -pub extern fn WebCore__FetchHeaders__createFromUWS(arg0: ?*JSC__JSGlobalObject, arg1: ?*anyopaque) ?*bindings.FetchHeaders; -pub extern fn WebCore__FetchHeaders__createValue(arg0: ?*JSC__JSGlobalObject, arg1: [*c]StringPointer, arg2: [*c]StringPointer, arg3: [*c]const ZigString, arg4: u32) JSC__JSValue; +pub extern fn WebCore__FetchHeaders__createFromUWS(arg0: *bindings.JSGlobalObject, arg1: ?*anyopaque) ?*bindings.FetchHeaders; +pub extern fn WebCore__FetchHeaders__createValue(arg0: *bindings.JSGlobalObject, arg1: [*c]StringPointer, arg2: [*c]StringPointer, arg3: [*c]const ZigString, arg4: u32) JSC__JSValue; pub extern fn WebCore__FetchHeaders__deref(arg0: ?*bindings.FetchHeaders) void; pub extern fn WebCore__FetchHeaders__fastGet_(arg0: ?*bindings.FetchHeaders, arg1: u8, arg2: [*c]ZigString) void; pub extern fn WebCore__FetchHeaders__fastHas_(arg0: ?*bindings.FetchHeaders, arg1: u8) bool; @@ -116,114 +116,114 @@ pub extern fn WebCore__FetchHeaders__get_(arg0: ?*bindings.FetchHeaders, arg1: [ pub extern fn WebCore__FetchHeaders__has(arg0: ?*bindings.FetchHeaders, arg1: [*c]const ZigString) bool; pub extern fn WebCore__FetchHeaders__put_(arg0: ?*bindings.FetchHeaders, arg1: [*c]const ZigString, arg2: [*c]const ZigString) void; pub extern fn WebCore__FetchHeaders__remove(arg0: ?*bindings.FetchHeaders, arg1: [*c]const ZigString) void; -pub extern fn WebCore__FetchHeaders__toJS(arg0: ?*bindings.FetchHeaders, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; +pub extern fn WebCore__FetchHeaders__toJS(arg0: ?*bindings.FetchHeaders, arg1: *bindings.JSGlobalObject) JSC__JSValue; pub extern fn WebCore__FetchHeaders__toUWSResponse(arg0: ?*bindings.FetchHeaders, arg1: bool, arg2: ?*anyopaque) void; -pub extern fn SystemError__toErrorInstance(arg0: [*c]const SystemError, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn JSC__JSCell__getObject(arg0: [*c]JSC__JSCell) [*c]JSC__JSObject; -pub extern fn JSC__JSCell__getType(arg0: [*c]JSC__JSCell) u8; -pub extern fn JSC__JSString__eql(arg0: [*c]const JSC__JSString, arg1: ?*JSC__JSGlobalObject, arg2: [*c]JSC__JSString) bool; +pub extern fn SystemError__toErrorInstance(arg0: [*c]const SystemError, arg1: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn JSC__JSCell__getObject(arg0: [*c]bindings.JSCell) [*c]bindings.JSObject; +pub extern fn JSC__JSCell__getType(arg0: [*c]bindings.JSCell) u8; +pub extern fn JSC__JSString__eql(arg0: [*c]const JSC__JSString, arg1: *bindings.JSGlobalObject, arg2: [*c]bindings.JSString) bool; pub extern fn JSC__JSString__is8Bit(arg0: [*c]const JSC__JSString) bool; -pub extern fn JSC__JSString__iterator(arg0: [*c]JSC__JSString, arg1: ?*JSC__JSGlobalObject, arg2: ?*anyopaque) void; +pub extern fn JSC__JSString__iterator(arg0: [*c]bindings.JSString, arg1: *bindings.JSGlobalObject, arg2: ?*anyopaque) void; pub extern fn JSC__JSString__length(arg0: [*c]const JSC__JSString) usize; -pub extern fn JSC__JSString__toObject(arg0: [*c]JSC__JSString, arg1: ?*JSC__JSGlobalObject) [*c]JSC__JSObject; -pub extern fn JSC__JSString__toZigString(arg0: [*c]JSC__JSString, arg1: ?*JSC__JSGlobalObject, arg2: [*c]ZigString) void; -pub extern fn JSC__JSModuleLoader__evaluate(arg0: ?*JSC__JSGlobalObject, arg1: [*c]const u8, arg2: usize, arg3: [*c]const u8, arg4: usize, arg5: [*c]const u8, arg6: usize, JSValue7: JSC__JSValue, arg8: [*c]JSC__JSValue) JSC__JSValue; -pub extern fn JSC__JSModuleLoader__loadAndEvaluateModule(arg0: ?*JSC__JSGlobalObject, arg1: [*c]const ZigString) [*c]JSC__JSInternalPromise; -pub extern fn JSC__JSPromise__asValue(arg0: [*c]JSC__JSPromise, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn JSC__JSPromise__create(arg0: ?*JSC__JSGlobalObject) [*c]JSC__JSPromise; -pub extern fn JSC__JSPromise__isHandled(arg0: [*c]const JSC__JSPromise, arg1: [*c]JSC__VM) bool; -pub extern fn JSC__JSPromise__reject(arg0: [*c]JSC__JSPromise, arg1: ?*JSC__JSGlobalObject, JSValue2: JSC__JSValue) void; -pub extern fn JSC__JSPromise__rejectAsHandled(arg0: [*c]JSC__JSPromise, arg1: ?*JSC__JSGlobalObject, JSValue2: JSC__JSValue) void; -pub extern fn JSC__JSPromise__rejectAsHandledException(arg0: [*c]JSC__JSPromise, arg1: ?*JSC__JSGlobalObject, arg2: [*c]JSC__Exception) void; -pub extern fn JSC__JSPromise__rejectedPromise(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) [*c]JSC__JSPromise; -pub extern fn JSC__JSPromise__rejectedPromiseValue(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) JSC__JSValue; -pub extern fn JSC__JSPromise__rejectWithCaughtException(arg0: [*c]JSC__JSPromise, arg1: ?*JSC__JSGlobalObject, arg2: bJSC__ThrowScope) void; -pub extern fn JSC__JSPromise__resolve(arg0: [*c]JSC__JSPromise, arg1: ?*JSC__JSGlobalObject, JSValue2: JSC__JSValue) void; -pub extern fn JSC__JSPromise__resolvedPromise(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) [*c]JSC__JSPromise; -pub extern fn JSC__JSPromise__resolvedPromiseValue(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) JSC__JSValue; -pub extern fn JSC__JSPromise__result(arg0: [*c]JSC__JSPromise, arg1: [*c]JSC__VM) JSC__JSValue; -pub extern fn JSC__JSPromise__status(arg0: [*c]const JSC__JSPromise, arg1: [*c]JSC__VM) u32; -pub extern fn JSC__JSInternalPromise__create(arg0: ?*JSC__JSGlobalObject) [*c]JSC__JSInternalPromise; -pub extern fn JSC__JSInternalPromise__isHandled(arg0: [*c]const JSC__JSInternalPromise, arg1: [*c]JSC__VM) bool; -pub extern fn JSC__JSInternalPromise__reject(arg0: [*c]JSC__JSInternalPromise, arg1: ?*JSC__JSGlobalObject, JSValue2: JSC__JSValue) void; -pub extern fn JSC__JSInternalPromise__rejectAsHandled(arg0: [*c]JSC__JSInternalPromise, arg1: ?*JSC__JSGlobalObject, JSValue2: JSC__JSValue) void; -pub extern fn JSC__JSInternalPromise__rejectAsHandledException(arg0: [*c]JSC__JSInternalPromise, arg1: ?*JSC__JSGlobalObject, arg2: [*c]JSC__Exception) void; -pub extern fn JSC__JSInternalPromise__rejectedPromise(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) [*c]JSC__JSInternalPromise; -pub extern fn JSC__JSInternalPromise__rejectWithCaughtException(arg0: [*c]JSC__JSInternalPromise, arg1: ?*JSC__JSGlobalObject, arg2: bJSC__ThrowScope) void; -pub extern fn JSC__JSInternalPromise__resolve(arg0: [*c]JSC__JSInternalPromise, arg1: ?*JSC__JSGlobalObject, JSValue2: JSC__JSValue) void; -pub extern fn JSC__JSInternalPromise__resolvedPromise(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) [*c]JSC__JSInternalPromise; -pub extern fn JSC__JSInternalPromise__result(arg0: [*c]const JSC__JSInternalPromise, arg1: [*c]JSC__VM) JSC__JSValue; -pub extern fn JSC__JSInternalPromise__status(arg0: [*c]const JSC__JSInternalPromise, arg1: [*c]JSC__VM) u32; +pub extern fn JSC__JSString__toObject(arg0: [*c]bindings.JSString, arg1: *bindings.JSGlobalObject) [*c]bindings.JSObject; +pub extern fn JSC__JSString__toZigString(arg0: [*c]bindings.JSString, arg1: *bindings.JSGlobalObject, arg2: [*c]ZigString) void; +pub extern fn JSC__JSModuleLoader__evaluate(arg0: *bindings.JSGlobalObject, arg1: [*c]const u8, arg2: usize, arg3: [*c]const u8, arg4: usize, arg5: [*c]const u8, arg6: usize, JSValue7: JSC__JSValue, arg8: [*c]bindings.JSValue) JSC__JSValue; +pub extern fn JSC__JSModuleLoader__loadAndEvaluateModule(arg0: *bindings.JSGlobalObject, arg1: [*c]const ZigString) [*c]bindings.JSInternalPromise; +pub extern fn JSC__JSPromise__asValue(arg0: ?*bindings.JSPromise, arg1: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn JSC__JSPromise__create(arg0: *bindings.JSGlobalObject) ?*bindings.JSPromise; +pub extern fn JSC__JSPromise__isHandled(arg0: [*c]const JSC__JSPromise, arg1: *bindings.VM) bool; +pub extern fn JSC__JSPromise__reject(arg0: ?*bindings.JSPromise, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) void; +pub extern fn JSC__JSPromise__rejectAsHandled(arg0: ?*bindings.JSPromise, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) void; +pub extern fn JSC__JSPromise__rejectAsHandledException(arg0: ?*bindings.JSPromise, arg1: *bindings.JSGlobalObject, arg2: [*c]bindings.Exception) void; +pub extern fn JSC__JSPromise__rejectedPromise(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*bindings.JSPromise; +pub extern fn JSC__JSPromise__rejectedPromiseValue(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) JSC__JSValue; +pub extern fn JSC__JSPromise__rejectWithCaughtException(arg0: ?*bindings.JSPromise, arg1: *bindings.JSGlobalObject, arg2: bJSC__ThrowScope) void; +pub extern fn JSC__JSPromise__resolve(arg0: ?*bindings.JSPromise, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) void; +pub extern fn JSC__JSPromise__resolvedPromise(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*bindings.JSPromise; +pub extern fn JSC__JSPromise__resolvedPromiseValue(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) JSC__JSValue; +pub extern fn JSC__JSPromise__result(arg0: ?*bindings.JSPromise, arg1: *bindings.VM) JSC__JSValue; +pub extern fn JSC__JSPromise__status(arg0: [*c]const JSC__JSPromise, arg1: *bindings.VM) u32; +pub extern fn JSC__JSInternalPromise__create(arg0: *bindings.JSGlobalObject) [*c]bindings.JSInternalPromise; +pub extern fn JSC__JSInternalPromise__isHandled(arg0: [*c]const JSC__JSInternalPromise, arg1: *bindings.VM) bool; +pub extern fn JSC__JSInternalPromise__reject(arg0: [*c]bindings.JSInternalPromise, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) void; +pub extern fn JSC__JSInternalPromise__rejectAsHandled(arg0: [*c]bindings.JSInternalPromise, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) void; +pub extern fn JSC__JSInternalPromise__rejectAsHandledException(arg0: [*c]bindings.JSInternalPromise, arg1: *bindings.JSGlobalObject, arg2: [*c]bindings.Exception) void; +pub extern fn JSC__JSInternalPromise__rejectedPromise(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) [*c]bindings.JSInternalPromise; +pub extern fn JSC__JSInternalPromise__rejectWithCaughtException(arg0: [*c]bindings.JSInternalPromise, arg1: *bindings.JSGlobalObject, arg2: bJSC__ThrowScope) void; +pub extern fn JSC__JSInternalPromise__resolve(arg0: [*c]bindings.JSInternalPromise, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) void; +pub extern fn JSC__JSInternalPromise__resolvedPromise(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) [*c]bindings.JSInternalPromise; +pub extern fn JSC__JSInternalPromise__result(arg0: [*c]const JSC__JSInternalPromise, arg1: *bindings.VM) JSC__JSValue; +pub extern fn JSC__JSInternalPromise__status(arg0: [*c]const JSC__JSInternalPromise, arg1: *bindings.VM) u32; pub extern fn JSC__JSFunction__optimizeSoon(JSValue0: JSC__JSValue) void; -pub extern fn JSC__JSGlobalObject__bunVM(arg0: ?*JSC__JSGlobalObject) ?*bindings.VirtualMachine; -pub extern fn JSC__JSGlobalObject__createAggregateError(arg0: ?*JSC__JSGlobalObject, arg1: [*c]*anyopaque, arg2: u16, arg3: [*c]const ZigString) JSC__JSValue; -pub extern fn JSC__JSGlobalObject__createSyntheticModule_(arg0: ?*JSC__JSGlobalObject, arg1: [*c]ZigString, arg2: usize, arg3: [*c]JSC__JSValue, arg4: usize) void; -pub extern fn JSC__JSGlobalObject__deleteModuleRegistryEntry(arg0: ?*JSC__JSGlobalObject, arg1: [*c]ZigString) void; -pub extern fn JSC__JSGlobalObject__generateHeapSnapshot(arg0: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn JSC__JSGlobalObject__getCachedObject(arg0: ?*JSC__JSGlobalObject, arg1: [*c]const ZigString) JSC__JSValue; -pub extern fn JSC__JSGlobalObject__handleRejectedPromises(arg0: ?*JSC__JSGlobalObject) void; -pub extern fn JSC__JSGlobalObject__putCachedObject(arg0: ?*JSC__JSGlobalObject, arg1: [*c]const ZigString, JSValue2: JSC__JSValue) JSC__JSValue; -pub extern fn JSC__JSGlobalObject__reload(arg0: ?*JSC__JSGlobalObject) void; -pub extern fn JSC__JSGlobalObject__startRemoteInspector(arg0: ?*JSC__JSGlobalObject, arg1: [*c]u8, arg2: u16) bool; -pub extern fn JSC__JSGlobalObject__vm(arg0: ?*JSC__JSGlobalObject) [*c]JSC__VM; -pub extern fn JSC__JSValue___then(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, JSValue2: JSC__JSValue, ArgFn3: ?fn (?*JSC__JSGlobalObject, ?*bindings.CallFrame) callconv(.C) JSC__JSValue, ArgFn4: ?fn (?*JSC__JSGlobalObject, ?*bindings.CallFrame) callconv(.C) JSC__JSValue) void; -pub extern fn JSC__JSValue__asArrayBuffer_(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: ?*Bun__ArrayBuffer) bool; -pub extern fn JSC__JSValue__asBigIntCompare(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, JSValue2: JSC__JSValue) u8; -pub extern fn JSC__JSValue__asCell(JSValue0: JSC__JSValue) [*c]JSC__JSCell; -pub extern fn JSC__JSValue__asInternalPromise(JSValue0: JSC__JSValue) [*c]JSC__JSInternalPromise; +pub extern fn JSC__JSGlobalObject__bunVM(arg0: *bindings.JSGlobalObject) ?*bindings.VirtualMachine; +pub extern fn JSC__JSGlobalObject__createAggregateError(arg0: *bindings.JSGlobalObject, arg1: [*c]*anyopaque, arg2: u16, arg3: [*c]const ZigString) JSC__JSValue; +pub extern fn JSC__JSGlobalObject__createSyntheticModule_(arg0: *bindings.JSGlobalObject, arg1: [*c]ZigString, arg2: usize, arg3: [*c]bindings.JSValue, arg4: usize) void; +pub extern fn JSC__JSGlobalObject__deleteModuleRegistryEntry(arg0: *bindings.JSGlobalObject, arg1: [*c]ZigString) void; +pub extern fn JSC__JSGlobalObject__generateHeapSnapshot(arg0: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn JSC__JSGlobalObject__getCachedObject(arg0: *bindings.JSGlobalObject, arg1: [*c]const ZigString) JSC__JSValue; +pub extern fn JSC__JSGlobalObject__handleRejectedPromises(arg0: *bindings.JSGlobalObject) void; +pub extern fn JSC__JSGlobalObject__putCachedObject(arg0: *bindings.JSGlobalObject, arg1: [*c]const ZigString, JSValue2: JSC__JSValue) JSC__JSValue; +pub extern fn JSC__JSGlobalObject__reload(arg0: *bindings.JSGlobalObject) void; +pub extern fn JSC__JSGlobalObject__startRemoteInspector(arg0: *bindings.JSGlobalObject, arg1: [*c]u8, arg2: u16) bool; +pub extern fn JSC__JSGlobalObject__vm(arg0: *bindings.JSGlobalObject) *bindings.VM; +pub extern fn JSC__JSValue___then(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue, ArgFn3: ?*const fn (*bindings.JSGlobalObject, *bindings.CallFrame) callconv(.C) JSC__JSValue, ArgFn4: ?*const fn (*bindings.JSGlobalObject, *bindings.CallFrame) callconv(.C) JSC__JSValue) void; +pub extern fn JSC__JSValue__asArrayBuffer_(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: ?*Bun__ArrayBuffer) bool; +pub extern fn JSC__JSValue__asBigIntCompare(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) u8; +pub extern fn JSC__JSValue__asCell(JSValue0: JSC__JSValue) [*c]bindings.JSCell; +pub extern fn JSC__JSValue__asInternalPromise(JSValue0: JSC__JSValue) [*c]bindings.JSInternalPromise; pub extern fn JSC__JSValue__asNumber(JSValue0: JSC__JSValue) f64; pub extern fn JSC__JSValue__asObject(JSValue0: JSC__JSValue) bJSC__JSObject; -pub extern fn JSC__JSValue__asPromise(JSValue0: JSC__JSValue) [*c]JSC__JSPromise; -pub extern fn JSC__JSValue__asString(JSValue0: JSC__JSValue) [*c]JSC__JSString; -pub extern fn JSC__JSValue__coerceToInt32(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) i32; -pub extern fn JSC__JSValue__createEmptyObject(arg0: ?*JSC__JSGlobalObject, arg1: usize) JSC__JSValue; -pub extern fn JSC__JSValue__createInternalPromise(arg0: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn JSC__JSValue__createObject2(arg0: ?*JSC__JSGlobalObject, arg1: [*c]const ZigString, arg2: [*c]const ZigString, JSValue3: JSC__JSValue, JSValue4: JSC__JSValue) JSC__JSValue; -pub extern fn JSC__JSValue__createRangeError(arg0: [*c]const ZigString, arg1: [*c]const ZigString, arg2: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn JSC__JSValue__createRopeString(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, arg2: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn JSC__JSValue__createStringArray(arg0: ?*JSC__JSGlobalObject, arg1: [*c]ZigString, arg2: usize, arg3: bool) JSC__JSValue; -pub extern fn JSC__JSValue__createTypeError(arg0: [*c]const ZigString, arg1: [*c]const ZigString, arg2: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn JSC__JSValue__createUninitializedUint8Array(arg0: ?*JSC__JSGlobalObject, arg1: usize) JSC__JSValue; -pub extern fn JSC__JSValue__deepEquals(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, arg2: ?*JSC__JSGlobalObject) bool; -pub extern fn JSC__JSValue__eqlCell(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSCell) bool; +pub extern fn JSC__JSValue__asPromise(JSValue0: JSC__JSValue) ?*bindings.JSPromise; +pub extern fn JSC__JSValue__asString(JSValue0: JSC__JSValue) [*c]bindings.JSString; +pub extern fn JSC__JSValue__coerceToInt32(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) i32; +pub extern fn JSC__JSValue__createEmptyObject(arg0: *bindings.JSGlobalObject, arg1: usize) JSC__JSValue; +pub extern fn JSC__JSValue__createInternalPromise(arg0: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn JSC__JSValue__createObject2(arg0: *bindings.JSGlobalObject, arg1: [*c]const ZigString, arg2: [*c]const ZigString, JSValue3: JSC__JSValue, JSValue4: JSC__JSValue) JSC__JSValue; +pub extern fn JSC__JSValue__createRangeError(arg0: [*c]const ZigString, arg1: [*c]const ZigString, arg2: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn JSC__JSValue__createRopeString(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, arg2: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn JSC__JSValue__createStringArray(arg0: *bindings.JSGlobalObject, arg1: [*c]ZigString, arg2: usize, arg3: bool) JSC__JSValue; +pub extern fn JSC__JSValue__createTypeError(arg0: [*c]const ZigString, arg1: [*c]const ZigString, arg2: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn JSC__JSValue__createUninitializedUint8Array(arg0: *bindings.JSGlobalObject, arg1: usize) JSC__JSValue; +pub extern fn JSC__JSValue__deepEquals(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, arg2: *bindings.JSGlobalObject) bool; +pub extern fn JSC__JSValue__eqlCell(JSValue0: JSC__JSValue, arg1: [*c]bindings.JSCell) bool; pub extern fn JSC__JSValue__eqlValue(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) bool; -pub extern fn JSC__JSValue__fastGet_(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: u8) JSC__JSValue; -pub extern fn JSC__JSValue__forEach(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: ?*anyopaque, ArgFn3: ?fn ([*c]JSC__VM, ?*JSC__JSGlobalObject, ?*anyopaque, JSC__JSValue) callconv(.C) void) void; -pub extern fn JSC__JSValue__forEachProperty(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: ?*anyopaque, ArgFn3: ?fn (?*JSC__JSGlobalObject, ?*anyopaque, [*c]ZigString, JSC__JSValue, bool) callconv(.C) void) void; -pub extern fn JSC__JSValue__fromEntries(arg0: ?*JSC__JSGlobalObject, arg1: [*c]ZigString, arg2: [*c]ZigString, arg3: usize, arg4: bool) JSC__JSValue; -pub extern fn JSC__JSValue__fromInt64NoTruncate(arg0: ?*JSC__JSGlobalObject, arg1: i64) JSC__JSValue; -pub extern fn JSC__JSValue__fromUInt64NoTruncate(arg0: ?*JSC__JSGlobalObject, arg1: u64) JSC__JSValue; -pub extern fn JSC__JSValue__getClassName(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: [*c]ZigString) void; -pub extern fn JSC__JSValue__getErrorsProperty(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn JSC__JSValue__getIfPropertyExistsFromPath(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, JSValue2: JSC__JSValue) JSC__JSValue; -pub extern fn JSC__JSValue__getIfPropertyExistsImpl(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: [*c]const u8, arg3: u32) JSC__JSValue; -pub extern fn JSC__JSValue__getLengthOfArray(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) u64; -pub extern fn JSC__JSValue__getNameProperty(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: [*c]ZigString) void; -pub extern fn JSC__JSValue__getPrototype(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn JSC__JSValue__getSymbolDescription(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: [*c]ZigString) void; -pub extern fn JSC__JSValue__isAggregateError(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) bool; +pub extern fn JSC__JSValue__fastGet_(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: u8) JSC__JSValue; +pub extern fn JSC__JSValue__forEach(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: ?*anyopaque, ArgFn3: ?*const fn (*bindings.VM, *bindings.JSGlobalObject, ?*anyopaque, JSC__JSValue) callconv(.C) void) void; +pub extern fn JSC__JSValue__forEachProperty(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: ?*anyopaque, ArgFn3: ?*const fn (*bindings.JSGlobalObject, ?*anyopaque, [*c]ZigString, JSC__JSValue, bool) callconv(.C) void) void; +pub extern fn JSC__JSValue__fromEntries(arg0: *bindings.JSGlobalObject, arg1: [*c]ZigString, arg2: [*c]ZigString, arg3: usize, arg4: bool) JSC__JSValue; +pub extern fn JSC__JSValue__fromInt64NoTruncate(arg0: *bindings.JSGlobalObject, arg1: i64) JSC__JSValue; +pub extern fn JSC__JSValue__fromUInt64NoTruncate(arg0: *bindings.JSGlobalObject, arg1: u64) JSC__JSValue; +pub extern fn JSC__JSValue__getClassName(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: [*c]ZigString) void; +pub extern fn JSC__JSValue__getErrorsProperty(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn JSC__JSValue__getIfPropertyExistsFromPath(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) JSC__JSValue; +pub extern fn JSC__JSValue__getIfPropertyExistsImpl(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: [*c]const u8, arg3: u32) JSC__JSValue; +pub extern fn JSC__JSValue__getLengthOfArray(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) u64; +pub extern fn JSC__JSValue__getNameProperty(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: [*c]ZigString) void; +pub extern fn JSC__JSValue__getPrototype(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn JSC__JSValue__getSymbolDescription(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: [*c]ZigString) void; +pub extern fn JSC__JSValue__isAggregateError(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) bool; pub extern fn JSC__JSValue__isAnyInt(JSValue0: JSC__JSValue) bool; pub extern fn JSC__JSValue__isBigInt(JSValue0: JSC__JSValue) bool; pub extern fn JSC__JSValue__isBigInt32(JSValue0: JSC__JSValue) bool; pub extern fn JSC__JSValue__isBoolean(JSValue0: JSC__JSValue) bool; -pub extern fn JSC__JSValue__isCallable(JSValue0: JSC__JSValue, arg1: [*c]JSC__VM) bool; +pub extern fn JSC__JSValue__isCallable(JSValue0: JSC__JSValue, arg1: *bindings.VM) bool; pub extern fn JSC__JSValue__isCell(JSValue0: JSC__JSValue) bool; -pub extern fn JSC__JSValue__isClass(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) bool; +pub extern fn JSC__JSValue__isClass(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) bool; pub extern fn JSC__JSValue__isCustomGetterSetter(JSValue0: JSC__JSValue) bool; pub extern fn JSC__JSValue__isError(JSValue0: JSC__JSValue) bool; -pub extern fn JSC__JSValue__isException(JSValue0: JSC__JSValue, arg1: [*c]JSC__VM) bool; +pub extern fn JSC__JSValue__isException(JSValue0: JSC__JSValue, arg1: *bindings.VM) bool; pub extern fn JSC__JSValue__isGetterSetter(JSValue0: JSC__JSValue) bool; pub extern fn JSC__JSValue__isHeapBigInt(JSValue0: JSC__JSValue) bool; pub extern fn JSC__JSValue__isInt32(JSValue0: JSC__JSValue) bool; pub extern fn JSC__JSValue__isInt32AsAnyInt(JSValue0: JSC__JSValue) bool; -pub extern fn JSC__JSValue__isIterable(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) bool; +pub extern fn JSC__JSValue__isIterable(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) bool; pub extern fn JSC__JSValue__isNumber(JSValue0: JSC__JSValue) bool; pub extern fn JSC__JSValue__isObject(JSValue0: JSC__JSValue) bool; pub extern fn JSC__JSValue__isPrimitive(JSValue0: JSC__JSValue) bool; -pub extern fn JSC__JSValue__isSameValue(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, arg2: ?*JSC__JSGlobalObject) bool; +pub extern fn JSC__JSValue__isSameValue(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, arg2: *bindings.JSGlobalObject) bool; pub extern fn JSC__JSValue__isString(JSValue0: JSC__JSValue) bool; pub extern fn JSC__JSValue__isSymbol(JSValue0: JSC__JSValue) bool; -pub extern fn JSC__JSValue__isTerminationException(JSValue0: JSC__JSValue, arg1: [*c]JSC__VM) bool; +pub extern fn JSC__JSValue__isTerminationException(JSValue0: JSC__JSValue, arg1: *bindings.VM) bool; pub extern fn JSC__JSValue__isUInt32AsAnyInt(JSValue0: JSC__JSValue) bool; pub extern fn JSC__JSValue__jsBoolean(arg0: bool) JSC__JSValue; pub extern fn JSC__JSValue__jsDoubleNumber(arg0: f64) JSC__JSValue; @@ -232,102 +232,102 @@ pub extern fn JSC__JSValue__jsNumberFromChar(arg0: u8) JSC__JSValue; pub extern fn JSC__JSValue__jsNumberFromDouble(arg0: f64) JSC__JSValue; pub extern fn JSC__JSValue__jsNumberFromInt64(arg0: i64) JSC__JSValue; pub extern fn JSC__JSValue__jsNumberFromU16(arg0: u16) JSC__JSValue; -pub extern fn JSC__JSValue__jsonStringify(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: u32, arg3: [*c]ZigString) void; +pub extern fn JSC__JSValue__jsonStringify(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: u32, arg3: [*c]ZigString) void; pub extern fn JSC__JSValue__jsTDZValue(...) JSC__JSValue; pub extern fn JSC__JSValue__jsType(JSValue0: JSC__JSValue) u8; pub extern fn JSC__JSValue__jsUndefined(...) JSC__JSValue; -pub extern fn JSC__JSValue__makeWithNameAndPrototype(arg0: ?*JSC__JSGlobalObject, arg1: ?*anyopaque, arg2: ?*anyopaque, arg3: [*c]const ZigString) JSC__JSValue; -pub extern fn JSC__JSValue__parseJSON(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; -pub extern fn JSC__JSValue__put(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: [*c]const ZigString, JSValue3: JSC__JSValue) void; -pub extern fn JSC__JSValue__putRecord(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: [*c]ZigString, arg3: [*c]ZigString, arg4: usize) void; -pub extern fn JSC__JSValue__strictDeepEquals(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, arg2: ?*JSC__JSGlobalObject) bool; -pub extern fn JSC__JSValue__symbolFor(arg0: ?*JSC__JSGlobalObject, arg1: [*c]ZigString) JSC__JSValue; -pub extern fn JSC__JSValue__symbolKeyFor(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: [*c]ZigString) bool; +pub extern fn JSC__JSValue__makeWithNameAndPrototype(arg0: *bindings.JSGlobalObject, arg1: ?*anyopaque, arg2: ?*anyopaque, arg3: [*c]const ZigString) JSC__JSValue; +pub extern fn JSC__JSValue__parseJSON(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) JSC__JSValue; +pub extern fn JSC__JSValue__put(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: [*c]const ZigString, JSValue3: JSC__JSValue) void; +pub extern fn JSC__JSValue__putRecord(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: [*c]ZigString, arg3: [*c]ZigString, arg4: usize) void; +pub extern fn JSC__JSValue__strictDeepEquals(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, arg2: *bindings.JSGlobalObject) bool; +pub extern fn JSC__JSValue__symbolFor(arg0: *bindings.JSGlobalObject, arg1: [*c]ZigString) JSC__JSValue; +pub extern fn JSC__JSValue__symbolKeyFor(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: [*c]ZigString) bool; pub extern fn JSC__JSValue__toBoolean(JSValue0: JSC__JSValue) bool; -pub extern fn JSC__JSValue__toBooleanSlow(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) bool; -pub extern fn JSC__JSValue__toError(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) JSC__JSValue; +pub extern fn JSC__JSValue__toBooleanSlow(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) bool; +pub extern fn JSC__JSValue__toError(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) JSC__JSValue; pub extern fn JSC__JSValue__toInt32(JSValue0: JSC__JSValue) i32; pub extern fn JSC__JSValue__toInt64(JSValue0: JSC__JSValue) i64; -pub extern fn JSC__JSValue__toObject(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) [*c]JSC__JSObject; -pub extern fn JSC__JSValue__toString(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) [*c]JSC__JSString; -pub extern fn JSC__JSValue__toStringOrNull(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject) [*c]JSC__JSString; +pub extern fn JSC__JSValue__toObject(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) [*c]bindings.JSObject; +pub extern fn JSC__JSValue__toString(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) [*c]bindings.JSString; +pub extern fn JSC__JSValue__toStringOrNull(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) [*c]bindings.JSString; pub extern fn JSC__JSValue__toUInt64NoTruncate(JSValue0: JSC__JSValue) u64; -pub extern fn JSC__JSValue__toZigException(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: [*c]ZigException) void; -pub extern fn JSC__JSValue__toZigString(JSValue0: JSC__JSValue, arg1: [*c]ZigString, arg2: ?*JSC__JSGlobalObject) void; -pub extern fn JSC__Exception__create(arg0: ?*JSC__JSGlobalObject, arg1: [*c]JSC__JSObject, StackCaptureAction2: u8) [*c]JSC__Exception; -pub extern fn JSC__Exception__getStackTrace(arg0: [*c]JSC__Exception, arg1: [*c]ZigStackTrace) void; -pub extern fn JSC__Exception__value(arg0: [*c]JSC__Exception) JSC__JSValue; -pub extern fn JSC__VM__blockBytesAllocated(arg0: [*c]JSC__VM) usize; -pub extern fn JSC__VM__clearExecutionTimeLimit(arg0: [*c]JSC__VM) void; -pub extern fn JSC__VM__collectAsync(arg0: [*c]JSC__VM) void; -pub extern fn JSC__VM__create(HeapType0: u8) [*c]JSC__VM; -pub extern fn JSC__VM__deferGC(arg0: [*c]JSC__VM, arg1: ?*anyopaque, ArgFn2: ?fn (?*anyopaque) callconv(.C) void) void; -pub extern fn JSC__VM__deinit(arg0: [*c]JSC__VM, arg1: ?*JSC__JSGlobalObject) void; -pub extern fn JSC__VM__deleteAllCode(arg0: [*c]JSC__VM, arg1: ?*JSC__JSGlobalObject) void; -pub extern fn JSC__VM__doWork(arg0: [*c]JSC__VM) void; -pub extern fn JSC__VM__drainMicrotasks(arg0: [*c]JSC__VM) void; -pub extern fn JSC__VM__executionForbidden(arg0: [*c]JSC__VM) bool; -pub extern fn JSC__VM__externalMemorySize(arg0: [*c]JSC__VM) usize; -pub extern fn JSC__VM__heapSize(arg0: [*c]JSC__VM) usize; -pub extern fn JSC__VM__holdAPILock(arg0: [*c]JSC__VM, arg1: ?*anyopaque, ArgFn2: ?fn (?*anyopaque) callconv(.C) void) void; -pub extern fn JSC__VM__isEntered(arg0: [*c]JSC__VM) bool; +pub extern fn JSC__JSValue__toZigException(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: [*c]ZigException) void; +pub extern fn JSC__JSValue__toZigString(JSValue0: JSC__JSValue, arg1: [*c]ZigString, arg2: *bindings.JSGlobalObject) void; +pub extern fn JSC__Exception__create(arg0: *bindings.JSGlobalObject, arg1: [*c]bindings.JSObject, StackCaptureAction2: u8) [*c]bindings.Exception; +pub extern fn JSC__Exception__getStackTrace(arg0: [*c]bindings.Exception, arg1: [*c]ZigStackTrace) void; +pub extern fn JSC__Exception__value(arg0: [*c]bindings.Exception) JSC__JSValue; +pub extern fn JSC__VM__blockBytesAllocated(arg0: *bindings.VM) usize; +pub extern fn JSC__VM__clearExecutionTimeLimit(arg0: *bindings.VM) void; +pub extern fn JSC__VM__collectAsync(arg0: *bindings.VM) void; +pub extern fn JSC__VM__create(HeapType0: u8) *bindings.VM; +pub extern fn JSC__VM__deferGC(arg0: *bindings.VM, arg1: ?*anyopaque, ArgFn2: ?*const fn (?*anyopaque) callconv(.C) void) void; +pub extern fn JSC__VM__deinit(arg0: *bindings.VM, arg1: *bindings.JSGlobalObject) void; +pub extern fn JSC__VM__deleteAllCode(arg0: *bindings.VM, arg1: *bindings.JSGlobalObject) void; +pub extern fn JSC__VM__doWork(arg0: *bindings.VM) void; +pub extern fn JSC__VM__drainMicrotasks(arg0: *bindings.VM) void; +pub extern fn JSC__VM__executionForbidden(arg0: *bindings.VM) bool; +pub extern fn JSC__VM__externalMemorySize(arg0: *bindings.VM) usize; +pub extern fn JSC__VM__heapSize(arg0: *bindings.VM) usize; +pub extern fn JSC__VM__holdAPILock(arg0: *bindings.VM, arg1: ?*anyopaque, ArgFn2: ?*const fn (?*anyopaque) callconv(.C) void) void; +pub extern fn JSC__VM__isEntered(arg0: *bindings.VM) bool; pub extern fn JSC__VM__isJITEnabled(...) bool; -pub extern fn JSC__VM__releaseWeakRefs(arg0: [*c]JSC__VM) void; -pub extern fn JSC__VM__runGC(arg0: [*c]JSC__VM, arg1: bool) JSC__JSValue; -pub extern fn JSC__VM__setExecutionForbidden(arg0: [*c]JSC__VM, arg1: bool) void; -pub extern fn JSC__VM__setExecutionTimeLimit(arg0: [*c]JSC__VM, arg1: f64) void; -pub extern fn JSC__VM__shrinkFootprint(arg0: [*c]JSC__VM) void; -pub extern fn JSC__VM__throwError(arg0: [*c]JSC__VM, arg1: ?*JSC__JSGlobalObject, JSValue2: JSC__JSValue) void; -pub extern fn JSC__VM__whenIdle(arg0: [*c]JSC__VM, ArgFn1: ?fn (...) callconv(.C) void) void; -pub extern fn JSC__ThrowScope__clearException(arg0: [*c]JSC__ThrowScope) void; -pub extern fn JSC__ThrowScope__declare(arg0: [*c]JSC__VM, arg1: [*c]u8, arg2: [*c]u8, arg3: usize) bJSC__ThrowScope; -pub extern fn JSC__ThrowScope__exception(arg0: [*c]JSC__ThrowScope) [*c]JSC__Exception; -pub extern fn JSC__ThrowScope__release(arg0: [*c]JSC__ThrowScope) void; -pub extern fn JSC__CatchScope__clearException(arg0: [*c]JSC__CatchScope) void; -pub extern fn JSC__CatchScope__declare(arg0: [*c]JSC__VM, arg1: [*c]u8, arg2: [*c]u8, arg3: usize) bJSC__CatchScope; -pub extern fn JSC__CatchScope__exception(arg0: [*c]JSC__CatchScope) [*c]JSC__Exception; -pub extern fn FFI__ptr__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__u8__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__u16__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__u32__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__ptr__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__i8__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__i16__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__i32__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__f32__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__f64__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__i64__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__u64__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Reader__intptr__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Crypto__getRandomValues__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Crypto__randomUUID__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Crypto__timingSafeEqual__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void; -pub extern fn Zig__GlobalObject__create(arg0: [*c]JSClassRef, arg1: i32, arg2: ?*anyopaque) ?*JSC__JSGlobalObject; -pub extern fn Zig__GlobalObject__getModuleRegistryMap(arg0: ?*JSC__JSGlobalObject) ?*anyopaque; -pub extern fn Zig__GlobalObject__resetModuleRegistryMap(arg0: ?*JSC__JSGlobalObject, arg1: ?*anyopaque) bool; -pub extern fn Bun__Path__create(arg0: ?*JSC__JSGlobalObject, arg1: bool) JSC__JSValue; -pub extern fn ArrayBufferSink__assignToStream(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue; -pub extern fn ArrayBufferSink__createObject(arg0: ?*JSC__JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue; +pub extern fn JSC__VM__releaseWeakRefs(arg0: *bindings.VM) void; +pub extern fn JSC__VM__runGC(arg0: *bindings.VM, arg1: bool) JSC__JSValue; +pub extern fn JSC__VM__setExecutionForbidden(arg0: *bindings.VM, arg1: bool) void; +pub extern fn JSC__VM__setExecutionTimeLimit(arg0: *bindings.VM, arg1: f64) void; +pub extern fn JSC__VM__shrinkFootprint(arg0: *bindings.VM) void; +pub extern fn JSC__VM__throwError(arg0: *bindings.VM, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) void; +pub extern fn JSC__VM__whenIdle(arg0: *bindings.VM, ArgFn1: ?*const fn (...) callconv(.C) void) void; +pub extern fn JSC__ThrowScope__clearException(arg0: [*c]bindings.ThrowScope) void; +pub extern fn JSC__ThrowScope__declare(arg0: *bindings.VM, arg1: [*c]u8, arg2: [*c]u8, arg3: usize) bJSC__ThrowScope; +pub extern fn JSC__ThrowScope__exception(arg0: [*c]bindings.ThrowScope) [*c]bindings.Exception; +pub extern fn JSC__ThrowScope__release(arg0: [*c]bindings.ThrowScope) void; +pub extern fn JSC__CatchScope__clearException(arg0: [*c]bindings.CatchScope) void; +pub extern fn JSC__CatchScope__declare(arg0: *bindings.VM, arg1: [*c]u8, arg2: [*c]u8, arg3: usize) bJSC__CatchScope; +pub extern fn JSC__CatchScope__exception(arg0: [*c]bindings.CatchScope) [*c]bindings.Exception; +pub extern fn FFI__ptr__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__u8__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__u16__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__u32__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__ptr__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__i8__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__i16__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__i32__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__f32__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__f64__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__i64__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__u64__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Reader__intptr__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Crypto__getRandomValues__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Crypto__randomUUID__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Crypto__timingSafeEqual__put(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) void; +pub extern fn Zig__GlobalObject__create(arg0: [*c]JSClassRef, arg1: i32, arg2: ?*anyopaque) *bindings.JSGlobalObject; +pub extern fn Zig__GlobalObject__getModuleRegistryMap(arg0: *bindings.JSGlobalObject) ?*anyopaque; +pub extern fn Zig__GlobalObject__resetModuleRegistryMap(arg0: *bindings.JSGlobalObject, arg1: ?*anyopaque) bool; +pub extern fn Bun__Path__create(arg0: *bindings.JSGlobalObject, arg1: bool) JSC__JSValue; +pub extern fn ArrayBufferSink__assignToStream(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue; +pub extern fn ArrayBufferSink__createObject(arg0: *bindings.JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue; pub extern fn ArrayBufferSink__detachPtr(JSValue0: JSC__JSValue) void; -pub extern fn ArrayBufferSink__fromJS(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque; +pub extern fn ArrayBufferSink__fromJS(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque; pub extern fn ArrayBufferSink__onClose(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) void; pub extern fn ArrayBufferSink__onReady(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, JSValue2: JSC__JSValue) void; -pub extern fn HTTPSResponseSink__assignToStream(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue; -pub extern fn HTTPSResponseSink__createObject(arg0: ?*JSC__JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue; +pub extern fn HTTPSResponseSink__assignToStream(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue; +pub extern fn HTTPSResponseSink__createObject(arg0: *bindings.JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue; pub extern fn HTTPSResponseSink__detachPtr(JSValue0: JSC__JSValue) void; -pub extern fn HTTPSResponseSink__fromJS(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque; +pub extern fn HTTPSResponseSink__fromJS(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque; pub extern fn HTTPSResponseSink__onClose(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) void; pub extern fn HTTPSResponseSink__onReady(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, JSValue2: JSC__JSValue) void; -pub extern fn HTTPResponseSink__assignToStream(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue; -pub extern fn HTTPResponseSink__createObject(arg0: ?*JSC__JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue; +pub extern fn HTTPResponseSink__assignToStream(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue; +pub extern fn HTTPResponseSink__createObject(arg0: *bindings.JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue; pub extern fn HTTPResponseSink__detachPtr(JSValue0: JSC__JSValue) void; -pub extern fn HTTPResponseSink__fromJS(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque; +pub extern fn HTTPResponseSink__fromJS(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque; pub extern fn HTTPResponseSink__onClose(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) void; pub extern fn HTTPResponseSink__onReady(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, JSValue2: JSC__JSValue) void; -pub extern fn FileSink__assignToStream(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue; -pub extern fn FileSink__createObject(arg0: ?*JSC__JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue; +pub extern fn FileSink__assignToStream(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue; +pub extern fn FileSink__createObject(arg0: *bindings.JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue; pub extern fn FileSink__detachPtr(JSValue0: JSC__JSValue) void; -pub extern fn FileSink__fromJS(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque; +pub extern fn FileSink__fromJS(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque; pub extern fn FileSink__onClose(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) void; pub extern fn FileSink__onReady(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, JSValue2: JSC__JSValue) void; -pub extern fn ZigException__fromException(arg0: [*c]JSC__Exception) ZigException; +pub extern fn ZigException__fromException(arg0: [*c]bindings.Exception) ZigException; diff --git a/src/bun.js/bindings/shimmer.zig b/src/bun.js/bindings/shimmer.zig index f31c894cb..cde7712c5 100644 --- a/src/bun.js/bindings/shimmer.zig +++ b/src/bun.js/bindings/shimmer.zig @@ -36,7 +36,7 @@ pub fn Shimmer(comptime _namespace: []const u8, comptime _name: []const u8, comp // return FromType; // } - // var ReturnTypeInfo: std.builtin.TypeInfo = @typeInfo(FromType); + // var ReturnTypeInfo: std.builtin.Type = @typeInfo(FromType); // if (ReturnTypeInfo == .Pointer and NewReturnType != *anyopaque) { // NewReturnType = ReturnTypeInfo.Pointer.child; @@ -110,7 +110,7 @@ pub fn Shimmer(comptime _namespace: []const u8, comptime _name: []const u8, comp if (@typeInfo(Function) != .Fn) { @compileError("Expected " ++ @typeName(Parent) ++ "." ++ @typeName(Function) ++ " to be a function but received " ++ @tagName(@typeInfo(Function))); } - var Fn: std.builtin.TypeInfo.Fn = @typeInfo(Function).Fn; + var Fn: std.builtin.Type.Fn = @typeInfo(Function).Fn; if (Fn.calling_convention != .C) { @compileError("Expected " ++ @typeName(Parent) ++ "." ++ @typeName(Function) ++ " to have a C Calling Convention."); } @@ -139,7 +139,7 @@ pub fn Shimmer(comptime _namespace: []const u8, comptime _name: []const u8, comp if (@typeInfo(Function) != .Fn) { @compileError("Expected " ++ @typeName(Parent) ++ "." ++ @typeName(Function) ++ " to be a function but received " ++ @tagName(@typeInfo(Function))); } - var Fn: std.builtin.TypeInfo.Fn = @typeInfo(Function).Fn; + var Fn: std.builtin.Type.Fn = @typeInfo(Function).Fn; if (Fn.calling_convention != .C) { @compileError("Expected " ++ @typeName(Parent) ++ "." ++ @typeName(Function) ++ " to have a C Calling Convention."); } @@ -182,17 +182,17 @@ pub fn Shimmer(comptime _namespace: []const u8, comptime _name: []const u8, comp unreachable; } else { const Fn = comptime @field(headers, symbolName(typeName)); - if (@typeInfo(@TypeOf(Fn)).Fn.args.len > 0) + if (@typeInfo(@TypeOf(Fn)).Fn.params.len > 0) return matchNullable( comptime @typeInfo(@TypeOf(@field(Parent, typeName))).Fn.return_type.?, comptime @typeInfo(@TypeOf(Fn)).Fn.return_type.?, - @call(.{}, Fn, @bitCast(std.meta.ArgsTuple(@TypeOf(Fn)), args)), + @call(.auto, Fn, args), ); return matchNullable( comptime @typeInfo(@TypeOf(@field(Parent, typeName))).Fn.return_type.?, comptime @typeInfo(@TypeOf(Fn)).Fn.return_type.?, - @call(.{}, Fn, .{}), + @call(.auto, Fn, .{}), ); } } diff --git a/src/bun.js/bindings/sizes.zig b/src/bun.js/bindings/sizes.zig index 136eb9f61..795159e49 100644 --- a/src/bun.js/bindings/sizes.zig +++ b/src/bun.js/bindings/sizes.zig @@ -6,13 +6,13 @@ // 1. We can't dynamically link JavaScriptCore // 2. It's important that this is run whenever JavaScriptCore is updated or the bindings on the Zig side change. // Failure to do so will lead to undefined behavior and probably some frustrated people. -// --- Regenerate this: --- +// --- Regenerate this: --- // 1. "make headers" // 2. "make sizegen" // 3. "make headers" // ------------------------ // You can verify the numbers written in this file at runtime via the `extern`d types -// Run "headers" twice because it uses these values in the output. That's how all the bJSC__.* types are created - from these values. +// Run "headers" twice because it uses these values in the output. That's how all the bJSC__.* types are created - from these values. pub const JSC__JSObject = 16; pub const JSC__JSObject_align = 8; pub const WebCore__DOMURL = 112; diff --git a/src/bun.js/bindings/static_export.zig b/src/bun.js/bindings/static_export.zig index f8936f0df..a3d47e56e 100644 --- a/src/bun.js/bindings/static_export.zig +++ b/src/bun.js/bindings/static_export.zig @@ -5,7 +5,7 @@ local_name: []const u8, Parent: type, -pub fn Decl(comptime this: *const @This()) std.builtin.TypeInfo.Declaration { +pub fn Decl(comptime this: *const @This()) std.builtin.Type.Declaration { return comptime std.meta.declarationInfo(this.Parent, this.local_name); } diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index b770fe3e4..56e68cce0 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -28,7 +28,7 @@ pub fn ConcurrentPromiseTask(comptime Context: type) type { return struct { const This = @This(); ctx: *Context, - task: WorkPoolTask = .{ .callback = runFromThreadPool }, + task: WorkPoolTask = .{ .callback = &runFromThreadPool }, event_loop: *JSC.EventLoop, allocator: std.mem.Allocator, promise: JSC.JSPromise.Strong = .{}, @@ -41,7 +41,7 @@ pub fn ConcurrentPromiseTask(comptime Context: type) type { pub fn createOnJSThread(allocator: std.mem.Allocator, globalThis: *JSGlobalObject, value: *Context) !*This { var this = try allocator.create(This); this.* = .{ - .event_loop = VirtualMachine.vm.event_loop, + .event_loop = VirtualMachine.get().event_loop, .ctx = value, .allocator = allocator, .globalThis = globalThis, @@ -86,7 +86,7 @@ pub fn IOTask(comptime Context: type) type { return struct { const This = @This(); ctx: *Context, - task: NetworkThread.Task = .{ .callback = runFromThreadPool }, + task: NetworkThread.Task = .{ .callback = &runFromThreadPool }, event_loop: *JSC.EventLoop, allocator: std.mem.Allocator, globalThis: *JSGlobalObject, @@ -140,7 +140,7 @@ pub fn IOTask(comptime Context: type) type { pub const AnyTask = struct { ctx: ?*anyopaque, - callback: fn (*anyopaque) void, + callback: *const (fn (*anyopaque) void), pub fn run(this: *AnyTask) void { @setRuntimeSafety(false); @@ -586,7 +586,7 @@ pub const EventLoop = struct { var task = Task.from(timer.as(*anyopaque)); timer.deinit(); - JSC.VirtualMachine.vm.enqueueTask(task); + JSC.VirtualMachine.get().enqueueTask(task); } pub fn ensureWaker(this: *EventLoop) void { diff --git a/src/bun.js/http.exports.js b/src/bun.js/http.exports.js index 9db81a3a7..6e2eedacb 100644 --- a/src/bun.js/http.exports.js +++ b/src/bun.js/http.exports.js @@ -178,25 +178,37 @@ export class IncomingMessage extends Readable { if (this.#noBody) { this.push(null); this.complete = true; - } else if (this.#bodyStream === null) { + } else if (this.#bodyStream == null) { const contentLength = this.#req.headers.get("content-length"); - var remaining = contentLength ? parseInt(contentLength, 10) : 0; + let remaining = contentLength ? parseInt(contentLength, 10) : 0; this.#bodyStream = Readable.fromWeb(this.#req.body, { highWaterMark: Number.isFinite(remaining) ? Math.min(remaining, 16384) : 16384, }); - this.#bodyStream.on("data", (chunk) => { - this.push(chunk); - remaining -= chunk?.byteLength ?? 0; - if (remaining <= 0) { + const isBodySizeKnown = remaining > 0 && Number.isSafeInteger(remaining); + + if (isBodySizeKnown) { + this.#bodyStream.on("data", (chunk) => { + this.push(chunk); + // when we are streaming a known body size, automatically close the stream when we have read enough + remaining -= chunk?.byteLength ?? 0; + if (remaining <= 0) { + this.#closeBodyStream(); + } + }); + } else { + this.#bodyStream.on("data", (chunk) => { + this.push(chunk); + }); + } + + // this can be closed by the time we get here if enough data was synchronously available + this.#bodyStream && + this.#bodyStream.on("end", () => { this.#closeBodyStream(); - } - }); - this.#bodyStream.on("end", () => { - this.#closeBodyStream(); - }); + }); } else { // this.#bodyStream.read(size); } diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index c0740b735..e0b8a5376 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -115,12 +115,12 @@ const Blob = @import("../blob.zig"); pub const Buffer = MarkedArrayBuffer; const Lock = @import("../lock.zig").Lock; -pub const OpaqueCallback = fn (current: ?*anyopaque) callconv(.C) void; +pub const OpaqueCallback = *const fn (current: ?*anyopaque) callconv(.C) void; pub fn OpaqueWrap(comptime Context: type, comptime Function: fn (this: *Context) void) OpaqueCallback { return struct { pub fn callback(ctx: ?*anyopaque) callconv(.C) void { var context: *Context = @ptrCast(*Context, @alignCast(@alignOf(Context), ctx.?)); - @call(.{}, Function, .{context}); + @call(.auto, Function, .{context}); } }.callback; } @@ -246,15 +246,16 @@ pub const SavedSourceMap = struct { const uws = @import("bun").uws; pub export fn Bun__getDefaultGlobal() *JSGlobalObject { - return JSC.VirtualMachine.vm.global; + _ = @sizeOf(JSC.VirtualMachine) + 1; + return JSC.VirtualMachine.get().global; } pub export fn Bun__getVM() *JSC.VirtualMachine { - return JSC.VirtualMachine.vm; + return JSC.VirtualMachine.get(); } pub export fn Bun__drainMicrotasks() void { - JSC.VirtualMachine.vm.eventLoop().tick(); + JSC.VirtualMachine.get().eventLoop().tick(); } export fn Bun__readOriginTimer(vm: *JSC.VirtualMachine) u64 { @@ -263,25 +264,23 @@ export fn Bun__readOriginTimer(vm: *JSC.VirtualMachine) u64 { export fn Bun__readOriginTimerStart(vm: *JSC.VirtualMachine) f64 { // timespce to milliseconds - // use f128 to reduce precision loss when converting to f64 - return @floatCast(f64, (@intToFloat(f128, vm.origin_timestamp) + JSC.VirtualMachine.origin_relative_epoch) / 1_000_000.0); + return @floatCast(f64, (@intToFloat(f64, vm.origin_timestamp) + JSC.VirtualMachine.origin_relative_epoch) / 1_000_000.0); } -comptime { - if (!JSC.is_bindgen) { - _ = Bun__getDefaultGlobal; - _ = Bun__getVM; - _ = Bun__drainMicrotasks; - _ = Bun__queueTask; - _ = Bun__queueTaskConcurrently; - _ = Bun__handleRejectedPromise; - _ = Bun__readOriginTimer; - _ = Bun__onDidAppendPlugin; - _ = Bun__readOriginTimerStart; - _ = Bun__reportUnhandledError; - _ = Bun__queueTaskWithTimeout; - } -} +// comptime { +// if (!JSC.is_bindgen) { +// _ = Bun__getDefaultGlobal; +// _ = Bun__getVM; +// _ = Bun__drainMicrotasks; +// _ = Bun__queueTask; +// _ = Bun__queueTaskConcurrently; +// _ = Bun__handleRejectedPromise; +// _ = Bun__readOriginTimer; +// _ = Bun__onDidAppendPlugin; +// _ = Bun__readOriginTimerStart; +// _ = Bun__reportUnhandledError; +// } +// } /// This function is called on the main thread /// The bunVM() call will assert this @@ -430,7 +429,7 @@ pub const VirtualMachine = struct { auto_install_dependencies: bool = false, load_builtins_from_path: []const u8 = "", - onUnhandledRejection: fn (*VirtualMachine, globalObject: *JSC.JSGlobalObject, JSC.JSValue) void = defaultOnUnhandledRejection, + onUnhandledRejection: *const fn (*VirtualMachine, globalObject: *JSC.JSGlobalObject, JSC.JSValue) void = defaultOnUnhandledRejection, onUnhandledRejectionCtx: ?*anyopaque = null, unhandled_error_counter: usize = 0, @@ -439,6 +438,14 @@ pub const VirtualMachine = struct { gc_controller: JSC.GarbageCollectionController = .{}, + const VMHolder = struct { + pub threadlocal var vm: ?*VirtualMachine = null; + }; + + pub inline fn get() *VirtualMachine { + return VMHolder.vm.?; + } + pub const GCLevel = enum(u3) { none = 0, mild = 1, @@ -574,15 +581,6 @@ pub const VirtualMachine = struct { pub const MacroMap = std.AutoArrayHashMap(i32, js.JSObjectRef); - /// Threadlocals are slow on macOS - pub threadlocal var vm_loaded = false; - - /// Threadlocals are slow on macOS - /// Consider using `globalThis.bunVM()` instead. - /// There may be a time where we run multiple VMs in the same thread - /// At that point, this threadlocal will be a problem. - pub threadlocal var vm: *VirtualMachine = undefined; - pub fn enableMacroMode(this: *VirtualMachine) void { if (!this.has_enabled_macro_mode) { this.has_enabled_macro_mode = true; @@ -621,16 +619,16 @@ pub const VirtualMachine = struct { pub fn getAPIConstructors(globalObject: *JSGlobalObject) []const JSC.JSValue { if (is_bindgen) return &[_]JSC.JSValue{}; - const is_first = !VirtualMachine.vm.has_loaded_constructors; + const is_first = !VirtualMachine.get().has_loaded_constructors; if (is_first) { - VirtualMachine.vm.global = globalObject; - VirtualMachine.vm.has_loaded_constructors = true; + VirtualMachine.get().global = globalObject; + VirtualMachine.get().has_loaded_constructors = true; } var slice = if (is_first) - @as([]JSC.JSValue, &JSC.VirtualMachine.vm.global_api_constructors) + @as([]JSC.JSValue, &JSC.VirtualMachine.get().global_api_constructors) else - VirtualMachine.vm.allocator.alloc(JSC.JSValue, GlobalConstructors.len) catch unreachable; + VirtualMachine.get().allocator.alloc(JSC.JSValue, GlobalConstructors.len) catch unreachable; inline for (GlobalConstructors) |Class, i| { var ref = Class.constructor(globalObject.ref()).?; @@ -656,7 +654,7 @@ pub const VirtualMachine = struct { @intCast( u128, // handle if they set their system clock to be before epoch - @maximum( + @max( std.time.nanoTimestamp(), origin_relative_epoch, ), @@ -664,6 +662,10 @@ pub const VirtualMachine = struct { ); } + pub inline fn isLoaded() bool { + return VMHolder.vm != null; + } + pub fn init( allocator: std.mem.Allocator, _args: Api.TransformOptions, @@ -679,7 +681,7 @@ pub const VirtualMachine = struct { log.* = logger.Log.init(allocator); } - VirtualMachine.vm = try allocator.create(VirtualMachine); + VMHolder.vm = try allocator.create(VirtualMachine); var console = try allocator.create(ZigConsoleClient); console.* = ZigConsoleClient.init(Output.errorWriter(), Output.writer()); const bundler = try Bundler.init( @@ -690,7 +692,9 @@ pub const VirtualMachine = struct { env_loader, ); - VirtualMachine.vm.* = VirtualMachine{ + var vm = VMHolder.vm.?; + + vm.* = VirtualMachine{ .global = undefined, .allocator = allocator, .entry_point = ServerEntryPoint{}, @@ -705,49 +709,48 @@ pub const VirtualMachine = struct { .saved_source_map_table = SavedSourceMap.HashTable.init(allocator), .source_mappings = undefined, .macros = MacroMap.init(allocator), - .macro_entry_points = @TypeOf(VirtualMachine.vm.macro_entry_points).init(allocator), + .macro_entry_points = @TypeOf(vm.macro_entry_points).init(allocator), .origin_timer = std.time.Timer.start() catch @panic("Please don't mess with timers."), .origin_timestamp = getOriginTimestamp(), .ref_strings = JSC.RefString.Map.init(allocator), .file_blobs = JSC.WebCore.Blob.Store.Map.init(allocator), }; - VirtualMachine.vm.source_mappings = .{ .map = &VirtualMachine.vm.saved_source_map_table }; - VirtualMachine.vm.regular_event_loop.tasks = EventLoop.Queue.init( + vm.source_mappings = .{ .map = &vm.saved_source_map_table }; + vm.regular_event_loop.tasks = EventLoop.Queue.init( default_allocator, ); - VirtualMachine.vm.regular_event_loop.tasks.ensureUnusedCapacity(64) catch unreachable; - VirtualMachine.vm.regular_event_loop.concurrent_tasks = .{}; - VirtualMachine.vm.event_loop = &VirtualMachine.vm.regular_event_loop; + vm.regular_event_loop.tasks.ensureUnusedCapacity(64) catch unreachable; + vm.regular_event_loop.concurrent_tasks = .{}; + vm.event_loop = &vm.regular_event_loop; vm.bundler.macro_context = null; - VirtualMachine.vm.bundler.resolver.onWakePackageManager = .{ - .context = &VirtualMachine.vm.modules, + vm.bundler.resolver.onWakePackageManager = .{ + .context = &vm.modules, .handler = ModuleLoader.AsyncModule.Queue.onWakeHandler, .onDependencyError = JSC.ModuleLoader.AsyncModule.Queue.onDependencyError, }; - VirtualMachine.vm.bundler.configureLinker(); - try VirtualMachine.vm.bundler.configureFramework(false); + vm.bundler.configureLinker(); + try vm.bundler.configureFramework(false); vm.bundler.macro_context = js_ast.Macro.MacroContext.init(&vm.bundler); if (_args.serve orelse false) { - VirtualMachine.vm.bundler.linker.onImportCSS = Bun.onImportCSS; + vm.bundler.linker.onImportCSS = Bun.onImportCSS; } var global_classes: [GlobalClasses.len]js.JSClassRef = undefined; inline for (GlobalClasses) |Class, i| { global_classes[i] = Class.get().*; } - VirtualMachine.vm.global = ZigGlobalObject.create( + vm.global = ZigGlobalObject.create( &global_classes, @intCast(i32, global_classes.len), vm.console, ); - VirtualMachine.vm.regular_event_loop.global = VirtualMachine.vm.global; - VirtualMachine.vm.regular_event_loop.virtual_machine = VirtualMachine.vm; - VirtualMachine.vm_loaded = true; + vm.regular_event_loop.global = vm.global; + vm.regular_event_loop.virtual_machine = vm; if (source_code_printer == null) { var writer = try js_printer.BufferWriter.init(allocator); @@ -756,7 +759,7 @@ pub const VirtualMachine = struct { source_code_printer.?.ctx.append_null_byte = false; } - return VirtualMachine.vm; + return vm; } // dynamic import @@ -767,7 +770,7 @@ pub const VirtualMachine = struct { pub threadlocal var source_code_printer: ?*js_printer.BufferPrinter = null; pub fn clearRefString(_: *anyopaque, ref_string: *JSC.RefString) void { - _ = VirtualMachine.vm.ref_strings.remove(ref_string.hash); + _ = VirtualMachine.get().ref_strings.remove(ref_string.hash); } pub fn refCountedResolvedSource(this: *VirtualMachine, code: []const u8, specifier: []const u8, source_url: []const u8, hash_: ?u32) ResolvedSource { @@ -836,7 +839,7 @@ pub const VirtualMachine = struct { ret: *ErrorableResolvedSource, comptime flags: FetchFlags, ) !ResolvedSource { - std.debug.assert(VirtualMachine.vm_loaded); + std.debug.assert(VirtualMachine.isLoaded()); if (try ModuleLoader.fetchBuiltinModule(jsc_vm, _specifier, log, comptime flags.disableTranspiling())) |builtin| { return builtin; @@ -881,11 +884,11 @@ pub const VirtualMachine = struct { comptime is_a_file_path: bool, comptime realpath: bool, ) !void { - std.debug.assert(VirtualMachine.vm_loaded); + std.debug.assert(VirtualMachine.isLoaded()); // macOS threadlocal vars are very slow // we won't change threads in this function // so we can copy it here - var jsc_vm = vm; + var jsc_vm = VirtualMachine.get(); if (jsc_vm.node_modules == null and strings.eqlComptime(std.fs.path.basename(specifier), Runtime.Runtime.Imports.alt_name)) { ret.path = Runtime.Runtime.Imports.Name; @@ -989,7 +992,7 @@ pub const VirtualMachine = struct { microtask: *Microtask, ) void { if (comptime Environment.allow_assert) - std.debug.assert(VirtualMachine.vm_loaded); + std.debug.assert(VirtualMachine.isLoaded()); var vm_ = globalObject.bunVM(); if (vm_.global == globalObject) { @@ -1013,7 +1016,7 @@ pub const VirtualMachine = struct { pub fn resolveMaybeNeedsTrailingSlash(res: *ErrorableZigString, global: *JSGlobalObject, specifier: ZigString, source: ZigString, comptime is_a_file_path: bool, comptime realpath: bool) void { var result = ResolveFunctionResult{ .path = "", .result = null }; - var jsc_vm = vm; + var jsc_vm = VirtualMachine.get(); if (jsc_vm.plugin_runner) |plugin_runner| { if (PluginRunner.couldBePlugin(specifier.slice())) { const namespace = PluginRunner.extractNamespace(specifier.slice()); @@ -1076,7 +1079,7 @@ pub const VirtualMachine = struct { }; { - res.* = ErrorableZigString.err(err, @ptrCast(*anyopaque, ResolveError.create(global, vm.allocator, msg, source.slice()))); + res.* = ErrorableZigString.err(err, @ptrCast(*anyopaque, ResolveError.create(global, VirtualMachine.get().allocator, msg, source.slice()))); } return; @@ -1088,8 +1091,8 @@ pub const VirtualMachine = struct { // // This double prints // pub fn promiseRejectionTracker(global: *JSGlobalObject, promise: *JSPromise, _: JSPromiseRejectionOperation) callconv(.C) JSValue { // const result = promise.result(global.vm()); - // if (@enumToInt(VirtualMachine.vm.last_error_jsvalue) != @enumToInt(result)) { - // VirtualMachine.vm.runErrorHandler(result, null); + // if (@enumToInt(VirtualMachine.get().last_error_jsvalue) != @enumToInt(result)) { + // VirtualMachine.get().runErrorHandler(result, null); // } // return JSValue.jsUndefined(); @@ -1099,18 +1102,18 @@ pub const VirtualMachine = struct { pub fn fetch(ret: *ErrorableResolvedSource, global: *JSGlobalObject, specifier: ZigString, source: ZigString) callconv(.C) void { var jsc_vm: *VirtualMachine = if (comptime Environment.isLinux) - vm + VirtualMachine.get() else global.bunVM(); - var log = logger.Log.init(vm.bundler.allocator); + var log = logger.Log.init(jsc_vm.bundler.allocator); var spec = specifier.toSlice(jsc_vm.allocator); defer spec.deinit(); var refer = source.toSlice(jsc_vm.allocator); defer refer.deinit(); const result = if (!jsc_vm.bundler.options.disable_transpilation) - @call(.{ .modifier = .always_inline }, fetchWithoutOnLoadPlugins, .{ jsc_vm, global, spec.slice(), refer.slice(), &log, ret, .transpile }) catch |err| { + @call(.always_inline, fetchWithoutOnLoadPlugins, .{ jsc_vm, global, spec.slice(), refer.slice(), &log, ret, .transpile }) catch |err| { processFetchLog(global, specifier, source, &log, ret, err); return; } @@ -1143,11 +1146,12 @@ pub const VirtualMachine = struct { } ret.result.value = result; + var vm = get(); if (vm.blobs) |blobs| { const specifier_blob = brk: { - if (strings.hasPrefix(spec.slice(), VirtualMachine.vm.bundler.fs.top_level_dir)) { - break :brk spec.slice()[VirtualMachine.vm.bundler.fs.top_level_dir.len..]; + if (strings.hasPrefix(spec.slice(), VirtualMachine.get().bundler.fs.top_level_dir)) { + break :brk spec.slice()[VirtualMachine.get().bundler.fs.top_level_dir.len..]; } break :brk spec.slice(); }; @@ -1171,17 +1175,17 @@ pub const VirtualMachine = struct { .data = logger.rangeData( null, logger.Range.None, - std.fmt.allocPrint(vm.allocator, "Unexpected pending import in \"{s}\". To automatically install npm packages with Bun, please use an import statement instead of require() or dynamic import().\nThis error can also happen if dependencies import packages which are not referenced anywhere. Worst case, run `bun install` and opt-out of the node_modules folder until we come up with a better way to handle this error.", .{specifier.slice()}) catch unreachable, + std.fmt.allocPrint(globalThis.allocator(), "Unexpected pending import in \"{s}\". To automatically install npm packages with Bun, please use an import statement instead of require() or dynamic import().\nThis error can also happen if dependencies import packages which are not referenced anywhere. Worst case, run `bun install` and opt-out of the node_modules folder until we come up with a better way to handle this error.", .{specifier.slice()}) catch unreachable, ), }; } break :brk logger.Msg{ - .data = logger.rangeData(null, logger.Range.None, std.fmt.allocPrint(vm.allocator, "{s} while building {s}", .{ @errorName(err), specifier.slice() }) catch unreachable), + .data = logger.rangeData(null, logger.Range.None, std.fmt.allocPrint(globalThis.allocator(), "{s} while building {s}", .{ @errorName(err), specifier.slice() }) catch unreachable), }; }; { - ret.* = ErrorableResolvedSource.err(err, @ptrCast(*anyopaque, BuildError.create(globalThis, vm.bundler.allocator, msg))); + ret.* = ErrorableResolvedSource.err(err, @ptrCast(*anyopaque, BuildError.create(globalThis, globalThis.allocator(), msg))); } return; }, @@ -1189,10 +1193,10 @@ pub const VirtualMachine = struct { 1 => { const msg = log.msgs.items[0]; ret.* = ErrorableResolvedSource.err(err, switch (msg.metadata) { - .build => BuildError.create(globalThis, vm.bundler.allocator, msg).?, + .build => BuildError.create(globalThis, globalThis.allocator(), msg).?, .resolve => ResolveError.create( globalThis, - vm.bundler.allocator, + globalThis.allocator(), msg, referrer.slice(), ).?, @@ -1202,14 +1206,14 @@ pub const VirtualMachine = struct { else => { var errors_stack: [256]*anyopaque = undefined; - var errors = errors_stack[0..@minimum(log.msgs.items.len, errors_stack.len)]; + var errors = errors_stack[0..@min(log.msgs.items.len, errors_stack.len)]; for (log.msgs.items) |msg, i| { errors[i] = switch (msg.metadata) { - .build => BuildError.create(globalThis, vm.bundler.allocator, msg).?, + .build => BuildError.create(globalThis, globalThis.allocator(), msg).?, .resolve => ResolveError.create( globalThis, - vm.bundler.allocator, + globalThis.allocator(), msg, referrer.slice(), ).?, @@ -1222,7 +1226,7 @@ pub const VirtualMachine = struct { errors.ptr, @intCast(u16, errors.len), &ZigString.init( - std.fmt.allocPrint(vm.bundler.allocator, "{d} errors building \"{s}\"", .{ + std.fmt.allocPrint(globalThis.allocator(), "{d} errors building \"{s}\"", .{ errors.len, specifier.slice(), }) catch unreachable, @@ -1378,7 +1382,7 @@ pub const VirtualMachine = struct { path: string, promise: *JSInternalPromise = undefined, pub fn load(this: *MacroEntryPointLoader) void { - this.promise = vm._loadMacroEntryPoint(this.path); + this.promise = VirtualMachine.get()._loadMacroEntryPoint(this.path); } }; @@ -1448,7 +1452,7 @@ pub const VirtualMachine = struct { } inline fn iterator(_: [*c]VM, _: [*c]JSGlobalObject, nextValue: JSValue, ctx: ?*anyopaque, comptime color: bool) void { var this_ = @intToPtr(*@This(), @ptrToInt(ctx)); - VirtualMachine.vm.printErrorlikeObject(nextValue, null, this_.current_exception_list, Writer, this_.writer, color); + VirtualMachine.get().printErrorlikeObject(nextValue, null, this_.current_exception_list, Writer, this_.writer, color); } }; var iter = AggregateErrorIterator{ .writer = writer, .current_exception_list = exception_list }; @@ -1554,6 +1558,7 @@ pub const VirtualMachine = struct { pub fn printStackTrace(comptime Writer: type, writer: Writer, trace: ZigStackTrace, comptime allow_ansi_colors: bool) !void { const stack = trace.frames(); if (stack.len > 0) { + var vm = VirtualMachine.get(); var i: i16 = 0; const origin: ?*const URL = if (vm.is_from_devserver) &vm.origin else null; const dir = vm.bundler.fs.top_level_dir; @@ -1616,8 +1621,8 @@ pub const VirtualMachine = struct { if (frames[i].position.isInvalid()) continue; if (this.source_mappings.resolveMapping( frames[i].source_url.slice(), - @maximum(frames[i].position.line, 0), - @maximum(frames[i].position.column_start, 0), + @max(frames[i].position.line, 0), + @max(frames[i].position.column_start, 0), )) |mapping| { frames[i].position.line = mapping.original.lines; frames[i].position.column_start = mapping.original.columns; @@ -1674,8 +1679,8 @@ pub const VirtualMachine = struct { var top = &frames[0]; if (this.source_mappings.resolveMapping( top.source_url.slice(), - @maximum(top.position.line, 0), - @maximum(top.position.column_start, 0), + @max(top.position.line, 0), + @max(top.position.column_start, 0), )) |mapping| { var log = logger.Log.init(default_allocator); var errorable: ErrorableResolvedSource = undefined; @@ -1702,7 +1707,7 @@ pub const VirtualMachine = struct { std.mem.set(ZigString, source_lines, ZigString.Empty); std.mem.set(i32, source_line_numbers, 0); - var lines_ = lines[0..@minimum(lines.len, source_lines.len)]; + var lines_ = lines[0..@min(lines.len, source_lines.len)]; for (lines_) |line, j| { source_lines[(lines_.len - 1) - j] = ZigString.init(line); source_line_numbers[j] = top.position.line - @intCast(i32, j) + 1; @@ -1724,8 +1729,8 @@ pub const VirtualMachine = struct { if (frame.position.isInvalid()) continue; if (this.source_mappings.resolveMapping( frame.source_url.slice(), - @maximum(frame.position.line, 0), - @maximum(frame.position.column_start, 0), + @max(frame.position.line, 0), + @max(frame.position.column_start, 0), )) |mapping| { frame.position.line = mapping.original.lines; frame.remapped = true; @@ -1743,7 +1748,7 @@ pub const VirtualMachine = struct { var line_numbers = exception.stack.source_lines_numbers[0..exception.stack.source_lines_len]; var max_line: i32 = -1; - for (line_numbers) |line| max_line = @maximum(max_line, line); + for (line_numbers) |line| max_line = @max(max_line, line); const max_line_number_pad = std.fmt.count("{d}", .{max_line}); var source_lines = exception.stack.sourceLineIterator(); @@ -1942,14 +1947,14 @@ pub const VirtualMachine = struct { } }; -const GetterFn = fn ( +const GetterFn = *const fn ( this: anytype, ctx: js.JSContextRef, thisObject: js.JSValueRef, prop: js.JSStringRef, exception: js.ExceptionRef, ) js.JSValueRef; -const SetterFn = fn ( +const SetterFn = *const fn ( this: anytype, ctx: js.JSContextRef, thisObject: js.JSValueRef, @@ -2071,10 +2076,10 @@ pub const EventListenerMixin = struct { defer name_slice.deinit(); const name = name_slice.slice(); const event = EventType.match(name) orelse return js.JSValueMakeUndefined(ctx); - var entry = VirtualMachine.vm.event_listeners.getOrPut(event) catch unreachable; + var entry = VirtualMachine.get().event_listeners.getOrPut(event) catch unreachable; if (!entry.found_existing) { - entry.value_ptr.* = List.initCapacity(VirtualMachine.vm.allocator, 1) catch unreachable; + entry.value_ptr.* = List.initCapacity(VirtualMachine.get().allocator, 1) catch unreachable; } var callback = arguments[arguments.len - 1]; @@ -2092,7 +2097,7 @@ pub const EventListenerMixin = struct { .read_only = true, }, .{ - .@"callAsFunction" = .{ + .callAsFunction = .{ .rfn = Handler.addListener, }, }, @@ -2177,35 +2182,35 @@ pub const ResolveError = struct { }, .{ .toString = .{ .rfn = toString }, - .convertToType = .{ .rfn = convertToType }, + .convertToType = .{ .rfn = &convertToType }, }, .{ - .@"referrer" = .{ - .@"get" = getReferrer, + .referrer = .{ + .get = getReferrer, .ro = true, }, - .@"code" = .{ - .@"get" = getCode, + .code = .{ + .get = getCode, .ro = true, }, - .@"message" = .{ - .@"get" = getMessage, + .message = .{ + .get = getMessage, .ro = true, }, - .@"name" = .{ - .@"get" = getName, + .name = .{ + .get = getName, .ro = true, }, - .@"specifier" = .{ - .@"get" = getSpecifier, + .specifier = .{ + .get = getSpecifier, .ro = true, }, - .@"importKind" = .{ - .@"get" = getImportKind, + .importKind = .{ + .get = getImportKind, .ro = true, }, - .@"position" = .{ - .@"get" = getPosition, + .position = .{ + .get = getPosition, .ro = true, }, }, @@ -2325,17 +2330,17 @@ pub const BuildError = struct { .toString = .{ .rfn = toString }, }, .{ - .@"message" = .{ - .@"get" = getMessage, + .message = .{ + .get = getMessage, .ro = true, }, - .@"name" = .{ - .@"get" = getName, + .name = .{ + .get = getName, .ro = true, }, // This is called "position" instead of "location" because "location" may be confused with Location. - .@"position" = .{ - .@"get" = getPosition, + .position = .{ + .get = getPosition, .ro = true, }, }, @@ -2534,7 +2539,7 @@ pub const HotReloader = struct { javascript_callback: JSC.Strong, zig_callback: struct { ptr: *anyopaque, - function: FunctionSignature, + function: *const FunctionSignature, }, }; } diff --git a/src/bun.js/javascript_core_c_api.zig b/src/bun.js/javascript_core_c_api.zig index 13e96f22a..dd2efd014 100644 --- a/src/bun.js/javascript_core_c_api.zig +++ b/src/bun.js/javascript_core_c_api.zig @@ -3,7 +3,7 @@ const std = @import("std"); const cpp = @import("./bindings/bindings.zig"); const generic = opaque { pub fn value(this: *const @This()) cpp.JSValue { - return @bitCast(cpp.JSValue.Type, @ptrToInt(this)); + return @intToEnum(cpp.JSValue, @bitCast(cpp.JSValue.Type, @ptrToInt(this))); } pub inline fn bunVM(this: *@This()) *@import("bun").JSC.VirtualMachine { @@ -66,8 +66,8 @@ pub const OpaqueJSString = opaque { if (zig_str.isUTF8()) { return JSValueToStringCopy( - bun.JSC.VirtualMachine.vm.global, - zig_str.toValueGC(bun.JSC.VirtualMachine.vm.global).asObjectRef(), + bun.JSC.VirtualMachine.get().global, + zig_str.toValueGC(bun.JSC.VirtualMachine.get().global).asObjectRef(), null, ); } @@ -98,7 +98,7 @@ pub const JSPropertyNameArray = opaque { pub const JSPropertyNameArrayRef = ?*JSPropertyNameArray; pub const struct_OpaqueJSPropertyNameAccumulator = generic; pub const JSPropertyNameAccumulatorRef = ?*struct_OpaqueJSPropertyNameAccumulator; -pub const JSTypedArrayBytesDeallocator = ?fn (*anyopaque, *anyopaque) callconv(.C) void; +pub const JSTypedArrayBytesDeallocator = ?*const fn (*anyopaque, *anyopaque) callconv(.C) void; pub const OpaqueJSValue = generic; pub const JSValueRef = ?*OpaqueJSValue; pub const JSObjectRef = ?*OpaqueJSValue; @@ -218,15 +218,15 @@ pub const JSClassAttributes = enum(c_uint) { pub const kJSClassAttributeNone = @enumToInt(JSClassAttributes.kJSClassAttributeNone); pub const kJSClassAttributeNoAutomaticPrototype = @enumToInt(JSClassAttributes.kJSClassAttributeNoAutomaticPrototype); -pub const JSObjectInitializeCallback = ?fn (JSContextRef, JSObjectRef) callconv(.C) void; -pub const JSObjectFinalizeCallback = ?fn (JSObjectRef) callconv(.C) void; -pub const JSObjectHasPropertyCallback = ?fn (JSContextRef, JSObjectRef, JSStringRef) callconv(.C) bool; -pub const JSObjectGetPropertyCallback = ?fn (JSContextRef, JSObjectRef, JSStringRef, ExceptionRef) callconv(.C) JSValueRef; -pub const JSObjectSetPropertyCallback = ?fn (JSContextRef, JSObjectRef, JSStringRef, JSValueRef, ExceptionRef) callconv(.C) bool; -pub const JSObjectDeletePropertyCallback = ?fn (JSContextRef, JSObjectRef, JSStringRef, ExceptionRef) callconv(.C) bool; -pub const JSObjectGetPropertyNamesCallback = ?fn (JSContextRef, JSObjectRef, JSPropertyNameAccumulatorRef) callconv(.C) void; +pub const JSObjectInitializeCallback = *const fn (JSContextRef, JSObjectRef) callconv(.C) void; +pub const JSObjectFinalizeCallback = *const fn (JSObjectRef) callconv(.C) void; +pub const JSObjectHasPropertyCallback = *const fn (JSContextRef, JSObjectRef, JSStringRef) callconv(.C) bool; +pub const JSObjectGetPropertyCallback = *const fn (JSContextRef, JSObjectRef, JSStringRef, ExceptionRef) callconv(.C) JSValueRef; +pub const JSObjectSetPropertyCallback = *const fn (JSContextRef, JSObjectRef, JSStringRef, JSValueRef, ExceptionRef) callconv(.C) bool; +pub const JSObjectDeletePropertyCallback = *const fn (JSContextRef, JSObjectRef, JSStringRef, ExceptionRef) callconv(.C) bool; +pub const JSObjectGetPropertyNamesCallback = *const fn (JSContextRef, JSObjectRef, JSPropertyNameAccumulatorRef) callconv(.C) void; pub const ExceptionRef = [*c]JSValueRef; -pub const JSObjectCallAsFunctionCallback = ?fn ( +pub const JSObjectCallAsFunctionCallback = *const fn ( ctx: JSContextRef, function: JSObjectRef, thisObject: JSObjectRef, @@ -234,38 +234,38 @@ pub const JSObjectCallAsFunctionCallback = ?fn ( arguments: [*c]const JSValueRef, exception: ExceptionRef, ) callconv(.C) JSValueRef; -pub const JSObjectCallAsConstructorCallback = ?fn (JSContextRef, JSObjectRef, usize, [*c]const JSValueRef, ExceptionRef) callconv(.C) JSObjectRef; -pub const JSObjectHasInstanceCallback = ?fn (JSContextRef, JSObjectRef, JSValueRef, ExceptionRef) callconv(.C) bool; -pub const JSObjectConvertToTypeCallback = ?fn (JSContextRef, JSObjectRef, JSType, 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 JSStaticValue = extern struct { - name: [*c]const u8, - getProperty: JSObjectGetPropertyCallback, - setProperty: JSObjectSetPropertyCallback, - attributes: JSPropertyAttributes, + name: [*c]const u8 = null, + getProperty: ?JSObjectGetPropertyCallback = null, + setProperty: ?JSObjectSetPropertyCallback = null, + attributes: JSPropertyAttributes = .kJSPropertyAttributeNone, }; pub const JSStaticFunction = extern struct { - name: [*c]const u8, - callAsFunction: JSObjectCallAsFunctionCallback, - attributes: JSPropertyAttributes, + name: [*c]const u8 = null, + callAsFunction: ?JSObjectCallAsFunctionCallback = null, + attributes: JSPropertyAttributes = .kJSPropertyAttributeNone, }; pub const JSClassDefinition = extern struct { - version: c_int, - attributes: JSClassAttributes, - className: [*c]const u8, - parentClass: JSClassRef, - staticValues: [*c]const JSStaticValue, - staticFunctions: [*c]const JSStaticFunction, - initialize: JSObjectInitializeCallback, - finalize: JSObjectFinalizeCallback, - hasProperty: JSObjectHasPropertyCallback, - getProperty: JSObjectGetPropertyCallback, - setProperty: JSObjectSetPropertyCallback, - deleteProperty: JSObjectDeletePropertyCallback, - getPropertyNames: JSObjectGetPropertyNamesCallback, - callAsFunction: JSObjectCallAsFunctionCallback, - callAsConstructor: JSObjectCallAsConstructorCallback, - hasInstance: JSObjectHasInstanceCallback, - convertToType: JSObjectConvertToTypeCallback, + version: c_int = 0, + attributes: JSClassAttributes = .kJSClassAttributeNone, + className: [*:0]const u8 = "", + parentClass: JSClassRef = null, + staticValues: [*c]const JSStaticValue = null, + staticFunctions: [*c]const JSStaticFunction = null, + initialize: ?JSObjectInitializeCallback = null, + finalize: ?JSObjectFinalizeCallback = null, + hasProperty: ?JSObjectHasPropertyCallback = null, + getProperty: ?JSObjectGetPropertyCallback = null, + setProperty: ?JSObjectSetPropertyCallback = null, + deleteProperty: ?JSObjectDeletePropertyCallback = null, + getPropertyNames: ?JSObjectGetPropertyNamesCallback = null, + callAsFunction: ?JSObjectCallAsFunctionCallback = null, + callAsConstructor: ?JSObjectCallAsConstructorCallback = null, + hasInstance: ?JSObjectHasInstanceCallback = null, + convertToType: ?JSObjectConvertToTypeCallback = null, }; pub extern const kJSClassDefinitionEmpty: JSClassDefinition; pub extern "c" fn JSClassCreate(definition: [*c]const JSClassDefinition) JSClassRef; @@ -486,7 +486,7 @@ pub const CellType = enum(u8) { }; } }; -pub const ExternalStringFinalizer = fn (finalize_ptr: ?*anyopaque, ref: JSStringRef, buffer: *anyopaque, byteLength: usize) callconv(.C) void; +pub const ExternalStringFinalizer = *const fn (finalize_ptr: ?*anyopaque, ref: JSStringRef, buffer: *anyopaque, byteLength: usize) callconv(.C) void; pub extern fn JSStringCreate(string: UTF8Ptr, length: usize) JSStringRef; pub extern fn JSStringCreateStatic(string: UTF8Ptr, length: usize) JSStringRef; pub extern fn JSStringCreateExternal(string: UTF8Ptr, length: usize, finalize_ptr: ?*anyopaque, finalizer: ExternalStringFinalizer) JSStringRef; @@ -497,8 +497,8 @@ pub extern fn JSCellType(cell: JSCellValue) CellType; pub extern fn JSStringIsStatic(ref: JSStringRef) bool; pub extern fn JSStringIsExternal(ref: JSStringRef) bool; -pub const JStringIteratorAppendCallback = fn (ctx: *JSStringIterator_, ptr: *anyopaque, length: u32) callconv(.C) anyopaque; -pub const JStringIteratorWriteCallback = fn (ctx: *JSStringIterator_, ptr: *anyopaque, length: u32, offset: u32) callconv(.C) anyopaque; +pub const JStringIteratorAppendCallback = *const fn (ctx: *JSStringIterator_, ptr: *anyopaque, length: u32) callconv(.C) anyopaque; +pub const JStringIteratorWriteCallback = *const fn (ctx: *JSStringIterator_, ptr: *anyopaque, length: u32, offset: u32) callconv(.C) anyopaque; const JSStringIterator_ = extern struct { ctx: *anyopaque, stop: u8, diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index 85db973ce..f9379e107 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -88,12 +88,11 @@ const PackageManager = @import("../install/install.zig").PackageManager; const Install = @import("../install/install.zig"); const VirtualMachine = JSC.VirtualMachine; const Dependency = @import("../install/dependency.zig"); - // This exists to make it so we can reload these quicker in development fn jsModuleFromFile(from_path: string, comptime input: string) string { - const absolute_path = comptime std.fs.path.dirname(@src().file).? ++ "/" ++ input; + const absolute_path = comptime (bun.Environment.base_path ++ std.fs.path.dirname(@src().file).?) ++ "/" ++ input; const Holder = struct { - pub const file = @embedFile(absolute_path); + pub const file = @embedFile(input); }; if (comptime !Environment.allow_assert) { @@ -152,18 +151,18 @@ inline fn jsSyntheticModule(comptime name: ResolvedSource.Tag) ResolvedSource { fn dumpSource(specifier: string, printer: anytype) !void { const BunDebugHolder = struct { - pub var dir: ?std.fs.Dir = null; + pub var dir: ?std.fs.IterableDir = null; }; if (BunDebugHolder.dir == null) { - BunDebugHolder.dir = try std.fs.cwd().makeOpenPath("/tmp/bun-debug-src/", .{ .iterate = true }); + BunDebugHolder.dir = try std.fs.cwd().makeOpenPathIterable("/tmp/bun-debug-src/", .{}); } if (std.fs.path.dirname(specifier)) |dir_path| { - var parent = try BunDebugHolder.dir.?.makeOpenPath(dir_path[1..], .{ .iterate = true }); + var parent = try BunDebugHolder.dir.?.dir.makeOpenPathIterable(dir_path[1..], .{}); defer parent.close(); - try parent.writeFile(std.fs.path.basename(specifier), printer.ctx.getWritten()); + try parent.dir.writeFile(std.fs.path.basename(specifier), printer.ctx.getWritten()); } else { - try BunDebugHolder.dir.?.writeFile(std.fs.path.basename(specifier), printer.ctx.getWritten()); + try BunDebugHolder.dir.?.dir.writeFile(std.fs.path.basename(specifier), printer.ctx.getWritten()); } } @@ -772,7 +771,7 @@ pub const ModuleLoader = struct { debug("resumeLoadingModule: {s}", .{this.specifier}); var parse_result = this.parse_result; var path = this.path; - var jsc_vm = JSC.VirtualMachine.vm; + var jsc_vm = JSC.VirtualMachine.get(); var specifier = this.specifier; var old_log = jsc_vm.log; @@ -1451,7 +1450,7 @@ pub const ModuleLoader = struct { const after_namespace = if (namespace.len == 0) specifier else - specifier[@minimum(namespace.len + 1, specifier.len)..]; + specifier[@min(namespace.len + 1, specifier.len)..]; return globalObject.runOnLoadPlugins(ZigString.init(namespace), ZigString.init(after_namespace), .bun) orelse return JSValue.zero; } @@ -1755,7 +1754,7 @@ pub const ModuleLoader = struct { .hash = 0, }; }, - .@"ws" => { + .ws => { return ResolvedSource{ .allocator = null, .source_code = ZigString.init( @@ -1821,7 +1820,7 @@ pub const ModuleLoader = struct { .hash = 0, }; }, - .@"undici" => { + .undici => { return ResolvedSource{ .allocator = null, .source_code = ZigString.init( @@ -1854,7 +1853,7 @@ pub const ModuleLoader = struct { .hash = 0, }; }, - .@"depd" => { + .depd => { return ResolvedSource{ .allocator = null, .source_code = ZigString.init( @@ -1970,7 +1969,7 @@ pub const HardcodedModule = enum { @"bun:jsc", @"bun:main", @"bun:sqlite", - @"depd", + depd, @"detect-libc", @"node:assert", @"node:buffer", @@ -1998,8 +1997,8 @@ pub const HardcodedModule = enum { @"node:url", @"node:util", @"node:util/types", - @"undici", - @"ws", + undici, + ws, /// Already resolved modules go in here. /// This does not remap the module name, it is just a hash table. /// Do not put modules that have aliases in here @@ -2012,7 +2011,7 @@ pub const HardcodedModule = enum { .{ "bun:jsc", HardcodedModule.@"bun:jsc" }, .{ "bun:main", HardcodedModule.@"bun:main" }, .{ "bun:sqlite", HardcodedModule.@"bun:sqlite" }, - .{ "depd", HardcodedModule.@"depd" }, + .{ "depd", HardcodedModule.depd }, .{ "detect-libc", HardcodedModule.@"detect-libc" }, .{ "node:assert", HardcodedModule.@"node:assert" }, .{ "node:buffer", HardcodedModule.@"node:buffer" }, @@ -2040,8 +2039,8 @@ pub const HardcodedModule = enum { .{ "node:url", HardcodedModule.@"node:url" }, .{ "node:util", HardcodedModule.@"node:util" }, .{ "node:util/types", HardcodedModule.@"node:util/types" }, - .{ "undici", HardcodedModule.@"undici" }, - .{ "ws", HardcodedModule.@"ws" }, + .{ "undici", HardcodedModule.undici }, + .{ "ws", HardcodedModule.ws }, }, ); pub const Aliases = bun.ComptimeStringMap( diff --git a/src/bun.js/node/buffer.zig b/src/bun.js/node/buffer.zig index b796109e3..5637e45b6 100644 --- a/src/bun.js/node/buffer.zig +++ b/src/bun.js/node/buffer.zig @@ -77,7 +77,7 @@ pub const BufferVectorized = struct { const minimum_contents = contents; while (buf.len >= contents.len) { - const min_len = @minimum(contents.len, buf.len); + const min_len = @min(contents.len, buf.len); std.mem.copy(u8, buf[0..min_len], contents[0..min_len]); if (buf.len <= contents.len) { break; @@ -87,7 +87,7 @@ pub const BufferVectorized = struct { } while (buf.len > 0) { - const to_fill = @minimum(minimum_contents.len, buf.len); + const to_fill = @min(minimum_contents.len, buf.len); std.mem.copy(u8, buf[0..to_fill], minimum_contents[0..to_fill]); buf = buf[to_fill..]; } diff --git a/src/bun.js/node/dir_iterator.zig b/src/bun.js/node/dir_iterator.zig index c309e0d67..7db7facc7 100644 --- a/src/bun.js/node/dir_iterator.zig +++ b/src/bun.js/node/dir_iterator.zig @@ -1,4 +1,4 @@ -// This is copied from std.fs.Dir.Iterator +// This is copied from std.fs.IterableDir.Iterator // The differences are: // - it returns errors in the expected format // - doesn't mark BADF as unreachable @@ -19,7 +19,7 @@ const Maybe = JSC.Maybe; const File = std.fs.File; const Result = Maybe(?Entry); -const Entry = JSC.Node.DirEnt; +const Entry = JSC.Node.Dirent; pub const Iterator = switch (builtin.os.tag) { .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris => struct { diff --git a/src/bun.js/node/node.classes.ts b/src/bun.js/node/node.classes.ts new file mode 100644 index 000000000..355b5847e --- /dev/null +++ b/src/bun.js/node/node.classes.ts @@ -0,0 +1,156 @@ +import { define } from "../scripts/class-definitions"; + +export default [ + define({ + name: "Dirent", + construct: true, + finalize: true, + + klass: {}, + + proto: { + isBlockDevice: { + fn: "isBlockDevice", + length: 0, + }, + isCharacterDevice: { + fn: "isCharacterDevice", + length: 0, + }, + isDirectory: { + fn: "isDirectory", + length: 0, + }, + isFIFO: { + fn: "isFIFO", + length: 0, + }, + isFile: { + fn: "isFile", + length: 0, + }, + isSocket: { + fn: "isSocket", + length: 0, + }, + isSymbolicLink: { + fn: "isSymbolicLink", + length: 0, + }, + name: { + getter: "getName", + cache: true, + }, + }, + }), + define({ + name: "NodeJSFS", + construct: true, + finalize: false, + + klass: {}, + proto: { + appendFile: { fn: "appendFile", length: 4 }, + appendFileSync: { fn: "appendFileSync", length: 3 }, + access: { fn: "access", length: 3 }, + accessSync: { fn: "accessSync", length: 2 }, + chown: { fn: "chown", length: 4 }, + chownSync: { fn: "chownSync", length: 3 }, + chmod: { fn: "chmod", length: 3 }, + chmodSync: { fn: "chmodSync", length: 2 }, + close: { fn: "close", length: 1 }, + closeSync: { fn: "closeSync", length: 1 }, + copyFile: { fn: "copyFile", length: 4 }, + copyFileSync: { fn: "copyFileSync", length: 3 }, + + // TODO: + // cp: { fn: "cp", length: 4 }, + // cpSync: { fn: "cpSync", length: 3 }, + + exists: { fn: "exists", length: 2 }, + existsSync: { fn: "existsSync", length: 1 }, + fchown: { fn: "fchown", length: 4 }, + fchownSync: { fn: "fchownSync", length: 3 }, + fchmod: { fn: "fchmod", length: 3 }, + fchmodSync: { fn: "fchmodSync", length: 2 }, + fdatasync: { fn: "fdatasync", length: 2 }, + fdatasyncSync: { fn: "fdatasyncSync", length: 1 }, + fstat: { fn: "fstat", length: 1 }, + fstatSync: { fn: "fstatSync", length: 1 }, + fsync: { fn: "fsync", length: 2 }, + fsyncSync: { fn: "fsyncSync", length: 1 }, + ftruncate: { fn: "ftruncate", length: 1 }, + ftruncateSync: { fn: "ftruncateSync", length: 1 }, + futimes: { fn: "futimes", length: 4 }, + futimesSync: { fn: "futimesSync", length: 3 }, + lchown: { fn: "lchown", length: 4 }, + lchownSync: { fn: "lchownSync", length: 3 }, + lchmod: { fn: "lchmod", length: 3 }, + lchmodSync: { fn: "lchmodSync", length: 2 }, + link: { fn: "link", length: 3 }, + linkSync: { fn: "linkSync", length: 2 }, + lstat: { fn: "lstat", length: 1 }, + lstatSync: { fn: "lstatSync", length: 1 }, + lutimes: { fn: "lutimes", length: 4 }, + lutimesSync: { fn: "lutimesSync", length: 3 }, + mkdir: { fn: "mkdir", length: 3 }, + mkdirSync: { fn: "mkdirSync", length: 2 }, + mkdtemp: { fn: "mkdtemp", length: 3 }, + mkdtempSync: { fn: "mkdtempSync", length: 2 }, + open: { fn: "open", length: 4 }, + openSync: { fn: "openSync", length: 3 }, + opendir: { fn: "opendir", length: 3 }, + opendirSync: { fn: "opendirSync", length: 2 }, + readdir: { fn: "readdir", length: 3 }, + readdirSync: { fn: "readdirSync", length: 2 }, + read: { fn: "read", length: 6 }, + readSync: { fn: "readSync", length: 5 }, + readv: { fn: "readv", length: 4 }, + readvSync: { fn: "readvSync", length: 3 }, + readFile: { fn: "readFile", length: 3 }, + readFileSync: { fn: "readFileSync", length: 2 }, + readlink: { fn: "readlink", length: 3 }, + readlinkSync: { fn: "readlinkSync", length: 2 }, + realpath: { fn: "realpath", length: 3 }, + realpathSync: { fn: "realpathSync", length: 2 }, + rename: { fn: "rename", length: 3 }, + renameSync: { fn: "renameSync", length: 2 }, + rm: { fn: "rm", length: 3 }, + rmSync: { fn: "rmSync", length: 2 }, + rmdir: { fn: "rmdir", length: 3 }, + rmdirSync: { fn: "rmdirSync", length: 2 }, + stat: { fn: "stat", length: 1 }, + statSync: { fn: "statSync", length: 1 }, + symlink: { fn: "symlink", length: 4 }, + symlinkSync: { fn: "symlinkSync", length: 3 }, + truncate: { fn: "truncate", length: 3 }, + truncateSync: { fn: "truncateSync", length: 2 }, + // TODO: + // unwatchFile: { fn: "unwatchFile", length: 2 }, + unlink: { fn: "unlink", length: 2 }, + unlinkSync: { fn: "unlinkSync", length: 1 }, + utimes: { fn: "utimes", length: 4 }, + utimesSync: { fn: "utimesSync", length: 3 }, + // TODO: + // watch: { fn: "watch", length: 3 }, + // watchFile: { fn: "watchFile", length: 3 }, + writeFile: { fn: "writeFile", length: 4 }, + writeFileSync: { fn: "writeFileSync", length: 3 }, + write: { fn: "write", length: 6 }, + writeSync: { fn: "writeSync", length: 5 }, + writev: { fn: "writev", length: 4 }, + writevSync: { fn: "writevSync", length: 3 }, + // TODO: + // Dir: { fn: 'Dir', length: 3 }, + Dirent: { getter: "getDirent" }, + // Stats: { fn: 'Stats', length: 14 }, + // ReadStream: { fn: 'ReadStream', length: 2 }, + // WriteStream: { fn: 'WriteStream', length: 2 }, + // FileReadStream: { fn: 'FileReadStream', length: 2 }, + // FileWriteStream: { fn: 'FileWriteStream', length: 2 }, + // _toUnixTimestamp: { fn: '_toUnixTimestamp', length: 1 } + // createReadStream: { fn: "createReadStream", length: 2 }, + // createWriteStream: { fn: "createWriteStream", length: 2 }, + }, + }), +]; diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index 75b50efed..5f36532ca 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -40,7 +40,7 @@ const ReadPosition = u63; const Stats = JSC.Node.Stats; const BigIntStats = JSC.Node.BigIntStats; -const DirEnt = JSC.Node.DirEnt; +const Dirent = JSC.Node.Dirent; pub const FlavoredIO = struct { io: *AsyncIO, @@ -993,7 +993,7 @@ const Arguments = struct { pub const Open = struct { path: PathLike, - flags: FileSystemFlags = FileSystemFlags.@"r", + flags: FileSystemFlags = FileSystemFlags.r, mode: Mode = default_permission, pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, exception: JSC.C.ExceptionRef) ?Open { @@ -1011,7 +1011,7 @@ const Arguments = struct { if (exception.* != null) return null; - var flags = FileSystemFlags.@"r"; + var flags = FileSystemFlags.r; var mode: Mode = default_permission; if (arguments.next()) |val| { @@ -1445,7 +1445,7 @@ const Arguments = struct { path: PathOrFileDescriptor, encoding: Encoding = Encoding.utf8, - flag: FileSystemFlags = FileSystemFlags.@"r", + flag: FileSystemFlags = FileSystemFlags.r, pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, exception: JSC.C.ExceptionRef) ?ReadFile { const path = PathOrFileDescriptor.fromJS(ctx, arguments, arguments.arena.allocator(), exception) orelse { @@ -1463,7 +1463,7 @@ const Arguments = struct { if (exception.* != null) return null; var encoding = Encoding.buffer; - var flag = FileSystemFlags.@"r"; + var flag = FileSystemFlags.r; if (arguments.next()) |arg| { arguments.eat(); @@ -1523,8 +1523,8 @@ const Arguments = struct { pub const WriteFile = struct { encoding: Encoding = Encoding.utf8, - flag: FileSystemFlags = FileSystemFlags.@"w", - mode: Mode = 0666, + flag: FileSystemFlags = FileSystemFlags.w, + mode: Mode = 0o666, file: PathOrFileDescriptor, data: StringOrBuffer, @@ -1569,7 +1569,7 @@ const Arguments = struct { arguments.eat(); var encoding = Encoding.buffer; - var flag = FileSystemFlags.@"w"; + var flag = FileSystemFlags.w; var mode: Mode = default_permission; if (arguments.next()) |arg| { @@ -1752,7 +1752,7 @@ const Arguments = struct { pub const Access = struct { path: PathLike, - mode: FileSystemFlags = FileSystemFlags.@"r", + mode: FileSystemFlags = FileSystemFlags.r, pub fn fromJS(ctx: JSC.C.JSContextRef, arguments: *ArgumentsSlice, exception: JSC.C.ExceptionRef) ?Access { const path = PathLike.fromJS(ctx, arguments, exception) orelse { @@ -1769,7 +1769,7 @@ const Arguments = struct { if (exception.* != null) return null; - var mode = FileSystemFlags.@"r"; + var mode = FileSystemFlags.r; if (arguments.next()) |arg| { arguments.eat(); @@ -1797,7 +1797,7 @@ const Arguments = struct { pub const CreateReadStream = struct { file: PathOrFileDescriptor, - flags: FileSystemFlags = FileSystemFlags.@"r", + flags: FileSystemFlags = FileSystemFlags.r, encoding: Encoding = Encoding.utf8, mode: Mode = default_permission, autoClose: bool = true, @@ -1932,7 +1932,7 @@ const Arguments = struct { pub const CreateWriteStream = struct { file: PathOrFileDescriptor, - flags: FileSystemFlags = FileSystemFlags.@"w", + flags: FileSystemFlags = FileSystemFlags.w, encoding: Encoding = Encoding.utf8, mode: Mode = default_permission, autoClose: bool = true, @@ -2153,7 +2153,7 @@ const Arguments = struct { }; pub const Copy = struct { - pub const FilterCallback = fn (source: string, destination: string) bool; + pub const FilterCallback = *const fn (source: string, destination: string) bool; /// Dereference symlinks /// @default false dereference: bool = false, @@ -2255,8 +2255,8 @@ const Return = struct { bytes_read: u52, buffer_val: JSC.JSValue = JSC.JSValue.zero, const fields = .{ - .@"bytesRead" = JSC.ZigString.init("bytesRead"), - .@"buffer" = JSC.ZigString.init("buffer"), + .bytesRead = JSC.ZigString.init("bytesRead"), + .buffer = JSC.ZigString.init("buffer"), }; pub fn toJS(this: Read, ctx: JSC.C.JSContextRef, _: JSC.C.ExceptionRef) JSC.C.JSValueRef { defer if (!this.buffer_val.isEmptyOrUndefinedOrNull()) @@ -2266,7 +2266,7 @@ const Return = struct { ctx.ptr(), &fields.bytesRead, &fields.buffer, - JSC.JSValue.jsNumberFromUint64(@intCast(u52, @minimum(std.math.maxInt(u52), this.bytes_read))), + JSC.JSValue.jsNumberFromUint64(@intCast(u52, @min(std.math.maxInt(u52), this.bytes_read))), this.buffer_val, ).asObjectRef(); } @@ -2277,8 +2277,8 @@ const Return = struct { buffer: StringOrBuffer, buffer_val: JSC.JSValue = JSC.JSValue.zero, const fields = .{ - .@"bytesWritten" = JSC.ZigString.init("bytesWritten"), - .@"buffer" = JSC.ZigString.init("buffer"), + .bytesWritten = JSC.ZigString.init("bytesWritten"), + .buffer = JSC.ZigString.init("buffer"), }; // Excited for the issue that's like "cannot read file bigger than 2 GB" @@ -2290,7 +2290,7 @@ const Return = struct { ctx.ptr(), &fields.bytesWritten, &fields.buffer, - JSC.JSValue.jsNumberFromUint64(@intCast(u52, @minimum(std.math.maxInt(u52), this.bytes_written))), + JSC.JSValue.jsNumberFromUint64(@intCast(u52, @min(std.math.maxInt(u52), this.bytes_written))), if (this.buffer == .buffer) this.buffer_val else @@ -2301,7 +2301,7 @@ const Return = struct { pub const Write = struct { bytes_written: u52, const fields = .{ - .@"bytesWritten" = JSC.ZigString.init("bytesWritten"), + .bytesWritten = JSC.ZigString.init("bytesWritten"), }; // Excited for the issue that's like "cannot read file bigger than 2 GB" @@ -2311,7 +2311,7 @@ const Return = struct { }; pub const Readdir = union(Tag) { - with_file_types: []const DirEnt, + with_file_types: []Dirent, buffers: []const Buffer, files: []const PathString, @@ -2323,7 +2323,7 @@ const Return = struct { pub fn toJS(this: Readdir, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef { return switch (this) { - .with_file_types => JSC.To.JS.withType([]const DirEnt, this.with_file_types, ctx, exception), + .with_file_types => JSC.To.JS.withType([]const Dirent, this.with_file_types, ctx, exception), .buffers => JSC.To.JS.withType([]const Buffer, this.buffers, ctx, exception), .files => JSC.To.JS.withTypeClone([]const PathString, this.files, ctx, exception, true), }; @@ -2386,7 +2386,6 @@ pub const NodeFS = struct { return Maybe(Return.AppendFile).success; }, else => { - _ = this; @compileError("Not implemented yet"); }, } @@ -2395,7 +2394,7 @@ pub const NodeFS = struct { const path = path_.sliceZ(&this.sync_error_buf); switch (comptime flavor) { .sync => { - const fd = switch (Syscall.open(path, @enumToInt(FileSystemFlags.@"a"), 000666)) { + const fd = switch (Syscall.open(path, @enumToInt(FileSystemFlags.a), 0o000666)) { .result => |result| result, .err => |err| return .{ .err = err }, }; @@ -2415,7 +2414,6 @@ pub const NodeFS = struct { return Maybe(Return.AppendFile).success; }, else => { - _ = this; @compileError("Not implemented yet"); }, } @@ -2425,14 +2423,12 @@ pub const NodeFS = struct { return Maybe(Return.AppendFile).todo; } - pub fn close(this: *NodeFS, args: Arguments.Close, comptime flavor: Flavor) Maybe(Return.Close) { + pub fn close(_: *NodeFS, args: Arguments.Close, comptime flavor: Flavor) Maybe(Return.Close) { switch (comptime flavor) { .sync => { return if (Syscall.close(args.fd)) |err| .{ .err = err } else Maybe(Return.Close).success; }, - else => { - _ = this; - }, + else => {}, } return .{ .err = Syscall.Error.todo }; @@ -2442,7 +2438,7 @@ pub const NodeFS = struct { /// https://github.com/pnpm/pnpm/issues/2761 /// https://github.com/libuv/libuv/pull/2578 /// https://github.com/nodejs/node/issues/34624 - pub fn copyFile(this: *NodeFS, args: Arguments.CopyFile, comptime flavor: Flavor) Maybe(Return.CopyFile) { + pub fn copyFile(_: *NodeFS, args: Arguments.CopyFile, comptime flavor: Flavor) Maybe(Return.CopyFile) { const ret = Maybe(Return.CopyFile); switch (comptime flavor) { @@ -2480,7 +2476,7 @@ pub const NodeFS = struct { return ret.success; } } else { - const src_fd = switch (Syscall.open(src, std.os.O.RDONLY, 0644)) { + const src_fd = switch (Syscall.open(src, std.os.O.RDONLY, 0o644)) { .result => |result| result, .err => |err| return .{ .err = err.withPath(args.src.slice()) }, }; @@ -2509,9 +2505,9 @@ pub const NodeFS = struct { // 16 KB is high end of what is okay to use for stack space // good thing we ask for absurdly large stack sizes var buf: [16384]u8 = undefined; - var remain = @intCast(u64, @maximum(stat_.size, 0)); + var remain = @intCast(u64, @max(stat_.size, 0)); toplevel: while (remain > 0) { - const amt = switch (Syscall.read(src_fd, buf[0..@minimum(buf.len, remain)])) { + const amt = switch (Syscall.read(src_fd, buf[0..@min(buf.len, remain)])) { .result => |result| result, .err => |err| return Maybe(Return.CopyFile){ .err = err.withPath(src) }, }; @@ -2579,7 +2575,7 @@ pub const NodeFS = struct { return Maybe(Return.CopyFile).todo; } - const src_fd = switch (Syscall.open(src, std.os.O.RDONLY, 0644)) { + const src_fd = switch (Syscall.open(src, std.os.O.RDONLY, 0o644)) { .result => |result| result, .err => |err| return .{ .err = err }, }; @@ -2607,7 +2603,7 @@ pub const NodeFS = struct { .err => |err| return Maybe(Return.CopyFile){ .err = err }, }; - var size = @intCast(usize, @maximum(stat_.size, 0)); + var size = @intCast(usize, @max(stat_.size, 0)); defer { _ = linux.ftruncate(dest_fd, @intCast(i64, @truncate(u63, wrote))); @@ -2653,11 +2649,7 @@ pub const NodeFS = struct { return ret.success; } }, - else => { - _ = args; - _ = this; - _ = flavor; - }, + else => {}, } return Maybe(Return.CopyFile).todo; @@ -2676,9 +2668,7 @@ pub const NodeFS = struct { }, else => {}, } - _ = args; - _ = this; - _ = flavor; + return Ret.todo; } @@ -2689,9 +2679,7 @@ pub const NodeFS = struct { .sync => return Syscall.chown(path, args.uid, args.gid), else => {}, } - _ = args; - _ = this; - _ = flavor; + return Maybe(Return.Chown).todo; } @@ -2706,26 +2694,22 @@ pub const NodeFS = struct { }, else => {}, } - _ = args; - _ = this; - _ = flavor; + return Maybe(Return.Chmod).todo; } /// This should almost never be async - pub fn fchmod(this: *NodeFS, args: Arguments.FChmod, comptime flavor: Flavor) Maybe(Return.Fchmod) { + pub fn fchmod(_: *NodeFS, args: Arguments.FChmod, comptime flavor: Flavor) Maybe(Return.Fchmod) { switch (comptime flavor) { .sync => { return Syscall.fchmod(args.fd, args.mode); }, else => {}, } - _ = args; - _ = this; - _ = flavor; + return Maybe(Return.Fchmod).todo; } - pub fn fchown(this: *NodeFS, args: Arguments.Fchown, comptime flavor: Flavor) Maybe(Return.Fchown) { + pub fn fchown(_: *NodeFS, args: Arguments.Fchown, comptime flavor: Flavor) Maybe(Return.Fchown) { switch (comptime flavor) { .sync => { return Maybe(Return.Fchown).errnoSys(C.fchown(args.fd, args.uid, args.gid), .fchown) orelse @@ -2733,24 +2717,19 @@ pub const NodeFS = struct { }, else => {}, } - _ = args; - _ = this; - _ = flavor; + return Maybe(Return.Fchown).todo; } - pub fn fdatasync(this: *NodeFS, args: Arguments.FdataSync, comptime flavor: Flavor) Maybe(Return.Fdatasync) { + pub fn fdatasync(_: *NodeFS, args: Arguments.FdataSync, comptime flavor: Flavor) Maybe(Return.Fdatasync) { switch (comptime flavor) { .sync => return Maybe(Return.Fdatasync).errnoSys(system.fdatasync(args.fd), .fdatasync) orelse Maybe(Return.Fdatasync).success, else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Fdatasync).todo; } - pub fn fstat(this: *NodeFS, args: Arguments.Fstat, comptime flavor: Flavor) Maybe(Return.Fstat) { + pub fn fstat(_: *NodeFS, args: Arguments.Fstat, comptime flavor: Flavor) Maybe(Return.Fstat) { if (args.big_int) return Maybe(Return.Fstat).todo; switch (comptime flavor) { @@ -2763,38 +2742,29 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Fstat).todo; } - pub fn fsync(this: *NodeFS, args: Arguments.Fsync, comptime flavor: Flavor) Maybe(Return.Fsync) { + pub fn fsync(_: *NodeFS, args: Arguments.Fsync, comptime flavor: Flavor) Maybe(Return.Fsync) { switch (comptime flavor) { .sync => return Maybe(Return.Fsync).errnoSys(system.fsync(args.fd), .fsync) orelse Maybe(Return.Fsync).success, else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Fsync).todo; } - pub fn ftruncate(this: *NodeFS, args: Arguments.FTruncate, comptime flavor: Flavor) Maybe(Return.Ftruncate) { + pub fn ftruncate(_: *NodeFS, args: Arguments.FTruncate, comptime flavor: Flavor) Maybe(Return.Ftruncate) { switch (comptime flavor) { .sync => return Maybe(Return.Ftruncate).errnoSys(system.ftruncate(args.fd, args.len orelse 0), .ftruncate) orelse Maybe(Return.Ftruncate).success, else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Ftruncate).todo; } - pub fn futimes(this: *NodeFS, args: Arguments.Futimes, comptime flavor: Flavor) Maybe(Return.Futimes) { + pub fn futimes(_: *NodeFS, args: Arguments.Futimes, comptime flavor: Flavor) Maybe(Return.Futimes) { var times = [2]std.os.timespec{ .{ .tv_sec = args.mtime, @@ -2814,9 +2784,6 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Futimes).todo; } @@ -2830,9 +2797,7 @@ pub const NodeFS = struct { }, else => {}, } - _ = args; - _ = this; - _ = flavor; + return Maybe(Return.Lchmod).todo; } @@ -2846,9 +2811,7 @@ pub const NodeFS = struct { }, else => {}, } - _ = args; - _ = this; - _ = flavor; + return Maybe(Return.Lchown).todo; } pub fn link(this: *NodeFS, args: Arguments.Link, comptime flavor: Flavor) Maybe(Return.Link) { @@ -2864,9 +2827,6 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Link).todo; } pub fn lstat(this: *NodeFS, args: Arguments.Lstat, comptime flavor: Flavor) Maybe(Return.Lstat) { @@ -2886,9 +2846,6 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Lstat).todo; } @@ -2907,9 +2864,7 @@ pub const NodeFS = struct { }, else => {}, } - _ = args; - _ = this; - _ = flavor; + return Maybe(Return.Mkdir).todo; } @@ -3044,15 +2999,12 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Mkdir).todo; } - pub fn mkdtemp(this: *NodeFS, args: Arguments.MkdirTemp, comptime flavor: Flavor) Maybe(Return.Mkdtemp) { + pub fn mkdtemp(this: *NodeFS, args: Arguments.MkdirTemp, comptime _: Flavor) Maybe(Return.Mkdtemp) { var prefix_buf = &this.sync_error_buf; - const len = @minimum(args.prefix.len, prefix_buf.len - 7); + const len = @min(args.prefix.len, prefix_buf.len - 7); if (len > 0) { @memcpy(prefix_buf, args.prefix.ptr, len); } @@ -3065,8 +3017,6 @@ pub const NodeFS = struct { else => |errno| return .{ .err = Syscall.Error{ .errno = @truncate(Syscall.Error.Int, @enumToInt(errno)), .syscall = .mkdtemp } }, } - _ = this; - _ = flavor; return .{ .result = PathString.init(bun.default_allocator.dupe(u8, std.mem.span(rc.?)) catch unreachable), }; @@ -3086,30 +3036,21 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Open).todo; } - pub fn openDir(this: *NodeFS, args: Arguments.OpenDir, comptime flavor: Flavor) Maybe(Return.OpenDir) { - _ = args; - _ = this; - _ = flavor; + pub fn openDir(_: *NodeFS, _: Arguments.OpenDir, comptime _: Flavor) Maybe(Return.OpenDir) { return Maybe(Return.OpenDir).todo; } - fn _read(this: *NodeFS, args: Arguments.Read, comptime flavor: Flavor) Maybe(Return.Read) { - _ = args; - _ = this; - _ = flavor; + fn _read(_: *NodeFS, args: Arguments.Read, comptime flavor: Flavor) Maybe(Return.Read) { if (Environment.allow_assert) std.debug.assert(args.position == null); switch (comptime flavor) { // The sync version does no allocation except when returning the path .sync => { var buf = args.buffer.slice(); - buf = buf[@minimum(args.offset, buf.len)..]; - buf = buf[0..@minimum(buf.len, args.length)]; + buf = buf[@min(args.offset, buf.len)..]; + buf = buf[0..@min(buf.len, args.length)]; return switch (Syscall.read(args.fd, buf)) { .err => |err| .{ @@ -3128,14 +3069,12 @@ pub const NodeFS = struct { return Maybe(Return.Read).todo; } - fn _pread(this: *NodeFS, args: Arguments.Read, comptime flavor: Flavor) Maybe(Return.Read) { - _ = this; - + fn _pread(_: *NodeFS, args: Arguments.Read, comptime flavor: Flavor) Maybe(Return.Read) { switch (comptime flavor) { .sync => { var buf = args.buffer.slice(); - buf = buf[@minimum(args.offset, buf.len)..]; - buf = buf[0..@minimum(buf.len, args.length)]; + buf = buf[@min(args.offset, buf.len)..]; + buf = buf[0..@min(buf.len, args.length)]; return switch (Syscall.pread(args.fd, buf, args.position.?)) { .err => |err| .{ @@ -3170,16 +3109,12 @@ pub const NodeFS = struct { pub fn write(this: *NodeFS, args: Arguments.Write, comptime flavor: Flavor) Maybe(Return.Write) { return if (args.position != null) _pwrite(this, args, flavor) else _write(this, args, flavor); } - fn _write(this: *NodeFS, args: Arguments.Write, comptime flavor: Flavor) Maybe(Return.Write) { - _ = args; - _ = this; - _ = flavor; - + fn _write(_: *NodeFS, args: Arguments.Write, comptime flavor: Flavor) Maybe(Return.Write) { switch (comptime flavor) { .sync => { var buf = args.buffer.slice(); - buf = buf[@minimum(args.offset, buf.len)..]; - buf = buf[0..@minimum(buf.len, args.length)]; + buf = buf[@min(args.offset, buf.len)..]; + buf = buf[0..@min(buf.len, args.length)]; return switch (Syscall.write(args.fd, buf)) { .err => |err| .{ @@ -3198,18 +3133,14 @@ pub const NodeFS = struct { return Maybe(Return.Write).todo; } - fn _pwrite(this: *NodeFS, args: Arguments.Write, comptime flavor: Flavor) Maybe(Return.Write) { - _ = args; - _ = this; - _ = flavor; - + fn _pwrite(_: *NodeFS, args: Arguments.Write, comptime flavor: Flavor) Maybe(Return.Write) { const position = args.position.?; switch (comptime flavor) { .sync => { var buf = args.buffer.slice(); - buf = buf[@minimum(args.offset, buf.len)..]; - buf = buf[0..@minimum(args.length, buf.len)]; + buf = buf[@min(args.offset, buf.len)..]; + buf = buf[0..@min(args.length, buf.len)]; return switch (Syscall.pwrite(args.fd, buf, position)) { .err => |err| .{ @@ -3247,7 +3178,7 @@ pub const NodeFS = struct { return _readdir( this, args, - DirEnt, + Dirent, flavor, ); }, @@ -3261,7 +3192,7 @@ pub const NodeFS = struct { comptime flavor: Flavor, ) Maybe(Return.Readdir) { const file_type = comptime switch (ExpectedType) { - DirEnt => "with_file_types", + Dirent => "with_file_types", PathString => "files", Buffer => "buffers", else => unreachable, @@ -3289,7 +3220,7 @@ pub const NodeFS = struct { .err => |err| { for (entries.items) |*item| { switch (comptime ExpectedType) { - DirEnt => { + Dirent => { bun.default_allocator.free(item.name.slice()); }, Buffer => { @@ -3311,7 +3242,7 @@ pub const NodeFS = struct { .result => |ent| ent, }) |current| : (entry = iterator.next()) { switch (comptime ExpectedType) { - DirEnt => { + Dirent => { entries.append(.{ .name = PathString.init(bun.default_allocator.dupe(u8, current.name.slice()) catch unreachable), .kind = current.kind, @@ -3335,9 +3266,6 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Readdir).todo; } pub fn readFile(this: *NodeFS, args: Arguments.ReadFile, comptime flavor: Flavor) Maybe(Return.ReadFile) { @@ -3374,7 +3302,7 @@ pub const NodeFS = struct { }; // For certain files, the size might be 0 but the file might still have contents. - const size = @intCast(u64, @maximum(stat_.size, 0)); + const size = @intCast(u64, @max(stat_.size, 0)); var buf = std.ArrayList(u8).init(bun.default_allocator); buf.ensureTotalCapacityPrecise(size + 16) catch unreachable; @@ -3457,9 +3385,6 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.ReadFile).todo; } @@ -3515,9 +3440,6 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.WriteFile).todo; } @@ -3549,9 +3471,6 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Readlink).todo; } pub fn realpath(this: *NodeFS, args: Arguments.Realpath, comptime flavor: Flavor) Maybe(Return.Realpath) { @@ -3606,16 +3525,13 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Realpath).todo; } pub const realpathNative = realpath; // pub fn realpathNative(this: *NodeFS, args: Arguments.Realpath, comptime flavor: Flavor) Maybe(Return.Realpath) { // _ = args; - // _ = this; - // _ = flavor; + // + // // return error.NotImplementedYet; // } pub fn rename(this: *NodeFS, args: Arguments.Rename, comptime flavor: Flavor) Maybe(Return.Rename) { @@ -3631,9 +3547,6 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Rename).todo; } pub fn rmdir(this: *NodeFS, args: Arguments.RmDir, comptime flavor: Flavor) Maybe(Return.Rmdir) { @@ -3644,15 +3557,10 @@ pub const NodeFS = struct { }, else => {}, } - _ = args; - _ = this; - _ = flavor; + return Maybe(Return.Rmdir).todo; } pub fn rm(this: *NodeFS, args: Arguments.RmDir, comptime flavor: Flavor) Maybe(Return.Rm) { - _ = args; - _ = this; - _ = flavor; switch (comptime flavor) { .sync => { if (comptime Environment.isMac) { @@ -3832,9 +3740,6 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Stat).todo; } @@ -3851,9 +3756,6 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Symlink).todo; } fn _truncate(this: *NodeFS, path: PathLike, len: JSC.WebCore.Blob.SizeType, comptime flavor: Flavor) Maybe(Return.Truncate) { @@ -3865,8 +3767,6 @@ pub const NodeFS = struct { else => {}, } - _ = this; - _ = flavor; return Maybe(Return.Truncate).todo; } pub fn truncate(this: *NodeFS, args: Arguments.Truncate, comptime flavor: Flavor) Maybe(Return.Truncate) { @@ -3891,15 +3791,9 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Unlink).todo; } - pub fn unwatchFile(this: *NodeFS, args: Arguments.UnwatchFile, comptime flavor: Flavor) Maybe(Return.UnwatchFile) { - _ = args; - _ = this; - _ = flavor; + pub fn unwatchFile(_: *NodeFS, _: Arguments.UnwatchFile, comptime _: Flavor) Maybe(Return.UnwatchFile) { return Maybe(Return.UnwatchFile).todo; } pub fn utimes(this: *NodeFS, args: Arguments.Utimes, comptime flavor: Flavor) Maybe(Return.Utimes) { @@ -3927,9 +3821,6 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Utimes).todo; } @@ -3958,15 +3849,9 @@ pub const NodeFS = struct { else => {}, } - _ = args; - _ = this; - _ = flavor; return Maybe(Return.Lutimes).todo; } - pub fn watch(this: *NodeFS, args: Arguments.Watch, comptime flavor: Flavor) Maybe(Return.Watch) { - _ = args; - _ = this; - _ = flavor; + pub fn watch(_: *NodeFS, _: Arguments.Watch, comptime _: Flavor) Maybe(Return.Watch) { return Maybe(Return.Watch).todo; } pub fn createReadStream(_: *NodeFS, _: Arguments.CreateReadStream, comptime _: Flavor) Maybe(Return.CreateReadStream) { diff --git a/src/bun.js/node/node_fs_binding.zig b/src/bun.js/node/node_fs_binding.zig index e88e0cbf7..07ecf4619 100644 --- a/src/bun.js/node/node_fs_binding.zig +++ b/src/bun.js/node/node_fs_binding.zig @@ -10,13 +10,10 @@ const Args = JSC.Node.NodeFS.Arguments; const d = JSC.d; const NodeFSFunction = fn ( - *JSC.Node.NodeFS, - JSC.C.JSContextRef, - JSC.C.JSObjectRef, - JSC.C.JSObjectRef, - []const JSC.C.JSValueRef, - JSC.C.ExceptionRef, -) JSC.C.JSValueRef; + this: *JSC.Node.NodeJSFS, + globalObject: *JSC.JSGlobalObject, + callframe: *JSC.CallFrame, +) callconv(.C) JSC.JSValue; pub const toJSTrait = std.meta.trait.hasFn("toJS"); pub const fromJSTrait = std.meta.trait.hasFn("fromJS"); @@ -26,45 +23,63 @@ fn callSync(comptime FunctionEnum: NodeFSFunctionEnum) NodeFSFunction { const Function = @field(JSC.Node.NodeFS, @tagName(FunctionEnum)); const FunctionType = @TypeOf(Function); - const function: std.builtin.TypeInfo.Fn = comptime @typeInfo(FunctionType).Fn; - comptime if (function.args.len != 3) @compileError("Expected 3 arguments"); - const Arguments = comptime function.args[1].arg_type.?; + const function: std.builtin.Type.Fn = comptime @typeInfo(FunctionType).Fn; + comptime if (function.params.len != 3) @compileError("Expected 3 arguments"); + const Arguments = comptime function.params[1].type.?; const FormattedName = comptime [1]u8{std.ascii.toUpper(@tagName(FunctionEnum)[0])} ++ @tagName(FunctionEnum)[1..]; const Result = comptime JSC.Maybe(@field(JSC.Node.NodeFS.ReturnType, FormattedName)); const NodeBindingClosure = struct { pub fn bind( - this: *JSC.Node.NodeFS, - ctx: JSC.C.JSContextRef, - _: JSC.C.JSObjectRef, - _: JSC.C.JSObjectRef, - arguments: []const JSC.C.JSValueRef, - exception: JSC.C.ExceptionRef, - ) JSC.C.JSValueRef { - var slice = ArgumentsSlice.init(ctx.bunVM(), @ptrCast([*]const JSC.JSValue, arguments.ptr)[0..arguments.len]); + this: *JSC.Node.NodeJSFS, + globalObject: *JSC.JSGlobalObject, + callframe: *JSC.CallFrame, + ) callconv(.C) JSC.JSValue { + var exceptionref: JSC.C.JSValueRef = null; + + var arguments = callframe.arguments(8); + var slice = ArgumentsSlice.init(globalObject.bunVM(), arguments.ptr[0..arguments.len]); defer slice.deinit(); const args = if (comptime Arguments != void) - (Arguments.fromJS(ctx, &slice, exception) orelse return null) + (Arguments.fromJS(globalObject, &slice, &exceptionref) orelse return .zero) else Arguments{}; - if (exception.* != null) return null; + + const exception1 = JSC.JSValue.c(exceptionref); + + if (exception1 != .zero) { + globalObject.throwValue(exception1); + return .zero; + } const result: Result = Function( - this, + &this.node_fs, args, comptime Flavor.sync, ); - return switch (result) { - .err => |err| brk: { - exception.* = err.toJS(ctx); - break :brk null; + switch (result) { + .err => |err| { + globalObject.throwValue(JSC.JSValue.c(err.toJS(globalObject))); + return .zero; }, - .result => |res| if (comptime Result.ReturnType != void) - JSC.To.JS.withType(Result.ReturnType, res, ctx, exception) - else - JSC.C.JSValueMakeUndefined(ctx), - }; + .result => |res| { + if (comptime Result.ReturnType != void) { + const out = JSC.JSValue.c(JSC.To.JS.withType(Result.ReturnType, res, globalObject, &exceptionref)); + const exception = JSC.JSValue.c(exceptionref); + if (exception != .zero) { + globalObject.throwValue(exception); + return .zero; + } + + return out; + } else { + return JSC.JSValue.jsUndefined(); + } + + unreachable; + }, + } } }; @@ -75,27 +90,20 @@ fn call(comptime Function: NodeFSFunctionEnum) NodeFSFunction { // const FunctionType = @TypeOf(Function); _ = Function; - // const function: std.builtin.TypeInfo.Fn = comptime @typeInfo(FunctionType).Fn; + // const function: std.builtin.Type.Fn = comptime @typeInfo(FunctionType).Fn; // comptime if (function.args.len != 3) @compileError("Expected 3 arguments"); - // const Arguments = comptime function.args[2].arg_type orelse @compileError(std.fmt.comptimePrint("Function {s} expected to have an arg type at [2]", .{@typeName(FunctionType)})); + // const Arguments = comptime function.args[2].type orelse @compileError(std.fmt.comptimePrint("Function {s} expected to have an arg type at [2]", .{@typeName(FunctionType)})); // const Result = comptime function.return_type.?; // comptime if (Arguments != void and !fromJSTrait(Arguments)) @compileError(std.fmt.comptimePrint("{s} is missing fromJS()", .{@typeName(Arguments)})); // comptime if (Result != void and !toJSTrait(Result)) @compileError(std.fmt.comptimePrint("{s} is missing toJS()", .{@typeName(Result)})); const NodeBindingClosure = struct { pub fn bind( - this: *JSC.Node.NodeFS, - ctx: JSC.C.JSContextRef, - _: JSC.C.JSObjectRef, - _: JSC.C.JSObjectRef, - arguments: []const JSC.C.JSValueRef, - exception: JSC.C.ExceptionRef, - ) JSC.C.JSValueRef { - _ = this; - _ = ctx; - _ = arguments; - var err = JSC.SystemError{}; - exception.* = err.toErrorInstance(ctx.ptr()).asObjectRef(); - return null; + _: *JSC.Node.NodeJSFS, + globalObject: *JSC.JSGlobalObject, + _: *JSC.CallFrame, + ) callconv(.C) JSC.JSValue { + globalObject.throw("Not implemented yet", .{}); + return .zero; // var slice = ArgumentsSlice.init(arguments); // defer { @@ -130,310 +138,102 @@ fn call(comptime Function: NodeFSFunctionEnum) NodeFSFunction { return NodeBindingClosure.bind; } -pub const NodeFSBindings = JSC.NewClass( - JSC.Node.NodeFS, - .{ .name = "fs", .ts = .{ .module = .{ .path = "fs" } } }, - - .{ - .access = .{ - .name = "access", - .rfn = call(.access), - }, - .appendFile = .{ - .name = "appendFile", - .rfn = call(.appendFile), - }, - .close = .{ - .name = "close", - .rfn = call(.close), - }, - .copyFile = .{ - .name = "copyFile", - .rfn = call(.copyFile), - }, - .exists = .{ - .name = "exists", - .rfn = call(.exists), - }, - .chown = .{ - .name = "chown", - .rfn = call(.chown), - }, - .chmod = .{ - .name = "chmod", - .rfn = call(.chmod), - }, - .fchmod = .{ - .name = "fchmod", - .rfn = call(.fchmod), - }, - .fchown = .{ - .name = "fchown", - .rfn = call(.fchown), - }, - .fstat = .{ - .name = "fstat", - .rfn = call(.fstat), - }, - .fsync = .{ - .name = "fsync", - .rfn = call(.fsync), - }, - .ftruncate = .{ - .name = "ftruncate", - .rfn = call(.ftruncate), - }, - .futimes = .{ - .name = "futimes", - .rfn = call(.futimes), - }, - .lchmod = .{ - .name = "lchmod", - .rfn = call(.lchmod), - }, - .lchown = .{ - .name = "lchown", - .rfn = call(.lchown), - }, - .link = .{ - .name = "link", - .rfn = call(.link), - }, - .lstat = .{ - .name = "lstat", - .rfn = call(.lstat), - }, - .mkdir = .{ - .name = "mkdir", - .rfn = call(.mkdir), - }, - .mkdtemp = .{ - .name = "mkdtemp", - .rfn = call(.mkdtemp), - }, - .open = .{ - .name = "open", - .rfn = call(.open), - }, - .read = .{ - .name = "read", - .rfn = call(.read), - }, - .write = .{ - .name = "write", - .rfn = call(.write), - }, - .readdir = .{ - .name = "readdir", - .rfn = call(.readdir), - }, - .readFile = .{ - .name = "readFile", - .rfn = call(.readFile), - }, - .writeFile = .{ - .name = "writeFile", - .rfn = call(.writeFile), - }, - .readlink = .{ - .name = "readlink", - .rfn = call(.readlink), - }, - .rm = .{ - .name = "rm", - .rfn = call(.rm), - }, - .rmdir = .{ - .name = "rmdir", - .rfn = call(.rmdir), - }, - .realpath = .{ - .name = "realpath", - .rfn = call(.realpath), - }, - .rename = .{ - .name = "rename", - .rfn = call(.rename), - }, - .stat = .{ - .name = "stat", - .rfn = call(.stat), - }, - .symlink = .{ - .name = "symlink", - .rfn = call(.symlink), - }, - .truncate = .{ - .name = "truncate", - .rfn = call(.truncate), - }, - .unlink = .{ - .name = "unlink", - .rfn = call(.unlink), - }, - .utimes = .{ - .name = "utimes", - .rfn = call(.utimes), - }, - .lutimes = .{ - .name = "lutimes", - .rfn = call(.lutimes), - }, - - .createReadStream = .{ - .name = "createReadStream", - .rfn = if (FeatureFlags.node_streams) callSync(.createReadStream) else call(.createReadStream), - }, - - .createWriteStream = .{ - .name = "createWriteStream", - .rfn = if (FeatureFlags.node_streams) callSync(.createWriteStream) else call(.createWriteStream), - }, - - .accessSync = .{ - .name = "accessSync", - .rfn = callSync(.access), - }, - .appendFileSync = .{ - .name = "appendFileSync", - .rfn = callSync(.appendFile), - }, - .closeSync = .{ - .name = "closeSync", - .rfn = callSync(.close), - }, - .copyFileSync = .{ - .name = "copyFileSync", - .rfn = callSync(.copyFile), - }, - .existsSync = .{ - .name = "existsSync", - .rfn = callSync(.exists), - }, - .chownSync = .{ - .name = "chownSync", - .rfn = callSync(.chown), - }, - .chmodSync = .{ - .name = "chmodSync", - .rfn = callSync(.chmod), - }, - .fchmodSync = .{ - .name = "fchmodSync", - .rfn = callSync(.fchmod), - }, - .fchownSync = .{ - .name = "fchownSync", - .rfn = callSync(.fchown), - }, - .fstatSync = .{ - .name = "fstatSync", - .rfn = callSync(.fstat), - }, - .fsyncSync = .{ - .name = "fsyncSync", - .rfn = callSync(.fsync), - }, - .ftruncateSync = .{ - .name = "ftruncateSync", - .rfn = callSync(.ftruncate), - }, - .futimesSync = .{ - .name = "futimesSync", - .rfn = callSync(.futimes), - }, - .lchmodSync = .{ - .name = "lchmodSync", - .rfn = callSync(.lchmod), - }, - .lchownSync = .{ - .name = "lchownSync", - .rfn = callSync(.lchown), - }, - .linkSync = .{ - .name = "linkSync", - .rfn = callSync(.link), - }, - .lstatSync = .{ - .name = "lstatSync", - .rfn = callSync(.lstat), - }, - .mkdirSync = .{ - .name = "mkdirSync", - .rfn = callSync(.mkdir), - }, - .mkdtempSync = .{ - .name = "mkdtempSync", - .rfn = callSync(.mkdtemp), - }, - .openSync = .{ - .name = "openSync", - .rfn = callSync(.open), - }, - .readSync = .{ - .name = "readSync", - .rfn = callSync(.read), - }, - .writeSync = .{ - .name = "writeSync", - .rfn = callSync(.write), - }, - .readdirSync = .{ - .name = "readdirSync", - .rfn = callSync(.readdir), - }, - .readFileSync = .{ - .name = "readFileSync", - .rfn = callSync(.readFile), - }, - .writeFileSync = .{ - .name = "writeFileSync", - .rfn = callSync(.writeFile), - }, - .readlinkSync = .{ - .name = "readlinkSync", - .rfn = callSync(.readlink), - }, - .realpathSync = .{ - .name = "realpathSync", - .rfn = callSync(.realpath), - }, - .renameSync = .{ - .name = "renameSync", - .rfn = callSync(.rename), - }, - .statSync = .{ - .name = "statSync", - .rfn = callSync(.stat), - }, - .symlinkSync = .{ - .name = "symlinkSync", - .rfn = callSync(.symlink), - }, - .truncateSync = .{ - .name = "truncateSync", - .rfn = callSync(.truncate), - }, - .unlinkSync = .{ - .name = "unlinkSync", - .rfn = callSync(.unlink), - }, - .utimesSync = .{ - .name = "utimesSync", - .rfn = callSync(.utimes), - }, - .lutimesSync = .{ - .name = "lutimesSync", - .rfn = callSync(.lutimes), - }, - .rmSync = .{ - .name = "rmSync", - .rfn = callSync(.rm), - }, - .rmdirSync = .{ - .name = "rmdirSync", - .rfn = callSync(.rmdir), - }, - }, - .{}, -); +pub const NodeJSFS = struct { + node_fs: JSC.Node.NodeFS = undefined, + + pub usingnamespace JSC.Codegen.JSNodeJSFS; + + pub fn constructor(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) ?*@This() { + globalObject.throw("Not a constructor", .{}); + return null; + } + + pub const access = call(.access); + pub const appendFile = call(.appendFile); + pub const close = call(.close); + pub const copyFile = call(.copyFile); + pub const exists = call(.exists); + pub const chown = call(.chown); + pub const chmod = call(.chmod); + pub const fchmod = call(.fchmod); + pub const fchown = call(.fchown); + pub const fstat = call(.fstat); + pub const fsync = call(.fsync); + pub const ftruncate = call(.ftruncate); + pub const futimes = call(.futimes); + pub const lchmod = call(.lchmod); + pub const lchown = call(.lchown); + pub const link = call(.link); + pub const lstat = call(.lstat); + pub const mkdir = call(.mkdir); + pub const mkdtemp = call(.mkdtemp); + pub const open = call(.open); + pub const read = call(.read); + pub const write = call(.write); + pub const readdir = call(.readdir); + pub const readFile = call(.readFile); + pub const writeFile = call(.writeFile); + pub const readlink = call(.readlink); + pub const rm = call(.rm); + pub const rmdir = call(.rmdir); + pub const realpath = call(.realpath); + pub const rename = call(.rename); + pub const stat = call(.stat); + pub const symlink = call(.symlink); + pub const truncate = call(.truncate); + pub const unlink = call(.unlink); + pub const utimes = call(.utimes); + pub const lutimes = call(.lutimes); + pub const accessSync = callSync(.access); + pub const appendFileSync = callSync(.appendFile); + pub const closeSync = callSync(.close); + pub const copyFileSync = callSync(.copyFile); + pub const existsSync = callSync(.exists); + pub const chownSync = callSync(.chown); + pub const chmodSync = callSync(.chmod); + pub const fchmodSync = callSync(.fchmod); + pub const fchownSync = callSync(.fchown); + pub const fstatSync = callSync(.fstat); + pub const fsyncSync = callSync(.fsync); + pub const ftruncateSync = callSync(.ftruncate); + pub const futimesSync = callSync(.futimes); + pub const lchmodSync = callSync(.lchmod); + pub const lchownSync = callSync(.lchown); + pub const linkSync = callSync(.link); + pub const lstatSync = callSync(.lstat); + pub const mkdirSync = callSync(.mkdir); + pub const mkdtempSync = callSync(.mkdtemp); + pub const openSync = callSync(.open); + pub const readSync = callSync(.read); + pub const writeSync = callSync(.write); + pub const readdirSync = callSync(.readdir); + pub const readFileSync = callSync(.readFile); + pub const writeFileSync = callSync(.writeFile); + pub const readlinkSync = callSync(.readlink); + pub const realpathSync = callSync(.realpath); + pub const renameSync = callSync(.rename); + pub const statSync = callSync(.stat); + pub const symlinkSync = callSync(.symlink); + pub const truncateSync = callSync(.truncate); + pub const unlinkSync = callSync(.unlink); + pub const utimesSync = callSync(.utimes); + pub const lutimesSync = callSync(.lutimes); + pub const rmSync = callSync(.rm); + pub const rmdirSync = callSync(.rmdir); + + pub const fdatasyncSync = callSync(.fdatasync); + pub const fdatasync = call(.fdatasync); + + pub fn getDirent(_: *NodeJSFS, globalThis: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue { + return JSC.Node.Dirent.getConstructor(globalThis); + } + + // Not implemented yet: + const notimpl = fdatasync; + pub const opendir = notimpl; + pub const opendirSync = notimpl; + pub const readv = notimpl; + pub const readvSync = notimpl; + pub const writev = notimpl; + pub const writevSync = notimpl; +}; diff --git a/src/bun.js/node/node_os.zig b/src/bun.js/node/node_os.zig index 3018fd138..525ee991b 100644 --- a/src/bun.js/node/node_os.zig +++ b/src/bun.js/node/node_os.zig @@ -32,7 +32,7 @@ pub const Os = struct { module.put(globalObject, JSC.ZigString.static("setPriority"), JSC.NewFunction(globalObject, JSC.ZigString.static("setPriority"), 2, setPriority, true)); module.put(globalObject, JSC.ZigString.static("tmpdir"), JSC.NewFunction(globalObject, JSC.ZigString.static("tmpdir"), 0, tmpdir, true)); module.put(globalObject, JSC.ZigString.static("totalmem"), JSC.NewFunction(globalObject, JSC.ZigString.static("totalmem"), 0, totalmem, true)); - module.put(globalObject, JSC.ZigString.static("type"), JSC.NewFunction(globalObject, JSC.ZigString.static("type"), 0, Os.@"type", true)); + module.put(globalObject, JSC.ZigString.static("type"), JSC.NewFunction(globalObject, JSC.ZigString.static("type"), 0, Os.type, true)); module.put(globalObject, JSC.ZigString.static("uptime"), JSC.NewFunction(globalObject, JSC.ZigString.static("uptime"), 0, uptime, true)); module.put(globalObject, JSC.ZigString.static("userInfo"), JSC.NewFunction(globalObject, JSC.ZigString.static("userInfo"), 0, userInfo, true)); module.put(globalObject, JSC.ZigString.static("version"), JSC.NewFunction(globalObject, JSC.ZigString.static("version"), 0, version, true)); diff --git a/src/bun.js/node/syscall.zig b/src/bun.js/node/syscall.zig index 50ba6e33f..06b007ef1 100644 --- a/src/bun.js/node/syscall.zig +++ b/src/bun.js/node/syscall.zig @@ -253,7 +253,7 @@ const max_count = switch (builtin.os.tag) { }; pub fn write(fd: os.fd_t, bytes: []const u8) Maybe(usize) { - const adjusted_len = @minimum(max_count, bytes.len); + const adjusted_len = @min(max_count, bytes.len); if (comptime Environment.isMac) { const rc = system.@"write$NOCANCEL"(fd, bytes.ptr, adjusted_len); @@ -290,7 +290,7 @@ else const fcntl_symbol = system.fcntl; pub fn pread(fd: os.fd_t, buf: []u8, offset: i64) Maybe(usize) { - const adjusted_len = @minimum(buf.len, max_count); + const adjusted_len = @min(buf.len, max_count); const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned while (true) { const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset); @@ -309,7 +309,7 @@ else sys.pwrite; pub fn pwrite(fd: os.fd_t, bytes: []const u8, offset: i64) Maybe(usize) { - const adjusted_len = @minimum(bytes.len, max_count); + const adjusted_len = @min(bytes.len, max_count); const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned while (true) { @@ -327,7 +327,7 @@ pub fn pwrite(fd: os.fd_t, bytes: []const u8, offset: i64) Maybe(usize) { pub fn read(fd: os.fd_t, buf: []u8) Maybe(usize) { const debug_timer = bun.Output.DebugTimer.start(); - const adjusted_len = @minimum(buf.len, max_count); + const adjusted_len = @min(buf.len, max_count); if (comptime Environment.isMac) { const rc = system.@"read$NOCANCEL"(fd, buf.ptr, adjusted_len); @@ -353,7 +353,7 @@ pub fn read(fd: os.fd_t, buf: []u8) Maybe(usize) { } pub fn recv(fd: os.fd_t, buf: []u8, flag: u32) Maybe(usize) { - const adjusted_len = @minimum(buf.len, max_count); + const adjusted_len = @min(buf.len, max_count); if (comptime Environment.isMac) { const rc = system.@"recvfrom$NOCANCEL"(fd, buf.ptr, adjusted_len, flag, null, null); @@ -582,7 +582,7 @@ pub fn mmapFile(path: [:0]const u8, flags: u32, wanted_size: ?usize, offset: usi }, }), offset) catch 0; - if (wanted_size) |size_| size = @minimum(size, size_); + if (wanted_size) |size_| size = @min(size, size_); const map = switch (mmap(null, size, os.PROT.READ | os.PROT.WRITE, flags, fd, offset)) { .result => |map| map, @@ -612,7 +612,7 @@ pub const Error = struct { const errno_values = std.enums.values(os.E); var err = @enumToInt(os.E.SUCCESS); for (errno_values) |errn| { - err = @maximum(err, @enumToInt(errn)); + err = @max(err, @enumToInt(errn)); } break :brk err; }; @@ -774,7 +774,7 @@ pub fn getMaxPipeSizeOnLinux() usize { // we set the absolute max to 8 MB because honestly that's a huge pipe // my current linux machine only goes up to 1 MB, so that's very unlikely to be hit - return @minimum(@truncate(c_int, max_pipe_size -| 32), 1024 * 1024 * 8); + return @min(@truncate(c_int, max_pipe_size -| 32), 1024 * 1024 * 8); } }.once, c_int), ); diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index dce75cf68..ed202830c 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -24,8 +24,8 @@ pub const Mode = if (Environment.isLinux) u32 else std.os.mode_t; const heap_allocator = bun.default_allocator; pub fn DeclEnum(comptime T: type) type { const fieldInfos = std.meta.declarations(T); - var enumFields: [fieldInfos.len]std.builtin.TypeInfo.EnumField = undefined; - var decls = [_]std.builtin.TypeInfo.Declaration{}; + var enumFields: [fieldInfos.len]std.builtin.Type.EnumField = undefined; + var decls = [_]std.builtin.Type.Declaration{}; inline for (fieldInfos) |field, i| { enumFields[i] = .{ .name = field.name, @@ -34,7 +34,6 @@ pub fn DeclEnum(comptime T: type) type { } return @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = std.math.IntFittingRange(0, fieldInfos.len - 1), .fields = &enumFields, .decls = &decls, @@ -787,7 +786,7 @@ pub fn timeLikeFromJS(ctx: JSC.C.JSContextRef, value_: JSC.JSValue, exception: J return null; } - return @floatToInt(TimeLike, @maximum(@floor(seconds), std.math.minInt(TimeLike))); + return @floatToInt(TimeLike, @max(@floor(seconds), std.math.minInt(TimeLike))); } pub fn modeFromJS(ctx: JSC.C.JSContextRef, value: JSC.JSValue, exception: JSC.C.ExceptionRef) ?Mode { @@ -837,7 +836,7 @@ pub const PathOrFileDescriptor = union(Tag) { } pub fn format(this: JSC.Node.PathOrFileDescriptor, comptime fmt: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { - if (fmt.len != 0 and fmt != "s") { + if (fmt.len != 0 and fmt[0] != 's') { @compileError("Unsupported format argument: '" ++ fmt ++ "'."); } switch (this) { @@ -869,7 +868,7 @@ pub const PathOrFileDescriptor = union(Tag) { pub const FileSystemFlags = enum(Mode) { /// Open file for appending. The file is created if it does not exist. - @"a" = std.os.O.APPEND | std.os.O.WRONLY | std.os.O.CREAT, + a = std.os.O.APPEND | std.os.O.WRONLY | std.os.O.CREAT, /// Like 'a' but fails if the path exists. // @"ax" = std.os.O.APPEND | std.os.O.EXCL, /// Open file for reading and appending. The file is created if it does not exist. @@ -881,7 +880,7 @@ pub const FileSystemFlags = enum(Mode) { /// Open file for reading and appending in synchronous mode. The file is created if it does not exist. // @"as+" = std.os.O.APPEND | std.os.O.RDWR, /// Open file for reading. An exception occurs if the file does not exist. - @"r" = std.os.O.RDONLY, + r = std.os.O.RDONLY, /// Open file for reading and writing. An exception occurs if the file does not exist. // @"r+" = std.os.O.RDWR, /// Open file for reading and writing in synchronous mode. Instructs the operating system to bypass the local file system cache. @@ -889,7 +888,7 @@ pub const FileSystemFlags = enum(Mode) { /// This doesn't turn fs.open() or fsPromises.open() into a synchronous blocking call. If synchronous operation is desired, something like fs.openSync() should be used. // @"rs+" = std.os.O.RDWR, /// Open file for writing. The file is created (if it does not exist) or truncated (if it exists). - @"w" = std.os.O.WRONLY | std.os.O.CREAT, + w = std.os.O.WRONLY | std.os.O.CREAT, /// Like 'w' but fails if the path exists. // @"wx" = std.os.O.WRONLY | std.os.O.TRUNC, // /// Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists). @@ -933,7 +932,7 @@ pub const FileSystemFlags = enum(Mode) { val.toZigString(&zig_str, ctx.ptr()); var buf: [4]u8 = .{ 0, 0, 0, 0 }; - @memcpy(&buf, zig_str.ptr, @minimum(buf.len, zig_str.len)); + @memcpy(&buf, zig_str.ptr, @min(buf.len, zig_str.len)); const Matcher = strings.ExactSizeMatcher(4); // https://github.com/nodejs/node/blob/8c3637cd35cca352794e2c128f3bc5e6b6c41380/lib/internal/fs/utils.js#L565 @@ -989,9 +988,9 @@ pub const Date = enum(u64) { _, pub fn toJS(this: Date, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef { - const seconds = @floatCast(f64, @intToFloat(f128, @enumToInt(this)) * 1000.0); - const unix_timestamp = JSC.C.JSValueMakeNumber(ctx, seconds); - const array: [1]JSC.C.JSValueRef = .{unix_timestamp}; + const seconds = @floatCast(f64, @intToFloat(f64, @enumToInt(this)) * 1000.0); + const unix_timestamp = JSC.JSValue.jsNumber(seconds); + const array: [1]JSC.C.JSValueRef = .{unix_timestamp.asObjectRef()}; const obj = JSC.C.JSObjectMakeDate(ctx, 1, &array, exception); return obj; } @@ -1141,9 +1140,9 @@ fn StatsLike(comptime name: [:0]const u8, comptime T: type) type { .atime_ms = @truncate(T, @intCast(i64, if (atime.tv_nsec > 0) (@intCast(usize, atime.tv_nsec) / std.time.ns_per_ms) else 0)), .mtime_ms = @truncate(T, @intCast(i64, if (mtime.tv_nsec > 0) (@intCast(usize, mtime.tv_nsec) / std.time.ns_per_ms) else 0)), .ctime_ms = @truncate(T, @intCast(i64, if (ctime.tv_nsec > 0) (@intCast(usize, ctime.tv_nsec) / std.time.ns_per_ms) else 0)), - .atime = @intToEnum(Date, @intCast(u64, @maximum(atime.tv_sec, 0))), - .mtime = @intToEnum(Date, @intCast(u64, @maximum(mtime.tv_sec, 0))), - .ctime = @intToEnum(Date, @intCast(u64, @maximum(ctime.tv_sec, 0))), + .atime = @intToEnum(Date, @intCast(u64, @max(atime.tv_sec, 0))), + .mtime = @intToEnum(Date, @intCast(u64, @max(mtime.tv_sec, 0))), + .ctime = @intToEnum(Date, @intCast(u64, @max(ctime.tv_sec, 0))), // Linux doesn't include this info in stat // maybe it does in statx, but do you really need birthtime? If you do please file an issue. @@ -1155,7 +1154,7 @@ fn StatsLike(comptime name: [:0]const u8, comptime T: type) type { .birthtime = if (Environment.isLinux) @intToEnum(Date, 0) else - @intToEnum(Date, @intCast(u64, @maximum(stat_.birthtime().tv_sec, 0))), + @intToEnum(Date, @intCast(u64, @max(stat_.birthtime().tv_sec, 0))), }; } @@ -1226,121 +1225,74 @@ pub const BigIntStats = StatsLike("BigIntStats", i64); /// When using the async iterator, the `fs.Dir` object will be automatically /// closed after the iterator exits. /// @since v12.12.0 -pub const DirEnt = struct { +pub const Dirent = struct { name: PathString, // not publicly exposed kind: Kind, pub const Kind = std.fs.File.Kind; + pub usingnamespace JSC.Codegen.JSDirent; + + pub fn constructor(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) ?*Dirent { + globalObject.throw("Dirent is not a constructor", .{}); + return null; + } + + pub fn getName(this: *Dirent, globalObject: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue { + return JSC.ZigString.fromUTF8(this.name.slice()).toValueGC(globalObject); + } pub fn isBlockDevice( - this: *DirEnt, - ctx: JSC.C.JSContextRef, - _: JSC.C.JSObjectRef, - _: JSC.C.JSObjectRef, - _: []const JSC.C.JSValueRef, - _: JSC.C.ExceptionRef, - ) JSC.C.JSValueRef { - return JSC.C.JSValueMakeBoolean(ctx, this.kind == std.fs.File.Kind.BlockDevice); + this: *Dirent, + _: *JSC.JSGlobalObject, + _: *JSC.CallFrame, + ) callconv(.C) JSC.JSValue { + return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.BlockDevice); } pub fn isCharacterDevice( - this: *DirEnt, - ctx: JSC.C.JSContextRef, - _: JSC.C.JSObjectRef, - _: JSC.C.JSObjectRef, - _: []const JSC.C.JSValueRef, - _: JSC.C.ExceptionRef, - ) JSC.C.JSValueRef { - return JSC.C.JSValueMakeBoolean(ctx, this.kind == std.fs.File.Kind.CharacterDevice); + this: *Dirent, + _: *JSC.JSGlobalObject, + _: *JSC.CallFrame, + ) callconv(.C) JSC.JSValue { + return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.CharacterDevice); } pub fn isDirectory( - this: *DirEnt, - ctx: JSC.C.JSContextRef, - _: JSC.C.JSObjectRef, - _: JSC.C.JSObjectRef, - _: []const JSC.C.JSValueRef, - _: JSC.C.ExceptionRef, - ) JSC.C.JSValueRef { - return JSC.C.JSValueMakeBoolean(ctx, this.kind == std.fs.File.Kind.Directory); + this: *Dirent, + _: *JSC.JSGlobalObject, + _: *JSC.CallFrame, + ) callconv(.C) JSC.JSValue { + return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.Directory); } pub fn isFIFO( - this: *DirEnt, - ctx: JSC.C.JSContextRef, - _: JSC.C.JSObjectRef, - _: JSC.C.JSObjectRef, - _: []const JSC.C.JSValueRef, - _: JSC.C.ExceptionRef, - ) JSC.C.JSValueRef { - return JSC.C.JSValueMakeBoolean(ctx, this.kind == std.fs.File.Kind.NamedPipe or this.kind == std.fs.File.Kind.EventPort); + this: *Dirent, + _: *JSC.JSGlobalObject, + _: *JSC.CallFrame, + ) callconv(.C) JSC.JSValue { + return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.NamedPipe or this.kind == std.fs.File.Kind.EventPort); } pub fn isFile( - this: *DirEnt, - ctx: JSC.C.JSContextRef, - _: JSC.C.JSObjectRef, - _: JSC.C.JSObjectRef, - _: []const JSC.C.JSValueRef, - _: JSC.C.ExceptionRef, - ) JSC.C.JSValueRef { - return JSC.C.JSValueMakeBoolean(ctx, this.kind == std.fs.File.Kind.File); + this: *Dirent, + _: *JSC.JSGlobalObject, + _: *JSC.CallFrame, + ) callconv(.C) JSC.JSValue { + return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.File); } pub fn isSocket( - this: *DirEnt, - ctx: JSC.C.JSContextRef, - _: JSC.C.JSObjectRef, - _: JSC.C.JSObjectRef, - _: []const JSC.C.JSValueRef, - _: JSC.C.ExceptionRef, - ) JSC.C.JSValueRef { - return JSC.C.JSValueMakeBoolean(ctx, this.kind == std.fs.File.Kind.UnixDomainSocket); + this: *Dirent, + _: *JSC.JSGlobalObject, + _: *JSC.CallFrame, + ) callconv(.C) JSC.JSValue { + return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.UnixDomainSocket); } pub fn isSymbolicLink( - this: *DirEnt, - ctx: JSC.C.JSContextRef, - _: JSC.C.JSObjectRef, - _: JSC.C.JSObjectRef, - _: []const JSC.C.JSValueRef, - _: JSC.C.ExceptionRef, - ) JSC.C.JSValueRef { - return JSC.C.JSValueMakeBoolean(ctx, this.kind == std.fs.File.Kind.SymLink); - } - - pub const Class = JSC.NewClass(DirEnt, .{ .name = "DirEnt" }, .{ - .isBlockDevice = .{ - .name = "isBlockDevice", - .rfn = isBlockDevice, - }, - .isCharacterDevice = .{ - .name = "isCharacterDevice", - .rfn = isCharacterDevice, - }, - .isDirectory = .{ - .name = "isDirectory", - .rfn = isDirectory, - }, - .isFIFO = .{ - .name = "isFIFO", - .rfn = isFIFO, - }, - .isFile = .{ - .name = "isFile", - .rfn = isFile, - }, - .isSocket = .{ - .name = "isSocket", - .rfn = isSocket, - }, - .isSymbolicLink = .{ - .name = "isSymbolicLink", - .rfn = isSymbolicLink, - }, - }, .{ - .name = .{ - .get = JSC.To.JS.Getter(DirEnt, .name), - .name = "name", - }, - }); + this: *Dirent, + _: *JSC.JSGlobalObject, + _: *JSC.CallFrame, + ) callconv(.C) JSC.JSValue { + return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.SymLink); + } - pub fn finalize(this: *DirEnt) void { + pub fn finalize(this: *Dirent) callconv(.C) void { bun.default_allocator.free(this.name.slice()); bun.default_allocator.destroy(this); } @@ -1645,7 +1597,7 @@ pub const Path = struct { if (u16_slice.len > 3) buf[3] = u16_slice[3]; - return std.fs.path.isAbsoluteWindowsWTF16(buf[0..@minimum(u16_slice.len, buf.len)]); + return std.fs.path.isAbsoluteWindowsWTF16(buf[0..@min(u16_slice.len, buf.len)]); } return std.fs.path.isAbsoluteWindows(zig_str.slice()); @@ -1819,16 +1771,16 @@ pub const Path = struct { } pub const Export = shim.exportFunctions(.{ - .@"basename" = basename, - .@"dirname" = dirname, - .@"extname" = extname, - .@"format" = format, - .@"isAbsolute" = isAbsolute, - .@"join" = join, - .@"normalize" = normalize, - .@"parse" = parse, - .@"relative" = relative, - .@"resolve" = resolve, + .basename = basename, + .dirname = dirname, + .extname = extname, + .format = format, + .isAbsolute = isAbsolute, + .join = join, + .normalize = normalize, + .parse = parse, + .relative = relative, + .resolve = resolve, }); pub const Extern = [_][]const u8{"create"}; @@ -1962,14 +1914,14 @@ pub const Process = struct { // When we update the cwd from JS, we have to update the bundler's version as well // However, this might be called many times in a row, so we use a pre-allocated buffer // that way we don't have to worry about garbage collector - JSC.VirtualMachine.vm.bundler.fs.top_level_dir = std.os.getcwd(&JSC.VirtualMachine.vm.bundler.fs.top_level_dir_buf) catch { - _ = Syscall.chdir(std.meta.assumeSentinel(JSC.VirtualMachine.vm.bundler.fs.top_level_dir, 0)); + JSC.VirtualMachine.get().bundler.fs.top_level_dir = std.os.getcwd(&JSC.VirtualMachine.get().bundler.fs.top_level_dir_buf) catch { + _ = Syscall.chdir(std.meta.assumeSentinel(JSC.VirtualMachine.get().bundler.fs.top_level_dir, 0)); return JSC.toInvalidArguments("Invalid path", .{}, globalObject.ref()); }; - JSC.VirtualMachine.vm.bundler.fs.top_level_dir_buf[JSC.VirtualMachine.vm.bundler.fs.top_level_dir.len] = std.fs.path.sep; - JSC.VirtualMachine.vm.bundler.fs.top_level_dir_buf[JSC.VirtualMachine.vm.bundler.fs.top_level_dir.len + 1] = 0; - JSC.VirtualMachine.vm.bundler.fs.top_level_dir = JSC.VirtualMachine.vm.bundler.fs.top_level_dir_buf[0 .. JSC.VirtualMachine.vm.bundler.fs.top_level_dir.len + 1]; + JSC.VirtualMachine.get().bundler.fs.top_level_dir_buf[JSC.VirtualMachine.get().bundler.fs.top_level_dir.len] = std.fs.path.sep; + JSC.VirtualMachine.get().bundler.fs.top_level_dir_buf[JSC.VirtualMachine.get().bundler.fs.top_level_dir.len + 1] = 0; + JSC.VirtualMachine.get().bundler.fs.top_level_dir = JSC.VirtualMachine.get().bundler.fs.top_level_dir_buf[0 .. JSC.VirtualMachine.get().bundler.fs.top_level_dir.len + 1]; return JSC.JSValue.jsUndefined(); }, @@ -1977,18 +1929,18 @@ pub const Process = struct { } pub fn exit(_: *JSC.JSGlobalObject, code: i32) callconv(.C) void { - std.os.exit(@truncate(u8, @intCast(u32, @maximum(code, 0)))); - } - - pub export const Bun__version: [:0]const u8 = "v" ++ bun.Global.package_json_version; - pub export const Bun__versions_mimalloc: [:0]const u8 = bun.Global.versions.mimalloc; - pub export const Bun__versions_webkit: [:0]const u8 = bun.Global.versions.webkit; - pub export const Bun__versions_libarchive: [:0]const u8 = bun.Global.versions.libarchive; - pub export const Bun__versions_picohttpparser: [:0]const u8 = bun.Global.versions.picohttpparser; - pub export const Bun__versions_boringssl: [:0]const u8 = bun.Global.versions.boringssl; - pub export const Bun__versions_zlib: [:0]const u8 = bun.Global.versions.zlib; - pub export const Bun__versions_zig: [:0]const u8 = bun.Global.versions.zig; - pub export const Bun__version_sha: [:0]const u8 = bun.Environment.git_sha; + std.os.exit(@truncate(u8, @intCast(u32, @max(code, 0)))); + } + + pub export const Bun__version: [*:0]const u8 = "v" ++ bun.Global.package_json_version; + pub export const Bun__versions_mimalloc: [*:0]const u8 = bun.Global.versions.mimalloc; + pub export const Bun__versions_webkit: [*:0]const u8 = bun.Global.versions.webkit; + pub export const Bun__versions_libarchive: [*:0]const u8 = bun.Global.versions.libarchive; + pub export const Bun__versions_picohttpparser: [*:0]const u8 = bun.Global.versions.picohttpparser; + pub export const Bun__versions_boringssl: [*:0]const u8 = bun.Global.versions.boringssl; + pub export const Bun__versions_zlib: [*:0]const u8 = bun.Global.versions.zlib; + pub export const Bun__versions_zig: [*:0]const u8 = bun.Global.versions.zig; + pub export const Bun__version_sha: [*:0]const u8 = bun.Environment.git_sha; }; comptime { diff --git a/src/bun.js/rare_data.zig b/src/bun.js/rare_data.zig index 26869c19d..4f760c0d6 100644 --- a/src/bun.js/rare_data.zig +++ b/src/bun.js/rare_data.zig @@ -117,7 +117,7 @@ pub const CleanupHook = struct { }; } - pub const Function = fn (?*anyopaque) callconv(.C) void; + pub const Function = *const fn (?*anyopaque) callconv(.C) void; }; pub fn pushCleanupHook( @@ -126,7 +126,7 @@ pub fn pushCleanupHook( ctx: ?*anyopaque, func: CleanupHook.Function, ) void { - var hook = JSC.VirtualMachine.vm.allocator.create(CleanupHook) catch unreachable; + var hook = JSC.VirtualMachine.get().allocator.create(CleanupHook) catch unreachable; hook.* = CleanupHook.from(globalThis, ctx, func); if (this.cleanup_hook == null) { this.cleanup_hook = hook; diff --git a/src/bun.js/scripts/generate-classes.ts b/src/bun.js/scripts/generate-classes.ts index b08e573b4..01a42a5fe 100644 --- a/src/bun.js/scripts/generate-classes.ts +++ b/src/bun.js/scripts/generate-classes.ts @@ -8,6 +8,7 @@ const directoriesToSearch = [ resolve(`${import.meta.dir}/../api`), resolve(`${import.meta.dir}/../test`), resolve(`${import.meta.dir}/../webcore`), + resolve(`${import.meta.dir}/../node`), ]; function symbolName(typeName, name) { @@ -1430,7 +1431,7 @@ function generateZig( output += ` if (@TypeOf(${typeName}.${fn}) != CallbackType) @compileLog( - "Expected ${typeName}.${fn} to be a callback" + "Expected ${typeName}.${fn} to be a callback but received " ++ @typeName(@TypeOf(${typeName}.${fn})) );`; } }, diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 7e6f59c2e..2a98d42f8 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -91,7 +91,7 @@ pub const TestRunner = struct { this.pending_test = null; // disable idling - JSC.VirtualMachine.vm.uws_event_loop.?.wakeup(); + JSC.VirtualMachine.get().uws_event_loop.?.wakeup(); } pub fn drain(this: *TestRunner) void { @@ -126,9 +126,9 @@ pub const TestRunner = struct { } pub const Callback = struct { - pub const OnUpdateCount = fn (this: *Callback, delta: u32, total: u32) void; - pub const OnTestStart = fn (this: *Callback, test_id: Test.ID) void; - pub const OnTestUpdate = fn (this: *Callback, test_id: Test.ID, file: string, label: string, expectations: u32, parent: ?*DescribeScope) void; + pub const OnUpdateCount = *const fn (this: *Callback, delta: u32, total: u32) void; + pub const OnTestStart = *const fn (this: *Callback, test_id: Test.ID) void; + pub const OnTestUpdate = *const fn (this: *Callback, test_id: Test.ID, file: string, label: string, expectations: u32, parent: ?*DescribeScope) void; onUpdateCount: OnUpdateCount, onTestStart: OnTestStart, onTestPass: OnTestUpdate, @@ -251,7 +251,7 @@ pub const Expect = struct { pub fn finalize( this: *Expect, ) callconv(.C) void { - VirtualMachine.vm.allocator.destroy(this); + VirtualMachine.get().allocator.destroy(this); } pub fn call(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSC.JSValue { @@ -1201,7 +1201,7 @@ pub const TestScope = struct { exception: js.ExceptionRef, is_only: bool, ) js.JSObjectRef { - var args = bun.cast([]const JSC.JSValue, arguments[0..@minimum(arguments.len, 2)]); + var args = bun.cast([]const JSC.JSValue, arguments[0..@min(arguments.len, 2)]); var label: string = ""; if (args.len == 0) { return this; @@ -1290,7 +1290,7 @@ pub const TestScope = struct { task: *TestRunnerTask, ) Result { if (comptime is_bindgen) return undefined; - var vm = VirtualMachine.vm; + var vm = VirtualMachine.get(); var callback = this.callback; defer { js.JSValueUnprotect(vm.global, callback); @@ -1325,7 +1325,7 @@ pub const TestScope = struct { if (initial_value.jsType() == .JSPromise) { if (this.promise != null) { - return .{ .pending = .{} }; + return .{ .pending = {} }; } var promise: *JSC.JSPromise = initial_value.asPromise().?; @@ -1430,13 +1430,13 @@ pub const DescribeScope = struct { pub threadlocal var active: *DescribeScope = undefined; pub threadlocal var module: *DescribeScope = undefined; - const CallbackFn = fn ( - _: void, - ctx: js.JSContextRef, - _: js.JSObjectRef, - _: js.JSObjectRef, - arguments: []const js.JSValueRef, - exception: js.ExceptionRef, + const CallbackFn = *const fn ( + void, + js.JSContextRef, + js.JSObjectRef, + js.JSObjectRef, + []const js.JSValueRef, + js.ExceptionRef, ) js.JSObjectRef; fn createCallback(comptime hook: LifecycleHook) CallbackFn { @@ -1572,7 +1572,7 @@ pub const DescribeScope = struct { var result = js.JSObjectCallAsFunctionReturnValue(ctx, callback, thisObject, 0, null); if (result.asPromise() != null or result.asInternalPromise() != null) { - var vm = JSC.VirtualMachine.vm; + var vm = JSC.VirtualMachine.get(); var promise = JSInternalPromise.resolvedPromise(ctx.ptr(), result); vm.waitForPromise(promise); @@ -1864,7 +1864,7 @@ pub const TestRunnerTask = struct { } fn deinit(this: *TestRunnerTask) void { - var vm = JSC.VirtualMachine.vm; + var vm = JSC.VirtualMachine.get(); if (vm.onUnhandledRejectionCtx) |ctx| { if (ctx == @ptrCast(*anyopaque, this)) { vm.onUnhandledRejectionCtx = null; diff --git a/src/bun.js/unbounded_queue.zig b/src/bun.js/unbounded_queue.zig index fd092290d..bc609bc3b 100644 --- a/src/bun.js/unbounded_queue.zig +++ b/src/bun.js/unbounded_queue.zig @@ -19,8 +19,7 @@ pub const cache_line_length = switch (@import("builtin").target.cpu.arch) { }; pub fn UnboundedQueue(comptime T: type, comptime next_field: meta.FieldEnum(T)) type { - const next = meta.fieldInfo(T, next_field).name; - + const next_name = meta.fieldInfo(T, next_field).name; return struct { const Self = @This(); @@ -31,7 +30,7 @@ pub fn UnboundedQueue(comptime T: type, comptime next_field: meta.FieldEnum(T)) pub fn next(self: *Self.Batch.Iterator) ?*T { if (self.batch.count == 0) return null; const front = self.batch.front orelse unreachable; - self.batch.front = @field(front, next); + self.batch.front = @field(front, next_name); self.batch.count -= 1; return front; } @@ -45,6 +44,7 @@ pub fn UnboundedQueue(comptime T: type, comptime next_field: meta.FieldEnum(T)) return .{ .batch = self }; } }; + const next = next_name; pub const queue_padding_length = cache_line_length / 2; diff --git a/src/bun.js/webcore.zig b/src/bun.js/webcore.zig index 2d1605049..a2aa39382 100644 --- a/src/bun.js/webcore.zig +++ b/src/bun.js/webcore.zig @@ -19,7 +19,7 @@ pub const Alert = struct { void, .{ .name = "alert" }, .{ - .@"call" = .{ .rfn = call }, + .call = .{ .rfn = call }, }, .{}, ); @@ -41,7 +41,8 @@ pub const Alert = struct { // 2. If the method was invoked with no arguments, then let message be the empty string; otherwise, let message be the method's first argument. if (has_message) { - const allocator = std.heap.stackFallback(2048, bun.default_allocator).get(); + var state = std.heap.stackFallback(2048, bun.default_allocator); + const allocator = state.get(); const message = arguments[0].?.value().toSlice(ctx.ptr(), allocator); defer message.deinit(); @@ -87,7 +88,7 @@ pub const Confirm = struct { void, .{ .name = "confirm" }, .{ - .@"call" = .{ .rfn = call }, + .call = .{ .rfn = call }, }, .{}, ); @@ -108,7 +109,8 @@ pub const Confirm = struct { const has_message = arguments.len != 0; if (has_message) { - const allocator = std.heap.stackFallback(1024, bun.default_allocator).get(); + var state = std.heap.stackFallback(1024, bun.default_allocator); + const allocator = state.get(); // 2. Set message to the result of normalizing newlines given message. // * Not pertinent to a server runtime so we will just let the terminal handle this. @@ -179,7 +181,7 @@ pub const Prompt = struct { void, .{ .name = "prompt" }, .{ - .@"call" = .{ .rfn = call }, + .call = .{ .rfn = call }, }, .{}, ); @@ -237,7 +239,8 @@ pub const Prompt = struct { arguments: []const JSC.C.JSValueRef, _: JSC.C.ExceptionRef, ) JSC.C.JSValueRef { - var allocator = std.heap.stackFallback(2048, bun.default_allocator).get(); + var state = std.heap.stackFallback(2048, bun.default_allocator); + const allocator = state.get(); var output = bun.Output.writer(); const has_message = arguments.len != 0; const has_default = arguments.len >= 2; @@ -366,7 +369,7 @@ pub const Crypto = struct { .getRandomValues = JSC.DOMCall("Crypto", @This(), "getRandomValues", JSC.JSValue, JSC.DOMEffect.top), .randomUUID = JSC.DOMCall("Crypto", @This(), "randomUUID", *JSC.JSString, JSC.DOMEffect.top), .timingSafeEqual = JSC.DOMCall("Crypto", @This(), "timingSafeEqual", JSC.JSValue, JSC.DOMEffect.top), - .scryptSync = .{ .rfn = JSC.wrapWithHasContainer(Crypto, "scryptSync", false, false, false) }, + .scryptSync = .{ .rfn = &JSC.wrapWithHasContainer(Crypto, "scryptSync", false, false, false) }, }, .{}, ); diff --git a/src/bun.js/webcore/encoding.zig b/src/bun.js/webcore/encoding.zig index c3444c71f..9573b1f3a 100644 --- a/src/bun.js/webcore/encoding.zig +++ b/src/bun.js/webcore/encoding.zig @@ -248,7 +248,7 @@ comptime { /// https://encoding.spec.whatwg.org/encodings.json pub const EncodingLabel = enum { @"UTF-8", - @"IBM866", + IBM866, @"ISO-8859-2", @"ISO-8859-3", @"ISO-8859-4", @@ -264,7 +264,7 @@ pub const EncodingLabel = enum { @"ISO-8859-16", @"KOI8-R", @"KOI8-U", - @"macintosh", + macintosh, @"windows-874", @"windows-1250", @"windows-1251", @@ -279,10 +279,10 @@ pub const EncodingLabel = enum { @"windows-1257", @"windows-1258", @"x-mac-cyrillic", - @"Big5", + Big5, @"EUC-JP", @"ISO-2022-JP", - @"Shift_JIS", + Shift_JIS, @"EUC-KR", @"UTF-16BE", @"UTF-16LE", @@ -402,7 +402,7 @@ pub const TextDecoder = struct { scratch_memory: []u8 = &[_]u8{}, ignore_bom: bool = false, fatal: bool = false, - encoding: EncodingLabel = EncodingLabel.utf8, + encoding: EncodingLabel = EncodingLabel.@"UTF-8", pub fn finalize(this: *TextDecoder) callconv(.C) void { bun.default_allocator.destroy(this); @@ -499,7 +499,7 @@ pub const TextDecoder = struct { var buffer = std.ArrayListAlignedUnmanaged(u16, @alignOf(@TypeOf(slice.ptr))){}; // copy the allocator to reduce the number of threadlocal accesses - const allocator = VirtualMachine.vm.allocator; + const allocator = VirtualMachine.get().allocator; buffer.ensureTotalCapacity(allocator, slice.len) catch unreachable; buffer.items.len = i; @@ -560,7 +560,7 @@ pub const TextDecoder = struct { } } - var full = buffer.toOwnedSlice(allocator); + var full = buffer.toOwnedSlice(allocator) catch @panic("TODO"); var out = ZigString.init(""); out.ptr = @ptrCast([*]u8, full.ptr); @@ -587,7 +587,7 @@ pub const TextDecoder = struct { } switch (this.encoding) { - EncodingLabel.@"latin1" => { + EncodingLabel.latin1 => { return ZigString.init(array_buffer.byteSlice()).toValueGC(globalThis); }, EncodingLabel.@"UTF-8" => { @@ -608,10 +608,6 @@ pub const TextDecoder = struct { globalThis.throw("Out of memory", .{}); return JSValue.zero; }, - else => { - globalThis.throw("Unknown error", .{}); - return JSValue.zero; - }, } } } else { @@ -625,10 +621,6 @@ pub const TextDecoder = struct { globalThis.throw("Out of memory", .{}); return JSValue.zero; }, - else => { - globalThis.throw("Unknown error", .{}); - return JSValue.zero; - }, } } } @@ -654,7 +646,7 @@ pub const TextDecoder = struct { pub fn decodeWithoutTypeChecks(this: *TextDecoder, globalThis: *JSC.JSGlobalObject, uint8array: *JSC.JSUint8Array) callconv(.C) JSValue { const buffer_slice = uint8array.slice(); switch (this.encoding) { - EncodingLabel.@"latin1" => { + EncodingLabel.latin1 => { return ZigString.init(buffer_slice).toValueGC(globalThis); }, EncodingLabel.@"UTF-8" => { @@ -673,10 +665,6 @@ pub const TextDecoder = struct { globalThis.throw("Out of memory", .{}); return JSValue.zero; }, - else => { - globalThis.throw("Unknown error", .{}); - return JSValue.zero; - }, } } } else { @@ -690,10 +678,6 @@ pub const TextDecoder = struct { globalThis.throw("Out of memory", .{}); return JSValue.zero; }, - else => { - globalThis.throw("Unknown error", .{}); - return JSValue.zero; - }, } } } @@ -852,7 +836,7 @@ pub const Encoder = struct { return ZigString.Empty.toValue(global); const input = input_ptr[0..len]; - const allocator = VirtualMachine.vm.allocator; + const allocator = VirtualMachine.get().allocator; switch (comptime encoding) { .ascii => { @@ -931,13 +915,13 @@ pub const Encoder = struct { switch (comptime encoding) { JSC.Node.Encoding.buffer => { - const written = @minimum(len, to_len); + const written = @min(len, to_len); @memcpy(to, input, written); return @intCast(i64, written); }, .latin1, .ascii => { - const written = @minimum(len, to_len); + const written = @min(len, to_len); @memcpy(to, input, written); // Hoping this gets auto vectorized @@ -972,7 +956,7 @@ pub const Encoder = struct { }, JSC.Node.Encoding.base64url => { - var slice = strings.trim(input[0..len], "\r\n\t " ++ [_]u8{std.ascii.control_code.VT}); + var slice = strings.trim(input[0..len], "\r\n\t " ++ [_]u8{std.ascii.control_code.vt}); if (slice.len == 0) return 0; @@ -1033,7 +1017,7 @@ pub const Encoder = struct { .latin1, JSC.Node.Encoding.ascii, JSC.Node.Encoding.ucs2, JSC.Node.Encoding.buffer, JSC.Node.Encoding.utf16le => { strings.copyU16IntoU8(to[0..to_len], []const u16, input[0..len]); - return @intCast(i64, @minimum(len, to_len)); + return @intCast(i64, @min(len, to_len)); }, JSC.Node.Encoding.hex => { @@ -1084,7 +1068,7 @@ pub const Encoder = struct { if (len == 0) return &[_]u8{}; - const allocator = VirtualMachine.vm.allocator; + const allocator = VirtualMachine.get().allocator; switch (comptime encoding) { JSC.Node.Encoding.buffer => { @@ -1121,7 +1105,7 @@ pub const Encoder = struct { }, JSC.Node.Encoding.base64url => { - var slice = strings.trim(input[0..len], "\r\n\t " ++ [_]u8{std.ascii.control_code.VT}); + var slice = strings.trim(input[0..len], "\r\n\t " ++ [_]u8{std.ascii.control_code.vt}); if (slice.len == 0) return &[_]u8{}; @@ -1138,7 +1122,7 @@ pub const Encoder = struct { }, JSC.Node.Encoding.base64 => { - var slice = strings.trim(input[0..len], "\r\n\t " ++ [_]u8{std.ascii.control_code.VT}); + var slice = strings.trim(input[0..len], "\r\n\t " ++ [_]u8{std.ascii.control_code.vt}); var outlen = bun.base64.decodeLen(slice); var to = allocator.alloc(u8, outlen) catch return &[_]u8{}; @@ -1153,7 +1137,7 @@ pub const Encoder = struct { if (len == 0) return &[_]u8{}; - const allocator = VirtualMachine.vm.allocator; + const allocator = VirtualMachine.get().allocator; switch (comptime encoding) { .utf8 => { diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index 333c27c40..1ed29f196 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -45,6 +45,7 @@ const StringJoiner = @import("../../string_joiner.zig"); const uws = @import("bun").uws; pub const Response = struct { + const ResponseMixin = BodyMixin(@This()); pub usingnamespace JSC.Codegen.JSResponse; allocator: std.mem.Allocator, @@ -56,6 +57,13 @@ pub const Response = struct { // We must report a consistent value for this reported_estimated_size: ?u63 = null, + pub const getText = ResponseMixin.getText; + pub const getBody = ResponseMixin.getBody; + pub const getBodyUsed = ResponseMixin.getBodyUsed; + pub const getJSON = ResponseMixin.getJSON; + pub const getArrayBuffer = ResponseMixin.getArrayBuffer; + pub const getBlob = ResponseMixin.getBlob; + pub fn estimatedSize(this: *Response) callconv(.C) usize { return this.reported_estimated_size orelse brk: { this.reported_estimated_size = @intCast( @@ -229,8 +237,6 @@ pub const Response = struct { return new_response; } - pub usingnamespace BodyMixin(@This()); - pub fn getStatus( this: *Response, _: *JSC.JSGlobalObject, @@ -319,7 +325,7 @@ pub const Response = struct { .init = Body.Init{ .status_code = 200, }, - .value = Body.Value.empty, + .value = .{ .Empty = {} }, }, .allocator = getAllocator(globalThis), .url = "", @@ -351,7 +357,7 @@ pub const Response = struct { if (args.nextEat()) |init| { if (init.isUndefinedOrNull()) {} else if (init.isNumber()) { - response.body.init.status_code = @intCast(u16, @minimum(@maximum(0, init.toInt32()), std.math.maxInt(u16))); + response.body.init.status_code = @intCast(u16, @min(@max(0, init.toInt32()), std.math.maxInt(u16))); } else { if (Body.Init.init(getAllocator(globalThis), globalThis, init, init.jsType()) catch null) |_init| { response.body.init = _init; @@ -380,7 +386,7 @@ pub const Response = struct { .init = Body.Init{ .status_code = 302, }, - .value = Body.Value.empty, + .value = .{ .Empty = {} }, }, .allocator = getAllocator(globalThis), .url = "", @@ -397,7 +403,7 @@ pub const Response = struct { if (args.nextEat()) |init| { if (init.isUndefinedOrNull()) {} else if (init.isNumber()) { - response.body.init.status_code = @intCast(u16, @minimum(@maximum(0, init.toInt32()), std.math.maxInt(u16))); + response.body.init.status_code = @intCast(u16, @min(@max(0, init.toInt32()), std.math.maxInt(u16))); } else { if (Body.Init.init(getAllocator(globalThis), globalThis, init, init.jsType()) catch null) |_init| { response.body.init = _init; @@ -424,7 +430,7 @@ pub const Response = struct { .init = Body.Init{ .status_code = 0, }, - .value = Body.Value.empty, + .value = .{ .Empty = {} }, }, .allocator = getAllocator(globalThis), .url = "", @@ -541,7 +547,7 @@ pub const Fetch = struct { void, .{ .name = "fetch" }, .{ - .@"call" = .{ + .call = .{ .rfn = Fetch.call, .ts = d.ts{}, }, @@ -854,7 +860,8 @@ pub const Fetch = struct { } if (options.fastGet(ctx.ptr(), .body)) |body__| { - if (Body.Value.fromJS(ctx.ptr(), body__)) |*body_value| { + if (Body.Value.fromJS(ctx.ptr(), body__)) |body_const| { + var body_value = body_const; // TODO: buffer ReadableStream? // we have to explicitly check for InternalBlob body = body_value.useAsAnyBlob(); @@ -1883,7 +1890,7 @@ pub const Blob = struct { return this.opened_fd; } - pub const OpenCallback = fn (*This, bun.FileDescriptor) void; + pub const OpenCallback = *const fn (*This, bun.FileDescriptor) void; pub fn getFd(this: *This, comptime Callback: OpenCallback) void { if (this.opened_fd != null_fd) { @@ -1898,7 +1905,7 @@ pub const Blob = struct { } } - const WrappedOpenCallback = fn (*State, *HTTPClient.NetworkThread.Completion, AsyncIO.OpenError!bun.FileDescriptor) void; + const WrappedOpenCallback = *const fn (*State, *HTTPClient.NetworkThread.Completion, AsyncIO.OpenError!bun.FileDescriptor) void; fn OpenCallbackWrapper(comptime Callback: OpenCallback) WrappedOpenCallback { return struct { const callback = Callback; @@ -2014,7 +2021,7 @@ pub const Blob = struct { }; pub const ResultType = SystemError.Maybe(Read); - pub const OnReadFileCallback = fn (ctx: *anyopaque, bytes: ResultType) void; + pub const OnReadFileCallback = *const fn (ctx: *anyopaque, bytes: ResultType) void; pub usingnamespace FileOpenerMixin(ReadFile); pub usingnamespace FileCloserMixin(ReadFile); @@ -2069,7 +2076,7 @@ pub const Blob = struct { onRead, &this.read_completion, this.opened_fd, - remaining[0..@minimum(remaining.len, this.max_length - this.read_off)], + remaining[0..@min(remaining.len, this.max_length - this.read_off)], this.offset + this.read_off, ); } @@ -2155,7 +2162,7 @@ pub const Blob = struct { const file = &this.file_store; const needs_close = fd != null_fd and file.pathlike == .path and fd > 2; - this.size = @maximum(this.read_len, this.size); + this.size = @max(this.read_len, this.size); if (needs_close) { this.doClose(); @@ -2190,8 +2197,8 @@ pub const Blob = struct { } if (stat.size > 0 and std.os.S.ISREG(stat.mode)) { - this.size = @minimum( - @truncate(SizeType, @intCast(SizeType, @maximum(@intCast(i64, stat.size), 0))), + this.size = @min( + @truncate(SizeType, @intCast(SizeType, @max(@intCast(i64, stat.size), 0))), this.max_length, ); // read up to 4k at a time if @@ -2232,7 +2239,7 @@ pub const Blob = struct { fn doReadLoop(this: *ReadFile) void { this.read_off += this.read_len; - var remain = this.buffer[@minimum(this.read_off, @truncate(Blob.SizeType, this.buffer.len))..]; + var remain = this.buffer[@min(this.read_off, @truncate(Blob.SizeType, this.buffer.len))..]; if (remain.len > 0 and this.errno == null) { this.doRead(); @@ -2262,7 +2269,7 @@ pub const Blob = struct { wrote: usize = 0, pub const ResultType = SystemError.Maybe(SizeType); - pub const OnWriteFileCallback = fn (ctx: *anyopaque, count: ResultType) void; + pub const OnWriteFileCallback = *const fn (ctx: *anyopaque, count: ResultType) void; pub usingnamespace FileOpenerMixin(WriteFile); pub usingnamespace FileCloserMixin(WriteFile); @@ -2404,7 +2411,7 @@ pub const Blob = struct { var file_offset = this.file_blob.offset; const this_tick = file_offset + this.wrote; - remain = remain[@minimum(this.wrote, remain.len)..]; + remain = remain[@min(this.wrote, remain.len)..]; if (remain.len > 0 and this.errno == null) { this.doWrite(remain, this_tick); @@ -2452,7 +2459,7 @@ pub const Blob = struct { pub const ResultType = anyerror!SizeType; - pub const Callback = fn (ctx: *anyopaque, len: ResultType) void; + pub const Callback = *const fn (ctx: *anyopaque, len: ResultType) void; pub const CopyFilePromiseTask = JSC.ConcurrentPromiseTask(CopyFile); pub const CopyFilePromiseTaskEventLoopTask = CopyFilePromiseTask.EventLoopTask; @@ -2815,7 +2822,7 @@ pub const Blob = struct { } if (stat.size != 0) { - this.max_length = @maximum(@minimum(@intCast(SizeType, stat.size), this.max_length), this.offset) - this.offset; + this.max_length = @max(@min(@intCast(SizeType, stat.size), this.max_length), this.offset) - this.offset; if (this.max_length == 0) { this.doClose(); return; @@ -2967,7 +2974,7 @@ pub const Blob = struct { return JSValue.jsUndefined(); } - recommended_chunk_size = @intCast(SizeType, @maximum(0, @truncate(i52, arguments[0].toInt64()))); + recommended_chunk_size = @intCast(SizeType, @max(0, @truncate(i52, arguments[0].toInt64()))); } return JSC.WebCore.ReadableStream.fromBlob( globalThis, @@ -3133,10 +3140,10 @@ pub const Blob = struct { const start = start_.toInt64(); if (start < 0) { // If the optional start parameter is negative, let relativeStart be start + size. - relativeStart = @intCast(i64, @maximum(start + @intCast(i64, this.size), 0)); + relativeStart = @intCast(i64, @max(start + @intCast(i64, this.size), 0)); } else { // Otherwise, let relativeStart be start. - relativeStart = @minimum(@intCast(i64, start), @intCast(i64, this.size)); + relativeStart = @min(@intCast(i64, start), @intCast(i64, this.size)); } } @@ -3145,10 +3152,10 @@ pub const Blob = struct { // If end is negative, let relativeEnd be max((size + end), 0). if (end < 0) { // If the optional start parameter is negative, let relativeStart be start + size. - relativeEnd = @intCast(i64, @maximum(end + @intCast(i64, this.size), 0)); + relativeEnd = @intCast(i64, @max(end + @intCast(i64, this.size), 0)); } else { // Otherwise, let relativeStart be start. - relativeEnd = @minimum(@intCast(i64, end), @intCast(i64, this.size)); + relativeEnd = @min(@intCast(i64, end), @intCast(i64, this.size)); } } @@ -3164,7 +3171,7 @@ pub const Blob = struct { } } - const len = @intCast(SizeType, @maximum(relativeEnd - relativeStart, 0)); + const len = @intCast(SizeType, @max(relativeEnd - relativeStart, 0)); // This copies over the is_all_ascii flag // which is okay because this will only be a <= slice @@ -3235,7 +3242,7 @@ pub const Blob = struct { const offset = this.offset; const store_size = store.size(); if (store_size != Blob.max_size) { - this.offset = @minimum(store_size, offset); + this.offset = @min(store_size, offset); this.size = store_size - offset; } @@ -3247,7 +3254,7 @@ pub const Blob = struct { switch (JSC.Node.Syscall.stat(store.data.file.pathlike.path.sliceZ(&buffer))) { .result => |stat| { store.data.file.max_size = if (std.os.S.ISREG(stat.mode) or stat.size > 0) - @truncate(SizeType, @intCast(u64, @maximum(stat.size, 0))) + @truncate(SizeType, @intCast(u64, @max(stat.size, 0))) else Blob.max_size; store.data.file.mode = stat.mode; @@ -3260,7 +3267,7 @@ pub const Blob = struct { switch (JSC.Node.Syscall.fstat(store.data.file.pathlike.fd)) { .result => |stat| { store.data.file.max_size = if (std.os.S.ISREG(stat.mode) or stat.size > 0) - @truncate(SizeType, @intCast(u64, @maximum(stat.size, 0))) + @truncate(SizeType, @intCast(u64, @max(stat.size, 0))) else Blob.max_size; store.data.file.mode = stat.mode; @@ -3276,7 +3283,7 @@ pub const Blob = struct { const store_size = store.data.file.max_size; const offset = this.offset; - this.offset = @minimum(store_size, offset); + this.offset = @min(store_size, offset); this.size = store_size -| offset; return; } @@ -3457,7 +3464,7 @@ pub const Blob = struct { if (slice_.len == 0) return ""; slice_ = slice_[this.offset..]; - return slice_[0..@minimum(slice_.len, @as(usize, this.size))]; + return slice_[0..@min(slice_.len, @as(usize, this.size))]; } pub const Lifetime = JSC.WebCore.Lifetime; @@ -3488,7 +3495,7 @@ pub const Blob = struct { .result => |result| { const bytes = result.buf; if (blob.size > 0) - blob.size = @minimum(@truncate(u32, bytes.len), blob.size); + blob.size = @min(@truncate(u32, bytes.len), blob.size); const value = Function(&blob, globalThis, bytes, .temporary); // invalid JSON needs to be rejected @@ -4322,7 +4329,7 @@ pub const InlineBlob = extern struct { // https://developer.mozilla.org/en-US/docs/Web/API/Body pub const Body = struct { init: Init = Init{ .headers = null, .status_code = 200 }, - value: Value = Value.empty, + value: Value, // = Value.empty, pub inline fn len(this: *const Body) Blob.SizeType { return this.value.size(); @@ -4465,13 +4472,13 @@ pub const Body = struct { task: ?*anyopaque = null, /// runs after the data is available. - onReceiveValue: ?fn (ctx: *anyopaque, value: *Value) void = null, + onReceiveValue: ?*const fn (ctx: *anyopaque, value: *Value) void = null, /// conditionally runs when requesting data /// used in HTTP server to ignore request bodies unless asked for it - onStartBuffering: ?fn (ctx: *anyopaque) void = null, + onStartBuffering: ?*const fn (ctx: *anyopaque) void = null, - onStartStreaming: ?fn (ctx: *anyopaque) JSC.WebCore.DrainResult = null, + onStartStreaming: ?*const fn (ctx: *anyopaque) JSC.WebCore.DrainResult = null, deinit: bool = false, action: Action = Action.none, @@ -4623,7 +4630,7 @@ pub const Body = struct { Error, }; - pub const empty = Value{ .Empty = .{} }; + // pub const empty = Value{ .Empty = void{} }; pub fn toReadableStream(this: *Value, globalThis: *JSGlobalObject) JSValue { JSC.markBinding(@src()); @@ -4956,7 +4963,7 @@ pub const Body = struct { .Blob => { var new_blob = this.Blob; std.debug.assert(new_blob.allocator == null); // owned by Body - this.* = .{ .Used = .{} }; + this.* = .{ .Used = {} }; return new_blob; }, .InternalBlob => { @@ -4966,13 +4973,13 @@ pub const Body = struct { // we have to use the default allocator // even if it was actually allocated on a different thread bun.default_allocator, - JSC.VirtualMachine.vm.global, + JSC.VirtualMachine.get().global, ); if (this.InternalBlob.was_string) { new_blob.content_type = MimeType.text.value; } - this.* = .{ .Used = .{} }; + this.* = .{ .Used = {} }; return new_blob; }, // .InlineBlob => { @@ -4980,11 +4987,11 @@ pub const Body = struct { // const new_blob = Blob.create( // cloned[0..this.InlineBlob.len], // bun.default_allocator, - // JSC.VirtualMachine.vm.global, + // JSC.VirtualMachine.get().global, // this.InlineBlob.was_string, // ); - // this.* = .{ .Used = .{} }; + // this.* = .{ .Used = {} }; // return new_blob; // }, else => { @@ -5002,7 +5009,7 @@ pub const Body = struct { else => return null, }; - this.* = .{ .Used = .{} }; + this.* = .{ .Used = {} }; return any_blob; } @@ -5082,16 +5089,16 @@ pub const Body = struct { if (tag == .InternalBlob) { this.InternalBlob.clearAndFree(); - this.* = Value.empty; + this.* = Value{ .Empty = {} }; //Value.empty; } if (tag == .Blob) { this.Blob.deinit(); - this.* = Value.empty; + this.* = Value{ .Empty = {} }; //Value.empty; } if (tag == .Error) { - JSC.C.JSValueUnprotect(VirtualMachine.vm.global, this.Error.asObjectRef()); + JSC.C.JSValueUnprotect(VirtualMachine.get().global, this.Error.asObjectRef()); } } @@ -5115,7 +5122,7 @@ pub const Body = struct { return Value{ .Blob = this.Blob.dupe() }; } - return Value{ .Empty = .{} }; + return Value{ .Empty = {} }; } }; @@ -5125,7 +5132,7 @@ pub const Body = struct { .headers = null, .status_code = 404, }, - .value = Value.empty, + .value = Value{ .Empty = {} }, //Value.empty, }; } @@ -5134,7 +5141,7 @@ pub const Body = struct { .init = Init{ .status_code = 200, }, - .value = Value.empty, + .value = Value{ .Empty = {} }, //Value.empty, }; } @@ -5175,6 +5182,7 @@ pub const Body = struct { init_type: JSC.JSValue.JSType, ) ?Body { var body = Body{ + .value = Value{ .Empty = {} }, .init = Init{ .headers = null, .status_code = 200 }, }; var allocator = getAllocator(globalThis); @@ -5201,7 +5209,7 @@ pub const Request = struct { url_was_allocated: bool = false, headers: ?*FetchHeaders = null, - body: Body.Value = Body.Value{ .Empty = .{} }, + body: Body.Value = Body.Value{ .Empty = {} }, method: Method = Method.GET, uws_request: ?*uws.Request = null, https: bool = false, @@ -5210,8 +5218,16 @@ pub const Request = struct { // We must report a consistent value for this reported_estimated_size: ?u63 = null, + const RequestMixin = BodyMixin(@This()); pub usingnamespace JSC.Codegen.JSRequest; + pub const getText = RequestMixin.getText; + pub const getBody = RequestMixin.getBody; + pub const getBodyUsed = RequestMixin.getBodyUsed; + pub const getJSON = RequestMixin.getJSON; + pub const getArrayBuffer = RequestMixin.getArrayBuffer; + pub const getBlob = RequestMixin.getBlob; + pub fn estimatedSize(this: *Request) callconv(.C) usize { return this.reported_estimated_size orelse brk: { this.reported_estimated_size = @truncate(u63, this.body.estimatedSize() + this.sizeOfURL() + @sizeOf(Request)); @@ -5267,7 +5283,7 @@ pub const Request = struct { pub fn fromRequestContext(ctx: *RequestContext) !Request { var req = Request{ .url = std.mem.span(ctx.getFullURL()), - .body = Body.Value.empty, + .body = .{ .Empty = {} }, .method = ctx.method, .headers = FetchHeaders.createFromPicoHeaders(ctx.request.headers), .url_was_allocated = true, @@ -5533,8 +5549,6 @@ pub const Request = struct { return &this.body; } - pub usingnamespace BodyMixin(@This()); - pub fn doClone( this: *Request, globalThis: *JSC.JSGlobalObject, @@ -5709,7 +5723,7 @@ pub const FetchEvent = struct { pending_promise: JSValue = JSValue.zero, onPromiseRejectionCtx: *anyopaque = undefined, - onPromiseRejectionHandler: ?fn (ctx: *anyopaque, err: anyerror, fetch_event: *FetchEvent, value: JSValue) void = null, + onPromiseRejectionHandler: ?*const fn (ctx: *anyopaque, err: anyerror, fetch_event: *FetchEvent, value: JSValue) void = null, rejected: bool = false, pub const Class = NewClass( @@ -5720,7 +5734,7 @@ pub const FetchEvent = struct { .ts = .{ .class = d.ts.class{ .interface = true } }, }, .{ - .@"respondWith" = .{ + .respondWith = .{ .rfn = respondWith, .ts = d.ts{ .tsdoc = "Render the response in the active HTTP request", @@ -5730,20 +5744,20 @@ pub const FetchEvent = struct { }, }, }, - .@"waitUntil" = waitUntil, + .waitUntil = waitUntil, .finalize = finalize, }, .{ - .@"client" = .{ - .@"get" = getClient, + .client = .{ + .get = getClient, .ro = true, .ts = d.ts{ .tsdoc = "HTTP client metadata. This is not implemented yet, do not use.", .@"return" = "undefined", }, }, - .@"request" = .{ - .@"get" = getRequest, + .request = .{ + .get = getRequest, .ro = true, .ts = d.ts{ .tsdoc = "HTTP request", @@ -5756,7 +5770,7 @@ pub const FetchEvent = struct { pub fn finalize( this: *FetchEvent, ) void { - VirtualMachine.vm.allocator.destroy(this); + VirtualMachine.get().allocator.destroy(this); } pub fn getClient( @@ -5877,15 +5891,15 @@ pub const FetchEvent = struct { }; defer { - if (!VirtualMachine.vm.had_errors) { + if (!VirtualMachine.get().had_errors) { Output.printElapsed(@intToFloat(f64, (request_context.timer.lap())) / std.time.ns_per_ms); Output.prettyError( " <b>{s}<r><d> - <b>{d}<r> <d>transpiled, <d><b>{d}<r> <d>imports<r>\n", .{ request_context.matched_route.?.name, - VirtualMachine.vm.transpiled_count, - VirtualMachine.vm.resolved_count, + VirtualMachine.get().transpiled_count, + VirtualMachine.get().resolved_count, }, ); } diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index 176a96655..c355ae13d 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -433,7 +433,7 @@ pub const StreamStart = union(Tag) { if (value.get(globalThis, "highWaterMark")) |chunkSize| { empty = false; - chunk_size = @intCast(JSC.WebCore.Blob.SizeType, @maximum(0, @truncate(i51, chunkSize.toInt64()))); + chunk_size = @intCast(JSC.WebCore.Blob.SizeType, @max(0, @truncate(i51, chunkSize.toInt64()))); } if (!empty) { @@ -450,7 +450,7 @@ pub const StreamStart = union(Tag) { var chunk_size: JSC.WebCore.Blob.SizeType = 0; if (value.get(globalThis, "highWaterMark")) |chunkSize| { - chunk_size = @intCast(JSC.WebCore.Blob.SizeType, @maximum(0, @truncate(i51, chunkSize.toInt64()))); + chunk_size = @intCast(JSC.WebCore.Blob.SizeType, @max(0, @truncate(i51, chunkSize.toInt64()))); } if (value.get(globalThis, "path")) |path| { @@ -486,7 +486,7 @@ pub const StreamStart = union(Tag) { if (value.get(globalThis, "highWaterMark")) |chunkSize| { empty = false; - chunk_size = @intCast(JSC.WebCore.Blob.SizeType, @maximum(256, @truncate(i51, chunkSize.toInt64()))); + chunk_size = @intCast(JSC.WebCore.Blob.SizeType, @max(256, @truncate(i51, chunkSize.toInt64()))); } if (!empty) { @@ -585,14 +585,14 @@ pub const StreamResult = union(Tag) { ctx: *anyopaque, handler: Fn, - pub const Fn = fn (ctx: *anyopaque, result: StreamResult.Writable) void; + pub const Fn = *const fn (ctx: *anyopaque, result: StreamResult.Writable) void; pub fn init(this: *Handler, comptime Context: type, ctx: *Context, comptime handler_fn: fn (*Context, StreamResult.Writable) void) void { this.ctx = ctx; this.handler = struct { const handler = handler_fn; pub fn onHandle(ctx_: *anyopaque, result: StreamResult.Writable) void { - @call(.{ .modifier = .always_inline }, handler, .{ bun.cast(*Context, ctx_), result }); + @call(.always_inline, handler, .{ bun.cast(*Context, ctx_), result }); } }.onHandle; } @@ -708,14 +708,14 @@ pub const StreamResult = union(Tag) { ctx: *anyopaque, handler: Fn, - pub const Fn = fn (ctx: *anyopaque, result: StreamResult) void; + pub const Fn = *const fn (ctx: *anyopaque, result: StreamResult) void; pub fn init(this: *Handler, comptime Context: type, ctx: *Context, comptime handler_fn: fn (*Context, StreamResult) void) void { this.ctx = ctx; this.handler = struct { const handler = handler_fn; pub fn onHandle(ctx_: *anyopaque, result: StreamResult) void { - @call(.{ .modifier = .always_inline }, handler, .{ bun.cast(*Context, ctx_), result }); + @call(.always_inline, handler, .{ bun.cast(*Context, ctx_), result }); } }.onHandle; } @@ -852,9 +852,9 @@ pub const Signal = struct { } pub const VTable = struct { - pub const OnCloseFn = fn (this: *anyopaque, err: ?Syscall.Error) void; - pub const OnReadyFn = fn (this: *anyopaque, amount: ?Blob.SizeType, offset: ?Blob.SizeType) void; - pub const OnStartFn = fn (this: *anyopaque) void; + pub const OnCloseFn = *const (fn (this: *anyopaque, err: ?Syscall.Error) void); + pub const OnReadyFn = *const (fn (this: *anyopaque, amount: ?Blob.SizeType, offset: ?Blob.SizeType) void); + pub const OnStartFn = *const (fn (this: *anyopaque) void); close: OnCloseFn, ready: OnReadyFn, start: OnStartFn, @@ -1007,11 +1007,11 @@ pub const Sink = struct { }; pub const VTable = struct { - pub const WriteUTF16Fn = fn (this: *anyopaque, data: StreamResult) StreamResult.Writable; - pub const WriteUTF8Fn = fn (this: *anyopaque, data: StreamResult) StreamResult.Writable; - pub const WriteLatin1Fn = fn (this: *anyopaque, data: StreamResult) StreamResult.Writable; - pub const EndFn = fn (this: *anyopaque, err: ?Syscall.Error) JSC.Node.Maybe(void); - pub const ConnectFn = fn (this: *anyopaque, signal: Signal) JSC.Node.Maybe(void); + pub const WriteUTF16Fn = *const (fn (this: *anyopaque, data: StreamResult) StreamResult.Writable); + pub const WriteUTF8Fn = *const (fn (this: *anyopaque, data: StreamResult) StreamResult.Writable); + pub const WriteLatin1Fn = *const (fn (this: *anyopaque, data: StreamResult) StreamResult.Writable); + pub const EndFn = *const (fn (this: *anyopaque, err: ?Syscall.Error) JSC.Node.Maybe(void)); + pub const ConnectFn = *const (fn (this: *anyopaque, signal: Signal) JSC.Node.Maybe(void)); connect: ConnectFn, write: WriteUTF8Fn, @@ -1150,9 +1150,9 @@ pub const FileSink = struct { pub fn updateRef(this: *FileSink, value: bool) void { if (this.poll_ref) |poll| { if (value) - poll.enableKeepingProcessAlive(JSC.VirtualMachine.vm) + poll.enableKeepingProcessAlive(JSC.VirtualMachine.get()) else - poll.disableKeepingProcessAlive(JSC.VirtualMachine.vm); + poll.disableKeepingProcessAlive(JSC.VirtualMachine.get()); } } @@ -1232,7 +1232,7 @@ pub const FileSink = struct { // On Linux, we can adjust the pipe size to avoid blocking. this.has_adjusted_pipe_size_on_linux = true; - switch (JSC.Node.Syscall.setPipeCapacityOnLinux(fd, @minimum(Syscall.getMaxPipeSizeOnLinux(), remain_len))) { + switch (JSC.Node.Syscall.setPipeCapacityOnLinux(fd, @min(Syscall.getMaxPipeSizeOnLinux(), remain_len))) { .result => |len| { if (len > 0) { this.max_write_size = len; @@ -1249,7 +1249,7 @@ pub const FileSink = struct { const initial = total; const fd = this.fd; var remain = buffer; - remain = remain[@minimum(this.head, remain.len)..]; + remain = remain[@min(this.head, remain.len)..]; if (remain.len == 0) return .{ .owned = 0 }; defer this.written = total; @@ -1330,7 +1330,7 @@ pub const FileSink = struct { if (max_to_write > 0) { while (remain.len > 0) { - const write_buf = remain[0..@minimum(remain.len, max_to_write)]; + const write_buf = remain[0..@min(remain.len, max_to_write)]; const res = JSC.Node.Syscall.write(fd, write_buf); if (res == .err) { @@ -1526,7 +1526,7 @@ pub const FileSink = struct { pub fn ready(this: *FileSink, writable: i64) void { var remain = this.buffer.slice(); - const pending = remain[@minimum(this.head, remain.len)..].len; + const pending = remain[@min(this.head, remain.len)..].len; if (pending == 0) { if (this.isWatching()) { this.unwatch(this.fd); @@ -1536,7 +1536,7 @@ pub const FileSink = struct { } if (comptime Environment.isMac) { - _ = this.flushMaybePollWithSizeAndBuffer(this.buffer.slice(), @intCast(usize, @maximum(writable, 0))); + _ = this.flushMaybePollWithSizeAndBuffer(this.buffer.slice(), @intCast(usize, @max(writable, 0))); } else { _ = this.flushMaybePollWithSizeAndBuffer(this.buffer.slice(), std.math.maxInt(usize)); } @@ -1852,7 +1852,7 @@ pub const ArrayBufferSink = struct { var list = this.bytes.listManaged(this.allocator); this.bytes = bun.ByteList.init(""); return ArrayBuffer.fromBytes( - list.toOwnedSlice(), + try list.toOwnedSlice(), if (as_uint8array) .Uint8Array else @@ -1871,7 +1871,7 @@ pub const ArrayBufferSink = struct { this.done = true; this.signal.close(null); return .{ .result = ArrayBuffer.fromBytes( - list.toOwnedSlice(), + list.toOwnedSlice() catch @panic("TODO"), if (this.as_uint8array) .Uint8Array else @@ -1896,7 +1896,7 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type { pub const name = std.fmt.comptimePrint("{s}", .{std.mem.span(name_)}); // This attaches it to JS - pub const SinkSignal = struct { + pub const SinkSignal = extern struct { cpp: JSValue, pub fn init(cpp: JSValue) Signal { @@ -2219,15 +2219,15 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type { } pub const Export = shim.exportFunctions(.{ - .@"finalize" = finalize, - .@"write" = write, - .@"close" = close, - .@"flush" = flush, - .@"start" = start, - .@"end" = end, - .@"construct" = construct, - .@"endWithSink" = endWithSink, - .@"updateRef" = updateRef, + .finalize = finalize, + .write = write, + .close = close, + .flush = flush, + .start = start, + .end = end, + .construct = construct, + .endWithSink = endWithSink, + .updateRef = updateRef, }); pub fn updateRef(ptr: *anyopaque, value: bool) callconv(.C) void { @@ -2332,7 +2332,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type { fn send(this: *@This(), buf: []const u8) bool { std.debug.assert(!this.done); - defer log("send: {d} bytes (backpressure: {d})", .{ buf.len, this.has_backpressure }); + defer log("send: {d} bytes (backpressure: {any})", .{ buf.len, this.has_backpressure }); if (this.requested_end and !this.res.state().isHttpWriteCalled()) { const success = this.res.tryEnd(buf, this.end_len, false); @@ -2373,7 +2373,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type { // do not write more than available // if we do, it will cause this to be delayed until the next call, each time - const to_write = @minimum(@truncate(Blob.SizeType, write_offset), @as(Blob.SizeType, this.buffer.len)); + const to_write = @min(@truncate(Blob.SizeType, write_offset), @as(Blob.SizeType, this.buffer.len)); // figure out how much data exactly to write const readable = this.readableSlice()[0..to_write]; @@ -2399,7 +2399,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type { if (!this.done and !this.requested_end and !this.hasBackpressure()) { const pending = @truncate(Blob.SizeType, write_offset) -| to_write; const written_after_flush = this.wrote - initial_wrote; - const to_report = pending - @minimum(written_after_flush, pending); + const to_report = pending - @min(written_after_flush, pending); if ((written_after_flush == initial_wrote and pending == 0) or to_report > 0) { this.signal.ready(to_report, null); @@ -2475,7 +2475,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type { } pub fn flushFromJS(this: *@This(), globalThis: *JSGlobalObject, wait: bool) JSC.Node.Maybe(JSValue) { - log("flushFromJS({s})", .{wait}); + log("flushFromJS({any})", .{wait}); if (!wait) { return this.flushFromJSNoWait(); } @@ -2667,7 +2667,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type { // In this case, it's always an error pub fn end(this: *@This(), err: ?Syscall.Error) JSC.Node.Maybe(void) { - log("end({s})", .{err}); + log("end({any})", .{err}); if (this.requested_end) { return .{ .result = {} }; @@ -2814,7 +2814,7 @@ pub fn ReadableStreamSource( comptime onStart: anytype, comptime onPull: anytype, comptime onCancel: fn (this: *Context) void, - comptime deinit: fn (this: *Context) void, + comptime deinit_fn: fn (this: *Context) void, comptime setRefUnrefFn: ?fn (this: *Context, enable: bool) void, comptime drainInternalBuffer: ?fn (this: *Context) bun.ByteList, ) type { @@ -2823,7 +2823,7 @@ pub fn ReadableStreamSource( cancelled: bool = false, deinited: bool = false, pending_err: ?Syscall.Error = null, - close_handler: ?fn (*anyopaque) void = null, + close_handler: ?*const fn (*anyopaque) void = null, close_ctx: ?*anyopaque = null, close_jsvalue: JSValue = JSValue.zero, globalThis: *JSGlobalObject = undefined, @@ -2892,7 +2892,7 @@ pub fn ReadableStreamSource( return; } this.deinited = true; - deinit(&this.context); + deinit_fn(&this.context); } pub fn getError(this: *This) ?Syscall.Error { @@ -3034,7 +3034,7 @@ pub fn ReadableStreamSource( } pub const Export = shim.exportFunctions(.{ - .@"load" = load, + .load = load, }); comptime { @@ -3066,7 +3066,7 @@ pub const ByteBlobLoader = struct { this.* = ByteBlobLoader{ .offset = blobe.offset, .store = blobe.store.?, - .chunk_size = if (user_chunk_size > 0) @minimum(user_chunk_size, blobe.size) else @minimum(1024 * 1024 * 2, blobe.size), + .chunk_size = if (user_chunk_size > 0) @min(user_chunk_size, blobe.size) else @min(1024 * 1024 * 2, blobe.size), .remain = blobe.size, .done = false, }; @@ -3086,7 +3086,7 @@ pub const ByteBlobLoader = struct { var temporary = this.store.sharedView(); temporary = temporary[this.offset..]; - temporary = temporary[0..@minimum(buffer.len, @minimum(temporary.len, this.remain))]; + temporary = temporary[0..@min(buffer.len, @min(temporary.len, this.remain))]; if (temporary.len == 0) { this.store.deref(); this.done = true; @@ -3120,7 +3120,7 @@ pub const ByteBlobLoader = struct { pub fn drain(this: *ByteBlobLoader) bun.ByteList { var temporary = this.store.sharedView(); temporary = temporary[this.offset..]; - temporary = temporary[0..@minimum(16384, @minimum(temporary.len, this.remain))]; + temporary = temporary[0..@min(16384, @min(temporary.len, this.remain))]; var cloned = bun.ByteList.init(temporary).listManaged(bun.default_allocator).clone() catch @panic("Out of memory"); this.offset +|= @truncate(Blob.SizeType, cloned.items.len); @@ -3141,7 +3141,7 @@ pub const ByteBlobLoader = struct { ); }; -pub const PipeFunction = fn (ctx: *anyopaque, stream: StreamResult, allocator: std.mem.Allocator) void; +pub const PipeFunction = *const fn (ctx: *anyopaque, stream: StreamResult, allocator: std.mem.Allocator) void; pub const PathOrFileDescriptor = union(enum) { path: ZigString.Slice, @@ -3202,14 +3202,14 @@ pub const ByteStream = struct { } if (this.has_received_last_chunk) { - return .{ .chunk_size = @truncate(Blob.SizeType, @minimum(1024 * 1024 * 2, this.buffer.items.len)) }; + return .{ .chunk_size = @truncate(Blob.SizeType, @min(1024 * 1024 * 2, this.buffer.items.len)) }; } if (this.highWaterMark == 0) { return .{ .ready = void{} }; } - return .{ .chunk_size = @maximum(this.highWaterMark, std.mem.page_size) }; + return .{ .chunk_size = @max(this.highWaterMark, std.mem.page_size) }; } pub fn value(this: *@This()) JSValue { @@ -3260,7 +3260,7 @@ pub const ByteStream = struct { if (this.pending.state == .pending) { std.debug.assert(this.buffer.items.len == 0); - var to_copy = this.pending_buffer[0..@minimum(chunk.len, this.pending_buffer.len)]; + var to_copy = this.pending_buffer[0..@min(chunk.len, this.pending_buffer.len)]; const pending_buffer_len = this.pending_buffer.len; std.debug.assert(to_copy.ptr != chunk.ptr); @memcpy(to_copy.ptr, chunk.ptr, to_copy.len); @@ -3347,7 +3347,7 @@ pub const ByteStream = struct { if (this.buffer.items.len > 0) { std.debug.assert(this.value() == .zero); - const to_write = @minimum( + const to_write = @min( this.buffer.items.len - this.offset, buffer.len, ); @@ -3571,7 +3571,7 @@ pub const FIFO = struct { return @as(u32, 0); } - return @intCast(u32, @maximum(len, 0)); + return @intCast(u32, @max(len, 0)); } pub fn adjustPipeCapacityOnLinux(this: *FIFO, current: usize, max: usize) void { @@ -3579,7 +3579,7 @@ pub const FIFO = struct { if (!this.has_adjusted_pipe_size_on_linux) { if (current > 0 and max >= std.mem.page_size * 16) { this.has_adjusted_pipe_size_on_linux = true; - _ = Syscall.setPipeCapacityOnLinux(this.fd, @minimum(max * 4, Syscall.getMaxPipeSizeOnLinux())); + _ = Syscall.setPipeCapacityOnLinux(this.fd, @min(max * 4, Syscall.getMaxPipeSizeOnLinux())); } } } @@ -3668,7 +3668,7 @@ pub const FIFO = struct { } if (size_or_offset != std.math.maxInt(@TypeOf(size_or_offset))) - this.to_read = @intCast(u32, @maximum(size_or_offset, 0)); + this.to_read = @intCast(u32, @max(size_or_offset, 0)); return this.to_read; } @@ -3909,11 +3909,11 @@ pub const File = struct { return if (this.remaining_bytes > 0 and this.isSeekable()) if (available_to_read != std.math.maxInt(usize)) - @minimum(chunk_size, available_to_read) + @min(chunk_size, available_to_read) else - @minimum(this.remaining_bytes -| this.total_read, chunk_size) + @min(this.remaining_bytes -| this.total_read, chunk_size) else - @minimum(available_to_read, chunk_size); + @min(available_to_read, chunk_size); } pub fn start( @@ -4044,7 +4044,7 @@ pub const File = struct { this.pending.result = .{ .err = Syscall.Error{ // this is too hacky - .errno = @truncate(Syscall.Error.Int, @intCast(u16, @maximum(1, @errorToInt(err)))), + .errno = @truncate(Syscall.Error.Int, @intCast(u16, @max(1, @errorToInt(err)))), .syscall = .read, }, }; @@ -4062,7 +4062,7 @@ pub const File = struct { var remaining = this.buf[this.concurrent.read..]; while (remaining.len > 0) { - const to_read = @minimum(@as(usize, this.concurrent.chunk_size), remaining.len); + const to_read = @min(@as(usize, this.concurrent.chunk_size), remaining.len); switch (Syscall.read(this.fd, remaining[0..to_read])) { .err => |err| { const retry = std.os.E.AGAIN; @@ -4503,9 +4503,9 @@ pub const FileReader = struct { }, .File => { if (value) - this.lazy_readable.readable.File.poll_ref.ref(JSC.VirtualMachine.vm) + this.lazy_readable.readable.File.poll_ref.ref(JSC.VirtualMachine.get()) else - this.lazy_readable.readable.File.poll_ref.unref(JSC.VirtualMachine.vm); + this.lazy_readable.readable.File.poll_ref.unref(JSC.VirtualMachine.get()); }, } } @@ -4570,14 +4570,14 @@ pub fn NewReadyWatcher( const fd = @intCast(c_int, fd_); std.debug.assert(@intCast(c_int, this.poll_ref.?.fd) == fd); std.debug.assert( - this.poll_ref.?.unregister(JSC.VirtualMachine.vm.uws_event_loop.?) == .result, + this.poll_ref.?.unregister(JSC.VirtualMachine.get().uws_event_loop.?) == .result, ); } pub fn pollRef(this: *Context) *JSC.FilePoll { return this.poll_ref orelse brk: { this.poll_ref = JSC.FilePoll.init( - JSC.VirtualMachine.vm, + JSC.VirtualMachine.get(), this.fd, .{}, Context, @@ -4599,7 +4599,7 @@ pub fn NewReadyWatcher( const fd = @intCast(c_int, fd_); var poll_ref: *JSC.FilePoll = this.poll_ref orelse brk: { this.poll_ref = JSC.FilePoll.init( - JSC.VirtualMachine.vm, + JSC.VirtualMachine.get(), fd, .{}, Context, @@ -4609,7 +4609,7 @@ pub fn NewReadyWatcher( }; std.debug.assert(poll_ref.fd == fd); std.debug.assert(!this.isWatching()); - switch (poll_ref.register(JSC.VirtualMachine.vm.uws_event_loop.?, flag, true)) { + switch (poll_ref.register(JSC.VirtualMachine.get().uws_event_loop.?, flag, true)) { .err => |err| { bun.unreachablePanic("FilePoll.register failed: {d}", .{err.errno}); }, |