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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andreas Tolfsen 2019-01-15 18:10:33 +00:00
Родитель cb7ce369ed
Коммит c34e8d40b6
1 изменённых файлов: 5 добавлений и 1 удалений

Просмотреть файл

@ -244,7 +244,11 @@ class SingletonDispatcher extends Dispatcher {
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);
}
}