Event.listeners getting munged
Can anybody familiar with the Ext.util.Event class think of how my listeners array occassionally gets munged? I find that scripts start failing, throwing something like "this.listeners.splice" is not a function, and sure enough, this.listeners is an INTEGER! I think equal to the number of elements that were previously in the array. I haven't been able to trace it, but looking at every possible reference to the listeners array in the Event class, I can't see how it would happen. Only Array.slice, Array.splice, and Array.push are used, none of which could either a) transform an array in-place to an int, or b) return an int that gets assigned to this.listeners.
Stumpy am I.
-jeff
// create new observable
var foo = function() {
// on something, add even while firing
foo.superclass.constructor.call(this);
this.events = {'load': true};
this.on('load', function(){ this.loglen(); console.log("ADDING LISTENER, firing? " + this.events.load.firing); this.on('load', this.somethingelse); this.loglen() }, this);
// fire load
this.fireEvent("load");
};
Ext.extend(foo, Ext.util.Observable, {
loglen: function() {
console.log("LISTENERS LENGTH: " + this.events.load.listeners.length);
},
somethingelse: function() {
console.log("RUNNING SOMETHING ELSE");
this.loglen();
console.log("ADDING LISTENER, firing? " + this.events.load.firing);
}
});
var doo = new foo();
W/O Fix, console is:
LISTENERS LENGTH: 1
ADDING LISTENER, firing? true
LISTENERS LENGTH: undefined
After fix, console is:
LISTENERS LENGTH: 1
ADDING LISTENER, firing? true
LISTENERS LENGTH: 2
ext-all-debug.js, line 1342:
this.listeners = this.listeners.slice(0).push(l);
push returns the length of the array. Should be:
(this.listeners = this.listeners.slice(0)).push(l);
I believe the idea here is to not modify in-place the array while firing (lest you foul an iteration going on)... this should work to create a copy, assign it to this.listeners, and push the new value... w/o modifying the orig array.
#If you have any other info about this subject , Please add it free.# |

