bug 1520228: toolkit: improve error description when ActorChild is missing EventTarget; r=Felipe
authorAndreas Tolfsen <ato@sny.no>
Tue, 15 Jan 2019 18:10:33 +0000
changeset 511076 6fa82f19a6d708c9db7b37ae39702f759d7cb942
parent 511075 d29c64bd30daa39854747f41bff56d7fb51ca3d3
child 511077 06f2abbc4a597718dc4ada6823c11e2d6b8dbeaa
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1520228
milestone66.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 1520228: toolkit: improve error description when ActorChild is missing EventTarget; r=Felipe When an ActorChild is predefined to listen for DOM events and it does not implement EventTarget.handleEvent(), a standard JS error is thrown in toolkit/modules/ActorManagerChild.jsm that the handleEvent property is missing. If you have more than one ActorChild this error message is cryptic as it does not refer to _which_ of the children that is missing handleEvent. This patch introduces a type check for handleEvent that throws an error (as before) when it is not implemented. Differential Revision: https://phabricator.services.mozilla.com/D16578
toolkit/modules/ActorManagerChild.jsm
--- a/toolkit/modules/ActorManagerChild.jsm
+++ b/toolkit/modules/ActorManagerChild.jsm
@@ -239,17 +239,21 @@ class SingletonDispatcher extends Dispat
     } else if (event.type == "pagehide") {
       this.hidden = true;
       this.cleanup();
     }
   }
 
   handleActorEvent(actor, event) {
     if (event.target.ownerGlobal == this.window) {
-      this.getActor(actor).handleEvent(event);
+      const inst = this.getActor(actor);
+      if (typeof inst.handleEvent != "function") {
+        throw new Error(`Unhandled event for ${actor}: ${event.type}: missing handleEvent`);
+      }
+      inst.handleEvent(event);
     }
   }
 
   addEventListener(event, actor, options) {
     let listener = this.handleActorEvent.bind(this, actor);
     this.listeners.push([event, listener, options]);
     this.mm.addEventListener(event, listener, options);
   }