JSObject* crash before Finalizer called

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

JSObject* crash before Finalizer called

answerwinner
here it says that finzlizer will be called at some point AFTER the object becomes unreachable:
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSClass

My code looks like this:
class Example
{
    static JSObject* jsObj;
    static void myFinalizer(JSFreeOp* fop, JSObject* obj)
    {
        jsObj = NULL;
    }
   
    // some code to init jsObj

    // will be call very frequently
    void Run() {
        if (jsObj) {
           // do something with jsObj
           // CRASH here
           // (1)
        }
    }
}

it seems that jsObj becomes unavailable before myFinalizer called.
Is there a way to know if jsObj is available or not at line marked with (1)?

(I would like jsObj's life cycle to be controlled by javascript, so JS_Add**Root(jsObj) is not my option)
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: JSObject* crash before Finalizer called

answerwinner
I've found the answer.

I should use JS::Heap<T>, it will keep jsObj always valid when GC moved it.
it doesn't protect jsObj from being collected.

This is exactly what I want!
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine