diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index fa235d8e6b26..b9f836aa3690 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -652,7 +652,6 @@ EventListenerManager::RemoveEventListenerInternal( Listener* listener; uint32_t count = mListeners.Length(); - uint32_t typeCount = 0; bool deviceType = IsDeviceType(aEventMessage); RefPtr kungFuDeathGrip(this); @@ -661,23 +660,18 @@ EventListenerManager::RemoveEventListenerInternal( listener = &mListeners.ElementAt(i); if (EVENT_TYPE_EQUALS(listener, aEventMessage, aUserType, aTypeString, aAllEvents)) { - ++typeCount; if (listener->mListener == aListenerHolder && listener->mFlags.EqualsForRemoval(aFlags)) { mListeners.RemoveElementAt(i); - --count; NotifyEventListenerRemoved(aUserType); - if (!deviceType) { - return; + if (!aAllEvents && deviceType) { + DisableDevice(aEventMessage); } - --typeCount; + return; } } } - if (!aAllEvents && deviceType && typeCount == 0) { - DisableDevice(aEventMessage); - } } bool @@ -927,6 +921,9 @@ EventListenerManager::RemoveEventHandler(nsIAtom* aName, if (listener) { mListeners.RemoveElementAt(uint32_t(listener - &mListeners.ElementAt(0))); NotifyEventListenerRemoved(aName); + if (IsDeviceType(eventMessage)) { + DisableDevice(eventMessage); + } } } diff --git a/dom/events/test/test_bug742376.html b/dom/events/test/test_bug742376.html index 4c3cea7e20ee..7672ea014f69 100644 --- a/dom/events/test/test_bug742376.html +++ b/dom/events/test/test_bug742376.html @@ -31,8 +31,10 @@ is(hasListeners(), false, "Must not have listeners before tests start"); function dumbListener(event) {} function dumbListener2(event) {} +function dumbListener3(event) {} window.addEventListener("deviceorientation", dumbListener, false); +window.addEventListener("random_event_name", function() {}, false); window.addEventListener("deviceorientation", dumbListener2, false); is(hasListeners(), true, "Listeners should have been added"); @@ -46,11 +48,23 @@ window.setTimeout(function() { window.removeEventListener("deviceorientation", dumbListener2, false); window.setTimeout(function() { is(hasListeners(), false, "Listeners should have been removed"); - SimpleTest.finish(); + testEventHandler(); }, 0); }, 0); }, 0); +function testEventHandler() { + window.ondeviceorientation = function() {} + window.setTimeout(function() { + is(hasListeners(), true, "Handler should have been added"); + window.ondeviceorientation = null; + window.setTimeout(function() { + is(hasListeners(), false, "Handler should have been removed"); + SimpleTest.finish(); + }, 0); + }, 0) +} + SimpleTest.waitForExplicitFinish();