Closed
Bug 495277
Opened 15 years ago
Closed 12 years ago
autocomplete.xml should not use new Function()
Categories
(Toolkit :: Autocomplete, defect)
Toolkit
Autocomplete
Tracking
()
RESOLVED
FIXED
mozilla13
People
(Reporter: vlad, Assigned: felix)
References
Details
Attachments
(1 file, 3 obsolete files)
10.05 KB,
patch
|
Gavin
:
review+
|
Details | Diff | Splinter Review |
autocomplete should not use new Function, especially not in code that's executed each time the user types a key in the urlbar: http://hg.mozilla.org/mozilla-central/file/tip/toolkit/content/widgets/autocomplete.xml#l403 fireEvent() is only called from 4 different places, to handle onsearchbegin, onsearchcomplete, ontextreverted, ontextentered. We should just have properties on autocomplete to store those, and if a string is set we should turn it into a function object once. Then we should just get rid of fireEvent and just call the right event handling function directly.
Flags: wanted1.9.2+
Comment 1•15 years ago
|
||
Performance-wise, it would be best to just ignore dynamic changes to these attributes (onsearchbegin, onsearchcomplete, ontextreverted, and ontextentered). Would that be an acceptable trade-off?
Assignee | ||
Comment 2•13 years ago
|
||
- Took to suggestion in comment 1 and ignored setting these properties after autocomplete is constructed. As far as I can tell from searching the codebase, none of these properties are modified dynamically.
Assignee: nobody → ffung
Attachment #572664 -
Flags: review?(vladimir)
Comment 3•13 years ago
|
||
Comment on attachment 572664 [details] [diff] [review] Reduce calls to new Function in Autocomplete.xml >diff --git a/toolkit/content/widgets/autocomplete.xml b/toolkit/content/widgets/autocomplete.xml > <constructor><![CDATA[ > mController = Components.classes["@mozilla.org/autocomplete/controller;1"]. > getService(Components.interfaces.nsIAutoCompleteController); >+ >+ mSearchBeginHandler = this.initEventHandler("searchbegin"); >+ mSearchCompleteHandler = this.initEventHandler("searchcomplete"); >+ mTextEnteredHandler = this.initEventHandler("textentered"); >+ mTextRevertedHandler = this.initEventHandler("textreverted"); Use this.mSearchBeginHandler, etc. And fix mController while you're here too? >+ <method name="initEventHandler"> >+ let handlerString = this.getAttribute("on" + aEventType); >+ if (handlerString) { >+ return new Function("eventType", "param", handlerString); You could return: (new Function("eventType", "param", handlerString)).bind(this, aEventType); and then just call the function directly (without .apply, at least for those without additional parameters) from the handlers. Are there tests for this functionality? There should be, shouldn't be too hard to add. Cancelling the review request pending response to these comments.
Attachment #572664 -
Flags: review?(vladimir)
Assignee | ||
Comment 4•13 years ago
|
||
Additional Changes: - Addressed above comments Notes: - toolkit/content/tests/chrome/test_autocomplete[2..4].xul seem to cover the relevant functionality.
Attachment #572664 -
Attachment is obsolete: true
Attachment #581613 -
Flags: review?(gavin.sharp)
Comment 5•13 years ago
|
||
(In reply to Felix Fung (:felix) from comment #4) > - toolkit/content/tests/chrome/test_autocomplete[2..4].xul seem to cover the > relevant functionality. None of those tests appear to cover e.g. onsearchbegin="foo()" attributes on an xul:autocomplete input, which is what you're changing here.
Assignee | ||
Comment 6•13 years ago
|
||
Additional Changes: - Added tests
Attachment #581613 -
Attachment is obsolete: true
Attachment #581928 -
Flags: review?(gavin.sharp)
Attachment #581613 -
Flags: review?(gavin.sharp)
Comment 7•13 years ago
|
||
Could you please use _ instead of the m prefix for new fields?
Assignee | ||
Comment 8•13 years ago
|
||
Additional Changes: - Prefixed new fields with _ instead of m.
Attachment #581928 -
Attachment is obsolete: true
Attachment #584245 -
Flags: review?(gavin.sharp)
Attachment #581928 -
Flags: review?(gavin.sharp)
Updated•13 years ago
|
Attachment #584245 -
Flags: review?(gavin.sharp) → review+
Assignee | ||
Comment 9•13 years ago
|
||
Where should we comment that making dynamic changes on these properties (e.g. onsearchbegin) does not work as one would expect and instead would do nothing.
Assignee | ||
Comment 11•12 years ago
|
||
Updated docs. https://hg.mozilla.org/integration/mozilla-inbound/rev/f01f200f798a
Comment 12•12 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/f01f200f798a
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla13
You need to log in
before you can comment on or make changes to this bug.
Description
•