diff options
Diffstat (limited to 'ext/ffi/00_ffi.js')
-rw-r--r-- | ext/ffi/00_ffi.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js index 190873307..f308ecad9 100644 --- a/ext/ffi/00_ffi.js +++ b/ext/ffi/00_ffi.js @@ -201,6 +201,7 @@ } class UnsafeCallback { + #refcount; #rid; definition; callback; @@ -217,13 +218,30 @@ definition, callback, ); + this.#refcount = 0; this.#rid = rid; this.pointer = pointer; this.definition = definition; this.callback = callback; } + ref() { + if (this.#refcount++ === 0) { + core.opSync("op_ffi_unsafe_callback_ref", true); + } + } + + unref() { + if (--this.#refcount === 0) { + core.opSync("op_ffi_unsafe_callback_ref", false); + } + } + close() { + if (this.#refcount) { + this.#refcount = 0; + core.opSync("op_ffi_unsafe_callback_ref", false); + } core.close(this.#rid); } } |