mozjs icon indicating copy to clipboard operation
mozjs copied to clipboard

Add safe GC rooting infrastructure

Open jdm opened this issue 2 years ago • 6 comments

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.

jdm avatar Feb 19 '23 16:02 jdm

What role does script_plugin provider of unrooted_must_root lint plays on those types if any?

sagudev avatar Feb 19 '23 17:02 sagudev

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.

jdm avatar Feb 19 '23 19:02 jdm

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.

redfire75369 avatar Apr 10 '23 11:04 redfire75369

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.

redfire75369 avatar Apr 10 '23 13:04 redfire75369

Not done in #352.

sagudev avatar Nov 28 '24 16:11 sagudev

We should write warning on HandleValueArray::from_rooted_slice that it expects rooted slice not slice of rooted elements.

sagudev avatar Nov 28 '24 16:11 sagudev