diff options
-rw-r--r-- | src/bun.js/bindings/bindings.zig | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index c8d0515e9..7e3fa6d8e 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -4597,13 +4597,20 @@ pub const JSValue = enum(JSValueReprInt) { return FFI.JSVALUE_TO_BOOL(.{ .asJSValue = this }); } + pub inline fn asInt52(this: JSValue) i64 { + if (comptime bun.Environment.allow_assert) { + std.debug.assert(this.isNumber()); + } + return @intFromFloat(i64, @max(@min(this.asDouble(), std.math.maxInt(i52)), std.math.minInt(i52))); + } + pub fn toInt32(this: JSValue) i32 { if (this.isInt32()) { return asInt32(this); } if (this.isNumber()) { - return @truncate(i32, @intFromFloat(i64, asDouble(this))); + return @truncate(i32, this.asInt52()); } if (comptime bun.Environment.allow_assert) { |