Re: How do I trace objects on the heap with JS 59

Boris Zbarsky <[email protected]> Mon, 27 Aug 2018 13:07:12 -0400
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
On 8/15/18 7:08 PM, James Stortz wrote:
> Ok, so the JSObject has a C++ Object that
> it mirrors, as a high-level interface. The desired relationship is that C++
> or JS can work on their respective counterpart and have changes reflected
> accordingly.

So you want the JS object to keep the C++ object alive as needed _and_ 
the C++ object to keep the JS object alive?  But for both to go away 
once both become unreachable (in JS and C++ respectively)?

> I can't think of any elegant solutions off the top of my head.

Well, there's what Firefox does, which is having C++ objects trace their 
JS objects as needed, etc, but breaking the cycles when the C++ object 
is conceptually dead.

> I don't think storing raw JSObject* pointers in the C++ is viable.

That's correct.

> It would be great if there was a
> distinction between Heap/Rooted objects that I could test for during some
> GC trace/hook, but there's not a better place to delete the Heap<JSObject*>
> wrapper, is there?

I'm not sure what you mean here.

> Is there a way I can check for when a JSObject "would've" gone out of scope?

Sure, you can run a GC marking pass and see what color it ended up being.

-Boris