style: Simplify code for keeping alive shared memory until all sheets go away.

The existing code wasn't sound, as CSSOM objects also needed to go away before
the shared memory goes away (as they keep references to them).

This is sound assuming no presence of reference cycles introduced by CSSOM.

We may want to live with this and rely on chrome code not writing cycles like
this with UA stylesheet DOM objects.

We could explicitly drop all potentially-static objects... That seems pretty
error prone though.

Or we could also just leak the shared memory buffer, is there any reason why we
may not want to do that?

Differential Revision: https://phabricator.services.mozilla.com/D51870
This commit is contained in:
Emilio Cobos Álvarez 2019-11-07 11:19:23 +00:00
parent 9c1dd4b3ea
commit cceb0bcb73
No known key found for this signature in database
GPG key ID: E1152D0994E4BF8A
2 changed files with 13 additions and 4 deletions

View file

@ -124,6 +124,7 @@ impl StylesheetContents {
url_data: UrlExtraData,
quirks_mode: QuirksMode,
) -> Self {
debug_assert!(rules.is_static());
Self {
rules,
origin,
@ -144,6 +145,9 @@ impl StylesheetContents {
/// Measure heap usage.
#[cfg(feature = "gecko")]
pub fn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize {
if self.rules.is_static() {
return 0;
}
// Measurement of other fields may be added later.
self.rules.unconditional_shallow_size_of(ops) +
self.rules.read_with(guard).size_of(guard, ops)