aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-07-18 02:07:41 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-07-18 02:07:41 -0700
commitdf0db54c58008d2a61a0c515a8611a231ae1d541 (patch)
treed98650c81c7b71c3f1b6116319a1d72d513ae3da /src/bun.js
parent0fd493fd781cfaaa704f08751f4239dd36ec5492 (diff)
parent661355546a4658ea927bfd70698577c1db301243 (diff)
downloadbun-df0db54c58008d2a61a0c515a8611a231ae1d541.tar.gz
bun-df0db54c58008d2a61a0c515a8611a231ae1d541.tar.zst
bun-df0db54c58008d2a61a0c515a8611a231ae1d541.zip
Merge branch 'main' into jarred/brotli
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/api/JSBundler.zig4
-rw-r--r--src/bun.js/api/JSTranspiler.zig10
-rw-r--r--src/bun.js/api/bun.zig186
-rw-r--r--src/bun.js/api/bun/dns_resolver.zig24
-rw-r--r--src/bun.js/api/bun/socket.zig698
-rw-r--r--src/bun.js/api/bun/spawn.zig12
-rw-r--r--src/bun.js/api/bun/subprocess.zig36
-rw-r--r--src/bun.js/api/bun/x509.zig560
-rw-r--r--src/bun.js/api/ffi.zig16
-rw-r--r--src/bun.js/api/html_rewriter.zig2
-rw-r--r--src/bun.js/api/server.zig72
-rw-r--r--src/bun.js/api/sockets.classes.ts53
-rw-r--r--src/bun.js/base.zig50
-rw-r--r--src/bun.js/bindings/FFI.zig58
-rw-r--r--src/bun.js/bindings/JSSink.cpp2
-rw-r--r--src/bun.js/bindings/JSSink.h2
-rw-r--r--src/bun.js/bindings/Process.cpp77
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses.cpp806
-rw-r--r--src/bun.js/bindings/bindings.cpp8
-rw-r--r--src/bun.js/bindings/bindings.zig199
-rw-r--r--src/bun.js/bindings/exports.zig60
-rw-r--r--src/bun.js/bindings/generated_classes.zig78
-rw-r--r--src/bun.js/bindings/headers.h1
-rw-r--r--src/bun.js/bindings/headers.zig1
-rw-r--r--src/bun.js/bindings/napi.cpp20
-rw-r--r--src/bun.js/bindings/shimmer.zig2
-rw-r--r--src/bun.js/event_loop.zig8
-rw-r--r--src/bun.js/javascript.zig62
-rw-r--r--src/bun.js/javascript_core_c_api.zig2
-rw-r--r--src/bun.js/module_loader.zig18
-rw-r--r--src/bun.js/node/dir_iterator.zig17
-rw-r--r--src/bun.js/node/fs_events.zig2
-rw-r--r--src/bun.js/node/node_fs.zig78
-rw-r--r--src/bun.js/node/node_os.zig20
-rw-r--r--src/bun.js/node/syscall.zig106
-rw-r--r--src/bun.js/node/types.zig98
-rw-r--r--src/bun.js/test/diff_format.zig4
-rw-r--r--src/bun.js/test/expect.zig6
-rw-r--r--src/bun.js/test/jest.zig22
-rw-r--r--src/bun.js/test/pretty_format.zig34
-rw-r--r--src/bun.js/webcore.zig12
-rw-r--r--src/bun.js/webcore/blob.zig120
-rw-r--r--src/bun.js/webcore/body.zig16
-rw-r--r--src/bun.js/webcore/encoding.zig44
-rw-r--r--src/bun.js/webcore/request.zig2
-rw-r--r--src/bun.js/webcore/response.zig20
-rw-r--r--src/bun.js/webcore/streams.zig179
47 files changed, 3083 insertions, 824 deletions
diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig
index 44ceaee9d..6a821f447 100644
--- a/src/bun.js/api/JSBundler.zig
+++ b/src/bun.js/api/JSBundler.zig
@@ -533,7 +533,7 @@ pub const JSBundler = struct {
arguments_: []const js.JSValueRef,
_: js.ExceptionRef,
) js.JSValueRef {
- return build(globalThis, @ptrCast([]const JSC.JSValue, arguments_)).asObjectRef();
+ return build(globalThis, @as([]const JSC.JSValue, @ptrCast(arguments_))).asObjectRef();
}
pub const Resolve = struct {
@@ -844,7 +844,7 @@ pub const JSBundler = struct {
this.value = .{
.success = .{
- .loader = @enumFromInt(options.Loader, @intCast(u8, loader_as_int.to(i32))),
+ .loader = @as(options.Loader, @enumFromInt(@as(u8, @intCast(loader_as_int.to(i32))))),
.source_code = source_code,
},
};
diff --git a/src/bun.js/api/JSTranspiler.zig b/src/bun.js/api/JSTranspiler.zig
index 95b0eeaae..5c5bee171 100644
--- a/src/bun.js/api/JSTranspiler.zig
+++ b/src/bun.js/api/JSTranspiler.zig
@@ -85,7 +85,7 @@ const TranspilerOptions = struct {
// This is going to be hard to not leak
pub const TransformTask = struct {
input_code: ZigString = ZigString.init(""),
- protected_input_value: JSC.JSValue = @enumFromInt(JSC.JSValue, 0),
+ protected_input_value: JSC.JSValue = @as(JSC.JSValue, @enumFromInt(0)),
output_code: ZigString = ZigString.init(""),
bundler: Bundler.Bundler = undefined,
log: logger.Log,
@@ -221,7 +221,7 @@ pub const TransformTask = struct {
finish(this.output_code, this.global, promise);
if (@intFromEnum(this.protected_input_value) != 0) {
- this.protected_input_value = @enumFromInt(JSC.JSValue, 0);
+ this.protected_input_value = @as(JSC.JSValue, @enumFromInt(0));
}
this.deinit();
}
@@ -612,7 +612,7 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std
var length_iter = iter;
while (length_iter.next()) |value| {
if (value.isString()) {
- const length = @truncate(u32, value.getLength(globalThis));
+ const length = @as(u32, @truncate(value.getLength(globalThis)));
string_count += @as(u32, @intFromBool(length > 0));
total_name_buf_len += length;
}
@@ -879,7 +879,7 @@ fn getParseResult(this: *Transpiler, allocator: std.mem.Allocator, code: []const
for (res.ast.import_records.slice()) |*import| {
if (import.kind.isCommonJS()) {
import.do_commonjs_transform_in_printer = true;
- import.module_id = @truncate(u32, bun.hash(import.path.pretty));
+ import.module_id = @as(u32, @truncate(bun.hash(import.path.pretty)));
}
}
}
@@ -1218,7 +1218,7 @@ fn namedImportsToJS(
array.ensureStillAlive();
const path = JSC.ZigString.init(record.path.text).toValueGC(global);
const kind = JSC.ZigString.init(record.kind.label()).toValueGC(global);
- array.putIndex(global, @truncate(u32, i), JSC.JSValue.createObject2(global, path_label, kind_label, path, kind));
+ array.putIndex(global, @as(u32, @truncate(i)), JSC.JSValue.createObject2(global, path_label, kind_label, path, kind));
}
return array;
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig
index 97ad056e8..d63765b16 100644
--- a/src/bun.js/api/bun.zig
+++ b/src/bun.js/api/bun.zig
@@ -105,12 +105,12 @@ pub fn onImportCSS(
var writer = css_imports_buf.writer();
const offset = css_imports_buf.items.len;
css_imports_list[css_imports_list_tail] = .{
- .offset = @truncate(u32, offset),
+ .offset = @as(u32, @truncate(offset)),
.length = 0,
};
getPublicPath(resolve_result.path_pair.primary.text, origin, @TypeOf(writer), writer);
const length = css_imports_buf.items.len - offset;
- css_imports_list[css_imports_list_tail].length = @truncate(u32, length);
+ css_imports_list[css_imports_list_tail].length = @as(u32, @truncate(length));
css_imports_list_tail += 1;
}
@@ -239,7 +239,7 @@ pub fn inspect(
ZigConsoleClient.format(
.Debug,
ctx.ptr(),
- @ptrCast([*]const JSValue, arguments.ptr),
+ @as([*]const JSValue, @ptrCast(arguments.ptr)),
arguments.len,
Writer,
Writer,
@@ -303,7 +303,7 @@ pub fn registerMacro(
return js.JSValueMakeUndefined(ctx);
}
// TODO: make this faster
- const id = @truncate(i32, @intFromFloat(i64, js.JSValueToNumber(ctx, arguments[0], exception)));
+ const id = @as(i32, @truncate(@as(i64, @intFromFloat(js.JSValueToNumber(ctx, arguments[0], exception)))));
if (id == -1 or id == 0) {
JSError(getAllocator(ctx), "Internal error registering macros: invalid id", .{}, ctx, exception);
return js.JSValueMakeUndefined(ctx);
@@ -882,7 +882,7 @@ pub fn sleepSync(
return ret;
}
- std.time.sleep(@intCast(u64, milliseconds) * std.time.ns_per_ms);
+ std.time.sleep(@as(u64, @intCast(milliseconds)) * std.time.ns_per_ms);
return ret;
}
@@ -1398,21 +1398,21 @@ pub fn indexOfLine(
var offset: usize = 0;
if (arguments.len > 1) {
- offset = @intCast(
+ offset = @as(
usize,
- @max(
+ @intCast(@max(
arguments[1].to(u32),
0,
- ),
+ )),
);
}
const bytes = buffer.byteSlice();
var current_offset = offset;
- const end = @truncate(u32, bytes.len);
+ const end = @as(u32, @truncate(bytes.len));
while (current_offset < end) {
- if (strings.indexOfNewlineOrNonASCII(bytes, @truncate(u32, current_offset))) |i| {
+ if (strings.indexOfNewlineOrNonASCII(bytes, @as(u32, @truncate(current_offset)))) |i| {
const byte = bytes[i];
if (byte > 0x7F) {
current_offset += @max(strings.wtf8ByteSequenceLength(byte), 1);
@@ -1537,7 +1537,7 @@ pub const Crypto = struct {
}
pub fn hash(this: *EVP, engine: *BoringSSL.ENGINE, input: []const u8, output: []u8) ?u32 {
- var outsize: c_uint = @min(@truncate(u16, output.len), this.size());
+ var outsize: c_uint = @min(@as(u16, @truncate(output.len)), this.size());
if (BoringSSL.EVP_Digest(input.ptr, input.len, output.ptr, &outsize, this.md, engine) != 1) {
return null;
}
@@ -1546,7 +1546,7 @@ pub const Crypto = struct {
}
pub fn final(this: *EVP, engine: *BoringSSL.ENGINE, output: []u8) []const u8 {
- var outsize: u32 = @min(@truncate(u16, output.len), this.size());
+ var outsize: u32 = @min(@as(u16, @truncate(output.len)), this.size());
if (BoringSSL.EVP_DigestFinal_ex(
&this.ctx,
output.ptr,
@@ -1565,7 +1565,7 @@ pub const Crypto = struct {
}
pub fn size(this: *EVP) u16 {
- return @truncate(u16, BoringSSL.EVP_MD_CTX_size(&this.ctx));
+ return @as(u16, @truncate(BoringSSL.EVP_MD_CTX_size(&this.ctx)));
}
pub fn copy(this: *const EVP, engine: *BoringSSL.ENGINE) error{OutOfMemory}!EVP {
@@ -1683,7 +1683,7 @@ pub const Crypto = struct {
return null;
}
- algorithm.bcrypt = @intCast(u6, rounds);
+ algorithm.bcrypt = @as(u6, @intCast(rounds));
}
return algorithm;
@@ -1704,7 +1704,7 @@ pub const Crypto = struct {
return null;
}
- argon.time_cost = @intCast(u32, time_cost);
+ argon.time_cost = @as(u32, @intCast(time_cost));
}
if (value.getTruthy(globalObject, "memoryCost")) |memory_value| {
@@ -1720,7 +1720,7 @@ pub const Crypto = struct {
return null;
}
- argon.memory_cost = @intCast(u32, memory_cost);
+ argon.memory_cost = @as(u32, @intCast(memory_cost));
}
return @unionInit(Algorithm.Value, @tagName(tag), argon);
@@ -2444,7 +2444,7 @@ pub const Crypto = struct {
this: *CryptoHasher,
_: *JSC.JSGlobalObject,
) callconv(.C) JSC.JSValue {
- return JSC.JSValue.jsNumber(@truncate(u16, this.evp.size()));
+ return JSC.JSValue.jsNumber(@as(u16, @truncate(this.evp.size())));
}
pub fn getAlgorithm(
@@ -3100,12 +3100,12 @@ pub fn allocUnsafe(
) js.JSValueRef {
var args = JSC.Node.ArgumentsSlice.from(ctx.bunVM(), arguments);
- const length = @intCast(
+ const length = @as(
usize,
- @min(
+ @intCast(@min(
@max(1, (args.nextEat() orelse JSC.JSValue.jsNumber(@as(i32, 1))).toInt32()),
std.math.maxInt(i32),
- ),
+ )),
);
var bytes = bun.default_allocator.alloc(u8, length) catch {
JSC.JSError(bun.default_allocator, "OOM! Out of memory", .{}, ctx, exception);
@@ -3152,11 +3152,11 @@ pub fn mmapFile(
flags |= @as(u32, if (shared.toBoolean()) std.os.MAP.SHARED else std.os.MAP.PRIVATE);
if (opts.get(ctx.ptr(), "size")) |value| {
- map_size = @intCast(usize, value.toInt64());
+ map_size = @as(usize, @intCast(value.toInt64()));
}
if (opts.get(ctx.ptr(), "offset")) |value| {
- offset = @intCast(usize, value.toInt64());
+ offset = @as(usize, @intCast(value.toInt64()));
offset = std.mem.alignBackwardAnyAlign(offset, std.mem.page_size);
}
} else {
@@ -3172,11 +3172,11 @@ pub fn mmapFile(
},
};
- return JSC.C.JSObjectMakeTypedArrayWithBytesNoCopy(ctx, JSC.C.JSTypedArrayType.kJSTypedArrayTypeUint8Array, @ptrCast(?*anyopaque, map.ptr), map.len, struct {
+ return JSC.C.JSObjectMakeTypedArrayWithBytesNoCopy(ctx, JSC.C.JSTypedArrayType.kJSTypedArrayTypeUint8Array, @as(?*anyopaque, @ptrCast(map.ptr)), map.len, struct {
pub fn x(ptr: ?*anyopaque, size: ?*anyopaque) callconv(.C) void {
- _ = JSC.Node.Syscall.munmap(@ptrCast([*]align(std.mem.page_size) u8, @alignCast(std.mem.page_size, ptr))[0..@intFromPtr(size)]);
+ _ = JSC.Node.Syscall.munmap(@as([*]align(std.mem.page_size) u8, @ptrCast(@alignCast(ptr)))[0..@intFromPtr(size)]);
}
- }.x, @ptrFromInt(?*anyopaque, map.len), exception);
+ }.x, @as(?*anyopaque, @ptrFromInt(map.len)), exception);
}
pub fn getTranspilerConstructor(
@@ -3327,17 +3327,17 @@ pub const Hash = struct {
}
}
if (comptime std.meta.trait.isNumber(@TypeOf(function_args[0]))) {
- function_args[0] = @intCast(@TypeOf(function_args[0]), seed);
+ function_args[0] = @as(@TypeOf(function_args[0]), @intCast(seed));
function_args[1] = input;
} else {
- function_args[1] = @intCast(@TypeOf(function_args[1]), seed);
+ function_args[1] = @as(@TypeOf(function_args[1]), @intCast(seed));
function_args[0] = input;
}
const value = @call(.auto, Function, function_args);
if (@TypeOf(value) == u32) {
- return JSC.JSValue.jsNumber(@bitCast(i32, value)).asObjectRef();
+ return JSC.JSValue.jsNumber(@as(i32, @bitCast(value))).asObjectRef();
}
return JSC.JSValue.jsNumber(value).asObjectRef();
}
@@ -3443,7 +3443,7 @@ pub const Unsafe = struct {
switch (array_buffer.typed_array_type) {
.Uint16Array, .Int16Array => {
var zig_str = ZigString.init("");
- zig_str._unsafe_ptr_do_not_use = @ptrCast([*]const u8, @alignCast(@alignOf([*]align(1) const u16), array_buffer.ptr));
+ zig_str._unsafe_ptr_do_not_use = @as([*]const u8, @ptrCast(@alignCast(array_buffer.ptr)));
zig_str.len = array_buffer.len;
zig_str.markUTF16();
// the deinitializer for string causes segfaults
@@ -3766,7 +3766,7 @@ pub const Timer = struct {
var arg = args.ptr;
var i: u32 = 0;
while (i < count) : (i += 1) {
- arg[0] = JSC.JSObject.getIndex(arguments, globalThis, @truncate(u32, i));
+ arg[0] = JSC.JSObject.getIndex(arguments, globalThis, @as(u32, @truncate(i)));
arg += 1;
}
}
@@ -4365,8 +4365,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) u8, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) u8, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn @"u16"(
@@ -4374,8 +4374,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) u16, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) u16, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn @"u32"(
@@ -4383,8 +4383,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) u32, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) u32, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn ptr(
@@ -4392,8 +4392,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) u64, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) u64, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn @"i8"(
@@ -4401,8 +4401,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) i8, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) i8, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn @"i16"(
@@ -4410,8 +4410,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) i16, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) i16, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn @"i32"(
@@ -4419,8 +4419,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) i32, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) i32, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn intptr(
@@ -4428,8 +4428,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) i64, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) i64, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
@@ -4438,8 +4438,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) f32, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) f32, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
@@ -4448,8 +4448,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) f64, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) f64, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
@@ -4458,8 +4458,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) i64, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) i64, @ptrFromInt(addr)).*;
return JSValue.fromInt64NoTruncate(global, value);
}
@@ -4468,8 +4468,8 @@ pub const FFI = struct {
_: JSValue,
arguments: []const JSValue,
) JSValue {
- const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @intCast(usize, arguments[1].to(i32)) else @as(usize, 0);
- const value = @ptrFromInt(*align(1) u64, addr).*;
+ const addr = arguments[0].asPtrAddress() + if (arguments.len > 1) @as(usize, @intCast(arguments[1].to(i32))) else @as(usize, 0);
+ const value = @as(*align(1) u64, @ptrFromInt(addr)).*;
return JSValue.fromUInt64NoTruncate(global, value);
}
@@ -4479,8 +4479,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) u8, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) u8, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn u16WithoutTypeChecks(
@@ -4489,8 +4489,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) u16, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) u16, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn u32WithoutTypeChecks(
@@ -4499,8 +4499,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) u32, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) u32, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn ptrWithoutTypeChecks(
@@ -4509,8 +4509,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) u64, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) u64, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn i8WithoutTypeChecks(
@@ -4519,8 +4519,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) i8, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) i8, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn i16WithoutTypeChecks(
@@ -4529,8 +4529,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) i16, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) i16, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn i32WithoutTypeChecks(
@@ -4539,8 +4539,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) i32, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) i32, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
pub fn intptrWithoutTypeChecks(
@@ -4549,8 +4549,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) i64, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) i64, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
@@ -4560,8 +4560,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) f32, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) f32, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
@@ -4571,8 +4571,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) f64, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) f64, @ptrFromInt(addr)).*;
return JSValue.jsNumber(value);
}
@@ -4582,8 +4582,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) u64, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) u64, @ptrFromInt(addr)).*;
return JSValue.fromUInt64NoTruncate(global, value);
}
@@ -4593,8 +4593,8 @@ pub const FFI = struct {
raw_addr: i64,
offset: i32,
) callconv(.C) JSValue {
- const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @ptrFromInt(*align(1) i64, addr).*;
+ const addr = @as(usize, @intCast(raw_addr)) + @as(usize, @intCast(offset));
+ const value = @as(*align(1) i64, @ptrFromInt(addr)).*;
return JSValue.fromInt64NoTruncate(global, value);
}
@@ -4671,9 +4671,9 @@ pub const FFI = struct {
const bytei64 = off.toInt64();
if (bytei64 < 0) {
- addr -|= @intCast(usize, bytei64 * -1);
+ addr -|= @as(usize, @intCast(bytei64 * -1));
} else {
- addr += @intCast(usize, bytei64);
+ addr += @as(usize, @intCast(bytei64));
}
if (addr > @intFromPtr(array_buffer.ptr) + @as(usize, array_buffer.byte_len)) {
@@ -4719,15 +4719,15 @@ pub const FFI = struct {
// return .{ .err = JSC.toInvalidArguments("ptr must be a finite number.", .{}, globalThis) };
// }
- var addr = @bitCast(usize, num);
+ var addr = @as(usize, @bitCast(num));
if (byteOffset) |byte_off| {
if (byte_off.isNumber()) {
const off = byte_off.toInt64();
if (off < 0) {
- addr -|= @intCast(usize, off * -1);
+ addr -|= @as(usize, @intCast(off * -1));
} else {
- addr +|= @intCast(usize, off);
+ addr +|= @as(usize, @intCast(off));
}
if (addr == 0) {
@@ -4767,12 +4767,12 @@ pub const FFI = struct {
return .{ .err = JSC.toInvalidArguments("length exceeds max addressable memory. This usually means a bug in your code.", .{}, globalThis) };
}
- const length = @intCast(usize, length_i);
- return .{ .slice = @ptrFromInt([*]u8, addr)[0..length] };
+ const length = @as(usize, @intCast(length_i));
+ return .{ .slice = @as([*]u8, @ptrFromInt(addr))[0..length] };
}
}
- return .{ .slice = bun.span(@ptrFromInt([*:0]u8, addr)) };
+ return .{ .slice = bun.span(@as([*:0]u8, @ptrFromInt(addr))) };
}
fn getCPtr(value: JSValue) ?usize {
@@ -4781,7 +4781,7 @@ pub const FFI = struct {
const addr = value.asPtrAddress();
if (addr > 0) return addr;
} else if (value.isBigInt()) {
- const addr = @bitCast(u64, value.toUInt64NoTruncate());
+ const addr = @as(u64, @bitCast(value.toUInt64NoTruncate()));
if (addr > 0) {
return addr;
}
@@ -4807,11 +4807,11 @@ pub const FFI = struct {
var ctx: ?*anyopaque = null;
if (finalizationCallback) |callback_value| {
if (getCPtr(callback_value)) |callback_ptr| {
- callback = @ptrFromInt(JSC.C.JSTypedArrayBytesDeallocator, callback_ptr);
+ callback = @as(JSC.C.JSTypedArrayBytesDeallocator, @ptrFromInt(callback_ptr));
if (finalizationCtxOrPtr) |ctx_value| {
if (getCPtr(ctx_value)) |ctx_ptr| {
- ctx = @ptrFromInt(*anyopaque, ctx_ptr);
+ ctx = @as(*anyopaque, @ptrFromInt(ctx_ptr));
} else if (!ctx_value.isUndefinedOrNull()) {
return JSC.toInvalidArguments("Expected user data to be a C pointer (number or BigInt)", .{}, globalThis);
}
@@ -4821,7 +4821,7 @@ pub const FFI = struct {
}
} else if (finalizationCtxOrPtr) |callback_value| {
if (getCPtr(callback_value)) |callback_ptr| {
- callback = @ptrFromInt(JSC.C.JSTypedArrayBytesDeallocator, callback_ptr);
+ callback = @as(JSC.C.JSTypedArrayBytesDeallocator, @ptrFromInt(callback_ptr));
} else if (!callback_value.isEmptyOrUndefinedOrNull()) {
return JSC.toInvalidArguments("Expected callback to be a C pointer (number or BigInt)", .{}, globalThis);
}
@@ -4849,11 +4849,11 @@ pub const FFI = struct {
var ctx: ?*anyopaque = null;
if (finalizationCallback) |callback_value| {
if (getCPtr(callback_value)) |callback_ptr| {
- callback = @ptrFromInt(JSC.C.JSTypedArrayBytesDeallocator, callback_ptr);
+ callback = @as(JSC.C.JSTypedArrayBytesDeallocator, @ptrFromInt(callback_ptr));
if (finalizationCtxOrPtr) |ctx_value| {
if (getCPtr(ctx_value)) |ctx_ptr| {
- ctx = @ptrFromInt(*anyopaque, ctx_ptr);
+ ctx = @as(*anyopaque, @ptrFromInt(ctx_ptr));
} else if (!ctx_value.isEmptyOrUndefinedOrNull()) {
return JSC.toInvalidArguments("Expected user data to be a C pointer (number or BigInt)", .{}, globalThis);
}
@@ -4863,7 +4863,7 @@ pub const FFI = struct {
}
} else if (finalizationCtxOrPtr) |callback_value| {
if (getCPtr(callback_value)) |callback_ptr| {
- callback = @ptrFromInt(JSC.C.JSTypedArrayBytesDeallocator, callback_ptr);
+ callback = @as(JSC.C.JSTypedArrayBytesDeallocator, @ptrFromInt(callback_ptr));
} else if (!callback_value.isEmptyOrUndefinedOrNull()) {
return JSC.toInvalidArguments("Expected callback to be a C pointer (number or BigInt)", .{}, globalThis);
}
diff --git a/src/bun.js/api/bun/dns_resolver.zig b/src/bun.js/api/bun/dns_resolver.zig
index d0d4f5b7b..4d961b54c 100644
--- a/src/bun.js/api/bun/dns_resolver.zig
+++ b/src/bun.js/api/bun/dns_resolver.zig
@@ -176,7 +176,7 @@ pub fn addressToString(
switch (address.any.family) {
std.os.AF.INET => {
var self = address.in;
- const bytes = @ptrCast(*const [4]u8, &self.sa.addr);
+ const bytes = @as(*const [4]u8, @ptrCast(&self.sa.addr));
break :brk std.fmt.allocPrint(allocator, "{}.{}.{}.{}", .{
bytes[0],
bytes[1],
@@ -554,7 +554,7 @@ pub const GetAddrInfo = struct {
.list => |list| brk: {
var stack = std.heap.stackFallback(2048, globalThis.allocator());
var arena = @import("root").bun.ArenaAllocator.init(stack.get());
- const array = JSC.JSValue.createEmptyArray(globalThis, @truncate(u32, list.items.len));
+ const array = JSC.JSValue.createEmptyArray(globalThis, @as(u32, @truncate(list.items.len)));
var i: u32 = 0;
const items: []const Result = list.items;
for (items) |item| {
@@ -594,7 +594,7 @@ pub const GetAddrInfo = struct {
pub fn fromAddrInfo(addrinfo: *std.c.addrinfo) ?Result {
return Result{
- .address = std.net.Address.initPosix(@alignCast(4, addrinfo.addr orelse return null)),
+ .address = std.net.Address.initPosix(@alignCast(addrinfo.addr orelse return null)),
// no TTL in POSIX getaddrinfo()
.ttl = 0,
};
@@ -650,8 +650,8 @@ pub fn ResolveInfoRequest(comptime cares_type: type, comptime type_name: []const
request.cache = @This().CacheConfig{
.pending_cache = true,
.entry_cache = false,
- .pos_in_pending = @truncate(u5, @field(resolver.?, cache_field).indexOf(cache.new).?),
- .name_len = @truncate(u9, name.len),
+ .pos_in_pending = @as(u5, @truncate(@field(resolver.?, cache_field).indexOf(cache.new).?)),
+ .name_len = @as(u9, @truncate(name.len)),
};
cache.new.lookup = request;
}
@@ -682,7 +682,7 @@ pub fn ResolveInfoRequest(comptime cares_type: type, comptime type_name: []const
const hash = hasher.final();
return PendingCacheKey{
.hash = hash,
- .len = @truncate(u16, name.len),
+ .len = @as(u16, @truncate(name.len)),
.lookup = undefined,
};
}
@@ -751,8 +751,8 @@ pub const GetAddrInfoRequest = struct {
request.cache = CacheConfig{
.pending_cache = true,
.entry_cache = false,
- .pos_in_pending = @truncate(u5, @field(resolver.?, cache_field).indexOf(cache.new).?),
- .name_len = @truncate(u9, query.name.len),
+ .pos_in_pending = @as(u5, @truncate(@field(resolver.?, cache_field).indexOf(cache.new).?)),
+ .name_len = @as(u9, @truncate(query.name.len)),
};
cache.new.lookup = request;
}
@@ -782,7 +782,7 @@ pub const GetAddrInfoRequest = struct {
pub fn init(query: GetAddrInfo) PendingCacheKey {
return PendingCacheKey{
.hash = query.hash(),
- .len = @truncate(u16, query.name.len),
+ .len = @as(u16, @truncate(query.name.len)),
.lookup = undefined,
};
}
@@ -793,7 +793,7 @@ pub const GetAddrInfoRequest = struct {
addr_info: ?*std.c.addrinfo,
arg: ?*anyopaque,
) callconv(.C) void {
- const this = @ptrFromInt(*GetAddrInfoRequest, @intFromPtr(arg));
+ const this = @as(*GetAddrInfoRequest, @ptrFromInt(@intFromPtr(arg)));
log("getAddrInfoAsyncCallback: status={d}", .{status});
if (this.backend == .libinfo) {
@@ -1394,13 +1394,13 @@ pub const DNSResolver = struct {
poll: *JSC.FilePoll,
) void {
var channel = this.channel orelse {
- _ = this.polls.orderedRemove(@intCast(i32, poll.fd));
+ _ = this.polls.orderedRemove(@as(i32, @intCast(poll.fd)));
poll.deinit();
return;
};
channel.process(
- @intCast(i32, poll.fd),
+ @as(i32, @intCast(poll.fd)),
poll.isReadable(),
poll.isWritable(),
);
diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig
index 1d85c705c..2f35a48a5 100644
--- a/src/bun.js/api/bun/socket.zig
+++ b/src/bun.js/api/bun/socket.zig
@@ -16,6 +16,8 @@ const Which = @import("../../../which.zig");
const uws = @import("root").bun.uws;
const ZigString = JSC.ZigString;
const BoringSSL = bun.BoringSSL;
+const X509 = @import("./x509.zig");
+
// const Corker = struct {
// ptr: ?*[16384]u8 = null,
// holder: ?*anyopaque = null,
@@ -56,6 +58,79 @@ const BoringSSL = bun.BoringSSL;
// }
// };
+noinline fn getSSLException(globalThis: *JSC.JSGlobalObject, defaultMessage: []const u8) JSValue {
+ var zig_str: ZigString = ZigString.init("");
+ var output_buf: [4096]u8 = undefined;
+
+ output_buf[0] = 0;
+ var written: usize = 0;
+ var ssl_error = BoringSSL.ERR_get_error();
+ while (ssl_error != 0 and written < output_buf.len) : (ssl_error = BoringSSL.ERR_get_error()) {
+ if (written > 0) {
+ output_buf[written] = '\n';
+ written += 1;
+ }
+
+ if (BoringSSL.ERR_reason_error_string(
+ ssl_error,
+ )) |reason_ptr| {
+ const reason = std.mem.span(reason_ptr);
+ if (reason.len == 0) {
+ break;
+ }
+ @memcpy(output_buf[written..][0..reason.len], reason);
+ written += reason.len;
+ }
+
+ if (BoringSSL.ERR_func_error_string(
+ ssl_error,
+ )) |reason_ptr| {
+ const reason = std.mem.span(reason_ptr);
+ if (reason.len > 0) {
+ output_buf[written..][0.." via ".len].* = " via ".*;
+ written += " via ".len;
+ @memcpy(output_buf[written..][0..reason.len], reason);
+ written += reason.len;
+ }
+ }
+
+ if (BoringSSL.ERR_lib_error_string(
+ ssl_error,
+ )) |reason_ptr| {
+ const reason = std.mem.span(reason_ptr);
+ if (reason.len > 0) {
+ output_buf[written..][0] = ' ';
+ written += 1;
+ @memcpy(output_buf[written..][0..reason.len], reason);
+ written += reason.len;
+ }
+ }
+ }
+
+ if (written > 0) {
+ var message = output_buf[0..written];
+ zig_str = ZigString.init(std.fmt.allocPrint(bun.default_allocator, "OpenSSL {s}", .{message}) catch unreachable);
+ var encoded_str = zig_str.withEncoding();
+ encoded_str.mark();
+
+ // We shouldn't *need* to do this but it's not entirely clear.
+ BoringSSL.ERR_clear_error();
+ }
+
+ if (zig_str.len == 0) {
+ zig_str = ZigString.init(defaultMessage);
+ }
+
+ // store the exception in here
+ // toErrorInstance clones the string
+ const exception = zig_str.toErrorInstance(globalThis);
+
+ // reference it in stack memory
+ exception.ensureStillAlive();
+
+ return exception;
+}
+
fn normalizeHost(input: anytype) @TypeOf(input) {
if (input.len == 0) {
return "localhost";
@@ -66,7 +141,6 @@ fn normalizeHost(input: anytype) @TypeOf(input) {
return input;
}
-
const BinaryType = JSC.BinaryType;
const WrappedType = enum {
@@ -315,7 +389,7 @@ pub const SocketConfig = struct {
if (parsed_url.getPort()) |port_num| {
port_value = JSValue.jsNumber(port_num);
hostname_or_unix.ptr = parsed_url.hostname.ptr;
- hostname_or_unix.len = @truncate(u32, parsed_url.hostname.len);
+ hostname_or_unix.len = @as(u32, @truncate(parsed_url.hostname.len));
}
}
@@ -422,10 +496,10 @@ pub const Listener = struct {
pub fn deinit(this: UnixOrHost) void {
switch (this) {
.unix => |u| {
- bun.default_allocator.destroy(@ptrFromInt([*]u8, @intFromPtr(u.ptr)));
+ bun.default_allocator.destroy(@as([*]u8, @ptrFromInt(@intFromPtr(u.ptr))));
},
.host => |h| {
- bun.default_allocator.destroy(@ptrFromInt([*]u8, @intFromPtr(h.host.ptr)));
+ bun.default_allocator.destroy(@as([*]u8, @ptrFromInt(@intFromPtr(h.host.ptr))));
},
}
}
@@ -583,7 +657,7 @@ pub const Listener = struct {
);
// should return the assigned port
if (socket) |s| {
- connection.host.port = @intCast(u16, s.getLocalPort(ssl_enabled));
+ connection.host.port = @as(u16, @intCast(s.getLocalPort(ssl_enabled)));
}
break :brk socket;
},
@@ -963,7 +1037,7 @@ fn selectALPNCallback(
return BoringSSL.SSL_TLSEXT_ERR_NOACK;
}
- const status = BoringSSL.SSL_select_next_proto(bun.cast([*c][*c]u8, out), outlen, protos.ptr, @intCast(c_uint, protos.len), in, inlen);
+ const status = BoringSSL.SSL_select_next_proto(bun.cast([*c][*c]u8, out), outlen, protos.ptr, @as(c_uint, @intCast(protos.len)), in, inlen);
// Previous versions of Node.js returned SSL_TLSEXT_ERR_NOACK if no protocol
// match was found. This would neither cause a fatal alert nor would it result
@@ -1175,7 +1249,8 @@ fn NewSocket(comptime ssl: bool) type {
// Add SNI support for TLS (mongodb and others requires this)
if (comptime ssl) {
- var ssl_ptr: *BoringSSL.SSL = @ptrCast(*BoringSSL.SSL, socket.getNativeHandle());
+ var ssl_ptr = this.socket.ssl();
+
if (!ssl_ptr.isInitFinished()) {
if (this.server_name) |server_name| {
const host = normalizeHost(server_name);
@@ -1198,7 +1273,7 @@ fn NewSocket(comptime ssl: bool) type {
if (this.handlers.is_server) {
BoringSSL.SSL_CTX_set_alpn_select_cb(BoringSSL.SSL_get_SSL_CTX(ssl_ptr), selectALPNCallback, bun.cast(*anyopaque, this));
} else {
- _ = BoringSSL.SSL_set_alpn_protos(ssl_ptr, protos.ptr, @intCast(c_uint, protos.len));
+ _ = BoringSSL.SSL_set_alpn_protos(ssl_ptr, protos.ptr, @as(c_uint, @intCast(protos.len)));
}
}
}
@@ -1483,7 +1558,7 @@ fn NewSocket(comptime ssl: bool) type {
return .zero;
}
- this.socket.timeout(@intCast(c_uint, t));
+ this.socket.timeout(@as(c_uint, @intCast(t)));
return JSValue.jsUndefined();
}
@@ -1566,7 +1641,7 @@ fn NewSocket(comptime ssl: bool) type {
var text_buf: [512]u8 = undefined;
this.socket.remoteAddress(&buf, &length);
- const address_bytes = buf[0..@intCast(usize, length)];
+ const address_bytes = buf[0..@as(usize, @intCast(length))];
const address: std.net.Address = switch (length) {
4 => std.net.Address.initIp4(address_bytes[0..4].*, 0),
16 => std.net.Address.initIp6(address_bytes[0..16].*, 0, 0, 0),
@@ -1880,6 +1955,107 @@ fn NewSocket(comptime ssl: bool) type {
return JSValue.jsUndefined();
}
+ pub fn getTLSTicket(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ if (comptime ssl == false) {
+ return JSValue.jsUndefined();
+ }
+
+ if (this.detached) {
+ return JSValue.jsUndefined();
+ }
+
+ var ssl_ptr = this.socket.ssl();
+ const session = BoringSSL.SSL_get_session(ssl_ptr) orelse return JSValue.jsUndefined();
+ var ticket: [*c]const u8 = undefined;
+ var length: usize = 0;
+ //The pointer is only valid while the connection is in use so we need to copy it
+ BoringSSL.SSL_SESSION_get0_ticket(session, @as([*c][*c]const u8, @ptrCast(&ticket)), &length);
+
+ if (ticket == null or length == 0) {
+ return JSValue.jsUndefined();
+ }
+
+ return JSC.ArrayBuffer.createBuffer(globalObject, ticket[0..length]);
+ }
+
+ pub fn setSession(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ if (comptime ssl == false) {
+ return JSValue.jsUndefined();
+ }
+
+ if (this.detached) {
+ return JSValue.jsUndefined();
+ }
+
+ const args = callframe.arguments(1);
+
+ if (args.len < 1) {
+ globalObject.throw("Expected session to be a string, Buffer or TypedArray", .{});
+ return .zero;
+ }
+
+ const session_arg = args.ptr[0];
+ var arena: bun.ArenaAllocator = bun.ArenaAllocator.init(bun.default_allocator);
+ defer arena.deinit();
+
+ var exception_ref = [_]JSC.C.JSValueRef{null};
+ var exception: JSC.C.ExceptionRef = &exception_ref;
+ if (JSC.Node.StringOrBuffer.fromJS(globalObject, arena.allocator(), session_arg, exception)) |sb| {
+ var session_slice = sb.slice();
+ var ssl_ptr = this.socket.ssl();
+ var tmp = @as([*c]const u8, @ptrCast(session_slice.ptr));
+ const session = BoringSSL.d2i_SSL_SESSION(null, &tmp, @as(c_long, @intCast(session_slice.len))) orelse return JSValue.jsUndefined();
+ if (BoringSSL.SSL_set_session(ssl_ptr, session) != 1) {
+ globalObject.throwValue(getSSLException(globalObject, "SSL_set_session error"));
+ return .zero;
+ }
+ return JSValue.jsUndefined();
+ } else if (exception.* != null) {
+ globalObject.throwValue(JSC.JSValue.c(exception.*));
+ return .zero;
+ } else {
+ globalObject.throw("Expected session to be a string, Buffer or TypedArray", .{});
+ return .zero;
+ }
+ }
+
+ pub fn getSession(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ if (comptime ssl == false) {
+ return JSValue.jsUndefined();
+ }
+
+ if (this.detached) {
+ return JSValue.jsUndefined();
+ }
+
+ var ssl_ptr = this.socket.ssl();
+ const session = BoringSSL.SSL_get_session(ssl_ptr) orelse return JSValue.jsUndefined();
+ const size = BoringSSL.i2d_SSL_SESSION(session, null);
+ if (size <= 0) {
+ return JSValue.jsUndefined();
+ }
+
+ const buffer_size = @as(usize, @intCast(size));
+ var buffer = JSValue.createBufferFromLength(globalObject, buffer_size);
+ var buffer_ptr = @as([*c]u8, @ptrCast(buffer.asArrayBuffer(globalObject).?.ptr));
+
+ const result_size = BoringSSL.i2d_SSL_SESSION(session, &buffer_ptr);
+ std.debug.assert(result_size == size);
+ return buffer;
+ }
+
pub fn getALPNProtocol(
this: *This,
globalObject: *JSC.JSGlobalObject,
@@ -1895,7 +2071,8 @@ fn NewSocket(comptime ssl: bool) type {
var alpn_proto: [*c]const u8 = null;
var alpn_proto_len: u32 = 0;
- var ssl_ptr: *BoringSSL.SSL = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
+ var ssl_ptr = this.socket.ssl();
+
BoringSSL.SSL_get0_alpn_selected(ssl_ptr, &alpn_proto, &alpn_proto_len);
if (alpn_proto == null or alpn_proto_len == 0) {
return JSValue.jsBoolean(false);
@@ -1910,7 +2087,502 @@ fn NewSocket(comptime ssl: bool) type {
}
return ZigString.fromUTF8(slice).toValueGC(globalObject);
}
+ pub fn exportKeyingMaterial(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ if (comptime ssl == false) {
+ return JSValue.jsUndefined();
+ }
+
+ if (this.detached) {
+ return JSValue.jsUndefined();
+ }
+
+ const args = callframe.arguments(3);
+ if (args.len < 2) {
+ globalObject.throw("Expected length and label to be provided", .{});
+ return .zero;
+ }
+ const length_arg = args.ptr[0];
+ if (!length_arg.isNumber()) {
+ globalObject.throw("Expected length to be a number", .{});
+ return .zero;
+ }
+
+ const length = length_arg.coerceToInt64(globalObject);
+ if (length < 0) {
+ globalObject.throw("Expected length to be a positive number", .{});
+ return .zero;
+ }
+
+ const label_arg = args.ptr[1];
+ if (!label_arg.isString()) {
+ globalObject.throw("Expected label to be a string", .{});
+ return .zero;
+ }
+
+ var label = label_arg.toSliceOrNull(globalObject) orelse {
+ globalObject.throw("Expected label to be a string", .{});
+ return .zero;
+ };
+
+ defer label.deinit();
+ const label_slice = label.slice();
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
+
+ if (args.len > 2) {
+ const context_arg = args.ptr[2];
+
+ var arena: bun.ArenaAllocator = bun.ArenaAllocator.init(bun.default_allocator);
+ defer arena.deinit();
+
+ var exception_ref = [_]JSC.C.JSValueRef{null};
+ var exception: JSC.C.ExceptionRef = &exception_ref;
+ if (JSC.Node.StringOrBuffer.fromJS(globalObject, arena.allocator(), context_arg, exception)) |sb| {
+ const context_slice = sb.slice();
+
+ const buffer_size = @as(usize, @intCast(length));
+ var buffer = JSValue.createBufferFromLength(globalObject, buffer_size);
+ var buffer_ptr = @as([*c]u8, @ptrCast(buffer.asArrayBuffer(globalObject).?.ptr));
+
+ const result = BoringSSL.SSL_export_keying_material(ssl_ptr, buffer_ptr, buffer_size, @as([*c]const u8, @ptrCast(label_slice.ptr)), label_slice.len, @as([*c]const u8, @ptrCast(context_slice.ptr)), context_slice.len, 1);
+ if (result != 1) {
+ globalObject.throwValue(getSSLException(globalObject, "Failed to export keying material"));
+ return .zero;
+ }
+ return buffer;
+ } else if (exception.* != null) {
+ globalObject.throwValue(JSC.JSValue.c(exception.*));
+ return .zero;
+ } else {
+ globalObject.throw("Expected context to be a string, Buffer or TypedArray", .{});
+ return .zero;
+ }
+ } else {
+ const buffer_size = @as(usize, @intCast(length));
+ var buffer = JSValue.createBufferFromLength(globalObject, buffer_size);
+ var buffer_ptr = @as([*c]u8, @ptrCast(buffer.asArrayBuffer(globalObject).?.ptr));
+
+ const result = BoringSSL.SSL_export_keying_material(ssl_ptr, buffer_ptr, buffer_size, @as([*c]const u8, @ptrCast(label_slice.ptr)), label_slice.len, null, 0, 0);
+ if (result != 1) {
+ globalObject.throwValue(getSSLException(globalObject, "Failed to export keying material"));
+ return .zero;
+ }
+ return buffer;
+ }
+ }
+
+ pub fn getEphemeralKeyInfo(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ if (comptime ssl == false) {
+ return JSValue.jsNull();
+ }
+
+ if (this.detached) {
+ return JSValue.jsNull();
+ }
+
+ // only available for clients
+ if (this.handlers.is_server) {
+ return JSValue.jsNull();
+ }
+ var result = JSValue.createEmptyObject(globalObject, 3);
+
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
+ // TODO: investigate better option or compatible way to get the key
+ // this implementation follows nodejs but for BoringSSL SSL_get_server_tmp_key will always return 0
+ // wich will result in a empty object
+ // var raw_key: [*c]BoringSSL.EVP_PKEY = undefined;
+ // if (BoringSSL.SSL_get_server_tmp_key(ssl_ptr, @ptrCast([*c][*c]BoringSSL.EVP_PKEY, &raw_key)) == 0) {
+ // return result;
+ // }
+ var raw_key: [*c]BoringSSL.EVP_PKEY = BoringSSL.SSL_get_privatekey(ssl_ptr);
+ if (raw_key == null) {
+ return result;
+ }
+
+ const kid = BoringSSL.EVP_PKEY_id(raw_key);
+ const bits = BoringSSL.EVP_PKEY_bits(raw_key);
+
+ switch (kid) {
+ BoringSSL.EVP_PKEY_DH => {
+ result.put(globalObject, ZigString.static("type"), ZigString.static("DH").toValue(globalObject));
+ result.put(globalObject, ZigString.static("size"), JSValue.jsNumber(bits));
+ },
+
+ BoringSSL.EVP_PKEY_EC, BoringSSL.EVP_PKEY_X25519, BoringSSL.EVP_PKEY_X448 => {
+ var curve_name: []const u8 = undefined;
+ if (kid == BoringSSL.EVP_PKEY_EC) {
+ const ec = BoringSSL.EVP_PKEY_get1_EC_KEY(raw_key);
+ const nid = BoringSSL.EC_GROUP_get_curve_name(BoringSSL.EC_KEY_get0_group(ec));
+ const nid_str = BoringSSL.OBJ_nid2sn(nid);
+ if (nid_str != null) {
+ curve_name = nid_str[0..bun.len(nid_str)];
+ } else {
+ curve_name = "";
+ }
+ } else {
+ const kid_str = BoringSSL.OBJ_nid2sn(kid);
+ if (kid_str != null) {
+ curve_name = kid_str[0..bun.len(kid_str)];
+ } else {
+ curve_name = "";
+ }
+ }
+ result.put(globalObject, ZigString.static("type"), ZigString.static("ECDH").toValue(globalObject));
+ result.put(globalObject, ZigString.static("name"), ZigString.fromUTF8(curve_name).toValueGC(globalObject));
+ result.put(globalObject, ZigString.static("size"), JSValue.jsNumber(bits));
+ },
+ else => {},
+ }
+ return result;
+ }
+
+ pub fn getCipher(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ if (comptime ssl == false) {
+ return JSValue.jsUndefined();
+ }
+
+ if (this.detached) {
+ return JSValue.jsUndefined();
+ }
+ var result = JSValue.createEmptyObject(globalObject, 3);
+
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
+ const cipher = BoringSSL.SSL_get_current_cipher(ssl_ptr);
+ if (cipher == null) {
+ result.put(globalObject, ZigString.static("name"), JSValue.jsNull());
+ result.put(globalObject, ZigString.static("standardName"), JSValue.jsNull());
+ result.put(globalObject, ZigString.static("version"), JSValue.jsNull());
+ return result;
+ }
+
+ const name = BoringSSL.SSL_CIPHER_get_name(cipher);
+ if (name == null) {
+ result.put(globalObject, ZigString.static("name"), JSValue.jsNull());
+ } else {
+ result.put(globalObject, ZigString.static("name"), ZigString.fromUTF8(name[0..bun.len(name)]).toValueGC(globalObject));
+ }
+
+ const standard_name = BoringSSL.SSL_CIPHER_standard_name(cipher);
+ if (standard_name == null) {
+ result.put(globalObject, ZigString.static("standardName"), JSValue.jsNull());
+ } else {
+ result.put(globalObject, ZigString.static("standardName"), ZigString.fromUTF8(standard_name[0..bun.len(standard_name)]).toValueGC(globalObject));
+ }
+
+ const version = BoringSSL.SSL_CIPHER_get_version(cipher);
+ if (version == null) {
+ result.put(globalObject, ZigString.static("version"), JSValue.jsNull());
+ } else {
+ result.put(globalObject, ZigString.static("version"), ZigString.fromUTF8(version[0..bun.len(version)]).toValueGC(globalObject));
+ }
+
+ return result;
+ }
+
+ pub fn getTLSPeerFinishedMessage(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ if (comptime ssl == false) {
+ return JSValue.jsUndefined();
+ }
+
+ if (this.detached) {
+ return JSValue.jsUndefined();
+ }
+
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
+ // We cannot just pass nullptr to SSL_get_peer_finished()
+ // because it would further be propagated to memcpy(),
+ // where the standard requirements as described in ISO/IEC 9899:2011
+ // sections 7.21.2.1, 7.21.1.2, and 7.1.4, would be violated.
+ // Thus, we use a dummy byte.
+ var dummy: [1]u8 = undefined;
+ const size = BoringSSL.SSL_get_peer_finished(ssl_ptr, @as(*anyopaque, @ptrCast(&dummy)), @sizeOf(@TypeOf(dummy)));
+ if (size == 0) return JSValue.jsUndefined();
+
+ const buffer_size = @as(usize, @intCast(size));
+ var buffer = JSValue.createBufferFromLength(globalObject, buffer_size);
+ var buffer_ptr = @as(*anyopaque, @ptrCast(buffer.asArrayBuffer(globalObject).?.ptr));
+
+ const result_size = BoringSSL.SSL_get_peer_finished(ssl_ptr, buffer_ptr, buffer_size);
+ std.debug.assert(result_size == size);
+ return buffer;
+ }
+
+ pub fn getTLSFinishedMessage(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ if (comptime ssl == false) {
+ return JSValue.jsUndefined();
+ }
+
+ if (this.detached) {
+ return JSValue.jsUndefined();
+ }
+
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
+ // We cannot just pass nullptr to SSL_get_finished()
+ // because it would further be propagated to memcpy(),
+ // where the standard requirements as described in ISO/IEC 9899:2011
+ // sections 7.21.2.1, 7.21.1.2, and 7.1.4, would be violated.
+ // Thus, we use a dummy byte.
+ var dummy: [1]u8 = undefined;
+ const size = BoringSSL.SSL_get_finished(ssl_ptr, @as(*anyopaque, @ptrCast(&dummy)), @sizeOf(@TypeOf(dummy)));
+ if (size == 0) return JSValue.jsUndefined();
+
+ const buffer_size = @as(usize, @intCast(size));
+ var buffer = JSValue.createBufferFromLength(globalObject, buffer_size);
+ var buffer_ptr = @as(*anyopaque, @ptrCast(buffer.asArrayBuffer(globalObject).?.ptr));
+
+ const result_size = BoringSSL.SSL_get_finished(ssl_ptr, buffer_ptr, buffer_size);
+ std.debug.assert(result_size == size);
+ return buffer;
+ }
+
+ pub fn getSharedSigalgs(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ JSC.markBinding(@src());
+ if (comptime ssl == false) {
+ return JSValue.jsNull();
+ }
+
+ if (this.detached) {
+ return JSValue.jsNull();
+ }
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
+
+ const nsig = BoringSSL.SSL_get_shared_sigalgs(ssl_ptr, 0, null, null, null, null, null);
+
+ const array = JSC.JSValue.createEmptyArray(globalObject, @as(usize, @intCast(nsig)));
+
+ for (0..@as(usize, @intCast(nsig))) |i| {
+ var hash_nid: c_int = 0;
+ var sign_nid: c_int = 0;
+ var sig_with_md: []const u8 = "";
+
+ _ = BoringSSL.SSL_get_shared_sigalgs(ssl_ptr, @as(c_int, @intCast(i)), &sign_nid, &hash_nid, null, null, null);
+ switch (sign_nid) {
+ BoringSSL.EVP_PKEY_RSA => {
+ sig_with_md = "RSA";
+ },
+ BoringSSL.EVP_PKEY_RSA_PSS => {
+ sig_with_md = "RSA-PSS";
+ },
+
+ BoringSSL.EVP_PKEY_DSA => {
+ sig_with_md = "DSA";
+ },
+
+ BoringSSL.EVP_PKEY_EC => {
+ sig_with_md = "ECDSA";
+ },
+
+ BoringSSL.NID_ED25519 => {
+ sig_with_md = "Ed25519";
+ },
+
+ BoringSSL.NID_ED448 => {
+ sig_with_md = "Ed448";
+ },
+ BoringSSL.NID_id_GostR3410_2001 => {
+ sig_with_md = "gost2001";
+ },
+
+ BoringSSL.NID_id_GostR3410_2012_256 => {
+ sig_with_md = "gost2012_256";
+ },
+ BoringSSL.NID_id_GostR3410_2012_512 => {
+ sig_with_md = "gost2012_512";
+ },
+ else => {
+ const sn_str = BoringSSL.OBJ_nid2sn(sign_nid);
+ if (sn_str != null) {
+ sig_with_md = sn_str[0..bun.len(sn_str)];
+ } else {
+ sig_with_md = "UNDEF";
+ }
+ },
+ }
+
+ const hash_str = BoringSSL.OBJ_nid2sn(hash_nid);
+ if (hash_str != null) {
+ const hash_str_len = bun.len(hash_str);
+ const hash_slice = hash_str[0..hash_str_len];
+ const buffer = bun.default_allocator.alloc(u8, sig_with_md.len + hash_str_len + 1) catch unreachable;
+ defer bun.default_allocator.free(buffer);
+
+ bun.copy(u8, buffer, sig_with_md);
+ buffer[sig_with_md.len] = '+';
+ bun.copy(u8, buffer[sig_with_md.len + 1 ..], hash_slice);
+ array.putIndex(globalObject, @as(u32, @intCast(i)), JSC.ZigString.fromUTF8(buffer).toValueGC(globalObject));
+ } else {
+ const buffer = bun.default_allocator.alloc(u8, sig_with_md.len + 6) catch unreachable;
+ defer bun.default_allocator.free(buffer);
+
+ bun.copy(u8, buffer, sig_with_md);
+ bun.copy(u8, buffer[sig_with_md.len..], "+UNDEF");
+ array.putIndex(globalObject, @as(u32, @intCast(i)), JSC.ZigString.fromUTF8(buffer).toValueGC(globalObject));
+ }
+ }
+ return array;
+ }
+
+ pub fn getTLSVersion(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ JSC.markBinding(@src());
+ if (comptime ssl == false) {
+ return JSValue.jsNull();
+ }
+
+ if (this.detached) {
+ return JSValue.jsNull();
+ }
+
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
+ const version = BoringSSL.SSL_get_version(ssl_ptr);
+ if (version == null) return JSValue.jsNull();
+ const version_len = bun.len(version);
+ if (version_len == 0) return JSValue.jsNull();
+ const slice = version[0..version_len];
+ return ZigString.fromUTF8(slice).toValueGC(globalObject);
+ }
+ pub fn setMaxSendFragment(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ JSC.markBinding(@src());
+ if (comptime ssl == false) {
+ return JSValue.jsBoolean(false);
+ }
+
+ if (this.detached) {
+ return JSValue.jsBoolean(false);
+ }
+
+ const args = callframe.arguments(1);
+
+ if (args.len < 1) {
+ globalObject.throw("Expected size to be a number", .{});
+ return .zero;
+ }
+
+ const arg = args.ptr[0];
+ if (!arg.isNumber()) {
+ globalObject.throw("Expected size to be a number", .{});
+ return .zero;
+ }
+ const size = args.ptr[0].coerceToInt64(globalObject);
+ if (size < 1) {
+ globalObject.throw("Expected size to be greater than 1", .{});
+ return .zero;
+ }
+ if (size > 16384) {
+ globalObject.throw("Expected size to be less than 16385", .{});
+ return .zero;
+ }
+
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
+ return JSValue.jsBoolean(BoringSSL.SSL_set_max_send_fragment(ssl_ptr, @as(usize, @intCast(size))) == 1);
+ }
+ pub fn getPeerCertificate(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ JSC.markBinding(@src());
+ if (comptime ssl == false) {
+ return JSValue.jsUndefined();
+ }
+
+ if (this.detached) {
+ return JSValue.jsUndefined();
+ }
+
+ const args = callframe.arguments(1);
+ var abbreviated: bool = true;
+ if (args.len > 0) {
+ const arg = args.ptr[0];
+ if (!arg.isBoolean()) {
+ globalObject.throw("Expected abbreviated to be a boolean", .{});
+ return .zero;
+ }
+ abbreviated = arg.toBoolean();
+ }
+
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
+
+ if (abbreviated) {
+ if (this.handlers.is_server) {
+ const cert = BoringSSL.SSL_get_peer_certificate(ssl_ptr);
+ if (cert) |x509| {
+ return X509.toJS(x509, globalObject);
+ }
+ }
+
+ const cert_chain = BoringSSL.SSL_get_peer_cert_chain(ssl_ptr) orelse return JSValue.jsUndefined();
+ const cert = BoringSSL.sk_X509_value(cert_chain, 0) orelse return JSValue.jsUndefined();
+ return X509.toJS(cert, globalObject);
+ }
+ var cert: ?*BoringSSL.X509 = null;
+ if (this.handlers.is_server) {
+ cert = BoringSSL.SSL_get_peer_certificate(ssl_ptr);
+ }
+
+ const cert_chain = BoringSSL.SSL_get_peer_cert_chain(ssl_ptr);
+ const first_cert = if (cert) |c| c else if (cert_chain) |cc| BoringSSL.sk_X509_value(cc, 0) else null;
+
+ if (first_cert == null) {
+ return JSValue.jsUndefined();
+ }
+
+ // TODO: we need to support the non abbreviated version of this
+ return JSValue.jsUndefined();
+ }
+
+ pub fn getCertificate(
+ this: *This,
+ globalObject: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ if (comptime ssl == false) {
+ return JSValue.jsUndefined();
+ }
+
+ if (this.detached) {
+ return JSValue.jsUndefined();
+ }
+
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
+ const cert = BoringSSL.SSL_get_certificate(ssl_ptr);
+
+ if (cert) |x509| {
+ return X509.toJS(x509, globalObject);
+ }
+ return JSValue.jsUndefined();
+ }
pub fn setServername(
this: *This,
globalObject: *JSC.JSGlobalObject,
@@ -1952,7 +2624,8 @@ fn NewSocket(comptime ssl: bool) type {
const host = normalizeHost(@as([]const u8, slice));
if (host.len > 0) {
- var ssl_ptr: *BoringSSL.SSL = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
+ var ssl_ptr = this.socket.ssl();
+
if (ssl_ptr.isInitFinished()) {
// match node.js exceptions
globalObject.throw("Already started.", .{});
@@ -2222,6 +2895,7 @@ pub fn NewWrappedHandler(comptime tls: bool) type {
if (comptime tls) {
TLSSocket.onData(this.tls, socket, data);
} else {
+ // tedius use this
TLSSocket.onData(this.tcp, socket, data);
}
}
diff --git a/src/bun.js/api/bun/spawn.zig b/src/bun.js/api/bun/spawn.zig
index 5de8c2265..be354c7f0 100644
--- a/src/bun.js/api/bun/spawn.zig
+++ b/src/bun.js/api/bun/spawn.zig
@@ -62,14 +62,14 @@ pub const PosixSpawn = struct {
pub fn get(self: Attr) !u16 {
var flags: c_short = undefined;
switch (errno(system.posix_spawnattr_getflags(&self.attr, &flags))) {
- .SUCCESS => return @bitCast(u16, flags),
+ .SUCCESS => return @as(u16, @bitCast(flags)),
.INVAL => unreachable,
else => |err| return unexpectedErrno(err),
}
}
pub fn set(self: *Attr, flags: u16) !void {
- switch (errno(system.posix_spawnattr_setflags(&self.attr, @bitCast(c_short, flags)))) {
+ switch (errno(system.posix_spawnattr_setflags(&self.attr, @as(c_short, @bitCast(flags))))) {
.SUCCESS => return,
.INVAL => unreachable,
else => |err| return unexpectedErrno(err),
@@ -107,7 +107,7 @@ pub const PosixSpawn = struct {
}
pub fn openZ(self: *Actions, fd: fd_t, path: [*:0]const u8, flags: u32, mode: mode_t) !void {
- switch (errno(system.posix_spawn_file_actions_addopen(&self.actions, fd, path, @bitCast(c_int, flags), mode))) {
+ switch (errno(system.posix_spawn_file_actions_addopen(&self.actions, fd, path, @as(c_int, @bitCast(flags)), mode))) {
.SUCCESS => return,
.BADF => return error.InvalidFileDescriptor,
.NOMEM => return error.SystemResources,
@@ -283,12 +283,12 @@ pub const PosixSpawn = struct {
const Status = c_int;
var status: Status = undefined;
while (true) {
- const rc = system.waitpid(pid, &status, @intCast(c_int, flags));
+ const rc = system.waitpid(pid, &status, @as(c_int, @intCast(flags)));
switch (errno(rc)) {
.SUCCESS => return Maybe(WaitPidResult){
.result = .{
- .pid = @intCast(pid_t, rc),
- .status = @bitCast(u32, status),
+ .pid = @as(pid_t, @intCast(rc)),
+ .status = @as(u32, @bitCast(status)),
},
},
.INTR => continue,
diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig
index ba813c463..1bc7f234a 100644
--- a/src/bun.js/api/bun/subprocess.zig
+++ b/src/bun.js/api/bun/subprocess.zig
@@ -201,7 +201,7 @@ pub const Subprocess = struct {
};
},
.path => Readable{ .ignore = {} },
- .blob, .fd => Readable{ .fd = @intCast(bun.FileDescriptor, fd) },
+ .blob, .fd => Readable{ .fd = @as(bun.FileDescriptor, @intCast(fd)) },
.array_buffer => Readable{
.pipe = .{
.buffer = BufferedOutput.initWithSlice(fd, stdio.array_buffer.slice()),
@@ -360,7 +360,7 @@ pub const Subprocess = struct {
}
// first appeared in Linux 5.1
- const rc = std.os.linux.pidfd_send_signal(this.pidfd, @intCast(u8, sig), null, 0);
+ const rc = std.os.linux.pidfd_send_signal(this.pidfd, @as(u8, @intCast(sig)), null, 0);
if (rc != 0) {
const errno = std.os.linux.getErrno(rc);
@@ -628,7 +628,7 @@ pub const Subprocess = struct {
},
else => {
const slice = result.slice();
- this.internal_buffer.len += @truncate(u32, slice.len);
+ this.internal_buffer.len += @as(u32, @truncate(slice.len));
if (slice.len > 0)
std.debug.assert(this.internal_buffer.contains(slice));
@@ -673,7 +673,7 @@ pub const Subprocess = struct {
if (slice.ptr == stack_buf.ptr) {
this.internal_buffer.append(auto_sizer.allocator, slice) catch @panic("out of memory");
} else {
- this.internal_buffer.len += @truncate(u32, slice.len);
+ this.internal_buffer.len += @as(u32, @truncate(slice.len));
}
if (slice.len < buf_to_use.len) {
@@ -706,7 +706,7 @@ pub const Subprocess = struct {
return;
},
.read => |slice| {
- this.internal_buffer.len += @truncate(u32, slice.len);
+ this.internal_buffer.len += @as(u32, @truncate(slice.len));
if (slice.len < buf_to_use.len) {
this.watch();
@@ -881,7 +881,7 @@ pub const Subprocess = struct {
return Writable{ .buffered_input = buffered_input };
},
.fd => {
- return Writable{ .fd = @intCast(bun.FileDescriptor, fd) };
+ return Writable{ .fd = @as(bun.FileDescriptor, @intCast(fd)) };
},
.inherit => {
return Writable{ .inherit = {} };
@@ -1303,7 +1303,7 @@ pub const Subprocess = struct {
globalThis.throw("out of memory", .{});
return .zero;
};
- env = @ptrCast(@TypeOf(env), env_array.items.ptr);
+ env = @as(@TypeOf(env), @ptrCast(env_array.items.ptr));
}
const pid = brk: {
@@ -1321,7 +1321,7 @@ pub const Subprocess = struct {
}
}
- break :brk switch (PosixSpawn.spawnZ(argv.items[0].?, actions, attr, @ptrCast([*:null]?[*:0]const u8, argv.items[0..].ptr), env)) {
+ break :brk switch (PosixSpawn.spawnZ(argv.items[0].?, actions, attr, @as([*:null]?[*:0]const u8, @ptrCast(argv.items[0..].ptr)), env)) {
.err => |err| return err.toJSC(globalThis),
.result => |pid_| pid_,
};
@@ -1329,7 +1329,7 @@ pub const Subprocess = struct {
const pidfd: std.os.fd_t = brk: {
if (Environment.isMac) {
- break :brk @intCast(std.os.fd_t, pid);
+ break :brk @as(std.os.fd_t, @intCast(pid));
}
const kernel = @import("../../../analytics.zig").GenerateHeader.GeneratePlatform.kernelVersion();
@@ -1346,7 +1346,7 @@ pub const Subprocess = struct {
);
switch (std.os.linux.getErrno(fd)) {
- .SUCCESS => break :brk @intCast(std.os.fd_t, fd),
+ .SUCCESS => break :brk @as(std.os.fd_t, @intCast(fd)),
else => |err| {
globalThis.throwValue(JSC.Node.Syscall.Error.fromCode(err, .open).toJSC(globalThis));
var status: u32 = 0;
@@ -1484,7 +1484,7 @@ pub const Subprocess = struct {
subprocess.finalizeSync();
const sync_value = JSC.JSValue.createEmptyObject(globalThis, 4);
- sync_value.put(globalThis, JSC.ZigString.static("exitCode"), JSValue.jsNumber(@intCast(i32, exitCode)));
+ sync_value.put(globalThis, JSC.ZigString.static("exitCode"), JSValue.jsNumber(@as(i32, @intCast(exitCode))));
sync_value.put(globalThis, JSC.ZigString.static("stdout"), stdout);
sync_value.put(globalThis, JSC.ZigString.static("stderr"), stderr);
sync_value.put(globalThis, JSC.ZigString.static("success"), JSValue.jsBoolean(exitCode == 0));
@@ -1531,13 +1531,13 @@ pub const Subprocess = struct {
},
.result => |result| {
if (std.os.W.IFEXITED(result.status)) {
- this.exit_code = @truncate(u8, std.os.W.EXITSTATUS(result.status));
+ this.exit_code = @as(u8, @truncate(std.os.W.EXITSTATUS(result.status)));
}
if (std.os.W.IFSIGNALED(result.status)) {
- this.signal_code = @enumFromInt(SignalCode, @truncate(u8, std.os.W.TERMSIG(result.status)));
+ this.signal_code = @as(SignalCode, @enumFromInt(@as(u8, @truncate(std.os.W.TERMSIG(result.status)))));
} else if (std.os.W.IFSTOPPED(result.status)) {
- this.signal_code = @enumFromInt(SignalCode, @truncate(u8, std.os.W.STOPSIG(result.status)));
+ this.signal_code = @as(SignalCode, @enumFromInt(@as(u8, @truncate(std.os.W.STOPSIG(result.status)))));
}
if (!this.hasExited()) {
@@ -1688,10 +1688,10 @@ pub const Subprocess = struct {
if (blob.needsToReadFile()) {
if (blob.store()) |store| {
if (store.data.file.pathlike == .fd) {
- if (store.data.file.pathlike.fd == @intCast(bun.FileDescriptor, i)) {
+ if (store.data.file.pathlike.fd == @as(bun.FileDescriptor, @intCast(i))) {
stdio_array[i] = Stdio{ .inherit = {} };
} else {
- switch (@intCast(std.os.fd_t, i)) {
+ switch (@as(std.os.fd_t, @intCast(i))) {
std.os.STDIN_FILENO => {
if (i == std.os.STDERR_FILENO or i == std.os.STDOUT_FILENO) {
globalThis.throwInvalidArguments("stdin cannot be used for stdout or stderr", .{});
@@ -1754,9 +1754,9 @@ pub const Subprocess = struct {
return false;
}
- const fd = @intCast(bun.FileDescriptor, fd_);
+ const fd = @as(bun.FileDescriptor, @intCast(fd_));
- switch (@intCast(std.os.fd_t, i)) {
+ switch (@as(std.os.fd_t, @intCast(i))) {
std.os.STDIN_FILENO => {
if (i == std.os.STDERR_FILENO or i == std.os.STDOUT_FILENO) {
globalThis.throwInvalidArguments("stdin cannot be used for stdout or stderr", .{});
diff --git a/src/bun.js/api/bun/x509.zig b/src/bun.js/api/bun/x509.zig
new file mode 100644
index 000000000..20ab16547
--- /dev/null
+++ b/src/bun.js/api/bun/x509.zig
@@ -0,0 +1,560 @@
+const BoringSSL = bun.BoringSSL;
+const bun = @import("root").bun;
+const ZigString = JSC.ZigString;
+const std = @import("std");
+const JSC = @import("root").bun.JSC;
+const JSValue = JSC.JSValue;
+const JSGlobalObject = JSC.JSGlobalObject;
+
+fn x509GetNameObject(globalObject: *JSGlobalObject, name: ?*BoringSSL.X509_NAME) JSValue {
+ const cnt = BoringSSL.X509_NAME_entry_count(name);
+ if (cnt <= 0) {
+ return JSValue.jsUndefined();
+ }
+ var result = JSValue.createEmptyObject(globalObject, 1);
+
+ for (0..@as(usize, @intCast(cnt))) |i| {
+ const entry = BoringSSL.X509_NAME_get_entry(name, @as(c_int, @intCast(i))) orelse continue;
+ // We intentionally ignore the value of X509_NAME_ENTRY_set because the
+ // representation as an object does not allow grouping entries into sets
+ // anyway, and multi-value RDNs are rare, i.e., the vast majority of
+ // Relative Distinguished Names contains a single type-value pair only.
+ const type_ = BoringSSL.X509_NAME_ENTRY_get_object(entry);
+
+ // If BoringSSL knows the type, use the short name of the type as the key, and
+ // the numeric representation of the type's OID otherwise.
+ const type_nid = BoringSSL.OBJ_obj2nid(type_);
+ var type_buf: [80]u8 = undefined;
+ var name_slice: []const u8 = undefined;
+ if (type_nid != BoringSSL.NID_undef) {
+ const type_str = BoringSSL.OBJ_nid2sn(type_nid);
+ if (type_str == null) {
+ continue;
+ }
+ name_slice = type_str[0..bun.len(type_str)];
+ } else {
+ const length = BoringSSL.OBJ_obj2txt(&type_buf, @sizeOf(@TypeOf(type_buf)), type_, 1);
+ if (length <= 0) {
+ continue;
+ }
+ name_slice = type_buf[0..@as(usize, @intCast(length))];
+ }
+
+ const value_data = BoringSSL.X509_NAME_ENTRY_get_data(entry);
+
+ var value_str: [*c]u8 = undefined;
+ const value_str_len = BoringSSL.ASN1_STRING_to_UTF8(&value_str, value_data);
+ if (value_str_len < 0) {
+ continue;
+ }
+ const value_slice = value_str[0..@as(usize, @intCast(value_str_len))];
+ defer BoringSSL.OPENSSL_free(value_str);
+ // For backward compatibility, we only create arrays if multiple values
+ // exist for the same key. That is not great but there is not much we can
+ // change here without breaking things. Note that this creates nested data
+ // structures, yet still does not allow representing Distinguished Names
+ // accurately.
+ if (result.getTruthy(globalObject, name_slice)) |value| {
+ if (value.jsType().isArray()) {
+ value.push(globalObject, JSC.ZigString.fromUTF8(value_slice).toValueGC(globalObject));
+ } else {
+ const prop_name = JSC.ZigString.fromUTF8(name_slice);
+ const array = JSValue.createEmptyArray(globalObject, 2);
+ array.putIndex(globalObject, 0, value);
+ array.putIndex(globalObject, 1, JSC.ZigString.fromUTF8(value_slice).toValueGC(globalObject));
+ result.put(globalObject, &prop_name, array);
+ }
+ } else {
+ const prop_name = JSC.ZigString.fromUTF8(name_slice);
+ result.put(globalObject, &prop_name, JSC.ZigString.fromUTF8(value_slice).toValueGC(globalObject));
+ }
+ }
+ return result;
+}
+
+inline fn isSafeAltName(name: []const u8, utf8: bool) bool {
+ for (name) |c| {
+ switch (c) {
+ '"',
+ '\\',
+ // These mess with encoding rules.
+ // Fall through.
+ ',',
+ // Commas make it impossible to split the list of subject alternative
+ // names unambiguously, which is why we have to escape.
+ // Fall through.
+ '\'',
+ => {
+ // Single quotes are unlikely to appear in any legitimate values, but they
+ // could be used to make a value look like it was escaped (i.e., enclosed
+ // in single/double quotes).
+ return false;
+ },
+ else => {
+ if (utf8) {
+ // In UTF8 strings, we require escaping for any ASCII control character,
+ // but NOT for non-ASCII characters. Note that all bytes of any code
+ // point that consists of more than a single byte have their MSB set.
+ if (c < ' ' or c == '\x7f') {
+ return false;
+ }
+ } else {
+ // Check if the char is a control character or non-ASCII character. Note
+ // that char may or may not be a signed type. Regardless, non-ASCII
+ // values will always be outside of this range.
+ if (c < ' ' or c > '~') {
+ return false;
+ }
+ }
+ },
+ }
+ }
+ return true;
+}
+
+inline fn printAltName(out: *BoringSSL.BIO, name: []const u8, utf8: bool, safe_prefix: ?[*]const u8) void {
+ if (isSafeAltName(name, utf8)) {
+ // For backward-compatibility, append "safe" names without any
+ // modifications.
+ if (safe_prefix) |prefix| {
+ _ = BoringSSL.BIO_printf(out, "%s:", prefix);
+ }
+ _ = BoringSSL.BIO_write(out, @as([*]const u8, @ptrCast(name.ptr)), @as(c_int, @intCast(name.len)));
+ } else {
+ // If a name is not "safe", we cannot embed it without special
+ // encoding. This does not usually happen, but we don't want to hide
+ // it from the user either. We use JSON compatible escaping here.
+ _ = BoringSSL.BIO_write(out, "\"", 1);
+ if (safe_prefix) |prefix| {
+ _ = BoringSSL.BIO_printf(out, "%s:", prefix);
+ }
+ for (name) |c| {
+ if (c == '\\') {
+ _ = BoringSSL.BIO_write(out, "\\\\", 2);
+ } else if (c == '"') {
+ _ = BoringSSL.BIO_write(out, "\\\"", 2);
+ } else if ((c >= ' ' and c != ',' and c <= '~') or (utf8 and (c & 0x80) != 0)) {
+ // Note that the above condition explicitly excludes commas, which means
+ // that those are encoded as Unicode escape sequences in the "else"
+ // block. That is not strictly necessary, and Node.js itself would parse
+ // it correctly either way. We only do this to account for third-party
+ // code that might be splitting the string at commas (as Node.js itself
+ // used to do).
+ _ = BoringSSL.BIO_write(out, bun.cast([*]const u8, &c), 1);
+ } else {
+ // Control character or non-ASCII character. We treat everything as
+ // Latin-1, which corresponds to the first 255 Unicode code points.
+ const hex = "0123456789abcdef";
+ const u = [_]u8{ '\\', 'u', '0', '0', hex[(c & 0xf0) >> 4], hex[c & 0x0f] };
+ _ = BoringSSL.BIO_write(out, &u, @sizeOf(@TypeOf(u)));
+ }
+ }
+ _ = BoringSSL.BIO_write(out, "\"", 1);
+ }
+}
+
+inline fn printLatin1AltName(out: *BoringSSL.BIO, name: *BoringSSL.ASN1_IA5STRING, safe_prefix: ?[*]const u8) void {
+ printAltName(out, name.data[0..@as(usize, @intCast(name.length))], false, safe_prefix);
+}
+
+inline fn printUTF8AltName(out: *BoringSSL.BIO, name: *BoringSSL.ASN1_UTF8STRING, safe_prefix: ?[*]const u8) void {
+ printAltName(out, name.data[0..@as(usize, @intCast(name.length))], true, safe_prefix);
+}
+
+pub const kX509NameFlagsRFC2253WithinUtf8JSON = BoringSSL.XN_FLAG_RFC2253 & ~BoringSSL.ASN1_STRFLGS_ESC_MSB & ~BoringSSL.ASN1_STRFLGS_ESC_CTRL;
+
+// This function emulates the behavior of i2v_GENERAL_NAME in a safer and less
+// ambiguous way. "othername:" entries use the GENERAL_NAME_print format.
+fn x509PrintGeneralName(out: *BoringSSL.BIO, name: *BoringSSL.GENERAL_NAME) bool {
+ if (name.name_type == .GEN_DNS) {
+ _ = BoringSSL.BIO_write(out, "DNS:", 4);
+ // Note that the preferred name syntax (see RFCs 5280 and 1034) with
+ // wildcards is a subset of what we consider "safe", so spec-compliant DNS
+ // names will never need to be escaped.
+ printLatin1AltName(out, name.d.dNSName, null);
+ } else if (name.name_type == .GEN_EMAIL) {
+ _ = BoringSSL.BIO_write(out, "email:", 6);
+ printLatin1AltName(out, name.d.rfc822Name, null);
+ } else if (name.name_type == .GEN_URI) {
+ _ = BoringSSL.BIO_write(out, "URI:", 4);
+ // The set of "safe" names was designed to include just about any URI,
+ // with a few exceptions, most notably URIs that contains commas (see
+ // RFC 2396). In other words, most legitimate URIs will not require
+ // escaping.
+ printLatin1AltName(out, name.d.uniformResourceIdentifier, null);
+ } else if (name.name_type == .GEN_DIRNAME) {
+ // Earlier versions of Node.js used X509_NAME_oneline to print the X509_NAME
+ // object. The format was non standard and should be avoided. The use of
+ // X509_NAME_oneline is discouraged by OpenSSL but was required for backward
+ // compatibility. Conveniently, X509_NAME_oneline produced ASCII and the
+ // output was unlikely to contains commas or other characters that would
+ // require escaping. However, it SHOULD NOT produce ASCII output since an
+ // RFC5280 AttributeValue may be a UTF8String.
+ // Newer versions of Node.js have since switched to X509_NAME_print_ex to
+ // produce a better format at the cost of backward compatibility. The new
+ // format may contain Unicode characters and it is likely to contain commas,
+ // which require escaping. Fortunately, the recently safeguarded function
+ // printAltName handles all of that safely.
+ _ = BoringSSL.BIO_printf(out, "DirName:");
+
+ const tmp = BoringSSL.BIO_new(BoringSSL.BIO_s_mem()) orelse return false;
+
+ if (BoringSSL.X509_NAME_print_ex(tmp, name.d.dirn, 0, kX509NameFlagsRFC2253WithinUtf8JSON) < 0) {
+ return false;
+ }
+ var oline: [*]const u8 = undefined;
+ const n_bytes = BoringSSL.BIO_get_mem_data(tmp, @as([*c][*c]u8, @ptrCast(&oline)));
+ if (n_bytes <= 0) return false;
+ printAltName(out, oline[0..@as(usize, @intCast(n_bytes))], true, null);
+ } else if (name.name_type == .GEN_OTHERNAME) {
+ // The format that is used here is based on OpenSSL's implementation of
+ // GENERAL_NAME_print (as of OpenSSL 3.0.1). Earlier versions of Node.js
+ // instead produced the same format as i2v_GENERAL_NAME, which was somewhat
+ // awkward, especially when passed to translatePeerCertificate.
+ var unicode: bool = true;
+ var prefix: ?[*]const u8 = null;
+
+ const nid = BoringSSL.OBJ_obj2nid(name.d.otherName.type_id);
+ switch (nid) {
+ BoringSSL.NID_id_on_SmtpUTF8Mailbox => {
+ prefix = "SmtpUTF8Mailbox";
+ },
+ BoringSSL.NID_XmppAddr => {
+ prefix = "XmppAddr";
+ },
+ BoringSSL.NID_SRVName => {
+ prefix = "SRVName";
+ unicode = false;
+ },
+ BoringSSL.NID_ms_upn => {
+ prefix = "UPN";
+ },
+ BoringSSL.NID_NAIRealm => {
+ prefix = "NAIRealm";
+ },
+ else => {
+ prefix = null;
+ },
+ }
+ if (name.d.otherName.value) |v| {
+ const val_type = v.type;
+ if (prefix == null or
+ (unicode and val_type != BoringSSL.V_ASN1_UTF8STRING) or
+ (!unicode and val_type != BoringSSL.V_ASN1_IA5STRING))
+ {
+ _ = BoringSSL.BIO_printf(out, "othername:<unsupported>");
+ } else {
+ _ = BoringSSL.BIO_printf(out, "othername:");
+ if (unicode) {
+ printUTF8AltName(out, v.value.utf8string, prefix);
+ } else {
+ printLatin1AltName(out, v.value.ia5string, prefix);
+ }
+ }
+ } else {
+ _ = BoringSSL.BIO_printf(out, "othername:<unsupported>");
+ }
+ } else if (name.name_type == .GEN_IPADD) {
+ _ = BoringSSL.BIO_printf(out, "IP Address:");
+ const ip = name.d.ip;
+ const b = ip.data;
+ if (ip.length == 4) {
+ _ = BoringSSL.BIO_printf(out, "%d.%d.%d.%d", b[0], b[1], b[2], b[3]);
+ } else if (ip.length == 16) {
+ for (0..8) |j| {
+ const pair: u16 = (@as(u16, @intCast(b[2 * j])) << 8) | @as(u16, @intCast(b[2 * j + 1]));
+ _ = BoringSSL.BIO_printf(out, if (j == 0) "%X" else ":%X", pair);
+ }
+ } else {
+ _ = BoringSSL.BIO_printf(out, "<invalid length=%d>", ip.length);
+ }
+ } else if (name.name_type == .GEN_RID) {
+ // Unlike OpenSSL's default implementation, never print the OID as text and
+ // instead always print its numeric representation.
+ var oline: [256]u8 = undefined;
+ _ = BoringSSL.OBJ_obj2txt(&oline, @sizeOf(@TypeOf(oline)), name.d.rid, 1);
+ _ = BoringSSL.BIO_printf(out, "Registered ID:%s", &oline);
+ } else if (name.name_type == .GEN_X400) {
+ _ = BoringSSL.BIO_printf(out, "X400Name:<unsupported>");
+ } else if (name.name_type == .GEN_EDIPARTY) {
+ _ = BoringSSL.BIO_printf(out, "EdiPartyName:<unsupported>");
+ } else {
+ return false;
+ }
+ return true;
+}
+
+fn x509InfoAccessPrint(out: *BoringSSL.BIO, ext: *BoringSSL.X509_EXTENSION) bool {
+ const method = BoringSSL.X509V3_EXT_get(ext);
+ if (method != BoringSSL.X509V3_EXT_get_nid(BoringSSL.NID_info_access)) {
+ return false;
+ }
+
+ if (BoringSSL.X509V3_EXT_d2i(ext)) |descs_| {
+ const descs: *BoringSSL.AUTHORITY_INFO_ACCESS = bun.cast(*BoringSSL.AUTHORITY_INFO_ACCESS, descs_);
+ defer BoringSSL.sk_ACCESS_DESCRIPTION_pop_free(descs, BoringSSL.sk_ACCESS_DESCRIPTION_free);
+ for (0..BoringSSL.sk_ACCESS_DESCRIPTION_num(descs)) |i| {
+ const gen = BoringSSL.sk_ACCESS_DESCRIPTION_value(descs, i);
+ if (gen) |desc| {
+ if (i != 0) {
+ _ = BoringSSL.BIO_write(out, "\n", 1);
+ }
+ var tmp: [80]u8 = undefined;
+ _ = BoringSSL.i2t_ASN1_OBJECT(&tmp, @sizeOf(@TypeOf(tmp)), desc.method);
+ _ = BoringSSL.BIO_printf(out, "%s - ", &tmp);
+
+ if (!x509PrintGeneralName(out, desc.location)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ return false;
+}
+fn x509SubjectAltNamePrint(out: *BoringSSL.BIO, ext: *BoringSSL.X509_EXTENSION) bool {
+ const method = BoringSSL.X509V3_EXT_get(ext);
+ if (method != BoringSSL.X509V3_EXT_get_nid(BoringSSL.NID_subject_alt_name)) {
+ return false;
+ }
+
+ if (BoringSSL.X509V3_EXT_d2i(ext)) |names_| {
+ const names: *BoringSSL.struct_stack_st_GENERAL_NAME = bun.cast(*BoringSSL.struct_stack_st_GENERAL_NAME, names_);
+ defer BoringSSL.sk_GENERAL_NAME_pop_free(names, BoringSSL.sk_GENERAL_NAME_free);
+ for (0..BoringSSL.sk_GENERAL_NAME_num(names)) |i| {
+ const gen = BoringSSL.sk_GENERAL_NAME_value(names, i);
+ if (gen) |gen_name| {
+ if (i != 0) {
+ _ = BoringSSL.BIO_write(out, ", ", 2);
+ }
+
+ if (!x509PrintGeneralName(out, gen_name)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+ return false;
+}
+
+fn x509GetSubjectAltNameString(globalObject: *JSGlobalObject, bio: *BoringSSL.BIO, cert: *BoringSSL.X509) JSValue {
+ const index = BoringSSL.X509_get_ext_by_NID(cert, BoringSSL.NID_subject_alt_name, -1);
+ if (index < 0)
+ return JSValue.jsUndefined();
+
+ defer _ = BoringSSL.BIO_reset(bio);
+
+ const ext = BoringSSL.X509_get_ext(cert, index) orelse return JSValue.jsUndefined();
+
+ if (!x509SubjectAltNamePrint(bio, ext)) {
+ return JSValue.jsNull();
+ }
+
+ return JSC.ZigString.fromUTF8(bio.slice()).toValueGC(globalObject);
+}
+
+fn x509GetInfoAccessString(globalObject: *JSGlobalObject, bio: *BoringSSL.BIO, cert: *BoringSSL.X509) JSValue {
+ const index = BoringSSL.X509_get_ext_by_NID(cert, BoringSSL.NID_info_access, -1);
+ if (index < 0)
+ return JSValue.jsUndefined();
+ defer _ = BoringSSL.BIO_reset(bio);
+ const ext = BoringSSL.X509_get_ext(cert, index) orelse return JSValue.jsUndefined();
+
+ if (!x509InfoAccessPrint(bio, ext)) {
+ return JSValue.jsNull();
+ }
+
+ return JSC.ZigString.fromUTF8(bio.slice()).toValueGC(globalObject);
+}
+
+fn addFingerprintDigest(md: []const u8, mdSize: c_uint, fingerprint: []u8) usize {
+ const hex: []const u8 = "0123456789ABCDEF";
+ var idx: usize = 0;
+
+ const slice = md[0..@as(usize, @intCast(mdSize))];
+ for (slice) |byte| {
+ fingerprint[idx] = hex[(byte & 0xF0) >> 4];
+ fingerprint[idx + 1] = hex[byte & 0x0F];
+ fingerprint[idx + 2] = ':';
+ idx += 3;
+ }
+ const length = if (idx > 0) (idx - 1) else 0;
+ fingerprint[length] = 0;
+ return length;
+}
+
+fn getFingerprintDigest(cert: *BoringSSL.X509, method: *const BoringSSL.EVP_MD, globalObject: *JSGlobalObject) JSValue {
+ var md: [BoringSSL.EVP_MAX_MD_SIZE]u8 = undefined;
+ var md_size: c_uint = 0;
+ var fingerprint: [BoringSSL.EVP_MAX_MD_SIZE * 3]u8 = undefined;
+
+ if (BoringSSL.X509_digest(cert, method, @as([*c]u8, @ptrCast(&md)), &md_size) != 0) {
+ const length = addFingerprintDigest(&md, md_size, &fingerprint);
+ return JSC.ZigString.fromUTF8(fingerprint[0..length]).toValueGC(globalObject);
+ }
+ return JSValue.jsUndefined();
+}
+
+fn getSerialNumber(cert: *BoringSSL.X509, globalObject: *JSGlobalObject) JSValue {
+ const serial_number = BoringSSL.X509_get_serialNumber(cert);
+ if (serial_number != null) {
+ const bignum = BoringSSL.ASN1_INTEGER_to_BN(serial_number, null);
+ if (bignum != null) {
+ const data = BoringSSL.BN_bn2hex(bignum);
+ if (data != null) {
+ const slice = data[0..bun.len(data)];
+ // BoringSSL prints the hex value of the serialNumber in lower case, but we need upper case
+ toUpper(slice);
+ return JSC.ZigString.fromUTF8(slice).toValueGC(globalObject);
+ }
+ }
+ }
+ return JSValue.jsUndefined();
+}
+
+fn getRawDERCertificate(cert: *BoringSSL.X509, globalObject: *JSGlobalObject) JSValue {
+ const size = BoringSSL.i2d_X509(cert, null);
+ var buffer = JSValue.createBufferFromLength(globalObject, @as(usize, @intCast(size)));
+ var buffer_ptr = @as([*c]u8, @ptrCast(buffer.asArrayBuffer(globalObject).?.ptr));
+ const result_size = BoringSSL.i2d_X509(cert, &buffer_ptr);
+ std.debug.assert(result_size == size);
+ return buffer;
+}
+
+fn toUpper(slice: []u8) void {
+ for (0..slice.len) |i| {
+ const c = slice[i];
+ if (c >= 'a' and c <= 'z') {
+ slice[i] &= 223;
+ }
+ }
+}
+
+pub fn toJS(cert: *BoringSSL.X509, globalObject: *JSGlobalObject) JSValue {
+ const bio = BoringSSL.BIO_new(BoringSSL.BIO_s_mem()) orelse {
+ globalObject.throw("Failed to create BIO", .{});
+ return .zero;
+ };
+ defer _ = BoringSSL.BIO_free(bio);
+ var result = JSValue.createEmptyObject(globalObject, 8);
+ // X509_check_ca() returns a range of values. Only 1 means "is a CA"
+ const is_ca = BoringSSL.X509_check_ca(cert) == 1;
+ const subject = BoringSSL.X509_get_subject_name(cert);
+ result.put(globalObject, ZigString.static("subject"), x509GetNameObject(globalObject, subject));
+ const issuer = BoringSSL.X509_get_issuer_name(cert);
+ result.put(globalObject, ZigString.static("issuer"), x509GetNameObject(globalObject, issuer));
+ result.put(globalObject, ZigString.static("subjectaltname"), x509GetSubjectAltNameString(globalObject, bio, cert));
+ result.put(globalObject, ZigString.static("infoAccess"), x509GetInfoAccessString(globalObject, bio, cert));
+ result.put(globalObject, ZigString.static("ca"), JSValue.jsBoolean(is_ca));
+
+ const pkey = BoringSSL.X509_get_pubkey(cert);
+
+ switch (BoringSSL.EVP_PKEY_id(pkey)) {
+ BoringSSL.EVP_PKEY_RSA => {
+ const rsa_key = BoringSSL.EVP_PKEY_get1_RSA(pkey);
+ if (rsa_key) |rsa| {
+ var n: [*c]const BoringSSL.BIGNUM = undefined;
+ var e: [*c]const BoringSSL.BIGNUM = undefined;
+ BoringSSL.RSA_get0_key(rsa, @as([*c][*c]const BoringSSL.BIGNUM, @ptrCast(&n)), @as([*c][*c]const BoringSSL.BIGNUM, @ptrCast(&e)), null);
+ _ = BoringSSL.BN_print(bio, n);
+
+ var bits = JSValue.jsUndefined();
+
+ const bits_value = BoringSSL.BN_num_bits(n);
+ if (bits_value > 0) {
+ bits = JSValue.jsNumber(bits_value);
+ }
+
+ result.put(globalObject, ZigString.static("bits"), bits);
+ const slice = bio.slice();
+ // BoringSSL prints the hex value of the modulus in lower case, but we need upper case
+ toUpper(slice);
+ const modulus = JSC.ZigString.fromUTF8(slice).toValueGC(globalObject);
+ _ = BoringSSL.BIO_reset(bio);
+ result.put(globalObject, ZigString.static("modulus"), modulus);
+
+ const exponent_word = BoringSSL.BN_get_word(e);
+ _ = BoringSSL.BIO_printf(bio, "0x" ++ BoringSSL.BN_HEX_FMT1, exponent_word);
+ const exponent = JSC.ZigString.fromUTF8(bio.slice()).toValueGC(globalObject);
+ _ = BoringSSL.BIO_reset(bio);
+ result.put(globalObject, ZigString.static("exponent"), exponent);
+
+ const size = BoringSSL.i2d_RSA_PUBKEY(rsa, null);
+ if (size <= 0) {
+ globalObject.throw("Failed to get public key length", .{});
+ return .zero;
+ }
+
+ var buffer = JSValue.createBufferFromLength(globalObject, @as(usize, @intCast(size)));
+ var buffer_ptr = @as([*c]u8, @ptrCast(buffer.asArrayBuffer(globalObject).?.ptr));
+
+ _ = BoringSSL.i2d_RSA_PUBKEY(rsa, &buffer_ptr);
+
+ result.put(globalObject, ZigString.static("pubkey"), buffer);
+ }
+ },
+ BoringSSL.EVP_PKEY_EC => {
+ const ec_key = BoringSSL.EVP_PKEY_get1_EC_KEY(pkey);
+ if (ec_key) |ec| {
+ const group = BoringSSL.EC_KEY_get0_group(ec);
+ var bits = JSValue.jsUndefined();
+ if (group) |g| {
+ const bits_value = BoringSSL.EC_GROUP_order_bits(g);
+ if (bits_value > 0) {
+ bits = JSValue.jsNumber(bits_value);
+ }
+ }
+ result.put(globalObject, ZigString.static("bits"), bits);
+
+ const ec_pubkey = BoringSSL.EC_KEY_get0_public_key(ec);
+ if (ec_pubkey) |point| {
+ const form = BoringSSL.EC_KEY_get_conv_form(ec);
+ const size = BoringSSL.EC_POINT_point2oct(group, point, form, null, 0, null);
+ if (size <= 0) {
+ globalObject.throw("Failed to get public key length", .{});
+ return .zero;
+ }
+
+ var buffer = JSValue.createBufferFromLength(globalObject, @as(usize, @intCast(size)));
+ var buffer_ptr = @as([*c]u8, @ptrCast(buffer.asArrayBuffer(globalObject).?.ptr));
+
+ const result_size = BoringSSL.EC_POINT_point2oct(group, point, form, buffer_ptr, size, null);
+ std.debug.assert(result_size == size);
+ result.put(globalObject, ZigString.static("pubkey"), buffer);
+ } else {
+ result.put(globalObject, ZigString.static("pubkey"), JSValue.jsUndefined());
+ }
+ const nid = BoringSSL.EC_GROUP_get_curve_name(group);
+
+ if (nid != 0) {
+ // Curve is well-known, get its OID and NIST nick-name (if it has one).
+ const asn1Curve_str = BoringSSL.OBJ_nid2sn(nid);
+ if (asn1Curve_str != null) {
+ result.put(globalObject, ZigString.static("asn1Curve"), JSC.ZigString.fromUTF8(asn1Curve_str[0..bun.len(asn1Curve_str)]).toValueGC(globalObject));
+ }
+ const nistCurve_str = BoringSSL.EC_curve_nid2nist(nid);
+ if (nistCurve_str != null) {
+ result.put(globalObject, ZigString.static("nistCurve"), JSC.ZigString.fromUTF8(nistCurve_str[0..bun.len(nistCurve_str)]).toValueGC(globalObject));
+ }
+ }
+ }
+ },
+ else => {},
+ }
+ _ = BoringSSL.ASN1_TIME_print(bio, BoringSSL.X509_get0_notBefore(cert));
+ result.put(globalObject, ZigString.static("valid_from"), JSC.ZigString.fromUTF8(bio.slice()).toValueGC(globalObject));
+ _ = BoringSSL.BIO_reset(bio);
+
+ _ = BoringSSL.ASN1_TIME_print(bio, BoringSSL.X509_get0_notAfter(cert));
+ result.put(globalObject, ZigString.static("valid_to"), JSC.ZigString.fromUTF8(bio.slice()).toValueGC(globalObject));
+ _ = BoringSSL.BIO_reset(bio);
+
+ result.put(globalObject, ZigString.static("fingerprint"), getFingerprintDigest(cert, BoringSSL.EVP_sha1(), globalObject));
+ result.put(globalObject, ZigString.static("fingerprint256"), getFingerprintDigest(cert, BoringSSL.EVP_sha256(), globalObject));
+ result.put(globalObject, ZigString.static("fingerprint512"), getFingerprintDigest(cert, BoringSSL.EVP_sha512(), globalObject));
+ result.put(globalObject, ZigString.static("serialNumber"), getSerialNumber(cert, globalObject));
+ result.put(globalObject, ZigString.static("raw"), getRawDERCertificate(cert, globalObject));
+ return result;
+}
diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig
index ba31b67ed..1ca44619d 100644
--- a/src/bun.js/api/ffi.zig
+++ b/src/bun.js/api/ffi.zig
@@ -383,7 +383,7 @@ pub const FFI = struct {
const cb = JSC.NewRuntimeFunction(
global,
&str,
- @intCast(u32, function.arg_types.items.len),
+ @as(u32, @intCast(function.arg_types.items.len)),
bun.cast(JSC.JSHostFunctionPtr, compiled.ptr),
false,
);
@@ -479,7 +479,7 @@ pub const FFI = struct {
const cb = JSC.NewRuntimeFunction(
global,
name,
- @intCast(u32, function.arg_types.items.len),
+ @as(u32, @intCast(function.arg_types.items.len)),
bun.cast(JSC.JSHostFunctionPtr, compiled.ptr),
false,
);
@@ -523,7 +523,7 @@ pub const FFI = struct {
const int = val.to(i32);
switch (int) {
0...ABIType.max => {
- abi_types.appendAssumeCapacity(@enumFromInt(ABIType, int));
+ abi_types.appendAssumeCapacity(@as(ABIType, @enumFromInt(int)));
continue;
},
else => {
@@ -560,7 +560,7 @@ pub const FFI = struct {
const int = ret_value.toInt32();
switch (int) {
0...ABIType.max => {
- return_type = @enumFromInt(ABIType, int);
+ return_type = @as(ABIType, @enumFromInt(int));
break :brk;
},
else => {
@@ -594,11 +594,11 @@ pub const FFI = struct {
if (ptr.isNumber()) {
const num = ptr.asPtrAddress();
if (num > 0)
- function.symbol_from_dynamic_library = @ptrFromInt(*anyopaque, num);
+ function.symbol_from_dynamic_library = @as(*anyopaque, @ptrFromInt(num));
} else {
const num = ptr.toUInt64NoTruncate();
if (num > 0) {
- function.symbol_from_dynamic_library = @ptrFromInt(*anyopaque, num);
+ function.symbol_from_dynamic_library = @as(*anyopaque, @ptrFromInt(num));
}
}
}
@@ -831,7 +831,7 @@ pub const FFI = struct {
return;
}
- var bytes: []u8 = try allocator.alloc(u8, @intCast(usize, relocation_size));
+ var bytes: []u8 = try allocator.alloc(u8, @as(usize, @intCast(relocation_size)));
defer {
if (this.step == .failed) {
allocator.free(bytes);
@@ -1001,7 +1001,7 @@ pub const FFI = struct {
return;
}
- var bytes: []u8 = try allocator.alloc(u8, @intCast(usize, relocation_size));
+ var bytes: []u8 = try allocator.alloc(u8, @as(usize, @intCast(relocation_size)));
defer {
if (this.step == .failed) {
allocator.free(bytes);
diff --git a/src/bun.js/api/html_rewriter.zig b/src/bun.js/api/html_rewriter.zig
index b309e07d7..651db981b 100644
--- a/src/bun.js/api/html_rewriter.zig
+++ b/src/bun.js/api/html_rewriter.zig
@@ -1874,7 +1874,7 @@ pub const Element = struct {
AttributeIterator.getAttributeIteratorJSClass(globalObject).asObjectRef(),
null,
1,
- @ptrCast([*]JSC.C.JSObjectRef, &attr),
+ @as([*]JSC.C.JSObjectRef, @ptrCast(&attr)),
null,
),
);
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 63e83d9bf..fbf22678b 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -170,7 +170,7 @@ pub const ServerConfig = struct {
pub fn asUSockets(this_: ?SSLConfig) uws.us_bun_socket_context_options_t {
var ctx_opts: uws.us_bun_socket_context_options_t = undefined;
- @memset(@ptrCast([*]u8, &ctx_opts)[0..@sizeOf(uws.us_bun_socket_context_options_t)], 0);
+ @memset(@as([*]u8, @ptrCast(&ctx_opts))[0..@sizeOf(uws.us_bun_socket_context_options_t)], 0);
if (this_) |ssl_config| {
if (ssl_config.key_file_name != null)
@@ -714,12 +714,12 @@ pub const ServerConfig = struct {
}
if (arg.getTruthy(global, "port")) |port_| {
- args.port = @intCast(
+ args.port = @as(
u16,
- @min(
+ @intCast(@min(
@max(0, port_.coerce(i32, global)),
std.math.maxInt(u16),
- ),
+ )),
);
}
@@ -783,7 +783,7 @@ pub const ServerConfig = struct {
if (arg.getTruthy(global, "maxRequestBodySize")) |max_request_body_size| {
if (max_request_body_size.isNumber()) {
- args.max_request_body_size = @intCast(u64, @max(0, max_request_body_size.toInt64()));
+ args.max_request_body_size = @as(u64, @intCast(@max(0, max_request_body_size.toInt64())));
}
}
@@ -1239,7 +1239,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
.reason = .fetch_event_handler,
.cwd = VirtualMachine.get().bundler.fs.top_level_dir,
.problems = Api.Problems{
- .code = @truncate(u16, @intFromError(err)),
+ .code = @as(u16, @truncate(@intFromError(err))),
.name = @errorName(err),
.exceptions = exceptions,
.build = log.toAPI(allocator) catch unreachable,
@@ -1641,19 +1641,19 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
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);
+ const adjusted_count = @as(u63, @intCast(adjusted_count_temporary));
if (Environment.isLinux) {
- var signed_offset = @intCast(i64, this.sendfile.offset);
+ var signed_offset = @as(i64, @intCast(this.sendfile.offset));
const start = this.sendfile.offset;
const val =
// this does the syscall directly, without libc
linux.sendfile(this.sendfile.socket_fd, this.sendfile.fd, &signed_offset, this.sendfile.remain);
- this.sendfile.offset = @intCast(Blob.SizeType, signed_offset);
+ this.sendfile.offset = @as(Blob.SizeType, @intCast(signed_offset));
const errcode = linux.getErrno(val);
- this.sendfile.remain -|= @intCast(Blob.SizeType, this.sendfile.offset -| start);
+ this.sendfile.remain -|= @as(Blob.SizeType, @intCast(this.sendfile.offset -| start));
if (errcode != .SUCCESS or this.flags.aborted or this.sendfile.remain == 0 or val == 0) {
if (errcode != .AGAIN and errcode != .SUCCESS and errcode != .PIPE) {
@@ -1665,7 +1665,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
}
} else {
var sbytes: std.os.off_t = adjusted_count;
- const signed_offset = @bitCast(i64, @as(u64, this.sendfile.offset));
+ const signed_offset = @as(i64, @bitCast(@as(u64, this.sendfile.offset)));
const errcode = std.c.getErrno(std.c.sendfile(
this.sendfile.fd,
this.sendfile.socket_fd,
@@ -1675,7 +1675,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
null,
0,
));
- const wrote = @intCast(Blob.SizeType, sbytes);
+ const wrote = @as(Blob.SizeType, @intCast(sbytes));
this.sendfile.offset +|= wrote;
this.sendfile.remain -|= wrote;
if (errcode != .AGAIN or this.flags.aborted or this.sendfile.remain == 0 or sbytes == 0) {
@@ -1718,7 +1718,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_[@min(bytes_.len, @truncate(usize, write_offset))..];
+ var bytes = bytes_[@min(bytes_.len, @as(usize, @truncate(write_offset)))..];
if (resp.tryEnd(bytes, bytes_.len, this.shouldCloseConnection())) {
this.finalize();
return true;
@@ -1732,7 +1732,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_[@min(bytes_.len, @truncate(usize, write_offset))..];
+ var bytes = bytes_[@min(bytes_.len, @as(usize, @truncate(write_offset)))..];
if (resp.tryEnd(bytes, bytes_.len, this.shouldCloseConnection())) {
this.response_buf_owned.items.len = 0;
this.finalize();
@@ -1788,7 +1788,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
}
var err = JSC.Node.Syscall.Error{
- .errno = @intCast(JSC.Node.Syscall.Error.Int, @intFromEnum(std.os.E.INVAL)),
+ .errno = @as(JSC.Node.Syscall.Error.Int, @intCast(@intFromEnum(std.os.E.INVAL))),
.syscall = .sendfile,
};
var sys = err.withPathLike(file.pathlike).toSystemError();
@@ -1807,7 +1807,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
}
var err = JSC.Node.Syscall.Error{
- .errno = @intCast(JSC.Node.Syscall.Error.Int, @intFromEnum(std.os.E.INVAL)),
+ .errno = @as(JSC.Node.Syscall.Error.Int, @intCast(@intFromEnum(std.os.E.INVAL))),
.syscall = .sendfile,
};
var sys = err.withPathLike(file.pathlike).toSystemError();
@@ -1820,7 +1820,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
}
const original_size = this.blob.Blob.size;
- const stat_size = @intCast(Blob.SizeType, stat.size);
+ const stat_size = @as(Blob.SizeType, @intCast(stat.size));
this.blob.Blob.size = if (std.os.S.ISREG(stat.mode))
stat_size
else
@@ -1900,7 +1900,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
this.blob.Blob.resolveSize();
this.doRenderBlob();
} else {
- const stat_size = @intCast(Blob.SizeType, result.result.total_size);
+ const stat_size = @as(Blob.SizeType, @intCast(result.result.total_size));
const original_size = this.blob.Blob.size;
this.blob.Blob.size = if (original_size == 0 or original_size == Blob.max_size)
@@ -1913,8 +1913,8 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
// this is used by content-range
this.sendfile = .{
- .fd = @truncate(i32, bun.invalid_fd),
- .remain = @truncate(Blob.SizeType, result.result.buf.len),
+ .fd = @as(i32, @truncate(bun.invalid_fd)),
+ .remain = @as(Blob.SizeType, @truncate(result.result.buf.len)),
.offset = this.blob.Blob.offset,
.auto_close = false,
.socket_fd = -999,
@@ -1988,7 +1988,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
this.server.globalThis,
stream.value,
response_stream,
- @ptrCast(**anyopaque, &signal.ptr),
+ @as(**anyopaque, @ptrCast(&signal.ptr)),
);
assignment_result.ensureStillAlive();
@@ -3228,7 +3228,7 @@ pub const WebSocketServer = struct {
globalObject.throwInvalidArguments("websocket expects maxPayloadLength to be an integer", .{});
return null;
}
- server.maxPayloadLength = @intCast(u32, @max(value.toInt64(), 0));
+ server.maxPayloadLength = @as(u32, @intCast(@max(value.toInt64(), 0)));
}
}
@@ -3239,7 +3239,7 @@ pub const WebSocketServer = struct {
return null;
}
- var idleTimeout = @intCast(u16, @truncate(u32, @max(value.toInt64(), 0)));
+ var idleTimeout = @as(u16, @intCast(@as(u32, @truncate(@max(value.toInt64(), 0)))));
if (idleTimeout > 960) {
globalObject.throwInvalidArguments("websocket expects idleTimeout to be 960 or less", .{});
return null;
@@ -3259,7 +3259,7 @@ pub const WebSocketServer = struct {
return null;
}
- server.backpressureLimit = @intCast(u32, @max(value.toInt64(), 0));
+ server.backpressureLimit = @as(u32, @intCast(@max(value.toInt64(), 0)));
}
}
@@ -3683,7 +3683,7 @@ pub const ServerWebSocket = struct {
return JSValue.jsNumber(
// if 0, return 0
// else return number of bytes sent
- if (result) @intCast(i32, @truncate(u31, buffer.len)) else @as(i32, 0),
+ if (result) @as(i32, @intCast(@as(u31, @truncate(buffer.len)))) else @as(i32, 0),
);
}
@@ -3701,7 +3701,7 @@ pub const ServerWebSocket = struct {
return JSValue.jsNumber(
// if 0, return 0
// else return number of bytes sent
- if (result) @intCast(i32, @truncate(u31, buffer.len)) else @as(i32, 0),
+ if (result) @as(i32, @intCast(@as(u31, @truncate(buffer.len)))) else @as(i32, 0),
);
}
@@ -3762,7 +3762,7 @@ pub const ServerWebSocket = struct {
return JSValue.jsNumber(
// if 0, return 0
// else return number of bytes sent
- if (result) @intCast(i32, @truncate(u31, buffer.len)) else @as(i32, 0),
+ if (result) @as(i32, @intCast(@as(u31, @truncate(buffer.len)))) else @as(i32, 0),
);
}
@@ -3823,7 +3823,7 @@ pub const ServerWebSocket = struct {
return JSValue.jsNumber(
// if 0, return 0
// else return number of bytes sent
- if (result) @intCast(i32, @truncate(u31, buffer.len)) else @as(i32, 0),
+ if (result) @as(i32, @intCast(@as(u31, @truncate(buffer.len)))) else @as(i32, 0),
);
}
@@ -3863,7 +3863,7 @@ pub const ServerWebSocket = struct {
return JSValue.jsNumber(
// if 0, return 0
// else return number of bytes sent
- if (result) @intCast(i32, @truncate(u31, buffer.len)) else @as(i32, 0),
+ if (result) @as(i32, @intCast(@as(u31, @truncate(buffer.len)))) else @as(i32, 0),
);
}
@@ -3905,7 +3905,7 @@ pub const ServerWebSocket = struct {
return JSValue.jsNumber(
// if 0, return 0
// else return number of bytes sent
- if (result) @intCast(i32, @truncate(u31, buffer.len)) else @as(i32, 0),
+ if (result) @as(i32, @intCast(@as(u31, @truncate(buffer.len)))) else @as(i32, 0),
);
}
@@ -4596,7 +4596,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
return JSValue.jsNumber(
// if 0, return 0
// else return number of bytes sent
- @as(i32, @intFromBool(uws.AnyWebSocket.publishWithOptions(ssl_enabled, app, topic_slice.slice(), buffer.slice(), .binary, compress))) * @intCast(i32, @truncate(u31, buffer.len)),
+ @as(i32, @intFromBool(uws.AnyWebSocket.publishWithOptions(ssl_enabled, app, topic_slice.slice(), buffer.slice(), .binary, compress))) * @as(i32, @intCast(@as(u31, @truncate(buffer.len)))),
);
}
@@ -4608,7 +4608,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
return JSValue.jsNumber(
// if 0, return 0
// else return number of bytes sent
- @as(i32, @intFromBool(uws.AnyWebSocket.publishWithOptions(ssl_enabled, app, topic_slice.slice(), buffer, .text, compress))) * @intCast(i32, @truncate(u31, buffer.len)),
+ @as(i32, @intFromBool(uws.AnyWebSocket.publishWithOptions(ssl_enabled, app, topic_slice.slice(), buffer, .text, compress))) * @as(i32, @intCast(@as(u31, @truncate(buffer.len)))),
);
}
@@ -4739,7 +4739,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
// See https://github.com/oven-sh/bun/issues/1339
// obviously invalid pointer marks it as used
- upgrader.upgrade_context = @ptrFromInt(*uws.uws_socket_context_s, std.math.maxInt(usize));
+ upgrader.upgrade_context = @as(*uws.uws_socket_context_s, @ptrFromInt(std.math.maxInt(usize)));
request.upgrader = null;
resp.clearAborted();
@@ -4961,11 +4961,11 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
}
pub fn getPendingRequests(this: *ThisServer) JSC.JSValue {
- return JSC.JSValue.jsNumber(@intCast(i32, @truncate(u31, this.pending_requests)));
+ return JSC.JSValue.jsNumber(@as(i32, @intCast(@as(u31, @truncate(this.pending_requests)))));
}
pub fn getPendingWebSockets(this: *ThisServer) JSC.JSValue {
- return JSC.JSValue.jsNumber(@intCast(i32, @truncate(u31, this.activeSocketsCount())));
+ return JSC.JSValue.jsNumber(@as(i32, @intCast(@as(u31, @truncate(this.activeSocketsCount())))));
}
pub fn getHostname(this: *ThisServer, globalThis: *JSGlobalObject) JSC.JSValue {
@@ -5001,7 +5001,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
pub fn activeSocketsCount(this: *const ThisServer) u32 {
const websocket = &(this.config.websocket orelse return 0);
- return @truncate(u32, websocket.handler.active_connections);
+ return @as(u32, @truncate(websocket.handler.active_connections));
}
pub fn hasActiveWebSockets(this: *const ThisServer) bool {
diff --git a/src/bun.js/api/sockets.classes.ts b/src/bun.js/api/sockets.classes.ts
index 5bd073b9f..2a17ca39d 100644
--- a/src/bun.js/api/sockets.classes.ts
+++ b/src/bun.js/api/sockets.classes.ts
@@ -12,6 +12,59 @@ function generate(ssl) {
fn: "getAuthorizationError",
length: 0,
},
+
+ getTLSFinishedMessage: {
+ fn: "getTLSFinishedMessage",
+ length: 0,
+ },
+ getTLSPeerFinishedMessage: {
+ fn: "getTLSPeerFinishedMessage",
+ length: 0,
+ },
+ getEphemeralKeyInfo: {
+ fn: "getEphemeralKeyInfo",
+ length: 0,
+ },
+ getCipher: {
+ fn: "getCipher",
+ length: 0,
+ },
+ getSession: {
+ fn: "getSession",
+ length: 0,
+ },
+ setSession: {
+ fn: "setSession",
+ length: 0,
+ },
+ getTLSTicket: {
+ fn: "getTLSTicket",
+ length: 0,
+ },
+ exportKeyingMaterial: {
+ fn: "exportKeyingMaterial",
+ length: 3,
+ },
+ setMaxSendFragment: {
+ fn: "setMaxSendFragment",
+ length: 1,
+ },
+ getSharedSigalgs: {
+ fn: "getSharedSigalgs",
+ length: 0,
+ },
+ getTLSVersion: {
+ fn: "getTLSVersion",
+ length: 0,
+ },
+ getPeerCertificate: {
+ fn: "getPeerCertificate",
+ length: 1,
+ },
+ getCertificate: {
+ fn: "getCertificate",
+ length: 0,
+ },
authorized: {
getter: "getAuthorized",
},
diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig
index b9dba8b37..b6623af88 100644
--- a/src/bun.js/base.zig
+++ b/src/bun.js/base.zig
@@ -272,7 +272,7 @@ pub const To = struct {
if (value.len <= prefill) {
var array: [prefill]JSC.C.JSValueRef = undefined;
var i: u8 = 0;
- const len = @min(@intCast(u8, value.len), prefill);
+ const len = @min(@as(u8, @intCast(value.len)), prefill);
while (i < len and exception.* == null) : (i += 1) {
array[i] = if (comptime Child == JSC.C.JSValueRef)
value[i]
@@ -1294,7 +1294,7 @@ pub fn NewClassWithInstanceType(
@memset(
&props,
js.JSStaticValue{
- .name = @ptrFromInt([*c]const u8, 0),
+ .name = @as([*c]const u8, @ptrFromInt(0)),
.getProperty = null,
.setProperty = null,
.attributes = js.JSPropertyAttributes.kJSPropertyAttributeNone,
@@ -1311,7 +1311,7 @@ pub fn NewClassWithInstanceType(
.name = lit ++ .{0},
.getProperty = null,
.setProperty = null,
- .attributes = @enumFromInt(js.JSPropertyAttributes, 0),
+ .attributes = @as(js.JSPropertyAttributes, @enumFromInt(0)),
};
static_prop.getProperty = StaticProperty(i).getter;
@@ -1423,7 +1423,7 @@ pub fn NewClassWithInstanceType(
PointerType,
if (@typeInfo(@TypeOf(ctxfn)) == .Pointer) ctxfn.* else ctxfn,
).rfn,
- .attributes = @enumFromInt(js.JSPropertyAttributes, attributes),
+ .attributes = @as(js.JSPropertyAttributes, @enumFromInt(attributes)),
};
count += 1;
@@ -1447,7 +1447,7 @@ pub fn NewClassWithInstanceType(
if (is_read_only)
base |= @intFromEnum(js.JSPropertyAttributes.kJSPropertyAttributeReadOnly);
- break :brk @enumFromInt(js.JSPropertyAttributes, base);
+ break :brk @as(js.JSPropertyAttributes, @enumFromInt(base));
};
__static_functions[count] = js.JSStaticFunction{
@@ -1820,7 +1820,7 @@ pub const ArrayBuffer = extern struct {
}
pub fn fromBytes(bytes: []u8, typed_array_type: JSC.JSValue.JSType) ArrayBuffer {
- return ArrayBuffer{ .offset = 0, .len = @intCast(u32, bytes.len), .byte_len = @intCast(u32, bytes.len), .typed_array_type = typed_array_type, .ptr = bytes.ptr };
+ return ArrayBuffer{ .offset = 0, .len = @as(u32, @intCast(bytes.len)), .byte_len = @as(u32, @intCast(bytes.len)), .typed_array_type = typed_array_type, .ptr = bytes.ptr };
}
pub fn toJSUnchecked(this: ArrayBuffer, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.JSValue {
@@ -1848,7 +1848,7 @@ pub const ArrayBuffer = extern struct {
this.ptr,
this.byte_len,
MarkedArrayBuffer_deallocator,
- @ptrFromInt(*anyopaque, @intFromPtr(&bun.default_allocator)),
+ @as(*anyopaque, @ptrFromInt(@intFromPtr(&bun.default_allocator))),
exception,
));
}
@@ -1859,7 +1859,7 @@ pub const ArrayBuffer = extern struct {
this.ptr,
this.byte_len,
MarkedArrayBuffer_deallocator,
- @ptrFromInt(*anyopaque, @intFromPtr(&bun.default_allocator)),
+ @as(*anyopaque, @ptrFromInt(@intFromPtr(&bun.default_allocator))),
exception,
));
}
@@ -1952,15 +1952,15 @@ pub const ArrayBuffer = extern struct {
pub const slice = byteSlice;
pub inline fn asU16(this: *const @This()) []u16 {
- return std.mem.bytesAsSlice(u16, @alignCast(@alignOf([*]u16), this.ptr[this.offset..this.byte_len]));
+ return std.mem.bytesAsSlice(u16, @as([*]u16, @alignCast(this.ptr))[this.offset..this.byte_len]);
}
pub inline fn asU16Unaligned(this: *const @This()) []align(1) u16 {
- return std.mem.bytesAsSlice(u16, @alignCast(@alignOf([*]align(1) u16), this.ptr[this.offset..this.byte_len]));
+ return std.mem.bytesAsSlice(u16, @as([*]align(1) u16, @alignCast(this.ptr))[this.offset..this.byte_len]);
}
pub inline fn asU32(this: *const @This()) []u32 {
- return std.mem.bytesAsSlice(u32, @alignCast(@alignOf([*]u32), this.ptr)[this.offset..this.byte_len]);
+ return std.mem.bytesAsSlice(u32, @as([*]u32, @alignCast(this.ptr))[this.offset..this.byte_len]);
}
};
@@ -3373,7 +3373,7 @@ pub const FilePoll = struct {
const DNSResolver = JSC.DNS.DNSResolver;
const GetAddrInfoRequest = JSC.DNS.GetAddrInfoRequest;
const Deactivated = opaque {
- pub var owner: Owner = Owner.init(@ptrFromInt(*Deactivated, @as(usize, 0xDEADBEEF)));
+ pub var owner: Owner = Owner.init(@as(*Deactivated, @ptrFromInt(@as(usize, 0xDEADBEEF))));
};
pub const Owner = bun.TaggedPointerUnion(.{
@@ -3666,7 +3666,7 @@ pub const FilePoll = struct {
pub fn initWithOwner(vm: *JSC.VirtualMachine, fd: bun.FileDescriptor, flags: Flags.Struct, owner: Owner) *FilePoll {
var poll = vm.rareData().filePolls(vm).get();
- poll.fd = @intCast(u32, fd);
+ poll.fd = @as(u32, @intCast(fd));
poll.flags = Flags.Set.init(flags);
poll.owner = owner;
if (KQueueGenerationNumber != u0) {
@@ -3711,9 +3711,9 @@ pub const FilePoll = struct {
var file_poll = tag.as(FilePoll);
if (comptime Environment.isMac)
- onKQueueEvent(file_poll, loop, &loop.ready_polls[@intCast(usize, loop.current_ready_poll)])
+ onKQueueEvent(file_poll, loop, &loop.ready_polls[@as(usize, @intCast(loop.current_ready_poll))])
else if (comptime Environment.isLinux)
- onEpollEvent(file_poll, loop, &loop.ready_polls[@intCast(usize, loop.current_ready_poll)]);
+ onEpollEvent(file_poll, loop, &loop.ready_polls[@as(usize, @intCast(loop.current_ready_poll))]);
}
const Pollable = bun.TaggedPointerUnion(
@@ -3761,7 +3761,7 @@ pub const FilePoll = struct {
const ctl = linux.epoll_ctl(
watcher_fd,
if (this.isRegistered() or this.flags.contains(.needs_rearm)) linux.EPOLL.CTL_MOD else linux.EPOLL.CTL_ADD,
- @intCast(std.os.fd_t, fd),
+ @as(std.os.fd_t, @intCast(fd)),
&event,
);
@@ -3773,7 +3773,7 @@ pub const FilePoll = struct {
const one_shot_flag: u16 = if (!this.flags.contains(.one_shot)) 0 else std.c.EV_ONESHOT;
changelist[0] = switch (flag) {
.readable => .{
- .ident = @intCast(u64, fd),
+ .ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_READ,
.data = 0,
.fflags = 0,
@@ -3782,7 +3782,7 @@ pub const FilePoll = struct {
.ext = .{ this.generation_number, 0 },
},
.writable => .{
- .ident = @intCast(u64, fd),
+ .ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_WRITE,
.data = 0,
.fflags = 0,
@@ -3791,7 +3791,7 @@ pub const FilePoll = struct {
.ext = .{ this.generation_number, 0 },
},
.process => .{
- .ident = @intCast(u64, fd),
+ .ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_PROC,
.data = 0,
.fflags = std.c.NOTE_EXIT,
@@ -3800,7 +3800,7 @@ pub const FilePoll = struct {
.ext = .{ this.generation_number, 0 },
},
.machport => .{
- .ident = @intCast(u64, fd),
+ .ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_MACHPORT,
.data = 0,
.fflags = 0,
@@ -3913,7 +3913,7 @@ pub const FilePoll = struct {
const ctl = linux.epoll_ctl(
watcher_fd,
linux.EPOLL.CTL_DEL,
- @intCast(std.os.fd_t, fd),
+ @as(std.os.fd_t, @intCast(fd)),
null,
);
@@ -3925,7 +3925,7 @@ pub const FilePoll = struct {
changelist[0] = switch (flag) {
.readable => .{
- .ident = @intCast(u64, fd),
+ .ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_READ,
.data = 0,
.fflags = 0,
@@ -3934,7 +3934,7 @@ pub const FilePoll = struct {
.ext = .{ 0, 0 },
},
.machport => .{
- .ident = @intCast(u64, fd),
+ .ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_MACHPORT,
.data = 0,
.fflags = 0,
@@ -3943,7 +3943,7 @@ pub const FilePoll = struct {
.ext = .{ 0, 0 },
},
.writable => .{
- .ident = @intCast(u64, fd),
+ .ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_WRITE,
.data = 0,
.fflags = 0,
@@ -3952,7 +3952,7 @@ pub const FilePoll = struct {
.ext = .{ 0, 0 },
},
.process => .{
- .ident = @intCast(u64, fd),
+ .ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_PROC,
.data = 0,
.fflags = std.c.NOTE_EXIT,
diff --git a/src/bun.js/bindings/FFI.zig b/src/bun.js/bindings/FFI.zig
index fde4a8d30..9d16bd78e 100644
--- a/src/bun.js/bindings/FFI.zig
+++ b/src/bun.js/bindings/FFI.zig
@@ -18,41 +18,41 @@ pub const union_EncodedJSValue = extern union {
};
pub const EncodedJSValue = union_EncodedJSValue;
pub export var ValueUndefined: EncodedJSValue = EncodedJSValue{
- .asInt64 = @bitCast(i64, @as(c_longlong, @as(c_int, 2) | @as(c_int, 8))),
+ .asInt64 = @as(i64, @bitCast(@as(c_longlong, @as(c_int, 2) | @as(c_int, 8)))),
};
pub export var ValueTrue: EncodedJSValue = EncodedJSValue{
- .asInt64 = @bitCast(i64, @as(c_longlong, (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 1))),
+ .asInt64 = @as(i64, @bitCast(@as(c_longlong, (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 1)))),
};
pub const JSContext = ?*anyopaque;
pub inline fn JSVALUE_IS_CELL(arg_val: EncodedJSValue) bool {
const val = arg_val;
- return !(((@bitCast(c_ulonglong, val.asInt64) & @as(c_ulonglong, 18446181123756130304)) | @bitCast(c_ulonglong, @as(c_longlong, @as(c_int, 2)))) != 0);
+ return !(((@as(c_ulonglong, @bitCast(val.asInt64)) & @as(c_ulonglong, 18446181123756130304)) | @as(c_ulonglong, @bitCast(@as(c_longlong, @as(c_int, 2))))) != 0);
}
pub inline fn JSVALUE_IS_INT32(arg_val: EncodedJSValue) @"bool" {
const val = arg_val;
- return (@bitCast(c_ulonglong, val.asInt64) & @as(c_ulonglong, 18446181123756130304)) == @as(c_ulonglong, 18446181123756130304);
+ return (@as(c_ulonglong, @bitCast(val.asInt64)) & @as(c_ulonglong, 18446181123756130304)) == @as(c_ulonglong, 18446181123756130304);
}
pub inline fn JSVALUE_IS_NUMBER(arg_val: EncodedJSValue) @"bool" {
const val = arg_val;
- return (@bitCast(c_ulonglong, val.asInt64) & @as(c_ulonglong, 18446181123756130304)) != 0;
+ return (@as(c_ulonglong, @bitCast(val.asInt64)) & @as(c_ulonglong, 18446181123756130304)) != 0;
}
pub inline fn JSVALUE_TO_UINT64(arg_value: EncodedJSValue) u64 {
var value = arg_value;
if (JSVALUE_IS_INT32(value)) {
- return @bitCast(u64, @as(c_longlong, JSVALUE_TO_INT32(value)));
+ return @as(u64, @bitCast(@as(c_longlong, JSVALUE_TO_INT32(value))));
}
if (JSVALUE_IS_NUMBER(value)) {
- return @intFromFloat(u64, JSVALUE_TO_DOUBLE(value));
+ return @as(u64, @intFromFloat(JSVALUE_TO_DOUBLE(value)));
}
return JSVALUE_TO_UINT64_SLOW(value);
}
pub inline fn JSVALUE_TO_INT64(arg_value: EncodedJSValue) i64 {
const value = arg_value;
if (JSVALUE_IS_INT32(value)) {
- return @bitCast(i64, @as(c_longlong, JSVALUE_TO_INT32(value)));
+ return @as(i64, @bitCast(@as(c_longlong, JSVALUE_TO_INT32(value))));
}
if (JSVALUE_IS_NUMBER(value)) {
- return @intFromFloat(i64, JSVALUE_TO_DOUBLE(value));
+ return @as(i64, @intFromFloat(JSVALUE_TO_DOUBLE(value)));
}
return JSVALUE_TO_INT64_SLOW(value);
}
@@ -63,69 +63,69 @@ pub const INT64_TO_JSVALUE_SLOW = @import("./bindings.zig").JSValue.fromInt64NoT
pub inline fn UINT64_TO_JSVALUE(arg_globalObject: ?*anyopaque, arg_val: u64) EncodedJSValue {
var globalObject = arg_globalObject;
const val = arg_val;
- if (val < @bitCast(c_ulonglong, @as(c_longlong, @as(c_long, 2147483648)))) {
- return INT32_TO_JSVALUE(@bitCast(i32, @truncate(c_uint, val)));
+ if (val < @as(c_ulonglong, @bitCast(@as(c_longlong, @as(c_long, 2147483648))))) {
+ return INT32_TO_JSVALUE(@as(i32, @bitCast(@as(c_uint, @truncate(val)))));
}
- if (val < @bitCast(c_ulonglong, @as(c_longlong, @as(c_long, 9007199254740991)))) {
- return DOUBLE_TO_JSVALUE(@floatFromInt(f64, val));
+ if (val < @as(c_ulonglong, @bitCast(@as(c_longlong, @as(c_long, 9007199254740991))))) {
+ return DOUBLE_TO_JSVALUE(@as(f64, @floatFromInt(val)));
}
- return UINT64_TO_JSVALUE_SLOW(@ptrCast(*@import("./bindings.zig").JSGlobalObject, globalObject.?), val).asEncoded();
+ return UINT64_TO_JSVALUE_SLOW(@as(*@import("./bindings.zig").JSGlobalObject, @ptrCast(globalObject.?)), val).asEncoded();
}
pub inline fn INT64_TO_JSVALUE(arg_globalObject: ?*anyopaque, arg_val: i64) EncodedJSValue {
var globalObject = arg_globalObject;
var val = arg_val;
- if ((val >= @bitCast(c_longlong, @as(c_longlong, -@as(c_long, 2147483648)))) and (val <= @bitCast(c_longlong, @as(c_longlong, @as(c_long, 2147483648))))) {
- return INT32_TO_JSVALUE(@bitCast(i32, @truncate(c_int, val)));
+ if ((val >= @as(c_longlong, @bitCast(@as(c_longlong, -@as(c_long, 2147483648))))) and (val <= @as(c_longlong, @bitCast(@as(c_longlong, @as(c_long, 2147483648)))))) {
+ return INT32_TO_JSVALUE(@as(i32, @bitCast(@as(c_int, @truncate(val)))));
}
- if ((val >= @bitCast(c_longlong, @as(c_longlong, -@as(c_long, 9007199254740991)))) and (val <= @bitCast(c_longlong, @as(c_longlong, @as(c_long, 9007199254740991))))) {
- return DOUBLE_TO_JSVALUE(@floatFromInt(f64, val));
+ if ((val >= @as(c_longlong, @bitCast(@as(c_longlong, -@as(c_long, 9007199254740991))))) and (val <= @as(c_longlong, @bitCast(@as(c_longlong, @as(c_long, 9007199254740991)))))) {
+ return DOUBLE_TO_JSVALUE(@as(f64, @floatFromInt(val)));
}
- return INT64_TO_JSVALUE_SLOW(@ptrCast(*@import("./bindings.zig").JSGlobalObject, globalObject.?), val).asEncoded();
+ return INT64_TO_JSVALUE_SLOW(@as(*@import("./bindings.zig").JSGlobalObject, @ptrCast(globalObject.?)), val).asEncoded();
}
pub inline fn INT32_TO_JSVALUE(arg_val: i32) EncodedJSValue {
- return .{ .asInt64 = @bitCast(i64, @as(c_ulonglong, 18446181123756130304) | @bitCast(c_ulonglong, @as(c_ulonglong, @bitCast(u32, arg_val)))) };
+ return .{ .asInt64 = @as(i64, @bitCast(@as(c_ulonglong, 18446181123756130304) | @as(c_ulonglong, @bitCast(@as(c_ulonglong, @as(u32, @bitCast(arg_val))))))) };
}
pub inline fn DOUBLE_TO_JSVALUE(arg_val: f64) EncodedJSValue {
var res: EncodedJSValue = .{ .asDouble = arg_val };
- res.asInt64 += @as(c_longlong, 1) << @intCast(@import("std").math.Log2Int(c_longlong), 49);
+ res.asInt64 += @as(c_longlong, 1) << @as(@import("std").math.Log2Int(c_longlong), @intCast(49));
return res;
}
pub inline fn FLOAT_TO_JSVALUE(arg_val: f32) EncodedJSValue {
var val = arg_val;
- return DOUBLE_TO_JSVALUE(@floatCast(f64, val));
+ return DOUBLE_TO_JSVALUE(@as(f64, @floatCast(val)));
}
pub inline fn BOOLEAN_TO_JSVALUE(arg_val: @"bool") EncodedJSValue {
var val = arg_val;
var res: EncodedJSValue = undefined;
- res.asInt64 = @bitCast(i64, @as(c_longlong, if (@as(c_int, @intFromBool(val)) != 0) (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 1) else (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 0)));
+ res.asInt64 = @as(i64, @bitCast(@as(c_longlong, if (@as(c_int, @intFromBool(val)) != 0) (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 1) else (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 0))));
return res;
}
pub inline fn PTR_TO_JSVALUE(arg_ptr: ?*anyopaque) EncodedJSValue {
var ptr = arg_ptr;
var val: EncodedJSValue = undefined;
- val.asInt64 = @intCast(i64, @intFromPtr(ptr)) + (@as(c_longlong, 1) << @intCast(@import("std").math.Log2Int(c_longlong), 49));
+ val.asInt64 = @as(i64, @intCast(@intFromPtr(ptr))) + (@as(c_longlong, 1) << @as(@import("std").math.Log2Int(c_longlong), @intCast(49)));
return val;
}
pub inline fn JSVALUE_TO_PTR(arg_val: EncodedJSValue) ?*anyopaque {
var val = arg_val;
- return @ptrFromInt(?*anyopaque, val.asInt64 - (@as(c_longlong, 1) << @intCast(@import("std").math.Log2Int(c_longlong), 49)));
+ return @as(?*anyopaque, @ptrFromInt(val.asInt64 - (@as(c_longlong, 1) << @as(@import("std").math.Log2Int(c_longlong), @intCast(49)))));
}
pub inline fn JSVALUE_TO_INT32(arg_val: EncodedJSValue) i32 {
var val = arg_val;
- return @bitCast(i32, @truncate(c_int, val.asInt64));
+ return @as(i32, @bitCast(@as(c_int, @truncate(val.asInt64))));
}
pub inline fn JSVALUE_TO_FLOAT(arg_val: EncodedJSValue) f32 {
var val = arg_val;
- return @floatCast(f32, JSVALUE_TO_DOUBLE(val));
+ return @as(f32, @floatCast(JSVALUE_TO_DOUBLE(val)));
}
pub inline fn JSVALUE_TO_DOUBLE(arg_val: EncodedJSValue) f64 {
var val = arg_val;
- val.asInt64 -= comptime @as(c_longlong, 1) << @intCast(@import("std").math.Log2Int(c_longlong), 49);
+ val.asInt64 -= comptime @as(c_longlong, 1) << @as(@import("std").math.Log2Int(c_longlong), @intCast(49));
return val.asDouble;
}
pub inline fn JSVALUE_TO_BOOL(arg_val: EncodedJSValue) @"bool" {
var val = arg_val;
- return val.asInt64 == @bitCast(c_longlong, @as(c_longlong, (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 1)));
+ return val.asInt64 == @as(c_longlong, @bitCast(@as(c_longlong, (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 1))));
}
pub extern fn JSFunctionCall(globalObject: ?*anyopaque, callFrame: ?*anyopaque) ?*anyopaque;
pub const __block = @compileError("unable to translate macro: undefined identifier `__attribute__`"); // (no file):27:9
diff --git a/src/bun.js/bindings/JSSink.cpp b/src/bun.js/bindings/JSSink.cpp
index b360d429b..6da2cbdd2 100644
--- a/src/bun.js/bindings/JSSink.cpp
+++ b/src/bun.js/bindings/JSSink.cpp
@@ -1,6 +1,6 @@
// AUTO-GENERATED FILE. DO NOT EDIT.
-// Generated by 'make generate-sink' at 2023-07-18T03:21:16.951Z
+// Generated by 'make generate-sink' at 2023-07-18T09:07:30.319Z
// To regenerate this file, run:
//
// make generate-sink
diff --git a/src/bun.js/bindings/JSSink.h b/src/bun.js/bindings/JSSink.h
index 09cea950c..7e95b886a 100644
--- a/src/bun.js/bindings/JSSink.h
+++ b/src/bun.js/bindings/JSSink.h
@@ -1,6 +1,6 @@
// AUTO-GENERATED FILE. DO NOT EDIT.
-// Generated by 'make generate-sink' at 2023-07-18T03:21:16.950Z
+// Generated by 'make generate-sink' at 2023-07-18T09:07:30.318Z
//
#pragma once
diff --git a/src/bun.js/bindings/Process.cpp b/src/bun.js/bindings/Process.cpp
index dd5c41c44..6c58c94dd 100644
--- a/src/bun.js/bindings/Process.cpp
+++ b/src/bun.js/bindings/Process.cpp
@@ -15,6 +15,9 @@
#include <JavaScriptCore/LazyProperty.h>
#include <JavaScriptCore/LazyPropertyInlines.h>
#include <JavaScriptCore/VMTrapsInlines.h>
+#include <termios.h>
+#include <errno.h>
+#include <sys/ioctl.h>
#pragma mark - Node.js Process
@@ -109,7 +112,53 @@ JSC_DEFINE_CUSTOM_SETTER(Process_defaultSetter,
return true;
}
-JSC_DECLARE_HOST_FUNCTION(Process_functionNextTick);
+static bool getWindowSize(int fd, size_t* width, size_t* height)
+{
+ struct winsize ws;
+ int err;
+ do
+ err = ioctl(fd, TIOCGWINSZ, &ws);
+ while (err == -1 && errno == EINTR);
+
+ if (err == -1)
+ return false;
+
+ *width = ws.ws_col;
+ *height = ws.ws_row;
+
+ return true;
+}
+
+JSC_DEFINE_HOST_FUNCTION(Process_functionInternalGetWindowSize,
+ (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
+{
+ JSC::VM& vm = globalObject->vm();
+ auto argCount = callFrame->argumentCount();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ if (argCount == 0) {
+ JSC::throwTypeError(globalObject, throwScope, "getWindowSize requires 2 argument (a file descriptor)"_s);
+ return JSC::JSValue::encode(JSC::JSValue {});
+ }
+
+ int fd = callFrame->uncheckedArgument(0).toInt32(globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ JSC::JSArray* array = jsDynamicCast<JSC::JSArray*>(callFrame->uncheckedArgument(1));
+ if (!array || array->length() < 2) {
+ JSC::throwTypeError(globalObject, throwScope, "getWindowSize requires 2 argument (an array)"_s);
+ return JSC::JSValue::encode(JSC::JSValue {});
+ }
+
+ size_t width, height;
+ if (!getWindowSize(fd, &width, &height)) {
+ return JSC::JSValue::encode(jsBoolean(false));
+ }
+
+ array->putDirectIndex(globalObject, 0, jsNumber(width));
+ array->putDirectIndex(globalObject, 1, jsNumber(height));
+
+ return JSC::JSValue::encode(jsBoolean(true));
+}
+
JSC_DEFINE_HOST_FUNCTION(Process_functionNextTick,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
@@ -181,23 +230,35 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen,
auto argCount = callFrame->argumentCount();
if (argCount < 2) {
-
JSC::throwTypeError(globalObject, scope, "dlopen requires 2 arguments"_s);
return JSC::JSValue::encode(JSC::JSValue {});
}
JSC::JSValue moduleValue = callFrame->uncheckedArgument(0);
- if (!moduleValue.isObject()) {
+ JSC::JSObject* moduleObject = jsDynamicCast<JSC::JSObject*>(moduleValue);
+ if (UNLIKELY(!moduleObject)) {
JSC::throwTypeError(globalObject, scope, "dlopen requires an object as first argument"_s);
return JSC::JSValue::encode(JSC::JSValue {});
}
- JSC::Identifier exportsSymbol = JSC::Identifier::fromString(vm, "exports"_s);
- JSC::JSObject* exports = moduleValue.getObject()->getIfPropertyExists(globalObject, exportsSymbol).getObject();
+
+ JSValue exports = moduleObject->getIfPropertyExists(globalObject, builtinNames(vm).exportsPublicName());
+ RETURN_IF_EXCEPTION(scope, {});
+
+ if (UNLIKELY(!exports)) {
+ JSC::throwTypeError(globalObject, scope, "dlopen requires an object with an exports property"_s);
+ return JSC::JSValue::encode(JSC::JSValue {});
+ }
+
+ globalObject->pendingNapiModule = exports;
+ if (exports.isCell()) {
+ vm.writeBarrier(globalObject, exports.asCell());
+ }
WTF::String filename = callFrame->uncheckedArgument(1).toWTFString(globalObject);
+ RETURN_IF_EXCEPTION(scope, {});
+
CString utf8 = filename.utf8();
- globalObject->pendingNapiModule = exports;
void* handle = dlopen(utf8.data(), RTLD_LAZY);
if (!handle) {
@@ -855,9 +916,13 @@ static JSValue constructStdioWriteStream(JSC::JSGlobalObject* globalObject, int
{
auto& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
+ JSC::JSFunction* getWindowSizeFunction = JSC::JSFunction::create(vm, globalObject, 2,
+ String("getWindowSize"_s), Process_functionInternalGetWindowSize, ImplementationVisibility::Public);
+
JSC::JSFunction* getStdioWriteStream = JSC::JSFunction::create(vm, processObjectInternalsGetStdioWriteStreamCodeGenerator(vm), globalObject);
JSC::MarkedArgumentBuffer args;
args.append(JSC::jsNumber(fd));
+ args.append(getWindowSizeFunction);
auto clientData = WebCore::clientData(vm);
JSC::CallData callData = JSC::getCallData(getStdioWriteStream);
diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp
index c11766926..245010158 100644
--- a/src/bun.js/bindings/ZigGeneratedClasses.cpp
+++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp
@@ -17008,12 +17008,45 @@ JSC_DECLARE_CUSTOM_SETTER(TCPSocketPrototype__dataSetterWrap);
extern "C" EncodedJSValue TCPSocketPrototype__end(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__endCallback);
+extern "C" EncodedJSValue TCPSocketPrototype__exportKeyingMaterial(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__exportKeyingMaterialCallback);
+
extern "C" EncodedJSValue TCPSocketPrototype__flush(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__flushCallback);
extern "C" EncodedJSValue TCPSocketPrototype__getAuthorizationError(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__getAuthorizationErrorCallback);
+extern "C" EncodedJSValue TCPSocketPrototype__getCertificate(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__getCertificateCallback);
+
+extern "C" EncodedJSValue TCPSocketPrototype__getCipher(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__getCipherCallback);
+
+extern "C" EncodedJSValue TCPSocketPrototype__getEphemeralKeyInfo(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__getEphemeralKeyInfoCallback);
+
+extern "C" EncodedJSValue TCPSocketPrototype__getPeerCertificate(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__getPeerCertificateCallback);
+
+extern "C" EncodedJSValue TCPSocketPrototype__getSession(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__getSessionCallback);
+
+extern "C" EncodedJSValue TCPSocketPrototype__getSharedSigalgs(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__getSharedSigalgsCallback);
+
+extern "C" EncodedJSValue TCPSocketPrototype__getTLSFinishedMessage(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__getTLSFinishedMessageCallback);
+
+extern "C" EncodedJSValue TCPSocketPrototype__getTLSPeerFinishedMessage(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__getTLSPeerFinishedMessageCallback);
+
+extern "C" EncodedJSValue TCPSocketPrototype__getTLSTicket(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__getTLSTicketCallback);
+
+extern "C" EncodedJSValue TCPSocketPrototype__getTLSVersion(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__getTLSVersionCallback);
+
extern "C" JSC::EncodedJSValue TCPSocketPrototype__getListener(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
JSC_DECLARE_CUSTOM_GETTER(TCPSocketPrototype__listenerGetterWrap);
@@ -17032,9 +17065,15 @@ JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__reloadCallback);
extern "C" JSC::EncodedJSValue TCPSocketPrototype__getRemoteAddress(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
JSC_DECLARE_CUSTOM_GETTER(TCPSocketPrototype__remoteAddressGetterWrap);
+extern "C" EncodedJSValue TCPSocketPrototype__setMaxSendFragment(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__setMaxSendFragmentCallback);
+
extern "C" EncodedJSValue TCPSocketPrototype__setServername(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__setServernameCallback);
+extern "C" EncodedJSValue TCPSocketPrototype__setSession(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__setSessionCallback);
+
extern "C" EncodedJSValue TCPSocketPrototype__shutdown(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
JSC_DECLARE_HOST_FUNCTION(TCPSocketPrototype__shutdownCallback);
@@ -17057,15 +17096,28 @@ static const HashTableValue JSTCPSocketPrototypeTableValues[] = {
{ "authorized"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TCPSocketPrototype__authorizedGetterWrap, 0 } },
{ "data"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TCPSocketPrototype__dataGetterWrap, TCPSocketPrototype__dataSetterWrap } },
{ "end"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__endCallback, 3 } },
+ { "exportKeyingMaterial"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__exportKeyingMaterialCallback, 3 } },
{ "flush"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__flushCallback, 0 } },
{ "getAuthorizationError"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__getAuthorizationErrorCallback, 0 } },
+ { "getCertificate"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__getCertificateCallback, 0 } },
+ { "getCipher"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__getCipherCallback, 0 } },
+ { "getEphemeralKeyInfo"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__getEphemeralKeyInfoCallback, 0 } },
+ { "getPeerCertificate"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__getPeerCertificateCallback, 1 } },
+ { "getSession"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__getSessionCallback, 0 } },
+ { "getSharedSigalgs"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__getSharedSigalgsCallback, 0 } },
+ { "getTLSFinishedMessage"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__getTLSFinishedMessageCallback, 0 } },
+ { "getTLSPeerFinishedMessage"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__getTLSPeerFinishedMessageCallback, 0 } },
+ { "getTLSTicket"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__getTLSTicketCallback, 0 } },
+ { "getTLSVersion"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__getTLSVersionCallback, 0 } },
{ "listener"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TCPSocketPrototype__listenerGetterWrap, 0 } },
{ "localPort"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TCPSocketPrototype__localPortGetterWrap, 0 } },
{ "readyState"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TCPSocketPrototype__readyStateGetterWrap, 0 } },
{ "ref"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__refCallback, 0 } },
{ "reload"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__reloadCallback, 1 } },
{ "remoteAddress"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TCPSocketPrototype__remoteAddressGetterWrap, 0 } },
+ { "setMaxSendFragment"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__setMaxSendFragmentCallback, 1 } },
{ "setServername"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__setServernameCallback, 1 } },
+ { "setSession"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__setSessionCallback, 0 } },
{ "shutdown"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__shutdownCallback, 1 } },
{ "timeout"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__timeoutCallback, 1 } },
{ "unref"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TCPSocketPrototype__unrefCallback, 0 } },
@@ -17180,6 +17232,33 @@ JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__endCallback, (JSGlobalObject * lexi
return TCPSocketPrototype__end(thisObject->wrapped(), lexicalGlobalObject, callFrame);
}
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__exportKeyingMaterialCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__exportKeyingMaterial(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__flushCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
auto& vm = lexicalGlobalObject->vm();
@@ -17234,6 +17313,276 @@ JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__getAuthorizationErrorCallback, (JSG
return TCPSocketPrototype__getAuthorizationError(thisObject->wrapped(), lexicalGlobalObject, callFrame);
}
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__getCertificateCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__getCertificate(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__getCipherCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__getCipher(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__getEphemeralKeyInfoCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__getEphemeralKeyInfo(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__getPeerCertificateCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__getPeerCertificate(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__getSessionCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__getSession(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__getSharedSigalgsCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__getSharedSigalgs(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__getTLSFinishedMessageCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__getTLSFinishedMessage(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__getTLSPeerFinishedMessageCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__getTLSPeerFinishedMessage(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__getTLSTicketCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__getTLSTicket(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__getTLSVersionCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__getTLSVersion(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
JSC_DEFINE_CUSTOM_GETTER(TCPSocketPrototype__listenerGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
{
auto& vm = lexicalGlobalObject->vm();
@@ -17355,6 +17704,33 @@ extern "C" EncodedJSValue TCPSocketPrototype__remoteAddressGetCachedValue(JSC::E
return JSValue::encode(thisObject->m_remoteAddress.get());
}
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__setMaxSendFragmentCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__setMaxSendFragment(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__setServernameCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
auto& vm = lexicalGlobalObject->vm();
@@ -17382,6 +17758,33 @@ JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__setServernameCallback, (JSGlobalObj
return TCPSocketPrototype__setServername(thisObject->wrapped(), lexicalGlobalObject, callFrame);
}
+JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__setSessionCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTCPSocket* thisObject = jsDynamicCast<JSTCPSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TCPSocketPrototype__setSession(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
JSC_DEFINE_HOST_FUNCTION(TCPSocketPrototype__shutdownCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
auto& vm = lexicalGlobalObject->vm();
@@ -17694,12 +18097,45 @@ JSC_DECLARE_CUSTOM_SETTER(TLSSocketPrototype__dataSetterWrap);
extern "C" EncodedJSValue TLSSocketPrototype__end(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__endCallback);
+extern "C" EncodedJSValue TLSSocketPrototype__exportKeyingMaterial(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__exportKeyingMaterialCallback);
+
extern "C" EncodedJSValue TLSSocketPrototype__flush(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__flushCallback);
extern "C" EncodedJSValue TLSSocketPrototype__getAuthorizationError(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__getAuthorizationErrorCallback);
+extern "C" EncodedJSValue TLSSocketPrototype__getCertificate(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__getCertificateCallback);
+
+extern "C" EncodedJSValue TLSSocketPrototype__getCipher(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__getCipherCallback);
+
+extern "C" EncodedJSValue TLSSocketPrototype__getEphemeralKeyInfo(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__getEphemeralKeyInfoCallback);
+
+extern "C" EncodedJSValue TLSSocketPrototype__getPeerCertificate(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__getPeerCertificateCallback);
+
+extern "C" EncodedJSValue TLSSocketPrototype__getSession(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__getSessionCallback);
+
+extern "C" EncodedJSValue TLSSocketPrototype__getSharedSigalgs(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__getSharedSigalgsCallback);
+
+extern "C" EncodedJSValue TLSSocketPrototype__getTLSFinishedMessage(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__getTLSFinishedMessageCallback);
+
+extern "C" EncodedJSValue TLSSocketPrototype__getTLSPeerFinishedMessage(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__getTLSPeerFinishedMessageCallback);
+
+extern "C" EncodedJSValue TLSSocketPrototype__getTLSTicket(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__getTLSTicketCallback);
+
+extern "C" EncodedJSValue TLSSocketPrototype__getTLSVersion(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__getTLSVersionCallback);
+
extern "C" JSC::EncodedJSValue TLSSocketPrototype__getListener(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
JSC_DECLARE_CUSTOM_GETTER(TLSSocketPrototype__listenerGetterWrap);
@@ -17718,9 +18154,15 @@ JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__reloadCallback);
extern "C" JSC::EncodedJSValue TLSSocketPrototype__getRemoteAddress(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
JSC_DECLARE_CUSTOM_GETTER(TLSSocketPrototype__remoteAddressGetterWrap);
+extern "C" EncodedJSValue TLSSocketPrototype__setMaxSendFragment(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__setMaxSendFragmentCallback);
+
extern "C" EncodedJSValue TLSSocketPrototype__setServername(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__setServernameCallback);
+extern "C" EncodedJSValue TLSSocketPrototype__setSession(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__setSessionCallback);
+
extern "C" EncodedJSValue TLSSocketPrototype__shutdown(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
JSC_DECLARE_HOST_FUNCTION(TLSSocketPrototype__shutdownCallback);
@@ -17743,15 +18185,28 @@ static const HashTableValue JSTLSSocketPrototypeTableValues[] = {
{ "authorized"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TLSSocketPrototype__authorizedGetterWrap, 0 } },
{ "data"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TLSSocketPrototype__dataGetterWrap, TLSSocketPrototype__dataSetterWrap } },
{ "end"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__endCallback, 3 } },
+ { "exportKeyingMaterial"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__exportKeyingMaterialCallback, 3 } },
{ "flush"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__flushCallback, 0 } },
{ "getAuthorizationError"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__getAuthorizationErrorCallback, 0 } },
+ { "getCertificate"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__getCertificateCallback, 0 } },
+ { "getCipher"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__getCipherCallback, 0 } },
+ { "getEphemeralKeyInfo"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__getEphemeralKeyInfoCallback, 0 } },
+ { "getPeerCertificate"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__getPeerCertificateCallback, 1 } },
+ { "getSession"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__getSessionCallback, 0 } },
+ { "getSharedSigalgs"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__getSharedSigalgsCallback, 0 } },
+ { "getTLSFinishedMessage"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__getTLSFinishedMessageCallback, 0 } },
+ { "getTLSPeerFinishedMessage"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__getTLSPeerFinishedMessageCallback, 0 } },
+ { "getTLSTicket"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__getTLSTicketCallback, 0 } },
+ { "getTLSVersion"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__getTLSVersionCallback, 0 } },
{ "listener"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TLSSocketPrototype__listenerGetterWrap, 0 } },
{ "localPort"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TLSSocketPrototype__localPortGetterWrap, 0 } },
{ "readyState"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TLSSocketPrototype__readyStateGetterWrap, 0 } },
{ "ref"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__refCallback, 0 } },
{ "reload"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__reloadCallback, 1 } },
{ "remoteAddress"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, TLSSocketPrototype__remoteAddressGetterWrap, 0 } },
+ { "setMaxSendFragment"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__setMaxSendFragmentCallback, 1 } },
{ "setServername"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__setServernameCallback, 1 } },
+ { "setSession"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__setSessionCallback, 0 } },
{ "shutdown"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__shutdownCallback, 1 } },
{ "timeout"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__timeoutCallback, 1 } },
{ "unref"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, TLSSocketPrototype__unrefCallback, 0 } },
@@ -17866,6 +18321,33 @@ JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__endCallback, (JSGlobalObject * lexi
return TLSSocketPrototype__end(thisObject->wrapped(), lexicalGlobalObject, callFrame);
}
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__exportKeyingMaterialCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__exportKeyingMaterial(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__flushCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
auto& vm = lexicalGlobalObject->vm();
@@ -17920,6 +18402,276 @@ JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__getAuthorizationErrorCallback, (JSG
return TLSSocketPrototype__getAuthorizationError(thisObject->wrapped(), lexicalGlobalObject, callFrame);
}
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__getCertificateCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__getCertificate(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__getCipherCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__getCipher(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__getEphemeralKeyInfoCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__getEphemeralKeyInfo(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__getPeerCertificateCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__getPeerCertificate(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__getSessionCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__getSession(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__getSharedSigalgsCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__getSharedSigalgs(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__getTLSFinishedMessageCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__getTLSFinishedMessage(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__getTLSPeerFinishedMessageCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__getTLSPeerFinishedMessage(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__getTLSTicketCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__getTLSTicket(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__getTLSVersionCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__getTLSVersion(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
JSC_DEFINE_CUSTOM_GETTER(TLSSocketPrototype__listenerGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
{
auto& vm = lexicalGlobalObject->vm();
@@ -18041,6 +18793,33 @@ extern "C" EncodedJSValue TLSSocketPrototype__remoteAddressGetCachedValue(JSC::E
return JSValue::encode(thisObject->m_remoteAddress.get());
}
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__setMaxSendFragmentCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__setMaxSendFragment(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__setServernameCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
auto& vm = lexicalGlobalObject->vm();
@@ -18068,6 +18847,33 @@ JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__setServernameCallback, (JSGlobalObj
return TLSSocketPrototype__setServername(thisObject->wrapped(), lexicalGlobalObject, callFrame);
}
+JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__setSessionCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSTLSSocket* thisObject = jsDynamicCast<JSTLSSocket*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+#ifdef BUN_DEBUG
+ /** View the file name of the JS file that called this function
+ * from a debugger */
+ SourceOrigin sourceOrigin = callFrame->callerSourceOrigin(vm);
+ const char* fileName = sourceOrigin.string().utf8().data();
+ static const char* lastFileName = nullptr;
+ if (lastFileName != fileName) {
+ lastFileName = fileName;
+ }
+#endif
+
+ return TLSSocketPrototype__setSession(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
JSC_DEFINE_HOST_FUNCTION(TLSSocketPrototype__shutdownCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
auto& vm = lexicalGlobalObject->vm();
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index 552da4009..1c97a57a4 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -2190,6 +2190,14 @@ CPP_DECL void JSC__JSValue__putIndex(JSC__JSValue JSValue0, JSC__JSGlobalObject*
array->putDirectIndex(arg1, arg2, value2);
}
+CPP_DECL void JSC__JSValue__push(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue3)
+{
+ JSC::JSValue value = JSC::JSValue::decode(JSValue0);
+ JSC::JSValue value2 = JSC::JSValue::decode(JSValue3);
+ JSC::JSArray* array = JSC::jsCast<JSC::JSArray*>(value);
+ array->push(arg1, value2);
+}
+
JSC__JSValue JSC__JSValue__createStringArray(JSC__JSGlobalObject* globalObject, const ZigString* arg1,
size_t arg2, bool clone)
{
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index 670c44808..3386de9b2 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -48,7 +48,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(.always_inline, func, .{ @ptrCast(*Ctx, @alignCast(@alignOf(*Ctx), this.?)), obj.?, global.? });
+ @call(.always_inline, func, .{ @as(*Ctx, @ptrCast(@alignCast(this.?))), obj.?, global.? });
}
};
}
@@ -166,7 +166,7 @@ pub const ZigString = extern struct {
return Slice{
.allocator = NullableAllocator.init(allocator),
.ptr = out.ptr,
- .len = @truncate(u32, out.len),
+ .len = @as(u32, @truncate(out.len)),
};
}
@@ -180,9 +180,9 @@ pub const ZigString = extern struct {
pub fn charAt(this: ZigString, offset: usize) u8 {
if (this.is16Bit()) {
- return @truncate(u8, this.utf16SliceAligned()[offset]);
+ return @as(u8, @truncate(this.utf16SliceAligned()[offset]));
} else {
- return @truncate(u8, this.slice()[offset]);
+ return @as(u8, @truncate(this.slice()[offset]));
}
}
@@ -390,7 +390,7 @@ pub const ZigString = extern struct {
}
pub fn markStatic(this: *ZigString) void {
- this.ptr = @ptrFromInt([*]const u8, @intFromPtr(this.ptr) | (1 << 60));
+ this.ptr = @as([*]const u8, @ptrFromInt(@intFromPtr(this.ptr) | (1 << 60)));
}
pub fn isStatic(this: *const ZigString) bool {
@@ -405,7 +405,7 @@ pub const ZigString = extern struct {
pub fn init(allocator: std.mem.Allocator, input: []const u8) Slice {
return .{
.ptr = input.ptr,
- .len = @truncate(u32, input.len),
+ .len = @as(u32, @truncate(input.len)),
.allocator = NullableAllocator.init(allocator),
};
}
@@ -425,7 +425,7 @@ pub const ZigString = extern struct {
pub fn from(input: []u8, allocator: std.mem.Allocator) Slice {
return .{
.ptr = input.ptr,
- .len = @truncate(u32, input.len),
+ .len = @as(u32, @truncate(input.len)),
.allocator = NullableAllocator.init(allocator),
};
}
@@ -433,7 +433,7 @@ pub const ZigString = extern struct {
pub fn fromUTF8NeverFree(input: []const u8) Slice {
return .{
.ptr = input.ptr,
- .len = @truncate(u32, input.len),
+ .len = @as(u32, @truncate(input.len)),
.allocator = .{},
};
}
@@ -464,7 +464,7 @@ pub const ZigString = extern struct {
pub fn cloneWithTrailingSlash(this: Slice, allocator: std.mem.Allocator) !Slice {
var buf = try strings.cloneNormalizingSeparators(allocator, this.slice());
- return Slice{ .allocator = NullableAllocator.init(allocator), .ptr = buf.ptr, .len = @truncate(u32, buf.len) };
+ return Slice{ .allocator = NullableAllocator.init(allocator), .ptr = buf.ptr, .len = @as(u32, @truncate(buf.len)) };
}
pub fn cloneZ(this: Slice, allocator: std.mem.Allocator) !Slice {
@@ -503,7 +503,7 @@ pub const ZigString = extern struct {
}
pub fn mut(this: Slice) []u8 {
- return @ptrFromInt([*]u8, @intFromPtr(this.ptr))[0..this.len];
+ return @as([*]u8, @ptrFromInt(@intFromPtr(this.ptr)))[0..this.len];
}
/// Does nothing if the slice is not allocated
@@ -534,7 +534,7 @@ pub const ZigString = extern struct {
}
}
- return @ptrCast([*]align(1) const u16, untagged(this._unsafe_ptr_do_not_use))[0..this.len];
+ return @as([*]align(1) const u16, @ptrCast(untagged(this._unsafe_ptr_do_not_use)))[0..this.len];
}
pub inline fn utf16SliceAligned(this: *const ZigString) []const u16 {
@@ -544,7 +544,7 @@ pub const ZigString = extern struct {
}
}
- return @ptrCast([*]const u16, @alignCast(@alignOf(u16), untagged(this._unsafe_ptr_do_not_use)))[0..this.len];
+ return @as([*]const u16, @ptrCast(@alignCast(untagged(this._unsafe_ptr_do_not_use))))[0..this.len];
}
pub inline fn isEmpty(this: *const ZigString) bool {
@@ -634,7 +634,7 @@ pub const ZigString = extern struct {
/// Globally-allocated memory only
pub fn from16(slice_: [*]const u16, len: usize) ZigString {
- var str = init(@ptrCast([*]const u8, slice_)[0..len]);
+ var str = init(@as([*]const u8, @ptrCast(slice_))[0..len]);
str.markUTF16();
str.mark();
str.assertGlobal();
@@ -665,11 +665,11 @@ pub const ZigString = extern struct {
}
pub fn markUTF8(this: *ZigString) void {
- this._unsafe_ptr_do_not_use = @ptrFromInt([*]const u8, @intFromPtr(this._unsafe_ptr_do_not_use) | (1 << 61));
+ this._unsafe_ptr_do_not_use = @as([*]const u8, @ptrFromInt(@intFromPtr(this._unsafe_ptr_do_not_use) | (1 << 61)));
}
pub fn markUTF16(this: *ZigString) void {
- this._unsafe_ptr_do_not_use = @ptrFromInt([*]const u8, @intFromPtr(this._unsafe_ptr_do_not_use) | (1 << 63));
+ this._unsafe_ptr_do_not_use = @as([*]const u8, @ptrFromInt(@intFromPtr(this._unsafe_ptr_do_not_use) | (1 << 63)));
}
pub fn setOutputEncoding(this: *ZigString) void {
@@ -688,7 +688,7 @@ pub const ZigString = extern struct {
pub const mark = markGlobal;
pub inline fn markGlobal(this: *ZigString) void {
- this._unsafe_ptr_do_not_use = @ptrFromInt([*]const u8, @intFromPtr(this._unsafe_ptr_do_not_use) | (1 << 62));
+ this._unsafe_ptr_do_not_use = @as([*]const u8, @ptrFromInt(@intFromPtr(this._unsafe_ptr_do_not_use) | (1 << 62)));
}
pub fn format(self: ZigString, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
@@ -714,7 +714,7 @@ pub const ZigString = extern struct {
inline fn untagged(ptr: [*]const u8) [*]const u8 {
// this can be null ptr, so long as it's also a 0 length string
@setRuntimeSafety(false);
- return @ptrFromInt([*]const u8, @truncate(u53, @intFromPtr(ptr)));
+ return @as([*]const u8, @ptrFromInt(@as(u53, @truncate(@intFromPtr(ptr)))));
}
pub fn slice(this: *const ZigString) []const u8 {
@@ -738,14 +738,14 @@ pub const ZigString = extern struct {
var buffer = this.toOwnedSlice(allocator) catch unreachable;
return Slice{
.ptr = buffer.ptr,
- .len = @truncate(u32, buffer.len),
+ .len = @as(u32, @truncate(buffer.len)),
.allocator = NullableAllocator.init(allocator),
};
}
return Slice{
.ptr = untagged(this._unsafe_ptr_do_not_use),
- .len = @truncate(u32, this.len),
+ .len = @as(u32, @truncate(this.len)),
};
}
@@ -759,7 +759,7 @@ pub const ZigString = extern struct {
return Slice{
.allocator = NullableAllocator.init(allocator),
.ptr = buffer.ptr,
- .len = @truncate(u32, buffer.len),
+ .len = @as(u32, @truncate(buffer.len)),
};
}
@@ -768,13 +768,13 @@ pub const ZigString = extern struct {
return Slice{
.allocator = NullableAllocator.init(allocator),
.ptr = buffer.ptr,
- .len = @truncate(u32, buffer.len),
+ .len = @as(u32, @truncate(buffer.len)),
};
}
return Slice{
.ptr = untagged(this._unsafe_ptr_do_not_use),
- .len = @truncate(u32, this.len),
+ .len = @as(u32, @truncate(this.len)),
};
}
@@ -785,7 +785,7 @@ pub const ZigString = extern struct {
return Slice{
.allocator = NullableAllocator.init(allocator),
.ptr = buffer.ptr,
- .len = @truncate(u32, buffer.len),
+ .len = @as(u32, @truncate(buffer.len)),
};
}
@@ -797,14 +797,14 @@ pub const ZigString = extern struct {
var buffer = this.toOwnedSliceZ(allocator) catch unreachable;
return Slice{
.ptr = buffer.ptr,
- .len = @truncate(u32, buffer.len),
+ .len = @as(u32, @truncate(buffer.len)),
.allocator = NullableAllocator.init(allocator),
};
}
return Slice{
.ptr = untagged(this._unsafe_ptr_do_not_use),
- .len = @truncate(u32, this.len),
+ .len = @as(u32, @truncate(this.len)),
};
}
@@ -892,7 +892,7 @@ pub const ZigString = extern struct {
}
return if (this.is16Bit())
- C_API.JSStringCreateWithCharactersNoCopy(@ptrCast([*]const u16, @alignCast(@alignOf([*]const u16), untagged(this._unsafe_ptr_do_not_use))), this.len)
+ C_API.JSStringCreateWithCharactersNoCopy(@as([*]const u16, @ptrCast(@alignCast(untagged(this._unsafe_ptr_do_not_use)))), this.len)
else
C_API.JSStringCreateStatic(untagged(this._unsafe_ptr_do_not_use), this.len);
}
@@ -1019,7 +1019,7 @@ pub const DOMFormData = opaque {
const Wrapper = struct {
const cb = callback;
pub fn run(c: *anyopaque, str: *ZigString) callconv(.C) void {
- cb(@ptrCast(Ctx, c), str.*);
+ cb(@as(Ctx, @ptrCast(c)), str.*);
}
};
@@ -1631,11 +1631,11 @@ pub const Sizes = @import("../bindings/sizes.zig");
pub const JSUint8Array = opaque {
pub const name = "Uint8Array_alias";
pub fn ptr(this: *JSUint8Array) [*]u8 {
- return @ptrFromInt(*[*]u8, @intFromPtr(this) + Sizes.Bun_FFI_PointerOffsetToTypedArrayVector).*;
+ return @as(*[*]u8, @ptrFromInt(@intFromPtr(this) + Sizes.Bun_FFI_PointerOffsetToTypedArrayVector)).*;
}
pub fn len(this: *JSUint8Array) usize {
- return @ptrFromInt(*usize, @intFromPtr(this) + Sizes.Bun_FFI_PointerOffsetToTypedArrayLength).*;
+ return @as(*usize, @ptrFromInt(@intFromPtr(this) + Sizes.Bun_FFI_PointerOffsetToTypedArrayLength)).*;
}
pub fn slice(this: *JSUint8Array) []u8 {
@@ -1876,7 +1876,7 @@ pub fn PromiseCallback(comptime Type: type, comptime CallbackFunction: fn (*Type
arguments: [*]const JSValue,
arguments_len: usize,
) callconv(.C) JSValue {
- return CallbackFunction(@ptrCast(*Type, @alignCast(@alignOf(*Type), ctx.?)), globalThis, arguments[0..arguments_len]) catch |err| brk: {
+ return CallbackFunction(@as(*Type, @ptrCast(@alignCast(ctx.?))), globalThis, arguments[0..arguments_len]) catch |err| brk: {
break :brk ZigString.init(bun.asByteSlice(@errorName(err))).toErrorInstance(globalThis);
};
}
@@ -1907,7 +1907,7 @@ pub const AbortSignal = extern opaque {
}
};
- return this.addListener(@ptrCast(?*anyopaque, ctx), Wrapper.callback);
+ return this.addListener(@as(?*anyopaque, @ptrCast(ctx)), Wrapper.callback);
}
pub fn addListener(
@@ -2824,7 +2824,7 @@ pub const JSGlobalObject = extern struct {
const cppFn = shim.cppFn;
pub fn ref(this: *JSGlobalObject) C_API.JSContextRef {
- return @ptrCast(C_API.JSContextRef, this);
+ return @as(C_API.JSContextRef, @ptrCast(this));
}
pub const ctx = ref;
@@ -2866,16 +2866,16 @@ 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.get());
+ const assertion = this.bunVM_() == @as(*anyopaque, @ptrCast(JSC.VirtualMachine.get()));
if (!assertion) @breakpoint();
std.debug.assert(assertion);
}
- return @ptrCast(*JSC.VirtualMachine, @alignCast(std.meta.alignment(JSC.VirtualMachine), this.bunVM_()));
+ return @as(*JSC.VirtualMachine, @ptrCast(@alignCast(this.bunVM_())));
}
/// We can't do the threadlocal check when queued from another thread
pub fn bunVMConcurrently(this: *JSGlobalObject) *JSC.VirtualMachine {
- return @ptrCast(*JSC.VirtualMachine, @alignCast(@alignOf(JSC.VirtualMachine), this.bunVM_()));
+ return @as(*JSC.VirtualMachine, @ptrCast(@alignCast(this.bunVM_())));
}
pub fn handleRejectedPromises(this: *JSGlobalObject) void {
@@ -2943,7 +2943,7 @@ pub const JSArrayIterator = struct {
return .{
.array = value,
.global = global,
- .len = @truncate(u32, value.getLength(global)),
+ .len = @as(u32, @truncate(value.getLength(global))),
};
}
@@ -3014,10 +3014,10 @@ pub const JSMap = opaque {
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 = @as(JSValueReprInt, @bitCast(@as(i64, 0xa))),
+ null = @as(JSValueReprInt, @bitCast(@as(i64, 0x2))),
+ true = @as(JSValueReprInt, @bitCast(@as(i64, 0x4))),
+ false = @as(JSValueReprInt, @bitCast(@as(i64, 0x6))),
_,
pub const Type = JSValueReprInt;
@@ -3361,7 +3361,7 @@ pub const JSValue = enum(JSValueReprInt) {
};
pub inline fn cast(ptr: anytype) JSValue {
- return @enumFromInt(JSValue, @bitCast(i64, @intFromPtr(ptr)));
+ return @as(JSValue, @enumFromInt(@as(i64, @bitCast(@intFromPtr(ptr)))));
}
pub fn coerceToInt32(this: JSValue, globalThis: *JSC.JSGlobalObject) i32 {
@@ -3426,7 +3426,7 @@ pub const JSValue = enum(JSValueReprInt) {
}
if (this.isNumber()) {
- return @truncate(i32, this.coerceDoubleTruncatingIntoInt64());
+ return @as(i32, @truncate(this.coerceDoubleTruncatingIntoInt64()));
}
return this.coerceToInt32(globalThis);
@@ -3441,16 +3441,16 @@ pub const JSValue = enum(JSValueReprInt) {
return switch (comptime T) {
u32 => toU32(this),
u16 => toU16(this),
- c_uint => @intCast(c_uint, toU32(this)),
- c_int => @intCast(c_int, toInt32(this)),
+ c_uint => @as(c_uint, @intCast(toU32(this))),
+ c_int => @as(c_int, @intCast(toInt32(this))),
?AnyPromise => asAnyPromise(this),
- u52 => @truncate(u52, @intCast(u64, @max(this.toInt64(), 0))),
- i52 => @truncate(i52, @intCast(i52, this.toInt64())),
+ u52 => @as(u52, @truncate(@as(u64, @intCast(@max(this.toInt64(), 0))))),
+ i52 => @as(i52, @truncate(@as(i52, @intCast(this.toInt64())))),
u64 => toUInt64NoTruncate(this),
- u8 => @truncate(u8, toU32(this)),
- i16 => @truncate(i16, toInt32(this)),
- i8 => @truncate(i8, toInt32(this)),
- i32 => @truncate(i32, toInt32(this)),
+ u8 => @as(u8, @truncate(toU32(this))),
+ i16 => @as(i16, @truncate(toInt32(this))),
+ i8 => @as(i8, @truncate(toInt32(this))),
+ i32 => @as(i32, @truncate(toInt32(this))),
i64 => this.toInt64(),
bool => this.toBoolean(),
else => @compileError("Not implemented yet"),
@@ -3473,9 +3473,9 @@ pub const JSValue = enum(JSValueReprInt) {
return JSC.C.JSObjectCallAsFunctionReturnValue(
globalThis,
this.asObjectRef(),
- @ptrCast(JSC.C.JSValueRef, globalThis),
+ @as(JSC.C.JSValueRef, @ptrCast(globalThis)),
args.len,
- @ptrCast(?[*]const JSC.C.JSValueRef, args.ptr),
+ @as(?[*]const JSC.C.JSValueRef, @ptrCast(args.ptr)),
);
}
@@ -3484,9 +3484,9 @@ pub const JSValue = enum(JSValueReprInt) {
return JSC.C.JSObjectCallAsFunctionReturnValue(
globalThis,
this.asObjectRef(),
- @ptrCast(JSC.C.JSValueRef, thisValue.asNullableVoid()),
+ @as(JSC.C.JSValueRef, @ptrCast(thisValue.asNullableVoid())),
args.len,
- @ptrCast(?[*]const JSC.C.JSValueRef, args.ptr),
+ @as(?[*]const JSC.C.JSValueRef, @ptrCast(args.ptr)),
);
}
@@ -3527,6 +3527,10 @@ pub const JSValue = enum(JSValueReprInt) {
cppFn("putIndex", .{ value, globalObject, i, out });
}
+ pub fn push(value: JSValue, globalObject: *JSGlobalObject, out: JSValue) void {
+ cppFn("push", .{ value, globalObject, out });
+ }
+
pub fn as(value: JSValue, comptime ZigType: type) ?*ZigType {
if (value.isEmptyOrUndefinedOrNull())
return null;
@@ -3621,7 +3625,7 @@ pub const JSValue = enum(JSValueReprInt) {
pub fn createBufferFromLength(globalObject: *JSGlobalObject, len: usize) JSValue {
JSC.markBinding(@src());
- return JSBuffer__bufferFromLength(globalObject, @intCast(i64, len));
+ return JSBuffer__bufferFromLength(globalObject, @as(i64, @intCast(len)));
}
pub fn jestSnapshotPrettyFormat(this: JSValue, out: *MutableString, globalObject: *JSGlobalObject) !void {
@@ -3639,7 +3643,7 @@ pub const JSValue = enum(JSValueReprInt) {
JestPrettyFormat.format(
.Debug,
globalObject,
- @ptrCast([*]const JSValue, &this),
+ @as([*]const JSValue, @ptrCast(&this)),
1,
Writer,
Writer,
@@ -3700,7 +3704,7 @@ pub const JSValue = enum(JSValueReprInt) {
JSC.ZigConsoleClient.format(
.Debug,
globalObject,
- @ptrCast([*]const JSValue, &this),
+ @as([*]const JSValue, @ptrCast(&this)),
1,
Writer,
Writer,
@@ -3741,12 +3745,12 @@ pub const JSValue = enum(JSValueReprInt) {
return switch (comptime Number) {
JSValue => number,
f32, f64 => jsNumberFromDouble(@as(f64, number)),
- c_ushort, u8, i16, i32, c_int, i8, u16 => jsNumberFromInt32(@intCast(i32, number)),
- u32, u52, c_uint, i64 => jsNumberFromInt64(@intCast(i64, number)),
- usize, u64 => jsNumberFromUint64(@intCast(u64, number)),
+ c_ushort, u8, i16, i32, c_int, i8, u16 => jsNumberFromInt32(@as(i32, @intCast(number))),
+ u32, u52, c_uint, i64 => jsNumberFromInt64(@as(i64, @intCast(number))),
+ usize, u64 => jsNumberFromUint64(@as(u64, @intCast(number))),
comptime_int => switch (number) {
- 0...std.math.maxInt(i32) => jsNumberFromInt32(@intCast(i32, number)),
- else => jsNumberFromInt64(@intCast(i64, number)),
+ 0...std.math.maxInt(i32) => jsNumberFromInt32(@as(i32, @intCast(number))),
+ else => jsNumberFromInt64(@as(i64, @intCast(number))),
},
else => @compileError("Type transformation missing for number of type: " ++ @typeName(Number)),
};
@@ -3856,10 +3860,10 @@ pub const JSValue = enum(JSValueReprInt) {
pub fn jsNumberFromInt64(i: i64) JSValue {
if (i <= std.math.maxInt(i32)) {
- return jsNumberFromInt32(@intCast(i32, i));
+ return jsNumberFromInt32(@as(i32, @intCast(i)));
}
- return jsNumberFromDouble(@floatFromInt(f64, @truncate(i52, i)));
+ return jsNumberFromDouble(@as(f64, @floatFromInt(@as(i52, @truncate(i)))));
}
pub inline fn toJS(this: JSValue, _: *const JSGlobalObject) JSValue {
@@ -3868,10 +3872,10 @@ pub const JSValue = enum(JSValueReprInt) {
pub fn jsNumberFromUint64(i: u64) JSValue {
if (i <= std.math.maxInt(i32)) {
- return jsNumberFromInt32(@intCast(i32, i));
+ return jsNumberFromInt32(@as(i32, @intCast(i)));
}
- return jsNumberFromDouble(@floatFromInt(f64, @intCast(i52, @truncate(u51, i))));
+ return jsNumberFromDouble(@as(f64, @floatFromInt(@as(i52, @intCast(@as(u51, @truncate(i)))))));
}
pub fn coerceDoubleTruncatingIntoInt64(this: JSValue) i64 {
@@ -3885,9 +3889,9 @@ pub const JSValue = enum(JSValueReprInt) {
return if (double_value < 0) @as(i64, std.math.minInt(i64)) else @as(i64, std.math.maxInt(i64));
}
- return @intFromFloat(
+ return @as(
i64,
- double_value,
+ @intFromFloat(double_value),
);
}
@@ -4067,7 +4071,7 @@ pub const JSValue = enum(JSValueReprInt) {
pub inline fn isCell(this: JSValue) bool {
return switch (this) {
.zero, .undefined, .null, .true, .false => false,
- else => (@bitCast(u64, @intFromEnum(this)) & FFI.NotCellMask) == 0,
+ else => (@as(u64, @bitCast(@intFromEnum(this))) & FFI.NotCellMask) == 0,
};
}
@@ -4293,7 +4297,7 @@ pub const JSValue = enum(JSValueReprInt) {
}
pub fn get(this: JSValue, global: *JSGlobalObject, property: []const u8) ?JSValue {
- const value = getIfPropertyExistsImpl(this, global, property.ptr, @intCast(u32, property.len));
+ const value = getIfPropertyExistsImpl(this, global, property.ptr, @as(u32, @intCast(property.len)));
return if (@intFromEnum(value) != 0) value else return null;
}
@@ -4551,7 +4555,7 @@ pub const JSValue = enum(JSValueReprInt) {
pub fn asNumber(this: JSValue) f64 {
if (this.isInt32()) {
- return @floatFromInt(f64, this.asInt32());
+ return @as(f64, @floatFromInt(this.asInt32()));
}
if (isNumber(this)) {
@@ -4574,15 +4578,15 @@ pub const JSValue = enum(JSValueReprInt) {
}
pub fn asPtr(this: JSValue, comptime Pointer: type) *Pointer {
- return @ptrFromInt(*Pointer, this.asPtrAddress());
+ return @as(*Pointer, @ptrFromInt(this.asPtrAddress()));
}
pub fn fromPtrAddress(addr: anytype) JSValue {
- return jsNumber(@floatFromInt(f64, @bitCast(usize, @as(usize, addr))));
+ return jsNumber(@as(f64, @floatFromInt(@as(usize, @bitCast(@as(usize, addr))))));
}
pub fn asPtrAddress(this: JSValue) usize {
- return @bitCast(usize, @intFromFloat(usize, this.asDouble()));
+ return @as(usize, @bitCast(@as(usize, @intFromFloat(this.asDouble()))));
}
pub fn fromPtr(addr: anytype) JSValue {
@@ -4609,7 +4613,7 @@ pub const JSValue = enum(JSValueReprInt) {
if (comptime bun.Environment.allow_assert) {
std.debug.assert(this.isNumber());
}
- return @intFromFloat(i64, @max(@min(this.asDouble(), std.math.maxInt(i52)), std.math.minInt(i52)));
+ return @as(i64, @intFromFloat(@max(@min(this.asDouble(), std.math.maxInt(i52)), std.math.minInt(i52))));
}
pub fn toInt32(this: JSValue) i32 {
@@ -4618,7 +4622,7 @@ pub const JSValue = enum(JSValueReprInt) {
}
if (this.isNumber()) {
- return @truncate(i32, this.asInt52());
+ return @as(i32, @truncate(this.asInt52()));
}
if (comptime bun.Environment.allow_assert) {
@@ -4636,11 +4640,11 @@ pub const JSValue = enum(JSValueReprInt) {
}
pub inline fn toU16(this: JSValue) u16 {
- return @truncate(u16, @max(this.toInt32(), 0));
+ return @as(u16, @truncate(@max(this.toInt32(), 0)));
}
pub inline fn toU32(this: JSValue) u32 {
- return @intCast(u32, @min(@max(this.toInt64(), 0), std.math.maxInt(u32)));
+ return @as(u32, @intCast(@min(@max(this.toInt64(), 0), std.math.maxInt(u32))));
}
/// This function supports:
@@ -4661,7 +4665,7 @@ pub const JSValue = enum(JSValueReprInt) {
return 0;
}
- return @intFromFloat(u64, @max(@min(len, std.math.maxInt(i52)), 0));
+ return @as(u64, @intFromFloat(@max(@min(len, std.math.maxInt(i52)), 0)));
}
/// This function supports:
@@ -4682,7 +4686,7 @@ pub const JSValue = enum(JSValueReprInt) {
return null;
}
- return @intFromFloat(u64, @max(@min(len, std.math.maxInt(i52)), 0));
+ return @as(u64, @intFromFloat(@max(@min(len, std.math.maxInt(i52)), 0)));
}
/// Do not use this directly!
@@ -4727,19 +4731,19 @@ pub const JSValue = enum(JSValueReprInt) {
}
pub inline fn asRef(this: JSValue) C_API.JSValueRef {
- return @ptrFromInt(C_API.JSValueRef, @bitCast(usize, @intFromEnum(this)));
+ return @as(C_API.JSValueRef, @ptrFromInt(@as(usize, @bitCast(@intFromEnum(this)))));
}
pub inline fn c(this: C_API.JSValueRef) JSValue {
- return @enumFromInt(JSValue, @bitCast(JSValue.Type, @intFromPtr(this)));
+ return @as(JSValue, @enumFromInt(@as(JSValue.Type, @bitCast(@intFromPtr(this)))));
}
pub inline fn fromRef(this: C_API.JSValueRef) JSValue {
- return @enumFromInt(JSValue, @bitCast(JSValue.Type, @intFromPtr(this)));
+ return @as(JSValue, @enumFromInt(@as(JSValue.Type, @bitCast(@intFromPtr(this)))));
}
pub inline fn asObjectRef(this: JSValue) C_API.JSObjectRef {
- return @ptrCast(C_API.JSObjectRef, this.asVoid());
+ return @as(C_API.JSObjectRef, @ptrCast(this.asVoid()));
}
/// When the GC sees a JSValue referenced in the stack
@@ -4747,11 +4751,11 @@ pub const JSValue = enum(JSValueReprInt) {
/// This mimicks the implementation in JavaScriptCore's C++
pub inline fn ensureStillAlive(this: JSValue) void {
if (this.isEmpty() or this.isNumber() or this.isBoolean() or this.isUndefinedOrNull()) return;
- std.mem.doNotOptimizeAway(@ptrCast(C_API.JSObjectRef, this.asVoid()));
+ std.mem.doNotOptimizeAway(@as(C_API.JSObjectRef, @ptrCast(this.asVoid())));
}
pub inline fn asNullableVoid(this: JSValue) ?*anyopaque {
- return @ptrFromInt(?*anyopaque, @bitCast(usize, @intFromEnum(this)));
+ return @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@intFromEnum(this)))));
}
pub inline fn asVoid(this: JSValue) *anyopaque {
@@ -4851,6 +4855,7 @@ pub const JSValue = enum(JSValueReprInt) {
"put",
"putDirect",
"putIndex",
+ "push",
"putRecord",
"strictDeepEquals",
"symbolFor",
@@ -4995,7 +5000,7 @@ pub const VM = extern struct {
const callback_ = callback;
const Wrapper = struct {
pub fn run(ptr_: *anyopaque) callconv(.C) void {
- var ptr__ = @ptrCast(*Ptr, @alignCast(@alignOf(Ptr), ptr_));
+ var ptr__ = @as(*Ptr, @ptrCast(@alignCast(ptr_)));
callback_(ptr__);
}
};
@@ -5193,11 +5198,11 @@ pub const CallFrame = opaque {
pub const name = "JSC::CallFrame";
pub fn argumentsPtr(self: *const CallFrame) [*]const JSC.JSValue {
- return @ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + Sizes.Bun_CallFrame__firstArgument;
+ return @as([*]align(alignment) const JSC.JSValue, @ptrCast(@alignCast(self))) + Sizes.Bun_CallFrame__firstArgument;
}
pub fn callee(self: *const CallFrame) JSC.JSValue {
- return (@ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + Sizes.Bun_CallFrame__callee)[0];
+ return (@as([*]align(alignment) const JSC.JSValue, @ptrCast(@alignCast(self))) + Sizes.Bun_CallFrame__callee)[0];
}
fn Arguments(comptime max: usize) type {
@@ -5242,11 +5247,11 @@ pub const CallFrame = opaque {
}
pub fn this(self: *const CallFrame) JSC.JSValue {
- return (@ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + Sizes.Bun_CallFrame__thisArgument)[0];
+ return (@as([*]align(alignment) const JSC.JSValue, @ptrCast(@alignCast(self))) + Sizes.Bun_CallFrame__thisArgument)[0];
}
pub fn argumentsCount(self: *const CallFrame) usize {
- return @intCast(usize, (@ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + Sizes.Bun_CallFrame__argumentCountIncludingThis)[0].asInt32() - 1);
+ return @as(usize, @intCast((@as([*]align(alignment) const JSC.JSValue, @ptrCast(@alignCast(self))) + Sizes.Bun_CallFrame__argumentCountIncludingThis)[0].asInt32() - 1));
}
};
@@ -5289,7 +5294,7 @@ const DeinitFunction = *const fn (ctx: *anyopaque, buffer: [*]u8, len: usize) ca
pub const JSArray = struct {
pub fn from(globalThis: *JSGlobalObject, arguments: []const JSC.JSValue) JSValue {
- return JSC.JSValue.c(JSC.C.JSObjectMakeArray(globalThis, arguments.len, @ptrCast(?[*]const JSC.C.JSObjectRef, arguments.ptr), null));
+ return JSC.JSValue.c(JSC.C.JSObjectMakeArray(globalThis, arguments.len, @as(?[*]const JSC.C.JSObjectRef, @ptrCast(arguments.ptr)), null));
}
};
@@ -5329,7 +5334,7 @@ const private = struct {
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, @as(*const anyopaque, @ptrCast(&functionPointer)), strong);
}
pub fn NewFunction(
@@ -5376,7 +5381,7 @@ pub fn NewFunctionWithData(
globalObject,
symbolName,
argCount,
- @ptrCast(*const anyopaque, &functionPointer),
+ @as(*const anyopaque, @ptrCast(&functionPointer)),
strong,
data,
);
@@ -5479,7 +5484,7 @@ pub fn Thenable(comptime name: []const u8, comptime Then: type, comptime onResol
) callconv(.C) void {
@setRuntimeSafety(false);
const args_list = callframe.?.arguments(8);
- onResolve(@ptrCast(*Then, @alignCast(std.meta.alignment(Then), args_list.ptr[args_list.len - 1].asEncoded().asPtr)), globalThis, args_list.ptr[0]);
+ onResolve(@as(*Then, @ptrCast(@alignCast(args_list.ptr[args_list.len - 1].asEncoded().asPtr))), globalThis, args_list.ptr[0]);
}
pub fn reject(
@@ -5488,7 +5493,7 @@ pub fn Thenable(comptime name: []const u8, comptime Then: type, comptime onResol
) callconv(.C) void {
@setRuntimeSafety(false);
const args_list = callframe.?.arguments(8);
- onReject(@ptrCast(*Then, @alignCast(std.meta.alignment(Then), args_list.ptr[args_list.len - 1].asEncoded().asPtr)), globalThis, args_list.ptr[0]);
+ onReject(@as(*Then, @ptrCast(@alignCast(args_list.ptr[args_list.len - 1].asEncoded().asPtr))), globalThis, args_list.ptr[0]);
}
pub fn then(ctx: *Then, this: JSValue, globalThis: *JSGlobalObject) void {
@@ -5535,7 +5540,7 @@ pub fn JSPropertyIterator(comptime options: JSPropertyIteratorOptions) type {
const array_ref = JSC.C.JSObjectCopyPropertyNames(global, object);
return .{
.array_ref = array_ref,
- .len = @truncate(u32, JSC.C.JSPropertyNameArrayGetCount(array_ref)),
+ .len = @as(u32, @truncate(JSC.C.JSPropertyNameArrayGetCount(array_ref))),
.object = if (comptime options.include_value) object else .{},
.global = if (comptime options.include_value) global else .{},
.value = undefined,
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig
index 40ee4ff57..b569fe68c 100644
--- a/src/bun.js/bindings/exports.zig
+++ b/src/bun.js/bindings/exports.zig
@@ -119,7 +119,7 @@ pub const ErrorCode = enum(ErrorCodeInt) {
_,
pub inline fn from(code: anyerror) ErrorCode {
- return @enumFromInt(ErrorCode, @intFromError(code));
+ return @as(ErrorCode, @enumFromInt(@intFromError(code)));
}
pub const ParserError = @intFromEnum(ErrorCode.from(error.ParserError));
@@ -243,7 +243,7 @@ pub const ResolvedSource = extern struct {
const Mimalloc = @import("../../allocators/mimalloc.zig");
export fn ZigString__free(raw: [*]const u8, len: usize, allocator_: ?*anyopaque) void {
- var allocator: std.mem.Allocator = @ptrCast(*std.mem.Allocator, @alignCast(@alignOf(*std.mem.Allocator), allocator_ orelse return)).*;
+ var allocator: std.mem.Allocator = @as(*std.mem.Allocator, @ptrCast(@alignCast(allocator_ orelse return))).*;
var ptr = ZigString.init(raw[0..len]).slice().ptr;
if (comptime Environment.allow_assert) {
std.debug.assert(Mimalloc.mi_is_in_heap_region(ptr));
@@ -254,7 +254,7 @@ export fn ZigString__free(raw: [*]const u8, len: usize, allocator_: ?*anyopaque)
}
export fn ZigString__free_global(ptr: [*]const u8, len: usize) void {
- var untagged = @ptrFromInt(*anyopaque, @intFromPtr(ZigString.init(ptr[0..len]).slice().ptr));
+ var untagged = @as(*anyopaque, @ptrFromInt(@intFromPtr(ZigString.init(ptr[0..len]).slice().ptr)));
if (comptime Environment.allow_assert) {
std.debug.assert(Mimalloc.mi_is_in_heap_region(ptr));
}
@@ -468,7 +468,7 @@ pub const ZigStackTrace = extern struct {
var source_line_len = source_lines_iter.getLength();
if (source_line_len > 0) {
- var source_lines = try allocator.alloc(Api.SourceLine, @intCast(usize, @max(source_lines_iter.i + 1, 0)));
+ var source_lines = try allocator.alloc(Api.SourceLine, @as(usize, @intCast(@max(source_lines_iter.i + 1, 0))));
var source_line_buf = try allocator.alloc(u8, source_line_len);
source_lines_iter = this.sourceLineIterator();
var remain_buf = source_line_buf[0..];
@@ -523,7 +523,7 @@ pub const ZigStackTrace = extern struct {
pub fn getLength(this: *SourceLineIterator) usize {
var count: usize = 0;
- for (this.trace.source_lines_ptr[0..@intCast(usize, this.i + 1)]) |*line| {
+ for (this.trace.source_lines_ptr[0..@as(usize, @intCast(this.i + 1))]) |*line| {
count += line.length();
}
@@ -538,9 +538,9 @@ pub const ZigStackTrace = extern struct {
pub fn next(this: *SourceLineIterator) ?SourceLine {
if (this.i < 0) return null;
- const source_line = this.trace.source_lines_ptr[@intCast(usize, this.i)];
+ const source_line = this.trace.source_lines_ptr[@as(usize, @intCast(this.i))];
const result = SourceLine{
- .line = this.trace.source_lines_numbers[@intCast(usize, this.i)],
+ .line = this.trace.source_lines_numbers[@as(usize, @intCast(this.i))],
.text = source_line.toUTF8(bun.default_allocator),
};
this.i -= 1;
@@ -555,7 +555,7 @@ pub const ZigStackTrace = extern struct {
i = j;
}
}
- return SourceLineIterator{ .trace = this, .i = @intCast(i16, i) };
+ return SourceLineIterator{ .trace = this, .i = @as(i16, @intCast(i)) };
}
};
@@ -596,7 +596,7 @@ pub const ZigStackFrame = extern struct {
frame.position.column_stop = this.position.column_stop;
frame.position.expression_start = this.position.expression_start;
frame.position.expression_stop = this.position.expression_stop;
- frame.scope = @enumFromInt(Api.StackFrameScope, @intFromEnum(this.code_type));
+ frame.scope = @as(Api.StackFrameScope, @enumFromInt(@intFromEnum(this.code_type)));
return frame;
}
@@ -846,7 +846,7 @@ pub const ZigException = extern struct {
pub fn zigException(this: *Holder) *ZigException {
if (!this.loaded) {
this.zig_exception = ZigException{
- .code = @enumFromInt(JSErrorCode, 255),
+ .code = @as(JSErrorCode, @enumFromInt(255)),
.runtime_type = JSRuntimeType.Nothing,
.name = String.empty,
.message = String.empty,
@@ -1581,7 +1581,7 @@ pub const ZigConsoleClient = struct {
var writer = WrappedWriter(Writer){ .ctx = writer_ };
var slice = slice_;
var i: u32 = 0;
- var len: u32 = @truncate(u32, slice.len);
+ var len: u32 = @as(u32, @truncate(slice.len));
var any_non_ascii = false;
while (i < len) : (i += 1) {
switch (slice[i]) {
@@ -1608,7 +1608,7 @@ pub const ZigConsoleClient = struct {
any_non_ascii = false;
slice = slice[@min(slice.len, i + 1)..];
i = 0;
- len = @truncate(u32, slice.len);
+ len = @as(u32, @truncate(slice.len));
const next_value = this.remaining_values[0];
this.remaining_values = this.remaining_values[1..];
switch (token) {
@@ -2025,7 +2025,7 @@ pub const ZigConsoleClient = struct {
i = -i;
}
const digits = if (i != 0)
- bun.fmt.fastDigitCount(@intCast(usize, i)) + @as(usize, @intFromBool(is_negative))
+ bun.fmt.fastDigitCount(@as(usize, @intCast(i))) + @as(usize, @intFromBool(is_negative))
else
1;
this.addForNewLine(digits);
@@ -2136,7 +2136,7 @@ pub const ZigConsoleClient = struct {
writer.print(comptime Output.prettyFmt("<cyan>[Getter]<r>", enable_ansi_colors), .{});
},
.Array => {
- const len = @truncate(u32, value.getLength(this.globalThis));
+ const len = @as(u32, @truncate(value.getLength(this.globalThis)));
if (len == 0) {
writer.writeAll("[]");
this.addForNewLine(2);
@@ -2267,9 +2267,9 @@ pub const ZigConsoleClient = struct {
// this case should never happen
return this.printAs(.Undefined, Writer, writer_, .undefined, .Cell, enable_ansi_colors);
} else if (value.as(JSC.API.Bun.Timer.TimerObject)) |timer| {
- this.addForNewLine("Timeout(# ) ".len + bun.fmt.fastDigitCount(@intCast(u64, @max(timer.id, 0))));
+ this.addForNewLine("Timeout(# ) ".len + bun.fmt.fastDigitCount(@as(u64, @intCast(@max(timer.id, 0)))));
if (timer.kind == .setInterval) {
- this.addForNewLine("repeats ".len + bun.fmt.fastDigitCount(@intCast(u64, @max(timer.id, 0))));
+ this.addForNewLine("repeats ".len + bun.fmt.fastDigitCount(@as(u64, @intCast(@max(timer.id, 0)))));
writer.print(comptime Output.prettyFmt("<r><blue>Timeout<r> <d>(#<yellow>{d}<r><d>, repeats)<r>", enable_ansi_colors), .{
timer.id,
});
@@ -2344,7 +2344,7 @@ pub const ZigConsoleClient = struct {
writer.writeAll("Promise { " ++ comptime Output.prettyFmt("<r><cyan>", enable_ansi_colors));
- switch (JSPromise.status(@ptrCast(*JSPromise, value.asObjectRef().?), this.globalThis.vm())) {
+ switch (JSPromise.status(@as(*JSPromise, @ptrCast(value.asObjectRef().?)), this.globalThis.vm())) {
JSPromise.Status.Pending => {
writer.writeAll("<pending>");
},
@@ -2753,7 +2753,7 @@ pub const ZigConsoleClient = struct {
var j: usize = 0;
while (j < length) : (j += 1) {
- const child = JSC.JSObject.getIndex(children, this.globalThis, @intCast(u32, j));
+ const child = JSC.JSObject.getIndex(children, this.globalThis, @as(u32, @intCast(j)));
this.format(Tag.getAdvanced(child, this.globalThis, .{ .hide_global = true }), Writer, writer_, child, this.globalThis, enable_ansi_colors);
if (j + 1 < length) {
writer.writeAll("\n");
@@ -2883,56 +2883,56 @@ pub const ZigConsoleClient = struct {
*@TypeOf(writer),
&writer,
i8,
- @alignCast(std.meta.alignment([]i8), std.mem.bytesAsSlice(i8, slice)),
+ @as([]align(std.meta.alignment([]i8)) i8, @alignCast(std.mem.bytesAsSlice(i8, slice))),
enable_ansi_colors,
),
.Int16Array => this.writeTypedArray(
*@TypeOf(writer),
&writer,
i16,
- @alignCast(std.meta.alignment([]i16), std.mem.bytesAsSlice(i16, slice)),
+ @as([]align(std.meta.alignment([]i16)) i16, @alignCast(std.mem.bytesAsSlice(i16, slice))),
enable_ansi_colors,
),
.Uint16Array => this.writeTypedArray(
*@TypeOf(writer),
&writer,
u16,
- @alignCast(std.meta.alignment([]u16), std.mem.bytesAsSlice(u16, slice)),
+ @as([]align(std.meta.alignment([]u16)) u16, @alignCast(std.mem.bytesAsSlice(u16, slice))),
enable_ansi_colors,
),
.Int32Array => this.writeTypedArray(
*@TypeOf(writer),
&writer,
i32,
- @alignCast(std.meta.alignment([]i32), std.mem.bytesAsSlice(i32, slice)),
+ @as([]align(std.meta.alignment([]i32)) i32, @alignCast(std.mem.bytesAsSlice(i32, slice))),
enable_ansi_colors,
),
.Uint32Array => this.writeTypedArray(
*@TypeOf(writer),
&writer,
u32,
- @alignCast(std.meta.alignment([]u32), std.mem.bytesAsSlice(u32, slice)),
+ @as([]align(std.meta.alignment([]u32)) u32, @alignCast(std.mem.bytesAsSlice(u32, slice))),
enable_ansi_colors,
),
.Float32Array => this.writeTypedArray(
*@TypeOf(writer),
&writer,
f32,
- @alignCast(std.meta.alignment([]f32), std.mem.bytesAsSlice(f32, slice)),
+ @as([]align(std.meta.alignment([]f32)) f32, @alignCast(std.mem.bytesAsSlice(f32, slice))),
enable_ansi_colors,
),
.Float64Array => this.writeTypedArray(
*@TypeOf(writer),
&writer,
f64,
- @alignCast(std.meta.alignment([]f64), std.mem.bytesAsSlice(f64, slice)),
+ @as([]align(std.meta.alignment([]f64)) f64, @alignCast(std.mem.bytesAsSlice(f64, slice))),
enable_ansi_colors,
),
.BigInt64Array => this.writeTypedArray(
*@TypeOf(writer),
&writer,
i64,
- @alignCast(std.meta.alignment([]i64), std.mem.bytesAsSlice(i64, slice)),
+ @as([]align(std.meta.alignment([]i64)) i64, @alignCast(std.mem.bytesAsSlice(i64, slice))),
enable_ansi_colors,
),
.BigUint64Array => {
@@ -2940,7 +2940,7 @@ pub const ZigConsoleClient = struct {
*@TypeOf(writer),
&writer,
u64,
- @alignCast(std.meta.alignment([]u64), std.mem.bytesAsSlice(u64, slice)),
+ @as([]align(std.meta.alignment([]u64)) u64, @alignCast(std.mem.bytesAsSlice(u64, slice))),
enable_ansi_colors,
);
},
@@ -3115,7 +3115,7 @@ pub const ZigConsoleClient = struct {
var value: std.time.Timer = result.value orelse return;
// get the duration in microseconds
// then display it in milliseconds
- Output.printElapsed(@floatFromInt(f64, value.read() / std.time.ns_per_us) / std.time.us_per_ms);
+ Output.printElapsed(@as(f64, @floatFromInt(value.read() / std.time.ns_per_us)) / std.time.us_per_ms);
switch (len) {
0 => Output.printErrorln("\n", .{}),
else => Output.printErrorln(" {s}", .{chars[0..len]}),
@@ -3144,7 +3144,7 @@ pub const ZigConsoleClient = struct {
var value: std.time.Timer = (pending_time_logs.get(id) orelse return) orelse return;
// get the duration in microseconds
// then display it in milliseconds
- Output.printElapsed(@floatFromInt(f64, value.read() / std.time.ns_per_us) / std.time.us_per_ms);
+ Output.printElapsed(@as(f64, @floatFromInt(value.read() / std.time.ns_per_us)) / std.time.us_per_ms);
switch (len) {
0 => Output.printErrorln("\n", .{}),
else => Output.printErrorln(" {s}", .{chars[0..len]}),
@@ -3369,7 +3369,7 @@ pub const ZigConsoleClient = struct {
// };
pub inline fn toGlobalContextRef(ptr: *JSGlobalObject) CAPI.JSGlobalContextRef {
- return @ptrCast(CAPI.JSGlobalContextRef, ptr);
+ return @as(CAPI.JSGlobalContextRef, @ptrCast(ptr));
}
comptime {
diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig
index 10aec1865..947be7a51 100644
--- a/src/bun.js/bindings/generated_classes.zig
+++ b/src/bun.js/bindings/generated_classes.zig
@@ -4458,10 +4458,32 @@ pub const JSTCPSocket = struct {
@compileLog("Expected TCPSocket.setData to be a setter");
if (@TypeOf(TCPSocket.end) != CallbackType)
@compileLog("Expected TCPSocket.end to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.end)));
+ if (@TypeOf(TCPSocket.exportKeyingMaterial) != CallbackType)
+ @compileLog("Expected TCPSocket.exportKeyingMaterial to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.exportKeyingMaterial)));
if (@TypeOf(TCPSocket.flush) != CallbackType)
@compileLog("Expected TCPSocket.flush to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.flush)));
if (@TypeOf(TCPSocket.getAuthorizationError) != CallbackType)
@compileLog("Expected TCPSocket.getAuthorizationError to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.getAuthorizationError)));
+ if (@TypeOf(TCPSocket.getCertificate) != CallbackType)
+ @compileLog("Expected TCPSocket.getCertificate to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.getCertificate)));
+ if (@TypeOf(TCPSocket.getCipher) != CallbackType)
+ @compileLog("Expected TCPSocket.getCipher to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.getCipher)));
+ if (@TypeOf(TCPSocket.getEphemeralKeyInfo) != CallbackType)
+ @compileLog("Expected TCPSocket.getEphemeralKeyInfo to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.getEphemeralKeyInfo)));
+ if (@TypeOf(TCPSocket.getPeerCertificate) != CallbackType)
+ @compileLog("Expected TCPSocket.getPeerCertificate to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.getPeerCertificate)));
+ if (@TypeOf(TCPSocket.getSession) != CallbackType)
+ @compileLog("Expected TCPSocket.getSession to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.getSession)));
+ if (@TypeOf(TCPSocket.getSharedSigalgs) != CallbackType)
+ @compileLog("Expected TCPSocket.getSharedSigalgs to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.getSharedSigalgs)));
+ if (@TypeOf(TCPSocket.getTLSFinishedMessage) != CallbackType)
+ @compileLog("Expected TCPSocket.getTLSFinishedMessage to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.getTLSFinishedMessage)));
+ if (@TypeOf(TCPSocket.getTLSPeerFinishedMessage) != CallbackType)
+ @compileLog("Expected TCPSocket.getTLSPeerFinishedMessage to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.getTLSPeerFinishedMessage)));
+ if (@TypeOf(TCPSocket.getTLSTicket) != CallbackType)
+ @compileLog("Expected TCPSocket.getTLSTicket to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.getTLSTicket)));
+ if (@TypeOf(TCPSocket.getTLSVersion) != CallbackType)
+ @compileLog("Expected TCPSocket.getTLSVersion to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.getTLSVersion)));
if (@TypeOf(TCPSocket.getListener) != GetterType)
@compileLog("Expected TCPSocket.getListener to be a getter");
@@ -4478,8 +4500,12 @@ pub const JSTCPSocket = struct {
if (@TypeOf(TCPSocket.getRemoteAddress) != GetterType)
@compileLog("Expected TCPSocket.getRemoteAddress to be a getter");
+ if (@TypeOf(TCPSocket.setMaxSendFragment) != CallbackType)
+ @compileLog("Expected TCPSocket.setMaxSendFragment to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.setMaxSendFragment)));
if (@TypeOf(TCPSocket.setServername) != CallbackType)
@compileLog("Expected TCPSocket.setServername to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.setServername)));
+ if (@TypeOf(TCPSocket.setSession) != CallbackType)
+ @compileLog("Expected TCPSocket.setSession to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.setSession)));
if (@TypeOf(TCPSocket.shutdown) != CallbackType)
@compileLog("Expected TCPSocket.shutdown to be a callback but received " ++ @typeName(@TypeOf(TCPSocket.shutdown)));
if (@TypeOf(TCPSocket.timeout) != CallbackType)
@@ -4492,21 +4518,34 @@ pub const JSTCPSocket = struct {
@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.exportKeyingMaterial, .{ .name = "TCPSocketPrototype__exportKeyingMaterial" });
@export(TCPSocket.finalize, .{ .name = "TCPSocketClass__finalize" });
@export(TCPSocket.flush, .{ .name = "TCPSocketPrototype__flush" });
@export(TCPSocket.getALPNProtocol, .{ .name = "TCPSocketPrototype__getALPNProtocol" });
@export(TCPSocket.getAuthorizationError, .{ .name = "TCPSocketPrototype__getAuthorizationError" });
@export(TCPSocket.getAuthorized, .{ .name = "TCPSocketPrototype__getAuthorized" });
+ @export(TCPSocket.getCertificate, .{ .name = "TCPSocketPrototype__getCertificate" });
+ @export(TCPSocket.getCipher, .{ .name = "TCPSocketPrototype__getCipher" });
@export(TCPSocket.getData, .{ .name = "TCPSocketPrototype__getData" });
+ @export(TCPSocket.getEphemeralKeyInfo, .{ .name = "TCPSocketPrototype__getEphemeralKeyInfo" });
@export(TCPSocket.getListener, .{ .name = "TCPSocketPrototype__getListener" });
@export(TCPSocket.getLocalPort, .{ .name = "TCPSocketPrototype__getLocalPort" });
+ @export(TCPSocket.getPeerCertificate, .{ .name = "TCPSocketPrototype__getPeerCertificate" });
@export(TCPSocket.getReadyState, .{ .name = "TCPSocketPrototype__getReadyState" });
@export(TCPSocket.getRemoteAddress, .{ .name = "TCPSocketPrototype__getRemoteAddress" });
+ @export(TCPSocket.getSession, .{ .name = "TCPSocketPrototype__getSession" });
+ @export(TCPSocket.getSharedSigalgs, .{ .name = "TCPSocketPrototype__getSharedSigalgs" });
+ @export(TCPSocket.getTLSFinishedMessage, .{ .name = "TCPSocketPrototype__getTLSFinishedMessage" });
+ @export(TCPSocket.getTLSPeerFinishedMessage, .{ .name = "TCPSocketPrototype__getTLSPeerFinishedMessage" });
+ @export(TCPSocket.getTLSTicket, .{ .name = "TCPSocketPrototype__getTLSTicket" });
+ @export(TCPSocket.getTLSVersion, .{ .name = "TCPSocketPrototype__getTLSVersion" });
@export(TCPSocket.hasPendingActivity, .{ .name = "TCPSocket__hasPendingActivity" });
@export(TCPSocket.ref, .{ .name = "TCPSocketPrototype__ref" });
@export(TCPSocket.reload, .{ .name = "TCPSocketPrototype__reload" });
@export(TCPSocket.setData, .{ .name = "TCPSocketPrototype__setData" });
+ @export(TCPSocket.setMaxSendFragment, .{ .name = "TCPSocketPrototype__setMaxSendFragment" });
@export(TCPSocket.setServername, .{ .name = "TCPSocketPrototype__setServername" });
+ @export(TCPSocket.setSession, .{ .name = "TCPSocketPrototype__setSession" });
@export(TCPSocket.shutdown, .{ .name = "TCPSocketPrototype__shutdown" });
@export(TCPSocket.timeout, .{ .name = "TCPSocketPrototype__timeout" });
@export(TCPSocket.unref, .{ .name = "TCPSocketPrototype__unref" });
@@ -4623,10 +4662,32 @@ pub const JSTLSSocket = struct {
@compileLog("Expected TLSSocket.setData to be a setter");
if (@TypeOf(TLSSocket.end) != CallbackType)
@compileLog("Expected TLSSocket.end to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.end)));
+ if (@TypeOf(TLSSocket.exportKeyingMaterial) != CallbackType)
+ @compileLog("Expected TLSSocket.exportKeyingMaterial to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.exportKeyingMaterial)));
if (@TypeOf(TLSSocket.flush) != CallbackType)
@compileLog("Expected TLSSocket.flush to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.flush)));
if (@TypeOf(TLSSocket.getAuthorizationError) != CallbackType)
@compileLog("Expected TLSSocket.getAuthorizationError to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.getAuthorizationError)));
+ if (@TypeOf(TLSSocket.getCertificate) != CallbackType)
+ @compileLog("Expected TLSSocket.getCertificate to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.getCertificate)));
+ if (@TypeOf(TLSSocket.getCipher) != CallbackType)
+ @compileLog("Expected TLSSocket.getCipher to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.getCipher)));
+ if (@TypeOf(TLSSocket.getEphemeralKeyInfo) != CallbackType)
+ @compileLog("Expected TLSSocket.getEphemeralKeyInfo to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.getEphemeralKeyInfo)));
+ if (@TypeOf(TLSSocket.getPeerCertificate) != CallbackType)
+ @compileLog("Expected TLSSocket.getPeerCertificate to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.getPeerCertificate)));
+ if (@TypeOf(TLSSocket.getSession) != CallbackType)
+ @compileLog("Expected TLSSocket.getSession to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.getSession)));
+ if (@TypeOf(TLSSocket.getSharedSigalgs) != CallbackType)
+ @compileLog("Expected TLSSocket.getSharedSigalgs to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.getSharedSigalgs)));
+ if (@TypeOf(TLSSocket.getTLSFinishedMessage) != CallbackType)
+ @compileLog("Expected TLSSocket.getTLSFinishedMessage to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.getTLSFinishedMessage)));
+ if (@TypeOf(TLSSocket.getTLSPeerFinishedMessage) != CallbackType)
+ @compileLog("Expected TLSSocket.getTLSPeerFinishedMessage to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.getTLSPeerFinishedMessage)));
+ if (@TypeOf(TLSSocket.getTLSTicket) != CallbackType)
+ @compileLog("Expected TLSSocket.getTLSTicket to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.getTLSTicket)));
+ if (@TypeOf(TLSSocket.getTLSVersion) != CallbackType)
+ @compileLog("Expected TLSSocket.getTLSVersion to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.getTLSVersion)));
if (@TypeOf(TLSSocket.getListener) != GetterType)
@compileLog("Expected TLSSocket.getListener to be a getter");
@@ -4643,8 +4704,12 @@ pub const JSTLSSocket = struct {
if (@TypeOf(TLSSocket.getRemoteAddress) != GetterType)
@compileLog("Expected TLSSocket.getRemoteAddress to be a getter");
+ if (@TypeOf(TLSSocket.setMaxSendFragment) != CallbackType)
+ @compileLog("Expected TLSSocket.setMaxSendFragment to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.setMaxSendFragment)));
if (@TypeOf(TLSSocket.setServername) != CallbackType)
@compileLog("Expected TLSSocket.setServername to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.setServername)));
+ if (@TypeOf(TLSSocket.setSession) != CallbackType)
+ @compileLog("Expected TLSSocket.setSession to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.setSession)));
if (@TypeOf(TLSSocket.shutdown) != CallbackType)
@compileLog("Expected TLSSocket.shutdown to be a callback but received " ++ @typeName(@TypeOf(TLSSocket.shutdown)));
if (@TypeOf(TLSSocket.timeout) != CallbackType)
@@ -4657,21 +4722,34 @@ pub const JSTLSSocket = struct {
@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.exportKeyingMaterial, .{ .name = "TLSSocketPrototype__exportKeyingMaterial" });
@export(TLSSocket.finalize, .{ .name = "TLSSocketClass__finalize" });
@export(TLSSocket.flush, .{ .name = "TLSSocketPrototype__flush" });
@export(TLSSocket.getALPNProtocol, .{ .name = "TLSSocketPrototype__getALPNProtocol" });
@export(TLSSocket.getAuthorizationError, .{ .name = "TLSSocketPrototype__getAuthorizationError" });
@export(TLSSocket.getAuthorized, .{ .name = "TLSSocketPrototype__getAuthorized" });
+ @export(TLSSocket.getCertificate, .{ .name = "TLSSocketPrototype__getCertificate" });
+ @export(TLSSocket.getCipher, .{ .name = "TLSSocketPrototype__getCipher" });
@export(TLSSocket.getData, .{ .name = "TLSSocketPrototype__getData" });
+ @export(TLSSocket.getEphemeralKeyInfo, .{ .name = "TLSSocketPrototype__getEphemeralKeyInfo" });
@export(TLSSocket.getListener, .{ .name = "TLSSocketPrototype__getListener" });
@export(TLSSocket.getLocalPort, .{ .name = "TLSSocketPrototype__getLocalPort" });
+ @export(TLSSocket.getPeerCertificate, .{ .name = "TLSSocketPrototype__getPeerCertificate" });
@export(TLSSocket.getReadyState, .{ .name = "TLSSocketPrototype__getReadyState" });
@export(TLSSocket.getRemoteAddress, .{ .name = "TLSSocketPrototype__getRemoteAddress" });
+ @export(TLSSocket.getSession, .{ .name = "TLSSocketPrototype__getSession" });
+ @export(TLSSocket.getSharedSigalgs, .{ .name = "TLSSocketPrototype__getSharedSigalgs" });
+ @export(TLSSocket.getTLSFinishedMessage, .{ .name = "TLSSocketPrototype__getTLSFinishedMessage" });
+ @export(TLSSocket.getTLSPeerFinishedMessage, .{ .name = "TLSSocketPrototype__getTLSPeerFinishedMessage" });
+ @export(TLSSocket.getTLSTicket, .{ .name = "TLSSocketPrototype__getTLSTicket" });
+ @export(TLSSocket.getTLSVersion, .{ .name = "TLSSocketPrototype__getTLSVersion" });
@export(TLSSocket.hasPendingActivity, .{ .name = "TLSSocket__hasPendingActivity" });
@export(TLSSocket.ref, .{ .name = "TLSSocketPrototype__ref" });
@export(TLSSocket.reload, .{ .name = "TLSSocketPrototype__reload" });
@export(TLSSocket.setData, .{ .name = "TLSSocketPrototype__setData" });
+ @export(TLSSocket.setMaxSendFragment, .{ .name = "TLSSocketPrototype__setMaxSendFragment" });
@export(TLSSocket.setServername, .{ .name = "TLSSocketPrototype__setServername" });
+ @export(TLSSocket.setSession, .{ .name = "TLSSocketPrototype__setSession" });
@export(TLSSocket.shutdown, .{ .name = "TLSSocketPrototype__shutdown" });
@export(TLSSocket.timeout, .{ .name = "TLSSocketPrototype__timeout" });
@export(TLSSocket.unref, .{ .name = "TLSSocketPrototype__unref" });
diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h
index 02631d749..c03b621c1 100644
--- a/src/bun.js/bindings/headers.h
+++ b/src/bun.js/bindings/headers.h
@@ -383,6 +383,7 @@ CPP_DECL unsigned char JSC__JSValue__jsType(JSC__JSValue JSValue0);
CPP_DECL JSC__JSValue JSC__JSValue__jsUndefined();
CPP_DECL JSC__JSValue JSC__JSValue__makeWithNameAndPrototype(JSC__JSGlobalObject* arg0, void* arg1, void* arg2, const ZigString* arg3);
CPP_DECL JSC__JSValue JSC__JSValue__parseJSON(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
+CPP_DECL void JSC__JSValue__push(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2);
CPP_DECL void JSC__JSValue__put(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, const ZigString* arg2, JSC__JSValue JSValue3);
CPP_DECL void JSC__JSValue__putIndex(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, uint32_t arg2, JSC__JSValue JSValue3);
CPP_DECL void JSC__JSValue__putRecord(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, ZigString* arg2, ZigString* arg3, size_t arg4);
diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig
index 0b71d6918..b1e19557c 100644
--- a/src/bun.js/bindings/headers.zig
+++ b/src/bun.js/bindings/headers.zig
@@ -283,6 +283,7 @@ 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: *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__push(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) void;
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__putIndex(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: u32, 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;
diff --git a/src/bun.js/bindings/napi.cpp b/src/bun.js/bindings/napi.cpp
index c4bf7fc32..6e47db8c4 100644
--- a/src/bun.js/bindings/napi.cpp
+++ b/src/bun.js/bindings/napi.cpp
@@ -496,7 +496,10 @@ extern "C" void napi_module_register(napi_module* mod)
auto* globalObject = Bun__getDefaultGlobal();
JSC::VM& vm = globalObject->vm();
globalObject->napiModuleRegisterCallCount++;
- JSC::JSObject* object = globalObject->pendingNapiModule.getObject();
+ JSValue pendingNapiModule = globalObject->pendingNapiModule;
+ JSObject* object = (pendingNapiModule && pendingNapiModule.isObject()) ? pendingNapiModule.getObject()
+ : nullptr;
+
if (!object) {
object = JSC::constructEmptyObject(globalObject);
} else {
@@ -504,20 +507,23 @@ extern "C" void napi_module_register(napi_module* mod)
}
EnsureStillAliveScope ensureAlive(object);
- auto result = reinterpret_cast<JSC::EncodedJSValue>(
- mod->nm_register_func(reinterpret_cast<napi_env>(globalObject), reinterpret_cast<napi_value>(JSC::JSValue::encode(JSC::JSValue(object)))));
+ auto resultValue = toJS(
+ mod->nm_register_func(toNapi(globalObject), toNapi(object)));
auto keyStr = WTF::String::fromUTF8(mod->nm_modname);
- JSC::JSValue resultValue = JSC::JSValue::decode(result);
EnsureStillAliveScope ensureAlive2(resultValue);
if (resultValue.isEmpty()) {
- globalObject->pendingNapiModule = createError(globalObject, makeString("Node-API module \""_s, keyStr, "\" returned an error"_s));
+ JSValue errorInstance = createError(globalObject, makeString("Node-API module \""_s, keyStr, "\" returned an error"_s));
+ globalObject->pendingNapiModule = errorInstance;
+ vm.writeBarrier(globalObject, errorInstance);
EnsureStillAliveScope ensureAlive(globalObject->pendingNapiModule);
return;
}
if (!resultValue.isObject()) {
- globalObject->pendingNapiModule = createError(globalObject, makeString("Expected Node-API module \""_s, keyStr, "\" to return an exports object"_s));
+ JSValue errorInstance = createError(globalObject, makeString("Expected Node-API module \""_s, keyStr, "\" to return an exports object"_s));
+ globalObject->pendingNapiModule = errorInstance;
+ vm.writeBarrier(globalObject, errorInstance);
EnsureStillAliveScope ensureAlive(globalObject->pendingNapiModule);
return;
}
@@ -532,7 +538,9 @@ extern "C" void napi_module_register(napi_module* mod)
// Add it to the ESM registry
globalObject->moduleLoader()->provideFetch(globalObject, JSC::jsString(vm, WTFMove(keyStr)), WTFMove(source));
+
globalObject->pendingNapiModule = object;
+ vm.writeBarrier(globalObject, object);
}
extern "C" napi_status napi_wrap(napi_env env,
diff --git a/src/bun.js/bindings/shimmer.zig b/src/bun.js/bindings/shimmer.zig
index 3a6242000..29d12c1db 100644
--- a/src/bun.js/bindings/shimmer.zig
+++ b/src/bun.js/bindings/shimmer.zig
@@ -163,7 +163,7 @@ pub fn Shimmer(comptime _namespace: []const u8, comptime _name: []const u8, comp
if (comptime isNullableType(ExpectedReturnType) != isNullableType(ExternReturnType)) {
return value.?;
} else if (comptime (@typeInfo(ExpectedReturnType) == .Enum) and (@typeInfo(ExternReturnType) != .Enum)) {
- return @enumFromInt(ExpectedReturnType, value);
+ return @as(ExpectedReturnType, @enumFromInt(value));
} else {
return value;
}
diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig
index d9befef8e..2dbe88d47 100644
--- a/src/bun.js/event_loop.zig
+++ b/src/bun.js/event_loop.zig
@@ -173,7 +173,7 @@ pub const AnyTask = struct {
}
pub fn wrap(this: ?*anyopaque) void {
- @call(.always_inline, Callback, .{@ptrCast(*Type, @alignCast(@alignOf(Type), this.?))});
+ @call(.always_inline, Callback, .{@as(*Type, @ptrCast(@alignCast(this.?)))});
}
};
}
@@ -205,8 +205,8 @@ pub const AnyTaskWithExtraContext = struct {
.always_inline,
Callback,
.{
- @ptrCast(*Type, @alignCast(@alignOf(Type), this.?)),
- @ptrCast(*ContextType, @alignCast(@alignOf(ContextType), extra.?)),
+ @as(*Type, @ptrCast(@alignCast(this.?))),
+ @as(*ContextType, @ptrCast(@alignCast(extra.?))),
},
);
}
@@ -503,7 +503,7 @@ pub const EventLoop = struct {
}
this.tasks.head = if (this.tasks.count == 0) 0 else this.tasks.head;
- return @truncate(u32, counter);
+ return @as(u32, @truncate(counter));
}
pub fn tickConcurrent(this: *EventLoop) void {
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index 2e6d61952..fb855e047 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -119,7 +119,7 @@ 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.?));
+ var context: *Context = @as(*Context, @ptrCast(@alignCast(ctx.?)));
@call(.auto, Function, .{context});
}
}.callback;
@@ -142,7 +142,7 @@ pub const SavedSourceMap = struct {
}
pub inline fn len(this: SavedMappings) usize {
- return @bitCast(u64, this.data[0..8].*);
+ return @as(u64, @bitCast(this.data[0..8].*));
}
pub fn deinit(this: SavedMappings) void {
@@ -153,7 +153,7 @@ pub const SavedSourceMap = struct {
const result = SourceMap.Mapping.parse(
allocator,
this.data[16..this.len()],
- @bitCast(usize, this.data[8..16].*),
+ @as(usize, @bitCast(this.data[8..16].*)),
1,
);
switch (result) {
@@ -203,7 +203,7 @@ pub const SavedSourceMap = struct {
var source_map: *MappingList = source_map_;
source_map.deinit(default_allocator);
} else if (value.get(SavedMappings)) |saved_mappings| {
- var saved = SavedMappings{ .data = @ptrCast([*]u8, saved_mappings) };
+ var saved = SavedMappings{ .data = @as([*]u8, @ptrCast(saved_mappings)) };
saved.deinit();
}
@@ -219,7 +219,7 @@ pub const SavedSourceMap = struct {
return Value.from(mapping.value_ptr.*).as(MappingList).*;
},
Value.Tag.SavedMappings => {
- var saved = SavedMappings{ .data = @ptrCast([*]u8, Value.from(mapping.value_ptr.*).as(MappingList)) };
+ var saved = SavedMappings{ .data = @as([*]u8, @ptrCast(Value.from(mapping.value_ptr.*).as(MappingList))) };
defer saved.deinit();
var result = default_allocator.create(MappingList) catch unreachable;
result.* = saved.toMapping(default_allocator, path) catch {
@@ -264,7 +264,7 @@ export fn Bun__readOriginTimer(vm: *JSC.VirtualMachine) u64 {
export fn Bun__readOriginTimerStart(vm: *JSC.VirtualMachine) f64 {
// timespce to milliseconds
- return @floatCast(f64, (@floatFromInt(f64, vm.origin_timestamp) + JSC.VirtualMachine.origin_relative_epoch) / 1_000_000.0);
+ return @as(f64, @floatCast((@as(f64, @floatFromInt(vm.origin_timestamp)) + JSC.VirtualMachine.origin_relative_epoch) / 1_000_000.0));
}
// comptime {
@@ -794,16 +794,16 @@ pub const VirtualMachine = struct {
/// We subtract the timestamp from Jan 1, 2000 (Y2K)
pub const origin_relative_epoch = 946684800 * std.time.ns_per_s;
fn getOriginTimestamp() u64 {
- return @truncate(
+ return @as(
u64,
- @intCast(
+ @truncate(@as(
u128,
// handle if they set their system clock to be before epoch
- @max(
+ @intCast(@max(
std.time.nanoTimestamp(),
origin_relative_epoch,
- ),
- ) - origin_relative_epoch,
+ )),
+ ) - origin_relative_epoch),
);
}
@@ -883,7 +883,7 @@ pub const VirtualMachine = struct {
}
vm.global = ZigGlobalObject.create(
&global_classes,
- @intCast(i32, global_classes.len),
+ @as(i32, @intCast(global_classes.len)),
vm.console,
-1,
false,
@@ -985,7 +985,7 @@ pub const VirtualMachine = struct {
}
vm.global = ZigGlobalObject.create(
&global_classes,
- @intCast(i32, global_classes.len),
+ @as(i32, @intCast(global_classes.len)),
vm.console,
-1,
smol,
@@ -1087,9 +1087,9 @@ pub const VirtualMachine = struct {
}
vm.global = ZigGlobalObject.create(
&global_classes,
- @intCast(i32, global_classes.len),
+ @as(i32, @intCast(global_classes.len)),
vm.console,
- @intCast(i32, worker.execution_context_id),
+ @as(i32, @intCast(worker.execution_context_id)),
worker.mini,
);
vm.regular_event_loop.global = vm.global;
@@ -1402,7 +1402,7 @@ pub const VirtualMachine = struct {
var vm_ = globalObject.bunVM();
if (vm_.global == globalObject) {
- vm_.enqueueTask(Task.init(@ptrCast(*JSC.MicrotaskForDefaultGlobalObject, microtask)));
+ vm_.enqueueTask(Task.init(@as(*JSC.MicrotaskForDefaultGlobalObject, @ptrCast(microtask))));
} else {
vm_.enqueueTask(Task.init(microtask));
}
@@ -1685,7 +1685,7 @@ pub const VirtualMachine = struct {
err,
globalThis.createAggregateError(
errors.ptr,
- @intCast(u16, errors.len),
+ @as(u16, @intCast(errors.len)),
&ZigString.init(
std.fmt.allocPrint(globalThis.allocator(), "{d} errors building \"{}\"", .{
errors.len,
@@ -1730,7 +1730,7 @@ pub const VirtualMachine = struct {
this.last_reported_error_for_dedupe = result;
if (result.isException(this.global.vm())) {
- var exception = @ptrCast(*Exception, result.asVoid());
+ var exception = @as(*Exception, @ptrCast(result.asVoid()));
this.printException(
exception,
@@ -2001,7 +2001,7 @@ pub const VirtualMachine = struct {
iterator(_vm, globalObject, nextValue, ctx.?, false);
}
inline fn iterator(_: [*c]VM, _: [*c]JSGlobalObject, nextValue: JSValue, ctx: ?*anyopaque, comptime color: bool) void {
- var this_ = @ptrFromInt(*@This(), @intFromPtr(ctx));
+ var this_ = @as(*@This(), @ptrFromInt(@intFromPtr(ctx)));
VirtualMachine.get().printErrorlikeObject(nextValue, null, this_.current_exception_list, Writer, this_.writer, color, allow_side_effects);
}
};
@@ -2099,7 +2099,7 @@ pub const VirtualMachine = struct {
const dir = vm.bundler.fs.top_level_dir;
while (i < stack.len) : (i += 1) {
- const frame = stack[@intCast(usize, i)];
+ const frame = stack[@as(usize, @intCast(i))];
const file_slice = frame.source_url.toUTF8(bun.default_allocator);
defer file_slice.deinit();
const func_slice = frame.function_name.toUTF8(bun.default_allocator);
@@ -2215,7 +2215,7 @@ pub const VirtualMachine = struct {
frames[j] = frame;
j += 1;
}
- exception.stack.frames_len = @truncate(u8, j);
+ exception.stack.frames_len = @as(u8, @truncate(j));
frames.len = j;
}
}
@@ -2249,7 +2249,7 @@ pub const VirtualMachine = struct {
if (strings.getLinesInText(
code.slice(),
- @intCast(u32, top.position.line),
+ @as(u32, @intCast(top.position.line)),
JSC.ZigException.Holder.source_lines_count,
)) |lines| {
var source_lines = exception.stack.source_lines_ptr[0..JSC.ZigException.Holder.source_lines_count];
@@ -2260,12 +2260,12 @@ pub const VirtualMachine = struct {
var lines_ = lines[0..@min(lines.len, source_lines.len)];
for (lines_, 0..) |line, j| {
source_lines[(lines_.len - 1) - j] = String.init(line);
- source_line_numbers[j] = top.position.line - @intCast(i32, j) + 1;
+ source_line_numbers[j] = top.position.line - @as(i32, @intCast(j)) + 1;
}
- exception.stack.source_lines_len = @intCast(u8, lines_.len);
+ exception.stack.source_lines_len = @as(u8, @intCast(lines_.len));
- top.position.column_stop = @intCast(i32, source_lines[lines_.len - 1].length());
+ top.position.column_stop = @as(i32, @intCast(source_lines[lines_.len - 1].length()));
top.position.line_stop = top.position.column_stop;
// This expression range is no longer accurate
@@ -2372,11 +2372,11 @@ pub const VirtualMachine = struct {
);
if (!top.position.isInvalid()) {
- var first_non_whitespace = @intCast(u32, top.position.column_start);
+ var first_non_whitespace = @as(u32, @intCast(top.position.column_start));
while (first_non_whitespace < text.len and text[first_non_whitespace] == ' ') {
first_non_whitespace += 1;
}
- const indent = @intCast(usize, pad) + " | ".len + first_non_whitespace;
+ const indent = @as(usize, @intCast(pad)) + " | ".len + first_non_whitespace;
try writer.writeByteNTimes(' ', indent);
try writer.print(comptime Output.prettyFmt(
@@ -2572,7 +2572,7 @@ pub const EventListenerMixin = struct {
const FetchEventRejectionHandler = struct {
pub fn onRejection(_ctx: *anyopaque, err: anyerror, fetch_event: *FetchEvent, value: JSValue) void {
onError(
- @ptrFromInt(*CtxType, @intFromPtr(_ctx)),
+ @as(*CtxType, @ptrFromInt(@intFromPtr(_ctx))),
err,
value,
fetch_event.request_context.?,
@@ -2940,7 +2940,7 @@ pub fn NewHotReloader(comptime Ctx: type, comptime EventLoopType: type, comptime
var path_string: bun.PathString = undefined;
var file_hash: @This().Watcher.HashType = last_file_hash;
const abs_path: string = brk: {
- if (dir_ent.entries.get(@ptrCast([]const u8, changed_name))) |file_ent| {
+ if (dir_ent.entries.get(@as([]const u8, @ptrCast(changed_name)))) |file_ent| {
// reset the file descriptor
file_ent.entry.cache.fd = 0;
file_ent.entry.need_stat = true;
@@ -2950,9 +2950,9 @@ pub fn NewHotReloader(comptime Ctx: type, comptime EventLoopType: type, comptime
if (hash == file_hash) {
if (file_descriptors[entry_id] != 0) {
if (prev_entry_id != entry_id) {
- current_task.append(@truncate(u32, entry_id));
+ current_task.append(@as(u32, @truncate(entry_id)));
ctx.removeAtIndex(
- @truncate(u16, entry_id),
+ @as(u16, @truncate(entry_id)),
0,
&.{},
.file,
diff --git a/src/bun.js/javascript_core_c_api.zig b/src/bun.js/javascript_core_c_api.zig
index aba143a81..367b4e279 100644
--- a/src/bun.js/javascript_core_c_api.zig
+++ b/src/bun.js/javascript_core_c_api.zig
@@ -9,7 +9,7 @@ const std = @import("std");
const cpp = @import("./bindings/bindings.zig");
const generic = opaque {
pub fn value(this: *const @This()) cpp.JSValue {
- return @enumFromInt(cpp.JSValue, @bitCast(cpp.JSValue.Type, @intFromPtr(this)));
+ return @as(cpp.JSValue, @enumFromInt(@as(cpp.JSValue.Type, @bitCast(@intFromPtr(this)))));
}
pub inline fn bunVM(this: *@This()) *@import("root").bun.JSC.VirtualMachine {
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig
index e7e4d700e..07e25282f 100644
--- a/src/bun.js/module_loader.zig
+++ b/src/bun.js/module_loader.zig
@@ -826,7 +826,7 @@ pub const ModuleLoader = struct {
else
null;
resolved_source.commonjs_exports_len = if (commonjs_exports.len > 0)
- @truncate(u32, commonjs_exports.len)
+ @as(u32, @truncate(commonjs_exports.len))
else if (parse_result.ast.exports_kind == .cjs)
std.math.maxInt(u32)
else
@@ -845,7 +845,7 @@ pub const ModuleLoader = struct {
else
null,
.commonjs_exports_len = if (commonjs_exports.len > 0)
- @truncate(u32, commonjs_exports.len)
+ @as(u32, @truncate(commonjs_exports.len))
else if (parse_result.ast.exports_kind == .cjs)
std.math.maxInt(u32)
else
@@ -1228,7 +1228,7 @@ pub const ModuleLoader = struct {
else
null;
resolved_source.commonjs_exports_len = if (commonjs_exports.len > 0)
- @truncate(u32, commonjs_exports.len)
+ @as(u32, @truncate(commonjs_exports.len))
else if (parse_result.ast.exports_kind == .cjs)
std.math.maxInt(u32)
else
@@ -1265,7 +1265,7 @@ pub const ModuleLoader = struct {
else
null,
.commonjs_exports_len = if (commonjs_exports.len > 0)
- @truncate(u32, commonjs_exports.len)
+ @as(u32, @truncate(commonjs_exports.len))
else if (parse_result.ast.exports_kind == .cjs)
std.math.maxInt(u32)
else
@@ -1330,7 +1330,7 @@ pub const ModuleLoader = struct {
var encoded = JSC.EncodedJSValue{
.asPtr = globalThis,
};
- const globalValue = @enumFromInt(JSC.JSValue, encoded.asInt64);
+ const globalValue = @as(JSC.JSValue, @enumFromInt(encoded.asInt64));
globalValue.put(
globalThis,
JSC.ZigString.static("wasmSourceBytes"),
@@ -2204,9 +2204,11 @@ pub const HardcodedModule = enum {
.{ "path/win32", .{ .path = "node:path/win32" } },
.{ "perf_hooks", .{ .path = "node:perf_hooks" } },
.{ "process", .{ .path = "node:process" } },
- .{ "readable-stream", .{ .path = "node:stream" } },
- .{ "readable-stream/consumer", .{ .path = "node:stream/consumers" } },
- .{ "readable-stream/web", .{ .path = "node:stream/web" } },
+ // Older versions of `readable-stream` is incompatible with latest
+ // version of Node.js Stream API, which `bun` implements
+ // .{ "readable-stream", .{ .path = "node:stream" } },
+ // .{ "readable-stream/consumer", .{ .path = "node:stream/consumers" } },
+ // .{ "readable-stream/web", .{ .path = "node:stream/web" } },
.{ "readline", .{ .path = "node:readline" } },
.{ "readline/promises", .{ .path = "node:readline/promises" } },
.{ "stream", .{ .path = "node:stream" } },
diff --git a/src/bun.js/node/dir_iterator.zig b/src/bun.js/node/dir_iterator.zig
index dac78e5e2..968fde001 100644
--- a/src/bun.js/node/dir_iterator.zig
+++ b/src/bun.js/node/dir_iterator.zig
@@ -65,13 +65,13 @@ pub const Iterator = switch (builtin.os.tag) {
}
self.index = 0;
- self.end_index = @intCast(usize, rc);
+ self.end_index = @as(usize, @intCast(rc));
}
- const darwin_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]);
+ const darwin_entry = @as(*align(1) os.system.dirent, @ptrCast(&self.buf[self.index]));
const next_index = self.index + darwin_entry.reclen();
self.index = next_index;
- const name = @ptrCast([*]u8, &darwin_entry.d_name)[0..darwin_entry.d_namlen];
+ const name = @as([*]u8, @ptrCast(&darwin_entry.d_name))[0..darwin_entry.d_namlen];
if (strings.eqlComptime(name, ".") or strings.eqlComptime(name, "..") or (darwin_entry.d_ino == 0)) {
continue :start_over;
@@ -122,11 +122,11 @@ pub const Iterator = switch (builtin.os.tag) {
self.index = 0;
self.end_index = rc;
}
- const linux_entry = @ptrCast(*align(1) linux.dirent64, &self.buf[self.index]);
+ const linux_entry = @as(*align(1) linux.dirent64, @ptrCast(&self.buf[self.index]));
const next_index = self.index + linux_entry.reclen();
self.index = next_index;
- const name = mem.sliceTo(@ptrCast([*:0]u8, &linux_entry.d_name), 0);
+ const name = mem.sliceTo(@as([*:0]u8, @ptrCast(&linux_entry.d_name)), 0);
// skip . and .. entries
if (strings.eqlComptime(name, ".") or strings.eqlComptime(name, "..")) {
@@ -196,15 +196,14 @@ pub const Iterator = switch (builtin.os.tag) {
}
}
- const aligned_ptr = @alignCast(@alignOf(w.FILE_BOTH_DIR_INFORMATION), &self.buf[self.index]);
- const dir_info = @ptrCast(*w.FILE_BOTH_DIR_INFORMATION, aligned_ptr);
+ const dir_info: *w.FILE_BOTH_DIR_INFORMATION = @ptrCast(@alignCast(&self.buf[self.index]));
if (dir_info.NextEntryOffset != 0) {
self.index += dir_info.NextEntryOffset;
} else {
self.index = self.buf.len;
}
- const name_utf16le = @ptrCast([*]u16, &dir_info.FileName)[0 .. dir_info.FileNameLength / 2];
+ const name_utf16le = @as([*]u16, @ptrCast(&dir_info.FileName))[0 .. dir_info.FileNameLength / 2];
if (mem.eql(u16, name_utf16le, &[_]u16{'.'}) or mem.eql(u16, name_utf16le, &[_]u16{ '.', '.' }))
continue;
@@ -260,7 +259,7 @@ pub const Iterator = switch (builtin.os.tag) {
self.index = 0;
self.end_index = bufused;
}
- const entry = @ptrCast(*align(1) w.dirent_t, &self.buf[self.index]);
+ const entry = @as(*align(1) w.dirent_t, @ptrCast(&self.buf[self.index]));
const entry_size = @sizeOf(w.dirent_t);
const name_index = self.index + entry_size;
const name = mem.span(self.buf[name_index .. name_index + entry.d_namlen]);
diff --git a/src/bun.js/node/fs_events.zig b/src/bun.js/node/fs_events.zig
index a3fba5441..54c969d0f 100644
--- a/src/bun.js/node/fs_events.zig
+++ b/src/bun.js/node/fs_events.zig
@@ -254,7 +254,7 @@ pub const FSEventsLoop = struct {
}
pub fn wrap(this: ?*anyopaque) void {
- @call(.always_inline, Callback, .{@ptrCast(*Type, @alignCast(@alignOf(Type), this.?))});
+ @call(.always_inline, Callback, .{@as(*Type, @ptrCast(@alignCast(this.?)))});
}
};
}
diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig
index 3f298c5c7..8fb769fac 100644
--- a/src/bun.js/node/node_fs.zig
+++ b/src/bun.js/node/node_fs.zig
@@ -368,7 +368,7 @@ pub const Arguments = struct {
};
arguments.eat();
- break :brk @intCast(uid_t, uid_value.toInt32());
+ break :brk @as(uid_t, @intCast(uid_value.toInt32()));
};
const gid: gid_t = brk: {
@@ -385,7 +385,7 @@ pub const Arguments = struct {
};
arguments.eat();
- break :brk @intCast(gid_t, gid_value.toInt32());
+ break :brk @as(gid_t, @intCast(gid_value.toInt32()));
};
return Chown{ .path = path, .uid = uid, .gid = gid };
@@ -438,7 +438,7 @@ pub const Arguments = struct {
};
arguments.eat();
- break :brk @intCast(uid_t, uid_value.toInt32());
+ break :brk @as(uid_t, @intCast(uid_value.toInt32()));
};
const gid: gid_t = brk: {
@@ -455,7 +455,7 @@ pub const Arguments = struct {
};
arguments.eat();
- break :brk @intCast(gid_t, gid_value.toInt32());
+ break :brk @as(gid_t, @intCast(gid_value.toInt32()));
};
return Fchown{ .fd = fd, .uid = uid, .gid = gid };
@@ -1672,7 +1672,7 @@ pub const Arguments = struct {
}
if (arguments.remaining[1].isNumber() or arguments.remaining[1].isBigInt())
- args.position = @intCast(ReadPosition, arguments.remaining[1].to(i52));
+ args.position = @as(ReadPosition, @intCast(arguments.remaining[1].to(i52)));
arguments.remaining = arguments.remaining[2..];
} else if (current.isObject()) {
@@ -1798,7 +1798,7 @@ pub const Arguments = struct {
mode: Mode = 0o666,
file: PathOrFileDescriptor,
data: StringOrBuffer,
- dirfd: FileDescriptor = @intCast(FileDescriptor, std.fs.cwd().fd),
+ dirfd: FileDescriptor = @as(FileDescriptor, @intCast(std.fs.cwd().fd)),
pub fn deinit(self: WriteFile) void {
self.file.deinit();
@@ -2424,7 +2424,7 @@ pub const Arguments = struct {
return CopyFile{
.src = src,
.dest = dest,
- .mode = @enumFromInt(Constants.Copyfile, mode),
+ .mode = @as(Constants.Copyfile, @enumFromInt(mode)),
};
}
};
@@ -2568,7 +2568,7 @@ const Return = struct {
ctx.ptr(),
&fields.bytesRead,
&fields.buffer,
- JSC.JSValue.jsNumberFromUint64(@intCast(u52, @min(std.math.maxInt(u52), this.bytes_read))),
+ JSC.JSValue.jsNumberFromUint64(@as(u52, @intCast(@min(std.math.maxInt(u52), this.bytes_read)))),
this.buffer_val,
).asObjectRef();
}
@@ -2592,7 +2592,7 @@ const Return = struct {
ctx.ptr(),
&fields.bytesWritten,
&fields.buffer,
- JSC.JSValue.jsNumberFromUint64(@intCast(u52, @min(std.math.maxInt(u52), this.bytes_written))),
+ JSC.JSValue.jsNumberFromUint64(@as(u52, @intCast(@min(std.math.maxInt(u52), this.bytes_written)))),
if (this.buffer == .buffer)
this.buffer_val
else
@@ -2805,7 +2805,7 @@ pub const NodeFS = struct {
.err => |err| return Maybe(Return.CopyFile){ .err = err },
};
defer {
- _ = std.c.ftruncate(dest_fd, @intCast(std.c.off_t, @truncate(u63, wrote)));
+ _ = std.c.ftruncate(dest_fd, @as(std.c.off_t, @intCast(@as(u63, @truncate(wrote)))));
_ = Syscall.close(dest_fd);
}
@@ -2815,7 +2815,7 @@ 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, @max(stat_.size, 0));
+ var remain = @as(u64, @intCast(@max(stat_.size, 0)));
toplevel: while (remain > 0) {
const amt = switch (Syscall.read(src_fd, buf[0..@min(buf.len, remain)])) {
.result => |result| result,
@@ -2913,15 +2913,15 @@ pub const NodeFS = struct {
.err => |err| return Maybe(Return.CopyFile){ .err = err },
};
- var size = @intCast(usize, @max(stat_.size, 0));
+ var size = @as(usize, @intCast(@max(stat_.size, 0)));
defer {
- _ = linux.ftruncate(dest_fd, @intCast(i64, @truncate(u63, wrote)));
+ _ = linux.ftruncate(dest_fd, @as(i64, @intCast(@as(u63, @truncate(wrote)))));
_ = Syscall.close(dest_fd);
}
- var off_in_copy = @bitCast(i64, @as(u64, 0));
- var off_out_copy = @bitCast(i64, @as(u64, 0));
+ var off_in_copy = @as(i64, @bitCast(@as(u64, 0)));
+ var off_out_copy = @as(i64, @bitCast(@as(u64, 0)));
if (size == 0) {
// copy until EOF
@@ -3199,7 +3199,7 @@ pub const NodeFS = struct {
.sync => {
var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
const path = args.path.sliceZWithForceCopy(&buf, true);
- const len = @truncate(u16, path.len);
+ const len = @as(u16, @truncate(path.len));
// First, attempt to create the desired directory
// If that fails, then walk back up the path until we have a match
@@ -3349,8 +3349,8 @@ pub const NodeFS = struct {
};
}
// std.c.getErrno(rc) returns SUCCESS if rc is null so we call std.c._errno() directly
- const errno = @enumFromInt(std.c.E, std.c._errno().*);
- return .{ .err = Syscall.Error{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(errno)), .syscall = .mkdtemp } };
+ const errno = @as(std.c.E, @enumFromInt(std.c._errno().*));
+ return .{ .err = Syscall.Error{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(errno))), .syscall = .mkdtemp } };
}
pub fn open(this: *NodeFS, args: Arguments.Open, comptime flavor: Flavor) Maybe(Return.Open) {
switch (comptime flavor) {
@@ -3389,7 +3389,7 @@ pub const NodeFS = struct {
},
.result => |amt| .{
.result = .{
- .bytes_read = @truncate(u52, amt),
+ .bytes_read = @as(u52, @truncate(amt)),
},
},
};
@@ -3413,7 +3413,7 @@ pub const NodeFS = struct {
},
.result => |amt| .{
.result = .{
- .bytes_read = @truncate(u52, amt),
+ .bytes_read = @as(u52, @truncate(amt)),
},
},
};
@@ -3461,7 +3461,7 @@ pub const NodeFS = struct {
},
.result => |amt| .{
.result = .{
- .bytes_written = @truncate(u52, amt),
+ .bytes_written = @as(u52, @truncate(amt)),
},
},
};
@@ -3486,7 +3486,7 @@ pub const NodeFS = struct {
.err = err,
},
.result => |amt| .{ .result = .{
- .bytes_written = @truncate(u52, amt),
+ .bytes_written = @as(u52, @truncate(amt)),
} },
};
},
@@ -3506,7 +3506,7 @@ pub const NodeFS = struct {
.err = err,
},
.result => |amt| .{ .result = .{
- .bytes_read = @truncate(u52, amt),
+ .bytes_read = @as(u52, @truncate(amt)),
} },
};
},
@@ -3524,7 +3524,7 @@ pub const NodeFS = struct {
.err = err,
},
.result => |amt| .{ .result = .{
- .bytes_read = @truncate(u52, amt),
+ .bytes_read = @as(u52, @truncate(amt)),
} },
};
},
@@ -3544,7 +3544,7 @@ pub const NodeFS = struct {
.err = err,
},
.result => |amt| .{ .result = .{
- .bytes_written = @truncate(u52, amt),
+ .bytes_written = @as(u52, @truncate(amt)),
} },
};
},
@@ -3562,7 +3562,7 @@ pub const NodeFS = struct {
.err = err,
},
.result => |amt| .{ .result = .{
- .bytes_written = @truncate(u52, amt),
+ .bytes_written = @as(u52, @truncate(amt)),
} },
};
},
@@ -3775,21 +3775,21 @@ pub const NodeFS = struct {
}
// For certain files, the size might be 0 but the file might still have contents.
- const size = @intCast(
+ const size = @as(
u64,
- @max(
+ @intCast(@max(
@min(
stat_.size,
- @intCast(
+ @as(
@TypeOf(stat_.size),
// Only used in DOMFormData
- args.max_size orelse std.math.maxInt(
+ @intCast(args.max_size orelse std.math.maxInt(
JSC.WebCore.Blob.SizeType,
- ),
+ )),
),
),
0,
- ),
+ )),
) + if (comptime string_type == .null_terminated) 1 else 0;
var buf = std.ArrayList(u8).init(bun.default_allocator);
@@ -3937,20 +3937,20 @@ pub const NodeFS = struct {
// on linux, it's absolutely positioned
const pos = JSC.Node.Syscall.system.lseek(
fd,
- @intCast(std.os.off_t, 0),
+ @as(std.os.off_t, @intCast(0)),
std.os.linux.SEEK.CUR,
);
switch (JSC.Node.Syscall.getErrno(pos)) {
- .SUCCESS => break :brk @intCast(usize, pos),
+ .SUCCESS => break :brk @as(usize, @intCast(pos)),
else => break :preallocate,
}
};
bun.C.preallocate_file(
fd,
- @intCast(std.os.off_t, offset),
- @intCast(std.os.off_t, buf.len),
+ @as(std.os.off_t, @intCast(offset)),
+ @as(std.os.off_t, @intCast(buf.len)),
) catch {};
}
}
@@ -3973,7 +3973,7 @@ pub const NodeFS = struct {
// https://github.com/oven-sh/bun/issues/2931
if ((@intFromEnum(args.flag) & std.os.O.APPEND) == 0) {
- _ = ftruncateSync(.{ .fd = fd, .len = @truncate(JSC.WebCore.Blob.SizeType, written) });
+ _ = ftruncateSync(.{ .fd = fd, .len = @as(JSC.WebCore.Blob.SizeType, @truncate(written)) });
}
return Maybe(Return.WriteFile).success;
@@ -4119,7 +4119,7 @@ pub const NodeFS = struct {
while (true) {
if (Maybe(Return.Rmdir).errnoSys(bun.C.darwin.removefileat(std.os.AT.FDCWD, dest, null, flags), .rmdir)) |errno| {
- switch (@enumFromInt(os.E, errno.err.errno)) {
+ switch (@as(os.E, @enumFromInt(errno.err.errno))) {
.AGAIN, .INTR => continue,
.NOENT => return Maybe(Return.Rmdir).success,
.MLINK => {
@@ -4206,7 +4206,7 @@ pub const NodeFS = struct {
}
if (Maybe(Return.Rm).errnoSys(bun.C.darwin.removefileat(std.os.AT.FDCWD, dest, null, flags), .unlink)) |errno| {
- switch (@enumFromInt(os.E, errno.err.errno)) {
+ switch (@as(os.E, @enumFromInt(errno.err.errno))) {
.AGAIN, .INTR => continue,
.NOENT => {
if (args.force) {
diff --git a/src/bun.js/node/node_os.zig b/src/bun.js/node/node_os.zig
index 483acb3e2..5710b5c21 100644
--- a/src/bun.js/node/node_os.zig
+++ b/src/bun.js/node/node_os.zig
@@ -207,7 +207,7 @@ pub const Os = struct {
var num_cpus: c.natural_t = 0;
var info: [*]local_bindings.processor_cpu_load_info = undefined;
var info_size: std.c.mach_msg_type_number_t = 0;
- if (local_bindings.host_processor_info(std.c.mach_host_self(), local_bindings.PROCESSOR_CPU_LOAD_INFO, &num_cpus, @ptrCast(*local_bindings.processor_info_array_t, &info), &info_size) != .SUCCESS) {
+ if (local_bindings.host_processor_info(std.c.mach_host_self(), local_bindings.PROCESSOR_CPU_LOAD_INFO, &num_cpus, @as(*local_bindings.processor_info_array_t, @ptrCast(&info)), &info_size) != .SUCCESS) {
return error.no_processor_info;
}
defer _ = std.c.vm_deallocate(std.c.mach_task_self(), @intFromPtr(info), info_size);
@@ -247,10 +247,10 @@ pub const Os = struct {
@cInclude("unistd.h");
});
const ticks: i64 = unistd.sysconf(unistd._SC_CLK_TCK);
- const multiplier = 1000 / @intCast(u64, ticks);
+ const multiplier = 1000 / @as(u64, @intCast(ticks));
// Set up each CPU value in the return
- const values = JSC.JSValue.createEmptyArray(globalThis, @intCast(u32, num_cpus));
+ const values = JSC.JSValue.createEmptyArray(globalThis, @as(u32, @intCast(num_cpus)));
var cpu_index: u32 = 0;
while (cpu_index < num_cpus) : (cpu_index += 1) {
const times = CPUTimes{
@@ -436,8 +436,8 @@ pub const Os = struct {
if (helpers.skip(iface) or helpers.isLinkLayer(iface)) continue;
const interface_name = std.mem.sliceTo(iface.ifa_name, 0);
- const addr = std.net.Address.initPosix(@alignCast(4, @ptrCast(*std.os.sockaddr, iface.ifa_addr)));
- const netmask = std.net.Address.initPosix(@alignCast(4, @ptrCast(*std.os.sockaddr, iface.ifa_netmask)));
+ const addr = std.net.Address.initPosix(@alignCast(@as(*std.os.sockaddr, @ptrCast(iface.ifa_addr))));
+ const netmask = std.net.Address.initPosix(@alignCast(@as(*std.os.sockaddr, @ptrCast(iface.ifa_netmask))));
var interface = JSC.JSValue.createEmptyObject(globalThis, 7);
@@ -448,7 +448,7 @@ pub const Os = struct {
// be converted to a CIDR suffix
const maybe_suffix: ?u8 = switch (addr.any.family) {
std.os.AF.INET => netmaskToCIDRSuffix(netmask.in.sa.addr),
- std.os.AF.INET6 => netmaskToCIDRSuffix(@bitCast(u128, netmask.in6.sa.addr)),
+ std.os.AF.INET6 => netmaskToCIDRSuffix(@as(u128, @bitCast(netmask.in6.sa.addr))),
else => null,
};
@@ -500,9 +500,9 @@ pub const Os = struct {
// This is the correct link-layer interface entry for the current interface,
// cast to a link-layer socket address
if (comptime Environment.isLinux) {
- break @ptrCast(?*std.os.sockaddr.ll, @alignCast(4, ll_iface.ifa_addr));
+ break @as(?*std.os.sockaddr.ll, @ptrCast(@alignCast(ll_iface.ifa_addr)));
} else if (comptime Environment.isMac) {
- break @ptrCast(?*C.sockaddr_dl, @alignCast(2, ll_iface.ifa_addr));
+ break @as(?*C.sockaddr_dl, @ptrCast(@alignCast(ll_iface.ifa_addr)));
} else unreachable;
} else null;
@@ -530,7 +530,7 @@ pub const Os = struct {
// Does this entry already exist?
if (ret.get(globalThis, interface_name)) |array| {
// Add this interface entry to the existing array
- const next_index = @intCast(u32, array.getLength(globalThis));
+ const next_index = @as(u32, @intCast(array.getLength(globalThis)));
array.putIndex(globalThis, next_index, interface);
} else {
// Add it as an array with this interface as an element
@@ -750,7 +750,7 @@ test "netmaskToCIDRSuffix" {
};
inline for (ipv6_tests) |t| {
const addr = try std.net.Address.parseIp6(t[0], 0);
- const bits = @bitCast(u128, addr.in6.sa.addr);
+ const bits = @as(u128, @bitCast(addr.in6.sa.addr));
try std.testing.expectEqual(@as(?u8, t[1]), netmaskToCIDRSuffix(bits));
}
}
diff --git a/src/bun.js/node/syscall.zig b/src/bun.js/node/syscall.zig
index 5ff0b2f44..4dbb23f0d 100644
--- a/src/bun.js/node/syscall.zig
+++ b/src/bun.js/node/syscall.zig
@@ -182,7 +182,7 @@ pub fn mkdir(file_path: [:0]const u8, flags: JSC.Node.Mode) Maybe(void) {
pub fn fcntl(fd: bun.FileDescriptor, cmd: i32, arg: usize) Maybe(usize) {
const result = fcntl_symbol(fd, cmd, arg);
if (Maybe(usize).errnoSys(result, .fcntl)) |err| return err;
- return .{ .result = @intCast(usize, result) };
+ return .{ .result = @as(usize, @intCast(result)) };
}
pub fn getErrno(rc: anytype) std.os.E {
@@ -191,7 +191,7 @@ pub fn getErrno(rc: anytype) std.os.E {
return switch (Type) {
comptime_int, usize => std.os.linux.getErrno(@as(usize, rc)),
- i32, c_int, isize => std.os.linux.getErrno(@bitCast(usize, @as(isize, rc))),
+ i32, c_int, isize => std.os.linux.getErrno(@as(usize, @bitCast(@as(isize, rc)))),
else => @compileError("Not implemented yet for type " ++ @typeName(Type)),
};
}
@@ -199,14 +199,14 @@ pub fn getErrno(rc: anytype) std.os.E {
pub fn openat(dirfd: bun.FileDescriptor, file_path: [:0]const u8, flags: JSC.Node.Mode, perm: JSC.Node.Mode) Maybe(bun.FileDescriptor) {
if (comptime Environment.isMac) {
// https://opensource.apple.com/source/xnu/xnu-7195.81.3/libsyscall/wrappers/open-base.c
- const rc = bun.AsyncIO.darwin.@"openat$NOCANCEL"(dirfd, file_path.ptr, @intCast(c_uint, flags), @intCast(c_int, perm));
+ const rc = bun.AsyncIO.darwin.@"openat$NOCANCEL"(dirfd, file_path.ptr, @as(c_uint, @intCast(flags)), @as(c_int, @intCast(perm)));
log("openat({d}, {s}) = {d}", .{ dirfd, file_path, rc });
return switch (Syscall.getErrno(rc)) {
- .SUCCESS => .{ .result = @intCast(bun.FileDescriptor, rc) },
+ .SUCCESS => .{ .result = @as(bun.FileDescriptor, @intCast(rc)) },
else => |err| .{
.err = .{
- .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)),
+ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))),
.syscall = .open,
},
},
@@ -214,15 +214,15 @@ pub fn openat(dirfd: bun.FileDescriptor, file_path: [:0]const u8, flags: JSC.Nod
}
while (true) {
- const rc = Syscall.system.openat(@intCast(Syscall.system.fd_t, dirfd), file_path, flags, perm);
+ const rc = Syscall.system.openat(@as(Syscall.system.fd_t, @intCast(dirfd)), file_path, flags, perm);
log("openat({d}, {s}) = {d}", .{ dirfd, file_path, rc });
return switch (Syscall.getErrno(rc)) {
- .SUCCESS => .{ .result = @intCast(bun.FileDescriptor, rc) },
+ .SUCCESS => .{ .result = @as(bun.FileDescriptor, @intCast(rc)) },
.INTR => continue,
else => |err| {
return Maybe(std.os.fd_t){
.err = .{
- .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)),
+ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))),
.syscall = .open,
},
};
@@ -235,7 +235,7 @@ pub fn openat(dirfd: bun.FileDescriptor, file_path: [:0]const u8, flags: JSC.Nod
pub fn open(file_path: [:0]const u8, flags: JSC.Node.Mode, perm: JSC.Node.Mode) Maybe(bun.FileDescriptor) {
// this is what open() does anyway.
- return openat(@intCast(bun.FileDescriptor, std.fs.cwd().fd), file_path, flags, perm);
+ return openat(@as(bun.FileDescriptor, @intCast(std.fs.cwd().fd)), file_path, flags, perm);
}
/// This function will prevent stdout and stderr from being closed.
@@ -289,7 +289,7 @@ pub fn write(fd: os.fd_t, bytes: []const u8) Maybe(usize) {
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
} else {
while (true) {
const rc = sys.write(fd, bytes.ptr, adjusted_len);
@@ -300,7 +300,7 @@ pub fn write(fd: os.fd_t, bytes: []const u8) Maybe(usize) {
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
}
unreachable;
}
@@ -316,7 +316,7 @@ fn veclen(buffers: anytype) usize {
pub fn writev(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) {
if (comptime Environment.isMac) {
- const rc = writev_sym(fd, @ptrCast([*]std.os.iovec_const, buffers.ptr), @intCast(i32, buffers.len));
+ const rc = writev_sym(fd, @as([*]std.os.iovec_const, @ptrCast(buffers.ptr)), @as(i32, @intCast(buffers.len)));
if (comptime Environment.allow_assert)
log("writev({d}, {d}) = {d}", .{ fd, veclen(buffers), rc });
@@ -324,10 +324,10 @@ pub fn writev(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) {
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
} else {
while (true) {
- const rc = writev_sym(fd, @ptrCast([*]std.os.iovec_const, buffers.ptr), buffers.len);
+ const rc = writev_sym(fd, @as([*]std.os.iovec_const, @ptrCast(buffers.ptr)), buffers.len);
if (comptime Environment.allow_assert)
log("writev({d}, {d}) = {d}", .{ fd, veclen(buffers), rc });
@@ -336,7 +336,7 @@ pub fn writev(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) {
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
}
unreachable;
}
@@ -344,7 +344,7 @@ pub fn writev(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) {
pub fn pwritev(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usize) {
if (comptime Environment.isMac) {
- const rc = pwritev_sym(fd, @ptrCast([*]std.os.iovec_const, buffers.ptr), @intCast(i32, buffers.len), position);
+ const rc = pwritev_sym(fd, @as([*]std.os.iovec_const, @ptrCast(buffers.ptr)), @as(i32, @intCast(buffers.len)), position);
if (comptime Environment.allow_assert)
log("pwritev({d}, {d}) = {d}", .{ fd, veclen(buffers), rc });
@@ -352,10 +352,10 @@ pub fn pwritev(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usiz
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
} else {
while (true) {
- const rc = pwritev_sym(fd, @ptrCast([*]std.os.iovec_const, buffers.ptr), buffers.len, position);
+ const rc = pwritev_sym(fd, @as([*]std.os.iovec_const, @ptrCast(buffers.ptr)), buffers.len, position);
if (comptime Environment.allow_assert)
log("pwritev({d}, {d}) = {d}", .{ fd, veclen(buffers), rc });
@@ -364,7 +364,7 @@ pub fn pwritev(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usiz
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
}
unreachable;
}
@@ -372,7 +372,7 @@ pub fn pwritev(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usiz
pub fn readv(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) {
if (comptime Environment.isMac) {
- const rc = readv_sym(fd, buffers.ptr, @intCast(i32, buffers.len));
+ const rc = readv_sym(fd, buffers.ptr, @as(i32, @intCast(buffers.len)));
if (comptime Environment.allow_assert)
log("readv({d}, {d}) = {d}", .{ fd, veclen(buffers), rc });
@@ -380,7 +380,7 @@ pub fn readv(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) {
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
} else {
while (true) {
const rc = readv_sym(fd, buffers.ptr, buffers.len);
@@ -392,7 +392,7 @@ pub fn readv(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) {
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
}
unreachable;
}
@@ -400,7 +400,7 @@ pub fn readv(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) {
pub fn preadv(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usize) {
if (comptime Environment.isMac) {
- const rc = preadv_sym(fd, buffers.ptr, @intCast(i32, buffers.len), position);
+ const rc = preadv_sym(fd, buffers.ptr, @as(i32, @intCast(buffers.len)), position);
if (comptime Environment.allow_assert)
log("preadv({d}, {d}) = {d}", .{ fd, veclen(buffers), rc });
@@ -408,7 +408,7 @@ pub fn preadv(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usize
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
} else {
while (true) {
const rc = preadv_sym(fd, buffers.ptr, buffers.len, position);
@@ -420,7 +420,7 @@ pub fn preadv(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usize
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
}
unreachable;
}
@@ -465,14 +465,14 @@ const fcntl_symbol = system.fcntl;
pub fn pread(fd: os.fd_t, buf: []u8, offset: i64) Maybe(usize) {
const adjusted_len = @min(buf.len, max_count);
- const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
+ const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
while (true) {
const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset);
if (Maybe(usize).errnoSys(rc, .pread)) |err| {
if (err.getErrno() == .INTR) continue;
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
}
unreachable;
}
@@ -485,7 +485,7 @@ else
pub fn pwrite(fd: os.fd_t, bytes: []const u8, offset: i64) Maybe(usize) {
const adjusted_len = @min(bytes.len, max_count);
- const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
+ const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
while (true) {
const rc = pwrite_sym(fd, bytes.ptr, adjusted_len, ioffset);
return if (Maybe(usize).errnoSysFd(rc, .pwrite, fd)) |err| {
@@ -493,7 +493,7 @@ pub fn pwrite(fd: os.fd_t, bytes: []const u8, offset: i64) Maybe(usize) {
.INTR => continue,
else => return err,
}
- } else Maybe(usize){ .result = @intCast(usize, rc) };
+ } else Maybe(usize){ .result = @as(usize, @intCast(rc)) };
}
unreachable;
@@ -510,7 +510,7 @@ pub fn read(fd: os.fd_t, buf: []u8) Maybe(usize) {
if (Maybe(usize).errnoSys(rc, .read)) |err| {
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
} else {
while (true) {
const rc = sys.read(fd, buf.ptr, adjusted_len);
@@ -520,7 +520,7 @@ pub fn read(fd: os.fd_t, buf: []u8) Maybe(usize) {
if (err.getErrno() == .INTR) continue;
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
}
}
unreachable;
@@ -537,7 +537,7 @@ pub fn recv(fd: os.fd_t, buf: []u8, flag: u32) Maybe(usize) {
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
} else {
while (true) {
const rc = linux.recvfrom(fd, buf.ptr, adjusted_len, flag | os.SOCK.CLOEXEC | linux.MSG.CMSG_CLOEXEC, null, null);
@@ -547,7 +547,7 @@ pub fn recv(fd: os.fd_t, buf: []u8, flag: u32) Maybe(usize) {
if (err.getErrno() == .INTR) continue;
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
}
}
unreachable;
@@ -559,7 +559,7 @@ pub fn send(fd: os.fd_t, buf: []const u8, flag: u32) Maybe(usize) {
if (Maybe(usize).errnoSys(rc, .send)) |err| {
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
} else {
while (true) {
const rc = linux.sendto(fd, buf.ptr, buf.len, flag | os.SOCK.CLOEXEC | os.MSG.NOSIGNAL, null, 0);
@@ -569,7 +569,7 @@ pub fn send(fd: os.fd_t, buf: []const u8, flag: u32) Maybe(usize) {
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
}
}
unreachable;
@@ -583,7 +583,7 @@ pub fn readlink(in: [:0]const u8, buf: []u8) Maybe(usize) {
if (err.getErrno() == .INTR) continue;
return err;
}
- return Maybe(usize){ .result = @intCast(usize, rc) };
+ return Maybe(usize){ .result = @as(usize, @intCast(rc)) };
}
unreachable;
}
@@ -741,16 +741,16 @@ fn mmap(
fd: os.fd_t,
offset: u64,
) Maybe([]align(mem.page_size) u8) {
- const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
+ const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned
const rc = std.c.mmap(ptr, length, prot, flags, fd, ioffset);
const fail = std.c.MAP.FAILED;
if (rc == fail) {
return Maybe([]align(mem.page_size) u8){
- .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(std.c.getErrno(@bitCast(i64, @intFromPtr(fail))))), .syscall = .mmap },
+ .err = .{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(std.c.getErrno(@as(i64, @bitCast(@intFromPtr(fail))))))), .syscall = .mmap },
};
}
- return Maybe([]align(mem.page_size) u8){ .result = @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length] };
+ return Maybe([]align(mem.page_size) u8){ .result = @as([*]align(mem.page_size) u8, @ptrCast(@alignCast(rc)))[0..length] };
}
pub fn mmapFile(path: [:0]const u8, flags: u32, wanted_size: ?usize, offset: usize) Maybe([]align(mem.page_size) u8) {
@@ -759,13 +759,13 @@ pub fn mmapFile(path: [:0]const u8, flags: u32, wanted_size: ?usize, offset: usi
.err => |err| return .{ .err = err },
};
- var size = std.math.sub(usize, @intCast(usize, switch (fstat(fd)) {
+ var size = std.math.sub(usize, @as(usize, @intCast(switch (fstat(fd)) {
.result => |result| result.size,
.err => |err| {
_ = close(fd);
return .{ .err = err };
},
- }), offset) catch 0;
+ })), offset) catch 0;
if (wanted_size) |size_| size = @min(size, size_);
@@ -804,7 +804,7 @@ pub const Error = struct {
pub const Int: type = std.math.IntFittingRange(0, max_errno_value + 5);
errno: Int,
- syscall: Syscall.Tag = @enumFromInt(Syscall.Tag, 0),
+ syscall: Syscall.Tag = @as(Syscall.Tag, @enumFromInt(0)),
path: []const u8 = "",
fd: i32 = -1,
@@ -813,7 +813,7 @@ pub const Error = struct {
}
pub fn fromCode(errno: os.E, syscall: Syscall.Tag) Error {
- return .{ .errno = @truncate(Int, @intFromEnum(errno)), .syscall = syscall };
+ return .{ .errno = @as(Int, @truncate(@intFromEnum(errno))), .syscall = syscall };
}
pub fn format(self: Error, comptime fmt: []const u8, opts: std.fmt.FormatOptions, writer: anytype) !void {
@@ -824,16 +824,16 @@ pub const Error = struct {
pub const retry = Error{
.errno = if (Environment.isLinux)
- @intCast(Int, @intFromEnum(os.E.AGAIN))
+ @as(Int, @intCast(@intFromEnum(os.E.AGAIN)))
else if (Environment.isMac)
- @intCast(Int, @intFromEnum(os.E.WOULDBLOCK))
+ @as(Int, @intCast(@intFromEnum(os.E.WOULDBLOCK)))
else
- @intCast(Int, @intFromEnum(os.E.INTR)),
+ @as(Int, @intCast(@intFromEnum(os.E.INTR))),
.syscall = .retry,
};
pub inline fn getErrno(this: Error) os.E {
- return @enumFromInt(os.E, this.errno);
+ return @as(os.E, @enumFromInt(this.errno));
}
pub inline fn withPath(this: Error, path: anytype) Error {
@@ -848,7 +848,7 @@ pub const Error = struct {
return Error{
.errno = this.errno,
.syscall = this.syscall,
- .fd = @intCast(i32, fd),
+ .fd = @as(i32, @intCast(fd)),
};
}
@@ -878,7 +878,7 @@ pub const Error = struct {
// errno label
if (this.errno > 0 and this.errno < C.SystemErrno.max) {
- const system_errno = @enumFromInt(C.SystemErrno, this.errno);
+ const system_errno = @as(C.SystemErrno, @enumFromInt(this.errno));
err.code = bun.String.static(@tagName(system_errno));
if (C.SystemErrno.labels.get(system_errno)) |label| {
err.message = bun.String.static(label);
@@ -935,9 +935,9 @@ pub fn setPipeCapacityOnLinux(fd: bun.FileDescriptor, capacity: usize) Maybe(usi
}
pub fn getMaxPipeSizeOnLinux() usize {
- return @intCast(
+ return @as(
usize,
- bun.once(struct {
+ @intCast(bun.once(struct {
fn once() c_int {
const strings = bun.strings;
const default_out_size = 512 * 1024;
@@ -963,8 +963,8 @@ 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 @min(@truncate(c_int, max_pipe_size -| 32), 1024 * 1024 * 8);
+ return @min(@as(c_int, @truncate(max_pipe_size -| 32)), 1024 * 1024 * 8);
}
- }.once, c_int),
+ }.once, c_int)),
);
}
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig
index 0b19c7fcc..975a281e5 100644
--- a/src/bun.js/node/types.zig
+++ b/src/bun.js/node/types.zig
@@ -139,7 +139,7 @@ pub fn Maybe(comptime ResultType: type) type {
pub inline fn getErrno(this: @This()) os.E {
return switch (this) {
.result => os.E.SUCCESS,
- .err => |err| @enumFromInt(os.E, err.errno),
+ .err => |err| @as(os.E, @enumFromInt(err.errno)),
};
}
@@ -148,7 +148,7 @@ pub fn Maybe(comptime ResultType: type) type {
.SUCCESS => null,
else => |err| @This(){
// always truncate
- .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)) },
+ .err = .{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))) },
},
};
}
@@ -158,7 +158,7 @@ pub fn Maybe(comptime ResultType: type) type {
.SUCCESS => null,
else => |err| @This(){
// always truncate
- .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)), .syscall = syscall },
+ .err = .{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))), .syscall = syscall },
},
};
}
@@ -169,9 +169,9 @@ pub fn Maybe(comptime ResultType: type) type {
else => |err| @This(){
// always truncate
.err = .{
- .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)),
+ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))),
.syscall = syscall,
- .fd = @intCast(i32, fd),
+ .fd = @as(i32, @intCast(fd)),
},
},
};
@@ -182,7 +182,7 @@ pub fn Maybe(comptime ResultType: type) type {
.SUCCESS => null,
else => |err| @This(){
// always truncate
- .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)), .syscall = syscall, .path = bun.asByteSlice(path) },
+ .err = .{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))), .syscall = syscall, .path = bun.asByteSlice(path) },
},
};
}
@@ -203,7 +203,7 @@ pub const StringOrBuffer = union(Tag) {
}
pub export fn external_string_finalizer(_: ?*anyopaque, _: JSC.C.JSStringRef, buffer: *anyopaque, byteLength: usize) void {
- bun.default_allocator.free(@ptrCast([*]const u8, buffer)[0..byteLength]);
+ bun.default_allocator.free(@as([*]const u8, @ptrCast(buffer))[0..byteLength]);
}
pub fn toJS(this: StringOrBuffer, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef {
@@ -846,7 +846,7 @@ pub const VectorArrayBuffer = struct {
bufferlist.ensureTotalCapacityPrecise(len) catch @panic("Failed to allocate memory for ArrayBuffer[]");
while (i < len) {
- const element = val.getIndex(globalObject, @truncate(u32, i));
+ const element = val.getIndex(globalObject, @as(u32, @truncate(i)));
if (!element.isCell()) {
JSC.throwInvalidArguments("Expected ArrayBufferView[]", .{}, globalObject, exception);
@@ -906,7 +906,7 @@ pub const ArgumentsSlice = struct {
}
pub fn from(vm: *JSC.VirtualMachine, arguments: []const JSC.JSValueRef) ArgumentsSlice {
- return init(vm, @ptrCast([*]const JSC.JSValue, arguments.ptr)[0..arguments.len]);
+ return init(vm, @as([*]const JSC.JSValue, @ptrCast(arguments.ptr))[0..arguments.len]);
}
pub fn init(vm: *JSC.VirtualMachine, arguments: []const JSC.JSValue) ArgumentsSlice {
return ArgumentsSlice{
@@ -918,7 +918,7 @@ pub const ArgumentsSlice = struct {
}
pub inline fn len(this: *const ArgumentsSlice) u16 {
- return @truncate(u16, this.remaining.len);
+ return @as(u16, @truncate(this.remaining.len));
}
pub fn eat(this: *ArgumentsSlice) void {
if (this.remaining.len == 0) {
@@ -952,7 +952,7 @@ pub fn fileDescriptorFromJS(ctx: JSC.C.JSContextRef, value: JSC.JSValue, excepti
return null;
}
- return @truncate(bun.FileDescriptor, fd);
+ return @as(bun.FileDescriptor, @truncate(fd));
}
// Node.js docs:
@@ -965,7 +965,7 @@ pub fn timeLikeFromJS(globalThis: *JSC.JSGlobalObject, value: JSC.JSValue, _: JS
return null;
}
- return @truncate(TimeLike, @intFromFloat(i64, milliseconds / @as(f64, std.time.ms_per_s)));
+ return @as(TimeLike, @truncate(@as(i64, @intFromFloat(milliseconds / @as(f64, std.time.ms_per_s)))));
}
if (!value.isNumber() and !value.isString()) {
@@ -977,12 +977,12 @@ pub fn timeLikeFromJS(globalThis: *JSC.JSGlobalObject, value: JSC.JSValue, _: JS
return null;
}
- return @truncate(TimeLike, @intFromFloat(i64, seconds));
+ return @as(TimeLike, @truncate(@as(i64, @intFromFloat(seconds))));
}
pub fn modeFromJS(ctx: JSC.C.JSContextRef, value: JSC.JSValue, exception: JSC.C.ExceptionRef) ?Mode {
const mode_int = if (value.isNumber())
- @truncate(Mode, value.to(Mode))
+ @as(Mode, @truncate(value.to(Mode)))
else brk: {
if (value.isUndefinedOrNull()) return null;
@@ -1062,7 +1062,7 @@ pub const PathOrFileDescriptor = union(Tag) {
pub fn toJS(this: JSC.Node.PathOrFileDescriptor, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef {
return switch (this) {
.path => this.path.toJS(ctx, exception),
- .fd => JSC.JSValue.jsNumberFromInt32(@intCast(i32, this.fd)).asRef(),
+ .fd => JSC.JSValue.jsNumberFromInt32(@as(i32, @intCast(this.fd))).asRef(),
};
}
};
@@ -1167,7 +1167,7 @@ pub const FileSystemFlags = enum(Mode) {
pub fn fromJS(ctx: JSC.C.JSContextRef, val: JSC.JSValue, exception: JSC.C.ExceptionRef) ?FileSystemFlags {
if (val.isNumber()) {
const number = val.coerce(i32, ctx);
- return @enumFromInt(FileSystemFlags, @intCast(Mode, @max(number, 0)));
+ return @as(FileSystemFlags, @enumFromInt(@as(Mode, @intCast(@max(number, 0)))));
}
const jsType = val.jsType();
@@ -1198,7 +1198,7 @@ pub const FileSystemFlags = enum(Mode) {
inline else => |is_16bit| {
const chars = if (is_16bit) str.utf16SliceAligned() else str.slice();
- if (std.ascii.isDigit(@truncate(u8, chars[0]))) {
+ if (std.ascii.isDigit(@as(u8, @truncate(chars[0])))) {
// node allows "0o644" as a string :(
if (is_16bit) {
const slice = str.toSlice(bun.default_allocator);
@@ -1223,7 +1223,7 @@ pub const FileSystemFlags = enum(Mode) {
return null;
};
- return @enumFromInt(FileSystemFlags, @intCast(Mode, flags));
+ return @as(FileSystemFlags, @enumFromInt(@as(Mode, @intCast(flags))));
}
return null;
@@ -1235,7 +1235,7 @@ 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, @floatFromInt(f64, @intFromEnum(this)) * 1000.0);
+ const seconds = @as(f64, @floatCast(@as(f64, @floatFromInt(@intFromEnum(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);
@@ -1272,34 +1272,34 @@ fn StatsDataType(comptime T: type) type {
const ctime = stat_.ctime();
return @This(){
- .dev = @truncate(T, @intCast(i64, stat_.dev)),
- .ino = @truncate(T, @intCast(i64, stat_.ino)),
- .mode = @truncate(T, @intCast(i64, stat_.mode)),
- .nlink = @truncate(T, @intCast(i64, stat_.nlink)),
- .uid = @truncate(T, @intCast(i64, stat_.uid)),
- .gid = @truncate(T, @intCast(i64, stat_.gid)),
- .rdev = @truncate(T, @intCast(i64, stat_.rdev)),
- .size = @truncate(T, @intCast(i64, stat_.size)),
- .blksize = @truncate(T, @intCast(i64, stat_.blksize)),
- .blocks = @truncate(T, @intCast(i64, stat_.blocks)),
- .atime_ms = (@floatFromInt(f64, @max(atime.tv_sec, 0)) * std.time.ms_per_s) + (@floatFromInt(f64, @intCast(usize, @max(atime.tv_nsec, 0))) / std.time.ns_per_ms),
- .mtime_ms = (@floatFromInt(f64, @max(mtime.tv_sec, 0)) * std.time.ms_per_s) + (@floatFromInt(f64, @intCast(usize, @max(mtime.tv_nsec, 0))) / std.time.ns_per_ms),
- .ctime_ms = (@floatFromInt(f64, @max(ctime.tv_sec, 0)) * std.time.ms_per_s) + (@floatFromInt(f64, @intCast(usize, @max(ctime.tv_nsec, 0))) / std.time.ns_per_ms),
- .atime = @enumFromInt(Date, @intCast(u64, @max(atime.tv_sec, 0))),
- .mtime = @enumFromInt(Date, @intCast(u64, @max(mtime.tv_sec, 0))),
- .ctime = @enumFromInt(Date, @intCast(u64, @max(ctime.tv_sec, 0))),
+ .dev = @as(T, @truncate(@as(i64, @intCast(stat_.dev)))),
+ .ino = @as(T, @truncate(@as(i64, @intCast(stat_.ino)))),
+ .mode = @as(T, @truncate(@as(i64, @intCast(stat_.mode)))),
+ .nlink = @as(T, @truncate(@as(i64, @intCast(stat_.nlink)))),
+ .uid = @as(T, @truncate(@as(i64, @intCast(stat_.uid)))),
+ .gid = @as(T, @truncate(@as(i64, @intCast(stat_.gid)))),
+ .rdev = @as(T, @truncate(@as(i64, @intCast(stat_.rdev)))),
+ .size = @as(T, @truncate(@as(i64, @intCast(stat_.size)))),
+ .blksize = @as(T, @truncate(@as(i64, @intCast(stat_.blksize)))),
+ .blocks = @as(T, @truncate(@as(i64, @intCast(stat_.blocks)))),
+ .atime_ms = (@as(f64, @floatFromInt(@max(atime.tv_sec, 0))) * std.time.ms_per_s) + (@as(f64, @floatFromInt(@as(usize, @intCast(@max(atime.tv_nsec, 0))))) / std.time.ns_per_ms),
+ .mtime_ms = (@as(f64, @floatFromInt(@max(mtime.tv_sec, 0))) * std.time.ms_per_s) + (@as(f64, @floatFromInt(@as(usize, @intCast(@max(mtime.tv_nsec, 0))))) / std.time.ns_per_ms),
+ .ctime_ms = (@as(f64, @floatFromInt(@max(ctime.tv_sec, 0))) * std.time.ms_per_s) + (@as(f64, @floatFromInt(@as(usize, @intCast(@max(ctime.tv_nsec, 0))))) / std.time.ns_per_ms),
+ .atime = @as(Date, @enumFromInt(@as(u64, @intCast(@max(atime.tv_sec, 0))))),
+ .mtime = @as(Date, @enumFromInt(@as(u64, @intCast(@max(mtime.tv_sec, 0))))),
+ .ctime = @as(Date, @enumFromInt(@as(u64, @intCast(@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.
.birthtime_ms = if (Environment.isLinux)
0
else
- @truncate(T, @intCast(i64, if (stat_.birthtime().tv_nsec > 0) (@intCast(usize, stat_.birthtime().tv_nsec) / std.time.ns_per_ms) else 0)),
+ @as(T, @truncate(@as(i64, @intCast(if (stat_.birthtime().tv_nsec > 0) (@as(usize, @intCast(stat_.birthtime().tv_nsec)) / std.time.ns_per_ms) else 0)))),
.birthtime = if (Environment.isLinux)
- @enumFromInt(Date, 0)
+ @as(Date, @enumFromInt(0))
else
- @enumFromInt(Date, @intCast(u64, @max(stat_.birthtime().tv_sec, 0))),
+ @as(Date, @enumFromInt(@as(u64, @intCast(@max(stat_.birthtime().tv_sec, 0))))),
};
}
};
@@ -1375,33 +1375,33 @@ pub const Stats = union(enum) {
fn modeInternal(this: *This) i32 {
return switch (this.*) {
- .big => @truncate(i32, this.big.mode),
+ .big => @as(i32, @truncate(this.big.mode)),
.small => this.small.mode,
};
}
pub fn isBlockDevice(this: *This) JSC.JSValue {
- return JSC.JSValue.jsBoolean(os.S.ISBLK(@intCast(Mode, this.modeInternal())));
+ return JSC.JSValue.jsBoolean(os.S.ISBLK(@as(Mode, @intCast(this.modeInternal()))));
}
pub fn isCharacterDevice(this: *This) JSC.JSValue {
- return JSC.JSValue.jsBoolean(os.S.ISCHR(@intCast(Mode, this.modeInternal())));
+ return JSC.JSValue.jsBoolean(os.S.ISCHR(@as(Mode, @intCast(this.modeInternal()))));
}
pub fn isDirectory(this: *This) JSC.JSValue {
- return JSC.JSValue.jsBoolean(os.S.ISDIR(@intCast(Mode, this.modeInternal())));
+ return JSC.JSValue.jsBoolean(os.S.ISDIR(@as(Mode, @intCast(this.modeInternal()))));
}
pub fn isFIFO(this: *This) JSC.JSValue {
- return JSC.JSValue.jsBoolean(os.S.ISFIFO(@intCast(Mode, this.modeInternal())));
+ return JSC.JSValue.jsBoolean(os.S.ISFIFO(@as(Mode, @intCast(this.modeInternal()))));
}
pub fn isFile(this: *This) JSC.JSValue {
- return JSC.JSValue.jsBoolean(os.S.ISREG(@intCast(Mode, this.modeInternal())));
+ return JSC.JSValue.jsBoolean(os.S.ISREG(@as(Mode, @intCast(this.modeInternal()))));
}
pub fn isSocket(this: *This) JSC.JSValue {
- return JSC.JSValue.jsBoolean(os.S.ISSOCK(@intCast(Mode, this.modeInternal())));
+ return JSC.JSValue.jsBoolean(os.S.ISSOCK(@as(Mode, @intCast(this.modeInternal()))));
}
// Node.js says this method is only valid on the result of lstat()
@@ -1410,7 +1410,7 @@ pub const Stats = union(enum) {
//
// See https://nodejs.org/api/fs.html#statsissymboliclink
pub fn isSymbolicLink(this: *This) JSC.JSValue {
- return JSC.JSValue.jsBoolean(os.S.ISLNK(@intCast(Mode, this.modeInternal())));
+ return JSC.JSValue.jsBoolean(os.S.ISLNK(@as(Mode, @intCast(this.modeInternal()))));
}
pub fn finalize(this: *This) callconv(.C) void {
@@ -2204,7 +2204,7 @@ pub const Process = struct {
// 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.get().bundler.fs.top_level_dir = std.os.getcwd(&JSC.VirtualMachine.get().bundler.fs.top_level_dir_buf) catch {
- _ = Syscall.chdir(@ptrCast([:0]const u8, JSC.VirtualMachine.get().bundler.fs.top_level_dir));
+ _ = Syscall.chdir(@as([:0]const u8, @ptrCast(JSC.VirtualMachine.get().bundler.fs.top_level_dir)));
return JSC.toInvalidArguments("Invalid path", .{}, globalObject.ref());
};
@@ -2220,13 +2220,13 @@ pub const Process = struct {
pub fn exit(globalObject: *JSC.JSGlobalObject, code: i32) callconv(.C) void {
var vm = globalObject.bunVM();
if (vm.worker) |worker| {
- vm.exit_handler.exit_code = @truncate(u8, @max(code, 0));
+ vm.exit_handler.exit_code = @as(u8, @truncate(@max(code, 0)));
worker.terminate();
return;
}
vm.onExit();
- std.os.exit(@truncate(u8, @intCast(u32, @max(code, 0))));
+ std.os.exit(@as(u8, @truncate(@as(u32, @intCast(@max(code, 0))))));
}
pub export const Bun__version: [*:0]const u8 = "v" ++ bun.Global.package_json_version;
diff --git a/src/bun.js/test/diff_format.zig b/src/bun.js/test/diff_format.zig
index 4558a5f39..46afa8d0b 100644
--- a/src/bun.js/test/diff_format.zig
+++ b/src/bun.js/test/diff_format.zig
@@ -104,7 +104,7 @@ pub const DiffFormatter = struct {
ZigConsoleClient.format(
.Debug,
this.globalObject,
- @ptrCast([*]const JSValue, &received),
+ @as([*]const JSValue, @ptrCast(&received)),
1,
Writer,
Writer,
@@ -118,7 +118,7 @@ pub const DiffFormatter = struct {
ZigConsoleClient.format(
.Debug,
this.globalObject,
- @ptrCast([*]const JSValue, &this.expected),
+ @as([*]const JSValue, @ptrCast(&this.expected)),
1,
Writer,
Writer,
diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig
index 12f7011fb..e7209e683 100644
--- a/src/bun.js/test/expect.zig
+++ b/src/bun.js/test/expect.zig
@@ -117,7 +117,7 @@ pub const Expect = struct {
const now = std.time.Instant.now() catch unreachable;
const pending_test = Jest.runner.?.pending_test.?;
const elapsed = @divFloor(now.since(pending_test.started_at), std.time.ns_per_ms);
- const remaining = @truncate(u32, Jest.runner.?.last_test_timeout_timer_duration -| elapsed);
+ const remaining = @as(u32, @truncate(Jest.runner.?.last_test_timeout_timer_duration -| elapsed));
if (!globalThis.bunVM().waitForPromiseWithTimeout(promise, remaining)) {
pending_test.timeout();
@@ -2139,7 +2139,7 @@ pub const Expect = struct {
active_test_expectation_counter.actual += 1;
const not = this.flags.not;
- var pass = value.jsType().isArray() and @intCast(i32, value.getLength(globalThis)) == size.toInt32();
+ var pass = value.jsType().isArray() and @as(i32, @intCast(value.getLength(globalThis))) == size.toInt32();
if (not) pass = !pass;
if (pass) return thisValue;
@@ -3003,7 +3003,7 @@ pub const Expect = struct {
const times = arguments[0].coerce(i32, globalObject);
- var pass = @intCast(i32, calls.getLength(globalObject)) == times;
+ var pass = @as(i32, @intCast(calls.getLength(globalObject))) == times;
const not = this.flags.not;
if (not) pass = !pass;
diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig
index 4c97b5c77..429b79bcc 100644
--- a/src/bun.js/test/jest.zig
+++ b/src/bun.js/test/jest.zig
@@ -127,7 +127,7 @@ pub const TestRunner = struct {
if (this.last_test_timeout_timer_duration != milliseconds) {
this.last_test_timeout_timer_duration = milliseconds;
- this.test_timeout_timer.?.set(this, onTestTimeout, @intCast(i32, milliseconds), @intCast(i32, milliseconds));
+ this.test_timeout_timer.?.set(this, onTestTimeout, @as(i32, @intCast(milliseconds)), @as(i32, @intCast(milliseconds)));
}
}
}
@@ -209,7 +209,7 @@ pub const TestRunner = struct {
pub fn addTestCount(this: *TestRunner, count: u32) u32 {
this.tests.ensureUnusedCapacity(this.allocator, count) catch unreachable;
- const start = @truncate(Test.ID, this.tests.len);
+ const start = @as(Test.ID, @truncate(this.tests.len));
this.tests.len += count;
var statuses = this.tests.items(.status)[start..][0..count];
@memset(statuses, Test.Status.pending);
@@ -218,15 +218,15 @@ pub const TestRunner = struct {
}
pub fn getOrPutFile(this: *TestRunner, file_path: string) *DescribeScope {
- var entry = this.index.getOrPut(this.allocator, @truncate(u32, bun.hash(file_path))) catch unreachable;
+ var entry = this.index.getOrPut(this.allocator, @as(u32, @truncate(bun.hash(file_path)))) catch unreachable;
if (entry.found_existing) {
return this.files.items(.module_scope)[entry.value_ptr.*];
}
var scope = this.allocator.create(DescribeScope) catch unreachable;
- const file_id = @truncate(File.ID, this.files.len);
+ const file_id = @as(File.ID, @truncate(this.files.len));
scope.* = DescribeScope{
.file_id = file_id,
- .test_id_start = @truncate(Test.ID, this.tests.len),
+ .test_id_start = @as(Test.ID, @truncate(this.tests.len)),
};
this.files.append(this.allocator, .{ .module_scope = scope, .source = logger.Source.initEmptyFile(file_path) }) catch unreachable;
entry.value_ptr.* = file_id;
@@ -502,7 +502,7 @@ pub const Jest = struct {
JSError(getAllocator(ctx), "Run \"bun test\" to run a test", .{}, ctx, exception);
return js.JSValueMakeUndefined(ctx);
};
- const arguments = @ptrCast([]const JSC.JSValue, arguments_);
+ const arguments = @as([]const JSC.JSValue, @ptrCast(arguments_));
if (arguments.len < 1 or !arguments[0].isString()) {
JSError(getAllocator(ctx), "Bun.jest() expects a string filename", .{}, ctx, exception);
@@ -1077,7 +1077,7 @@ pub const DescribeScope = struct {
const file = this.file_id;
const allocator = getAllocator(globalObject);
var tests: []TestScope = this.tests.items;
- const end = @truncate(TestRunner.Test.ID, tests.len);
+ const end = @as(TestRunner.Test.ID, @truncate(tests.len));
this.pending_tests = std.DynamicBitSetUnmanaged.initFull(allocator, end) catch unreachable;
if (end == 0) {
@@ -1384,7 +1384,7 @@ pub const TestRunnerTask = struct {
fn deinit(this: *TestRunnerTask) void {
var vm = JSC.VirtualMachine.get();
if (vm.onUnhandledRejectionCtx) |ctx| {
- if (ctx == @ptrCast(*anyopaque, this)) {
+ if (ctx == @as(*anyopaque, @ptrCast(this))) {
vm.onUnhandledRejectionCtx = null;
}
}
@@ -1457,14 +1457,14 @@ inline fn createScope(
var timeout_ms: u32 = Jest.runner.?.default_timeout_ms;
if (options.isNumber()) {
- timeout_ms = @intCast(u32, @max(args[2].coerce(i32, globalThis), 0));
+ timeout_ms = @as(u32, @intCast(@max(args[2].coerce(i32, globalThis), 0)));
} else if (options.isObject()) {
if (options.get(globalThis, "timeout")) |timeout| {
if (!timeout.isNumber()) {
globalThis.throwPretty("{s} expects timeout to be a number", .{signature});
return .zero;
}
- timeout_ms = @intCast(u32, @max(timeout.coerce(i32, globalThis), 0));
+ timeout_ms = @as(u32, @intCast(@max(timeout.coerce(i32, globalThis), 0)));
}
if (options.get(globalThis, "retry")) |retries| {
if (!retries.isNumber()) {
@@ -1642,7 +1642,7 @@ pub fn printGithubAnnotation(exception: *JSC.ZigException) void {
var i: i16 = 0;
while (i < frames.len) : (i += 1) {
- const frame = frames[@intCast(usize, i)];
+ const frame = frames[@as(usize, @intCast(i))];
const source_url = frame.source_url.toUTF8(allocator);
defer source_url.deinit();
const file = bun.path.relative(dir, source_url.slice());
diff --git a/src/bun.js/test/pretty_format.zig b/src/bun.js/test/pretty_format.zig
index e907dd711..7d334d8e7 100644
--- a/src/bun.js/test/pretty_format.zig
+++ b/src/bun.js/test/pretty_format.zig
@@ -549,7 +549,7 @@ pub const JestPrettyFormat = struct {
var writer = WrappedWriter(Writer){ .ctx = writer_ };
var slice = slice_;
var i: u32 = 0;
- var len: u32 = @truncate(u32, slice.len);
+ var len: u32 = @as(u32, @truncate(slice.len));
var any_non_ascii = false;
while (i < len) : (i += 1) {
switch (slice[i]) {
@@ -576,7 +576,7 @@ pub const JestPrettyFormat = struct {
any_non_ascii = false;
slice = slice[@min(slice.len, i + 1)..];
i = 0;
- len = @truncate(u32, slice.len);
+ len = @as(u32, @truncate(slice.len));
const next_value = this.remaining_values[0];
this.remaining_values = this.remaining_values[1..];
switch (token) {
@@ -1047,7 +1047,7 @@ pub const JestPrettyFormat = struct {
i = -i;
}
const digits = if (i != 0)
- bun.fmt.fastDigitCount(@intCast(usize, i)) + @as(usize, @intFromBool(is_negative))
+ bun.fmt.fastDigitCount(@as(usize, @intCast(i))) + @as(usize, @intFromBool(is_negative))
else
1;
this.addForNewLine(digits);
@@ -1139,7 +1139,7 @@ pub const JestPrettyFormat = struct {
}
},
.Array => {
- const len = @truncate(u32, value.getLength(this.globalThis));
+ const len = @as(u32, @truncate(value.getLength(this.globalThis)));
if (len == 0) {
writer.writeAll("[]");
this.addForNewLine(2);
@@ -1250,9 +1250,9 @@ pub const JestPrettyFormat = struct {
enable_ansi_colors,
);
} else if (value.as(JSC.API.Bun.Timer.TimerObject)) |timer| {
- this.addForNewLine("Timeout(# ) ".len + bun.fmt.fastDigitCount(@intCast(u64, @max(timer.id, 0))));
+ this.addForNewLine("Timeout(# ) ".len + bun.fmt.fastDigitCount(@as(u64, @intCast(@max(timer.id, 0)))));
if (timer.kind == .setInterval) {
- this.addForNewLine("repeats ".len + bun.fmt.fastDigitCount(@intCast(u64, @max(timer.id, 0))));
+ this.addForNewLine("repeats ".len + bun.fmt.fastDigitCount(@as(u64, @intCast(@max(timer.id, 0)))));
writer.print(comptime Output.prettyFmt("<r><blue>Timeout<r> <d>(#<yellow>{d}<r><d>, repeats)<r>", enable_ansi_colors), .{
timer.id,
});
@@ -1670,7 +1670,7 @@ pub const JestPrettyFormat = struct {
var j: usize = 0;
while (j < length) : (j += 1) {
- const child = JSC.JSObject.getIndex(children, this.globalThis, @intCast(u32, j));
+ const child = JSC.JSObject.getIndex(children, this.globalThis, @as(u32, @intCast(j)));
this.format(Tag.get(child, this.globalThis), Writer, writer_, child, this.globalThis, enable_ansi_colors);
if (j + 1 < length) {
writer.writeAll("\n");
@@ -1827,7 +1827,7 @@ pub const JestPrettyFormat = struct {
if (slice.len > 0) {
switch (jsType) {
.Int8Array => {
- const slice_with_type = @alignCast(std.meta.alignment([]i8), std.mem.bytesAsSlice(i8, slice));
+ const slice_with_type: []align(std.meta.alignment([]i8)) i8 = @alignCast(std.mem.bytesAsSlice(i8, slice));
this.indent += 1;
defer this.indent -|= 1;
for (slice_with_type) |el| {
@@ -1837,7 +1837,7 @@ pub const JestPrettyFormat = struct {
}
},
.Int16Array => {
- const slice_with_type = @alignCast(std.meta.alignment([]i16), std.mem.bytesAsSlice(i16, slice));
+ const slice_with_type: []align(std.meta.alignment([]i16)) i16 = @alignCast(std.mem.bytesAsSlice(i16, slice));
this.indent += 1;
defer this.indent -|= 1;
for (slice_with_type) |el| {
@@ -1847,7 +1847,7 @@ pub const JestPrettyFormat = struct {
}
},
.Uint16Array => {
- const slice_with_type = @alignCast(std.meta.alignment([]u16), std.mem.bytesAsSlice(u16, slice));
+ const slice_with_type: []align(std.meta.alignment([]u16)) u16 = @alignCast(std.mem.bytesAsSlice(u16, slice));
this.indent += 1;
defer this.indent -|= 1;
for (slice_with_type) |el| {
@@ -1857,7 +1857,7 @@ pub const JestPrettyFormat = struct {
}
},
.Int32Array => {
- const slice_with_type = @alignCast(std.meta.alignment([]i32), std.mem.bytesAsSlice(i32, slice));
+ const slice_with_type: []align(std.meta.alignment([]i32)) i32 = @alignCast(std.mem.bytesAsSlice(i32, slice));
this.indent += 1;
defer this.indent -|= 1;
for (slice_with_type) |el| {
@@ -1867,7 +1867,7 @@ pub const JestPrettyFormat = struct {
}
},
.Uint32Array => {
- const slice_with_type = @alignCast(std.meta.alignment([]u32), std.mem.bytesAsSlice(u32, slice));
+ const slice_with_type: []align(std.meta.alignment([]u32)) u32 = @alignCast(std.mem.bytesAsSlice(u32, slice));
this.indent += 1;
defer this.indent -|= 1;
for (slice_with_type) |el| {
@@ -1877,7 +1877,7 @@ pub const JestPrettyFormat = struct {
}
},
.Float32Array => {
- const slice_with_type = @alignCast(std.meta.alignment([]f32), std.mem.bytesAsSlice(f32, slice));
+ const slice_with_type: []align(std.meta.alignment([]f32)) f32 = @alignCast(std.mem.bytesAsSlice(f32, slice));
this.indent += 1;
defer this.indent -|= 1;
for (slice_with_type) |el| {
@@ -1887,7 +1887,7 @@ pub const JestPrettyFormat = struct {
}
},
.Float64Array => {
- const slice_with_type = @alignCast(std.meta.alignment([]f64), std.mem.bytesAsSlice(f64, slice));
+ const slice_with_type: []align(std.meta.alignment([]f64)) f64 = @alignCast(std.mem.bytesAsSlice(f64, slice));
this.indent += 1;
defer this.indent -|= 1;
for (slice_with_type) |el| {
@@ -1897,7 +1897,7 @@ pub const JestPrettyFormat = struct {
}
},
.BigInt64Array => {
- const slice_with_type = @alignCast(std.meta.alignment([]i64), std.mem.bytesAsSlice(i64, slice));
+ const slice_with_type: []align(std.meta.alignment([]i64)) i64 = @alignCast(std.mem.bytesAsSlice(i64, slice));
this.indent += 1;
defer this.indent -|= 1;
for (slice_with_type) |el| {
@@ -1907,7 +1907,7 @@ pub const JestPrettyFormat = struct {
}
},
.BigUint64Array => {
- const slice_with_type = @alignCast(std.meta.alignment([]u64), std.mem.bytesAsSlice(u64, slice));
+ const slice_with_type: []align(std.meta.alignment([]u64)) u64 = @alignCast(std.mem.bytesAsSlice(u64, slice));
this.indent += 1;
defer this.indent -|= 1;
for (slice_with_type) |el| {
@@ -1919,7 +1919,7 @@ pub const JestPrettyFormat = struct {
// Uint8Array, Uint8ClampedArray, DataView, ArrayBuffer
else => {
- var slice_with_type = @alignCast(std.meta.alignment([]u8), std.mem.bytesAsSlice(u8, slice));
+ var slice_with_type: []align(std.meta.alignment([]u8)) u8 = @alignCast(std.mem.bytesAsSlice(u8, slice));
this.indent += 1;
defer this.indent -|= 1;
for (slice_with_type) |el| {
diff --git a/src/bun.js/webcore.zig b/src/bun.js/webcore.zig
index 8cb9ec80a..5fdc64c82 100644
--- a/src/bun.js/webcore.zig
+++ b/src/bun.js/webcore.zig
@@ -419,7 +419,7 @@ pub const Crypto = struct {
var cost: ?usize = null;
var parallelization: ?usize = null;
var maxmem: usize = 32 * 1024 * 1024;
- const keylen = @intCast(u32, @truncate(i33, keylen_int));
+ const keylen = @as(u32, @intCast(@as(i33, @truncate(keylen_int))));
if (options) |options_value| outer: {
if (options_value.isUndefined() or options_value == .zero)
@@ -441,7 +441,7 @@ pub const Crypto = struct {
.{},
);
} else if (N_int != 0) {
- cost = @intCast(usize, N_int);
+ cost = @as(usize, @intCast(N_int));
}
}
@@ -456,7 +456,7 @@ pub const Crypto = struct {
.{},
);
} else if (r_int != 0) {
- blockSize = @intCast(usize, r_int);
+ blockSize = @as(usize, @intCast(r_int));
}
}
@@ -471,7 +471,7 @@ pub const Crypto = struct {
.{},
);
} else if (p_int != 0) {
- parallelization = @intCast(usize, p_int);
+ parallelization = @as(usize, @intCast(p_int));
}
}
@@ -485,7 +485,7 @@ pub const Crypto = struct {
.{},
);
} else if (p_int != 0) {
- maxmem = @intCast(usize, p_int);
+ maxmem = @as(usize, @intCast(p_int));
}
}
}
@@ -664,7 +664,7 @@ pub const Crypto = struct {
) callconv(.C) JSC.JSValue {
var slice = array.slice();
randomData(globalThis, slice.ptr, slice.len);
- return @enumFromInt(JSC.JSValue, @bitCast(i64, @intFromPtr(array)));
+ return @as(JSC.JSValue, @enumFromInt(@as(i64, @bitCast(@intFromPtr(array)))));
}
fn randomData(
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig
index 7e0b7f24b..f2332a764 100644
--- a/src/bun.js/webcore/blob.zig
+++ b/src/bun.js/webcore/blob.zig
@@ -217,7 +217,7 @@ pub const Blob = struct {
pub const WriteError = error{};
pub fn write(this: StructuredCloneWriter, bytes: []const u8) WriteError!usize {
- this.impl(this.ctx, bytes.ptr, @truncate(u32, bytes.len));
+ this.impl(this.ctx, bytes.ptr, @as(u32, @truncate(bytes.len)));
return bytes.len;
}
};
@@ -229,9 +229,9 @@ pub const Blob = struct {
) !void {
try writer.writeIntNative(u8, serialization_version);
- try writer.writeIntNative(u64, @intCast(u64, this.offset));
+ try writer.writeIntNative(u64, @as(u64, @intCast(this.offset)));
- try writer.writeIntNative(u32, @truncate(u32, this.content_type.len));
+ try writer.writeIntNative(u32, @as(u32, @truncate(this.content_type.len)));
_ = try writer.write(this.content_type);
try writer.writeIntNative(u8, @intFromBool(this.content_type_was_set));
@@ -329,7 +329,7 @@ pub const Blob = struct {
switch (pathlike_tag) {
.fd => {
- const fd = @intCast(i32, try reader.readIntNative(u32));
+ const fd = @as(i32, @intCast(try reader.readIntNative(u32)));
var blob = try allocator.create(Blob);
blob.* = Blob.findOrCreateFileFromPath(
@@ -369,7 +369,7 @@ pub const Blob = struct {
},
};
blob.allocator = allocator;
- blob.offset = @intCast(u52, offset);
+ blob.offset = @as(u52, @intCast(offset));
if (content_type.len > 0) {
blob.content_type = content_type;
blob.content_type_allocated = true;
@@ -736,9 +736,9 @@ pub const Blob = struct {
return JSPromise.resolvedPromiseValue(ctx.ptr(), cloned.toJS(ctx)).asObjectRef();
} else if (destination_type == .bytes and source_type == .file) {
var fake_call_frame: [8]JSC.JSValue = undefined;
- @memset(@ptrCast([*]u8, &fake_call_frame)[0..@sizeOf(@TypeOf(fake_call_frame))], 0);
+ @memset(@as([*]u8, @ptrCast(&fake_call_frame))[0..@sizeOf(@TypeOf(fake_call_frame))], 0);
const blob_value =
- source_blob.getSlice(ctx, @ptrCast(*JSC.CallFrame, &fake_call_frame));
+ source_blob.getSlice(ctx, @as(*JSC.CallFrame, @ptrCast(&fake_call_frame)));
return JSPromise.resolvedPromiseValue(
ctx.ptr(),
@@ -1010,7 +1010,7 @@ pub const Blob = struct {
// we only truncate if it's a path
// if it's a file descriptor, we assume they want manual control over that behavior
if (truncate) {
- _ = JSC.Node.Syscall.system.ftruncate(fd, @intCast(i64, written));
+ _ = JSC.Node.Syscall.system.ftruncate(fd, @as(i64, @intCast(written)));
}
if (needs_open) {
@@ -1076,7 +1076,7 @@ pub const Blob = struct {
var written: usize = 0;
defer {
if (truncate) {
- _ = JSC.Node.Syscall.system.ftruncate(fd, @intCast(i64, written));
+ _ = JSC.Node.Syscall.system.ftruncate(fd, @as(i64, @intCast(written)));
}
if (needs_open) {
@@ -1298,18 +1298,18 @@ pub const Blob = struct {
switch (file.pathlike) {
.fd => |fd| {
- try writer.writeIntNative(u32, @intCast(u32, fd));
+ try writer.writeIntNative(u32, @as(u32, @intCast(fd)));
},
.path => |path| {
const path_slice = path.slice();
- try writer.writeIntNative(u32, @truncate(u32, path_slice.len));
+ try writer.writeIntNative(u32, @as(u32, @truncate(path_slice.len)));
_ = try writer.write(path_slice);
},
}
},
.bytes => |bytes| {
const slice = bytes.slice();
- try writer.writeIntNative(u32, @truncate(u32, slice.len));
+ try writer.writeIntNative(u32, @as(u32, @truncate(slice.len)));
_ = try writer.write(slice);
},
}
@@ -1409,7 +1409,7 @@ pub const Blob = struct {
this.file_blob.store.?.data.file.pathlike.path;
this.system_error = (JSC.Node.Syscall.Error{
- .errno = @intCast(JSC.Node.Syscall.Error.Int, -completion.result),
+ .errno = @as(JSC.Node.Syscall.Error.Int, @intCast(-completion.result)),
.path = path_string.slice(),
.syscall = .open,
}).toSystemError();
@@ -1544,7 +1544,7 @@ pub const Blob = struct {
}
};
- return try ReadFile.createWithCtx(allocator, store, @ptrCast(*anyopaque, context), Handler.run, off, max_len);
+ return try ReadFile.createWithCtx(allocator, store, @as(*anyopaque, @ptrCast(context)), Handler.run, off, max_len);
}
pub fn doRead(this: *ReadFile) void {
@@ -1605,11 +1605,11 @@ pub const Blob = struct {
pub fn onRead(this: *ReadFile, completion: *HTTPClient.NetworkThread.Completion, result: AsyncIO.ReadError!usize) void {
defer this.doReadLoop();
- this.read_len = @truncate(SizeType, result catch |err| {
+ this.read_len = @as(SizeType, @truncate(result catch |err| {
if (@hasField(HTTPClient.NetworkThread.Completion, "result")) {
this.errno = AsyncIO.asError(-completion.result);
this.system_error = (JSC.Node.Syscall.Error{
- .errno = @intCast(JSC.Node.Syscall.Error.Int, -completion.result),
+ .errno = @as(JSC.Node.Syscall.Error.Int, @intCast(-completion.result)),
.syscall = .read,
}).toSystemError();
} else {
@@ -1627,7 +1627,7 @@ pub const Blob = struct {
this.read_len = 0;
return;
- });
+ }));
}
fn runAsync(this: *ReadFile, task: *ReadFileTask) void {
@@ -1689,7 +1689,7 @@ pub const Blob = struct {
if (stat.size > 0 and std.os.S.ISREG(stat.mode)) {
this.size = @min(
- @truncate(SizeType, @intCast(SizeType, @max(@intCast(i64, stat.size), 0))),
+ @as(SizeType, @truncate(@as(SizeType, @intCast(@max(@as(i64, @intCast(stat.size)), 0))))),
this.max_length,
);
// read up to 4k at a time if
@@ -1730,7 +1730,7 @@ pub const Blob = struct {
fn doReadLoop(this: *ReadFile) void {
this.read_off += this.read_len;
- var remain = this.buffer[@min(this.read_off, @truncate(Blob.SizeType, this.buffer.len))..];
+ var remain = this.buffer[@min(this.read_off, @as(Blob.SizeType, @truncate(this.buffer.len)))..];
if (remain.len > 0 and this.errno == null) {
this.doRead();
@@ -1805,7 +1805,7 @@ pub const Blob = struct {
allocator,
file_blob,
bytes_blob,
- @ptrCast(*anyopaque, context),
+ @as(*anyopaque, @ptrCast(context)),
Handler.run,
);
}
@@ -1849,7 +1849,7 @@ pub const Blob = struct {
const wrote = this.wrote;
bun.default_allocator.destroy(this);
- cb(cb_ctx, .{ .result = @truncate(SizeType, wrote) });
+ cb(cb_ctx, .{ .result = @as(SizeType, @truncate(wrote)) });
}
pub fn run(this: *WriteFile, task: *WriteFileTask) void {
this.io_task = task;
@@ -1858,7 +1858,7 @@ pub const Blob = struct {
pub fn onWrite(this: *WriteFile, _: *HTTPClient.NetworkThread.Completion, result: AsyncIO.WriteError!usize) void {
defer this.doWriteLoop();
- this.wrote += @truncate(SizeType, result catch |errno| {
+ this.wrote += @as(SizeType, @truncate(result catch |errno| {
this.errno = errno;
this.system_error = this.system_error orelse JSC.SystemError{
.code = bun.String.static(bun.asByteSlice(@errorName(errno))),
@@ -1867,7 +1867,7 @@ pub const Blob = struct {
this.wrote = 0;
return;
- });
+ }));
}
fn runAsync(this: *WriteFile) void {
@@ -1920,12 +1920,12 @@ pub const Blob = struct {
};
const unsupported_directory_error = SystemError{
- .errno = @intCast(c_int, @intFromEnum(bun.C.SystemErrno.EISDIR)),
+ .errno = @as(c_int, @intCast(@intFromEnum(bun.C.SystemErrno.EISDIR))),
.message = bun.String.static("That doesn't work on folders"),
.syscall = bun.String.static("fstat"),
};
const unsupported_non_regular_file_error = SystemError{
- .errno = @intCast(c_int, @intFromEnum(bun.C.SystemErrno.ENOTSUP)),
+ .errno = @as(c_int, @intCast(@intFromEnum(bun.C.SystemErrno.ENOTSUP))),
.message = bun.String.static("Non-regular files aren't supported yet"),
.syscall = bun.String.static("fstat"),
};
@@ -2127,7 +2127,7 @@ pub const Blob = struct {
const dest_fd = this.destination_fd;
defer {
- this.read_len = @truncate(SizeType, total_written);
+ this.read_len = @as(SizeType, @truncate(total_written));
}
var has_unset_append = false;
@@ -2158,14 +2158,14 @@ pub const Blob = struct {
}
this.system_error = (JSC.Node.Syscall.Error{
- .errno = @intCast(JSC.Node.Syscall.Error.Int, @intFromEnum(linux.E.INVAL)),
+ .errno = @as(JSC.Node.Syscall.Error.Int, @intCast(@intFromEnum(linux.E.INVAL))),
.syscall = TryWith.tag.get(use).?,
}).toSystemError();
return AsyncIO.asError(linux.E.INVAL);
},
else => |errno| {
this.system_error = (JSC.Node.Syscall.Error{
- .errno = @intCast(JSC.Node.Syscall.Error.Int, @intFromEnum(errno)),
+ .errno = @as(JSC.Node.Syscall.Error.Int, @intCast(@intFromEnum(errno))),
.syscall = TryWith.tag.get(use).?,
}).toSystemError();
return AsyncIO.asError(errno);
@@ -2252,15 +2252,15 @@ pub const Blob = struct {
}
if (this.doClonefile()) {
- if (this.max_length != Blob.max_size and this.max_length < @intCast(SizeType, stat_.?.size)) {
+ if (this.max_length != Blob.max_size and this.max_length < @as(SizeType, @intCast(stat_.?.size))) {
// If this fails...well, there's not much we can do about it.
_ = bun.C.truncate(
this.destination_file_store.pathlike.path.sliceZAssume(),
- @intCast(std.os.off_t, this.max_length),
+ @as(std.os.off_t, @intCast(this.max_length)),
);
- this.read_len = @intCast(SizeType, this.max_length);
+ this.read_len = @as(SizeType, @intCast(this.max_length));
} else {
- this.read_len = @intCast(SizeType, stat_.?.size);
+ this.read_len = @as(SizeType, @intCast(stat_.?.size));
}
return;
} else |_| {
@@ -2313,7 +2313,7 @@ pub const Blob = struct {
}
if (stat.size != 0) {
- this.max_length = @max(@min(@intCast(SizeType, stat.size), this.max_length), this.offset) - this.offset;
+ this.max_length = @max(@min(@as(SizeType, @intCast(stat.size)), this.max_length), this.offset) - this.offset;
if (this.max_length == 0) {
this.doClose();
return;
@@ -2375,8 +2375,8 @@ pub const Blob = struct {
return;
};
- if (stat.size != 0 and @intCast(SizeType, stat.size) > this.max_length) {
- _ = darwin.ftruncate(this.destination_fd, @intCast(std.os.off_t, this.max_length));
+ if (stat.size != 0 and @as(SizeType, @intCast(stat.size)) > this.max_length) {
+ _ = darwin.ftruncate(this.destination_fd, @as(std.os.off_t, @intCast(this.max_length)));
}
this.doClose();
@@ -2426,8 +2426,8 @@ pub const Blob = struct {
pub fn init(bytes: []u8, allocator: std.mem.Allocator) ByteStore {
return .{
.ptr = bytes.ptr,
- .len = @truncate(SizeType, bytes.len),
- .cap = @truncate(SizeType, bytes.len),
+ .len = @as(SizeType, @truncate(bytes.len)),
+ .cap = @as(SizeType, @truncate(bytes.len)),
.allocator = allocator,
};
}
@@ -2470,7 +2470,7 @@ pub const Blob = struct {
return JSValue.jsUndefined();
}
- recommended_chunk_size = @intCast(SizeType, @max(0, @truncate(i52, arguments[0].toInt64())));
+ recommended_chunk_size = @as(SizeType, @intCast(@max(0, @as(i52, @truncate(arguments[0].toInt64())))));
}
return JSC.WebCore.ReadableStream.fromBlob(
globalThis,
@@ -2665,7 +2665,7 @@ pub const Blob = struct {
var relativeStart: i64 = 0;
// If the optional end parameter is not used as a parameter when making this call, let relativeEnd be size.
- var relativeEnd: i64 = @intCast(i64, this.size);
+ var relativeEnd: i64 = @as(i64, @intCast(this.size));
if (args.ptr[0].isString()) {
args.ptr[2] = args.ptr[0];
@@ -2684,10 +2684,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, @max(start +% @intCast(i64, this.size), 0));
+ relativeStart = @as(i64, @intCast(@max(start +% @as(i64, @intCast(this.size)), 0)));
} else {
// Otherwise, let relativeStart be start.
- relativeStart = @min(@intCast(i64, start), @intCast(i64, this.size));
+ relativeStart = @min(@as(i64, @intCast(start)), @as(i64, @intCast(this.size)));
}
}
}
@@ -2698,10 +2698,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, @max(end +% @intCast(i64, this.size), 0));
+ relativeEnd = @as(i64, @intCast(@max(end +% @as(i64, @intCast(this.size)), 0)));
} else {
// Otherwise, let relativeStart be start.
- relativeEnd = @min(@intCast(i64, end), @intCast(i64, this.size));
+ relativeEnd = @min(@as(i64, @intCast(end)), @as(i64, @intCast(this.size)));
}
}
}
@@ -2731,12 +2731,12 @@ pub const Blob = struct {
}
}
- const len = @intCast(SizeType, @max(relativeEnd -| relativeStart, 0));
+ const len = @as(SizeType, @intCast(@max(relativeEnd -| relativeStart, 0)));
// This copies over the is_all_ascii flag
// which is okay because this will only be a <= slice
var blob = this.dupe();
- blob.offset = @intCast(SizeType, relativeStart);
+ blob.offset = @as(SizeType, @intCast(relativeStart));
blob.size = len;
// infer the content type if it was not specified
@@ -2909,8 +2909,8 @@ pub const Blob = struct {
}
fn toJSTime(sec: isize, nsec: isize) JSTimeType {
- const millisec = @intCast(u64, @divTrunc(nsec, std.time.ns_per_ms));
- return @truncate(JSTimeType, @intCast(u64, sec * std.time.ms_per_s) + millisec);
+ const millisec = @as(u64, @intCast(@divTrunc(nsec, std.time.ns_per_ms)));
+ return @as(JSTimeType, @truncate(@as(u64, @intCast(sec * std.time.ms_per_s)) + millisec));
}
/// resolve file stat like size, last_modified
@@ -2920,7 +2920,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, @max(stat.size, 0)))
+ @as(SizeType, @truncate(@as(u64, @intCast(@max(stat.size, 0)))))
else
Blob.max_size;
store.data.file.mode = stat.mode;
@@ -2934,7 +2934,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, @max(stat.size, 0)))
+ @as(SizeType, @truncate(@as(u64, @intCast(@max(stat.size, 0)))))
else
Blob.max_size;
store.data.file.mode = stat.mode;
@@ -3027,7 +3027,7 @@ pub const Blob = struct {
store.?.is_all_ascii = is_all_ascii;
}
return Blob{
- .size = @truncate(SizeType, bytes.len),
+ .size = @as(SizeType, @truncate(bytes.len)),
.store = store,
.allocator = null,
.content_type = "",
@@ -3038,7 +3038,7 @@ pub const Blob = struct {
pub fn init(bytes: []u8, allocator: std.mem.Allocator, globalThis: *JSGlobalObject) Blob {
return Blob{
- .size = @truncate(SizeType, bytes.len),
+ .size = @as(SizeType, @truncate(bytes.len)),
.store = if (bytes.len > 0)
Blob.Store.init(bytes, allocator) catch unreachable
else
@@ -3057,7 +3057,7 @@ pub const Blob = struct {
) Blob {
var bytes = allocator.dupe(u8, bytes_) catch @panic("Out of memory");
return Blob{
- .size = @truncate(SizeType, bytes_.len),
+ .size = @as(SizeType, @truncate(bytes_.len)),
.store = if (bytes.len > 0)
Blob.Store.init(bytes, allocator) catch unreachable
else
@@ -3183,7 +3183,7 @@ pub const Blob = struct {
.result => |result| {
const bytes = result.buf;
if (blob.size > 0)
- blob.size = @min(@truncate(u32, bytes.len), blob.size);
+ blob.size = @min(@as(u32, @truncate(bytes.len)), blob.size);
const value = Function(&blob, globalThis, bytes, .temporary);
// invalid JSON needs to be rejected
@@ -3537,7 +3537,7 @@ pub const Blob = struct {
var sliced = top_value.toSlice(global, bun.default_allocator);
const is_all_ascii = !sliced.isAllocated();
if (!sliced.isAllocated() and sliced.len > 0) {
- sliced.ptr = @ptrCast([*]const u8, (try bun.default_allocator.dupe(u8, sliced.slice())).ptr);
+ sliced.ptr = @as([*]const u8, @ptrCast((try bun.default_allocator.dupe(u8, sliced.slice())).ptr));
sliced.allocator = NullableAllocator.init(bun.default_allocator);
}
@@ -3750,8 +3750,8 @@ pub const AnyBlob = union(enum) {
pub inline fn fastSize(this: *const AnyBlob) Blob.SizeType {
return switch (this.*) {
.Blob => this.Blob.size,
- .WTFStringImpl => @truncate(Blob.SizeType, this.WTFStringImpl.byteLength()),
- else => @truncate(Blob.SizeType, this.slice().len),
+ .WTFStringImpl => @as(Blob.SizeType, @truncate(this.WTFStringImpl.byteLength())),
+ else => @as(Blob.SizeType, @truncate(this.slice().len)),
};
}
@@ -3884,8 +3884,8 @@ pub const AnyBlob = union(enum) {
pub inline fn size(this: *const AnyBlob) Blob.SizeType {
return switch (this.*) {
.Blob => this.Blob.size,
- .WTFStringImpl => @truncate(Blob.SizeType, this.WTFStringImpl.utf8ByteLength()),
- else => @truncate(Blob.SizeType, this.slice().len),
+ .WTFStringImpl => @as(Blob.SizeType, @truncate(this.WTFStringImpl.utf8ByteLength())),
+ else => @as(Blob.SizeType, @truncate(this.slice().len)),
};
}
@@ -4054,7 +4054,7 @@ pub const InlineBlob = extern struct {
if (second.len > 0)
@memcpy(bytes_slice[first.len..][0..second.len], second);
- inline_blob.len = @truncate(@TypeOf(inline_blob.len), total);
+ inline_blob.len = @as(@TypeOf(inline_blob.len), @truncate(total));
return inline_blob;
}
@@ -4062,7 +4062,7 @@ pub const InlineBlob = extern struct {
std.debug.assert(data.len <= available_bytes);
var blob = InlineBlob{
- .len = @intCast(IntSize, data.len),
+ .len = @as(IntSize, @intCast(data.len)),
.was_string = was_string,
};
diff --git a/src/bun.js/webcore/body.zig b/src/bun.js/webcore/body.zig
index 028b104b2..169ac8fa4 100644
--- a/src/bun.js/webcore/body.zig
+++ b/src/bun.js/webcore/body.zig
@@ -176,7 +176,7 @@ pub const Body = struct {
if (response_init.fastGet(ctx, .status)) |status_value| {
const number = status_value.coerceToInt64(ctx);
if ((200 <= number and number < 600) or number == 101) {
- result.status_code = @truncate(u16, @intCast(u32, number));
+ result.status_code = @as(u16, @truncate(@as(u32, @intCast(number))));
} else {
const err = ctx.createRangeErrorInstance("The status provided ({d}) must be 101 or in the range of [200, 599]", .{number});
ctx.throwValue(err);
@@ -365,8 +365,8 @@ pub const Body = struct {
pub fn size(this: *const Value) Blob.SizeType {
return switch (this.*) {
.Blob => this.Blob.size,
- .InternalBlob => @truncate(Blob.SizeType, this.InternalBlob.sliceConst().len),
- .WTFStringImpl => @truncate(Blob.SizeType, this.WTFStringImpl.utf8ByteLength()),
+ .InternalBlob => @as(Blob.SizeType, @truncate(this.InternalBlob.sliceConst().len)),
+ .WTFStringImpl => @as(Blob.SizeType, @truncate(this.WTFStringImpl.utf8ByteLength())),
// .InlineBlob => @truncate(Blob.SizeType, this.InlineBlob.sliceConst().len),
else => 0,
};
@@ -375,8 +375,8 @@ pub const Body = struct {
pub fn fastSize(this: *const Value) Blob.SizeType {
return switch (this.*) {
.Blob => this.Blob.size,
- .InternalBlob => @truncate(Blob.SizeType, this.InternalBlob.sliceConst().len),
- .WTFStringImpl => @truncate(Blob.SizeType, this.WTFStringImpl.byteSlice().len),
+ .InternalBlob => @as(Blob.SizeType, @truncate(this.InternalBlob.sliceConst().len)),
+ .WTFStringImpl => @as(Blob.SizeType, @truncate(this.WTFStringImpl.byteSlice().len)),
// .InlineBlob => @truncate(Blob.SizeType, this.InlineBlob.sliceConst().len),
else => 0,
};
@@ -481,11 +481,11 @@ pub const Body = struct {
reader.context.setup();
if (drain_result == .estimated_size) {
- reader.context.highWaterMark = @truncate(Blob.SizeType, drain_result.estimated_size);
- reader.context.size_hint = @truncate(Blob.SizeType, drain_result.estimated_size);
+ reader.context.highWaterMark = @as(Blob.SizeType, @truncate(drain_result.estimated_size));
+ reader.context.size_hint = @as(Blob.SizeType, @truncate(drain_result.estimated_size));
} else if (drain_result == .owned) {
reader.context.buffer = drain_result.owned.list;
- reader.context.size_hint = @truncate(Blob.SizeType, drain_result.owned.size_hint);
+ reader.context.size_hint = @as(Blob.SizeType, @truncate(drain_result.owned.size_hint));
}
locked.readable = .{
diff --git a/src/bun.js/webcore/encoding.zig b/src/bun.js/webcore/encoding.zig
index dd47ccc29..42256a9ca 100644
--- a/src/bun.js/webcore/encoding.zig
+++ b/src/bun.js/webcore/encoding.zig
@@ -229,7 +229,7 @@ pub const TextEncoder = struct {
result.written = 3;
}
const sized: [2]u32 = .{ result.read, result.written };
- return @bitCast(u64, sized);
+ return @as(u64, @bitCast(sized));
}
pub export fn TextEncoder__encodeInto8(
@@ -243,7 +243,7 @@ pub const TextEncoder = struct {
const result: strings.EncodeIntoResult =
strings.copyLatin1IntoUTF8(output, []const u8, input);
const sized: [2]u32 = .{ result.read, result.written };
- return @bitCast(u64, sized);
+ return @as(u64, @bitCast(sized));
}
};
@@ -462,7 +462,7 @@ pub const TextDecoder = struct {
return ZigString.init(EncodingLabel.label.get(this.encoding).?).toValue(globalThis);
}
const Vector16 = std.meta.Vector(16, u16);
- const max_16_ascii: Vector16 = @splat(16, @as(u16, 127));
+ const max_16_ascii: Vector16 = @splat(@as(u16, 127));
fn decodeUTF16WithAlignment(
_: *TextDecoder,
@@ -477,12 +477,12 @@ pub const TextDecoder = struct {
const vec: strings.AsciiU16Vector = slice[i..][0..strings.ascii_u16_vector_size].*;
if ((@reduce(
.Or,
- @bitCast(
+ @as(
strings.AsciiVectorU16U1,
- vec > strings.max_u16_ascii,
- ) | @bitCast(
+ @bitCast(vec > strings.max_u16_ascii),
+ ) | @as(
strings.AsciiVectorU16U1,
- vec < strings.min_u16_ascii,
+ @bitCast(vec < strings.min_u16_ascii),
),
) == 0)) {
break;
@@ -502,7 +502,7 @@ pub const TextDecoder = struct {
return ZigString.init16(slice).toValueGC(ctx);
} else {
var str = ZigString.init("");
- str._unsafe_ptr_do_not_use = @ptrCast([*]const u8, slice.ptr);
+ str._unsafe_ptr_do_not_use = @as([*]const u8, @ptrCast(slice.ptr));
str.len = slice.len;
str.markUTF16();
return str.toValueGC(ctx.ptr());
@@ -575,7 +575,7 @@ pub const TextDecoder = struct {
var full = buffer.toOwnedSlice(allocator) catch @panic("TODO");
var out = ZigString.init("");
- out._unsafe_ptr_do_not_use = @ptrCast([*]u8, full.ptr);
+ out._unsafe_ptr_do_not_use = @as([*]u8, @ptrCast(full.ptr));
out.len = full.len;
out.markUTF16();
return out.toValueGC(ctx.ptr());
@@ -660,7 +660,7 @@ pub const TextDecoder = struct {
EncodingLabel.@"UTF-16LE" => {
if (std.mem.isAligned(@intFromPtr(buffer_slice.ptr), @alignOf([*]const u16))) {
- return this.decodeUTF16WithAlignment([]const u16, @alignCast(2, std.mem.bytesAsSlice(u16, buffer_slice)), globalThis);
+ return this.decodeUTF16WithAlignment([]align(2) const u16, @as([]align(2) const u16, @alignCast(std.mem.bytesAsSlice(u16, buffer_slice))), globalThis);
}
return this.decodeUTF16WithAlignment([]align(1) const u16, std.mem.bytesAsSlice(u16, buffer_slice), globalThis);
@@ -701,7 +701,7 @@ pub const TextDecoder = struct {
pub const Encoder = struct {
export fn Bun__encoding__writeLatin1(input: [*]const u8, len: usize, to: [*]u8, to_len: usize, encoding: u8) usize {
- return switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
+ return switch (@as(JSC.Node.Encoding, @enumFromInt(encoding))) {
.utf8 => writeU8(input, len, to, to_len, .utf8),
.latin1 => writeU8(input, len, to, to_len, .ascii),
.ascii => writeU8(input, len, to, to_len, .ascii),
@@ -714,7 +714,7 @@ pub const Encoder = struct {
} catch 0;
}
export fn Bun__encoding__writeUTF16(input: [*]const u16, len: usize, to: [*]u8, to_len: usize, encoding: u8) usize {
- return switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
+ return switch (@as(JSC.Node.Encoding, @enumFromInt(encoding))) {
.utf8 => writeU16(input, len, to, to_len, .utf8, false),
.latin1 => writeU16(input, len, to, to_len, .ascii, false),
.ascii => writeU16(input, len, to, to_len, .ascii, false),
@@ -727,7 +727,7 @@ pub const Encoder = struct {
} catch 0;
}
export fn Bun__encoding__byteLengthLatin1(input: [*]const u8, len: usize, encoding: u8) usize {
- return switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
+ return switch (@as(JSC.Node.Encoding, @enumFromInt(encoding))) {
.utf8 => byteLengthU8(input, len, .utf8),
.latin1 => byteLengthU8(input, len, .ascii),
.ascii => byteLengthU8(input, len, .ascii),
@@ -740,7 +740,7 @@ pub const Encoder = struct {
};
}
export fn Bun__encoding__byteLengthUTF16(input: [*]const u16, len: usize, encoding: u8) usize {
- return switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
+ return switch (@as(JSC.Node.Encoding, @enumFromInt(encoding))) {
.utf8 => byteLengthU16(input, len, .utf8),
.latin1 => byteLengthU16(input, len, .ascii),
.ascii => byteLengthU16(input, len, .ascii),
@@ -753,7 +753,7 @@ pub const Encoder = struct {
};
}
export fn Bun__encoding__constructFromLatin1(globalObject: *JSGlobalObject, input: [*]const u8, len: usize, encoding: u8) JSValue {
- var slice = switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
+ var slice = switch (@as(JSC.Node.Encoding, @enumFromInt(encoding))) {
.hex => constructFromU8(input, len, .hex),
.ascii => constructFromU8(input, len, .ascii),
.base64url => constructFromU8(input, len, .base64url),
@@ -766,7 +766,7 @@ pub const Encoder = struct {
return JSC.JSValue.createBuffer(globalObject, slice, globalObject.bunVM().allocator);
}
export fn Bun__encoding__constructFromUTF16(globalObject: *JSGlobalObject, input: [*]const u16, len: usize, encoding: u8) JSValue {
- var slice = switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
+ var slice = switch (@as(JSC.Node.Encoding, @enumFromInt(encoding))) {
.base64 => constructFromU16(input, len, .base64),
.hex => constructFromU16(input, len, .hex),
.base64url => constructFromU16(input, len, .base64url),
@@ -785,7 +785,7 @@ pub const Encoder = struct {
}
export fn Bun__encoding__toString(input: [*]const u8, len: usize, globalObject: *JSC.JSGlobalObject, encoding: u8) JSValue {
- return switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
+ return switch (@as(JSC.Node.Encoding, @enumFromInt(encoding))) {
.ucs2 => toString(input, len, globalObject, .utf16le),
.utf16le => toString(input, len, globalObject, .utf16le),
.utf8 => toString(input, len, globalObject, .utf8),
@@ -931,12 +931,12 @@ pub const Encoder = struct {
if (std.mem.isAligned(@intFromPtr(to_ptr), @alignOf([*]u16))) {
var buf = input[0..len];
- var output = @ptrCast([*]u16, @alignCast(@alignOf(u16), to_ptr))[0 .. to_len / 2];
+ var output = @as([*]u16, @ptrCast(@alignCast(to_ptr)))[0 .. to_len / 2];
var written = strings.copyLatin1IntoUTF16([]u16, output, []const u8, buf).written;
return written * 2;
} else {
var buf = input[0..len];
- var output = @ptrCast([*]align(1) u16, to_ptr)[0 .. to_len / 2];
+ var output = @as([*]align(1) u16, @ptrCast(to_ptr))[0 .. to_len / 2];
var written = strings.copyLatin1IntoUTF16([]align(1) u16, output, []const u8, buf).written;
return written * 2;
@@ -1007,7 +1007,7 @@ pub const Encoder = struct {
if (allow_partial_write) {
const bytes_input_len = len * 2;
const written = @min(bytes_input_len, to_len);
- const input_u8 = @ptrCast([*]const u8, input);
+ const input_u8 = @as([*]const u8, @ptrCast(input));
strings.copyU16IntoU8(to[0..written], []const u8, input_u8[0..written]);
return written;
} else {
@@ -1016,7 +1016,7 @@ pub const Encoder = struct {
if (written < 2) return 0;
const fixed_len = (written / 2) * 2;
- const input_u8 = @ptrCast([*]const u8, input);
+ const input_u8 = @as([*]const u8, @ptrCast(input));
strings.copyU16IntoU8(to[0..written], []const u8, input_u8[0..fixed_len]);
return fixed_len;
}
@@ -1140,7 +1140,7 @@ pub const Encoder = struct {
var input_bytes = std.mem.sliceAsBytes(input[0..len]);
@memcpy(to[0..input_bytes.len], input_bytes);
for (to[0..len], 0..) |c, i| {
- to[i] = @as(u8, @truncate(u7, c));
+ to[i] = @as(u8, @as(u7, @truncate(c)));
}
return to;
diff --git a/src/bun.js/webcore/request.zig b/src/bun.js/webcore/request.zig
index cff2ef2f3..75d4e63cd 100644
--- a/src/bun.js/webcore/request.zig
+++ b/src/bun.js/webcore/request.zig
@@ -120,7 +120,7 @@ pub const Request = struct {
pub fn estimatedSize(this: *Request) callconv(.C) usize {
return this.reported_estimated_size orelse brk: {
- this.reported_estimated_size = @truncate(u63, this.body.value.estimatedSize() + this.sizeOfURL() + @sizeOf(Request));
+ this.reported_estimated_size = @as(u63, @truncate(this.body.value.estimatedSize() + this.sizeOfURL() + @sizeOf(Request)));
break :brk this.reported_estimated_size.?;
};
}
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig
index f27e7f9aa..5987f749b 100644
--- a/src/bun.js/webcore/response.zig
+++ b/src/bun.js/webcore/response.zig
@@ -83,9 +83,9 @@ pub const Response = struct {
pub fn estimatedSize(this: *Response) callconv(.C) usize {
return this.reported_estimated_size orelse brk: {
- this.reported_estimated_size = @intCast(
+ this.reported_estimated_size = @as(
u63,
- this.body.value.estimatedSize() + this.url.len + this.status_text.len + @sizeOf(Response),
+ @intCast(this.body.value.estimatedSize() + this.url.len + this.status_text.len + @sizeOf(Response)),
);
break :brk this.reported_estimated_size.?;
};
@@ -411,7 +411,7 @@ pub const Response = struct {
if (args.nextEat()) |init| {
if (init.isUndefinedOrNull()) {} else if (init.isNumber()) {
- response.body.init.status_code = @intCast(u16, @min(@max(0, init.toInt32()), std.math.maxInt(u16)));
+ response.body.init.status_code = @as(u16, @intCast(@min(@max(0, init.toInt32()), std.math.maxInt(u16))));
} else {
if (Body.Init.init(getAllocator(globalThis), globalThis, init) catch null) |_init| {
response.body.init = _init;
@@ -457,7 +457,7 @@ pub const Response = struct {
if (args.nextEat()) |init| {
if (init.isUndefinedOrNull()) {} else if (init.isNumber()) {
- response.body.init.status_code = @intCast(u16, @min(@max(0, init.toInt32()), std.math.maxInt(u16)));
+ response.body.init.status_code = @as(u16, @intCast(@min(@max(0, init.toInt32()), std.math.maxInt(u16))));
} else {
if (Body.Init.init(getAllocator(globalThis), globalThis, init) catch null) |_init| {
response.body.init = _init;
@@ -827,7 +827,7 @@ pub const Fetch = struct {
.body = .{
.init = .{
.headers = FetchHeaders.createFromPicoHeaders(http_response.headers),
- .status_code = @truncate(u16, http_response.status_code),
+ .status_code = @as(u16, @truncate(http_response.status_code)),
},
.value = this.toBodyValue(),
},
@@ -838,7 +838,7 @@ pub const Fetch = struct {
const allocator = bun.default_allocator;
var response = allocator.create(Response) catch unreachable;
response.* = this.toResponse(allocator);
- return Response.makeMaybePooled(@ptrCast(js.JSContextRef, this.global_this), response);
+ return Response.makeMaybePooled(@as(js.JSContextRef, @ptrCast(this.global_this)), response);
}
pub fn get(
@@ -1375,7 +1375,7 @@ pub const Fetch = struct {
}
const original_size = body.Blob.size;
- const stat_size = @intCast(Blob.SizeType, stat.size);
+ const stat_size = @as(Blob.SizeType, @intCast(stat.size));
const blob_size = if (std.os.S.ISREG(stat.mode))
stat_size
else
@@ -1509,7 +1509,7 @@ pub const Headers = struct {
if (options.body) |body| {
if (body.hasContentTypeFromUser() and (fetch_headers_ref == null or !fetch_headers_ref.?.fastHas(.ContentType))) {
header_count += 1;
- buf_len += @truncate(u32, body.contentType().len + "Content-Type".len);
+ buf_len += @as(u32, @truncate(body.contentType().len + "Content-Type".len));
break :brk true;
}
}
@@ -1536,7 +1536,7 @@ pub const Headers = struct {
bun.copy(u8, headers.buf.items[buf_len_before_content_type + "Content-Type".len ..], options.body.?.contentType());
values[header_count - 1] = .{
.offset = buf_len_before_content_type + @as(u32, "Content-Type".len),
- .length = @truncate(u32, options.body.?.contentType().len),
+ .length = @as(u32, @truncate(options.body.?.contentType().len)),
};
}
@@ -1696,7 +1696,7 @@ pub const FetchEvent = struct {
defer {
if (!VirtualMachine.get().had_errors) {
- Output.printElapsed(@floatFromInt(f64, (request_context.timer.lap())) / std.time.ns_per_ms);
+ Output.printElapsed(@as(f64, @floatFromInt((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",
diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig
index 66e38b973..32aa67a28 100644
--- a/src/bun.js/webcore/streams.zig
+++ b/src/bun.js/webcore/streams.zig
@@ -326,20 +326,20 @@ pub const ReadableStream = struct {
pub fn init(filedes: bun.FileDescriptor) StreamTag {
var bytes = [8]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
- const filedes_ = @bitCast([8]u8, @as(usize, @truncate(u56, @intCast(usize, filedes))));
+ const filedes_ = @as([8]u8, @bitCast(@as(usize, @as(u56, @truncate(@as(usize, @intCast(filedes)))))));
bytes[1..8].* = filedes_[0..7].*;
- return @enumFromInt(StreamTag, @bitCast(u64, bytes));
+ return @as(StreamTag, @enumFromInt(@as(u64, @bitCast(bytes))));
}
pub fn fd(this: StreamTag) bun.FileDescriptor {
- var bytes = @bitCast([8]u8, @intFromEnum(this));
+ var bytes = @as([8]u8, @bitCast(@intFromEnum(this)));
if (bytes[0] != 1) {
return bun.invalid_fd;
}
var out: u64 = 0;
- @bitCast([8]u8, out)[0..7].* = bytes[1..8].*;
- return @intCast(bun.FileDescriptor, out);
+ @as([8]u8, @bitCast(out))[0..7].* = bytes[1..8].*;
+ return @as(bun.FileDescriptor, @intCast(out));
}
};
};
@@ -381,7 +381,7 @@ pub const StreamStart = union(Tag) {
return JSC.JSValue.jsUndefined();
},
.chunk_size => |chunk| {
- return JSC.JSValue.jsNumber(@intCast(Blob.SizeType, chunk));
+ return JSC.JSValue.jsNumber(@as(Blob.SizeType, @intCast(chunk)));
},
.err => |err| {
globalThis.vm().throwError(globalThis, err.toJSC(globalThis));
@@ -400,7 +400,7 @@ pub const StreamStart = union(Tag) {
if (value.get(globalThis, "chunkSize")) |chunkSize| {
if (chunkSize.isNumber())
- return .{ .chunk_size = @intCast(Blob.SizeType, @truncate(i52, chunkSize.toInt64())) };
+ return .{ .chunk_size = @as(Blob.SizeType, @intCast(@as(i52, @truncate(chunkSize.toInt64())))) };
}
return .{ .empty = {} };
@@ -435,7 +435,7 @@ pub const StreamStart = union(Tag) {
if (value.get(globalThis, "highWaterMark")) |chunkSize| {
if (chunkSize.isNumber()) {
empty = false;
- chunk_size = @intCast(JSC.WebCore.Blob.SizeType, @max(0, @truncate(i51, chunkSize.toInt64())));
+ chunk_size = @as(JSC.WebCore.Blob.SizeType, @intCast(@max(0, @as(i51, @truncate(chunkSize.toInt64())))));
}
}
@@ -454,7 +454,7 @@ pub const StreamStart = union(Tag) {
if (value.get(globalThis, "highWaterMark")) |chunkSize| {
if (chunkSize.isNumber())
- chunk_size = @intCast(JSC.WebCore.Blob.SizeType, @max(0, @truncate(i51, chunkSize.toInt64())));
+ chunk_size = @as(JSC.WebCore.Blob.SizeType, @intCast(@max(0, @as(i51, @truncate(chunkSize.toInt64())))));
}
if (value.get(globalThis, "path")) |path| {
@@ -491,7 +491,7 @@ pub const StreamStart = union(Tag) {
if (value.get(globalThis, "highWaterMark")) |chunkSize| {
if (chunkSize.isNumber()) {
empty = false;
- chunk_size = @intCast(JSC.WebCore.Blob.SizeType, @max(256, @truncate(i51, chunkSize.toInt64())));
+ chunk_size = @as(JSC.WebCore.Blob.SizeType, @intCast(@max(256, @as(i51, @truncate(chunkSize.toInt64())))));
}
}
@@ -845,7 +845,7 @@ pub const Signal = struct {
ptr: *anyopaque = dead,
vtable: VTable = VTable.Dead,
- pub const dead = @ptrFromInt(*anyopaque, 0xaaaaaaaa);
+ pub const dead = @as(*anyopaque, @ptrFromInt(0xaaaaaaaa));
pub fn clear(this: *Signal) void {
this.ptr = dead;
@@ -913,21 +913,21 @@ pub const Signal = struct {
const Functions = struct {
fn onClose(this: *anyopaque, err: ?Syscall.Error) void {
if (comptime !@hasDecl(Wrapped, "onClose"))
- Wrapped.close(@ptrCast(*Wrapped, @alignCast(std.meta.alignment(Wrapped), this)), err)
+ Wrapped.close(@as(*Wrapped, @ptrCast(@alignCast(this))), err)
else
- Wrapped.onClose(@ptrCast(*Wrapped, @alignCast(std.meta.alignment(Wrapped), this)), err);
+ Wrapped.onClose(@as(*Wrapped, @ptrCast(@alignCast(this))), err);
}
fn onReady(this: *anyopaque, amount: ?Blob.SizeType, offset: ?Blob.SizeType) void {
if (comptime !@hasDecl(Wrapped, "onReady"))
- Wrapped.ready(@ptrCast(*Wrapped, @alignCast(std.meta.alignment(Wrapped), this)), amount, offset)
+ Wrapped.ready(@as(*Wrapped, @ptrCast(@alignCast(this))), amount, offset)
else
- Wrapped.onReady(@ptrCast(*Wrapped, @alignCast(std.meta.alignment(Wrapped), this)), amount, offset);
+ Wrapped.onReady(@as(*Wrapped, @ptrCast(@alignCast(this))), amount, offset);
}
fn onStart(this: *anyopaque) void {
if (comptime !@hasDecl(Wrapped, "onStart"))
- Wrapped.start(@ptrCast(*Wrapped, @alignCast(std.meta.alignment(Wrapped), this)))
+ Wrapped.start(@as(*Wrapped, @ptrCast(@alignCast(this))))
else
- Wrapped.onStart(@ptrCast(*Wrapped, @alignCast(std.meta.alignment(Wrapped), this)));
+ Wrapped.onStart(@as(*Wrapped, @ptrCast(@alignCast(this))));
}
};
@@ -947,7 +947,7 @@ pub const Sink = struct {
used: bool = false,
pub const pending = Sink{
- .ptr = @ptrFromInt(*anyopaque, 0xaaaaaaaa),
+ .ptr = @as(*anyopaque, @ptrFromInt(0xaaaaaaaa)),
.vtable = undefined,
};
@@ -1059,19 +1059,19 @@ pub const Sink = struct {
) VTable {
const Functions = struct {
pub fn onWrite(this: *anyopaque, data: StreamResult) StreamResult.Writable {
- return Wrapped.write(@ptrCast(*Wrapped, @alignCast(std.meta.alignment(Wrapped), this)), data);
+ return Wrapped.write(@as(*Wrapped, @ptrCast(@alignCast(this))), data);
}
pub fn onConnect(this: *anyopaque, signal: Signal) JSC.Node.Maybe(void) {
- return Wrapped.connect(@ptrCast(*Wrapped, @alignCast(std.meta.alignment(Wrapped), this)), signal);
+ return Wrapped.connect(@as(*Wrapped, @ptrCast(@alignCast(this))), signal);
}
pub fn onWriteLatin1(this: *anyopaque, data: StreamResult) StreamResult.Writable {
- return Wrapped.writeLatin1(@ptrCast(*Wrapped, @alignCast(std.meta.alignment(Wrapped), this)), data);
+ return Wrapped.writeLatin1(@as(*Wrapped, @ptrCast(@alignCast(this))), data);
}
pub fn onWriteUTF16(this: *anyopaque, data: StreamResult) StreamResult.Writable {
- return Wrapped.writeUTF16(@ptrCast(*Wrapped, @alignCast(std.meta.alignment(Wrapped), this)), data);
+ return Wrapped.writeUTF16(@as(*Wrapped, @ptrCast(@alignCast(this))), data);
}
pub fn onEnd(this: *anyopaque, err: ?Syscall.Error) JSC.Node.Maybe(void) {
- return Wrapped.end(@ptrCast(*Wrapped, @alignCast(std.meta.alignment(Wrapped), this)), err);
+ return Wrapped.end(@as(*Wrapped, @ptrCast(@alignCast(this))), err);
}
};
@@ -1386,13 +1386,13 @@ pub const FileSink = struct {
},
.PIPE => {
this.cleanup();
- this.pending.consumed = @truncate(Blob.SizeType, total - initial);
+ this.pending.consumed = @as(Blob.SizeType, @truncate(total - initial));
return .{ .done = {} };
},
else => {},
}
this.pending.result = .{ .err = res.err };
- this.pending.consumed = @truncate(Blob.SizeType, total - initial);
+ this.pending.consumed = @as(Blob.SizeType, @truncate(total - initial));
return .{ .err = res.err };
}
@@ -1429,7 +1429,7 @@ pub const FileSink = struct {
poll.flags.remove(.writable);
std.debug.assert(poll.flags.contains(.poll_writable));
}
- this.pending.consumed = @truncate(Blob.SizeType, total - initial);
+ this.pending.consumed = @as(Blob.SizeType, @truncate(total - initial));
return .{
.pending = &this.pending,
@@ -1453,9 +1453,9 @@ pub const FileSink = struct {
}
this.pending.result = .{
- .owned = @truncate(Blob.SizeType, total),
+ .owned = @as(Blob.SizeType, @truncate(total)),
};
- this.pending.consumed = @truncate(Blob.SizeType, total - initial);
+ this.pending.consumed = @as(Blob.SizeType, @truncate(total - initial));
if (is_fifo and remain.len == 0 and this.isWatching()) {
this.unwatch(fd);
@@ -1477,7 +1477,7 @@ pub const FileSink = struct {
}
}
this.pending.run();
- return .{ .owned = @truncate(Blob.SizeType, total - initial) };
+ return .{ .owned = @as(Blob.SizeType, @truncate(total - initial)) };
}
pub fn flushFromJS(this: *FileSink, globalThis: *JSGlobalObject, _: bool) JSC.Node.Maybe(JSValue) {
@@ -1571,7 +1571,7 @@ pub const FileSink = struct {
}
if (comptime Environment.isMac) {
- _ = this.flushMaybePollWithSizeAndBuffer(this.buffer.slice(), @intCast(usize, @max(writable, 0)));
+ _ = this.flushMaybePollWithSizeAndBuffer(this.buffer.slice(), @as(usize, @intCast(@max(writable, 0))));
} else {
_ = this.flushMaybePollWithSizeAndBuffer(this.buffer.slice(), std.math.maxInt(usize));
}
@@ -1643,7 +1643,7 @@ pub const FileSink = struct {
if (this.next) |*next| {
return next.writeUTF16(data);
}
- const len = this.buffer.writeUTF16(this.allocator, @ptrCast([*]const u16, @alignCast(@alignOf(u16), data.slice().ptr))[0..std.mem.bytesAsSlice(u16, data.slice()).len]) catch {
+ const len = this.buffer.writeUTF16(this.allocator, @as([*]const u16, @ptrCast(@alignCast(data.slice().ptr)))[0..std.mem.bytesAsSlice(u16, data.slice()).len]) catch {
return .{ .err = Syscall.Error.oom };
};
@@ -1859,7 +1859,7 @@ pub const ArrayBufferSink = struct {
if (this.next) |*next| {
return next.writeUTF16(data);
}
- const len = this.bytes.writeUTF16(this.allocator, @ptrCast([*]const u16, @alignCast(@alignOf(u16), data.slice().ptr))[0..std.mem.bytesAsSlice(u16, data.slice()).len]) catch {
+ const len = this.bytes.writeUTF16(this.allocator, @as([*]const u16, @ptrCast(@alignCast(data.slice().ptr)))[0..std.mem.bytesAsSlice(u16, data.slice()).len]) catch {
return .{ .err = Syscall.Error.oom };
};
this.signal.ready(null, null);
@@ -2313,15 +2313,15 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
pub fn init(cpp: JSValue) Signal {
// this one can be null
@setRuntimeSafety(false);
- return Signal.initWithType(SinkSignal, @ptrFromInt(*SinkSignal, @bitCast(usize, @intFromEnum(cpp))));
+ return Signal.initWithType(SinkSignal, @as(*SinkSignal, @ptrFromInt(@as(usize, @bitCast(@intFromEnum(cpp))))));
}
pub fn close(this: *@This(), _: ?Syscall.Error) void {
- onClose(@bitCast(SinkSignal, @intFromPtr(this)).cpp, JSValue.jsUndefined());
+ onClose(@as(SinkSignal, @bitCast(@intFromPtr(this))).cpp, JSValue.jsUndefined());
}
pub fn ready(this: *@This(), _: ?Blob.SizeType, _: ?Blob.SizeType) void {
- onReady(@bitCast(SinkSignal, @intFromPtr(this)).cpp, JSValue.jsUndefined(), JSValue.jsUndefined());
+ onReady(@as(SinkSignal, @bitCast(@intFromPtr(this))).cpp, JSValue.jsUndefined(), JSValue.jsUndefined());
}
pub fn start(_: *@This()) void {}
@@ -2384,7 +2384,7 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
}
pub fn finalize(ptr: *anyopaque) callconv(.C) void {
- var this = @ptrCast(*ThisSink, @alignCast(std.meta.alignment(ThisSink), ptr));
+ var this = @as(*ThisSink, @ptrCast(@alignCast(ptr)));
this.sink.finalize();
}
@@ -2397,7 +2397,7 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
if (this.sink.signal.isDead())
return;
this.sink.signal.clear();
- const value = @enumFromInt(JSValue, @bitCast(JSC.JSValueReprInt, @intFromPtr(ptr)));
+ const value = @as(JSValue, @enumFromInt(@as(JSC.JSValueReprInt, @bitCast(@intFromPtr(ptr)))));
value.unprotect();
detachPtr(value);
}
@@ -2407,15 +2407,14 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
}
fn getThis(globalThis: *JSGlobalObject, callframe: *const JSC.CallFrame) ?*ThisSink {
- return @ptrCast(
+ return @as(
*ThisSink,
- @alignCast(
- std.meta.alignment(ThisSink),
+ @ptrCast(@alignCast(
fromJS(
globalThis,
callframe.this(),
) orelse return null,
- ),
+ )),
);
}
@@ -2535,7 +2534,7 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
pub fn close(globalThis: *JSGlobalObject, sink_ptr: ?*anyopaque) callconv(.C) JSValue {
JSC.markBinding(@src());
- var this = @ptrCast(*ThisSink, @alignCast(std.meta.alignment(ThisSink), sink_ptr orelse return invalidThis(globalThis)));
+ var this = @as(*ThisSink, @ptrCast(@alignCast(sink_ptr orelse return invalidThis(globalThis))));
if (comptime @hasDecl(SinkType, "getPendingError")) {
if (this.sink.getPendingError()) |err| {
@@ -2634,7 +2633,7 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
pub fn endWithSink(ptr: *anyopaque, globalThis: *JSGlobalObject) callconv(.C) JSValue {
JSC.markBinding(@src());
- var this = @ptrCast(*ThisSink, @alignCast(std.meta.alignment(ThisSink), ptr));
+ var this = @as(*ThisSink, @ptrCast(@alignCast(ptr)));
if (comptime @hasDecl(SinkType, "getPendingError")) {
if (this.sink.getPendingError()) |err| {
@@ -2697,7 +2696,7 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
// pub fn connect(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSValue {
// JSC.markBinding(@src());
-// var this = @ptrCast(*ThisSocket, @alignCast(std.meta.alignment(ThisSocket), fromJS(globalThis, callframe.this()) orelse {
+// var this = @ptrCast(*ThisSocket, @alignCast( fromJS(globalThis, callframe.this()) orelse {
// const err = JSC.toTypeError(JSC.Node.ErrorCode.ERR_INVALID_THIS, "Expected Socket", .{}, globalThis);
// globalThis.vm().throwError(globalThis, err);
// return JSC.JSValue.jsUndefined();
@@ -2747,10 +2746,10 @@ pub fn HTTPServerWritable(comptime ssl: bool) type {
}
fn handleWrote(this: *@This(), amount1: usize) void {
- const amount = @truncate(Blob.SizeType, amount1);
+ const amount = @as(Blob.SizeType, @truncate(amount1));
this.offset += amount;
this.wrote += amount;
- this.buffer.len -|= @truncate(u32, amount);
+ this.buffer.len -|= @as(u32, @truncate(amount));
if (this.offset >= this.buffer.len) {
this.offset = 0;
@@ -2806,7 +2805,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 = @min(@truncate(Blob.SizeType, write_offset), @as(Blob.SizeType, this.buffer.len));
+ const to_write = @min(@as(Blob.SizeType, @truncate(write_offset)), @as(Blob.SizeType, this.buffer.len));
// figure out how much data exactly to write
const readable = this.readableSlice()[0..to_write];
@@ -2816,7 +2815,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type {
return true;
}
- this.handleWrote(@truncate(Blob.SizeType, readable.len));
+ this.handleWrote(@as(Blob.SizeType, @truncate(readable.len)));
const initial_wrote = this.wrote;
if (this.buffer.len > 0 and !this.done) {
@@ -2830,7 +2829,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type {
// pending_flush or callback could have caused another send()
// so we check again if we should report readiness
if (!this.done and !this.requested_end and !this.hasBackpressure()) {
- const pending = @truncate(Blob.SizeType, write_offset) -| to_write;
+ const pending = @as(Blob.SizeType, @truncate(write_offset)) -| to_write;
const written_after_flush = this.wrote - initial_wrote;
const to_report = pending - @min(written_after_flush, pending);
@@ -2900,7 +2899,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type {
const success = this.send(slice);
if (success) {
- this.handleWrote(@truncate(Blob.SizeType, slice.len));
+ this.handleWrote(@as(Blob.SizeType, @truncate(slice.len)));
return .{ .result = JSValue.jsNumber(slice.len) };
}
@@ -2926,7 +2925,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type {
assert(slice.len > 0);
const success = this.send(slice);
if (success) {
- this.handleWrote(@truncate(Blob.SizeType, slice.len));
+ this.handleWrote(@as(Blob.SizeType, @truncate(slice.len)));
return .{ .result = JSC.JSPromise.resolvedPromiseValue(globalThis, JSValue.jsNumber(slice.len)) };
}
@@ -2961,7 +2960,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type {
}
const bytes = data.slice();
- const len = @truncate(Blob.SizeType, bytes.len);
+ const len = @as(Blob.SizeType, @truncate(bytes.len));
log("write({d})", .{bytes.len});
if (this.buffer.len == 0 and len >= this.highWaterMark) {
@@ -3013,7 +3012,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type {
}
const bytes = data.slice();
- const len = @truncate(Blob.SizeType, bytes.len);
+ const len = @as(Blob.SizeType, @truncate(bytes.len));
log("writeLatin1({d})", .{bytes.len});
if (this.buffer.len == 0 and len >= this.highWaterMark) {
@@ -3080,7 +3079,7 @@ pub fn HTTPServerWritable(comptime ssl: bool) type {
// we must always buffer UTF-16
// we assume the case of all-ascii UTF-16 string is pretty uncommon
- const written = this.buffer.writeUTF16(this.allocator, @alignCast(2, std.mem.bytesAsSlice(u16, bytes))) catch {
+ const written = this.buffer.writeUTF16(this.allocator, @alignCast(std.mem.bytesAsSlice(u16, bytes))) catch {
return .{ .err = Syscall.Error.fromCode(.NOMEM, .write) };
};
@@ -3089,13 +3088,13 @@ pub fn HTTPServerWritable(comptime ssl: bool) type {
if (readable.len >= this.highWaterMark or this.hasBackpressure()) {
if (this.send(readable)) {
this.handleWrote(readable.len);
- return .{ .owned = @intCast(Blob.SizeType, written) };
+ return .{ .owned = @as(Blob.SizeType, @intCast(written)) };
}
this.res.onWritable(*@This(), onWritable, this);
}
- return .{ .owned = @intCast(Blob.SizeType, written) };
+ return .{ .owned = @as(Blob.SizeType, @intCast(written)) };
}
// In this case, it's always an error
@@ -3527,7 +3526,7 @@ pub const ByteBlobLoader = struct {
return .{ .done = {} };
}
- const copied = @intCast(Blob.SizeType, temporary.len);
+ const copied = @as(Blob.SizeType, @intCast(temporary.len));
this.remain -|= copied;
this.offset +|= copied;
@@ -3557,8 +3556,8 @@ pub const ByteBlobLoader = struct {
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);
- this.remain -|= @truncate(Blob.SizeType, cloned.items.len);
+ this.offset +|= @as(Blob.SizeType, @truncate(cloned.items.len));
+ this.remain -|= @as(Blob.SizeType, @truncate(cloned.items.len));
return bun.ByteList.fromList(cloned);
}
@@ -3593,7 +3592,7 @@ pub const Pipe = struct {
pub fn New(comptime Type: type, comptime Function: anytype) type {
return struct {
pub fn pipe(self: *anyopaque, stream: StreamResult, allocator: std.mem.Allocator) void {
- Function(@ptrCast(*Type, @alignCast(@alignOf(Type), self)), stream, allocator);
+ Function(@as(*Type, @ptrCast(@alignCast(self))), stream, allocator);
}
pub fn init(self: *Type) Pipe {
@@ -3707,14 +3706,14 @@ pub const ByteStream = struct {
this.pending.result = .{
.into_array_and_done = .{
.value = this.value(),
- .len = @truncate(Blob.SizeType, to_copy.len),
+ .len = @as(Blob.SizeType, @truncate(to_copy.len)),
},
};
} else {
this.pending.result = .{
.into_array = .{
.value = this.value(),
- .len = @truncate(Blob.SizeType, to_copy.len),
+ .len = @as(Blob.SizeType, @truncate(to_copy.len)),
},
};
}
@@ -3803,7 +3802,7 @@ pub const ByteStream = struct {
return .{
.into_array_and_done = .{
.value = view,
- .len = @truncate(Blob.SizeType, to_write),
+ .len = @as(Blob.SizeType, @truncate(to_write)),
},
};
}
@@ -3811,7 +3810,7 @@ pub const ByteStream = struct {
return .{
.into_array = .{
.value = view,
- .len = @truncate(Blob.SizeType, to_write),
+ .len = @as(Blob.SizeType, @truncate(to_write)),
},
};
}
@@ -3902,9 +3901,9 @@ pub const ReadResult = union(enum) {
else if (owned)
StreamResult{ .owned = bun.ByteList.init(slice) }
else if (done)
- StreamResult{ .into_array_and_done = .{ .len = @truncate(Blob.SizeType, slice.len), .value = view } }
+ StreamResult{ .into_array_and_done = .{ .len = @as(Blob.SizeType, @truncate(slice.len)), .value = view } }
else
- StreamResult{ .into_array = .{ .len = @truncate(Blob.SizeType, slice.len), .value = view } };
+ StreamResult{ .into_array = .{ .len = @as(Blob.SizeType, @truncate(slice.len)), .value = view } };
},
};
}
@@ -4005,7 +4004,7 @@ pub const FIFO = struct {
return @as(u32, 0);
}
- return @intCast(u32, @max(len, 0));
+ return @as(u32, @intCast(@max(len, 0)));
}
pub fn adjustPipeCapacityOnLinux(this: *FIFO, current: usize, max: usize) void {
@@ -4036,7 +4035,7 @@ pub const FIFO = struct {
if (!is_readable and (this.close_on_empty_read or poll.isHUP())) {
// it might be readable actually
this.close_on_empty_read = true;
- switch (bun.isReadable(@intCast(std.os.fd_t, poll.fd))) {
+ switch (bun.isReadable(@as(std.os.fd_t, @intCast(poll.fd)))) {
.ready => {
this.close_on_empty_read = false;
return null;
@@ -4059,7 +4058,7 @@ pub const FIFO = struct {
// this happens if we've registered a watcher but we haven't
// ticked the event loop since registering it
- switch (bun.isReadable(@intCast(std.os.fd_t, poll.fd))) {
+ switch (bun.isReadable(@as(std.os.fd_t, @intCast(poll.fd)))) {
.ready => {
poll.flags.insert(.readable);
return null;
@@ -4102,7 +4101,7 @@ pub const FIFO = struct {
}
if (size_or_offset != std.math.maxInt(@TypeOf(size_or_offset)))
- this.to_read = @intCast(u32, @max(size_or_offset, 0));
+ this.to_read = @as(u32, @intCast(@max(size_or_offset, 0)));
return this.to_read;
}
@@ -4128,7 +4127,7 @@ pub const FIFO = struct {
var auto_sizer = this.auto_sizer orelse return;
if (comptime Environment.isMac) {
if (sizeOrOffset > 0) {
- this.buf = auto_sizer.resize(@intCast(usize, sizeOrOffset)) catch return;
+ this.buf = auto_sizer.resize(@as(usize, @intCast(sizeOrOffset))) catch return;
} else {
this.buf = auto_sizer.resize(8096) catch return;
}
@@ -4140,14 +4139,14 @@ pub const FIFO = struct {
// On Linux, we end up calling ioctl() twice if we don't do this
if (comptime Environment.isMac)
// i33 holds the same amount of unsigned space as a u32, so we truncate it there before casting
- @intCast(u32, @truncate(i33, sizeOrOffset))
+ @as(u32, @intCast(@as(i33, @truncate(sizeOrOffset))))
else
null,
);
if (read_result == .read) {
if (this.to_read) |*to_read| {
- to_read.* = to_read.* -| @truncate(u32, read_result.read.len);
+ to_read.* = to_read.* -| @as(u32, @truncate(read_result.read.len));
}
}
@@ -4182,7 +4181,7 @@ pub const FIFO = struct {
if (read_result == .read) {
if (this.to_read) |*to_read| {
- to_read.* = to_read.* -| @truncate(u32, read_result.read.len);
+ to_read.* = to_read.* -| @as(u32, @truncate(read_result.read.len));
}
}
@@ -4205,7 +4204,7 @@ pub const FIFO = struct {
) ReadResult {
const available_to_read = this.getAvailableToRead(
if (kqueue_read_amt != null)
- @intCast(i64, kqueue_read_amt.?)
+ @as(i64, @intCast(kqueue_read_amt.?))
else
std.math.maxInt(i64),
);
@@ -4382,7 +4381,7 @@ pub const File = struct {
if ((flags & std.os.O.NONBLOCK) == 0) {
auto_close = true;
fd = switch (Syscall.fcntl(fd, std.os.F.DUPFD, 0)) {
- .result => |_fd| @intCast(@TypeOf(fd), _fd),
+ .result => |_fd| @as(@TypeOf(fd), @intCast(_fd)),
.err => |err| return .{ .err = err },
};
@@ -4419,14 +4418,14 @@ pub const File = struct {
return .{ .err = Syscall.Error.fromCode(.INVAL, .fstat) };
}
- file.mode = @intCast(JSC.Node.Mode, stat.mode);
+ file.mode = @as(JSC.Node.Mode, @intCast(stat.mode));
this.mode = file.mode;
this.seekable = std.os.S.ISREG(stat.mode);
file.seekable = this.seekable;
if (this.seekable) {
- this.remaining_bytes = @intCast(Blob.SizeType, stat.size);
+ this.remaining_bytes = @as(Blob.SizeType, @intCast(stat.size));
file.max_size = this.remaining_bytes;
if (this.remaining_bytes == 0) {
@@ -4464,11 +4463,11 @@ pub const File = struct {
}
pub fn onRead(this: *File, completion: *HTTPClient.NetworkThread.Completion, result: AsyncIO.ReadError!usize) void {
- this.concurrent.read = @truncate(Blob.SizeType, result catch |err| {
+ this.concurrent.read = @as(Blob.SizeType, @truncate(result catch |err| {
if (@hasField(HTTPClient.NetworkThread.Completion, "result")) {
this.pending.result = .{
.err = Syscall.Error{
- .errno = @intCast(Syscall.Error.Int, -completion.result),
+ .errno = @as(Syscall.Error.Int, @intCast(-completion.result)),
.syscall = .read,
},
};
@@ -4476,7 +4475,7 @@ pub const File = struct {
this.pending.result = .{
.err = Syscall.Error{
// this is too hacky
- .errno = @truncate(Syscall.Error.Int, @intCast(u16, @max(1, @intFromError(err)))),
+ .errno = @as(Syscall.Error.Int, @truncate(@as(u16, @intCast(@max(1, @intFromError(err)))))),
.syscall = .read,
},
};
@@ -4484,7 +4483,7 @@ pub const File = struct {
this.concurrent.read = 0;
scheduleMainThreadTask(this);
return;
- });
+ }));
scheduleMainThreadTask(this);
}
@@ -4509,7 +4508,7 @@ pub const File = struct {
return;
},
.result => |result| {
- this.concurrent.read += @intCast(Blob.SizeType, result);
+ this.concurrent.read += @as(Blob.SizeType, @intCast(result));
remaining = remaining[result..];
if (result == 0) {
@@ -4556,7 +4555,7 @@ pub const File = struct {
this.pending.result = .{
.into_array = .{
.value = view,
- .len = @truncate(Blob.SizeType, this.concurrent.read),
+ .len = @as(Blob.SizeType, @truncate(this.concurrent.read)),
},
};
} else {
@@ -4615,7 +4614,7 @@ pub const File = struct {
if (this.scheduled_count == 0) {
this.buf = buf;
this.view.set(globalThis, view);
- this.scheduleAsync(@truncate(Blob.SizeType, buf.len), globalThis);
+ this.scheduleAsync(@as(Blob.SizeType, @truncate(buf.len)), globalThis);
}
return .{ .pending = &this.pending };
},
@@ -4641,7 +4640,7 @@ pub const File = struct {
}
},
.result => |result| {
- this.remaining_bytes -|= @truncate(@TypeOf(this.remaining_bytes), result);
+ this.remaining_bytes -|= @as(@TypeOf(this.remaining_bytes), @truncate(result));
if (result == 0) {
return .{ .done = {} };
@@ -4869,7 +4868,7 @@ pub const FileReader = struct {
if (this.readable().* == .File) {
const chunk_size = this.readable().File.calculateChunkSize(std.math.maxInt(usize));
- return .{ .chunk_size = @truncate(Blob.SizeType, chunk_size) };
+ return .{ .chunk_size = @as(Blob.SizeType, @truncate(chunk_size)) };
}
return .{ .chunk_size = if (this.user_chunk_size == 0) default_fifo_chunk_size else this.user_chunk_size };
@@ -4997,8 +4996,8 @@ pub fn NewReadyWatcher(
}
pub fn unwatch(this: *Context, fd_: anytype) void {
- const fd = @intCast(c_int, fd_);
- std.debug.assert(@intCast(c_int, this.poll_ref.?.fd) == fd);
+ const fd = @as(c_int, @intCast(fd_));
+ std.debug.assert(@as(c_int, @intCast(this.poll_ref.?.fd)) == fd);
std.debug.assert(
this.poll_ref.?.unregister(JSC.VirtualMachine.get().uws_event_loop.?) == .result,
);
@@ -5026,7 +5025,7 @@ pub fn NewReadyWatcher(
}
pub fn watch(this: *Context, fd_: anytype) void {
- const fd = @intCast(c_int, fd_);
+ const fd = @as(c_int, @intCast(fd_));
var poll_ref: *JSC.FilePoll = this.poll_ref orelse brk: {
this.poll_ref = JSC.FilePoll.init(
JSC.VirtualMachine.get(),