зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
fa8b8506e3
Коммит
8c183735cc
|
@ -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");
|
||||
});
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче