Closed
Bug 121495
Opened 23 years ago
Closed 20 years ago
nsXULElement::GetChildNodes returns a non-live nodelist
Categories
(Core :: DOM: Core & HTML, defect, P3)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
People
(Reporter: bzbarsky, Unassigned)
References
Details
Attachments
(1 file, 3 obsolete files)
30.25 KB,
patch
|
Details | Diff | Splinter Review |
The NodeList that's given by the childNodes property of an XUL element is not live. In particular, its length does not change as children are added to/removed from the element. Something like this will go into an infinite loop, for instance: var children = node.childNodes; while (children.length != 0) { node.removeChild(children.item(0)); } since children.length is never updated.
Reporter | ||
Comment 3•20 years ago
|
||
This does the C++ part. It doesn't address the issue of JS that depends on the bogus behavior so far....
Reporter | ||
Comment 4•20 years ago
|
||
Attachment #146157 -
Attachment is obsolete: true
Reporter | ||
Comment 5•20 years ago
|
||
A few of these were not strictly needed, but were just better code than what was there. I hate how we now have 2 or 3 copies of every single friggin' JS file, all with the same exact errors in them... :(
Reporter | ||
Comment 6•20 years ago
|
||
Comment on attachment 146158 [details] [diff] [review] Oops. Same, without stray changes. jst, would you review the core change? The changes to consumers will be in separate patches.
Attachment #146158 -
Flags: superreview?(jst)
Attachment #146158 -
Flags: review?(jst)
Reporter | ||
Comment 7•20 years ago
|
||
Comment on attachment 146163 [details] [diff] [review] Sweep through JS in tree Neil, jst, would you review the JS parts of this change?
Attachment #146163 -
Flags: superreview?(jst)
Attachment #146163 -
Flags: review?(neil.parkwaycc.co.uk)
Comment 8•20 years ago
|
||
Comment on attachment 146163 [details] [diff] [review] Sweep through JS in tree > // We need to leave the <label> to flex the buttons to the left > // so, don't remove the last child at position length - 1 >- for (var i = childNodesLength - 2; i >= 0; i--) { >- toolbar.removeChild(childNodes.item(i)); >+ while (childNodes.length > 1) { >+ // Remove back to front so there's less moving about. >+ toolbar.removeChild(childNodes.item(childNodes.length - 2)); > } I don't see what was wrong with the reverse loop approach, indeed I was wondering why you didn't use it in cases like the one below: > var kids = this.mTree.childNodes; > for (var i = 0 ; i < kids.length; ++i) >- if (kids[i].localName != "treechildren") >+ if (kids[i].localName != "treechildren") { > this.mTree.removeChild(kids[i]); >+ --i; // Adjust, since the list adjusted itself >+ } I'm not exactly a good commenter but I'm not convinced of the understandability of that comment... reversing the loop might give you a chance to write a more meaningful comment :-) >Index: extensions/p3p/resources/content/p3pSummary.js As this change is in a function commented as a workaround I'm going to assume that it just needs to work as it should get superceded...
Attachment #146163 -
Flags: review?(neil.parkwaycc.co.uk) → review+
Reporter | ||
Comment 9•20 years ago
|
||
> I don't see what was wrong with the reverse loop approach It tempts people to loop with a counter in general, which is a bad idea. ;) > reversing the loop might give you a chance to write a more meaningful comment Yeah, good point. I'll reverse those loops. Thanks for the review, Neil!
Comment 10•20 years ago
|
||
(In reply to comment #9) >>I don't see what was wrong with the reverse loop approach >It tempts people to loop with a counter in general, which is a bad idea. ;) Well just comment why the reverse loop happens to work as per those more meaningful comments you're going to write :-)
Comment 11•20 years ago
|
||
Comment on attachment 146158 [details] [diff] [review] Oops. Same, without stray changes. Sweet! r+sr=jst
Attachment #146158 -
Flags: superreview?(jst)
Attachment #146158 -
Flags: superreview+
Attachment #146158 -
Flags: review?(jst)
Attachment #146158 -
Flags: review+
Comment 12•20 years ago
|
||
Comment on attachment 146163 [details] [diff] [review] Sweep through JS in tree sr=jst
Attachment #146163 -
Flags: superreview?(jst) → superreview+
Reporter | ||
Comment 13•20 years ago
|
||
Attachment #146158 -
Attachment is obsolete: true
Attachment #146163 -
Attachment is obsolete: true
Reporter | ||
Comment 14•20 years ago
|
||
Patch checked in. No effect on Ts/Tp/Txul.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Reporter | ||
Updated•19 years ago
|
Component: DOM: Core → DOM: Core & HTML
QA Contact: stummala → general
You need to log in
before you can comment on or make changes to this bug.
Description
•