Closed Bug 1632686 Opened 3 months ago Closed 3 months ago

Global Object For StyleSheets That Have No Associated Document

Categories

(Core :: DOM: CSS Object Model, defect, P3)

defect

Tracking

()

RESOLVED FIXED
mozilla77
Tracking Status
firefox77 --- fixed

People

(Reporter: nordzilla, Assigned: nordzilla)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

There are cases in which a StyleSheet needs to create a promise to either resolve or reject.
Notably, the Replace() function (spec).

Creating a promise requires a global object (searchfox).

There are, in general, four global objects (spec), Entry, Incumbent, Current, and Relevant.

Within the 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 nsCOMPtr<nsIGlobalObject> mParentObject.

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.

Attached file example.html
Attachment #9143749 - Attachment description: Bug 1632686 - Retain GlobalObject in StyleSheets → Bug 1632686 - Retain GlobalObject in StyleSheets r=#style,emilio
Pushed by btara@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/5f1618cc19f5
Retain GlobalObject in StyleSheets r=emilio
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/23372 for changes under testing/web-platform/tests
Status: NEW → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla77
Upstream PR merged by moz-wptsync-bot
Regressions: 1635125
Regressions: 1635678
Blocks: 1636266
You need to log in before you can comment on or make changes to this bug.