Closed Bug 308068 Opened 20 years ago Closed 20 years ago

JavaScript strict warning in richlistbox.xml

Categories

(Toolkit :: UI Widgets, defect)

1.8 Branch
defect
Not set
trivial

Tracking

()

VERIFIED FIXED
mozilla1.8.1

People

(Reporter: zeniko, Assigned: zeniko)

References

Details

(Keywords: fixed1.8.1)

Attachments

(2 files, 1 obsolete file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4) Gecko/20050910 Firefox/1.4 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4) Gecko/20050910 Firefox/1.4 A strict warning is thrown, whenever the selectedItem field of a richlistbox is set to null (e.g. in clearSelection). A patch is following. Reproducible: Always Steps to Reproduce: 1. Make sure javascript.options.strict and javascript.options.showInConsole are set to true (in about:config) 2. Open the JavaScript Console and the Extensions Manager 3. Hit [Home] or [End] in the Extensions Manager Actual Results: The following two strict warnings are thrown: Warning: reference to undefined property children[run] Source File: chrome://global/content/bindings/richlistbox.xml Line: 331 Warning: reference to undefined property children[run] Source File: chrome://global/content/bindings/richlistbox.xml Line: 335 Expected Results: No console cluttering.
Assignee: nobody → doronr
The problem can be fixed by reversing the equality and the bounds check in getIndexOf. By testing for null at the beginning, the problem also goes away. Since getIndexOf and the selectedIndex getter share much common code, I decided to unify them and to combine both possible fixes for stability and speed. Hope the code remains clear enough.
Attachment #195681 - Flags: first-review?(bugs.mano)
Attachment #195681 - Flags: first-review?(bugs.mano) → first-review?(doronr)
Status: UNCONFIRMED → NEW
Ever confirmed: true
Version: unspecified → Trunk
Blocks: 296661
Summary: Strict warning in richlistbox (undefinded property children[run]) → JavaScript strict warning in richlistbox.xml
Comment on attachment 195681 [details] [diff] [review] Code simplification, fixes strict warning code gets somewhat unreadable, but doesn't take too much work to figure it out.
Attachment #195681 - Flags: first-review?(doronr) → first-review+
Comment on attachment 195681 [details] [diff] [review] Code simplification, fixes strict warning Any suggestions on how to make the code better readable?
Attachment #195681 - Flags: second-review?(mconnor)
What's wrong with using a for loop? Makes it much more readable IMO...
Thinking it over, the solution seems to be a one-liner when using the new Array.indexOf. The null-test remains for performance reasons (the replaced selectedIndex getter did the same test).
Attachment #195745 - Attachment is obsolete: true
Comment on attachment 195681 [details] [diff] [review] Code simplification, fixes strict warning >- while (children[run] != aElement && run < children.length) { >- run++; >+ while (index < children.length && children[index] != aElement) { >+ index++; > } > >- if (children[run] == aElement) >- index = run; >- >- return index; >+ return (index < children.length) ? index : -1; I generally find the following style clearer in the return on match case while (index < children.length) { if (children[index] == aElement) return index; index++ } return -1; r=me with that changed
Attachment #195681 - Flags: second-review?(mconnor) → second-review+
Comment on attachment 195851 [details] [diff] [review] using Array.indexOf for trivial solution I'd rather include this patch, anyway. Alternatively you might prefer attachment 195745 [details] [diff] [review]. Please review one of them before I rewrite the original patch.
Attachment #195851 - Flags: second-review?(mconnor)
Attachment #195851 - Flags: second-review?(mconnor) → second-review+
Attachment #195851 - Flags: approval1.8b5?
Whiteboard: [checkin needed]
Comment on attachment 195851 [details] [diff] [review] using Array.indexOf for trivial solution not the time or the place to take this kind of fix. please do not request approval for this kind of change when we're in lockdown mode. thanks.
Attachment #195851 - Flags: approval1.8b5? → approval1.8b5-
Assignee: doronr → zeniko
Trunk: mozilla/toolkit/content/widgets/richlistbox.xml; new revision: 1.22;
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Whiteboard: [checkin needed]
Target Milestone: --- → mozilla1.9alpha1
Status: RESOLVED → VERIFIED
Attachment #195851 - Flags: approval-branch-1.8.1?(mconnor)
Attachment #195851 - Flags: approval-branch-1.8.1?(mconnor) → approval-branch-1.8.1+
mozilla/toolkit/content/widgets/richlistbox.xml 1.13.2.11
Keywords: fixed1.8.1
Target Milestone: mozilla1.9alpha1 → mozilla1.8.1
Version: Trunk → 1.8 Branch
Flags: in-testsuite-
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: