summaryrefslogtreecommitdiff
path: root/ext/ffi/00_ffi.js
diff options
context:
space:
mode:
authorAapo Alasuutari <aapo.alasuutari@gmail.com>2023-02-22 19:32:38 +0200
committerGitHub <noreply@github.com>2023-02-22 19:32:38 +0200
commitb56b8c8a753442036ace3bb0f4403c952f18d408 (patch)
tree675c47da4847a754cf2cc3cb664dc8047944246d /ext/ffi/00_ffi.js
parent2bd7482295daae4edfd367d84505bb43735cd410 (diff)
feat(ext/ffi): Replace pointer integers with v8::External objects (#16889)
Diffstat (limited to 'ext/ffi/00_ffi.js')
-rw-r--r--ext/ffi/00_ffi.js34
1 files changed, 31 insertions, 3 deletions
diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js
index 6864fd638..24a0dc913 100644
--- a/ext/ffi/00_ffi.js
+++ b/ext/ffi/00_ffi.js
@@ -118,6 +118,13 @@ class UnsafePointerView {
);
}
+ getPointer(offset = 0) {
+ return ops.op_ffi_read_ptr(
+ this.pointer,
+ offset,
+ );
+ }
+
getCString(offset = 0) {
return ops.op_ffi_cstr_read(
this.pointer,
@@ -170,11 +177,33 @@ class UnsafePointerView {
const OUT_BUFFER = new Uint32Array(2);
const OUT_BUFFER_64 = new BigInt64Array(OUT_BUFFER.buffer);
class UnsafePointer {
+ static create(value) {
+ return ops.op_ffi_ptr_create(value);
+ }
+
+ static equals(a, b) {
+ if (a === null || b === null) {
+ return a === b;
+ }
+ return ops.op_ffi_ptr_equals(a, b);
+ }
+
static of(value) {
if (ObjectPrototypeIsPrototypeOf(UnsafeCallbackPrototype, value)) {
return value.pointer;
}
- ops.op_ffi_ptr_of(value, OUT_BUFFER);
+ return ops.op_ffi_ptr_of(value);
+ }
+
+ static offset(value, offset) {
+ return ops.op_ffi_ptr_offset(value, offset);
+ }
+
+ static value(value) {
+ if (ObjectPrototypeIsPrototypeOf(UnsafeCallbackPrototype, value)) {
+ value = value.pointer;
+ }
+ ops.op_ffi_ptr_value(value, OUT_BUFFER);
const result = OUT_BUFFER[0] + 2 ** 32 * OUT_BUFFER[1];
if (NumberIsSafeInteger(result)) {
return result;
@@ -240,8 +269,7 @@ class UnsafeFnPointer {
}
function isReturnedAsBigInt(type) {
- return type === "buffer" || type === "pointer" || type === "function" ||
- type === "u64" || type === "i64" ||
+ return type === "u64" || type === "i64" ||
type === "usize" || type === "isize";
}