Closed Bug 856146 Opened 11 years ago Closed 11 years ago

event/core/off should prevent in-progress emits from calling the removed handler.

Categories

(Add-on SDK Graveyard :: General, defect, P2)

x86
macOS
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: dcamp, Assigned: irakli)

Details

Attachments

(1 file)

In the dom:

--
function handler2() {
  console.log("got here");
} 
document.body.addEventListener("click", function() {
  document.body.removeEventListener("click", handler2);
});
document.body.addEventListener("click", handler2);
--

Will produce no output.  In addon-sdk:

--

function secondHandler() {
  console.log("got here");
}
 
on(target, "event", function() {
  off(target, "event", secondHandler);
});
on(target, "event", secondHandler);

--

Will print "got here".  This will cause some annoyance when converting devtools code from our EventEmitter to EventTarget, as we rely on off() in destroy methods to prevent further access to the object (and occasionally destroy objects from event handlers - usually in tests).
Assignee: nobody → rFobic
Attachment #731349 - Flags: review?(poirot.alex)
Attachment #731349 - Flags: review?(poirot.alex) → review+
Commit pushed to master at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/58aaa41444765afc5020638df04e91d0aecba8ce
Merge pull request #909 from Gozala/bug/remove-listeners@856146

fix Bug 856146 - Ignore removed listeners during dispatch. r=@ochameau
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Commit pushed to integration at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/58aaa41444765afc5020638df04e91d0aecba8ce
Merge pull request #909 from Gozala/bug/remove-listeners@856146
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: