diff options
Diffstat (limited to 'src/bun.js/base.zig')
-rw-r--r-- | src/bun.js/base.zig | 68 |
1 files changed, 36 insertions, 32 deletions
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 { |