diff options
Diffstat (limited to 'ext/ffi/00_ffi.js')
-rw-r--r-- | ext/ffi/00_ffi.js | 34 |
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"; } |