fune/browser/extensions/screenshots/webextension/assertIsTrusted.js
Mark Banner 58a6c8c6a4 Bug 1346825 - Import Screenshots version 6.3.0 into mozilla-central. rs=Mossop.
This is imported from https://github.com/mozilla-services/screenshots/.
It has been reviewed as patches landed, but also reviewed by Mossop and kmag.
2017-04-13 09:49:17 +01:00

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;