diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/api/FFI.h | 10 | ||||
-rw-r--r-- | src/bun.js/api/ffi.zig | 4 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/bun.js/api/FFI.h b/src/bun.js/api/FFI.h index a42228588..1233e3e2e 100644 --- a/src/bun.js/api/FFI.h +++ b/src/bun.js/api/FFI.h @@ -152,6 +152,8 @@ static bool JSVALUE_IS_NUMBER(EncodedJSValue val) { // This behavior change enables the JIT to handle it better // It also is better readability when console.log(myPtr) static void* JSVALUE_TO_PTR(EncodedJSValue val) { + if (val.asInt64 == TagValueNull) + return 0; val.asInt64 -= DoubleEncodeOffset; size_t ptr = (size_t)val.asDouble; return (void*)ptr; @@ -159,7 +161,13 @@ static void* JSVALUE_TO_PTR(EncodedJSValue val) { static EncodedJSValue PTR_TO_JSVALUE(void* ptr) { EncodedJSValue val; - val.asPtr = ptr; + if (ptr == 0) + { + val.asInt64 = TagValueNull; + return val; + } + + val.asDouble = (double)(size_t)ptr; val.asInt64 += DoubleEncodeOffset; return val; } diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig index 30d5a7085..14d5644c5 100644 --- a/src/bun.js/api/ffi.zig +++ b/src/bun.js/api/ffi.zig @@ -131,7 +131,7 @@ pub const FFI = struct { .compiled => { var function_ = bun.default_allocator.create(Function) catch unreachable; function_.* = func.*; - return JSC.JSValue.jsNumber(@bitCast(f64, @as(usize, @ptrToInt(function_.step.compiled.ptr)))); + return JSC.JSValue.fromPtrAddress(@ptrToInt(function_.step.compiled.ptr)); }, } } @@ -572,7 +572,7 @@ pub const FFI = struct { if (value.get(global, "ptr")) |ptr| { if (ptr.isNumber()) { - const num = @bitCast(usize, ptr.asNumber()); + const num = ptr.asPtrAddress(); if (num > 0) function.symbol_from_dynamic_library = @intToPtr(*anyopaque, num); } else { |