Re: Assertion failure on debug, what is wrong?
Steve Fink <[email protected]> Thu, 1 Sep 2016 14:05:12 -0700
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <[email protected]> |
On 08/30/2016 10:16 PM, Mihai Dobrescu wrote:
> On Monday, August 29, 2016 at 6:59:50 PM UTC+3, Boris Zbarsky wrote:
>> On 8/29/16 10:13 AM, Mihai Dobrescu wrote:
>>> But what if I need to make a class with a "global" member?
>>
>> Then you either use a PersistentRooted<JSObject*> member (if you want it
>> to be a permanent GC root until the class instance is destroyed) or a
>> Heap<JSObject*> and trace it if you want to participate in GC.
>>
>> -Boris
>
> If you're suggesting using JS::PersistentRootedObject, I don't get it working in debug, I got assertions failures all the time, what is the "protocol" using it in my case? Is there a consistent sample somewhere?
What assertions?
To use PersistentRooted, make it a field of your class/struct and
initialize it with a cx or rt in the constructor of your class/struct.
struct MyThing {
PersistentRootedObject global;
MyThing(JSContext* cx) : global(cx) {}
};
It's not the greatest code to read in general, but js/src/shell/js.cpp
has some examples of using PersistentRooted things.