aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/webcore
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/webcore')
-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
6 files changed, 190 insertions, 191 deletions
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(),