On Fri Dec 2 14:54:49 2022 +0000, Jacek Caban wrote:
Did you look at integrating it with the rest of MSHTML? While we will need a standalone GC implementation for regular ActiveScript hosts, MSHTML will ultimately need something better to handle cycles that involve MSHTML or even Gecko objects. While we may initially have JS-only GC, it's fine to not implement the whole thing right away, it would be good to have understanding of further work to make sure that this goes in the right direction. We already have some integration with Gecko cycle collector in MSHTML and we will probably need to extend it somehow to handle JS objects. It currently requires all reference counting to use `nsCycleCollectingAutoRefCnt`, so it's not very practical for JS. Gecko has some dedicated handling for its own JS objects in CC, but it's obviously not very useful for jscript.
For artificial testing, one could use something like:
It would be more interesting to have proper tests. You may, for example, add an external object that uses `CHECK_EXPECT()` in its destructor, add that object as a property of an interesting JS object and then check it with `CHECK_CALLED()`. I'd expect GC to trigger when script context is released, but there is also global JS function `CollectGarbage()` that could be used to trigger it. On related note, the initial implementation could trigger only inside `CollectGarbage()` and periodic run could be added in a separated patch.
I haven't looked into integration yet, I don't truly understand how the gecko refcounting works exactly, but we need a standalone GC anyway for normal jscript (not just for pre-IE9 mshtml jscript, but also standalone jscript), so I think this needs to be the first step anyway. An integration would definitely require using the private interface in some form (that I have for the "proxies" in Proton).
Thanks for the tests idea. I just realized my GC won't run if the script gets destroyed before it even does the next collect attempt. I'd love having some tests for it, I just didn't know how to do it, evidently I didn't even realize destroying the script should GC… :-)