Bug 1498331 - Supports the case where EventEmitter.off is called with more than 3 arguments r=jdescottes
authorJulien Wajsberg <felash@gmail.com>
Fri, 12 Oct 2018 08:39:32 +0000
changeset 499295 00388a3697f10a44b6cc2a7fccd34e6726411555
parent 499294 8fae8b6f75729913a112744214059491dd6b375b
child 499296 b14e0673f3d8af803fb7dbd601e76ed85c749c4f
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1498331
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1498331 - Supports the case where EventEmitter.off is called with more than 3 arguments r=jdescottes Differential Revision: https://phabricator.services.mozilla.com/D8445
devtools/shared/event-emitter.js
devtools/shared/tests/unit/test_eventemitter_static.js
--- a/devtools/shared/event-emitter.js
+++ b/devtools/shared/event-emitter.js
@@ -60,17 +60,17 @@ class EventEmitter {
   static off(target, type, listener) {
     const length = arguments.length;
     const events = target[eventListeners];
 
     if (!events) {
       return;
     }
 
-    if (length === 3) {
+    if (length >= 3) {
       // Trying to remove from the `target` the `listener` specified for the
       // event's `type` given.
       const listenersForType = events.get(type);
 
       // If we don't have listeners for the event's type, we bail out.
       if (!listenersForType) {
         return;
       }
--- a/devtools/shared/tests/unit/test_eventemitter_static.js
+++ b/devtools/shared/tests/unit/test_eventemitter_static.js
@@ -318,16 +318,23 @@ const TESTS = {
 
     emit(target, "foo", "bar");
     emit(target, "foo", "baz");
     emit(target, "done", "");
 
     await Promise.all([pFoo, pDone]);
   },
 
+  testCallingOffWithMoreThan3Args() {
+    const target = { name: "target"};
+    on(target, "data", fail);
+    off(target, "data", fail, undefined);
+    emit(target, "data", "Listener should be removed");
+  }
+
 };
 
 /**
  * Create a runnable tests based on the tests descriptor given.
  *
  * @param {Object} tests
  *  The tests descriptor object, contains the tests to run.
  */