aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/api
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/api
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/api')
-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
9 files changed, 107 insertions, 107 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;
}
}