v8::Object destructor callback?

304 views
Skip to first unread message

Jane Chen

unread,
Mar 28, 2014, 1:03:03 PM3/28/14
to v8-u...@googlegroups.com
I create a v8::Object from my ObjectTemplate and embed my own data with SetAlignedPointerInInternalField.  I want to get a call back when that v8::Object is destructed by v8, so that I can clean up my own stuff.  Does such an API exist?

Thanks!

Ben Noordhuis

unread,
Mar 28, 2014, 1:32:07 PM3/28/14
to v8-u...@googlegroups.com
Yes, Persistent<Object>::SetWeak() (called MakeWeak() in older versions of V8.)

Jane Chen

unread,
Mar 28, 2014, 2:20:02 PM3/28/14
to v8-u...@googlegroups.com
Ah!  Thanks Ben!

I got it just after I wrote my own book-keeping for them. :-)  Will check it out anyway.

Sven Panne

unread,
Mar 31, 2014, 2:16:15 AM3/31/14
to v8-u...@googlegroups.com
On Fri, Mar 28, 2014 at 7:20 PM, Jane Chen <jxch...@gmail.com> wrote:
[...] I got it just after I wrote my own book-keeping for them. :-)  Will check it out anyway.

Just as a reminder (this comes up roughly once a month at least ;-) : Don't make any assumptions when or even *if* the callback is invoked. All you can assume is that those callbacks are invoked via "best effort" on the v8 side, but nothing more. Perhaps we will add some kind of phantom reference to the external API at some point in the future (which can provide more guarantees then), but don't hold your breath...

Andreas Rossberg

unread,
Mar 31, 2014, 8:10:23 AM3/31/14
to v8-u...@googlegroups.com
Right, and this disclaimer should really be in v8.h in big letters.
I'll prepare a CL.

/Andreas

Gregory Hlavac

unread,
Mar 31, 2014, 9:43:11 AM3/31/14
to v8-u...@googlegroups.com
Should also have a disclaimer of..

'Don't assume any of these examples on these functions or classes will actually work, we never update them with the API'
Reply all
Reply to author
Forward
0 new messages