nan icon indicating copy to clipboard operation
nan copied to clipboard

Nan::Callback SetWeak

Open Lokomojo opened this issue 5 years ago • 1 comments

Hey.

I need to store V8 callbacks as weak references, with the finalizer callback so I can remove the reference when appropriate.

I've worked out how to do this with v8::Function, but I was hoping to keep the Nan::Callback wrapper intact in case of future API changes. Unfortunately the documentation is quite bare.

Is there a way to do this?

Lokomojo avatar May 17 '20 19:05 Lokomojo

Nan::Persistent<v8::Function>::SetWeak() coupled with Nan::Call() to actually invoke the function should do it.

Nan::Callback could in theory be extended to offer that functionality (internally it already uses a Nan::Persistent<v8::Function>) but I don't know, that's probably too esoteric and uncommon. A Nan::Callback is usually embedded in some other weak object.

bnoordhuis avatar May 26 '20 12:05 bnoordhuis