From e2be70b035459cb534360b72ece4ff2abaa09cd7 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Thu, 20 Oct 2022 07:07:37 +0300 Subject: feat(ext/ffi): Make op_ffi_ptr_of fast (#16297) Makes `op_ffi_ptr_of` fast. One of the tests changed from printing `false` to `true` as the fast `&[u8]` slice path creates the slice with a null pointer. Thus the `op_ffi_ptr_of` will now return a null pointer value whereas previously it returned a dangling pointer value. --- ext/ffi/00_ffi.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'ext/ffi/00_ffi.js') diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js index f5b0fb4c3..1b340a766 100644 --- a/ext/ffi/00_ffi.js +++ b/ext/ffi/00_ffi.js @@ -160,12 +160,19 @@ } } + const OUT_BUFFER = new Uint32Array(2); + const OUT_BUFFER_64 = new BigInt64Array(OUT_BUFFER.buffer); class UnsafePointer { static of(value) { if (ObjectPrototypeIsPrototypeOf(UnsafeCallbackPrototype, value)) { return value.pointer; } - return ops.op_ffi_ptr_of(value); + ops.op_ffi_ptr_of(value, OUT_BUFFER); + const result = OUT_BUFFER[0] + 2 ** 32 * OUT_BUFFER[1]; + if (NumberIsSafeInteger(result)) { + return result; + } + return OUT_BUFFER_64[0]; } } -- cgit v1.2.3