Closed
Bug 483643
Opened 16 years ago
Closed 16 years ago
Strict JavaScript warnings "reference to undefined property" and "assignment to undeclared variable"
Categories
(Calendar :: General, defect)
Calendar
General
Tracking
(Not tracked)
RESOLVED
FIXED
1.0b1
People
(Reporter: ssitter, Assigned: mschroeder)
References
Details
(Keywords: meta)
Attachments
(4 files, 2 obsolete files)
|
1.16 KB,
patch
|
ssitter
:
review+
|
Details | Diff | Splinter Review |
|
1.66 KB,
patch
|
dbo
:
review+
|
Details | Diff | Splinter Review |
|
33.63 KB,
patch
|
Fallen
:
review+
|
Details | Diff | Splinter Review |
|
431 bytes,
patch
|
dbo
:
review+
|
Details | Diff | Splinter Review |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2a1pre) Gecko/20090315 Sunbird/1.0pre [custom release build based on comm-central/mozilla-central]
Steps to Reproduce:
1. get a 1.9.2 based sunbird build
2. set advanced preference "javascript.options.strict" to true
3. restart sunbird and play around in views and dialogs
Actual Results:
The following warning is logged several thousand times:
Warning: reference to undefined property this.mData[aName]
Source file: file:///E:/sb/mozilla/dist/bin/calendar-js/calUtils.js
Line: 1668
Other warnings that are logged once or multiple times:
Warning: trailing comma is not legal in ECMA-262 object initializers
Source file: chrome://calendar/content/widgets/calendar-list-tree.xml
Line: 118, Column: 6
Source code:
})
Warning: assignment to undeclared variable date
Source file: chrome://calendar/content/widgets/minimonth.xml
Line: 435
Warning: assignment to undeclared variable sp
Source file: file:///E:/sb/mozilla/dist/bin/calendar-js/calStorageCalendar.js
Line: 1848
Warning: assignment to undeclared variable ap
Source file: file:///E:/sb/mozilla/dist/bin/calendar-js/calStorageCalendar.js
Line: 2538
Warning: assignment to undeclared variable j
Source file: file:///E:/sb/mozilla/dist/bin/calendar-js/calStorageCalendar.js
Line: 2579
Warning: assignment to undeclared variable calendarEvent
Source file: chrome://calendar/content/calendar-unifinder.js
Line: 785
Warning: assignment to undeclared variable currentListLength
Source file: chrome://calendar/content/import-export.js
Line: 258
Warning: assignment to undeclared variable newcol
Source file: chrome://calendar/content/calendar-multiday-view.xml
Line: 1286
Warning: reference to undefined property this[varname]
Source file: file:///E:/sb/mozilla/dist/bin/calendar-js/calItemBase.js
Line: 1020
Warning: reference to undefined property this.eventPromotedProps[name]
Source file: file:///E:/sb/mozilla/dist/bin/calendar-js/calEvent.js
Line: 189
Warning: reference to undefined property this.mExceptionMap[getRidKey(aRecurrenceId)]
Source file: file:///E:/sb/mozilla/dist/bin/calendar-js/calRecurrenceInfo.js
Line: 744
Warning: reference to undefined property calendarOfflineManager.prototype
Source file: chrome://calendar/content/calendar-management.js
Line: 259
Warning: reference to undefined property label.localName
Source file: chrome://calendar/content/calendar-base-view.xml
Line: 598
Warning: reference to undefined property unifinderObserver.prototype
Source file: chrome://calendar/content/calendar-unifinder.js
Line: 102
Warning: reference to undefined property window.mAlarmService
Source file: chrome://calendar/content/calendar-alarm-dialog.js
Line: 47
Warning: reference to undefined property window.organizer
Source file: chrome://calendar/content/calendar-event-dialog.js
Line: 2105
Warning: reference to undefined property window.organizer
Source file: chrome://calendar/content/calendar-event-dialog.js
Line: 1230
Warning: reference to undefined property parent.backupPrefList
Source file: chrome://calendar/content/preferences/categories.js
Line: 73
| Reporter | ||
Comment 1•16 years ago
|
||
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b4pre) Gecko/20090420 Calendar/1.0pre (BuildID: 20090420050308).
I now see many (all?) of the warnings in the official 1.9.1 builds too.
| Assignee | ||
Comment 2•16 years ago
|
||
Easy fix for "Warning: reference to undefined property label.localName
Source file: chrome://calendar/content/calendar-base-view.xml". Just a 'let' was missing. I do not if this patch has visible influence on the calendar views.
Attachment #380126 -
Flags: review?(ssitter)
| Assignee | ||
Comment 3•16 years ago
|
||
Stefan, is there any strict JavaScript warning left after my fix from comment#2?
| Reporter | ||
Comment 4•16 years ago
|
||
I still see for example the following warnings:
[JavaScript Warning: "assignment to undeclared variable cachedCalendar" {file:///e:/obj/sb-dbg/mozilla/dist/bin/calendar-js/calCachedCalendar.js" line: 192}]
[JavaScript Warning: "assignment to undeclared variable calendarEvent" {file: "chrome://calendar/content/calendar-unifinder.js" line: 785}]
[JavaScript Warning: "reference to undefined property Components.interfaces.calICachedCalendar" {file:///e:/obj/sb-dbg/mozilla/dist/bin/calendar-js/calCachedCalendar.js" line: 143}]
[JavaScript Warning: "reference to undefined property calendarOfflineManager.prototype" {file: "chrome://calendar/content/calendar-management.js" line: 256}]
[JavaScript Warning: "reference to undefined property label.localName" {file: "chrome://calendar/content/calendar-base-view.xml" line: 602}]
[JavaScript Warning: "reference to undefined property this.eventPromotedProps[name]" {file:///e:/obj/sb-dbg/mozilla/dist/bin/calendar-js/calEvent.js" line: 189}]
[JavaScript Warning: "reference to undefined property this.mTimerMap[calendar.id]" {file: "file:///e:/obj/sb-dbg/mozilla/dist/bin/calendar-js/calAlarmService.js" line: 512}]
[JavaScript Warning: "reference to undefined property this.todoPromotedProps[name]" {file:///e:/obj/sb-dbg/mozilla/dist/bin/calendar-js/calTodo.js" line: 218}]
[JavaScript Warning: "reference to undefined property this[varname]" {file:///e:/obj/sb-dbg/mozilla/dist/bin/calendar-js/calItemBase.js" line: 1021}]
[JavaScript Warning: "reference to undefined property window.mAlarmService" {file: "chrome://calendar/content/calendar-alarm-dialog.js" line: 47}]
[JavaScript Warning: "reference to undefined property window.organizer" {file: "chrome://calendar/content/calendar-event-dialog.js" line: 1239}]
| Reporter | ||
Updated•16 years ago
|
Attachment #380126 -
Flags: review?(ssitter) → review+
| Reporter | ||
Comment 5•16 years ago
|
||
Comment on attachment 380126 [details] [diff] [review]
[checked in] Fix for undefined property label.localName
r=ssitter
| Assignee | ||
Comment 6•16 years ago
|
||
Comment on attachment 380126 [details] [diff] [review]
[checked in] Fix for undefined property label.localName
Pushed to comm-central <http://hg.mozilla.org/comm-central/rev/e2d3efb4e7df>
Attachment #380126 -
Attachment description: Fix for undefined property label.localName → [checked in] Fix for undefined property label.localName
| Assignee | ||
Updated•16 years ago
|
Assignee: nobody → mschroeder
Status: NEW → ASSIGNED
OS: Windows XP → All
Hardware: x86 → All
| Assignee | ||
Comment 7•16 years ago
|
||
Here is a patch for many warnings that you can easily encounter when having javascript.options.strict enabled. Most of the time, there is just a 'let' missing. But I also fixed some indentation and whitespace issues. A lot of the 'reference to undefined property' warnings could be solved when checking '"x" in y' to see if y[x] or y.x exists. When there is a return value needed I use the ternary operator, and I am not always sure if I choose the correct return value in case the property does not exist for an object, so please have a deeper look there.
Some remarks:
> [JavaScript Warning: "reference to undefined property
> Components.interfaces.calICachedCalendar"
> {file:///e:/obj/sb-dbg/mozilla/dist/bin/calendar-js/calCachedCalendar.js" line:
> 143}]
We have no interface for cached calendars. Removing "Components.interfaces.calICachedCalendar" from the array in QueryInterface would fix this. Or do we need to define a interface for other implementations of cached calendars?
> [JavaScript Warning: "reference to undefined property
> calendarOfflineManager.prototype" {file:
> "chrome://calendar/content/calendar-management.js" line: 256}]
Is singleton, and therefore has to be removed!
> [JavaScript Warning: "reference to undefined property
> this.eventPromotedProps[name]"
> {file:///e:/obj/sb-dbg/mozilla/dist/bin/calendar-js/calEvent.js" line: 189}]
Returns false using ternary operator now!
> [JavaScript Warning: "reference to undefined property
> this.todoPromotedProps[name]"
> {file:///e:/obj/sb-dbg/mozilla/dist/bin/calendar-js/calTodo.js" line: 218}]
Returns false using ternary operator now!
> [JavaScript Warning: "reference to undefined property this[varname]"
> {file:///e:/obj/sb-dbg/mozilla/dist/bin/calendar-js/calItemBase.js" line:
> 1021}]
Returns null using ternary operator now!
Attachment #380760 -
Flags: review?(ssitter)
| Assignee | ||
Updated•16 years ago
|
Attachment #380760 -
Flags: review?(dbo.moz)
Comment 8•16 years ago
|
||
Comment on attachment 380760 [details] [diff] [review]
Fix a bunch of strict warnings
>diff --git a/calendar/base/content/calendar-alarm-> function getAlarmService() {
>- if (!window.mAlarmService) {
>+ if (!(mAlarmService in window) || !window.mAlarmService) {
I think this is slightly wrong; |if (!("mAlarmService" in window))| should do it.
> if (ok) {
>- var calMgr = getCalendarManager();
>+ let calMgr = getCalendarManager();
cal.getCalendarManager()?
> function onChangeCalendar(calendar) {
> var args = window.arguments[0];
>- var organizer = args.organizer;
>+ var organizer = ("organizer" in args ? args.organizer: null);
|let organizer = (args.organizer || null)| IMO reads better.
>- args.organizer = window.organizer && window.organizer.clone();
>+ args.organizer = (("organizer" in window && window.organizer) ? window.organizer.clone() : null);
dto here, e.g.
|args.organizer = (window.organizer || null) && window.organizer.clone()|
> if (ok) {
>- var child;
>+ var child;
let?
>- item.organizer = window.organizer;
>+ item.organizer = ("organizer" in window ? window.organizer : null);
dto
> isPropertyPromoted: function (name) {
>- return (this.eventPromotedProps[name]);
>+ // avoid strict undefined property warning
>+ return (name in this.eventPromotedProps ? this.eventPromotedProps[name] : false);
|return (this.eventPromotedProps[name] || false);|
> function makeMemberAttr(ctor, varname, dflt, attr, asProperty) {
> // XXX handle defaults!
> var getter = function () {
> if (asProperty)
> return this.getProperty(varname);
> else
>- return this[varname];
>+ return (varname in this ? this[varname] : null);
dto
> isPropertyPromoted: function (name) {
>- return (this.todoPromotedProps[name]);
>+ // avoid strict undefined property warning
>+ return (name in this.todoPromotedProps ? this.todoPromotedProps[name] : false);
dto
apart from that (though without testing the changes): r=dbo
Attachment #380760 -
Flags: review?(dbo.moz) → review+
| Assignee | ||
Comment 9•16 years ago
|
||
Warning: assignment to undeclared variable gCalItemsArrayFound
Source File: chrome://lightning/content/imip-bar.js
Line: 233
The declaration is the only use of the variable, so we can remove it.db
Attachment #381344 -
Flags: review?(dbo.moz)
Updated•16 years ago
|
Attachment #381344 -
Flags: review?(dbo.moz) → review+
Comment 10•16 years ago
|
||
Comment on attachment 381344 [details] [diff] [review]
[checked in] Fix warning for undeclared variable gCalItemsArrayFound
oh, leftovers from the pre-overhaul code..
thx, r=dbo
| Assignee | ||
Comment 11•16 years ago
|
||
Comment on attachment 381344 [details] [diff] [review]
[checked in] Fix warning for undeclared variable gCalItemsArrayFound
Pushed to comm-central <http://hg.mozilla.org/comm-central/rev/e70ca8d00475>
Attachment #381344 -
Attachment description: Fix warning for undeclared variable gCalItemsArrayFound → [checked in] Fix warning for undeclared variable gCalItemsArrayFound
| Assignee | ||
Comment 12•16 years ago
|
||
(In reply to comment #8)
> (From update of attachment 380760 [details] [diff] [review])
> > function onChangeCalendar(calendar) {
> > var args = window.arguments[0];
> >- var organizer = args.organizer;
> >+ var organizer = ("organizer" in args ? args.organizer: null);
> |let organizer = (args.organizer || null)| IMO reads better.
> >- args.organizer = window.organizer && window.organizer.clone();
> >+ args.organizer = (("organizer" in window && window.organizer) ? window.organizer.clone() : null);
> dto here, e.g.
> |args.organizer = (window.organizer || null) && window.organizer.clone()|
>
> >- item.organizer = window.organizer;
> >+ item.organizer = ("organizer" in window ? window.organizer : null);
> dto
This doesn't work, so I decided to add |window.organizer = null;| in
onLoad(), and leave everything else as is.
Daniel, can you have another quick look at this?
Attachment #380760 -
Attachment is obsolete: true
Attachment #381509 -
Flags: review?(dbo.moz)
Attachment #380760 -
Flags: review?(ssitter)
Comment 13•16 years ago
|
||
> diff --git a/calendar/base/src/calItemBase.js b/calendar/base/src/calItemBase.js
> --- a/calendar/base/src/calItemBase.js
> +++ b/calendar/base/src/calItemBase.js
> @@ -1013,17 +1013,17 @@
> * member.
> */
> function makeMemberAttr(ctor, varname, dflt, attr, asProperty) {
> // XXX handle defaults!
> var getter = function () {
> if (asProperty)
> return this.getProperty(varname);
> else
> - return this[varname];
> + return (this[varname] || null);
> };
This seems wrong: it will turn values like 0 (e.g., PRIORITY) or ""
into null. Also, shouldn't it be using the default 'dflt' value?
return (varname in this ? this[varname] : dflt);
Comment 14•16 years ago
|
||
(In reply to comment #12)
> This doesn't work, so I decided to add |window.organizer = null;| in
> onLoad(), and leave everything else as is.
which is OK, but being curious: why? We've fixed similar lookups e.g. calRecurrenceInfo.js this way. Does |let organizer = (args["organizer"] || null);| work?
(In reply to comment #13)
> > function makeMemberAttr(ctor, varname, dflt, attr, asProperty) {
> > // XXX handle defaults!
> > var getter = function () {
> > if (asProperty)
> > return this.getProperty(varname);
> > else
> > - return this[varname];
> > + return (this[varname] || null);
> > };
>
> This seems wrong: it will turn values like 0 (e.g., PRIORITY) or ""
> into null. Also, shouldn't it be using the default 'dflt' value?
> return (varname in this ? this[varname] : dflt);
Right. Though I am wondering why we run into that warning at all, because we handle all attributes as property (with the exception of attribute properties which seems to be correctly initialized).
Comment 15•16 years ago
|
||
> (In reply to comment #13)
> > > function makeMemberAttr(ctor, varname, dflt, attr, asProperty) {
> > > // XXX handle defaults!
> > > var getter = function () {
> > > if (asProperty)
> > > return this.getProperty(varname);
> > > else
> > > - return this[varname];
> > > + return (this[varname] || null);
> > > };
> >
> > This seems wrong: it will turn values like 0 (e.g., PRIORITY) or ""
> > into null. Also, shouldn't it be using the default 'dflt' value?
> > return (varname in this ? this[varname] : dflt);
> Right. Though I am wondering why we run into that warning at all, because we
> handle all attributes as property (with the exception of attribute properties
> which seems to be correctly initialized).
Not all calls to makeMemberAttr pass true for asProperty.
http://mxr.mozilla.org/comm-central/search?string=makeMemberAttr&find=calendar
shows calls in calAttendee.js
[efficiency nit at this code: wouldn't it be faster to check the asProperty outside the function, and return one of two functions, so the 'if' doesn't have to be executed every call? Or is the compiler smart enough to detect this is a constant and omit the branch?]
Updated•16 years ago
|
Attachment #381509 -
Flags: review?(dbo.moz) → review+
Comment 16•16 years ago
|
||
Comment on attachment 381509 [details] [diff] [review]
[checked in] Fix a bunch of strict warnings v2
Looks good, r=philipp
| Assignee | ||
Comment 17•16 years ago
|
||
(In reply to comment #14)
> (In reply to comment #12)
> > This doesn't work, so I decided to add |window.organizer = null;| in
> > onLoad(), and leave everything else as is.
> which is OK, but being curious: why? We've fixed similar lookups e.g.
> calRecurrenceInfo.js this way. Does |let organizer = (args["organizer"] ||
> null);| work?
No, it doesn't.
| Assignee | ||
Comment 18•16 years ago
|
||
Comment on attachment 381509 [details] [diff] [review]
[checked in] Fix a bunch of strict warnings v2
Pushed to comm-central <http://hg.mozilla.org/comm-central/rev/61c62b2d7ca7> without changes to calItemBase.js
Attachment #381509 -
Attachment description: Fix a bunch of strict warnings v2 → [checked in] Fix a bunch of strict warnings v2
| Assignee | ||
Comment 19•16 years ago
|
||
Daniel, what solution for 'makeMemberAttr' do you prefer?
(a) return (varname in this ? this[varname] : null);
(b) return (varname in this ? this[varname] : dflt);
What else needs to be taken care of if we start using the default value?
Comment 20•16 years ago
|
||
I am not sure whether we should use the default value, but leave it to client code to fall back as in the current code. See also a discussion in bug 367229 about this (maybe we could close it if we come to a consensus). Thus I'd vote to just return null and remove the |dflt| parameter.
| Assignee | ||
Comment 21•16 years ago
|
||
Here is a patch for removing the default value.
Comment 22•16 years ago
|
||
Removing the default values seems outside of the scope of this bug, maybe that part can go in bug 367229, where discussion proposes an alternative place for them.
There should be some way to get defaulted values so that people writing extensions don't all have to provide their own default values (opportunity for inconsistency).
For the purpose of this bug (avoiding warning), this patch avoids the warning (on New Event > Invite Attendees) but does not change the current behavior (returning undefined).
Attachment #385559 -
Flags: review?(mschroeder)
| Assignee | ||
Comment 23•16 years ago
|
||
Comment on attachment 385559 [details] [diff] [review]
[checked in] patch v1: avoid warning in makeMemberAttr getter
Daniel is the appropriate reviewer.
Attachment #385559 -
Flags: review?(mschroeder) → review?(dbo.moz)
Comment 24•16 years ago
|
||
Comment on attachment 385559 [details] [diff] [review]
[checked in] patch v1: avoid warning in makeMemberAttr getter
I've asked before, but why do we need to use the ternary operator instead of |return (this[varname] || undefined)|?
You've fixed a warning in calRecurrenceInfo.js that way (http://mxr.mozilla.org/comm-central/source/calendar/base/src/calRecurrenceInfo.js#748) and I like it.
r=dbo anyway
Attachment #385559 -
Flags: review?(dbo.moz) → review+
Comment 25•16 years ago
|
||
(In reply to comment #24)
> (From update of attachment 385559 [details] [diff] [review])
> I've asked before, but why do we need to use the ternary operator instead of
> |return (this[varname] || undefined)|?
That would return undefined for properties whose value is 0, which seems wrong, as I wrote in comment 13. It might cause round-trip dataloss. For example. undefined percent complete (no percent-complete property in the ICS) could mean progress info is not available; 0 percent complete could mean progress info is available and the task has not been started.
| Assignee | ||
Updated•16 years ago
|
Attachment #385441 -
Attachment is obsolete: true
Comment 26•16 years ago
|
||
Yes, right. I forgot about that.
| Assignee | ||
Comment 27•16 years ago
|
||
Comment on attachment 385559 [details] [diff] [review]
[checked in] patch v1: avoid warning in makeMemberAttr getter
Pushed to comm-central <http://hg.mozilla.org/comm-central/rev/035fc7c4ed38>
Attachment #385559 -
Attachment description: patch v1: avoid warning in makeMemberAttr getter → [checked in] patch v1: avoid warning in makeMemberAttr getter
| Reporter | ||
Comment 28•16 years ago
|
||
I think this bug can be resolved as FIXED. Further strict warnings can be reported with new bugs.
| Assignee | ||
Updated•16 years ago
|
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
Target Milestone: --- → 1.0
Updated•15 years ago
|
Target Milestone: 1.0 → 1.0b1
You need to log in
before you can comment on or make changes to this bug.
Description
•