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.h27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/bun.js/api/FFI.h b/src/bun.js/api/FFI.h
index 468f9a0fc..a42228588 100644
--- a/src/bun.js/api/FFI.h
+++ b/src/bun.js/api/FFI.h
@@ -146,17 +146,31 @@ static bool JSVALUE_IS_NUMBER(EncodedJSValue val) {
}
+// JSValue numbers-as-pointers are represented as a 52-bit integer
+// Previously, the pointer was stored at the end of the 64-bit value
+// Now, they're stored at the beginning of the 64-bit value
+// 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) {
- // must be a double
- return val.asInt64 == TagValueNull ? 0 : (void*)(val.asInt64 - DoubleEncodeOffset);
+ val.asInt64 -= DoubleEncodeOffset;
+ size_t ptr = (size_t)val.asDouble;
+ return (void*)ptr;
}
static EncodedJSValue PTR_TO_JSVALUE(void* ptr) {
EncodedJSValue val;
- val.asInt64 = ptr == 0 ? TagValueNull : (int64_t)ptr + DoubleEncodeOffset;
+ val.asPtr = ptr;
+ val.asInt64 += DoubleEncodeOffset;
return val;
}
+static EncodedJSValue DOUBLE_TO_JSVALUE(double val) {
+ EncodedJSValue res;
+ res.asDouble = val;
+ res.asInt64 += DoubleEncodeOffset;
+ return res;
+}
+
static int32_t JSVALUE_TO_INT32(EncodedJSValue val) {
return val.asInt64;
}
@@ -168,12 +182,7 @@ static EncodedJSValue INT32_TO_JSVALUE(int32_t val) {
}
-static EncodedJSValue DOUBLE_TO_JSVALUE(double val) {
- EncodedJSValue res;
- res.asDouble = val;
- res.asInt64 += DoubleEncodeOffset;
- return res;
-}
+
static EncodedJSValue FLOAT_TO_JSVALUE(float val) {
return DOUBLE_TO_JSVALUE((double)val);