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

RESOLVED FIXED

Status

P2
normal
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: dcamp, Assigned: irakli)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

5 years ago
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
Created attachment 731349 [details]
Pointer to Github pull request: https://github.com/mozilla/addon-sdk/pull/909

Pointer to Github pull-request
Attachment #731349 - Flags: review?(poirot.alex)

Updated

5 years ago
Priority: -- → P2
Attachment #731349 - Flags: review?(poirot.alex) → review+

Comment 2

5 years ago
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

Updated

5 years ago
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED

Comment 3

5 years ago
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.