mozjs
mozjs copied to clipboard
Add safe GC rooting infrastructure
https://github.com/servo/mozjs/pull/344#discussion_r1111180132 exposes an area where users of this crate currently need to build their own abstractions like RootedVec. Moving this into mozjs would allow creating safe HandleValueArray constructors. This would also require moving most of the tracing infrastructure into this crate, like the JSTraceable interface and RootedJSTraceableSet, and ensure that all runtimes have a trace hook that traces the known traceable set.
What role does script_plugin provider of unrooted_must_root lint plays on those types if any?
The script plugin is used for marking types that are only safe when used in a way that the GC can observe them. Ideally, types like JSVal and JSString and JSObject would be marked with it, but I suspect that requires further thought about supporting them correctly.
I am currently looking into taking the mozjs::rust::Trace trait and moving it to mozjs_sys (with re-exports for backwards compatibility). It seems pretty good so far.
RootedTraceableSet has been implemented, will be working on RootedVec soon enough.
Actually, I'm not too sure about how RootedVec should be implemented or designed, so I'll just make a PR first with the improved tracing infrastructure.
Not done in #352.
We should write warning on HandleValueArray::from_rooted_slice that it expects rooted slice not slice of rooted elements.