fune/browser/extensions/screenshots/webextension/assertIsTrusted.js
Jared Hirsch 47db4ca0b0 Bug 1361208 - import latest version of Screenshots (6.6.0) into the tree; r=standard8
MozReview-Commit-ID: DICbgINxnoa

--HG--
extra : rebase_source : 065193b99216d68cf7f3ab3a41944f3d2a0836eb
2017-05-01 16:58:23 -07:00

20 lines
660 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;