There are cases in which a StyleSheet needs to create a promise to either resolve or reject.
Replace() function (spec).
Creating a promise requires a global object (searchfox).
There are, in general, four global objects (spec), Entry, Incumbent, Current, and Relevant.
Replace() function, we want to create a promise using the Relevant Global, i.e. the global associated with the realm in which the sheet was created.
Typically, StyleSheets can get this global object through their associated document. There are, however, edge cases in which a sheet may be disassociated from a document (see attached HTML). We still want to be able to create a promise from the Relevant global object in these cases.
An ideal solution would be one in which a StyleSheet has a strong pointer directly to this global object. Let's say this could be
The problem with adding such a pointer is that it needs to be cycle collected. This isn't a problem in most cases. One particular case where this is a problem is when sheets are added to a cache in the loader (searchfox).
If the a sheet in the cache has a strong pointer back to a global object, this will cause any windows reachable by that global object to leak until shutdown, which is not ideal.
We need to either modify the way sheets are cached to allow for having a strong pointer, or to come up with a different means of getting at the sheet's Relevant global object.