Skip to content

Commit

Permalink
Fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed May 4, 2022
1 parent 5b760fe commit 6ab5ae8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
16 changes: 6 additions & 10 deletions src/javascript/jsc/ffi.exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,23 @@ 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) {
if (typeof val === "bigint") {
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) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions types/bun/ffi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6ab5ae8

Please sign in to comment.