diff options
-rw-r--r-- | src/javascript/jsc/ffi.exports.js | 16 | ||||
-rw-r--r-- | types/bun/ffi.d.ts | 4 |
2 files changed, 8 insertions, 12 deletions
diff --git a/src/javascript/jsc/ffi.exports.js b/src/javascript/jsc/ffi.exports.js index ae11326e5..1aa9eee51 100644 --- a/src/javascript/jsc/ffi.exports.js +++ b/src/javascript/jsc/ffi.exports.js @@ -76,13 +76,11 @@ ffiWrappers[FFIType.i64_fast] = function int64(val) { if (val < BigInt(Number.MAX_VALUE)) { return Number(val).valueOf() || 0; } - } - if (!val) { - return 0; + return val; } - return +val || 0; + return !val ? 0 : +val || 0; }; ffiWrappers[FFIType.u64_fast] = function u64_fast(val) { @@ -90,13 +88,11 @@ ffiWrappers[FFIType.u64_fast] = function u64_fast(val) { if (val < BigInt(Number.MAX_VALUE) && val > 0) { return Number(val).valueOf() || 0; } - } - if (!val) { - return 0; + return val; } - return +val || 0; + return !val ? 0 : +val || 0; }; ffiWrappers[FFIType.int64_t] = function int64(val) { @@ -105,7 +101,7 @@ ffiWrappers[FFIType.int64_t] = function int64(val) { } if (typeof val === "number") { - return BigInt(val); + return BigInt(val || 0); } return BigInt(+val || 0); @@ -117,7 +113,7 @@ ffiWrappers[FFIType.uint64_t] = function uint64(val) { } if (typeof val === "number") { - return val <= 0 ? BigInt(0) : BigInt(val); + return val <= 0 ? BigInt(0) : BigInt(val || 0); } return BigInt(+val || 0); diff --git a/types/bun/ffi.d.ts b/types/bun/ffi.d.ts index f27cbe551..688fb68b3 100644 --- a/types/bun/ffi.d.ts +++ b/types/bun/ffi.d.ts @@ -460,7 +460,7 @@ declare module "bun:ffi" { close(): void; } - export function dlopen(libraryName: string, symbols: Symbols): Library<T>; + export function dlopen(libraryName: string, symbols: Symbols): Library; /** * Read a pointer as a {@link Buffer} @@ -586,7 +586,7 @@ declare module "bun:ffi" { * reading beyond the bounds of the pointer will crash the program or cause * undefined behavior. Use with care! */ - constructor(ptr: number, byteOffset?: number, byteLength?: number): string; + constructor(ptr: number, byteOffset?: number, byteLength?: number); /** * The ptr to the C string |