aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/api/FFI.h6
-rw-r--r--src/bun.js/ffi.exports.js2
2 files changed, 7 insertions, 1 deletions
diff --git a/src/bun.js/api/FFI.h b/src/bun.js/api/FFI.h
index d7776dd23..bbe13bb5a 100644
--- a/src/bun.js/api/FFI.h
+++ b/src/bun.js/api/FFI.h
@@ -148,11 +148,17 @@ static bool JSVALUE_IS_NUMBER(EncodedJSValue val) {
static void* JSVALUE_TO_PTR(EncodedJSValue val) {
// must be a double
+ if (val.asInt64 == TagValueNull)
+ return 0;
return (void*)(val.asInt64 - DoubleEncodeOffset);
}
static EncodedJSValue PTR_TO_JSVALUE(void* ptr) {
EncodedJSValue val;
+ if (ptr == 0) {
+ val.asInt64 = TagValueNull;
+ return val;
+ }
val.asInt64 = (int64_t)ptr + DoubleEncodeOffset;
return val;
}
diff --git a/src/bun.js/ffi.exports.js b/src/bun.js/ffi.exports.js
index f149cc0a9..52dd6d0d4 100644
--- a/src/bun.js/ffi.exports.js
+++ b/src/bun.js/ffi.exports.js
@@ -175,7 +175,7 @@ ffiWrappers[FFIType.cstring] = ffiWrappers[FFIType.pointer] = function pointer(
) {
if (typeof val === "number") return val;
if (!val) {
- return 0;
+ return null;
}
if (ArrayBuffer.isView(val) || val instanceof ArrayBuffer) {