mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
If an exception is raised by a notification button callback, it is now logged. Also added a unit test for this new behavior.
This commit is contained in:
parent
9cfef4be35
commit
33c970ec5e
@ -125,9 +125,20 @@ Notification.prototype.buttons = [];
|
||||
* A button to display in a notification.
|
||||
*/
|
||||
function NotificationButton(label, accessKey, callback) {
|
||||
function callbackWrapper() {
|
||||
try {
|
||||
callback.apply(this, arguments);
|
||||
} catch (e) {
|
||||
let logger = Log4Moz.Service.getLogger("Notifications");
|
||||
logger.error("An exception occurred: " + Utils.exceptionStr(e));
|
||||
logger.info(Utils.stackTrace(e));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
this.label = label;
|
||||
this.accessKey = accessKey;
|
||||
this.callback = callback;
|
||||
this.callback = callbackWrapper;
|
||||
}
|
||||
|
||||
function TabsNotification() {
|
||||
|
32
services/sync/tests/unit/test_notifications.js
Normal file
32
services/sync/tests/unit/test_notifications.js
Normal file
@ -0,0 +1,32 @@
|
||||
Cu.import("resource://weave/notifications.js");
|
||||
|
||||
function run_test() {
|
||||
var logStats = initTestLogging("Info");
|
||||
|
||||
var blah = 0;
|
||||
|
||||
function callback(i) {
|
||||
blah = i;
|
||||
}
|
||||
|
||||
let button = new NotificationButton("label", "accessKey", callback);
|
||||
|
||||
button.callback(5);
|
||||
|
||||
do_check_eq(blah, 5);
|
||||
do_check_eq(logStats.errorsLogged, 0);
|
||||
|
||||
function badCallback() {
|
||||
throw new Error("oops");
|
||||
}
|
||||
|
||||
button = new NotificationButton("label", "accessKey", badCallback);
|
||||
|
||||
try {
|
||||
button.callback();
|
||||
} catch (e) {
|
||||
do_check_eq(e.message, "oops");
|
||||
}
|
||||
|
||||
do_check_eq(logStats.errorsLogged, 1);
|
||||
}
|
Loading…
Reference in New Issue
Block a user