On Tue, Oct 9, 2018 at 11:45 AM Mike Moening <mike.moen...@gmail.com> wrote:

> With recent versions of v8 the SetWeak method has changed and the
> Persistent<Value>* parameter has been dropped from the destructor callback.
> The destructor callback function is **supposed** to Reset() the persistent
> or its a leak.
> If you don't V8 crashes and tells you this:
>
> Check failed: Handle not reset in first callback. See comments on
> |v8::WeakCallbackInfo
>
> Old signature:
> void MyClass::DestructorCallback(Isolate* pIsolate, Persistent<Value>*
> value, MyClass* pObj)
>
> New signature
> void MyClass::DestructorCallback(const WeakCallbackInfo<MyClass>& oValue)
>
> If I call it like this:
> Persistent<Object> obj(isolate, objLocal);
> obj.SetWeak<MyClass>(pMyObject, MyClass::DestructorCallback,
> WeakCallbackType::kParameter);
>
> How can I pass the Persistent into my DestructorCallback function so I can
> Reset it??
> Persistent cannot be copied.
> So how can I Reset() it in the callback?
> Any help would be great.
>

See this example:
https://cs.chromium.org/chromium/src/v8/src/d8.cc?l=2312&gsn=SetWeak
You can often find such hints in the V8 API Changes doc
<https://docs.google.com/document/d/1g8JFi8T_oAE_7uAri7Njtig7fKaPDfotU6huOa1alds/edit>
(just
ask your favorite search engine for "V8 API Changes" to find it).


> Also the WeakCallbackType::kParameter  vs WeakCallbackType::kFinalizer
> thing has me confuzeled too.
> Which is the right type to use?
>

See the documentation:

// kParameter will pass a void* parameter back to the callback,
> kInternalFields
> // will pass the first two internal fields back to the callback, kFinalizer
> // will pass a void* parameter back, but is invoked before the object is
> // actually collected, so it can be resurrected. In the last case, it is
> not
> // possible to request a second pass callback.
> enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer };


Does that help?


>
> Thanks!
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to