aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/api')
-rw-r--r--src/bun.js/api/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.zig85
-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.zig38
-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
11 files changed, 244 insertions, 241 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 0a18dd015..2f35a48a5 100644
--- a/src/bun.js/api/bun/socket.zig
+++ b/src/bun.js/api/bun/socket.zig
@@ -389,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));
}
}
@@ -496,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))));
},
}
}
@@ -657,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;
},
@@ -1037,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
@@ -1250,6 +1250,7 @@ fn NewSocket(comptime ssl: bool) type {
// Add SNI support for TLS (mongodb and others requires this)
if (comptime ssl) {
var ssl_ptr = this.socket.ssl();
+
if (!ssl_ptr.isInitFinished()) {
if (this.server_name) |server_name| {
const host = normalizeHost(server_name);
@@ -1272,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)));
}
}
}
@@ -1557,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();
}
@@ -1640,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),
@@ -1972,7 +1973,7 @@ fn NewSocket(comptime ssl: bool) type {
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, @ptrCast([*c][*c]const u8, &ticket), &length);
+ BoringSSL.SSL_SESSION_get0_ticket(session, @as([*c][*c]const u8, @ptrCast(&ticket)), &length);
if (ticket == null or length == 0) {
return JSValue.jsUndefined();
@@ -2010,8 +2011,8 @@ fn NewSocket(comptime ssl: bool) type {
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 = @ptrCast([*c]const u8, session_slice.ptr);
- const session = BoringSSL.d2i_SSL_SESSION(null, &tmp, @intCast(c_long, session_slice.len)) orelse return JSValue.jsUndefined();
+ 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;
@@ -2046,9 +2047,9 @@ fn NewSocket(comptime ssl: bool) type {
return JSValue.jsUndefined();
}
- const buffer_size = @intCast(usize, size);
+ const buffer_size = @as(usize, @intCast(size));
var buffer = JSValue.createBufferFromLength(globalObject, buffer_size);
- var buffer_ptr = @ptrCast([*c]u8, buffer.asArrayBuffer(globalObject).?.ptr);
+ 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);
@@ -2071,6 +2072,7 @@ fn NewSocket(comptime ssl: bool) type {
var alpn_proto_len: u32 = 0;
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);
@@ -2128,7 +2130,7 @@ fn NewSocket(comptime ssl: bool) type {
defer label.deinit();
const label_slice = label.slice();
- const ssl_ptr = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
if (args.len > 2) {
const context_arg = args.ptr[2];
@@ -2141,11 +2143,11 @@ fn NewSocket(comptime ssl: bool) type {
if (JSC.Node.StringOrBuffer.fromJS(globalObject, arena.allocator(), context_arg, exception)) |sb| {
const context_slice = sb.slice();
- const buffer_size = @intCast(usize, length);
+ const buffer_size = @as(usize, @intCast(length));
var buffer = JSValue.createBufferFromLength(globalObject, buffer_size);
- var buffer_ptr = @ptrCast([*c]u8, buffer.asArrayBuffer(globalObject).?.ptr);
+ var buffer_ptr = @as([*c]u8, @ptrCast(buffer.asArrayBuffer(globalObject).?.ptr));
- const result = BoringSSL.SSL_export_keying_material(ssl_ptr, buffer_ptr, buffer_size, @ptrCast([*c]const u8, label_slice.ptr), label_slice.len, @ptrCast([*c]const u8, context_slice.ptr), context_slice.len, 1);
+ 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;
@@ -2159,11 +2161,11 @@ fn NewSocket(comptime ssl: bool) type {
return .zero;
}
} else {
- const buffer_size = @intCast(usize, length);
+ const buffer_size = @as(usize, @intCast(length));
var buffer = JSValue.createBufferFromLength(globalObject, buffer_size);
- var buffer_ptr = @ptrCast([*c]u8, buffer.asArrayBuffer(globalObject).?.ptr);
+ var buffer_ptr = @as([*c]u8, @ptrCast(buffer.asArrayBuffer(globalObject).?.ptr));
- const result = BoringSSL.SSL_export_keying_material(ssl_ptr, buffer_ptr, buffer_size, @ptrCast([*c]const u8, label_slice.ptr), label_slice.len, null, 0, 0);
+ 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;
@@ -2191,7 +2193,7 @@ fn NewSocket(comptime ssl: bool) type {
}
var result = JSValue.createEmptyObject(globalObject, 3);
- const ssl_ptr = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
+ 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
@@ -2255,7 +2257,7 @@ fn NewSocket(comptime ssl: bool) type {
}
var result = JSValue.createEmptyObject(globalObject, 3);
- const ssl_ptr = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
+ 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());
@@ -2301,19 +2303,19 @@ fn NewSocket(comptime ssl: bool) type {
return JSValue.jsUndefined();
}
- const ssl_ptr = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
+ 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, @ptrCast(*anyopaque, &dummy), @sizeOf(@TypeOf(dummy)));
+ 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 = @intCast(usize, size);
+ const buffer_size = @as(usize, @intCast(size));
var buffer = JSValue.createBufferFromLength(globalObject, buffer_size);
- var buffer_ptr = @ptrCast(*anyopaque, buffer.asArrayBuffer(globalObject).?.ptr);
+ 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);
@@ -2333,19 +2335,19 @@ fn NewSocket(comptime ssl: bool) type {
return JSValue.jsUndefined();
}
- const ssl_ptr = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
+ 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, @ptrCast(*anyopaque, &dummy), @sizeOf(@TypeOf(dummy)));
+ const size = BoringSSL.SSL_get_finished(ssl_ptr, @as(*anyopaque, @ptrCast(&dummy)), @sizeOf(@TypeOf(dummy)));
if (size == 0) return JSValue.jsUndefined();
- const buffer_size = @intCast(usize, size);
+ const buffer_size = @as(usize, @intCast(size));
var buffer = JSValue.createBufferFromLength(globalObject, buffer_size);
- var buffer_ptr = @ptrCast(*anyopaque, buffer.asArrayBuffer(globalObject).?.ptr);
+ 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);
@@ -2365,18 +2367,18 @@ fn NewSocket(comptime ssl: bool) type {
if (this.detached) {
return JSValue.jsNull();
}
- const ssl_ptr = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
+ 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, @intCast(usize, nsig));
+ const array = JSC.JSValue.createEmptyArray(globalObject, @as(usize, @intCast(nsig)));
- for (0..@intCast(usize, nsig)) |i| {
+ 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, @intCast(c_int, i), &sign_nid, &hash_nid, null, null, null);
+ _ = 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";
@@ -2430,14 +2432,14 @@ fn NewSocket(comptime ssl: bool) type {
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, @intCast(u32, i), JSC.ZigString.fromUTF8(buffer).toValueGC(globalObject));
+ 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, @intCast(u32, i), JSC.ZigString.fromUTF8(buffer).toValueGC(globalObject));
+ array.putIndex(globalObject, @as(u32, @intCast(i)), JSC.ZigString.fromUTF8(buffer).toValueGC(globalObject));
}
}
return array;
@@ -2457,7 +2459,7 @@ fn NewSocket(comptime ssl: bool) type {
return JSValue.jsNull();
}
- const ssl_ptr = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
+ 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);
@@ -2502,8 +2504,8 @@ fn NewSocket(comptime ssl: bool) type {
return .zero;
}
- const ssl_ptr = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
- return JSValue.jsBoolean(BoringSSL.SSL_set_max_send_fragment(ssl_ptr, @intCast(usize, size)) == 1);
+ 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,
@@ -2530,7 +2532,7 @@ fn NewSocket(comptime ssl: bool) type {
abbreviated = arg.toBoolean();
}
- const ssl_ptr = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
if (abbreviated) {
if (this.handlers.is_server) {
@@ -2573,7 +2575,7 @@ fn NewSocket(comptime ssl: bool) type {
return JSValue.jsUndefined();
}
- const ssl_ptr = @ptrCast(*BoringSSL.SSL, this.socket.getNativeHandle());
+ const ssl_ptr = @as(*BoringSSL.SSL, @ptrCast(this.socket.getNativeHandle()));
const cert = BoringSSL.SSL_get_certificate(ssl_ptr);
if (cert) |x509| {
@@ -2623,6 +2625,7 @@ fn NewSocket(comptime ssl: bool) type {
const host = normalizeHost(@as([]const u8, slice));
if (host.len > 0) {
var ssl_ptr = this.socket.ssl();
+
if (ssl_ptr.isInitFinished()) {
// match node.js exceptions
globalObject.throw("Already started.", .{});
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
index 707009936..20ab16547 100644
--- a/src/bun.js/api/bun/x509.zig
+++ b/src/bun.js/api/bun/x509.zig
@@ -13,8 +13,8 @@ fn x509GetNameObject(globalObject: *JSGlobalObject, name: ?*BoringSSL.X509_NAME)
}
var result = JSValue.createEmptyObject(globalObject, 1);
- for (0..@intCast(usize, cnt)) |i| {
- const entry = BoringSSL.X509_NAME_get_entry(name, @intCast(c_int, i)) orelse continue;
+ 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
@@ -37,7 +37,7 @@ fn x509GetNameObject(globalObject: *JSGlobalObject, name: ?*BoringSSL.X509_NAME)
if (length <= 0) {
continue;
}
- name_slice = type_buf[0..@intCast(usize, length)];
+ name_slice = type_buf[0..@as(usize, @intCast(length))];
}
const value_data = BoringSSL.X509_NAME_ENTRY_get_data(entry);
@@ -47,7 +47,7 @@ fn x509GetNameObject(globalObject: *JSGlobalObject, name: ?*BoringSSL.X509_NAME)
if (value_str_len < 0) {
continue;
}
- const value_slice = value_str[0..@intCast(usize, value_str_len)];
+ 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
@@ -119,7 +119,7 @@ inline fn printAltName(out: *BoringSSL.BIO, name: []const u8, utf8: bool, safe_p
if (safe_prefix) |prefix| {
_ = BoringSSL.BIO_printf(out, "%s:", prefix);
}
- _ = BoringSSL.BIO_write(out, @ptrCast([*]const u8, name.ptr), @intCast(c_int, name.len));
+ _ = 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
@@ -154,11 +154,11 @@ inline fn printAltName(out: *BoringSSL.BIO, name: []const u8, utf8: bool, safe_p
}
inline fn printLatin1AltName(out: *BoringSSL.BIO, name: *BoringSSL.ASN1_IA5STRING, safe_prefix: ?[*]const u8) void {
- printAltName(out, name.data[0..@intCast(usize, name.length)], false, safe_prefix);
+ 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..@intCast(usize, name.length)], true, safe_prefix);
+ 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;
@@ -203,9 +203,9 @@ fn x509PrintGeneralName(out: *BoringSSL.BIO, name: *BoringSSL.GENERAL_NAME) bool
return false;
}
var oline: [*]const u8 = undefined;
- const n_bytes = BoringSSL.BIO_get_mem_data(tmp, @ptrCast([*c][*c]u8, &oline));
+ 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..@intCast(usize, n_bytes)], true, null);
+ 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
@@ -262,7 +262,7 @@ fn x509PrintGeneralName(out: *BoringSSL.BIO, name: *BoringSSL.GENERAL_NAME) bool
_ = 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 = (@intCast(u16, b[2 * j]) << 8) | @intCast(u16, b[2 * j + 1]);
+ 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 {
@@ -373,7 +373,7 @@ fn addFingerprintDigest(md: []const u8, mdSize: c_uint, fingerprint: []u8) usize
const hex: []const u8 = "0123456789ABCDEF";
var idx: usize = 0;
- const slice = md[0..@intCast(usize, mdSize)];
+ const slice = md[0..@as(usize, @intCast(mdSize))];
for (slice) |byte| {
fingerprint[idx] = hex[(byte & 0xF0) >> 4];
fingerprint[idx + 1] = hex[byte & 0x0F];
@@ -390,7 +390,7 @@ fn getFingerprintDigest(cert: *BoringSSL.X509, method: *const BoringSSL.EVP_MD,
var md_size: c_uint = 0;
var fingerprint: [BoringSSL.EVP_MAX_MD_SIZE * 3]u8 = undefined;
- if (BoringSSL.X509_digest(cert, method, @ptrCast([*c]u8, &md), &md_size) != 0) {
+ 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);
}
@@ -416,8 +416,8 @@ fn getSerialNumber(cert: *BoringSSL.X509, globalObject: *JSGlobalObject) JSValue
fn getRawDERCertificate(cert: *BoringSSL.X509, globalObject: *JSGlobalObject) JSValue {
const size = BoringSSL.i2d_X509(cert, null);
- var buffer = JSValue.createBufferFromLength(globalObject, @intCast(usize, size));
- var buffer_ptr = @ptrCast([*c]u8, buffer.asArrayBuffer(globalObject).?.ptr);
+ 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;
@@ -457,7 +457,7 @@ pub fn toJS(cert: *BoringSSL.X509, globalObject: *JSGlobalObject) JSValue {
if (rsa_key) |rsa| {
var n: [*c]const BoringSSL.BIGNUM = undefined;
var e: [*c]const BoringSSL.BIGNUM = undefined;
- BoringSSL.RSA_get0_key(rsa, @ptrCast([*c][*c]const BoringSSL.BIGNUM, &n), @ptrCast([*c][*c]const BoringSSL.BIGNUM, &e), null);
+ 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();
@@ -487,8 +487,8 @@ pub fn toJS(cert: *BoringSSL.X509, globalObject: *JSGlobalObject) JSValue {
return .zero;
}
- var buffer = JSValue.createBufferFromLength(globalObject, @intCast(usize, size));
- var buffer_ptr = @ptrCast([*c]u8, buffer.asArrayBuffer(globalObject).?.ptr);
+ 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);
@@ -517,8 +517,8 @@ pub fn toJS(cert: *BoringSSL.X509, globalObject: *JSGlobalObject) JSValue {
return .zero;
}
- var buffer = JSValue.createBufferFromLength(globalObject, @intCast(usize, size));
- var buffer_ptr = @ptrCast([*c]u8, buffer.asArrayBuffer(globalObject).?.ptr);
+ 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);
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 {