Closed Bug 1119682 Opened 11 years ago Closed 11 years ago

JavaScript strict warning: nsSearchSuggestions.js, line 34: TypeError: setting a property that has only a getter

Categories

(Firefox :: Search, defect)

defect
Not set
minor
Points:
2

Tracking

()

RESOLVED FIXED
Firefox 38
Iteration:
38.1 - 26 Jan

People

(Reporter: Waldo, Assigned: Skandan, Mentored)

Details

Attachments

(1 file, 3 obsolete files)

SuggestAutoComplete.prototype = { ... get _suggestionLabel() { delete this._suggestionLabel; let bundle = Services.strings.createBundle("chrome://global/locale/search/search.properties"); return this._suggestionLabel = bundle.GetStringFromName("suggestion_label"); }, Line 34 is the return/assignment. Given this is in a prototype, it's almost certainly the case that |delete this._suggestionLabel| fails to to delete off an SuggestAutoComplete instance (the property's on the prototype, and deletion only affects own properties), then fails to assign because the assignment target is still a getter with no setter. Should be an easy bug to fix -- remove the deletion, add a |let label = ...| for the label string, use Object.defineProperty(SuggestAutoComplete.prototype, "_suggestionLabel", { value: label }), then return label.
Mentor: gijskruitbosch+bugs
I would love to take this on, but it might take me a few days ! I have to get back to college tomorrow where I have a few registration procedures, would that be fine?
(In reply to Prathik Sai [:Skandan] from comment #1) > I would love to take this on, but it might take me a few days ! I have to > get back to college tomorrow where I have a few registration procedures, > would that be fine? Sure, no rush.
Thank You Gijs! :-) I'm still a beginner at JS, but I'll work A.S.A.P.
Since I neglected to include it in comment 0: clicking on the magnifying-glass search icon in a browser with a fresh profile, with the search dropdown not already open (can't remember if the search box contained any text or not), was enough to consistently trigger the warning for me, and should be an easy way to verify the warning is gone.
Can you tell me how I can reproduce the error? I tried using Ctrl+Shift+J and then clicked the magnifying glass, but I seem to be doing something wrong. And please do tell me if I've done something wrong!
Attachment #8547199 - Flags: feedback?(gijskruitbosch+bugs)
Comment on attachment 8547199 [details] [diff] [review] Bug-1119682.diff (suggested solution implemented) (In reply to Prathik Sai [:Skandan] from comment #5) > Created attachment 8547199 [details] [diff] [review] > Bug-1119682.diff (suggested solution implemented) > > Can you tell me how I can reproduce the error? I tried using Ctrl+Shift+J > and then clicked the magnifying glass, but I seem to be doing something > wrong. And please do tell me if I've done something wrong! Try setting "javascript.options.strict" to true in about:config. That should help in reproducing this. Off-hand, the patch seems fine, save for some whitespace nits (please put spaces after the commas between arguments to a function call, and no space after the opening { of an object).
Attachment #8547199 - Flags: feedback?(gijskruitbosch+bugs) → feedback+
:) I'm sorry about the white space nits! Was concentrating more on the JS I forgot to hold to the general conventions. Working on keeping to standards.
Attachment #8547199 - Attachment is obsolete: true
Attachment #8547218 - Flags: feedback?(gijskruitbosch+bugs)
Comment on attachment 8547218 [details] [diff] [review] Bug-1119682.diff (white space nits fixed) Review of attachment 8547218 [details] [diff] [review]: ----------------------------------------------------------------- This looks good to me. Please adopt the nit below and then request review from ":MattN" or ":felipe" - sadly, I'm not a reviewer for the toolkit module which this changes. :-) ::: toolkit/components/search/nsSearchSuggestions.js @@ +32,3 @@ > let bundle = Services.strings.createBundle("chrome://global/locale/search/search.properties"); > + let label = bundle.GetStringFromName("suggestion_label"); > + Object.defineProperty(SuggestAutoComplete, "_suggestionLabel", {value : label}); Nit: sorry, I forgot, also no space before the ":" :-)
Attachment #8547218 - Flags: feedback?(gijskruitbosch+bugs) → feedback+
Attached patch Bug-1119682.diff (obsolete) — Splinter Review
Attachment #8547218 - Attachment is obsolete: true
Attachment #8547590 - Flags: review?(felipc)
Should I do something else? Or wait a bit more? Sorry if this sounds impatient. :)
Comment on attachment 8547590 [details] [diff] [review] Bug-1119682.diff Matt, do you have more cycles to review this patch from Prathik?
Attachment #8547590 - Flags: review?(MattN+bmo)
Comment on attachment 8547590 [details] [diff] [review] Bug-1119682.diff Review of attachment 8547590 [details] [diff] [review]: ----------------------------------------------------------------- ::: toolkit/components/search/nsSearchSuggestions.js @@ +32,3 @@ > let bundle = Services.strings.createBundle("chrome://global/locale/search/search.properties"); > + let label = bundle.GetStringFromName("suggestion_label"); > + Object.defineProperty(SuggestAutoComplete, "_suggestionLabel", {value: label}); On comment 0 by Jeff, he suggests that this property should be defined on the prototype, and not directly on the object. The warning has gone away with this patch because _suggestionLabel is not redefined in this case and this code will run every time, I imagine.
Attachment #8547590 - Flags: review?(felipc)
Attachment #8547590 - Flags: review?(MattN+bmo)
Attachment #8547590 - Flags: feedback+
Sorry about that overlooked detail. Property added to prototype.
Attachment #8547590 - Attachment is obsolete: true
Attachment #8549824 - Flags: review?(felipc)
Comment on attachment 8547590 [details] [diff] [review] Bug-1119682.diff Review of attachment 8547590 [details] [diff] [review]: ----------------------------------------------------------------- ::: toolkit/components/search/nsSearchSuggestions.js @@ +32,3 @@ > let bundle = Services.strings.createBundle("chrome://global/locale/search/search.properties"); > + let label = bundle.GetStringFromName("suggestion_label"); > + Object.defineProperty(SuggestAutoComplete, "_suggestionLabel", {value: label}); Yeah. You have <autocomplete object> -> ...some number of objects I don't know... -> SuggestAutoComplete.prototype -> Object.prototype -> null for the entire chain. Only SAC.prototype had the property before, so delete did nothing, and assignment did nothing because the getter-only property made it a no-op. With this patch you're defining onto SAC, which is not actually a member of the prototype chain, so the original getter will run every time. One possibly more pleasant way to do this might be to move _suggestionLabel onto SuggestAutoComplete itself, entirely. Object.defineProperty(SuggestAutoComplete, "_suggestionLabel", { get() { delete this._suggestionLabel; let bundle = Services.strings.createBundle("chrome://global/locale/search/search.properties"); return this._suggestionLabel = bundle.GetStringFromName("suggestion_label"); } }); and then change every |this._suggestionLabel| reference into a |SuggestAutoComplete._suggestionLabel| reference. That's obviously more change than just modifying this one getter to do what it was intended to do, of course.
Attachment #8547590 - Attachment is obsolete: false
Attachment #8547590 - Attachment is obsolete: true
Comment on attachment 8549824 [details] [diff] [review] Bug-1119682.diff(property added to prototype) Review of attachment 8549824 [details] [diff] [review]: ----------------------------------------------------------------- This approach as suggested in the beginning looks fine to me. Unless Waldo thinks there's some problem with it, this looks clean enough
Attachment #8549824 - Flags: review?(felipc) → review+
Nope, seems fine.
So should I upload a new patch with the reviewer tag added and set checkin-needed or is there a way I can add the reviewer tag to the current patch itself?
(In reply to Prathik Sai [:Skandan] from comment #17) > So should I upload a new patch with the reviewer tag added and set > checkin-needed or is there a way I can add the reviewer tag to the current > patch itself? Normally, it'd be good to upload a new copy and set checkin-needed, yes. As it is, I just landed this for you: remote: https://hg.mozilla.org/integration/fx-team/rev/694b5bb3861f
Assignee: nobody → prathikcoding167
Status: NEW → ASSIGNED
Iteration: --- → 38.1 - 26 Jan
Points: --- → 2
Flags: qe-verify-
Flags: in-testsuite-
Flags: firefox-backlog+
Thank You :Gijs :)
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 38
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: