forked from mirrors/gecko-dev
This is imported from https://github.com/mozilla-services/screenshots/. It has been reviewed as patches landed, but also reviewed by Mossop and kmag.
20 lines
663 B
JavaScript
20 lines
663 B
JavaScript
/** For use with addEventListener, assures that any events have event.isTrusted set to true
|
|
https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted
|
|
Should be applied *inside* catcher.watchFunction
|
|
*/
|
|
this.assertIsTrusted = function assertIsTrusted(handlerFunction) {
|
|
return function (event) {
|
|
if (! event) {
|
|
let exc = new Error("assertIsTrusted did not get an event");
|
|
exc.noPopup = true;
|
|
throw exc;
|
|
}
|
|
if (! event.isTrusted) {
|
|
let exc = new Error(`Received untrusted event (type: ${event.type})`);
|
|
exc.noPopup = true;
|
|
throw exc;
|
|
}
|
|
return handlerFunction.call(this, event);
|
|
};
|
|
}
|
|
null;
|