Closed Bug 408942 Opened 17 years ago Closed 17 years ago

For loop loops 4 times when it should only loop 2 times during listener notification

Categories

(Core :: DOM: Events, defect)

1.8 Branch
x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: ole.ersoy, Unassigned)

Details

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070417 Fedora/2.0.0.3-4.fc7 Firefox/2.0.0.3 Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070417 Fedora/2.0.0.3-4.fc7 Firefox/2.0.0.3 This is funky. Really really. OK - I have a dom node that can receive mouseClickEvents. When the click happens a notifyMouseClickListeners() method is called on a component that is bound to the domNode that is clicked. This component has 2 listeners on it, so the loop that notifies the listeners should execute 2 times. I'll first paste the method handling the notification, along with the debug statements contained in it, and then I'll paste the log from Firebug showing what gets printed. Here's the code: notifyMouseClickListeners: function(mouseClickEvent) { if (!this.componentReference.isDisabled()) { var mouseClickListeners = this. componentReference. mouseClickListeners. toArray(); var j = 0; for (i = 0; i<mouseClickListeners.length; i++) { j = j + i; console.debug("I'M BEING NOTIFIED AND i IS: " + i); console.debug("mouseCLickListeners.length is: " + mouseClickListeners.length); console.debug("J IS: " + j); listener = mouseClickListeners[i]; listener.handleMouseClickEvent(mouseClickEvent); } } }, Here's what firebug logs when the node gets clicked: I'M BEING NOTIFIED AND i IS: 0 mouseCLickListeners.length is: 2 J IS: 0 I'M BEING NOTIFIED AND i IS: 1 mouseCLickListeners.length is: 2 J IS: 1 I'M BEING NOTIFIED AND i IS: 1 mouseCLickListeners.length is: 2 J IS: 2 I'M BEING NOTIFIED AND i IS: 1 mouseCLickListeners.length is: 2 J IS: 3 Funky right? The loop executes 2 more times than it is supposed to. All other loops called outside of the event notification context work fine. What would allow the for loop to loop 4 times when clearly it should only loop 2? If this is tricky to isolate, I can probably put this up sometime in the near future. The node being clicked is an Accordion header. The first listener being notified lets the Accordion container know that a header has been click, at which point the Accordion evaluates whether it needs to show a different content pane. The second listener find a IFRAME element and changes the src attribute. Please let me know if there is anything else I can provide that might help resolve this. Cheers, - Ole Reproducible: Always Steps to Reproduce: 1. See Descriptoin 2. 3.
Component: General → DOM: Events
Product: Firefox → Core
QA Contact: general → events
Version: unspecified → 1.8 Branch
Sorry - I'm in need of brain... I just noticed that there is a "var" missing in front of the i loop variable. I put that in and now it works as expected. OOOK - Gooogle for "Monkey Brain Transplant"...
Status: UNCONFIRMED → RESOLVED
Closed: 17 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.