2019-07-10 15:03:37 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2017-04-13 11:49:17 +03:00
|
|
|
/** 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) {
|
2017-05-02 02:58:23 +03:00
|
|
|
return function(event) {
|
|
|
|
if (!event) {
|
2018-02-23 03:57:01 +03:00
|
|
|
const exc = new Error("assertIsTrusted did not get an event");
|
2017-04-13 11:49:17 +03:00
|
|
|
exc.noPopup = true;
|
|
|
|
throw exc;
|
|
|
|
}
|
2017-05-02 02:58:23 +03:00
|
|
|
if (!event.isTrusted) {
|
2018-02-23 03:57:01 +03:00
|
|
|
const exc = new Error(`Received untrusted event (type: ${event.type})`);
|
2017-04-13 11:49:17 +03:00
|
|
|
exc.noPopup = true;
|
|
|
|
throw exc;
|
|
|
|
}
|
|
|
|
return handlerFunction.call(this, event);
|
|
|
|
};
|
2018-06-18 19:07:23 +03:00
|
|
|
};
|
2017-04-13 11:49:17 +03:00
|
|
|
null;
|