diff options
author | 2023-08-08 03:30:05 -0300 | |
---|---|---|
committer | 2023-08-07 23:30:05 -0700 | |
commit | 182e600eb79655e85b3f0371bc46fc4de8e70094 (patch) | |
tree | b91231bc9155cc769cc81a7b2f0892c47bd26d2c /src/bun.js/api/bun.zig | |
parent | cb873cc0818d02216ac7285c58fe59883220d1a9 (diff) | |
download | bun-182e600eb79655e85b3f0371bc46fc4de8e70094.tar.gz bun-182e600eb79655e85b3f0371bc46fc4de8e70094.tar.zst bun-182e600eb79655e85b3f0371bc46fc4de8e70094.zip |
Fix `Bun.hash` functions (#4054)
* fix `Bun.hash` functions to behave as expected
* update Bun.hash tests
* properly test the returned hash
* include murmur32v2
* update Bun.hash docs
* run fmt
Diffstat (limited to 'src/bun.js/api/bun.zig')
-rw-r--r-- | src/bun.js/api/bun.zig | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig index 5210063ea..fe0aafc25 100644 --- a/src/bun.js/api/bun.zig +++ b/src/bun.js/api/bun.zig @@ -3192,24 +3192,24 @@ pub const Hash = struct { } else { var seed: u64 = 0; if (args.nextEat()) |arg| { - if (arg.isNumber()) { - seed = arg.toU32(); + if (arg.isNumber() or arg.isBigInt()) { + seed = arg.toUInt64NoTruncate(); } } if (comptime std.meta.trait.isNumber(@TypeOf(function_args[0]))) { - function_args[0] = @as(@TypeOf(function_args[0]), @intCast(seed)); + function_args[0] = @as(@TypeOf(function_args[0]), @truncate(seed)); function_args[1] = input; } else { - function_args[1] = @as(@TypeOf(function_args[1]), @intCast(seed)); function_args[0] = input; + function_args[1] = @as(@TypeOf(function_args[1]), @truncate(seed)); } const value = @call(.auto, Function, function_args); if (@TypeOf(value) == u32) { - return JSC.JSValue.jsNumber(@as(i32, @bitCast(value))).asObjectRef(); + return JSC.JSValue.jsNumber(@as(u32, @bitCast(value))).asObjectRef(); } - return JSC.JSValue.jsNumber(value).asObjectRef(); + return JSC.JSValue.fromUInt64NoTruncate(ctx.ptr(), value).asObjectRef(); } } }; |