aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/javascript.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/javascript.zig')
-rw-r--r--src/bun.js/javascript.zig62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index 2e6d61952..fb855e047 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -119,7 +119,7 @@ pub const OpaqueCallback = *const fn (current: ?*anyopaque) callconv(.C) void;
pub fn OpaqueWrap(comptime Context: type, comptime Function: fn (this: *Context) void) OpaqueCallback {
return struct {
pub fn callback(ctx: ?*anyopaque) callconv(.C) void {
- var context: *Context = @ptrCast(*Context, @alignCast(@alignOf(Context), ctx.?));
+ var context: *Context = @as(*Context, @ptrCast(@alignCast(ctx.?)));
@call(.auto, Function, .{context});
}
}.callback;
@@ -142,7 +142,7 @@ pub const SavedSourceMap = struct {
}
pub inline fn len(this: SavedMappings) usize {
- return @bitCast(u64, this.data[0..8].*);
+ return @as(u64, @bitCast(this.data[0..8].*));
}
pub fn deinit(this: SavedMappings) void {
@@ -153,7 +153,7 @@ pub const SavedSourceMap = struct {
const result = SourceMap.Mapping.parse(
allocator,
this.data[16..this.len()],
- @bitCast(usize, this.data[8..16].*),
+ @as(usize, @bitCast(this.data[8..16].*)),
1,
);
switch (result) {
@@ -203,7 +203,7 @@ pub const SavedSourceMap = struct {
var source_map: *MappingList = source_map_;
source_map.deinit(default_allocator);
} else if (value.get(SavedMappings)) |saved_mappings| {
- var saved = SavedMappings{ .data = @ptrCast([*]u8, saved_mappings) };
+ var saved = SavedMappings{ .data = @as([*]u8, @ptrCast(saved_mappings)) };
saved.deinit();
}
@@ -219,7 +219,7 @@ pub const SavedSourceMap = struct {
return Value.from(mapping.value_ptr.*).as(MappingList).*;
},
Value.Tag.SavedMappings => {
- var saved = SavedMappings{ .data = @ptrCast([*]u8, Value.from(mapping.value_ptr.*).as(MappingList)) };
+ var saved = SavedMappings{ .data = @as([*]u8, @ptrCast(Value.from(mapping.value_ptr.*).as(MappingList))) };
defer saved.deinit();
var result = default_allocator.create(MappingList) catch unreachable;
result.* = saved.toMapping(default_allocator, path) catch {
@@ -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, (@floatFromInt(f64, vm.origin_timestamp) + JSC.VirtualMachine.origin_relative_epoch) / 1_000_000.0);
+ return @as(f64, @floatCast((@as(f64, @floatFromInt(vm.origin_timestamp)) + JSC.VirtualMachine.origin_relative_epoch) / 1_000_000.0));
}
// comptime {
@@ -794,16 +794,16 @@ pub const VirtualMachine = struct {
/// We subtract the timestamp from Jan 1, 2000 (Y2K)
pub const origin_relative_epoch = 946684800 * std.time.ns_per_s;
fn getOriginTimestamp() u64 {
- return @truncate(
+ return @as(
u64,
- @intCast(
+ @truncate(@as(
u128,
// handle if they set their system clock to be before epoch
- @max(
+ @intCast(@max(
std.time.nanoTimestamp(),
origin_relative_epoch,
- ),
- ) - origin_relative_epoch,
+ )),
+ ) - origin_relative_epoch),
);
}
@@ -883,7 +883,7 @@ pub const VirtualMachine = struct {
}
vm.global = ZigGlobalObject.create(
&global_classes,
- @intCast(i32, global_classes.len),
+ @as(i32, @intCast(global_classes.len)),
vm.console,
-1,
false,
@@ -985,7 +985,7 @@ pub const VirtualMachine = struct {
}
vm.global = ZigGlobalObject.create(
&global_classes,
- @intCast(i32, global_classes.len),
+ @as(i32, @intCast(global_classes.len)),
vm.console,
-1,
smol,
@@ -1087,9 +1087,9 @@ pub const VirtualMachine = struct {
}
vm.global = ZigGlobalObject.create(
&global_classes,
- @intCast(i32, global_classes.len),
+ @as(i32, @intCast(global_classes.len)),
vm.console,
- @intCast(i32, worker.execution_context_id),
+ @as(i32, @intCast(worker.execution_context_id)),
worker.mini,
);
vm.regular_event_loop.global = vm.global;
@@ -1402,7 +1402,7 @@ pub const VirtualMachine = struct {
var vm_ = globalObject.bunVM();
if (vm_.global == globalObject) {
- vm_.enqueueTask(Task.init(@ptrCast(*JSC.MicrotaskForDefaultGlobalObject, microtask)));
+ vm_.enqueueTask(Task.init(@as(*JSC.MicrotaskForDefaultGlobalObject, @ptrCast(microtask))));
} else {
vm_.enqueueTask(Task.init(microtask));
}
@@ -1685,7 +1685,7 @@ pub const VirtualMachine = struct {
err,
globalThis.createAggregateError(
errors.ptr,
- @intCast(u16, errors.len),
+ @as(u16, @intCast(errors.len)),
&ZigString.init(
std.fmt.allocPrint(globalThis.allocator(), "{d} errors building \"{}\"", .{
errors.len,
@@ -1730,7 +1730,7 @@ pub const VirtualMachine = struct {
this.last_reported_error_for_dedupe = result;
if (result.isException(this.global.vm())) {
- var exception = @ptrCast(*Exception, result.asVoid());
+ var exception = @as(*Exception, @ptrCast(result.asVoid()));
this.printException(
exception,
@@ -2001,7 +2001,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_ = @ptrFromInt(*@This(), @intFromPtr(ctx));
+ var this_ = @as(*@This(), @ptrFromInt(@intFromPtr(ctx)));
VirtualMachine.get().printErrorlikeObject(nextValue, null, this_.current_exception_list, Writer, this_.writer, color, allow_side_effects);
}
};
@@ -2099,7 +2099,7 @@ pub const VirtualMachine = struct {
const dir = vm.bundler.fs.top_level_dir;
while (i < stack.len) : (i += 1) {
- const frame = stack[@intCast(usize, i)];
+ const frame = stack[@as(usize, @intCast(i))];
const file_slice = frame.source_url.toUTF8(bun.default_allocator);
defer file_slice.deinit();
const func_slice = frame.function_name.toUTF8(bun.default_allocator);
@@ -2215,7 +2215,7 @@ pub const VirtualMachine = struct {
frames[j] = frame;
j += 1;
}
- exception.stack.frames_len = @truncate(u8, j);
+ exception.stack.frames_len = @as(u8, @truncate(j));
frames.len = j;
}
}
@@ -2249,7 +2249,7 @@ pub const VirtualMachine = struct {
if (strings.getLinesInText(
code.slice(),
- @intCast(u32, top.position.line),
+ @as(u32, @intCast(top.position.line)),
JSC.ZigException.Holder.source_lines_count,
)) |lines| {
var source_lines = exception.stack.source_lines_ptr[0..JSC.ZigException.Holder.source_lines_count];
@@ -2260,12 +2260,12 @@ pub const VirtualMachine = struct {
var lines_ = lines[0..@min(lines.len, source_lines.len)];
for (lines_, 0..) |line, j| {
source_lines[(lines_.len - 1) - j] = String.init(line);
- source_line_numbers[j] = top.position.line - @intCast(i32, j) + 1;
+ source_line_numbers[j] = top.position.line - @as(i32, @intCast(j)) + 1;
}
- exception.stack.source_lines_len = @intCast(u8, lines_.len);
+ exception.stack.source_lines_len = @as(u8, @intCast(lines_.len));
- top.position.column_stop = @intCast(i32, source_lines[lines_.len - 1].length());
+ top.position.column_stop = @as(i32, @intCast(source_lines[lines_.len - 1].length()));
top.position.line_stop = top.position.column_stop;
// This expression range is no longer accurate
@@ -2372,11 +2372,11 @@ pub const VirtualMachine = struct {
);
if (!top.position.isInvalid()) {
- var first_non_whitespace = @intCast(u32, top.position.column_start);
+ var first_non_whitespace = @as(u32, @intCast(top.position.column_start));
while (first_non_whitespace < text.len and text[first_non_whitespace] == ' ') {
first_non_whitespace += 1;
}
- const indent = @intCast(usize, pad) + " | ".len + first_non_whitespace;
+ const indent = @as(usize, @intCast(pad)) + " | ".len + first_non_whitespace;
try writer.writeByteNTimes(' ', indent);
try writer.print(comptime Output.prettyFmt(
@@ -2572,7 +2572,7 @@ pub const EventListenerMixin = struct {
const FetchEventRejectionHandler = struct {
pub fn onRejection(_ctx: *anyopaque, err: anyerror, fetch_event: *FetchEvent, value: JSValue) void {
onError(
- @ptrFromInt(*CtxType, @intFromPtr(_ctx)),
+ @as(*CtxType, @ptrFromInt(@intFromPtr(_ctx))),
err,
value,
fetch_event.request_context.?,
@@ -2940,7 +2940,7 @@ pub fn NewHotReloader(comptime Ctx: type, comptime EventLoopType: type, comptime
var path_string: bun.PathString = undefined;
var file_hash: @This().Watcher.HashType = last_file_hash;
const abs_path: string = brk: {
- if (dir_ent.entries.get(@ptrCast([]const u8, changed_name))) |file_ent| {
+ if (dir_ent.entries.get(@as([]const u8, @ptrCast(changed_name)))) |file_ent| {
// reset the file descriptor
file_ent.entry.cache.fd = 0;
file_ent.entry.need_stat = true;
@@ -2950,9 +2950,9 @@ pub fn NewHotReloader(comptime Ctx: type, comptime EventLoopType: type, comptime
if (hash == file_hash) {
if (file_descriptors[entry_id] != 0) {
if (prev_entry_id != entry_id) {
- current_task.append(@truncate(u32, entry_id));
+ current_task.append(@as(u32, @truncate(entry_id)));
ctx.removeAtIndex(
- @truncate(u16, entry_id),
+ @as(u16, @truncate(entry_id)),
0,
&.{},
.file,