From b915257904c9e782918841c39fe2762fd82ef06c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Mon, 10 Dec 2012 10:24:01 +0100 Subject: [PATCH] Dont dispatch new added events when running the events dispatch loop. Fixes issue 152 --- .../client/plugins/events/EventsListener.java | 2 +- .../gwt/query/client/GQueryEventsTestGwt.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java index 38366b60..77abf267 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java @@ -495,7 +495,7 @@ public class EventsListener implements EventListener { int etype = getTypeInt(event.getType()); String originalEventType = GqEvent.getOriginalEventType(event); - for (int i = 0; i < elementEvents.length(); i++) { + for (int i = 0, l = elementEvents.length(); i < l; i++) { BindFunction listener = elementEvents.get(i); if (listener.hasEventType(etype) && (originalEventType == null || originalEventType diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java index fbc4c3e8..c5bdc5ac 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java @@ -1223,5 +1223,23 @@ public class GQueryEventsTestGwt extends GWTTestCase { assertEquals("red", $("button").css("color", false)); assertEquals("black", $("button").css("background-color", false)); } + + public void testIssue152() { + $(e).html("
"); + final GQuery div = $(".mdiv", e); + final int[] count = { 0 }; + div.one(Event.ONCLICK, null, new Function() { + public void f() { + count[0]++; + div.one(Event.ONCLICK, null, new Function() { + public void f() { + fail(); + } + }); + }; + }); + div.click(); + assertEquals(1, count[0]); + } } -- 2.39.5