summaryrefslogtreecommitdiff
path: root/ext/ffi/00_ffi.js
diff options
context:
space:
mode:
authorAapo Alasuutari <aapo.alasuutari@gmail.com>2022-10-13 15:06:52 +0300
committerGitHub <noreply@github.com>2022-10-13 17:36:52 +0530
commit17271532d4dcf8dfee1c7b1ac9dbdacb0a04deeb (patch)
tree45943106d7d7db741dbce2943c2204eec743e238 /ext/ffi/00_ffi.js
parentfda24b54e955c341c37ee29fbe59d9f7580e25e1 (diff)
fix(ext/ffi): Invalid 'function' return type check logic, remove U32x2 as unnecessary (#16259)
The return type checking for `"function"` type FFI values was incorrect and presumed that functions were still being registered as objects containing a "function" key. While here, I also removed the whole return type checking logic as it was needed for optionally creating BigInts on return when needed, but serde_v8 does this automatically now (I think).
Diffstat (limited to 'ext/ffi/00_ffi.js')
-rw-r--r--ext/ffi/00_ffi.js71
1 files changed, 4 insertions, 67 deletions
diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js
index c9d6d629c..30a02a609 100644
--- a/ext/ffi/00_ffi.js
+++ b/ext/ffi/00_ffi.js
@@ -13,7 +13,6 @@
NumberIsSafeInteger,
ArrayPrototypeJoin,
ObjectPrototypeIsPrototypeOf,
- PromisePrototypeThen,
TypeError,
Int32Array,
Uint32Array,
@@ -21,23 +20,6 @@
Function,
} = window.__bootstrap.primordials;
- function unpackU64(returnValue) {
- if (typeof returnValue === "number") {
- return returnValue;
- }
- const [hi, lo] = returnValue;
- return BigInt(hi) << 32n | BigInt(lo);
- }
-
- function unpackI64(returnValue) {
- if (typeof returnValue === "number") {
- return returnValue;
- }
- const [hi, lo] = returnValue;
- const u64 = unpackU64([hi, lo]);
- return u64 >> 63n ? u64 - 0x10000000000000000n : u64;
- }
-
class UnsafePointerView {
pointer;
@@ -163,25 +145,6 @@
}
}
- function unpackNonblockingReturnValue(type, result) {
- if (
- typeof type === "object" && type !== null && "function" in type ||
- type === "pointer"
- ) {
- return unpackU64(result);
- }
- switch (type) {
- case "isize":
- case "i64":
- return unpackI64(result);
- case "usize":
- case "u64":
- return unpackU64(result);
- default:
- return result;
- }
- }
-
class UnsafeFnPointer {
pointer;
definition;
@@ -192,25 +155,13 @@
}
call(...parameters) {
- const resultType = this.definition.result;
if (this.definition.nonblocking) {
- const promise = core.opAsync(
+ return core.opAsync(
"op_ffi_call_ptr_nonblocking",
this.pointer,
this.definition,
parameters,
);
-
- if (
- isReturnedAsBigInt(resultType)
- ) {
- return PromisePrototypeThen(
- promise,
- (result) => unpackNonblockingReturnValue(resultType, result),
- );
- }
-
- return promise;
} else {
return ops.op_ffi_call_ptr(
this.pointer,
@@ -221,13 +172,9 @@
}
}
- function isPointerType(type) {
- return type === "buffer" || type === "pointer" ||
- typeof type === "object" && type !== null && "function" in type;
- }
-
function isReturnedAsBigInt(type) {
- return isPointerType(type) || type === "u64" || type === "i64" ||
+ return type === "buffer" || type === "pointer" || type === "function" ||
+ type === "u64" || type === "i64" ||
type === "usize" || type === "isize";
}
@@ -329,22 +276,12 @@
configurable: false,
enumerable: true,
value: (...parameters) => {
- const promise = core.opAsync(
+ return core.opAsync(
"op_ffi_call_nonblocking",
this.#rid,
symbol,
parameters,
);
-
- if (needsUnpacking) {
- return PromisePrototypeThen(
- promise,
- (result) =>
- unpackNonblockingReturnValue(resultType, result),
- );
- }
-
- return promise;
},
writable: false,
},