aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/api/FFI.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/api/FFI.h')
-rw-r--r--src/bun.js/api/FFI.h10
1 files changed, 9 insertions, 1 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;
}