CssRuleView.jsm uses invalid weak map keys

RESOLVED FIXED in Firefox 17



Developer Tools: Inspector
5 years ago
5 years ago


(Reporter: mccr8, Assigned: dcamp)


Firefox 17
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)



(2 attachments)



5 years ago
Line 490 in CssRuleView.jsm uses (I think) a nsIDOMCSSStyleDeclaration as a key in the weak map |disabled| [1].  Unfortunately, this is not okay because the only C++ things we support as weak map keys are nodes (for technical reasons, we only can only support objects that support wrapper preservation, and just allowing nodes was a simple way to do that).

The current behavior is that the key will be successfully added (with a warning), but it can eventually get its entry in the weak map thrown out during a later GC.  In bug 761620, I am planning to make it so that unsupported keys are not added, and an exception is thrown, so it is more obvious that something has gone wrong.

To fix this, you either have to switch to using some other kind of key, which could be tricky.  If you can get back and forth between the style and its node maybe that would work.  Otherwise, you may need to switch to another data structure, like a map, though then you have to be more careful to avoid leaks.

In the longer term, in bug 753517, CSS things are going to be converted over to the new DOM bindings, which I believe means they will be wrapper cached, and thus we can loosen the restriction on weak map keys to include these CSS things.  But you probably want to fix this before that.

CCing Boris who understands what is going on with wrapper preservation of CSS stuff.

[1] http://mxr.mozilla.org/mozilla-central/source/browser/devtools/styleinspector/CssRuleView.jsm#490

Comment 1

5 years ago
Created attachment 645786 [details]
excerpts from a Moth run, showing where the weak map put failed

Comment 2

5 years ago
I guess these failing test are in the Style Inspector and Highlighter directories, not the Style Editor.
Component: Developer Tools: Style Editor → Developer Tools: Inspector

Comment 3

5 years ago
We can do something different here without too much trouble.
Assignee: nobody → dcamp


5 years ago
Priority: -- → P1
Until bug 753517 happens, css declarations do have a wrapper cache, but don't do wrapper preservation.

Comment 5

5 years ago
Oops, yeah, that's what I meant...

Comment 6

5 years ago
Switching to a Map would mean retaining the DOMCSSStyleDeclaration of any declaration edited by the rule view until the inspector is closed or the page is reloaded.

If I'm reading this right (and I'm probably not), holding a DOMCSSStyleDeclaration won't actually retain any style data.  Is that accurate?

If so, the impact of using a Map instead of a WeakMap will be pretty small.  If bug 753517 is going to let us use WeakMap support and is coming soonish, I'm inclined to just use a Map for now.  Anybody disagree?
> Is that accurate?

It depends on what you mean by "style data".

If you're holding onto a DOMCSSDeclarationImpl, then it'll keep alive the DOMCSSStyleRule.  It won't keep alive the underlying css::StyleRule.

So I think you'll just be out sizeof(DOMCSSStyleRule) but nothing else...

If bug 753517 doesn't land this cycle, then I really screwed up somewhere.

Comment 8

5 years ago
Created attachment 646275 [details] [diff] [review]
Use a Map for now
Attachment #646275 - Flags: review?(rcampbell)


5 years ago
Blocks: 777877
Comment on attachment 646275 [details] [diff] [review]
Use a Map for now

r+... FOR NOW!
Attachment #646275 - Flags: review?(rcampbell) → review+
Whiteboard: [land-in-fx-team]

Comment 10

5 years ago
Whiteboard: [land-in-fx-team] → [fixed-in-fx-team]
Last Resolved: 5 years ago
Resolution: --- → FIXED
Whiteboard: [fixed-in-fx-team]
Target Milestone: --- → Firefox 17
You need to log in before you can comment on or make changes to this bug.