diff options
author | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2023-03-05 10:01:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-05 08:01:23 +0000 |
commit | da201d9ea5e00f7fd2aefc3222759f3c253c1882 (patch) | |
tree | 2c1289a43454f6d804295d160601d849c5015468 /ext/ffi/00_ffi.js | |
parent | 0910be4d64272be6774b8b3d44852737e8c53ad4 (diff) |
feat(ext/ffi): Make External pointers keep reference to V8 buffer (#17955)
Diffstat (limited to 'ext/ffi/00_ffi.js')
-rw-r--r-- | ext/ffi/00_ffi.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js index d107e89fa..a63a027e8 100644 --- a/ext/ffi/00_ffi.js +++ b/ext/ffi/00_ffi.js @@ -26,6 +26,7 @@ const { SafeMap, SafeArrayIterator, SymbolFor, + WeakMap, } = primordials; const promiseIdSymbol = SymbolFor("Deno.core.internalPromiseId"); @@ -179,6 +180,7 @@ class UnsafePointerView { const OUT_BUFFER = new Uint32Array(2); const OUT_BUFFER_64 = new BigInt64Array(OUT_BUFFER.buffer); +const POINTER_TO_BUFFER_WEAK_MAP = new WeakMap(); class UnsafePointer { static create(value) { return ops.op_ffi_ptr_create(value); @@ -195,7 +197,11 @@ class UnsafePointer { if (ObjectPrototypeIsPrototypeOf(UnsafeCallbackPrototype, value)) { return value.pointer; } - return ops.op_ffi_ptr_of(value); + const pointer = ops.op_ffi_ptr_of(value); + if (pointer) { + POINTER_TO_BUFFER_WEAK_MAP.set(pointer, value); + } + return pointer; } static offset(value, offset) { |