Closed Bug 121495 Opened 23 years ago Closed 21 years ago

nsXULElement::GetChildNodes returns a non-live nodelist

Categories

(Core :: DOM: Core & HTML, defect, P3)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: bzbarsky, Unassigned)

References

Details

Attachments

(1 file, 3 obsolete files)

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.
changing priority to P3
Priority: -- → P3
Mass-reassigning bugs to dom_bugs@netscape.com
Assignee: jst → dom_bugs
Depends on: 198533
Depends on: 240186
Attached patch Preliminary patch (obsolete) — Splinter Review
This does the C++ part. It doesn't address the issue of JS that depends on the bogus behavior so far....
Attachment #146157 - Attachment is obsolete: true
Attached patch Sweep through JS in tree (obsolete) — Splinter Review
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... :(
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)
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 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+
> 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!
(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 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 on attachment 146163 [details] [diff] [review] Sweep through JS in tree sr=jst
Attachment #146163 - Flags: superreview?(jst) → superreview+
Attachment #146158 - Attachment is obsolete: true
Attachment #146163 - Attachment is obsolete: true
Patch checked in. No effect on Ts/Tp/Txul.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
this caused bug 320117
Blocks: 320117
No longer blocks: 320117
Depends on: 320117
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.

Attachment

General

Created:
Updated:
Size: