aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/api')
-rw-r--r--src/bun.js/api/FFI.h1
-rw-r--r--src/bun.js/api/bun.zig295
-rw-r--r--src/bun.js/api/bun/socket.zig16
-rw-r--r--src/bun.js/api/bun/spawn.zig4
-rw-r--r--src/bun.js/api/bun/subprocess.zig25
-rw-r--r--src/bun.js/api/ffi.zig111
-rw-r--r--src/bun.js/api/filesystem_router.zig10
-rw-r--r--src/bun.js/api/html_rewriter.zig8
-rw-r--r--src/bun.js/api/server.zig87
-rw-r--r--src/bun.js/api/transpiler.zig8
10 files changed, 298 insertions, 267 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");