mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1234020: Part 2l - [webext] Return promises from the alarms API. r=rpl
This commit is contained in:
parent
9613c18150
commit
fcdac58ee5
@ -5,7 +5,6 @@ var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
|||||||
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
|
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
|
||||||
var {
|
var {
|
||||||
EventManager,
|
EventManager,
|
||||||
runSafe,
|
|
||||||
} = ExtensionUtils;
|
} = ExtensionUtils;
|
||||||
|
|
||||||
// WeakMap[Extension -> Set[Alarm]]
|
// WeakMap[Extension -> Set[Alarm]]
|
||||||
@ -114,18 +113,22 @@ extensions.registerPrivilegedAPI("alarms", (extension, context) => {
|
|||||||
[name, callback] = args;
|
[name, callback] = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let alarm of alarmsMap.get(extension)) {
|
let promise = new Promise((resolve, reject) => {
|
||||||
if (alarm.name == name) {
|
for (let alarm of alarmsMap.get(extension)) {
|
||||||
runSafe(context, callback, alarm.data);
|
if (alarm.name == name) {
|
||||||
break;
|
return resolve(alarm.data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
reject("No matching alarm");
|
||||||
|
});
|
||||||
|
|
||||||
|
return context.wrapPromise(promise, callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
getAll: function(callback) {
|
getAll: function(callback) {
|
||||||
let alarms = alarmsMap.get(extension);
|
let alarms = alarmsMap.get(extension);
|
||||||
let result = alarms.map(alarm => alarm.data);
|
let result = alarms.map(alarm => alarm.data);
|
||||||
runSafe(context, callback, result);
|
return context.wrapPromise(Promise.resolve(result), callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
clear: function(...args) {
|
clear: function(...args) {
|
||||||
@ -146,9 +149,7 @@ extensions.registerPrivilegedAPI("alarms", (extension, context) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback) {
|
return context.wrapPromise(Promise.resolve(cleared), callback);
|
||||||
runSafe(context, callback, cleared);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
clearAll: function(callback) {
|
clearAll: function(callback) {
|
||||||
@ -158,9 +159,7 @@ extensions.registerPrivilegedAPI("alarms", (extension, context) => {
|
|||||||
alarm.clear();
|
alarm.clear();
|
||||||
cleared = true;
|
cleared = true;
|
||||||
}
|
}
|
||||||
if (callback) {
|
return context.wrapPromise(Promise.resolve(cleared), callback);
|
||||||
runSafe(context, callback, cleared);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onAlarm: new EventManager(context, "alarms.onAlarm", fire => {
|
onAlarm: new EventManager(context, "alarms.onAlarm", fire => {
|
||||||
|
Loading…
Reference in New Issue
Block a user