aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-06-21 23:38:18 -0700
committerGravatar GitHub <noreply@github.com> 2023-06-21 23:38:18 -0700
commit5fa13625a1ca0ea1a3a1c5bb86d0880dcfac349f (patch)
tree97f669a178e60772038751d690c3e298a63557b2 /src/bun.js
parentbfb322d618a3f0e9618d311ae69016fe7a08e771 (diff)
downloadbun-5fa13625a1ca0ea1a3a1c5bb86d0880dcfac349f.tar.gz
bun-5fa13625a1ca0ea1a3a1c5bb86d0880dcfac349f.tar.zst
bun-5fa13625a1ca0ea1a3a1c5bb86d0880dcfac349f.zip
upgrade zig to `v0.11.0-dev.3737+9eb008717` (#3374)
* progress * finish `@memset/@memcpy` update * Update build.zig * change `@enumToInt` to `@intFromEnum` and friends * update zig versions * it was 1 * add link to issue * add `compileError` reminder * fix merge * format * upgrade to llvm 16 * Revert "upgrade to llvm 16" This reverts commit cc930ceb1c5b4db9614a7638596948f704544ab8. --------- Co-authored-by: Jarred Sumner <jarred@jarredsumner.com> Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/api/JSBundler.zig6
-rw-r--r--src/bun.js/api/JSTranspiler.zig10
-rw-r--r--src/bun.js/api/bun.zig92
-rw-r--r--src/bun.js/api/bun/dns_resolver.zig14
-rw-r--r--src/bun.js/api/bun/socket.zig18
-rw-r--r--src/bun.js/api/bun/subprocess.zig6
-rw-r--r--src/bun.js/api/ffi.zig30
-rw-r--r--src/bun.js/api/html_rewriter.zig4
-rw-r--r--src/bun.js/api/server.zig34
-rw-r--r--src/bun.js/base.zig68
-rw-r--r--src/bun.js/bindings/FFI.zig14
-rw-r--r--src/bun.js/bindings/bindings.zig118
-rw-r--r--src/bun.js/bindings/exports.zig44
-rw-r--r--src/bun.js/bindings/header-gen.zig6
-rw-r--r--src/bun.js/bindings/shimmer.zig2
-rw-r--r--src/bun.js/javascript.zig20
-rw-r--r--src/bun.js/javascript_core_c_api.zig54
-rw-r--r--src/bun.js/module_loader.zig2
-rw-r--r--src/bun.js/node/buffer.zig2
-rw-r--r--src/bun.js/node/dir_iterator.zig54
-rw-r--r--src/bun.js/node/node_fs.zig34
-rw-r--r--src/bun.js/node/node_fs_constant.zig6
-rw-r--r--src/bun.js/node/node_os.zig6
-rw-r--r--src/bun.js/node/os/constants.zig4
-rw-r--r--src/bun.js/node/syscall.zig30
-rw-r--r--src/bun.js/node/types.zig62
-rw-r--r--src/bun.js/test/jest.zig8
-rw-r--r--src/bun.js/test/pretty_format.zig10
-rw-r--r--src/bun.js/webcore.zig2
-rw-r--r--src/bun.js/webcore/blob.zig20
-rw-r--r--src/bun.js/webcore/encoding.zig57
-rw-r--r--src/bun.js/webcore/request.zig6
-rw-r--r--src/bun.js/webcore/response.zig14
-rw-r--r--src/bun.js/webcore/streams.zig43
34 files changed, 454 insertions, 446 deletions
diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig
index 8e85f1190..e3b540da1 100644
--- a/src/bun.js/api/JSBundler.zig
+++ b/src/bun.js/api/JSBundler.zig
@@ -844,7 +844,7 @@ pub const JSBundler = struct {
this.value = .{
.success = .{
- .loader = @intToEnum(options.Loader, @intCast(u8, loader_as_int.to(i32))),
+ .loader = @enumFromInt(options.Loader, @intCast(u8, loader_as_int.to(i32))),
.source_code = source_code,
},
};
@@ -928,7 +928,7 @@ pub const JSBundler = struct {
else
ZigString.fromUTF8(namespace);
const path_string = ZigString.fromUTF8(path);
- JSBundlerPlugin__matchOnLoad(globalThis, this, &namespace_string, &path_string, context, @enumToInt(default_loader));
+ JSBundlerPlugin__matchOnLoad(globalThis, this, &namespace_string, &path_string, context, @intFromEnum(default_loader));
}
pub fn matchOnResolve(
@@ -949,7 +949,7 @@ pub const JSBundler = struct {
ZigString.fromUTF8(namespace);
const path_string = ZigString.fromUTF8(path);
const importer_string = ZigString.fromUTF8(importer);
- JSBundlerPlugin__matchOnResolve(globalThis, this, &namespace_string, &path_string, &importer_string, context, @enumToInt(import_record_kind));
+ JSBundlerPlugin__matchOnResolve(globalThis, this, &namespace_string, &path_string, &importer_string, context, @intFromEnum(import_record_kind));
}
pub fn addPlugin(
diff --git a/src/bun.js/api/JSTranspiler.zig b/src/bun.js/api/JSTranspiler.zig
index a1e1cfa36..308738abf 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 = @intToEnum(JSC.JSValue, 0),
+ protected_input_value: JSC.JSValue = @enumFromInt(JSC.JSValue, 0),
output_code: ZigString = ZigString.init(""),
bundler: Bundler.Bundler = undefined,
log: logger.Log,
@@ -220,8 +220,8 @@ pub const TransformTask = struct {
finish(this.output_code, this.global, promise);
- if (@enumToInt(this.protected_input_value) != 0) {
- this.protected_input_value = @intToEnum(JSC.JSValue, 0);
+ if (@intFromEnum(this.protected_input_value) != 0) {
+ this.protected_input_value = @enumFromInt(JSC.JSValue, 0);
}
this.deinit();
}
@@ -611,7 +611,7 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std
while (length_iter.next()) |value| {
if (value.isString()) {
const length = @truncate(u32, value.getLength(globalThis));
- string_count += @as(u32, @boolToInt(length > 0));
+ string_count += @as(u32, @intFromBool(length > 0));
total_name_buf_len += length;
}
}
@@ -877,7 +877,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, std.hash.Wyhash.hash(0, import.path.pretty));
+ import.module_id = @truncate(u32, bun.hash(import.path.pretty));
}
}
}
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig
index 5580e8840..9df125a58 100644
--- a/src/bun.js/api/bun.zig
+++ b/src/bun.js/api/bun.zig
@@ -303,7 +303,7 @@ pub fn registerMacro(
return js.JSValueMakeUndefined(ctx);
}
// TODO: make this faster
- const id = @truncate(i32, @floatToInt(i64, js.JSValueToNumber(ctx, arguments[0], exception)));
+ const id = @truncate(i32, @intFromFloat(i64, 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);
@@ -523,7 +523,7 @@ pub fn getFilePath(ctx: js.JSContextRef, arguments: []const js.JSValueRef, buf:
temp_strings_list[temp_strings_list_len] = out_slice;
// The dots are kind of unnecessary. They'll be normalized.
- if (out.len == 0 or @ptrToInt(out.ptr) == 0 or std.mem.eql(u8, out_slice, ".") or std.mem.eql(u8, out_slice, "..") or std.mem.eql(u8, out_slice, "../")) {
+ if (out.len == 0 or @intFromPtr(out.ptr) == 0 or std.mem.eql(u8, out_slice, ".") or std.mem.eql(u8, out_slice, "..") or std.mem.eql(u8, out_slice, "../")) {
JSError(getAllocator(ctx), "Expected a file path as a string or an array of strings to be part of a file path.", .{}, ctx, exception);
return null;
}
@@ -600,7 +600,7 @@ pub fn readFileAsStringCallback(
return js.JSValueMakeUndefined(ctx);
};
- if (stat.kind != .File) {
+ if (stat.kind != .file) {
JSError(getAllocator(ctx), "Can't read a {s} as a string (\"{s}\")", .{ @tagName(stat.kind), path }, ctx, exception);
return js.JSValueMakeUndefined(ctx);
}
@@ -641,7 +641,7 @@ pub fn readFileAsBytesCallback(
return js.JSValueMakeUndefined(ctx);
};
- if (stat.kind != .File) {
+ if (stat.kind != .file) {
JSError(allocator, "Can't read a {s} as a string (\"{s}\")", .{ @tagName(stat.kind), path }, ctx, exception);
return js.JSValueMakeUndefined(ctx);
}
@@ -1612,7 +1612,7 @@ pub const Crypto = struct {
fn createCryptoError(globalThis: *JSC.JSGlobalObject, err_code: u32) JSValue {
var outbuf: [128 + 1 + "BoringSSL error: ".len]u8 = undefined;
- @memset(&outbuf, 0, outbuf.len);
+ @memset(&outbuf, 0);
outbuf[0.."BoringSSL error: ".len].* = "BoringSSL error: ".*;
var message_buf = outbuf["BoringSSL error: ".len..];
@@ -3171,9 +3171,9 @@ pub fn mmapFile(
return JSC.C.JSObjectMakeTypedArrayWithBytesNoCopy(ctx, JSC.C.JSTypedArrayType.kJSTypedArrayTypeUint8Array, @ptrCast(?*anyopaque, 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..@ptrToInt(size)]);
+ _ = JSC.Node.Syscall.munmap(@ptrCast([*]align(std.mem.page_size) u8, @alignCast(std.mem.page_size, ptr))[0..@intFromPtr(size)]);
}
- }.x, @intToPtr(?*anyopaque, map.len), exception);
+ }.x, @ptrFromInt(?*anyopaque, map.len), exception);
}
pub fn getTranspilerConstructor(
@@ -3401,7 +3401,7 @@ pub const Unsafe = struct {
globalThis: *JSC.JSGlobalObject,
value_: ?JSValue,
) JSValue {
- const ret = JSValue.jsNumber(@as(i32, @enumToInt(globalThis.bunVM().aggressive_garbage_collection)));
+ const ret = JSValue.jsNumber(@as(i32, @intFromEnum(globalThis.bunVM().aggressive_garbage_collection)));
if (value_) |value| {
switch (value.coerce(i32, globalThis)) {
@@ -3912,7 +3912,7 @@ pub const Timer = struct {
id,
Timeout.run,
this.interval,
- @as(i32, @boolToInt(this.kind == .setInterval)) * this.interval,
+ @as(i32, @intFromBool(this.kind == .setInterval)) * this.interval,
);
return this_value;
}
@@ -4130,7 +4130,7 @@ pub const Timer = struct {
},
Timeout.run,
interval,
- @as(i32, @boolToInt(kind == .setInterval)) * interval,
+ @as(i32, @intFromBool(kind == .setInterval)) * interval,
);
}
@@ -4318,7 +4318,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) u8, addr).*;
+ const value = @ptrFromInt(*align(1) u8, addr).*;
return JSValue.jsNumber(value);
}
pub fn @"u16"(
@@ -4327,7 +4327,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) u16, addr).*;
+ const value = @ptrFromInt(*align(1) u16, addr).*;
return JSValue.jsNumber(value);
}
pub fn @"u32"(
@@ -4336,7 +4336,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) u32, addr).*;
+ const value = @ptrFromInt(*align(1) u32, addr).*;
return JSValue.jsNumber(value);
}
pub fn ptr(
@@ -4345,7 +4345,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) u64, addr).*;
+ const value = @ptrFromInt(*align(1) u64, addr).*;
return JSValue.jsNumber(value);
}
pub fn @"i8"(
@@ -4354,7 +4354,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) i8, addr).*;
+ const value = @ptrFromInt(*align(1) i8, addr).*;
return JSValue.jsNumber(value);
}
pub fn @"i16"(
@@ -4363,7 +4363,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) i16, addr).*;
+ const value = @ptrFromInt(*align(1) i16, addr).*;
return JSValue.jsNumber(value);
}
pub fn @"i32"(
@@ -4372,7 +4372,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) i32, addr).*;
+ const value = @ptrFromInt(*align(1) i32, addr).*;
return JSValue.jsNumber(value);
}
pub fn intptr(
@@ -4381,7 +4381,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) i64, addr).*;
+ const value = @ptrFromInt(*align(1) i64, addr).*;
return JSValue.jsNumber(value);
}
@@ -4391,7 +4391,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) f32, addr).*;
+ const value = @ptrFromInt(*align(1) f32, addr).*;
return JSValue.jsNumber(value);
}
@@ -4401,7 +4401,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) f64, addr).*;
+ const value = @ptrFromInt(*align(1) f64, addr).*;
return JSValue.jsNumber(value);
}
@@ -4411,7 +4411,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) i64, addr).*;
+ const value = @ptrFromInt(*align(1) i64, addr).*;
return JSValue.fromInt64NoTruncate(global, value);
}
@@ -4421,7 +4421,7 @@ pub const FFI = struct {
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 = @intToPtr(*align(1) u64, addr).*;
+ const value = @ptrFromInt(*align(1) u64, addr).*;
return JSValue.fromUInt64NoTruncate(global, value);
}
@@ -4432,7 +4432,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) u8, addr).*;
+ const value = @ptrFromInt(*align(1) u8, addr).*;
return JSValue.jsNumber(value);
}
pub fn u16WithoutTypeChecks(
@@ -4442,7 +4442,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) u16, addr).*;
+ const value = @ptrFromInt(*align(1) u16, addr).*;
return JSValue.jsNumber(value);
}
pub fn u32WithoutTypeChecks(
@@ -4452,7 +4452,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) u32, addr).*;
+ const value = @ptrFromInt(*align(1) u32, addr).*;
return JSValue.jsNumber(value);
}
pub fn ptrWithoutTypeChecks(
@@ -4462,7 +4462,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) u64, addr).*;
+ const value = @ptrFromInt(*align(1) u64, addr).*;
return JSValue.jsNumber(value);
}
pub fn i8WithoutTypeChecks(
@@ -4472,7 +4472,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) i8, addr).*;
+ const value = @ptrFromInt(*align(1) i8, addr).*;
return JSValue.jsNumber(value);
}
pub fn i16WithoutTypeChecks(
@@ -4482,7 +4482,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) i16, addr).*;
+ const value = @ptrFromInt(*align(1) i16, addr).*;
return JSValue.jsNumber(value);
}
pub fn i32WithoutTypeChecks(
@@ -4492,7 +4492,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) i32, addr).*;
+ const value = @ptrFromInt(*align(1) i32, addr).*;
return JSValue.jsNumber(value);
}
pub fn intptrWithoutTypeChecks(
@@ -4502,7 +4502,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) i64, addr).*;
+ const value = @ptrFromInt(*align(1) i64, addr).*;
return JSValue.jsNumber(value);
}
@@ -4513,7 +4513,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) f32, addr).*;
+ const value = @ptrFromInt(*align(1) f32, addr).*;
return JSValue.jsNumber(value);
}
@@ -4524,7 +4524,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) f64, addr).*;
+ const value = @ptrFromInt(*align(1) f64, addr).*;
return JSValue.jsNumber(value);
}
@@ -4535,7 +4535,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) u64, addr).*;
+ const value = @ptrFromInt(*align(1) u64, addr).*;
return JSValue.fromUInt64NoTruncate(global, value);
}
@@ -4546,7 +4546,7 @@ pub const FFI = struct {
offset: i32,
) callconv(.C) JSValue {
const addr = @intCast(usize, raw_addr) + @intCast(usize, offset);
- const value = @intToPtr(*align(1) i64, addr).*;
+ const value = @ptrFromInt(*align(1) i64, addr).*;
return JSValue.fromInt64NoTruncate(global, value);
}
@@ -4590,7 +4590,7 @@ pub const FFI = struct {
_: *anyopaque,
array: *JSC.JSUint8Array,
) callconv(.C) JSValue {
- return JSValue.fromPtrAddress(@ptrToInt(array.ptr()));
+ return JSValue.fromPtrAddress(@intFromPtr(array.ptr()));
}
fn ptr_(
@@ -4610,9 +4610,9 @@ pub const FFI = struct {
return JSC.toInvalidArguments("ArrayBufferView must have a length > 0. A pointer to empty memory doesn't work", .{}, globalThis);
}
- var addr: usize = @ptrToInt(array_buffer.ptr);
+ var addr: usize = @intFromPtr(array_buffer.ptr);
// const Sizes = @import("../bindings/sizes.zig");
- // std.debug.assert(addr == @ptrToInt(value.asEncoded().ptr) + Sizes.Bun_FFI_PointerOffsetToTypedArrayVector);
+ // std.debug.assert(addr == @intFromPtr(value.asEncoded().ptr) + Sizes.Bun_FFI_PointerOffsetToTypedArrayVector);
if (byteOffset) |off| {
if (!off.isEmptyOrUndefinedOrNull()) {
@@ -4628,7 +4628,7 @@ pub const FFI = struct {
addr += @intCast(usize, bytei64);
}
- if (addr > @ptrToInt(array_buffer.ptr) + @as(usize, array_buffer.byte_len)) {
+ if (addr > @intFromPtr(array_buffer.ptr) + @as(usize, array_buffer.byte_len)) {
return JSC.toInvalidArguments("byteOffset out of bounds", .{}, globalThis);
}
}
@@ -4720,11 +4720,11 @@ pub const FFI = struct {
}
const length = @intCast(usize, length_i);
- return .{ .slice = @intToPtr([*]u8, addr)[0..length] };
+ return .{ .slice = @ptrFromInt([*]u8, addr)[0..length] };
}
}
- return .{ .slice = bun.span(@intToPtr([*:0]u8, addr)) };
+ return .{ .slice = bun.span(@ptrFromInt([*:0]u8, addr)) };
}
fn getCPtr(value: JSValue) ?usize {
@@ -4759,11 +4759,11 @@ pub const FFI = struct {
var ctx: ?*anyopaque = null;
if (finalizationCallback) |callback_value| {
if (getCPtr(callback_value)) |callback_ptr| {
- callback = @intToPtr(JSC.C.JSTypedArrayBytesDeallocator, callback_ptr);
+ callback = @ptrFromInt(JSC.C.JSTypedArrayBytesDeallocator, callback_ptr);
if (finalizationCtxOrPtr) |ctx_value| {
if (getCPtr(ctx_value)) |ctx_ptr| {
- ctx = @intToPtr(*anyopaque, ctx_ptr);
+ ctx = @ptrFromInt(*anyopaque, ctx_ptr);
} else if (!ctx_value.isUndefinedOrNull()) {
return JSC.toInvalidArguments("Expected user data to be a C pointer (number or BigInt)", .{}, globalThis);
}
@@ -4773,7 +4773,7 @@ pub const FFI = struct {
}
} else if (finalizationCtxOrPtr) |callback_value| {
if (getCPtr(callback_value)) |callback_ptr| {
- callback = @intToPtr(JSC.C.JSTypedArrayBytesDeallocator, callback_ptr);
+ callback = @ptrFromInt(JSC.C.JSTypedArrayBytesDeallocator, callback_ptr);
} else if (!callback_value.isEmptyOrUndefinedOrNull()) {
return JSC.toInvalidArguments("Expected callback to be a C pointer (number or BigInt)", .{}, globalThis);
}
@@ -4801,11 +4801,11 @@ pub const FFI = struct {
var ctx: ?*anyopaque = null;
if (finalizationCallback) |callback_value| {
if (getCPtr(callback_value)) |callback_ptr| {
- callback = @intToPtr(JSC.C.JSTypedArrayBytesDeallocator, callback_ptr);
+ callback = @ptrFromInt(JSC.C.JSTypedArrayBytesDeallocator, callback_ptr);
if (finalizationCtxOrPtr) |ctx_value| {
if (getCPtr(ctx_value)) |ctx_ptr| {
- ctx = @intToPtr(*anyopaque, ctx_ptr);
+ ctx = @ptrFromInt(*anyopaque, ctx_ptr);
} else if (!ctx_value.isEmptyOrUndefinedOrNull()) {
return JSC.toInvalidArguments("Expected user data to be a C pointer (number or BigInt)", .{}, globalThis);
}
@@ -4815,7 +4815,7 @@ pub const FFI = struct {
}
} else if (finalizationCtxOrPtr) |callback_value| {
if (getCPtr(callback_value)) |callback_ptr| {
- callback = @intToPtr(JSC.C.JSTypedArrayBytesDeallocator, callback_ptr);
+ callback = @ptrFromInt(JSC.C.JSTypedArrayBytesDeallocator, 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 aec295056..fee834e5e 100644
--- a/src/bun.js/api/bun/dns_resolver.zig
+++ b/src/bun.js/api/bun/dns_resolver.zig
@@ -123,7 +123,7 @@ const LibInfo = struct {
this.vm.uws_event_loop.?,
.machport,
true,
- @ptrToInt(request.backend.libinfo.machport),
+ @intFromPtr(request.backend.libinfo.machport),
) == .result,
);
@@ -230,7 +230,7 @@ fn addrInfoCount(addrinfo: *std.c.addrinfo) u32 {
var count: u32 = 1;
var current: ?*std.c.addrinfo = addrinfo.next;
while (current != null) : (current = current.?.next) {
- count += @boolToInt(current.?.addr != null);
+ count += @intFromBool(current.?.addr != null);
}
return count;
}
@@ -285,7 +285,7 @@ pub const GetAddrInfo = struct {
pub fn toCAres(this: GetAddrInfo) bun.c_ares.AddrInfo_hints {
var hints: bun.c_ares.AddrInfo_hints = undefined;
- @memset(std.mem.asBytes(&hints), 0, @sizeOf(bun.c_ares.AddrInfo_hints));
+ @memset(std.mem.asBytes(&hints)[0..@sizeOf(bun.c_ares.AddrInfo_hints)], 0);
hints.ai_family = this.options.family.toLibC();
hints.ai_socktype = this.options.socktype.toLibC();
@@ -320,7 +320,7 @@ pub const GetAddrInfo = struct {
}
var hints: std.c.addrinfo = undefined;
- @memset(std.mem.asBytes(&hints), 0, @sizeOf(std.c.addrinfo));
+ @memset(std.mem.asBytes(&hints)[0..@sizeOf(std.c.addrinfo)], 0);
hints.family = this.family.toLibC();
hints.socktype = this.socktype.toLibC();
@@ -793,7 +793,7 @@ pub const GetAddrInfoRequest = struct {
addr_info: ?*std.c.addrinfo,
arg: ?*anyopaque,
) callconv(.C) void {
- const this = @intToPtr(*GetAddrInfoRequest, @ptrToInt(arg));
+ const this = @ptrFromInt(*GetAddrInfoRequest, @intFromPtr(arg));
log("getAddrInfoAsyncCallback: status={d}", .{status});
if (this.backend == .libinfo) {
@@ -846,8 +846,8 @@ pub const GetAddrInfoRequest = struct {
err,
debug_timer,
});
- if (@enumToInt(err) != 0 or addrinfo == null) {
- this.* = .{ .err = @enumToInt(err) };
+ if (@intFromEnum(err) != 0 or addrinfo == null) {
+ this.* = .{ .err = @intFromEnum(err) };
return;
}
diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig
index 48bfe4218..00e34a77d 100644
--- a/src/bun.js/api/bun/socket.zig
+++ b/src/bun.js/api/bun/socket.zig
@@ -398,10 +398,10 @@ pub const Listener = struct {
pub fn deinit(this: UnixOrHost) void {
switch (this) {
.unix => |u| {
- bun.default_allocator.destroy(@intToPtr([*]u8, @ptrToInt(u.ptr)));
+ bun.default_allocator.destroy(@ptrFromInt([*]u8, @intFromPtr(u.ptr)));
},
.host => |h| {
- bun.default_allocator.destroy(@intToPtr([*]u8, @ptrToInt(h.host.ptr)));
+ bun.default_allocator.destroy(@ptrFromInt([*]u8, @intFromPtr(h.host.ptr)));
},
}
}
@@ -472,7 +472,7 @@ pub const Listener = struct {
globalObject.bunVM().eventLoop().ensureWaker();
var socket_context = uws.us_create_bun_socket_context(
- @boolToInt(ssl_enabled),
+ @intFromBool(ssl_enabled),
uws.Loop.get().?,
@sizeOf(usize),
ctx_opts,
@@ -483,7 +483,7 @@ pub const Listener = struct {
hostname_or_unix.deinit();
}
- const errno = @enumToInt(std.c.getErrno(-1));
+ const errno = @intFromEnum(std.c.getErrno(-1));
if (errno != 0) {
err.put(globalObject, ZigString.static("errno"), JSValue.jsNumber(errno));
if (bun.C.SystemErrno.init(errno)) |str| {
@@ -544,7 +544,7 @@ pub const Listener = struct {
defer bun.default_allocator.free(host);
const socket = uws.us_socket_context_listen(
- @boolToInt(ssl_enabled),
+ @intFromBool(ssl_enabled),
socket_context,
normalizeHost(@as([:0]const u8, host)),
c.port,
@@ -560,13 +560,13 @@ pub const Listener = struct {
.unix => |u| {
var host = bun.default_allocator.dupeZ(u8, u) catch unreachable;
defer bun.default_allocator.free(host);
- break :brk uws.us_socket_context_listen_unix(@boolToInt(ssl_enabled), socket_context, host, socket_flags, 8);
+ break :brk uws.us_socket_context_listen_unix(@intFromBool(ssl_enabled), socket_context, host, socket_flags, 8);
},
}
} orelse {
defer {
hostname_or_unix.deinit();
- uws.us_socket_context_free(@boolToInt(ssl_enabled), socket_context);
+ uws.us_socket_context_free(@intFromBool(ssl_enabled), socket_context);
}
const err = globalObject.createErrorInstance(
@@ -575,7 +575,7 @@ pub const Listener = struct {
bun.span(hostname_or_unix.slice()),
},
);
- const errno = @enumToInt(std.c.getErrno(-1));
+ const errno = @intFromEnum(std.c.getErrno(-1));
if (errno != 0) {
err.put(globalObject, ZigString.static("errno"), JSValue.jsNumber(errno));
if (bun.C.SystemErrno.init(errno)) |str| {
@@ -789,7 +789,7 @@ pub const Listener = struct {
globalObject.bunVM().eventLoop().ensureWaker();
- var socket_context = uws.us_create_bun_socket_context(@boolToInt(ssl_enabled), uws.Loop.get().?, @sizeOf(usize), ctx_opts).?;
+ var socket_context = uws.us_create_bun_socket_context(@intFromBool(ssl_enabled), uws.Loop.get().?, @sizeOf(usize), ctx_opts).?;
var connection: Listener.UnixOrHost = if (port) |port_| .{
.host = .{ .host = (hostname_or_unix.cloneIfNeeded(bun.default_allocator) catch unreachable).slice(), .port = port_ },
} else .{
diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig
index 832afac78..ba813c463 100644
--- a/src/bun.js/api/bun/subprocess.zig
+++ b/src/bun.js/api/bun/subprocess.zig
@@ -1011,7 +1011,7 @@ pub const Subprocess = struct {
if (signal.name()) |name|
return JSC.ZigString.init(name).toValueGC(global)
else
- return JSC.JSValue.jsNumber(@enumToInt(signal));
+ return JSC.JSValue.jsNumber(@intFromEnum(signal));
}
return JSC.JSValue.jsNull();
@@ -1535,9 +1535,9 @@ pub const Subprocess = struct {
}
if (std.os.W.IFSIGNALED(result.status)) {
- this.signal_code = @intToEnum(SignalCode, @truncate(u8, std.os.W.TERMSIG(result.status)));
+ this.signal_code = @enumFromInt(SignalCode, @truncate(u8, std.os.W.TERMSIG(result.status)));
} else if (std.os.W.IFSTOPPED(result.status)) {
- this.signal_code = @intToEnum(SignalCode, @truncate(u8, std.os.W.STOPSIG(result.status)));
+ this.signal_code = @enumFromInt(SignalCode, @truncate(u8, std.os.W.STOPSIG(result.status)));
}
if (!this.hasExited()) {
diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig
index fe2b50955..e46e054ec 100644
--- a/src/bun.js/api/ffi.zig
+++ b/src/bun.js/api/ffi.zig
@@ -137,8 +137,8 @@ pub const FFI = struct {
globalThis,
ZigString.static("ptr"),
ZigString.static("ctx"),
- JSC.JSValue.fromPtrAddress(@ptrToInt(function_.step.compiled.ptr)),
- JSC.JSValue.fromPtrAddress(@ptrToInt(function_)),
+ JSC.JSValue.fromPtrAddress(@intFromPtr(function_.step.compiled.ptr)),
+ JSC.JSValue.fromPtrAddress(@intFromPtr(function_)),
);
},
}
@@ -523,7 +523,7 @@ pub const FFI = struct {
const int = val.to(i32);
switch (int) {
0...ABIType.max => {
- abi_types.appendAssumeCapacity(@intToEnum(ABIType, int));
+ abi_types.appendAssumeCapacity(@enumFromInt(ABIType, int));
continue;
},
else => {
@@ -560,7 +560,7 @@ pub const FFI = struct {
const int = ret_value.toInt32();
switch (int) {
0...ABIType.max => {
- return_type = @intToEnum(ABIType, int);
+ return_type = @enumFromInt(ABIType, 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 = @intToPtr(*anyopaque, num);
+ function.symbol_from_dynamic_library = @ptrFromInt(*anyopaque, num);
} else {
const num = ptr.toUInt64NoTruncate();
if (num > 0) {
- function.symbol_from_dynamic_library = @intToPtr(*anyopaque, num);
+ function.symbol_from_dynamic_library = @ptrFromInt(*anyopaque, num);
}
}
}
@@ -866,7 +866,7 @@ pub const FFI = struct {
c: u8,
byte_count: usize,
) callconv(.C) void {
- @memset(dest, c, byte_count);
+ @memset(dest[0..byte_count], c);
}
noinline fn memcpy(
@@ -874,7 +874,7 @@ pub const FFI = struct {
noalias source: [*]const u8,
byte_count: usize,
) callconv(.C) void {
- @memcpy(dest, source, byte_count);
+ @memcpy(dest[0..byte_count], source[0..byte_count]);
}
pub fn define(state: *TCC.TCCState) void {
@@ -1205,7 +1205,7 @@ pub const FFI = struct {
writer: anytype,
) !void {
{
- const ptr = @ptrToInt(globalObject);
+ const ptr = @intFromPtr(globalObject);
const fmt = bun.fmt.hexIntUpper(ptr);
try writer.print("#define JS_GLOBAL_OBJECT (void*)0x{any}ULL\n", .{fmt});
}
@@ -1290,7 +1290,7 @@ pub const FFI = struct {
var inner_buf: []u8 = &.{};
{
- const ptr = @ptrToInt(context_ptr);
+ const ptr = @intFromPtr(context_ptr);
const fmt = bun.fmt.hexIntUpper(ptr);
if (this.arg_types.items.len > 0) {
@@ -1355,7 +1355,7 @@ pub const FFI = struct {
function = 17,
- pub const max = @enumToInt(ABIType.function);
+ pub const max = @intFromEnum(ABIType.function);
/// Types that we can directly pass through as an `int64_t`
pub fn needsACastInC(this: ABIType) bool {
@@ -1414,11 +1414,11 @@ pub const FFI = struct {
// these are not all valid identifiers
try writer.writeAll(self.name);
try writer.writeAll("']:");
- try std.fmt.formatInt(@enumToInt(self.entry), 10, .lower, .{}, writer);
+ try std.fmt.formatInt(@intFromEnum(self.entry), 10, .lower, .{}, writer);
try writer.writeAll(",'");
- try std.fmt.formatInt(@enumToInt(self.entry), 10, .lower, .{}, writer);
+ try std.fmt.formatInt(@intFromEnum(self.entry), 10, .lower, .{}, writer);
try writer.writeAll("':");
- try std.fmt.formatInt(@enumToInt(self.entry), 10, .lower, .{}, writer);
+ try std.fmt.formatInt(@intFromEnum(self.entry), 10, .lower, .{}, writer);
}
};
pub const map_to_js_object = brk: {
@@ -1426,7 +1426,7 @@ pub const FFI = struct {
for (map, 0..) |item, i| {
var fmt = EnumMapFormatter{ .name = item.@"0", .entry = item.@"1" };
count += std.fmt.count("{}", .{fmt});
- count += @boolToInt(i > 0);
+ count += @intFromBool(i > 0);
}
var buf: [count]u8 = undefined;
diff --git a/src/bun.js/api/html_rewriter.zig b/src/bun.js/api/html_rewriter.zig
index bfbdb9a37..93a41b095 100644
--- a/src/bun.js/api/html_rewriter.zig
+++ b/src/bun.js/api/html_rewriter.zig
@@ -472,13 +472,13 @@ pub const HTMLRewriter = struct {
pub fn onFinishedLoading(sink: *BufferOutputSink, bytes: JSC.WebCore.Blob.Store.ReadFile.ResultType) void {
switch (bytes) {
.err => |err| {
- if (sink.response.body.value == .Locked and @ptrToInt(sink.response.body.value.Locked.task) == @ptrToInt(sink) and
+ if (sink.response.body.value == .Locked and @intFromPtr(sink.response.body.value.Locked.task) == @intFromPtr(sink) and
sink.response.body.value.Locked.promise == null)
{
sink.response.body.value = .{ .Empty = {} };
// is there a pending promise?
// we will need to reject it
- } else if (sink.response.body.value == .Locked and @ptrToInt(sink.response.body.value.Locked.task) == @ptrToInt(sink) and
+ } else if (sink.response.body.value == .Locked and @intFromPtr(sink.response.body.value.Locked.task) == @intFromPtr(sink) and
sink.response.body.value.Locked.promise != null)
{
sink.response.body.value.Locked.onReceiveValue = null;
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 37bc601a5..a56ff971f 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -168,7 +168,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));
+ @memset(@ptrCast([*]u8, &ctx_opts)[0..@sizeOf(uws.us_bun_socket_context_options_t)], 0);
if (this_) |ssl_config| {
if (ssl_config.key_file_name != null)
@@ -181,7 +181,7 @@ pub const ServerConfig = struct {
ctx_opts.dh_params_file_name = ssl_config.dh_params_file_name;
if (ssl_config.passphrase != null)
ctx_opts.passphrase = ssl_config.passphrase;
- ctx_opts.ssl_prefer_low_memory_usage = @boolToInt(ssl_config.low_memory_mode);
+ ctx_opts.ssl_prefer_low_memory_usage = @intFromBool(ssl_config.low_memory_mode);
if (ssl_config.key) |key| {
ctx_opts.key = key.ptr;
@@ -1240,7 +1240,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, @errorToInt(err)),
+ .code = @truncate(u16, @intFromError(err)),
.name = @errorName(err),
.exceptions = exceptions,
.build = log.toAPI(allocator) catch unreachable,
@@ -1790,7 +1790,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, @enumToInt(std.os.E.INVAL)),
+ .errno = @intCast(JSC.Node.Syscall.Error.Int, @intFromEnum(std.os.E.INVAL)),
.syscall = .sendfile,
};
var sys = err.withPathLike(file.pathlike).toSystemError();
@@ -1809,7 +1809,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, @enumToInt(std.os.E.INVAL)),
+ .errno = @intCast(JSC.Node.Syscall.Error.Int, @intFromEnum(std.os.E.INVAL)),
.syscall = .sendfile,
};
var sys = err.withPathLike(file.pathlike).toSystemError();
@@ -2113,7 +2113,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
const streamLog = Output.scoped(.ReadableStream, false);
pub fn didUpgradeWebSocket(this: *RequestContext) bool {
- return @ptrToInt(this.upgrade_context) == std.math.maxInt(usize);
+ return @intFromPtr(this.upgrade_context) == std.math.maxInt(usize);
}
pub fn onResponse(
@@ -2874,7 +2874,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
const prev_len = bytes.items.len;
bytes.items.len = total;
var slice = bytes.items[prev_len..];
- @memcpy(slice.ptr, chunk.ptr, chunk.len);
+ @memcpy(slice[0..chunk.len], chunk);
body.value = .{
.InternalBlob = .{
.bytes = bytes.toManaged(this.allocator),
@@ -3200,7 +3200,7 @@ pub const WebSocketServer = struct {
globalObject.throwInvalidArguments("websocket expects maxPayloadLength to be an integer", .{});
return null;
}
- server.maxPayloadLength = @intCast(u32, @truncate(i33, @max(value.toInt64(), 0)));
+ server.maxPayloadLength = @intCast(u32, @max(value.toInt64(), 0));
}
}
if (object.get(globalObject, "idleTimeout")) |value| {
@@ -3220,7 +3220,7 @@ pub const WebSocketServer = struct {
return null;
}
- server.backpressureLimit = @intCast(u32, @truncate(i33, @max(value.toInt64(), 0)));
+ server.backpressureLimit = @intCast(u32, @max(value.toInt64(), 0));
}
}
// if (object.get(globalObject, "sendPings")) |value| {
@@ -3366,7 +3366,7 @@ pub const ServerWebSocket = struct {
opcode: uws.Opcode,
) void {
log("onMessage({d}): {s}", .{
- @enumToInt(opcode),
+ @intFromEnum(opcode),
message,
});
const onMessageHandler = this.handler.onMessage;
@@ -4436,7 +4436,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, @boolToInt(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))) * @intCast(i32, @truncate(u31, buffer.len)),
);
}
@@ -4451,7 +4451,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, @boolToInt(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))) * @intCast(i32, @truncate(u31, buffer.len)),
);
}
@@ -4488,7 +4488,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
return JSC.jsBoolean(false);
}
- if (upgrader.upgrade_context == null or @ptrToInt(upgrader.upgrade_context) == std.math.maxInt(usize)) {
+ if (upgrader.upgrade_context == null or @intFromPtr(upgrader.upgrade_context) == std.math.maxInt(usize)) {
return JSC.jsBoolean(false);
}
const resp = upgrader.resp.?;
@@ -4582,7 +4582,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 = @intToPtr(*uws.uws_socket_context_s, std.math.maxInt(usize));
+ upgrader.upgrade_context = @ptrFromInt(*uws.uws_socket_context_s, std.math.maxInt(usize));
request.upgrader = null;
resp.clearAborted();
@@ -4947,7 +4947,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
if (reason.len == 0) {
break;
}
- @memcpy(output_buf[written..].ptr, reason.ptr, reason.len);
+ @memcpy(output_buf[written..][0..reason.len], reason);
written += reason.len;
}
@@ -4958,7 +4958,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
if (reason.len > 0) {
output_buf[written..][0.." via ".len].* = " via ".*;
written += " via ".len;
- @memcpy(output_buf[written..].ptr, reason.ptr, reason.len);
+ @memcpy(output_buf[written..][0..reason.len], reason);
written += reason.len;
}
}
@@ -4970,7 +4970,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
if (reason.len > 0) {
output_buf[written..][0] = ' ';
written += 1;
- @memcpy(output_buf[written..].ptr, reason.ptr, reason.len);
+ @memcpy(output_buf[written..][0..reason.len], reason);
written += reason.len;
}
}
diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig
index 038f7f38b..4a1249b5d 100644
--- a/src/bun.js/base.zig
+++ b/src/bun.js/base.zig
@@ -1291,23 +1291,27 @@ pub fn NewClassWithInstanceType(
const static_properties: [property_names.len + 1]js.JSStaticValue = brk: {
var props: [property_names.len + 1]js.JSStaticValue = undefined;
- std.mem.set(
- js.JSStaticValue,
+ @memset(
&props,
js.JSStaticValue{
- .name = @intToPtr([*c]const u8, 0),
+ .name = @ptrFromInt([*c]const u8, 0),
.getProperty = null,
.setProperty = null,
.attributes = js.JSPropertyAttributes.kJSPropertyAttributeNone,
},
);
+ if (property_name_literals.len > 0 and @TypeOf(property_name_literals[0]) == [:0]const u8) {
+ @compileError("@typeInfo() struct field names are null-terminated");
+ }
for (property_name_literals, 0..) |lit, i| {
props[i] = brk2: {
var static_prop = JSC.C.JSStaticValue{
- .name = lit.ptr[0..lit.len :0],
+ // TODO: update when @typeInfo struct field names are sentinel terminated
+ // https://github.com/ziglang/zig/issues/16072
+ .name = lit ++ .{0},
.getProperty = null,
.setProperty = null,
- .attributes = @intToEnum(js.JSPropertyAttributes, 0),
+ .attributes = @enumFromInt(js.JSPropertyAttributes, 0),
};
static_prop.getProperty = StaticProperty(i).getter;
@@ -1396,14 +1400,14 @@ pub fn NewClassWithInstanceType(
const ctxfn = CtxField.rfn;
const Func: std.builtin.Type.Fn = @typeInfo(@TypeOf(if (@typeInfo(@TypeOf(ctxfn)) == .Pointer) ctxfn.* else ctxfn)).Fn;
- var attributes: c_uint = @enumToInt(js.JSPropertyAttributes.kJSPropertyAttributeNone);
+ var attributes: c_uint = @intFromEnum(js.JSPropertyAttributes.kJSPropertyAttributeNone);
if (comptime is_read_only or hasReadOnly(@TypeOf(CtxField))) {
- attributes |= @enumToInt(js.JSPropertyAttributes.kJSPropertyAttributeReadOnly);
+ attributes |= @intFromEnum(js.JSPropertyAttributes.kJSPropertyAttributeReadOnly);
}
if (comptime hasEnumerable(@TypeOf(CtxField)) and !CtxField.enumerable) {
- attributes |= @enumToInt(js.JSPropertyAttributes.kJSPropertyAttributeDontEnum);
+ attributes |= @intFromEnum(js.JSPropertyAttributes.kJSPropertyAttributeDontEnum);
}
const PointerType = comptime brk: {
@@ -1419,7 +1423,7 @@ pub fn NewClassWithInstanceType(
PointerType,
if (@typeInfo(@TypeOf(ctxfn)) == .Pointer) ctxfn.* else ctxfn,
).rfn,
- .attributes = @intToEnum(js.JSPropertyAttributes, attributes),
+ .attributes = @enumFromInt(js.JSPropertyAttributes, attributes),
};
count += 1;
@@ -1438,12 +1442,12 @@ pub fn NewClassWithInstanceType(
def.hasInstance = &staticFunctions.hasInstance;
} else {
const attributes: js.JSPropertyAttributes = brk: {
- var base = @enumToInt(js.JSPropertyAttributes.kJSPropertyAttributeNone);
+ var base = @intFromEnum(js.JSPropertyAttributes.kJSPropertyAttributeNone);
if (is_read_only)
- base |= @enumToInt(js.JSPropertyAttributes.kJSPropertyAttributeReadOnly);
+ base |= @intFromEnum(js.JSPropertyAttributes.kJSPropertyAttributeReadOnly);
- break :brk @intToEnum(js.JSPropertyAttributes, base);
+ break :brk @enumFromInt(js.JSPropertyAttributes, base);
};
__static_functions[count] = js.JSStaticFunction{
@@ -1834,7 +1838,7 @@ pub const ArrayBuffer = extern struct {
this.ptr,
this.byte_len,
MarkedArrayBuffer_deallocator,
- @intToPtr(*anyopaque, @ptrToInt(&bun.default_allocator)),
+ @ptrFromInt(*anyopaque, @intFromPtr(&bun.default_allocator)),
exception,
));
}
@@ -1845,7 +1849,7 @@ pub const ArrayBuffer = extern struct {
this.ptr,
this.byte_len,
MarkedArrayBuffer_deallocator,
- @intToPtr(*anyopaque, @ptrToInt(&bun.default_allocator)),
+ @ptrFromInt(*anyopaque, @intFromPtr(&bun.default_allocator)),
exception,
));
}
@@ -2068,7 +2072,7 @@ pub const RefString = struct {
pub const Callback = fn (ctx: *anyopaque, str: *RefString) void;
pub fn computeHash(input: []const u8) u32 {
- return std.hash.XxHash32.hash(input);
+ return std.hash.XxHash32.hash(0, input);
}
pub fn slice(this: *RefString) []const u8 {
@@ -3355,7 +3359,7 @@ pub const FilePoll = struct {
const DNSResolver = JSC.DNS.DNSResolver;
const GetAddrInfoRequest = JSC.DNS.GetAddrInfoRequest;
const Deactivated = opaque {
- pub var owner: Owner = Owner.init(@intToPtr(*Deactivated, @as(usize, 0xDEADBEEF)));
+ pub var owner: Owner = Owner.init(@ptrFromInt(*Deactivated, @as(usize, 0xDEADBEEF)));
};
pub const Owner = bun.TaggedPointerUnion(.{
@@ -3610,7 +3614,7 @@ pub const FilePoll = struct {
return;
this.flags.insert(.disable);
- vm.uws_event_loop.?.active -= @as(u32, @boolToInt(this.flags.contains(.has_incremented_poll_count)));
+ vm.uws_event_loop.?.active -= @as(u32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
}
pub fn enableKeepingProcessAlive(this: *FilePoll, vm: *JSC.VirtualMachine) void {
@@ -3618,7 +3622,7 @@ pub const FilePoll = struct {
return;
this.flags.remove(.disable);
- vm.uws_event_loop.?.active += @as(u32, @boolToInt(this.flags.contains(.has_incremented_poll_count)));
+ vm.uws_event_loop.?.active += @as(u32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
}
pub fn canActivate(this: *const FilePoll) bool {
@@ -3628,16 +3632,16 @@ pub const FilePoll = struct {
/// Only intended to be used from EventLoop.Pollable
pub fn deactivate(this: *FilePoll, loop: *uws.Loop) void {
std.debug.assert(this.flags.contains(.has_incremented_poll_count));
- loop.num_polls -= @as(i32, @boolToInt(this.flags.contains(.has_incremented_poll_count)));
- loop.active -|= @as(u32, @boolToInt(!this.flags.contains(.disable) and this.flags.contains(.has_incremented_poll_count)));
+ loop.num_polls -= @as(i32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
+ loop.active -|= @as(u32, @intFromBool(!this.flags.contains(.disable) and this.flags.contains(.has_incremented_poll_count)));
this.flags.remove(.has_incremented_poll_count);
}
/// Only intended to be used from EventLoop.Pollable
pub fn activate(this: *FilePoll, loop: *uws.Loop) void {
- loop.num_polls += @as(i32, @boolToInt(!this.flags.contains(.has_incremented_poll_count)));
- loop.active += @as(u32, @boolToInt(!this.flags.contains(.disable) and !this.flags.contains(.has_incremented_poll_count)));
+ loop.num_polls += @as(i32, @intFromBool(!this.flags.contains(.has_incremented_poll_count)));
+ loop.active += @as(u32, @intFromBool(!this.flags.contains(.disable) and !this.flags.contains(.has_incremented_poll_count)));
this.flags.insert(.has_incremented_poll_count);
}
@@ -3738,7 +3742,7 @@ pub const FilePoll = struct {
else => unreachable,
};
- var event = linux.epoll_event{ .events = flags, .data = .{ .u64 = @ptrToInt(Pollable.init(this).ptr()) } };
+ var event = linux.epoll_event{ .events = flags, .data = .{ .u64 = @intFromPtr(Pollable.init(this).ptr()) } };
const ctl = linux.epoll_ctl(
watcher_fd,
@@ -3759,7 +3763,7 @@ pub const FilePoll = struct {
.filter = std.os.system.EVFILT_READ,
.data = 0,
.fflags = 0,
- .udata = @ptrToInt(Pollable.init(this).ptr()),
+ .udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
@@ -3768,7 +3772,7 @@ pub const FilePoll = struct {
.filter = std.os.system.EVFILT_WRITE,
.data = 0,
.fflags = 0,
- .udata = @ptrToInt(Pollable.init(this).ptr()),
+ .udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
@@ -3777,7 +3781,7 @@ pub const FilePoll = struct {
.filter = std.os.system.EVFILT_PROC,
.data = 0,
.fflags = std.c.NOTE_EXIT,
- .udata = @ptrToInt(Pollable.init(this).ptr()),
+ .udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
@@ -3786,7 +3790,7 @@ pub const FilePoll = struct {
.filter = std.os.system.EVFILT_MACHPORT,
.data = 0,
.fflags = 0,
- .udata = @ptrToInt(Pollable.init(this).ptr()),
+ .udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
@@ -3911,7 +3915,7 @@ pub const FilePoll = struct {
.filter = std.os.system.EVFILT_READ,
.data = 0,
.fflags = 0,
- .udata = @ptrToInt(Pollable.init(this).ptr()),
+ .udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
@@ -3920,7 +3924,7 @@ pub const FilePoll = struct {
.filter = std.os.system.EVFILT_MACHPORT,
.data = 0,
.fflags = 0,
- .udata = @ptrToInt(Pollable.init(this).ptr()),
+ .udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
@@ -3929,7 +3933,7 @@ pub const FilePoll = struct {
.filter = std.os.system.EVFILT_WRITE,
.data = 0,
.fflags = 0,
- .udata = @ptrToInt(Pollable.init(this).ptr()),
+ .udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
@@ -3938,7 +3942,7 @@ pub const FilePoll = struct {
.filter = std.os.system.EVFILT_PROC,
.data = 0,
.fflags = std.c.NOTE_EXIT,
- .udata = @ptrToInt(Pollable.init(this).ptr()),
+ .udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
@@ -3973,7 +3977,7 @@ pub const FilePoll = struct {
const errno = std.c.getErrno(rc);
switch (rc) {
- std.math.minInt(@TypeOf(rc))...-1 => return JSC.Maybe(void).errnoSys(@enumToInt(errno), .kevent).?,
+ std.math.minInt(@TypeOf(rc))...-1 => return JSC.Maybe(void).errnoSys(@intFromEnum(errno), .kevent).?,
else => {},
}
} else {
diff --git a/src/bun.js/bindings/FFI.zig b/src/bun.js/bindings/FFI.zig
index 087d8308c..fde4a8d30 100644
--- a/src/bun.js/bindings/FFI.zig
+++ b/src/bun.js/bindings/FFI.zig
@@ -42,7 +42,7 @@ pub inline fn JSVALUE_TO_UINT64(arg_value: EncodedJSValue) u64 {
return @bitCast(u64, @as(c_longlong, JSVALUE_TO_INT32(value)));
}
if (JSVALUE_IS_NUMBER(value)) {
- return @floatToInt(u64, JSVALUE_TO_DOUBLE(value));
+ return @intFromFloat(u64, JSVALUE_TO_DOUBLE(value));
}
return JSVALUE_TO_UINT64_SLOW(value);
}
@@ -52,7 +52,7 @@ pub inline fn JSVALUE_TO_INT64(arg_value: EncodedJSValue) i64 {
return @bitCast(i64, @as(c_longlong, JSVALUE_TO_INT32(value)));
}
if (JSVALUE_IS_NUMBER(value)) {
- return @floatToInt(i64, JSVALUE_TO_DOUBLE(value));
+ return @intFromFloat(i64, JSVALUE_TO_DOUBLE(value));
}
return JSVALUE_TO_INT64_SLOW(value);
}
@@ -67,7 +67,7 @@ pub inline fn UINT64_TO_JSVALUE(arg_globalObject: ?*anyopaque, arg_val: u64) Enc
return INT32_TO_JSVALUE(@bitCast(i32, @truncate(c_uint, val)));
}
if (val < @bitCast(c_ulonglong, @as(c_longlong, @as(c_long, 9007199254740991)))) {
- return DOUBLE_TO_JSVALUE(@intToFloat(f64, val));
+ return DOUBLE_TO_JSVALUE(@floatFromInt(f64, val));
}
return UINT64_TO_JSVALUE_SLOW(@ptrCast(*@import("./bindings.zig").JSGlobalObject, globalObject.?), val).asEncoded();
}
@@ -78,7 +78,7 @@ pub inline fn INT64_TO_JSVALUE(arg_globalObject: ?*anyopaque, arg_val: i64) Enco
return INT32_TO_JSVALUE(@bitCast(i32, @truncate(c_int, val)));
}
if ((val >= @bitCast(c_longlong, @as(c_longlong, -@as(c_long, 9007199254740991)))) and (val <= @bitCast(c_longlong, @as(c_longlong, @as(c_long, 9007199254740991))))) {
- return DOUBLE_TO_JSVALUE(@intToFloat(f64, val));
+ return DOUBLE_TO_JSVALUE(@floatFromInt(f64, val));
}
return INT64_TO_JSVALUE_SLOW(@ptrCast(*@import("./bindings.zig").JSGlobalObject, globalObject.?), val).asEncoded();
}
@@ -97,18 +97,18 @@ pub inline fn FLOAT_TO_JSVALUE(arg_val: f32) EncodedJSValue {
pub inline fn BOOLEAN_TO_JSVALUE(arg_val: @"bool") EncodedJSValue {
var val = arg_val;
var res: EncodedJSValue = undefined;
- res.asInt64 = @bitCast(i64, @as(c_longlong, if (@as(c_int, @boolToInt(val)) != 0) (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 1) else (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 0)));
+ res.asInt64 = @bitCast(i64, @as(c_longlong, if (@as(c_int, @intFromBool(val)) != 0) (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 1) else (@as(c_int, 2) | @as(c_int, 4)) | @as(c_int, 0)));
return res;
}
pub inline fn PTR_TO_JSVALUE(arg_ptr: ?*anyopaque) EncodedJSValue {
var ptr = arg_ptr;
var val: EncodedJSValue = undefined;
- val.asInt64 = @intCast(i64, @ptrToInt(ptr)) + (@as(c_longlong, 1) << @intCast(@import("std").math.Log2Int(c_longlong), 49));
+ val.asInt64 = @intCast(i64, @intFromPtr(ptr)) + (@as(c_longlong, 1) << @intCast(@import("std").math.Log2Int(c_longlong), 49));
return val;
}
pub inline fn JSVALUE_TO_PTR(arg_val: EncodedJSValue) ?*anyopaque {
var val = arg_val;
- return @intToPtr(?*anyopaque, val.asInt64 - (@as(c_longlong, 1) << @intCast(@import("std").math.Log2Int(c_longlong), 49)));
+ return @ptrFromInt(?*anyopaque, val.asInt64 - (@as(c_longlong, 1) << @intCast(@import("std").math.Log2Int(c_longlong), 49)));
}
pub inline fn JSVALUE_TO_INT32(arg_val: EncodedJSValue) i32 {
var val = arg_val;
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index 35c9d26fa..581fc6f85 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -370,11 +370,11 @@ pub const ZigString = extern struct {
}
pub fn markStatic(this: *ZigString) void {
- this.ptr = @intToPtr([*]const u8, @ptrToInt(this.ptr) | (1 << 60));
+ this.ptr = @ptrFromInt([*]const u8, @intFromPtr(this.ptr) | (1 << 60));
}
pub fn isStatic(this: *const ZigString) bool {
- return @ptrToInt(this.ptr) & (1 << 60) != 0;
+ return @intFromPtr(this.ptr) & (1 << 60) != 0;
}
pub const Slice = struct {
@@ -483,7 +483,7 @@ pub const ZigString = extern struct {
}
pub fn mut(this: Slice) []u8 {
- return @intToPtr([*]u8, @ptrToInt(this.ptr))[0..this.len];
+ return @ptrFromInt([*]u8, @intFromPtr(this.ptr))[0..this.len];
}
/// Does nothing if the slice is not allocated
@@ -504,7 +504,7 @@ pub const ZigString = extern struct {
pub const namespace = "";
pub inline fn is16Bit(this: *const ZigString) bool {
- return (@ptrToInt(this._unsafe_ptr_do_not_use) & (1 << 63)) != 0;
+ return (@intFromPtr(this._unsafe_ptr_do_not_use) & (1 << 63)) != 0;
}
pub inline fn utf16Slice(this: *const ZigString) []align(1) const u16 {
@@ -539,7 +539,7 @@ pub const ZigString = extern struct {
}
pub fn sortDesc(slice_: []ZigString) void {
- std.sort.sort(ZigString, slice_, {}, cmpDesc);
+ std.sort.block(ZigString, slice_, {}, cmpDesc);
}
pub fn cmpDesc(_: void, a: ZigString, b: ZigString) bool {
@@ -547,7 +547,7 @@ pub const ZigString = extern struct {
}
pub fn sortAsc(slice_: []ZigString) void {
- std.sort.sort(ZigString, slice_, {}, cmpAsc);
+ std.sort.block(ZigString, slice_, {}, cmpAsc);
}
pub fn cmpAsc(_: void, a: ZigString, b: ZigString) bool {
@@ -641,15 +641,15 @@ pub const ZigString = extern struct {
}
pub fn isUTF8(this: ZigString) bool {
- return (@ptrToInt(this._unsafe_ptr_do_not_use) & (1 << 61)) != 0;
+ return (@intFromPtr(this._unsafe_ptr_do_not_use) & (1 << 61)) != 0;
}
pub fn markUTF8(this: *ZigString) void {
- this._unsafe_ptr_do_not_use = @intToPtr([*]const u8, @ptrToInt(this._unsafe_ptr_do_not_use) | (1 << 61));
+ this._unsafe_ptr_do_not_use = @ptrFromInt([*]const u8, @intFromPtr(this._unsafe_ptr_do_not_use) | (1 << 61));
}
pub fn markUTF16(this: *ZigString) void {
- this._unsafe_ptr_do_not_use = @intToPtr([*]const u8, @ptrToInt(this._unsafe_ptr_do_not_use) | (1 << 63));
+ this._unsafe_ptr_do_not_use = @ptrFromInt([*]const u8, @intFromPtr(this._unsafe_ptr_do_not_use) | (1 << 63));
}
pub fn setOutputEncoding(this: *ZigString) void {
@@ -658,7 +658,7 @@ pub const ZigString = extern struct {
}
pub inline fn isGloballyAllocated(this: ZigString) bool {
- return (@ptrToInt(this._unsafe_ptr_do_not_use) & (1 << 62)) != 0;
+ return (@intFromPtr(this._unsafe_ptr_do_not_use) & (1 << 62)) != 0;
}
pub inline fn deinitGlobal(this: ZigString) void {
@@ -668,7 +668,7 @@ pub const ZigString = extern struct {
pub const mark = markGlobal;
pub inline fn markGlobal(this: *ZigString) void {
- this._unsafe_ptr_do_not_use = @intToPtr([*]const u8, @ptrToInt(this._unsafe_ptr_do_not_use) | (1 << 62));
+ this._unsafe_ptr_do_not_use = @ptrFromInt([*]const u8, @intFromPtr(this._unsafe_ptr_do_not_use) | (1 << 62));
}
pub fn format(self: ZigString, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
@@ -694,7 +694,7 @@ pub const ZigString = extern struct {
inline fn untagged(ptr: [*]const u8) [*]const u8 {
// this can be null ptr, so long as it's also a 0 length string
@setRuntimeSafety(false);
- return @intToPtr([*]const u8, @truncate(u53, @ptrToInt(ptr)));
+ return @ptrFromInt([*]const u8, @truncate(u53, @intFromPtr(ptr)));
}
pub fn slice(this: *const ZigString) []const u8 {
@@ -1303,7 +1303,7 @@ pub const FetchHeaders = opaque {
this: *FetchHeaders,
name_: HTTPHeaderName,
) bool {
- return fastHas_(this, @enumToInt(name_));
+ return fastHas_(this, @intFromEnum(name_));
}
pub fn fastGet(
@@ -1311,7 +1311,7 @@ pub const FetchHeaders = opaque {
name_: HTTPHeaderName,
) ?ZigString {
var str = ZigString.init("");
- fastGet_(this, @enumToInt(name_), &str);
+ fastGet_(this, @intFromEnum(name_), &str);
if (str.len == 0) {
return null;
}
@@ -1441,7 +1441,7 @@ pub const FetchHeaders = opaque {
this: *FetchHeaders,
header: HTTPHeaderName,
) void {
- return fastRemove_(this, @enumToInt(header));
+ return fastRemove_(this, @intFromEnum(header));
}
pub fn fastRemove_(
@@ -1611,11 +1611,11 @@ pub const Sizes = @import("../bindings/sizes.zig");
pub const JSUint8Array = opaque {
pub const name = "Uint8Array_alias";
pub fn ptr(this: *JSUint8Array) [*]u8 {
- return @intToPtr(*[*]u8, @ptrToInt(this) + Sizes.Bun_FFI_PointerOffsetToTypedArrayVector).*;
+ return @ptrFromInt(*[*]u8, @intFromPtr(this) + Sizes.Bun_FFI_PointerOffsetToTypedArrayVector).*;
}
pub fn len(this: *JSUint8Array) usize {
- return @intToPtr(*usize, @ptrToInt(this) + Sizes.Bun_FFI_PointerOffsetToTypedArrayLength).*;
+ return @ptrFromInt(*usize, @intFromPtr(this) + Sizes.Bun_FFI_PointerOffsetToTypedArrayLength).*;
}
pub fn slice(this: *JSUint8Array) []u8 {
@@ -3156,7 +3156,7 @@ pub const JSValue = enum(JSValueReprInt) {
pub fn isObject(this: JSType) bool {
// inline constexpr bool isObjectType(JSType type) { return type >= ObjectType; }
- return @enumToInt(this) >= @enumToInt(JSType.Object);
+ return @intFromEnum(this) >= @intFromEnum(JSType.Object);
}
pub fn isFunction(this: JSType) bool {
@@ -3311,7 +3311,7 @@ pub const JSValue = enum(JSValueReprInt) {
};
pub inline fn cast(ptr: anytype) JSValue {
- return @intToEnum(JSValue, @bitCast(i64, @ptrToInt(ptr)));
+ return @enumFromInt(JSValue, @bitCast(i64, @intFromPtr(ptr)));
}
pub fn coerceToInt32(this: JSValue, globalThis: *JSC.JSGlobalObject) i32 {
@@ -3808,7 +3808,7 @@ pub const JSValue = enum(JSValueReprInt) {
return jsNumberFromInt32(@intCast(i32, i));
}
- return jsNumberFromDouble(@intToFloat(f64, @truncate(i52, i)));
+ return jsNumberFromDouble(@floatFromInt(f64, @truncate(i52, i)));
}
pub inline fn toJS(this: JSValue, _: *const JSGlobalObject) JSValue {
@@ -3820,7 +3820,7 @@ pub const JSValue = enum(JSValueReprInt) {
return jsNumberFromInt32(@intCast(i32, i));
}
- return jsNumberFromDouble(@intToFloat(f64, @intCast(i52, @truncate(u51, i))));
+ return jsNumberFromDouble(@floatFromInt(f64, @intCast(i52, @truncate(u51, i))));
}
pub fn coerceDoubleTruncatingIntoInt64(this: JSValue) i64 {
@@ -3834,7 +3834,7 @@ pub const JSValue = enum(JSValueReprInt) {
return if (double_value < 0) @as(i64, std.math.minInt(i64)) else @as(i64, std.math.maxInt(i64));
}
- return @floatToInt(
+ return @intFromFloat(
i64,
double_value,
);
@@ -3871,26 +3871,26 @@ pub const JSValue = enum(JSValueReprInt) {
}
pub inline fn isUndefined(this: JSValue) bool {
- return @enumToInt(this) == 0xa;
+ return @intFromEnum(this) == 0xa;
}
pub inline fn isNull(this: JSValue) bool {
- return @enumToInt(this) == 0x2;
+ return @intFromEnum(this) == 0x2;
}
pub inline fn isEmptyOrUndefinedOrNull(this: JSValue) bool {
- return switch (@enumToInt(this)) {
+ return switch (@intFromEnum(this)) {
0, 0xa, 0x2 => true,
else => false,
};
}
pub fn isUndefinedOrNull(this: JSValue) bool {
- return switch (@enumToInt(this)) {
+ return switch (@intFromEnum(this)) {
0xa, 0x2 => true,
else => false,
};
}
/// Empty as in "JSValue {}" rather than an empty string
pub inline fn isEmpty(this: JSValue) bool {
- return switch (@enumToInt(this)) {
+ return switch (@intFromEnum(this)) {
0 => true,
else => false,
};
@@ -4016,7 +4016,7 @@ pub const JSValue = enum(JSValueReprInt) {
pub inline fn isCell(this: JSValue) bool {
return switch (this) {
.zero, .undefined, .null, .true, .false => false,
- else => (@bitCast(u64, @enumToInt(this)) & FFI.NotCellMask) == 0,
+ else => (@bitCast(u64, @intFromEnum(this)) & FFI.NotCellMask) == 0,
};
}
@@ -4179,7 +4179,7 @@ pub const JSValue = enum(JSValueReprInt) {
// intended to be more lightweight than ZigString
pub fn fastGet(this: JSValue, global: *JSGlobalObject, builtin_name: BuiltinName) ?JSValue {
- const result = fastGet_(this, global, @enumToInt(builtin_name));
+ const result = fastGet_(this, global, @intFromEnum(builtin_name));
if (result == .zero) {
return null;
}
@@ -4188,7 +4188,7 @@ pub const JSValue = enum(JSValueReprInt) {
}
pub fn fastGetDirect(this: JSValue, global: *JSGlobalObject, builtin_name: BuiltinName) ?JSValue {
- const result = fastGetDirect_(this, global, @enumToInt(builtin_name));
+ const result = fastGetDirect_(this, global, @intFromEnum(builtin_name));
if (result == .zero) {
return null;
}
@@ -4243,7 +4243,7 @@ pub const JSValue = enum(JSValueReprInt) {
pub fn get(this: JSValue, global: *JSGlobalObject, property: []const u8) ?JSValue {
const value = getIfPropertyExistsImpl(this, global, property.ptr, @intCast(u32, property.len));
- return if (@enumToInt(value) != 0) value else return null;
+ return if (@intFromEnum(value) != 0) value else return null;
}
pub fn implementsToString(this: JSValue, global: *JSGlobalObject) bool {
@@ -4407,7 +4407,7 @@ pub const JSValue = enum(JSValueReprInt) {
/// This algorithm differs from the IsStrictlyEqual Algorithm by treating all NaN values as equivalent and by differentiating +0𝔽 from -0𝔽.
/// https://tc39.es/ecma262/#sec-samevalue
pub fn isSameValue(this: JSValue, other: JSValue, global: *JSGlobalObject) bool {
- return @enumToInt(this) == @enumToInt(other) or cppFn("isSameValue", .{ this, other, global });
+ return @intFromEnum(this) == @intFromEnum(other) or cppFn("isSameValue", .{ this, other, global });
}
pub fn deepEquals(this: JSValue, other: JSValue, global: *JSGlobalObject) bool {
@@ -4460,7 +4460,7 @@ pub const JSValue = enum(JSValueReprInt) {
/// Get the internal number of the `JSC::DateInstance` object
/// Returns NaN if the value is not a `JSC::DateInstance` (`Date` in JS)
- pub fn getUnixTimestamp(this: JSValue) f64 {
+ pub fn getUnixTimestamp(this: JSValue) f64 {
return cppFn("getUnixTimestamp", .{
this,
});
@@ -4492,7 +4492,7 @@ pub const JSValue = enum(JSValueReprInt) {
pub fn asNumber(this: JSValue) f64 {
if (this.isInt32()) {
- return @intToFloat(f64, this.asInt32());
+ return @floatFromInt(f64, this.asInt32());
}
if (isNumber(this)) {
@@ -4515,19 +4515,19 @@ pub const JSValue = enum(JSValueReprInt) {
}
pub fn asPtr(this: JSValue, comptime Pointer: type) *Pointer {
- return @intToPtr(*Pointer, this.asPtrAddress());
+ return @ptrFromInt(*Pointer, this.asPtrAddress());
}
pub fn fromPtrAddress(addr: anytype) JSValue {
- return jsNumber(@intToFloat(f64, @bitCast(usize, @as(usize, addr))));
+ return jsNumber(@floatFromInt(f64, @bitCast(usize, @as(usize, addr))));
}
pub fn asPtrAddress(this: JSValue) usize {
- return @bitCast(usize, @floatToInt(usize, this.asDouble()));
+ return @bitCast(usize, @intFromFloat(usize, this.asDouble()));
}
pub fn fromPtr(addr: anytype) JSValue {
- return fromPtrAddress(@ptrToInt(addr));
+ return fromPtrAddress(@intFromPtr(addr));
}
pub fn toBooleanSlow(this: JSValue, global: *JSGlobalObject) bool {
@@ -4552,7 +4552,7 @@ pub const JSValue = enum(JSValueReprInt) {
}
if (this.isNumber()) {
- return @truncate(i32, @floatToInt(i64, asDouble(this)));
+ return @truncate(i32, @intFromFloat(i64, asDouble(this)));
}
if (comptime bun.Environment.allow_assert) {
@@ -4591,11 +4591,11 @@ pub const JSValue = enum(JSValueReprInt) {
/// If the "length" property does not exist, this function will return 0.
pub fn getLength(this: JSValue, globalThis: *JSGlobalObject) u64 {
const len = this.getLengthIfPropertyExistsInternal(globalThis);
- if (len == std.math.f64_max) {
+ if (len == std.math.floatMax(f64)) {
return 0;
}
- return @floatToInt(u64, @max(len, 0));
+ return @intFromFloat(u64, @max(len, 0));
}
/// This function supports:
@@ -4612,11 +4612,11 @@ pub const JSValue = enum(JSValueReprInt) {
/// If the "length" property does not exist, this function will return null.
pub fn tryGetLength(this: JSValue, globalThis: *JSGlobalObject) ?f64 {
const len = this.getLengthIfPropertyExistsInternal(globalThis);
- if (len == std.math.f64_max) {
+ if (len == std.math.floatMax(f64)) {
return null;
}
- return @floatToInt(u64, @max(len, 0));
+ return @intFromFloat(u64, @max(len, 0));
}
/// Do not use this directly!
@@ -4661,15 +4661,15 @@ pub const JSValue = enum(JSValueReprInt) {
}
pub inline fn asRef(this: JSValue) C_API.JSValueRef {
- return @intToPtr(C_API.JSValueRef, @bitCast(usize, @enumToInt(this)));
+ return @ptrFromInt(C_API.JSValueRef, @bitCast(usize, @intFromEnum(this)));
}
pub inline fn c(this: C_API.JSValueRef) JSValue {
- return @intToEnum(JSValue, @bitCast(JSValue.Type, @ptrToInt(this)));
+ return @enumFromInt(JSValue, @bitCast(JSValue.Type, @intFromPtr(this)));
}
pub inline fn fromRef(this: C_API.JSValueRef) JSValue {
- return @intToEnum(JSValue, @bitCast(JSValue.Type, @ptrToInt(this)));
+ return @enumFromInt(JSValue, @bitCast(JSValue.Type, @intFromPtr(this)));
}
pub inline fn asObjectRef(this: JSValue) C_API.JSObjectRef {
@@ -4685,12 +4685,12 @@ pub const JSValue = enum(JSValueReprInt) {
}
pub inline fn asNullableVoid(this: JSValue) ?*anyopaque {
- return @intToPtr(?*anyopaque, @bitCast(usize, @enumToInt(this)));
+ return @ptrFromInt(?*anyopaque, @bitCast(usize, @intFromEnum(this)));
}
pub inline fn asVoid(this: JSValue) *anyopaque {
if (comptime bun.Environment.allow_assert) {
- if (@enumToInt(this) == 0) {
+ if (@intFromEnum(this) == 0) {
@panic("JSValue is null");
}
}
@@ -4857,7 +4857,7 @@ pub const Exception = extern struct {
pub fn create(globalObject: *JSGlobalObject, object: *JSObject, stack_capture: StackCaptureAction) *Exception {
return cppFn(
"create",
- .{ globalObject, object, @enumToInt(stack_capture) },
+ .{ globalObject, object, @intFromEnum(stack_capture) },
);
}
@@ -4893,7 +4893,7 @@ pub const VM = extern struct {
LargeHeap = 1,
};
pub fn create(heap_type: HeapType) *VM {
- return cppFn("create", .{@enumToInt(heap_type)});
+ return cppFn("create", .{@intFromEnum(heap_type)});
}
pub fn deinit(vm: *VM, global_object: *JSGlobalObject) void {
@@ -5157,16 +5157,16 @@ pub const CallFrame = opaque {
pub fn arguments(self: *const CallFrame, comptime max: usize) Arguments(max) {
const len = self.argumentsCount();
var ptr = self.argumentsPtr();
- return switch (@min(len, max)) {
+ return switch (@as(u4, @min(len, max))) {
0 => .{ .ptr = undefined, .len = 0 },
- 1 => Arguments(max).init(1, ptr),
- 2 => Arguments(max).init(@min(2, max), ptr),
- 3 => Arguments(max).init(@min(3, max), ptr),
- 4 => Arguments(max).init(@min(4, max), ptr),
- 5 => Arguments(max).init(@min(5, max), ptr),
- 6 => Arguments(max).init(@min(6, max), ptr),
- 7 => Arguments(max).init(@min(7, max), ptr),
- 8 => Arguments(max).init(@min(8, max), ptr),
+ 4 => Arguments(max).init(comptime @min(4, max), ptr),
+ 2 => Arguments(max).init(comptime @min(2, max), ptr),
+ 6 => Arguments(max).init(comptime @min(6, max), ptr),
+ 3 => Arguments(max).init(comptime @min(3, max), ptr),
+ 8 => Arguments(max).init(comptime @min(8, max), ptr),
+ 5 => Arguments(max).init(comptime @min(5, max), ptr),
+ 1 => Arguments(max).init(comptime @min(1, max), ptr),
+ 7 => Arguments(max).init(comptime @min(7, max), ptr),
else => unreachable,
};
}
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig
index 6ea1eba60..de3f819b7 100644
--- a/src/bun.js/bindings/exports.zig
+++ b/src/bun.js/bindings/exports.zig
@@ -112,11 +112,11 @@ pub const ErrorCode = enum(ErrorCodeInt) {
_,
pub inline fn from(code: anyerror) ErrorCode {
- return @intToEnum(ErrorCode, @errorToInt(code));
+ return @enumFromInt(ErrorCode, @intFromError(code));
}
- pub const ParserError = @enumToInt(ErrorCode.from(error.ParserError));
- pub const JSErrorObject = @enumToInt(ErrorCode.from(error.JSErrorObject));
+ pub const ParserError = @intFromEnum(ErrorCode.from(error.ParserError));
+ pub const JSErrorObject = @intFromEnum(ErrorCode.from(error.JSErrorObject));
pub const Type = ErrorCodeInt;
};
@@ -244,7 +244,7 @@ export fn ZigString__free(raw: [*]const u8, len: usize, allocator_: ?*anyopaque)
}
export fn ZigString__free_global(ptr: [*]const u8, len: usize) void {
- var untagged = @intToPtr(*anyopaque, @ptrToInt(ZigString.init(ptr[0..len]).slice().ptr));
+ var untagged = @ptrFromInt(*anyopaque, @intFromPtr(ZigString.init(ptr[0..len]).slice().ptr));
if (comptime Environment.allow_assert) {
std.debug.assert(Mimalloc.mi_is_in_heap_region(ptr));
}
@@ -561,7 +561,7 @@ pub const ZigStackFrame = extern struct {
frame.position.source_offset = this.position.source_offset;
// For remapped code, we add 1 to the line number
- frame.position.line = this.position.line + @as(i32, @boolToInt(this.remapped));
+ frame.position.line = this.position.line + @as(i32, @intFromBool(this.remapped));
frame.position.line_start = this.position.line_start;
frame.position.line_stop = this.position.line_stop;
@@ -569,7 +569,7 @@ pub const ZigStackFrame = extern struct {
frame.position.column_stop = this.position.column_stop;
frame.position.expression_start = this.position.expression_start;
frame.position.expression_stop = this.position.expression_stop;
- frame.scope = @intToEnum(Api.StackFrameScope, @enumToInt(this.code_type));
+ frame.scope = @enumFromInt(Api.StackFrameScope, @intFromEnum(this.code_type));
return frame;
}
@@ -775,18 +775,18 @@ pub const ZigException = extern struct {
pub const Zero: Holder = Holder{
.frames = brk: {
var _frames: [frame_count]ZigStackFrame = undefined;
- std.mem.set(ZigStackFrame, &_frames, ZigStackFrame.Zero);
+ @memset(&_frames, ZigStackFrame.Zero);
break :brk _frames;
},
.source_line_numbers = brk: {
var lines: [source_lines_count]i32 = undefined;
- std.mem.set(i32, &lines, -1);
+ @memset(&lines, -1);
break :brk lines;
},
.source_lines = brk: {
var lines: [source_lines_count]ZigString = undefined;
- std.mem.set(ZigString, &lines, ZigString.Empty);
+ @memset(&lines, ZigString.Empty);
break :brk lines;
},
.zig_exception = undefined,
@@ -800,7 +800,7 @@ pub const ZigException = extern struct {
pub fn zigException(this: *Holder) *ZigException {
if (!this.loaded) {
this.zig_exception = ZigException{
- .code = @intToEnum(JSErrorCode, 255),
+ .code = @enumFromInt(JSErrorCode, 255),
.runtime_type = JSRuntimeType.Nothing,
.name = ZigString.Empty,
.message = ZigString.Empty,
@@ -836,8 +836,8 @@ pub const ZigException = extern struct {
var is_empty = true;
var api_exception = Api.JsException{
- .runtime_type = @enumToInt(this.runtime_type),
- .code = @enumToInt(this.code),
+ .runtime_type = @intFromEnum(this.runtime_type),
+ .code = @intFromEnum(this.code),
};
if (_name.len > 0) {
@@ -1314,7 +1314,7 @@ pub const ZigConsoleClient = struct {
};
pub fn getAdvanced(value: JSValue, globalThis: *JSGlobalObject, opts: Options) Result {
- switch (@enumToInt(value)) {
+ switch (@intFromEnum(value)) {
0, 0xa => return Result{
.tag = .Undefined,
},
@@ -1878,7 +1878,7 @@ pub const ZigConsoleClient = struct {
this.map = this.map_node.?.data;
}
- var entry = this.map.getOrPut(@enumToInt(value)) catch unreachable;
+ var entry = this.map.getOrPut(@intFromEnum(value)) catch unreachable;
if (entry.found_existing) {
writer.writeAll(comptime Output.prettyFmt("<r><cyan>[Circular]<r>", enable_ansi_colors));
return;
@@ -1887,7 +1887,7 @@ pub const ZigConsoleClient = struct {
defer {
if (comptime Format.canHaveCircularReferences()) {
- _ = this.map.remove(@enumToInt(value));
+ _ = this.map.remove(@intFromEnum(value));
}
}
@@ -1959,7 +1959,7 @@ pub const ZigConsoleClient = struct {
i = -i;
}
const digits = if (i != 0)
- bun.fmt.fastDigitCount(@intCast(usize, i)) + @as(usize, @boolToInt(is_negative))
+ bun.fmt.fastDigitCount(@intCast(usize, i)) + @as(usize, @intFromBool(is_negative))
else
1;
this.addForNewLine(digits);
@@ -2559,7 +2559,7 @@ pub const ZigConsoleClient = struct {
{
this.indent += 1;
defer this.indent -|= 1;
- const count_without_children = props_iter.len - @as(usize, @boolToInt(children_prop != null));
+ const count_without_children = props_iter.len - @as(usize, @intFromBool(children_prop != null));
while (props_iter.next()) |prop| {
if (prop.eqlComptime("children"))
@@ -3002,7 +3002,7 @@ pub const ZigConsoleClient = struct {
chars: [*]const u8,
len: usize,
) callconv(.C) void {
- const id = std.hash.Wyhash.hash(0, chars[0..len]);
+ const id = bun.hash(chars[0..len]);
if (!pending_time_logs_loaded) {
pending_time_logs = PendingTimers.init(default_allocator);
pending_time_logs_loaded = true;
@@ -3026,12 +3026,12 @@ pub const ZigConsoleClient = struct {
return;
}
- const id = std.hash.Wyhash.hash(0, chars[0..len]);
+ const id = bun.hash(chars[0..len]);
var result = (pending_time_logs.fetchPut(id, null) catch null) orelse return;
var value: std.time.Timer = result.value orelse return;
// get the duration in microseconds
// then display it in milliseconds
- Output.printElapsed(@intToFloat(f64, value.read() / std.time.ns_per_us) / std.time.us_per_ms);
+ Output.printElapsed(@floatFromInt(f64, value.read() / std.time.ns_per_us) / std.time.us_per_ms);
switch (len) {
0 => Output.printErrorln("\n", .{}),
else => Output.printErrorln(" {s}", .{chars[0..len]}),
@@ -3056,11 +3056,11 @@ pub const ZigConsoleClient = struct {
return;
}
- const id = std.hash.Wyhash.hash(0, chars[0..len]);
+ const id = bun.hash(chars[0..len]);
var value: std.time.Timer = (pending_time_logs.get(id) orelse return) orelse return;
// get the duration in microseconds
// then display it in milliseconds
- Output.printElapsed(@intToFloat(f64, value.read() / std.time.ns_per_us) / std.time.us_per_ms);
+ Output.printElapsed(@floatFromInt(f64, value.read() / std.time.ns_per_us) / std.time.us_per_ms);
switch (len) {
0 => Output.printErrorln("\n", .{}),
else => Output.printErrorln(" {s}", .{chars[0..len]}),
diff --git a/src/bun.js/bindings/header-gen.zig b/src/bun.js/bindings/header-gen.zig
index 089506a8f..eb0de1c09 100644
--- a/src/bun.js/bindings/header-gen.zig
+++ b/src/bun.js/bindings/header-gen.zig
@@ -807,7 +807,7 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
}
};
var extern_list = Type.Extern;
- std.sort.sort([]const u8, &extern_list, Sorder{}, Sorder.lessThan);
+ std.sort.block([]const u8, &extern_list, Sorder{}, Sorder.lessThan);
break :brk extern_list;
};
// impl_writer.print(" #include {s}\n", .{Type.include}) catch unreachable;
@@ -840,7 +840,7 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
}
};
var extern_list = Type.Export;
- std.sort.sort(StaticExport, &extern_list, Sorder{}, Sorder.lessThan);
+ std.sort.block(StaticExport, &extern_list, Sorder{}, Sorder.lessThan);
break :brk extern_list;
};
@@ -867,7 +867,7 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
// }
// };
// var extern_list = Type.lazy_static_functions;
- // std.sort.sort(StaticExport, &extern_list, Sorder{}, Sorder.lessThan);
+ // std.sort.block(StaticExport, &extern_list, Sorder{}, Sorder.lessThan);
// break :brk extern_list;
// };
diff --git a/src/bun.js/bindings/shimmer.zig b/src/bun.js/bindings/shimmer.zig
index a90bfab87..3a6242000 100644
--- a/src/bun.js/bindings/shimmer.zig
+++ b/src/bun.js/bindings/shimmer.zig
@@ -163,7 +163,7 @@ pub fn Shimmer(comptime _namespace: []const u8, comptime _name: []const u8, comp
if (comptime isNullableType(ExpectedReturnType) != isNullableType(ExternReturnType)) {
return value.?;
} else if (comptime (@typeInfo(ExpectedReturnType) == .Enum) and (@typeInfo(ExternReturnType) != .Enum)) {
- return @intToEnum(ExpectedReturnType, value);
+ return @enumFromInt(ExpectedReturnType, value);
} else {
return value;
}
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index d458b6e7e..545f41f19 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -196,7 +196,7 @@ pub const SavedSourceMap = struct {
pub const SourceMapHandler = js_printer.SourceMapHandler.For(SavedSourceMap, onSourceMapChunk);
pub fn putMappings(this: *SavedSourceMap, source: logger.Source, mappings: MutableString) !void {
- var entry = try this.map.getOrPut(std.hash.Wyhash.hash(0, source.path.text));
+ var entry = try this.map.getOrPut(bun.hash(source.path.text));
if (entry.found_existing) {
var value = Value.from(entry.value_ptr.*);
if (value.get(MappingList)) |source_map_| {
@@ -213,7 +213,7 @@ pub const SavedSourceMap = struct {
}
pub fn get(this: *SavedSourceMap, path: string) ?MappingList {
- var mapping = this.map.getEntry(std.hash.Wyhash.hash(0, path)) orelse return null;
+ var mapping = this.map.getEntry(bun.hash(path)) orelse return null;
switch (Value.from(mapping.value_ptr.*).tag()) {
(@field(Value.Tag, @typeName(MappingList))) => {
return Value.from(mapping.value_ptr.*).as(MappingList).*;
@@ -264,7 +264,7 @@ export fn Bun__readOriginTimer(vm: *JSC.VirtualMachine) u64 {
export fn Bun__readOriginTimerStart(vm: *JSC.VirtualMachine) f64 {
// timespce to milliseconds
- return @floatCast(f64, (@intToFloat(f64, vm.origin_timestamp) + JSC.VirtualMachine.origin_relative_epoch) / 1_000_000.0);
+ return @floatCast(f64, (@floatFromInt(f64, vm.origin_timestamp) + JSC.VirtualMachine.origin_relative_epoch) / 1_000_000.0);
}
// comptime {
@@ -1382,7 +1382,7 @@ pub const VirtualMachine = struct {
// // This double prints
// pub fn promiseRejectionTracker(global: *JSGlobalObject, promise: *JSPromise, _: JSPromiseRejectionOperation) callconv(.C) JSValue {
// const result = promise.result(global.vm());
- // if (@enumToInt(VirtualMachine.get().last_error_jsvalue) != @enumToInt(result)) {
+ // if (@intFromEnum(VirtualMachine.get().last_error_jsvalue) != @intFromEnum(result)) {
// VirtualMachine.get().runErrorHandler(result, null);
// }
@@ -1823,7 +1823,7 @@ pub const VirtualMachine = struct {
iterator(_vm, globalObject, nextValue, ctx.?, false);
}
inline fn iterator(_: [*c]VM, _: [*c]JSGlobalObject, nextValue: JSValue, ctx: ?*anyopaque, comptime color: bool) void {
- var this_ = @intToPtr(*@This(), @ptrToInt(ctx));
+ var this_ = @ptrFromInt(*@This(), @intFromPtr(ctx));
VirtualMachine.get().printErrorlikeObject(nextValue, null, this_.current_exception_list, Writer, this_.writer, color, allow_side_effects);
}
};
@@ -2066,8 +2066,8 @@ pub const VirtualMachine = struct {
)) |lines| {
var source_lines = exception.stack.source_lines_ptr[0..JSC.ZigException.Holder.source_lines_count];
var source_line_numbers = exception.stack.source_lines_numbers[0..JSC.ZigException.Holder.source_lines_count];
- std.mem.set(ZigString, source_lines, ZigString.Empty);
- std.mem.set(i32, source_line_numbers, 0);
+ @memset(source_lines, ZigString.Empty);
+ @memset(source_line_numbers, 0);
var lines_ = lines[0..@min(lines.len, source_lines.len)];
for (lines_, 0..) |line, j| {
@@ -2374,7 +2374,7 @@ pub const EventListenerMixin = struct {
const FetchEventRejectionHandler = struct {
pub fn onRejection(_ctx: *anyopaque, err: anyerror, fetch_event: *FetchEvent, value: JSValue) void {
onError(
- @intToPtr(*CtxType, @ptrToInt(_ctx)),
+ @ptrFromInt(*CtxType, @intFromPtr(_ctx)),
err,
value,
fetch_event.request_context.?,
@@ -2763,10 +2763,10 @@ pub fn NewHotReloader(comptime Ctx: type, comptime EventLoopType: type, comptime
break :brk path_string.slice();
} else {
var file_path_without_trailing_slash = std.mem.trimRight(u8, file_path, std.fs.path.sep_str);
- @memcpy(&_on_file_update_path_buf, file_path_without_trailing_slash.ptr, file_path_without_trailing_slash.len);
+ @memcpy(_on_file_update_path_buf[0..file_path_without_trailing_slash.len], file_path_without_trailing_slash);
_on_file_update_path_buf[file_path_without_trailing_slash.len] = std.fs.path.sep;
- @memcpy(_on_file_update_path_buf[file_path_without_trailing_slash.len + 1 ..].ptr, changed_name.ptr, changed_name.len);
+ @memcpy(_on_file_update_path_buf[file_path_without_trailing_slash.len..][0..changed_name.len], changed_name);
const path_slice = _on_file_update_path_buf[0 .. file_path_without_trailing_slash.len + changed_name.len + 1];
file_hash = @This().Watcher.getHash(path_slice);
break :brk path_slice;
diff --git a/src/bun.js/javascript_core_c_api.zig b/src/bun.js/javascript_core_c_api.zig
index 37f9df15d..aba143a81 100644
--- a/src/bun.js/javascript_core_c_api.zig
+++ b/src/bun.js/javascript_core_c_api.zig
@@ -9,7 +9,7 @@ const std = @import("std");
const cpp = @import("./bindings/bindings.zig");
const generic = opaque {
pub fn value(this: *const @This()) cpp.JSValue {
- return @intToEnum(cpp.JSValue, @bitCast(cpp.JSValue.Type, @ptrToInt(this)));
+ return @enumFromInt(cpp.JSValue, @bitCast(cpp.JSValue.Type, @intFromPtr(this)));
}
pub inline fn bunVM(this: *@This()) *@import("root").bun.JSC.VirtualMachine {
@@ -120,13 +120,13 @@ pub const JSType = enum(c_uint) {
kJSTypeObject,
kJSTypeSymbol,
};
-pub const kJSTypeUndefined = @enumToInt(JSType.kJSTypeUndefined);
-pub const kJSTypeNull = @enumToInt(JSType.kJSTypeNull);
-pub const kJSTypeBoolean = @enumToInt(JSType.kJSTypeBoolean);
-pub const kJSTypeNumber = @enumToInt(JSType.kJSTypeNumber);
-pub const kJSTypeString = @enumToInt(JSType.kJSTypeString);
-pub const kJSTypeObject = @enumToInt(JSType.kJSTypeObject);
-pub const kJSTypeSymbol = @enumToInt(JSType.kJSTypeSymbol);
+pub const kJSTypeUndefined = @intFromEnum(JSType.kJSTypeUndefined);
+pub const kJSTypeNull = @intFromEnum(JSType.kJSTypeNull);
+pub const kJSTypeBoolean = @intFromEnum(JSType.kJSTypeBoolean);
+pub const kJSTypeNumber = @intFromEnum(JSType.kJSTypeNumber);
+pub const kJSTypeString = @intFromEnum(JSType.kJSTypeString);
+pub const kJSTypeObject = @intFromEnum(JSType.kJSTypeObject);
+pub const kJSTypeSymbol = @intFromEnum(JSType.kJSTypeSymbol);
pub const JSTypedArrayType = enum(c_uint) {
kJSTypedArrayTypeInt8Array,
kJSTypedArrayTypeInt16Array,
@@ -141,17 +141,17 @@ pub const JSTypedArrayType = enum(c_uint) {
kJSTypedArrayTypeNone,
_,
};
-pub const kJSTypedArrayTypeInt8Array = @enumToInt(JSTypedArrayType.kJSTypedArrayTypeInt8Array);
-pub const kJSTypedArrayTypeInt16Array = @enumToInt(JSTypedArrayType.kJSTypedArrayTypeInt16Array);
-pub const kJSTypedArrayTypeInt32Array = @enumToInt(JSTypedArrayType.kJSTypedArrayTypeInt32Array);
-pub const kJSTypedArrayTypeUint8Array = @enumToInt(JSTypedArrayType.kJSTypedArrayTypeUint8Array);
-pub const kJSTypedArrayTypeUint8ClampedArray = @enumToInt(JSTypedArrayType.kJSTypedArrayTypeUint8ClampedArray);
-pub const kJSTypedArrayTypeUint16Array = @enumToInt(JSTypedArrayType.kJSTypedArrayTypeUint16Array);
-pub const kJSTypedArrayTypeUint32Array = @enumToInt(JSTypedArrayType.kJSTypedArrayTypeUint32Array);
-pub const kJSTypedArrayTypeFloat32Array = @enumToInt(JSTypedArrayType.kJSTypedArrayTypeFloat32Array);
-pub const kJSTypedArrayTypeFloat64Array = @enumToInt(JSTypedArrayType.kJSTypedArrayTypeFloat64Array);
-pub const kJSTypedArrayTypeArrayBuffer = @enumToInt(JSTypedArrayType.kJSTypedArrayTypeArrayBuffer);
-pub const kJSTypedArrayTypeNone = @enumToInt(JSTypedArrayType.kJSTypedArrayTypeNone);
+pub const kJSTypedArrayTypeInt8Array = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeInt8Array);
+pub const kJSTypedArrayTypeInt16Array = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeInt16Array);
+pub const kJSTypedArrayTypeInt32Array = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeInt32Array);
+pub const kJSTypedArrayTypeUint8Array = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeUint8Array);
+pub const kJSTypedArrayTypeUint8ClampedArray = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeUint8ClampedArray);
+pub const kJSTypedArrayTypeUint16Array = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeUint16Array);
+pub const kJSTypedArrayTypeUint32Array = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeUint32Array);
+pub const kJSTypedArrayTypeFloat32Array = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeFloat32Array);
+pub const kJSTypedArrayTypeFloat64Array = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeFloat64Array);
+pub const kJSTypedArrayTypeArrayBuffer = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeArrayBuffer);
+pub const kJSTypedArrayTypeNone = @intFromEnum(JSTypedArrayType.kJSTypedArrayTypeNone);
pub extern fn JSValueGetType(ctx: JSContextRef, value: JSValueRef) JSType;
pub extern fn JSValueIsUndefined(ctx: JSContextRef, value: JSValueRef) bool;
pub extern fn JSValueIsNull(ctx: JSContextRef, value: JSValueRef) bool;
@@ -187,7 +187,7 @@ pub inline fn JSValueUnprotect(ctx: JSContextRef, value: JSValueRef) void {
};
if (comptime log_protection) {
const Output = @import("root").bun.Output;
- Output.debug("[unprotect] {d}\n", .{@ptrToInt(value)});
+ Output.debug("[unprotect] {d}\n", .{@intFromPtr(value)});
}
// wrapper exists to make it easier to set a breakpoint
Wrapped.JSValueUnprotect(ctx, value);
@@ -199,7 +199,7 @@ pub inline fn JSValueProtect(ctx: JSContextRef, value: JSValueRef) void {
};
if (comptime log_protection) {
const Output = @import("root").bun.Output;
- Output.debug("[protect] {d}\n", .{@ptrToInt(value)});
+ Output.debug("[protect] {d}\n", .{@intFromPtr(value)});
}
// wrapper exists to make it easier to set a breakpoint
Wrapped.JSValueProtect(ctx, value);
@@ -212,18 +212,18 @@ pub const JSPropertyAttributes = enum(c_uint) {
kJSPropertyAttributeDontDelete = 8,
_,
};
-pub const kJSPropertyAttributeNone = @enumToInt(JSPropertyAttributes.kJSPropertyAttributeNone);
-pub const kJSPropertyAttributeReadOnly = @enumToInt(JSPropertyAttributes.kJSPropertyAttributeReadOnly);
-pub const kJSPropertyAttributeDontEnum = @enumToInt(JSPropertyAttributes.kJSPropertyAttributeDontEnum);
-pub const kJSPropertyAttributeDontDelete = @enumToInt(JSPropertyAttributes.kJSPropertyAttributeDontDelete);
+pub const kJSPropertyAttributeNone = @intFromEnum(JSPropertyAttributes.kJSPropertyAttributeNone);
+pub const kJSPropertyAttributeReadOnly = @intFromEnum(JSPropertyAttributes.kJSPropertyAttributeReadOnly);
+pub const kJSPropertyAttributeDontEnum = @intFromEnum(JSPropertyAttributes.kJSPropertyAttributeDontEnum);
+pub const kJSPropertyAttributeDontDelete = @intFromEnum(JSPropertyAttributes.kJSPropertyAttributeDontDelete);
pub const JSClassAttributes = enum(c_uint) {
kJSClassAttributeNone = 0,
kJSClassAttributeNoAutomaticPrototype = 2,
_,
};
-pub const kJSClassAttributeNone = @enumToInt(JSClassAttributes.kJSClassAttributeNone);
-pub const kJSClassAttributeNoAutomaticPrototype = @enumToInt(JSClassAttributes.kJSClassAttributeNoAutomaticPrototype);
+pub const kJSClassAttributeNone = @intFromEnum(JSClassAttributes.kJSClassAttributeNone);
+pub const kJSClassAttributeNoAutomaticPrototype = @intFromEnum(JSClassAttributes.kJSClassAttributeNoAutomaticPrototype);
pub const JSObjectInitializeCallback = *const fn (JSContextRef, JSObjectRef) callconv(.C) void;
pub const JSObjectFinalizeCallback = *const fn (JSObjectRef) callconv(.C) void;
pub const JSObjectHasPropertyCallback = *const fn (JSContextRef, JSObjectRef, JSStringRef) callconv(.C) bool;
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig
index d115573be..e249bba8b 100644
--- a/src/bun.js/module_loader.zig
+++ b/src/bun.js/module_loader.zig
@@ -1298,7 +1298,7 @@ pub const ModuleLoader = struct {
var encoded = JSC.EncodedJSValue{
.asPtr = globalThis,
};
- const globalValue = @intToEnum(JSC.JSValue, encoded.asInt64);
+ const globalValue = @enumFromInt(JSC.JSValue, encoded.asInt64);
globalValue.put(
globalThis,
JSC.ZigString.static("wasmSourceBytes"),
diff --git a/src/bun.js/node/buffer.zig b/src/bun.js/node/buffer.zig
index f73498069..3a0750f05 100644
--- a/src/bun.js/node/buffer.zig
+++ b/src/bun.js/node/buffer.zig
@@ -50,7 +50,7 @@ pub const BufferVectorized = struct {
switch (written) {
0 => {},
- 1 => @memset(buf.ptr, buf[0], buf.len),
+ 1 => @memset(buf, buf[0]),
else => {
var contents = buf[0..written];
buf = buf[written..];
diff --git a/src/bun.js/node/dir_iterator.zig b/src/bun.js/node/dir_iterator.zig
index aa939679c..dac78e5e2 100644
--- a/src/bun.js/node/dir_iterator.zig
+++ b/src/bun.js/node/dir_iterator.zig
@@ -78,15 +78,15 @@ pub const Iterator = switch (builtin.os.tag) {
}
const entry_kind = switch (darwin_entry.d_type) {
- os.DT.BLK => Entry.Kind.BlockDevice,
- os.DT.CHR => Entry.Kind.CharacterDevice,
- os.DT.DIR => Entry.Kind.Directory,
- os.DT.FIFO => Entry.Kind.NamedPipe,
- os.DT.LNK => Entry.Kind.SymLink,
- os.DT.REG => Entry.Kind.File,
- os.DT.SOCK => Entry.Kind.UnixDomainSocket,
- os.DT.WHT => Entry.Kind.Whiteout,
- else => Entry.Kind.Unknown,
+ os.DT.BLK => Entry.Kind.block_device,
+ os.DT.CHR => Entry.Kind.character_device,
+ os.DT.DIR => Entry.Kind.directory,
+ os.DT.FIFO => Entry.Kind.named_pipe,
+ os.DT.LNK => Entry.Kind.sym_link,
+ os.DT.REG => Entry.Kind.file,
+ os.DT.SOCK => Entry.Kind.unix_domain_socket,
+ os.DT.WHT => Entry.Kind.whiteout,
+ else => Entry.Kind.unknown,
};
return .{
.result = IteratorResult{
@@ -134,14 +134,14 @@ pub const Iterator = switch (builtin.os.tag) {
}
const entry_kind = switch (linux_entry.d_type) {
- linux.DT.BLK => Entry.Kind.BlockDevice,
- linux.DT.CHR => Entry.Kind.CharacterDevice,
- linux.DT.DIR => Entry.Kind.Directory,
- linux.DT.FIFO => Entry.Kind.NamedPipe,
- linux.DT.LNK => Entry.Kind.SymLink,
- linux.DT.REG => Entry.Kind.File,
- linux.DT.SOCK => Entry.Kind.UnixDomainSocket,
- else => Entry.Kind.Unknown,
+ linux.DT.BLK => Entry.Kind.block_device,
+ linux.DT.CHR => Entry.Kind.character_device,
+ linux.DT.DIR => Entry.Kind.directory,
+ linux.DT.FIFO => Entry.Kind.named_pipe,
+ linux.DT.LNK => Entry.Kind.sym_link,
+ linux.DT.REG => Entry.Kind.file,
+ linux.DT.SOCK => Entry.Kind.unix_domain_socket,
+ else => Entry.Kind.unknown,
};
return .{
.result = IteratorResult{
@@ -213,9 +213,9 @@ pub const Iterator = switch (builtin.os.tag) {
const name_utf8 = self.name_data[0..name_utf8_len];
const kind = blk: {
const attrs = dir_info.FileAttributes;
- if (attrs & w.FILE_ATTRIBUTE_DIRECTORY != 0) break :blk Entry.Kind.Directory;
- if (attrs & w.FILE_ATTRIBUTE_REPARSE_POINT != 0) break :blk Entry.Kind.SymLink;
- break :blk Entry.Kind.File;
+ if (attrs & w.FILE_ATTRIBUTE_DIRECTORY != 0) break :blk Entry.Kind.directory;
+ if (attrs & w.FILE_ATTRIBUTE_REPARSE_POINT != 0) break :blk Entry.Kind.sym_link;
+ break :blk Entry.Kind.file;
};
return .{
.result = IteratorResult{
@@ -275,13 +275,13 @@ pub const Iterator = switch (builtin.os.tag) {
}
const entry_kind = switch (entry.d_type) {
- .BLOCK_DEVICE => Entry.Kind.BlockDevice,
- .CHARACTER_DEVICE => Entry.Kind.CharacterDevice,
- .DIRECTORY => Entry.Kind.Directory,
- .SYMBOLIC_LINK => Entry.Kind.SymLink,
- .REGULAR_FILE => Entry.Kind.File,
- .SOCKET_STREAM, .SOCKET_DGRAM => Entry.Kind.UnixDomainSocket,
- else => Entry.Kind.Unknown,
+ .BLOCK_DEVICE => Entry.Kind.block_device,
+ .CHARACTER_DEVICE => Entry.Kind.character_device,
+ .DIRECTORY => Entry.Kind.directory,
+ .SYMBOLIC_LINK => Entry.Kind.sym_link,
+ .REGULAR_FILE => Entry.Kind.file,
+ .SOCKET_STREAM, .SOCKET_DGRAM => Entry.Kind.unix_domain_socket,
+ else => Entry.Kind.unknown,
};
return IteratorResult{
.name = name,
diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig
index 254d58455..3ea0822e6 100644
--- a/src/bun.js/node/node_fs.zig
+++ b/src/bun.js/node/node_fs.zig
@@ -2264,7 +2264,7 @@ pub const Arguments = struct {
return CopyFile{
.src = src,
.dest = dest,
- .mode = @intToEnum(Constants.Copyfile, mode),
+ .mode = @enumFromInt(Constants.Copyfile, mode),
};
}
};
@@ -2498,7 +2498,7 @@ pub const NodeFS = struct {
pub fn access(this: *NodeFS, args: Arguments.Access, comptime _: Flavor) Maybe(Return.Access) {
var path = args.path.sliceZ(&this.sync_error_buf);
- const rc = Syscall.system.access(path, @enumToInt(args.mode));
+ const rc = Syscall.system.access(path, @intFromEnum(args.mode));
return Maybe(Return.Access).errnoSysP(rc, .access, path) orelse Maybe(Return.Access).success;
}
@@ -2528,7 +2528,7 @@ pub const NodeFS = struct {
const path = path_.sliceZ(&this.sync_error_buf);
switch (comptime flavor) {
.sync => {
- const fd = switch (Syscall.open(path, @enumToInt(FileSystemFlags.a), 0o000666)) {
+ const fd = switch (Syscall.open(path, @intFromEnum(FileSystemFlags.a), 0o000666)) {
.result => |result| result,
.err => |err| return .{ .err = err },
};
@@ -2594,7 +2594,7 @@ pub const NodeFS = struct {
};
if (!os.S.ISREG(stat_.mode)) {
- return Maybe(Return.CopyFile){ .err = .{ .errno = @enumToInt(C.SystemErrno.ENOTSUP) } };
+ return Maybe(Return.CopyFile){ .err = .{ .errno = @intFromEnum(C.SystemErrno.ENOTSUP) } };
}
// 64 KB is about the break-even point for clonefile() to be worth it
@@ -2723,7 +2723,7 @@ pub const NodeFS = struct {
};
if (!os.S.ISREG(stat_.mode)) {
- return Maybe(Return.CopyFile){ .err = .{ .errno = @enumToInt(C.SystemErrno.ENOTSUP) } };
+ return Maybe(Return.CopyFile){ .err = .{ .errno = @intFromEnum(C.SystemErrno.ENOTSUP) } };
}
var flags: Mode = std.os.O.CREAT | std.os.O.WRONLY;
@@ -3026,7 +3026,7 @@ pub const NodeFS = struct {
.err => |err| {
switch (err.getErrno()) {
else => {
- @memcpy(&this.sync_error_buf, path.ptr, len);
+ @memcpy(this.sync_error_buf[0..len], path[0..len]);
return .{ .err = err.withPath(this.sync_error_buf[0..len]) };
},
@@ -3043,7 +3043,7 @@ pub const NodeFS = struct {
}
var working_mem = &this.sync_error_buf;
- @memcpy(working_mem, path.ptr, len);
+ @memcpy(working_mem[0..len], path[0..len]);
var i: u16 = len - 1;
@@ -3146,7 +3146,7 @@ pub const NodeFS = struct {
const prefix_slice = args.prefix.slice();
const len = @min(prefix_slice.len, prefix_buf.len -| 7);
if (len > 0) {
- @memcpy(prefix_buf, prefix_slice.ptr, len);
+ @memcpy(prefix_buf[0..len], prefix_slice[0..len]);
}
prefix_buf[len..][0..6].* = "XXXXXX".*;
prefix_buf[len..][6] = 0;
@@ -3162,15 +3162,15 @@ pub const NodeFS = struct {
};
}
// std.c.getErrno(rc) returns SUCCESS if rc is null so we call std.c._errno() directly
- const errno = @intToEnum(std.c.E, std.c._errno().*);
- return .{ .err = Syscall.Error{ .errno = @truncate(Syscall.Error.Int, @enumToInt(errno)), .syscall = .mkdtemp } };
+ const errno = @enumFromInt(std.c.E, std.c._errno().*);
+ return .{ .err = Syscall.Error{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(errno)), .syscall = .mkdtemp } };
}
pub fn open(this: *NodeFS, args: Arguments.Open, comptime flavor: Flavor) Maybe(Return.Open) {
switch (comptime flavor) {
// The sync version does no allocation except when returning the path
.sync => {
const path = args.path.sliceZ(&this.sync_error_buf);
- return switch (Syscall.open(path, @enumToInt(args.flags), args.mode)) {
+ return switch (Syscall.open(path, @intFromEnum(args.flags), args.mode)) {
.err => |err| .{
.err = err.withPath(args.path.slice()),
},
@@ -3605,7 +3605,7 @@ pub const NodeFS = struct {
break :brk switch (Syscall.openat(
args.dirfd,
path,
- @enumToInt(args.flag) | os.O.NOCTTY,
+ @intFromEnum(args.flag) | os.O.NOCTTY,
args.mode,
)) {
.err => |err| return .{
@@ -3672,7 +3672,7 @@ pub const NodeFS = struct {
}
// https://github.com/oven-sh/bun/issues/2931
- if ((@enumToInt(args.flag) & std.os.O.APPEND) == 0) {
+ if ((@intFromEnum(args.flag) & std.os.O.APPEND) == 0) {
_ = ftruncateSync(.{ .fd = fd, .len = @truncate(JSC.WebCore.Blob.SizeType, written) });
}
@@ -3819,12 +3819,12 @@ pub const NodeFS = struct {
while (true) {
if (Maybe(Return.Rmdir).errnoSys(bun.C.darwin.removefileat(std.os.AT.FDCWD, dest, null, flags), .rmdir)) |errno| {
- switch (@intToEnum(os.E, errno.err.errno)) {
+ switch (@enumFromInt(os.E, errno.err.errno)) {
.AGAIN, .INTR => continue,
.NOENT => return Maybe(Return.Rmdir).success,
.MLINK => {
var copy: [bun.MAX_PATH_BYTES]u8 = undefined;
- @memcpy(&copy, dest.ptr, dest.len);
+ @memcpy(copy[0..dest.len], dest);
copy[dest.len] = 0;
var dest_copy = copy[0..dest.len :0];
switch (Syscall.unlink(dest_copy).getErrno()) {
@@ -3906,7 +3906,7 @@ pub const NodeFS = struct {
}
if (Maybe(Return.Rm).errnoSys(bun.C.darwin.removefileat(std.os.AT.FDCWD, dest, null, flags), .unlink)) |errno| {
- switch (@intToEnum(os.E, errno.err.errno)) {
+ switch (@enumFromInt(os.E, errno.err.errno)) {
.AGAIN, .INTR => continue,
.NOENT => {
if (args.force) {
@@ -3918,7 +3918,7 @@ pub const NodeFS = struct {
.MLINK => {
var copy: [bun.MAX_PATH_BYTES]u8 = undefined;
- @memcpy(&copy, dest.ptr, dest.len);
+ @memcpy(copy[0..dest.len], dest);
copy[dest.len] = 0;
var dest_copy = copy[0..dest.len :0];
switch (Syscall.unlink(dest_copy).getErrno()) {
diff --git a/src/bun.js/node/node_fs_constant.zig b/src/bun.js/node/node_fs_constant.zig
index 378f332c6..8e642ebad 100644
--- a/src/bun.js/node/node_fs_constant.zig
+++ b/src/bun.js/node/node_fs_constant.zig
@@ -26,17 +26,17 @@ pub const Constants = struct {
pub const force = 4;
pub inline fn isForceClone(this: Copyfile) bool {
- return (@enumToInt(this) & COPYFILE_FICLONE_FORCE) != 0;
+ return (@intFromEnum(this) & COPYFILE_FICLONE_FORCE) != 0;
}
pub inline fn shouldntOverwrite(this: Copyfile) bool {
- return (@enumToInt(this) & COPYFILE_EXCL) != 0;
+ return (@intFromEnum(this) & COPYFILE_EXCL) != 0;
}
pub inline fn canUseClone(this: Copyfile) bool {
_ = this;
return Environment.isMac;
- // return (@enumToInt(this) | COPYFILE_FICLONE) != 0;
+ // return (@intFromEnum(this) | COPYFILE_FICLONE) != 0;
}
};
diff --git a/src/bun.js/node/node_os.zig b/src/bun.js/node/node_os.zig
index 4b37640cf..7f9ea2e28 100644
--- a/src/bun.js/node/node_os.zig
+++ b/src/bun.js/node/node_os.zig
@@ -211,7 +211,7 @@ pub const Os = struct {
if (local_bindings.host_processor_info(std.c.mach_host_self(), local_bindings.PROCESSOR_CPU_LOAD_INFO, &num_cpus, @ptrCast(*local_bindings.processor_info_array_t, &info), &info_size) != .SUCCESS) {
return error.no_processor_info;
}
- defer _ = std.c.vm_deallocate(std.c.mach_task_self(), @ptrToInt(info), info_size);
+ defer _ = std.c.vm_deallocate(std.c.mach_task_self(), @intFromPtr(info), info_size);
// Ensure we got the amount of data we expected to guard against buffer overruns
if (info_size != C.PROCESSOR_CPU_LOAD_INFO_COUNT * num_cpus) {
@@ -380,7 +380,7 @@ pub const Os = struct {
const err = JSC.SystemError{
.message = JSC.ZigString.init("A system error occurred: getifaddrs returned an error"),
.code = JSC.ZigString.init(@as(string, @tagName(JSC.Node.ErrorCode.ERR_SYSTEM_ERROR))),
- .errno = @enumToInt(std.os.errno(rc)),
+ .errno = @intFromEnum(std.os.errno(rc)),
.syscall = JSC.ZigString.init("getifaddrs"),
};
@@ -461,7 +461,7 @@ pub const Os = struct {
var cidr = JSC.JSValue.null;
if (maybe_suffix) |suffix| {
//NOTE addr_str might not start at buf[0] due to slicing in formatIp
- const start = @ptrToInt(addr_str.ptr) - @ptrToInt(&buf[0]);
+ const start = @intFromPtr(addr_str.ptr) - @intFromPtr(&buf[0]);
// Start writing the suffix immediately after the address
const suffix_str = std.fmt.bufPrint(buf[start + addr_str.len ..], "/{}", .{suffix}) catch unreachable;
// The full cidr value is the address + the suffix
diff --git a/src/bun.js/node/os/constants.zig b/src/bun.js/node/os/constants.zig
index a3508d383..9cf754e03 100644
--- a/src/bun.js/node/os/constants.zig
+++ b/src/bun.js/node/os/constants.zig
@@ -8,14 +8,14 @@ const ConstantType = enum { ERRNO, ERRNO_WIN, SIG, DLOPEN, OTHER };
fn getErrnoConstant(comptime name: []const u8) ?comptime_int {
return if (@hasField(std.os.E, name))
- return @enumToInt(@field(std.os.E, name))
+ return @intFromEnum(@field(std.os.E, name))
else
return null;
}
fn getWindowsErrnoConstant(comptime name: []const u8) ?comptime_int {
return if (@hasField(std.os.E, name))
- return @enumToInt(@field(std.os.windows.ws2_32.WinsockError, name))
+ return @intFromEnum(@field(std.os.windows.ws2_32.WinsockError, name))
else
return null;
}
diff --git a/src/bun.js/node/syscall.zig b/src/bun.js/node/syscall.zig
index 7b10a3028..77bd5b13d 100644
--- a/src/bun.js/node/syscall.zig
+++ b/src/bun.js/node/syscall.zig
@@ -202,7 +202,7 @@ pub fn openat(dirfd: bun.FileDescriptor, file_path: [:0]const u8, flags: JSC.Nod
.SUCCESS => .{ .result = @intCast(bun.FileDescriptor, rc) },
else => |err| .{
.err = .{
- .errno = @truncate(Syscall.Error.Int, @enumToInt(err)),
+ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)),
.syscall = .open,
},
},
@@ -218,7 +218,7 @@ pub fn openat(dirfd: bun.FileDescriptor, file_path: [:0]const u8, flags: JSC.Nod
else => |err| {
return Maybe(std.os.fd_t){
.err = .{
- .errno = @truncate(Syscall.Error.Int, @enumToInt(err)),
+ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)),
.syscall = .open,
},
};
@@ -253,14 +253,14 @@ pub fn closeAllowingStdoutAndStderr(fd: std.os.fd_t) ?Syscall.Error {
if (comptime Environment.isMac) {
// This avoids the EINTR problem.
return switch (system.getErrno(system.@"close$NOCANCEL"(fd))) {
- .BADF => Syscall.Error{ .errno = @enumToInt(os.E.BADF), .syscall = .close },
+ .BADF => Syscall.Error{ .errno = @intFromEnum(os.E.BADF), .syscall = .close },
else => null,
};
}
if (comptime Environment.isLinux) {
return switch (linux.getErrno(linux.close(fd))) {
- .BADF => Syscall.Error{ .errno = @enumToInt(os.E.BADF), .syscall = .close },
+ .BADF => Syscall.Error{ .errno = @intFromEnum(os.E.BADF), .syscall = .close },
else => null,
};
}
@@ -546,7 +546,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) Maybe([]u8) {
.macos, .ios, .watchos, .tvos => {
// On macOS, we can use F.GETPATH fcntl command to query the OS for
// the path to the file descriptor.
- @memset(out_buffer, 0, MAX_PATH_BYTES);
+ @memset(out_buffer[0..MAX_PATH_BYTES], 0);
if (Maybe([]u8).errnoSys(system.fcntl(fd, os.F.GETPATH, out_buffer), .fcntl)) |err| {
return err;
}
@@ -594,7 +594,7 @@ fn mmap(
const fail = std.c.MAP.FAILED;
if (rc == fail) {
return Maybe([]align(mem.page_size) u8){
- .err = .{ .errno = @truncate(Syscall.Error.Int, @enumToInt(std.c.getErrno(@bitCast(i64, @ptrToInt(fail))))), .syscall = .mmap },
+ .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(std.c.getErrno(@bitCast(i64, @intFromPtr(fail))))), .syscall = .mmap },
};
}
@@ -643,16 +643,16 @@ pub fn munmap(memory: []align(mem.page_size) const u8) Maybe(void) {
pub const Error = struct {
const max_errno_value = brk: {
const errno_values = std.enums.values(os.E);
- var err = @enumToInt(os.E.SUCCESS);
+ var err = @intFromEnum(os.E.SUCCESS);
for (errno_values) |errn| {
- err = @max(err, @enumToInt(errn));
+ err = @max(err, @intFromEnum(errn));
}
break :brk err;
};
pub const Int: type = std.math.IntFittingRange(0, max_errno_value + 5);
errno: Int,
- syscall: Syscall.Tag = @intToEnum(Syscall.Tag, 0),
+ syscall: Syscall.Tag = @enumFromInt(Syscall.Tag, 0),
path: []const u8 = "",
fd: i32 = -1,
@@ -661,7 +661,7 @@ pub const Error = struct {
}
pub fn fromCode(errno: os.E, syscall: Syscall.Tag) Error {
- return .{ .errno = @truncate(Int, @enumToInt(errno)), .syscall = syscall };
+ return .{ .errno = @truncate(Int, @intFromEnum(errno)), .syscall = syscall };
}
pub fn format(self: Error, comptime fmt: []const u8, opts: std.fmt.FormatOptions, writer: anytype) !void {
@@ -672,16 +672,16 @@ pub const Error = struct {
pub const retry = Error{
.errno = if (Environment.isLinux)
- @intCast(Int, @enumToInt(os.E.AGAIN))
+ @intCast(Int, @intFromEnum(os.E.AGAIN))
else if (Environment.isMac)
- @intCast(Int, @enumToInt(os.E.WOULDBLOCK))
+ @intCast(Int, @intFromEnum(os.E.WOULDBLOCK))
else
- @intCast(Int, @enumToInt(os.E.INTR)),
+ @intCast(Int, @intFromEnum(os.E.INTR)),
.syscall = .retry,
};
pub inline fn getErrno(this: Error) os.E {
- return @intToEnum(os.E, this.errno);
+ return @enumFromInt(os.E, this.errno);
}
pub inline fn withPath(this: Error, path: anytype) Error {
@@ -726,7 +726,7 @@ pub const Error = struct {
// errno label
if (this.errno > 0 and this.errno < C.SystemErrno.max) {
- const system_errno = @intToEnum(C.SystemErrno, this.errno);
+ const system_errno = @enumFromInt(C.SystemErrno, this.errno);
err.code = JSC.ZigString.init(@tagName(system_errno));
if (C.SystemErrno.labels.get(system_errno)) |label| {
err.message = JSC.ZigString.init(label);
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig
index 1fe378a84..e2de35706 100644
--- a/src/bun.js/node/types.zig
+++ b/src/bun.js/node/types.zig
@@ -135,7 +135,7 @@ pub fn Maybe(comptime ResultType: type) type {
pub inline fn getErrno(this: @This()) os.E {
return switch (this) {
.result => os.E.SUCCESS,
- .err => |err| @intToEnum(os.E, err.errno),
+ .err => |err| @enumFromInt(os.E, err.errno),
};
}
@@ -144,7 +144,7 @@ pub fn Maybe(comptime ResultType: type) type {
.SUCCESS => null,
else => |err| @This(){
// always truncate
- .err = .{ .errno = @truncate(Syscall.Error.Int, @enumToInt(err)) },
+ .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)) },
},
};
}
@@ -154,7 +154,7 @@ pub fn Maybe(comptime ResultType: type) type {
.SUCCESS => null,
else => |err| @This(){
// always truncate
- .err = .{ .errno = @truncate(Syscall.Error.Int, @enumToInt(err)), .syscall = syscall },
+ .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)), .syscall = syscall },
},
};
}
@@ -165,7 +165,7 @@ pub fn Maybe(comptime ResultType: type) type {
else => |err| @This(){
// always truncate
.err = .{
- .errno = @truncate(Syscall.Error.Int, @enumToInt(err)),
+ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)),
.syscall = syscall,
.fd = @intCast(i32, fd),
},
@@ -178,7 +178,7 @@ pub fn Maybe(comptime ResultType: type) type {
.SUCCESS => null,
else => |err| @This(){
// always truncate
- .err = .{ .errno = @truncate(Syscall.Error.Int, @enumToInt(err)), .syscall = syscall, .path = bun.asByteSlice(path) },
+ .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)), .syscall = syscall, .path = bun.asByteSlice(path) },
},
};
}
@@ -632,7 +632,7 @@ pub const PathLike = union(Tag) {
}
}
- @memcpy(buf, sliced.ptr, sliced.len);
+ @memcpy(buf[0..sliced.len], sliced);
buf[sliced.len] = 0;
return buf[0..sliced.len :0];
}
@@ -904,7 +904,7 @@ pub fn timeLikeFromJS(globalThis: *JSC.JSGlobalObject, value: JSC.JSValue, _: JS
return null;
}
- return @truncate(TimeLike, @floatToInt(i64, milliseconds / @as(f64, std.time.ms_per_s)));
+ return @truncate(TimeLike, @intFromFloat(i64, milliseconds / @as(f64, std.time.ms_per_s)));
}
if (!value.isNumber() and !value.isString()) {
@@ -916,7 +916,7 @@ pub fn timeLikeFromJS(globalThis: *JSC.JSGlobalObject, value: JSC.JSValue, _: JS
return null;
}
- return @truncate(TimeLike, @floatToInt(i64, seconds));
+ return @truncate(TimeLike, @intFromFloat(i64, seconds));
}
pub fn modeFromJS(ctx: JSC.C.JSContextRef, value: JSC.JSValue, exception: JSC.C.ExceptionRef) ?Mode {
@@ -968,8 +968,8 @@ pub const PathOrFileDescriptor = union(Tag) {
pub fn hash(this: JSC.Node.PathOrFileDescriptor) u64 {
return switch (this) {
- .path => std.hash.Wyhash.hash(0, this.path.slice()),
- .fd => std.hash.Wyhash.hash(0, std.mem.asBytes(&this.fd)),
+ .path => bun.hash(this.path.slice()),
+ .fd => bun.hash(std.mem.asBytes(&this.fd)),
};
}
@@ -1104,7 +1104,7 @@ pub const FileSystemFlags = enum(Mode) {
pub fn fromJS(ctx: JSC.C.JSContextRef, val: JSC.JSValue, exception: JSC.C.ExceptionRef) ?FileSystemFlags {
if (val.isNumber()) {
const number = val.coerce(i32, ctx);
- return @intToEnum(FileSystemFlags, @intCast(Mode, @max(number, 0)));
+ return @enumFromInt(FileSystemFlags, @intCast(Mode, @max(number, 0)));
}
const jsType = val.jsType();
@@ -1160,7 +1160,7 @@ pub const FileSystemFlags = enum(Mode) {
return null;
};
- return @intToEnum(FileSystemFlags, @intCast(Mode, flags));
+ return @enumFromInt(FileSystemFlags, @intCast(Mode, flags));
}
return null;
@@ -1172,7 +1172,7 @@ pub const Date = enum(u64) {
_,
pub fn toJS(this: Date, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef {
- const seconds = @floatCast(f64, @intToFloat(f64, @enumToInt(this)) * 1000.0);
+ const seconds = @floatCast(f64, @floatFromInt(f64, @intFromEnum(this)) * 1000.0);
const unix_timestamp = JSC.JSValue.jsNumber(seconds);
const array: [1]JSC.C.JSValueRef = .{unix_timestamp.asObjectRef()};
const obj = JSC.C.JSObjectMakeDate(ctx, 1, &array, exception);
@@ -1219,12 +1219,12 @@ fn StatsDataType(comptime T: type) type {
.size = @truncate(T, @intCast(i64, stat_.size)),
.blksize = @truncate(T, @intCast(i64, stat_.blksize)),
.blocks = @truncate(T, @intCast(i64, stat_.blocks)),
- .atime_ms = (@intToFloat(f64, @max(atime.tv_sec, 0)) * std.time.ms_per_s) + (@intToFloat(f64, @intCast(usize, @max(atime.tv_nsec, 0))) / std.time.ns_per_ms),
- .mtime_ms = (@intToFloat(f64, @max(mtime.tv_sec, 0)) * std.time.ms_per_s) + (@intToFloat(f64, @intCast(usize, @max(mtime.tv_nsec, 0))) / std.time.ns_per_ms),
- .ctime_ms = (@intToFloat(f64, @max(ctime.tv_sec, 0)) * std.time.ms_per_s) + (@intToFloat(f64, @intCast(usize, @max(ctime.tv_nsec, 0))) / std.time.ns_per_ms),
- .atime = @intToEnum(Date, @intCast(u64, @max(atime.tv_sec, 0))),
- .mtime = @intToEnum(Date, @intCast(u64, @max(mtime.tv_sec, 0))),
- .ctime = @intToEnum(Date, @intCast(u64, @max(ctime.tv_sec, 0))),
+ .atime_ms = (@floatFromInt(f64, @max(atime.tv_sec, 0)) * std.time.ms_per_s) + (@floatFromInt(f64, @intCast(usize, @max(atime.tv_nsec, 0))) / std.time.ns_per_ms),
+ .mtime_ms = (@floatFromInt(f64, @max(mtime.tv_sec, 0)) * std.time.ms_per_s) + (@floatFromInt(f64, @intCast(usize, @max(mtime.tv_nsec, 0))) / std.time.ns_per_ms),
+ .ctime_ms = (@floatFromInt(f64, @max(ctime.tv_sec, 0)) * std.time.ms_per_s) + (@floatFromInt(f64, @intCast(usize, @max(ctime.tv_nsec, 0))) / std.time.ns_per_ms),
+ .atime = @enumFromInt(Date, @intCast(u64, @max(atime.tv_sec, 0))),
+ .mtime = @enumFromInt(Date, @intCast(u64, @max(mtime.tv_sec, 0))),
+ .ctime = @enumFromInt(Date, @intCast(u64, @max(ctime.tv_sec, 0))),
// Linux doesn't include this info in stat
// maybe it does in statx, but do you really need birthtime? If you do please file an issue.
@@ -1234,9 +1234,9 @@ fn StatsDataType(comptime T: type) type {
@truncate(T, @intCast(i64, if (stat_.birthtime().tv_nsec > 0) (@intCast(usize, stat_.birthtime().tv_nsec) / std.time.ns_per_ms) else 0)),
.birthtime = if (Environment.isLinux)
- @intToEnum(Date, 0)
+ @enumFromInt(Date, 0)
else
- @intToEnum(Date, @intCast(u64, @max(stat_.birthtime().tv_sec, 0))),
+ @enumFromInt(Date, @intCast(u64, @max(stat_.birthtime().tv_sec, 0))),
};
}
};
@@ -1426,49 +1426,49 @@ pub const Dirent = struct {
_: *JSC.JSGlobalObject,
_: *JSC.CallFrame,
) callconv(.C) JSC.JSValue {
- return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.BlockDevice);
+ return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.block_device);
}
pub fn isCharacterDevice(
this: *Dirent,
_: *JSC.JSGlobalObject,
_: *JSC.CallFrame,
) callconv(.C) JSC.JSValue {
- return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.CharacterDevice);
+ return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.character_device);
}
pub fn isDirectory(
this: *Dirent,
_: *JSC.JSGlobalObject,
_: *JSC.CallFrame,
) callconv(.C) JSC.JSValue {
- return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.Directory);
+ return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.directory);
}
pub fn isFIFO(
this: *Dirent,
_: *JSC.JSGlobalObject,
_: *JSC.CallFrame,
) callconv(.C) JSC.JSValue {
- return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.NamedPipe or this.kind == std.fs.File.Kind.EventPort);
+ return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.named_pipe or this.kind == std.fs.File.Kind.event_port);
}
pub fn isFile(
this: *Dirent,
_: *JSC.JSGlobalObject,
_: *JSC.CallFrame,
) callconv(.C) JSC.JSValue {
- return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.File);
+ return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.file);
}
pub fn isSocket(
this: *Dirent,
_: *JSC.JSGlobalObject,
_: *JSC.CallFrame,
) callconv(.C) JSC.JSValue {
- return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.UnixDomainSocket);
+ return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.unix_domain_socket);
}
pub fn isSymbolicLink(
this: *Dirent,
_: *JSC.JSGlobalObject,
_: *JSC.CallFrame,
) callconv(.C) JSC.JSValue {
- return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.SymLink);
+ return JSC.JSValue.jsBoolean(this.kind == std.fs.File.Kind.sym_link);
}
pub fn finalize(this: *Dirent) callconv(.C) void {
@@ -1490,14 +1490,14 @@ pub const Emitter = struct {
pub fn append(this: *List, allocator: std.mem.Allocator, ctx: JSC.C.JSContextRef, listener: Listener) !void {
JSC.C.JSValueProtect(ctx, listener.callback.asObjectRef());
try this.list.append(allocator, listener);
- this.once_count +|= @as(u32, @boolToInt(listener.once));
+ this.once_count +|= @as(u32, @intFromBool(listener.once));
}
pub fn prepend(this: *List, allocator: std.mem.Allocator, ctx: JSC.C.JSContextRef, listener: Listener) !void {
JSC.C.JSValueProtect(ctx, listener.callback.asObjectRef());
try this.list.ensureUnusedCapacity(allocator, 1);
this.list.insertAssumeCapacity(0, listener);
- this.once_count +|= @as(u32, @boolToInt(listener.once));
+ this.once_count +|= @as(u32, @intFromBool(listener.once));
}
// removeListener() will remove, at most, one instance of a listener from the
@@ -1510,7 +1510,7 @@ pub const Emitter = struct {
for (callbacks, 0..) |item, i| {
if (callback.eqlValue(item)) {
JSC.C.JSValueUnprotect(ctx, callback.asObjectRef());
- this.once_count -|= @as(u32, @boolToInt(this.list.items(.once)[i]));
+ this.once_count -|= @as(u32, @intFromBool(this.list.items(.once)[i]));
this.list.orderedRemove(i);
return true;
}
diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig
index 00cc954ad..2dc4ae1c4 100644
--- a/src/bun.js/test/jest.zig
+++ b/src/bun.js/test/jest.zig
@@ -210,13 +210,13 @@ pub const TestRunner = struct {
const start = @truncate(Test.ID, this.tests.len);
this.tests.len += count;
var statuses = this.tests.items(.status)[start..][0..count];
- std.mem.set(Test.Status, statuses, Test.Status.pending);
+ @memset(statuses, Test.Status.pending);
this.callback.onUpdateCount(this.callback, count, count + start);
return start;
}
pub fn getOrPutFile(this: *TestRunner, file_path: string) *DescribeScope {
- var entry = this.index.getOrPut(this.allocator, @truncate(u32, std.hash.Wyhash.hash(0, file_path))) catch unreachable;
+ var entry = this.index.getOrPut(this.allocator, @truncate(u32, bun.hash(file_path))) catch unreachable;
if (entry.found_existing) {
return this.files.items(.module_scope)[entry.value_ptr.*];
}
@@ -317,7 +317,7 @@ pub const Snapshots = struct {
name_with_counter[name.len] = ' ';
bun.copy(u8, name_with_counter[name.len + 1 ..], counter_string);
- const name_hash = std.hash.Wyhash.hash(0, name_with_counter);
+ const name_hash = bun.hash(name_with_counter);
if (this.values.get(name_hash)) |expected| {
return expected;
}
@@ -416,7 +416,7 @@ pub const Snapshots = struct {
}
const value_clone = try this.allocator.alloc(u8, value.len);
bun.copy(u8, value_clone, value);
- const name_hash = std.hash.Wyhash.hash(0, key);
+ const name_hash = bun.hash(key);
try this.values.put(name_hash, value_clone);
}
}
diff --git a/src/bun.js/test/pretty_format.zig b/src/bun.js/test/pretty_format.zig
index 15ab88799..29e330a04 100644
--- a/src/bun.js/test/pretty_format.zig
+++ b/src/bun.js/test/pretty_format.zig
@@ -362,7 +362,7 @@ pub const JestPrettyFormat = struct {
};
pub fn get(value: JSValue, globalThis: *JSGlobalObject) Result {
- switch (@enumToInt(value)) {
+ switch (@intFromEnum(value)) {
0, 0xa => return Result{
.tag = .Undefined,
},
@@ -921,7 +921,7 @@ pub const JestPrettyFormat = struct {
this.map = this.map_node.?.data;
}
- var entry = this.map.getOrPut(@enumToInt(value)) catch unreachable;
+ var entry = this.map.getOrPut(@intFromEnum(value)) catch unreachable;
if (entry.found_existing) {
writer.writeAll(comptime Output.prettyFmt("<r><cyan>[Circular]<r>", enable_ansi_colors));
return;
@@ -930,7 +930,7 @@ pub const JestPrettyFormat = struct {
defer {
if (comptime Format.canHaveCircularReferences()) {
- _ = this.map.remove(@enumToInt(value));
+ _ = this.map.remove(@intFromEnum(value));
}
}
@@ -1049,7 +1049,7 @@ pub const JestPrettyFormat = struct {
i = -i;
}
const digits = if (i != 0)
- bun.fmt.fastDigitCount(@intCast(usize, i)) + @as(usize, @boolToInt(is_negative))
+ bun.fmt.fastDigitCount(@intCast(usize, i)) + @as(usize, @intFromBool(is_negative))
else
1;
this.addForNewLine(digits);
@@ -1553,7 +1553,7 @@ pub const JestPrettyFormat = struct {
{
this.indent += 1;
defer this.indent -|= 1;
- const count_without_children = props_iter.len - @as(usize, @boolToInt(children_prop != null));
+ const count_without_children = props_iter.len - @as(usize, @intFromBool(children_prop != null));
while (props_iter.next()) |prop| {
if (prop.eqlComptime("children"))
diff --git a/src/bun.js/webcore.zig b/src/bun.js/webcore.zig
index e7357e4ca..a5009e09e 100644
--- a/src/bun.js/webcore.zig
+++ b/src/bun.js/webcore.zig
@@ -663,7 +663,7 @@ pub const Crypto = struct {
) callconv(.C) JSC.JSValue {
var slice = array.slice();
randomData(globalThis, slice.ptr, slice.len);
- return @intToEnum(JSC.JSValue, @bitCast(i64, @ptrToInt(array)));
+ return @enumFromInt(JSC.JSValue, @bitCast(i64, @intFromPtr(array)));
}
fn randomData(
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig
index 9b3ddb8df..d19a2da26 100644
--- a/src/bun.js/webcore/blob.zig
+++ b/src/bun.js/webcore/blob.zig
@@ -546,7 +546,7 @@ 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)));
+ @memset(@ptrCast([*]u8, &fake_call_frame)[0..@sizeOf(@TypeOf(fake_call_frame))], 0);
const blob_value =
source_blob.getSlice(ctx, @ptrCast(*JSC.CallFrame, &fake_call_frame));
@@ -1232,7 +1232,7 @@ pub const Blob = struct {
}).toSystemError();
// assert we never end up reusing the memory
- std.debug.assert(@ptrToInt(this.system_error.?.path.slice().ptr) != @ptrToInt(path_buffer));
+ std.debug.assert(@intFromPtr(this.system_error.?.path.slice().ptr) != @intFromPtr(path_buffer));
callback(this, null_fd);
return;
@@ -1739,12 +1739,12 @@ pub const Blob = struct {
};
const unsupported_directory_error = SystemError{
- .errno = @intCast(c_int, @enumToInt(bun.C.SystemErrno.EISDIR)),
+ .errno = @intCast(c_int, @intFromEnum(bun.C.SystemErrno.EISDIR)),
.message = ZigString.init("That doesn't work on folders"),
.syscall = ZigString.init("fstat"),
};
const unsupported_non_regular_file_error = SystemError{
- .errno = @intCast(c_int, @enumToInt(bun.C.SystemErrno.ENOTSUP)),
+ .errno = @intCast(c_int, @intFromEnum(bun.C.SystemErrno.ENOTSUP)),
.message = ZigString.init("Non-regular files aren't supported yet"),
.syscall = ZigString.init("fstat"),
};
@@ -1978,14 +1978,14 @@ pub const Blob = struct {
}
this.system_error = (JSC.Node.Syscall.Error{
- .errno = @intCast(JSC.Node.Syscall.Error.Int, @enumToInt(linux.E.INVAL)),
+ .errno = @intCast(JSC.Node.Syscall.Error.Int, @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, @enumToInt(errno)),
+ .errno = @intCast(JSC.Node.Syscall.Error.Int, @intFromEnum(errno)),
.syscall = TryWith.tag.get(use).?,
}).toSystemError();
return AsyncIO.asError(errno);
@@ -2000,7 +2000,7 @@ pub const Blob = struct {
}
pub fn doFCopyFile(this: *CopyFile) anyerror!void {
- switch (JSC.Node.Syscall.fcopyfile(this.source_fd, this.destination_fd, os.system.COPYFILE_DATA)) {
+ switch (JSC.Node.Syscall.fcopyfile(this.source_fd, this.destination_fd, os.system.COPYFILE.DATA)) {
.err => |errno| {
this.system_error = errno.toSystemError();
@@ -3816,10 +3816,10 @@ pub const InlineBlob = extern struct {
var bytes_slice = inline_blob.bytes[0..total];
if (first.len > 0)
- @memcpy(bytes_slice.ptr, first.ptr, first.len);
+ @memcpy(bytes_slice[0..first.len], first);
if (second.len > 0)
- @memcpy(bytes_slice.ptr + first.len, second.ptr, second.len);
+ @memcpy(bytes_slice[first.len..][0..second.len], second);
inline_blob.len = @truncate(@TypeOf(inline_blob.len), total);
return inline_blob;
@@ -3834,7 +3834,7 @@ pub const InlineBlob = extern struct {
};
if (data.len > 0)
- @memcpy(&blob.bytes, data.ptr, data.len);
+ @memcpy(blob.bytes[0..data.len], data);
return blob;
}
diff --git a/src/bun.js/webcore/encoding.zig b/src/bun.js/webcore/encoding.zig
index e4b8a4b95..5c8221128 100644
--- a/src/bun.js/webcore/encoding.zig
+++ b/src/bun.js/webcore/encoding.zig
@@ -68,7 +68,7 @@ pub const TextEncoder = struct {
std.debug.assert(result.read == slice.len);
const array_buffer = uint8array.asArrayBuffer(globalThis).?;
std.debug.assert(result.written == array_buffer.len);
- @memcpy(array_buffer.byteSlice().ptr, &buf, result.written);
+ @memcpy(array_buffer.byteSlice()[0..result.written], buf[0..result.written]);
return uint8array;
} else {
const bytes = strings.allocateLatin1IntoUTF8(globalThis.bunVM().allocator, []const u8, slice) catch {
@@ -103,7 +103,7 @@ pub const TextEncoder = struct {
const uint8array = JSC.JSValue.createUninitializedUint8Array(globalThis, 3);
const array_buffer = uint8array.asArrayBuffer(globalThis).?;
const replacement_char = [_]u8{ 239, 191, 189 };
- @memcpy(array_buffer.slice().ptr, &replacement_char, replacement_char.len);
+ @memcpy(array_buffer.slice()[0..replacement_char.len], &replacement_char);
return uint8array;
}
const uint8array = JSC.JSValue.createUninitializedUint8Array(globalThis, result.written);
@@ -111,7 +111,7 @@ pub const TextEncoder = struct {
std.debug.assert(result.read == slice.len);
const array_buffer = uint8array.asArrayBuffer(globalThis).?;
std.debug.assert(result.written == array_buffer.len);
- @memcpy(array_buffer.slice().ptr, &buf, result.written);
+ @memcpy(array_buffer.slice()[0..result.written], buf[0..result.written]);
return uint8array;
} else {
var bytes = strings.toUTF8AllocWithType(
@@ -207,7 +207,7 @@ pub const TextEncoder = struct {
if (array.isEmpty()) {
array = JSC.JSValue.createUninitializedUint8Array(globalThis, length);
array.ensureStillAlive();
- @memcpy(array.asArrayBuffer(globalThis).?.ptr, buf_to_use.ptr, length);
+ @memcpy(array.asArrayBuffer(globalThis).?.ptr[0..length], buf_to_use[0..length]);
}
return array;
@@ -224,7 +224,7 @@ pub const TextEncoder = struct {
var result: strings.EncodeIntoResult = strings.copyUTF16IntoUTF8(output, []const u16, input, false);
if (output.len >= 3 and (result.read == 0 or result.written == 0)) {
const replacement_char = [_]u8{ 239, 191, 189 };
- @memcpy(buf_ptr, &replacement_char, replacement_char.len);
+ @memcpy(buf_ptr[0..replacement_char.len], &replacement_char);
result.read = 1;
result.written = 3;
}
@@ -515,10 +515,10 @@ pub const TextDecoder = struct {
buffer.ensureTotalCapacity(allocator, slice.len) catch unreachable;
buffer.items.len = i;
+ var len = std.mem.sliceAsBytes(slice[0..i]).len;
@memcpy(
- std.mem.sliceAsBytes(buffer.items).ptr,
- std.mem.sliceAsBytes(slice).ptr,
- std.mem.sliceAsBytes(slice[0..i]).len,
+ std.mem.sliceAsBytes(buffer.items)[0..len],
+ std.mem.sliceAsBytes(slice)[0..len],
);
const first_high_surrogate = 0xD800;
@@ -537,10 +537,10 @@ pub const TextDecoder = struct {
const prev = buffer.items.len;
buffer.items.len += count;
// Since this string is freshly allocated, we know it's not going to overlap
+ len = std.mem.sliceAsBytes(remainder[0..count]).len;
@memcpy(
- std.mem.sliceAsBytes(buffer.items[prev..]).ptr,
- std.mem.sliceAsBytes(remainder).ptr,
- std.mem.sliceAsBytes(remainder[0..count]).len,
+ std.mem.sliceAsBytes(buffer.items[prev..])[0..len],
+ std.mem.sliceAsBytes(remainder)[0..len],
);
remainder = remainder[count..];
},
@@ -659,7 +659,7 @@ pub const TextDecoder = struct {
},
EncodingLabel.@"UTF-16LE" => {
- if (std.mem.isAligned(@ptrToInt(buffer_slice.ptr), @alignOf([*]const u16))) {
+ 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);
}
@@ -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 (@intToEnum(JSC.Node.Encoding, encoding)) {
+ return switch (@enumFromInt(JSC.Node.Encoding, 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 (@intToEnum(JSC.Node.Encoding, encoding)) {
+ return switch (@enumFromInt(JSC.Node.Encoding, 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 (@intToEnum(JSC.Node.Encoding, encoding)) {
+ return switch (@enumFromInt(JSC.Node.Encoding, 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 (@intToEnum(JSC.Node.Encoding, encoding)) {
+ return switch (@enumFromInt(JSC.Node.Encoding, 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 (@intToEnum(JSC.Node.Encoding, encoding)) {
+ var slice = switch (@enumFromInt(JSC.Node.Encoding, 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 (@intToEnum(JSC.Node.Encoding, encoding)) {
+ var slice = switch (@enumFromInt(JSC.Node.Encoding, 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 (@intToEnum(JSC.Node.Encoding, encoding)) {
+ return switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
.ucs2 => toString(input, len, globalObject, .utf16le),
.utf16le => toString(input, len, globalObject, .utf16le),
.utf8 => toString(input, len, globalObject, .utf8),
@@ -830,7 +830,7 @@ pub const Encoder = struct {
.latin1 => {
var to = allocator.alloc(u8, len) catch return ZigString.init("Out of memory").toErrorInstance(global);
- @memcpy(to.ptr, input_ptr, to.len);
+ @memcpy(to, input_ptr[0..to.len]);
return ZigString.init(to).toExternalValue(global);
},
@@ -852,7 +852,7 @@ pub const Encoder = struct {
var output_bytes = std.mem.sliceAsBytes(output);
output_bytes[output_bytes.len - 1] = 0;
- @memcpy(output_bytes.ptr, input_ptr, output_bytes.len);
+ @memcpy(output_bytes, input_ptr[0..output_bytes.len]);
return ZigString.toExternalU16(output.ptr, output.len, global);
},
@@ -892,7 +892,7 @@ pub const Encoder = struct {
switch (comptime encoding) {
.buffer => {
const written = @min(len, to_len);
- @memcpy(to_ptr, input, written);
+ @memcpy(to_ptr[0..written], input[0..written]);
return written;
},
@@ -903,7 +903,7 @@ pub const Encoder = struct {
var remain = input[0..written];
if (bun.simdutf.validate.ascii(remain)) {
- @memcpy(to.ptr, remain.ptr, written);
+ @memcpy(to_ptr[0..written], remain[0..written]);
} else {
strings.copyLatin1IntoASCII(to, remain);
}
@@ -919,7 +919,7 @@ pub const Encoder = struct {
if (to_len < 2)
return 0;
- if (std.mem.isAligned(@ptrToInt(to_ptr), @alignOf([*]u16))) {
+ 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];
@@ -1065,14 +1065,14 @@ pub const Encoder = struct {
switch (comptime encoding) {
.buffer => {
var to = allocator.alloc(u8, len) catch return &[_]u8{};
- @memcpy(to.ptr, input, len);
+ @memcpy(to[0..len], input[0..len]);
return to;
},
.latin1, .ascii => {
var to = allocator.alloc(u8, len) catch return &[_]u8{};
- @memcpy(to.ptr, input, len);
+ @memcpy(to[0..len], input[0..len]);
return to;
},
@@ -1121,7 +1121,7 @@ pub const Encoder = struct {
.latin1, .buffer, .ascii => {
var to = allocator.alloc(u8, len) catch return &[_]u8{};
var input_bytes = std.mem.sliceAsBytes(input[0..len]);
- @memcpy(to.ptr, input_bytes.ptr, input_bytes.len);
+ @memcpy(to[0..input_bytes.len], input_bytes);
for (to[0..len], 0..) |c, i| {
to[i] = @as(u8, @truncate(u7, c));
}
@@ -1131,7 +1131,8 @@ pub const Encoder = struct {
// string is already encoded, just need to copy the data
.ucs2, .utf16le => {
var to = std.mem.sliceAsBytes(allocator.alloc(u16, len * 2) catch return &[_]u8{});
- @memcpy(to.ptr, std.mem.sliceAsBytes(input[0..len]).ptr, std.mem.sliceAsBytes(input[0..len]).len);
+ const bytes = std.mem.sliceAsBytes(input[0..len]);
+ @memcpy(to[0..bytes.len], bytes);
return to;
},
diff --git a/src/bun.js/webcore/request.zig b/src/bun.js/webcore/request.zig
index a8c648212..231f0deed 100644
--- a/src/bun.js/webcore/request.zig
+++ b/src/bun.js/webcore/request.zig
@@ -472,8 +472,8 @@ pub const Request = struct {
url_or_object,
if (is_first_argument_a_url) JSValue.undefined else url_or_object,
};
- const values_to_try = values_to_try_[0 .. @as(usize, @boolToInt(!is_first_argument_a_url)) +
- @as(usize, @boolToInt(arguments.len > 1 and arguments[1].isObject()))];
+ const values_to_try = values_to_try_[0 .. @as(usize, @intFromBool(!is_first_argument_a_url)) +
+ @as(usize, @intFromBool(arguments.len > 1 and arguments[1].isObject()))];
for (values_to_try) |value| {
const value_type = value.jsType();
@@ -564,7 +564,7 @@ pub const Request = struct {
fields.insert(.url);
// first value
- } else if (@enumToInt(value) == @enumToInt(values_to_try[values_to_try.len - 1]) and !is_first_argument_a_url and
+ } else if (@intFromEnum(value) == @intFromEnum(values_to_try[values_to_try.len - 1]) and !is_first_argument_a_url and
value.implementsToString(globalThis))
{
const slice = value.toSliceOrNull(globalThis) orelse {
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig
index beae4d182..b4ea08579 100644
--- a/src/bun.js/webcore/response.zig
+++ b/src/bun.js/webcore/response.zig
@@ -386,7 +386,7 @@ pub const Response = struct {
const json_value = args.nextEat() orelse JSC.JSValue.zero;
- if (@enumToInt(json_value) != 0) {
+ if (@intFromEnum(json_value) != 0) {
var zig_str = JSC.ZigString.init("");
// calling JSON.stringify on an empty string adds extra quotes
// so this is correct
@@ -448,7 +448,7 @@ pub const Response = struct {
const url_string_value = args.nextEat() orelse JSC.JSValue.zero;
var url_string = ZigString.init("");
- if (@enumToInt(url_string_value) != 0) {
+ if (@intFromEnum(url_string_value) != 0) {
url_string = url_string_value.getZigString(globalThis.ptr());
}
var url_string_slice = url_string.toSlice(getAllocator(globalThis));
@@ -1147,9 +1147,9 @@ pub const Fetch = struct {
JSC.JSError(bun.default_allocator, "Out of memory", .{}, ctx, exception);
return .zero;
};
- @memcpy(buffer.ptr, url_slice.ptr, url_slice.len);
+ @memcpy(buffer[0..url_slice.len], url_slice);
var proxy_url_slice = buffer[url_slice.len..];
- @memcpy(proxy_url_slice.ptr, proxy_url_zig.ptr, proxy_url_zig.len);
+ @memcpy(proxy_url_slice[0..proxy_url_zig.len], proxy_url_zig.ptr[0..proxy_url_zig.len]);
url = ZigURL.parse(buffer[0..url_slice.len]);
proxy = ZigURL.parse(proxy_url_slice);
@@ -1283,9 +1283,9 @@ pub const Fetch = struct {
JSC.JSError(bun.default_allocator, "Out of memory", .{}, ctx, exception);
return .zero;
};
- @memcpy(buffer.ptr, url_slice.ptr, url_slice.len);
+ @memcpy(buffer[0..url_slice.len], url_slice.ptr[0..url_slice.len]);
var proxy_url_slice = buffer[url_slice.len..];
- @memcpy(proxy_url_slice.ptr, proxy_url_zig.ptr, proxy_url_zig.len);
+ @memcpy(proxy_url_slice[0..proxy_url_zig.len], proxy_url_zig.ptr[0..proxy_url_zig.len]);
url = ZigURL.parse(buffer[0..url_slice.len]);
proxy = ZigURL.parse(proxy_url_slice);
@@ -1695,7 +1695,7 @@ pub const FetchEvent = struct {
defer {
if (!VirtualMachine.get().had_errors) {
- Output.printElapsed(@intToFloat(f64, (request_context.timer.lap())) / std.time.ns_per_ms);
+ Output.printElapsed(@floatFromInt(f64, (request_context.timer.lap())) / std.time.ns_per_ms);
Output.prettyError(
" <b>{s}<r><d> - <b>{d}<r> <d>transpiled, <d><b>{d}<r> <d>imports<r>\n",
diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig
index dddfcbaf5..5986afac7 100644
--- a/src/bun.js/webcore/streams.zig
+++ b/src/bun.js/webcore/streams.zig
@@ -247,7 +247,7 @@ pub const ReadableStream = struct {
pub fn fromNative(globalThis: *JSGlobalObject, id: Tag, ptr: *anyopaque) JSC.JSValue {
JSC.markBinding(@src());
- return ZigGlobalObject__createNativeReadableStream(globalThis, JSValue.fromPtr(ptr), JSValue.jsNumber(@enumToInt(id)));
+ return ZigGlobalObject__createNativeReadableStream(globalThis, JSValue.fromPtr(ptr), JSValue.jsNumber(@intFromEnum(id)));
}
pub fn fromBlob(globalThis: *JSGlobalObject, blob: *const Blob, recommended_chunk_size: Blob.SizeType) JSC.JSValue {
@@ -329,11 +329,11 @@ pub const ReadableStream = struct {
const filedes_ = @bitCast([8]u8, @as(usize, @truncate(u56, @intCast(usize, filedes))));
bytes[1..8].* = filedes_[0..7].*;
- return @intToEnum(StreamTag, @bitCast(u64, bytes));
+ return @enumFromInt(StreamTag, @bitCast(u64, bytes));
}
pub fn fd(this: StreamTag) bun.FileDescriptor {
- var bytes = @bitCast([8]u8, @enumToInt(this));
+ var bytes = @bitCast([8]u8, @intFromEnum(this));
if (bytes[0] != 1) {
return bun.invalid_fd;
}
@@ -780,13 +780,15 @@ pub const StreamResult = union(Tag) {
.temporary => |temp| {
var array = JSC.JSValue.createUninitializedUint8Array(globalThis, temp.len);
var slice_ = array.asArrayBuffer(globalThis).?.slice();
- @memcpy(slice_.ptr, temp.ptr, temp.len);
+ const temp_slice = temp.slice();
+ @memcpy(slice_[0..temp_slice.len], temp_slice);
return array;
},
.temporary_and_done => |temp| {
var array = JSC.JSValue.createUninitializedUint8Array(globalThis, temp.len);
var slice_ = array.asArrayBuffer(globalThis).?.slice();
- @memcpy(slice_.ptr, temp.ptr, temp.len);
+ const temp_slice = temp.slice();
+ @memcpy(slice_[0..temp_slice.len], temp_slice);
return array;
},
.into_array => |array| {
@@ -818,7 +820,7 @@ pub const Signal = struct {
ptr: *anyopaque = dead,
vtable: VTable = VTable.Dead,
- pub const dead = @intToPtr(*anyopaque, 0xaaaaaaaa);
+ pub const dead = @ptrFromInt(*anyopaque, 0xaaaaaaaa);
pub fn clear(this: *Signal) void {
this.ptr = dead;
@@ -920,7 +922,7 @@ pub const Sink = struct {
used: bool = false,
pub const pending = Sink{
- .ptr = @intToPtr(*anyopaque, 0xaaaaaaaa),
+ .ptr = @ptrFromInt(*anyopaque, 0xaaaaaaaa),
.vtable = undefined,
};
@@ -961,7 +963,8 @@ pub const Sink = struct {
if (stack_size >= str.len) {
var buf: [stack_size]u8 = undefined;
- @memcpy(&buf, str.ptr, str.len);
+ @memcpy(buf[0..str.len], str);
+
strings.replaceLatin1WithUTF8(buf[0..str.len]);
if (input.isDone()) {
const result = writeFn(ctx, .{ .temporary_and_done = bun.ByteList.init(buf[0..str.len]) });
@@ -974,7 +977,8 @@ pub const Sink = struct {
{
var slice = bun.default_allocator.alloc(u8, str.len) catch return .{ .err = Syscall.Error.oom };
- @memcpy(slice.ptr, str.ptr, str.len);
+ @memcpy(slice[0..str.len], str);
+
strings.replaceLatin1WithUTF8(slice[0..str.len]);
if (input.isDone()) {
return writeFn(ctx, .{ .owned_and_done = bun.ByteList.init(slice) });
@@ -1262,7 +1266,7 @@ pub const FileSink = struct {
const initial_remain = remain;
defer {
- std.debug.assert(total - initial == @ptrToInt(remain.ptr) - @ptrToInt(initial_remain.ptr));
+ std.debug.assert(total - initial == @intFromPtr(remain.ptr) - @intFromPtr(initial_remain.ptr));
if (remain.len == 0) {
this.head = 0;
@@ -1908,15 +1912,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, @intToPtr(*SinkSignal, @bitCast(usize, @enumToInt(cpp))));
+ return Signal.initWithType(SinkSignal, @ptrFromInt(*SinkSignal, @bitCast(usize, @intFromEnum(cpp))));
}
pub fn close(this: *@This(), _: ?Syscall.Error) void {
- onClose(@bitCast(SinkSignal, @ptrToInt(this)).cpp, JSValue.jsUndefined());
+ onClose(@bitCast(SinkSignal, @intFromPtr(this)).cpp, JSValue.jsUndefined());
}
pub fn ready(this: *@This(), _: ?Blob.SizeType, _: ?Blob.SizeType) void {
- onReady(@bitCast(SinkSignal, @ptrToInt(this)).cpp, JSValue.jsUndefined(), JSValue.jsUndefined());
+ onReady(@bitCast(SinkSignal, @intFromPtr(this)).cpp, JSValue.jsUndefined(), JSValue.jsUndefined());
}
pub fn start(_: *@This()) void {}
@@ -1992,7 +1996,7 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
if (this.sink.signal.isDead())
return;
this.sink.signal.clear();
- const value = @intToEnum(JSValue, @bitCast(JSC.JSValueReprInt, @ptrToInt(ptr)));
+ const value = @enumFromInt(JSValue, @bitCast(JSC.JSValueReprInt, @intFromPtr(ptr)));
value.unprotect();
detachPtr(value);
}
@@ -3127,7 +3131,7 @@ pub const ByteBlobLoader = struct {
this.remain -|= copied;
this.offset +|= copied;
std.debug.assert(buffer.ptr != temporary.ptr);
- @memcpy(buffer.ptr, temporary.ptr, temporary.len);
+ @memcpy(buffer[0..temporary.len], temporary);
if (this.remain == 0) {
return .{ .into_array_and_done = .{ .value = array, .len = copied } };
}
@@ -3231,7 +3235,7 @@ pub const ByteStream = struct {
}
if (this.has_received_last_chunk) {
- return .{ .chunk_size = @truncate(Blob.SizeType, @min(1024 * 1024 * 2, this.buffer.items.len)) };
+ return .{ .chunk_size = @min(1024 * 1024 * 2, this.buffer.items.len) };
}
if (this.highWaterMark == 0) {
@@ -3292,7 +3296,7 @@ pub const ByteStream = struct {
var to_copy = this.pending_buffer[0..@min(chunk.len, this.pending_buffer.len)];
const pending_buffer_len = this.pending_buffer.len;
std.debug.assert(to_copy.ptr != chunk.ptr);
- @memcpy(to_copy.ptr, chunk.ptr, to_copy.len);
+ @memcpy(to_copy, chunk[0..to_copy.len]);
this.pending_buffer = &.{};
const is_really_done = this.has_received_last_chunk and to_copy.len <= pending_buffer_len;
@@ -3382,7 +3386,7 @@ pub const ByteStream = struct {
);
var remaining_in_buffer = this.buffer.items[this.offset..][0..to_write];
- @memcpy(buffer.ptr, this.buffer.items.ptr + this.offset, to_write);
+ @memcpy(buffer[0..to_write], this.buffer.items[this.offset..][0..to_write]);
if (this.offset + to_write == this.buffer.items.len) {
this.offset = 0;
@@ -4071,7 +4075,7 @@ pub const File = struct {
this.pending.result = .{
.err = Syscall.Error{
// this is too hacky
- .errno = @truncate(Syscall.Error.Int, @intCast(u16, @max(1, @errorToInt(err)))),
+ .errno = @truncate(Syscall.Error.Int, @intCast(u16, @max(1, @intFromError(err)))),
.syscall = .read,
},
};
@@ -4655,4 +4659,3 @@ pub fn NewReadyWatcher(
// pub fn onError(this: *Streamer): anytype,
// };
// }
-