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

Boris Zbarsky <[email protected]> Tue, 14 Aug 2018 12:25:34 -0400
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
On 8/13/18 7:34 AM, Miles wrote:
> If I use JS::Heap<JSObject *> can these be automatically coerced into JS::Handle<JSObject *> for passing to functions or do I have to do something else to be able to pass them as function parameters?

You generally need to put them in a Rooted on the stack.

The reason for that is that Handle<JSObject*> is really a JSObject** 
under the hood.  Heap<JSObject*> stores a JSObject*.  If we allowed 
creation of a Handle from it, that Handle would point inside the Heap. 
Then if the code you are calling triggers some JS that changes the value 
of your member (updating the JSObject* value stored), the handle would 
suddenly be pointing to a different object, which is pretty confusing.

-Boris