mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1085199 - Part 2: Do not wrap the DOMRequest in a promise in dom/system/gonk tests; r=hsinyi
DOMRequest now has a .then() method compatible with Promise.
This commit is contained in:
parent
282844d494
commit
a8ad646f8b
@ -17,33 +17,6 @@ ok(ril, "ril.constructor is " + ril.constructor);
|
||||
let radioInterface = ril.getRadioInterface(0);
|
||||
ok(radioInterface, "radioInterface.constructor is " + radioInterface.constrctor);
|
||||
|
||||
/**
|
||||
* Wrap DOMRequest onsuccess/onerror events to Promise resolve/reject.
|
||||
*
|
||||
* Fulfill params: A DOMEvent.
|
||||
* Reject params: A DOMEvent.
|
||||
*
|
||||
* @param aRequest
|
||||
* A DOMRequest instance.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function wrapDomRequestAsPromise(aRequest) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
ok(aRequest instanceof DOMRequest,
|
||||
"aRequest is instanceof " + aRequest.constructor);
|
||||
|
||||
aRequest.addEventListener("success", function(aEvent) {
|
||||
deferred.resolve(aEvent);
|
||||
});
|
||||
aRequest.addEventListener("error", function(aEvent) {
|
||||
deferred.reject(aEvent);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mozSettings value specified by @aKey.
|
||||
*
|
||||
@ -63,11 +36,10 @@ function wrapDomRequestAsPromise(aRequest) {
|
||||
*/
|
||||
function getSettings(aKey, aAllowError) {
|
||||
let request = window.navigator.mozSettings.createLock().get(aKey);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(function resolve(aEvent) {
|
||||
return request.then(function resolve(aValue) {
|
||||
log("getSettings(" + aKey + ") - success");
|
||||
return aEvent.target.result[aKey];
|
||||
}, function reject(aEvent) {
|
||||
return aValue[aKey];
|
||||
}, function reject(aError) {
|
||||
ok(aAllowError, "getSettings(" + aKey + ") - error");
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user