Closed
Bug 716751
Opened 14 years ago
Closed 14 years ago
matchMedia() listeners lost
Categories
(Core :: DOM: CSS Object Model, defect, P2)
Core
DOM: CSS Object Model
Tracking
()
RESOLVED
FIXED
mozilla13
People
(Reporter: webkit, Assigned: dbaron)
Details
Attachments
(1 file)
|
11.73 KB,
patch
|
bzbarsky
:
review-
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.26 Safari/535.11
Steps to reproduce:
window.matchMedia("screen and (max-width:600px)").addListener(function(media){
console.log("HERE: " + window.innerWidth);
});
Then resized my browser several times.
Actual results:
The event handler fired three times and then stopped. In some cases, it fired zero times.
Expected results:
It should have continued to fire repeatedly. The only way to make this happen was to cache the MediaQueryList object, such as:
var mql = window.matchMedia("screen and (max-width:600px)");
mql.addListener(function(media){
console.log("HERE: " + window.innerWidth);
});
Yeah, we need to hold an ownin reference from the window/document/presshell to the returned object as long as it has listeners registered. Also, this should have used events, oh well.
Assignee: nobody → dbaron
Component: Untriaged → Layout
Product: Firefox → Core
QA Contact: untriaged → layout
Version: 9 Branch → Trunk
| Assignee | ||
Updated•14 years ago
|
Assignee: dbaron → nobody
Component: Layout → DOM: CSS Object Model
QA Contact: layout → style-system
| Assignee | ||
Updated•14 years ago
|
Assignee: nobody → dbaron
OS: Windows XP → All
Hardware: x86 → All
| Assignee | ||
Updated•14 years ago
|
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
| Assignee | ||
Comment 2•14 years ago
|
||
Attachment #601686 -
Flags: review?(bzbarsky)
Comment 3•14 years ago
|
||
Comment on attachment 601686 [details] [diff] [review]
patch
mListeners is a fallible array, right? So we could addref but fail to append in AddListener, then end up leaking on the next AddListener call, as far as I can tell.
Attachment #601686 -
Flags: review?(bzbarsky) → review-
| Assignee | ||
Comment 4•14 years ago
|
||
Oh, for some reason I read that as InfallibleTArray. I'd sort of thought that's what I'd written, too. But so it is.
The most straightforward fix would seem to be (in AddListener):
if (!mListeners.Contains(aListener)) {
mListeners.AppendElement(aListener);
+ if (!HasListeners()) {
+ // Append failed; undo the AddRef above.
+ NS_RELEASE_THIS();
+ }
}
Comment 5•14 years ago
|
||
Yes. r=me with that change.
| Assignee | ||
Comment 6•14 years ago
|
||
Priority: -- → P2
Target Milestone: --- → mozilla13
Comment 7•14 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•