Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#17513 closed defect (fixed)

dijit/_WidgetBase#_set incorrectly calls watchers when oldValue and value are both NaN

Reported by: Colin Snover Owned by: bill
Priority: blocker Milestone: 1.6.3
Component: Dijit Version: 1.6.2
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by Colin Snover)

Because NaN !== NaN is true in JavaScript?, watchers will be fired always in the scenario that oldValue is NaN and value is also NaN.

A (the?) fix is to change if(this._created && value !== oldValue){ to if(this._created && value !== oldValue && !isNaN(value) && !isNaN(oldValue)){ in _WidgetBase#_set.

(This is a particular problem for widgets like NumberTextBox? which use NaN regularly.)

Yay JavaScript?!

Change History (10)

comment:1 Changed 6 years ago by Colin Snover

Description: modified (diff)

comment:2 Changed 6 years ago by Colin Snover

Actually as bill pointed out to me, the above code is not correct because isNaN('foo') is true. The correct thing would be like:

	_set: function(/*String*/ name, /*anything*/ value){
		// summary:
		//		Helper function to set new value for specified attribute, and call handlers
		//		registered with watch() if the value has changed.

		function areBothNaN() {
			return value !== value && oldValue !== oldValue;
		}

		var oldValue = this[name];
		this[name] = value;
		if(this._created && value !== oldValue && !areBothNaN()){
			if(this._watchCallbacks){
				this._watchCallbacks(name, oldValue, value);
			}
			this.emit("attrmodified-" + name, {
				detail: {
					prevValue: oldValue,
					newValue: value
				}
			});
		}
	}
Last edited 6 years ago by Colin Snover (previous) (diff)

comment:3 Changed 6 years ago by Colin Snover

Owner: set to bill
Status: newassigned

comment:4 Changed 6 years ago by Colin Snover

Milestone: tbd1.9.2
Priority: highblocker

comment:5 Changed 6 years ago by Bill Keese <bill@…>

Resolution: fixed
Status: assignedclosed

In d95450e0820da1852880789cbebd8da4760c6dfe/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:5 Changed 6 years ago by Bill Keese <bill@…>

Resolution: fixed
Status: assignedclosed

In ae16bf6bd99c247440fd23743fd6b6824d34940a/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:6 Changed 6 years ago by Bill Keese <bill@…>

In 531b8f46acc8acba87d55a0338649bfc30ae58c9/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:7 Changed 6 years ago by Bill Keese <bill@…>

In 0792bf815b0ccc228f00694a9861607b13cda69d/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:7 Changed 6 years ago by Bill Keese <bill@…>

In 0dafe84e54844c9bedce5ef0150b767471ad27ee/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:8 Changed 6 years ago by bill

Milestone: 1.9.21.6.3
Note: See TracTickets for help on using tickets.