зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1374282 - script generated patch to remove Promise.defer calls, r=Mossop.
This commit is contained in:
Родитель
fb91723a8a
Коммит
5b8f8b884c
|
@ -39,50 +39,50 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=840488
|
|||
});
|
||||
|
||||
function navigateFrame(ifr, src) {
|
||||
let deferred = Promise.defer();
|
||||
function onload() {
|
||||
ifr.removeEventListener('load', onload);
|
||||
deferred.resolve();
|
||||
}
|
||||
ifr.addEventListener('load', onload, false);
|
||||
ifr.setAttribute('src', src);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
function onload() {
|
||||
ifr.removeEventListener('load', onload);
|
||||
resolve();
|
||||
}
|
||||
ifr.addEventListener('load', onload, false);
|
||||
ifr.setAttribute('src', src);
|
||||
});
|
||||
}
|
||||
|
||||
function navigateBack(ifr) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
// pageshow events don't fire on the iframe element, so we need to use the
|
||||
// chrome event handler for the docshell.
|
||||
var browser = ifr.contentWindow
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell)
|
||||
.chromeEventHandler;
|
||||
function onpageshow(evt) {
|
||||
info("Navigated back. Persisted: " + evt.persisted);
|
||||
browser.removeEventListener('pageshow', onpageshow);
|
||||
deferred.resolve();
|
||||
}
|
||||
browser.addEventListener('pageshow', onpageshow, false);
|
||||
ifr.contentWindow.history.back();
|
||||
return deferred.promise;
|
||||
// pageshow events don't fire on the iframe element, so we need to use the
|
||||
// chrome event handler for the docshell.
|
||||
var browser = ifr.contentWindow
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell)
|
||||
.chromeEventHandler;
|
||||
function onpageshow(evt) {
|
||||
info("Navigated back. Persisted: " + evt.persisted);
|
||||
browser.removeEventListener('pageshow', onpageshow);
|
||||
resolve();
|
||||
}
|
||||
browser.addEventListener('pageshow', onpageshow, false);
|
||||
ifr.contentWindow.history.back();
|
||||
});
|
||||
}
|
||||
|
||||
function addFrame(parentWin, name, expectOnload) {
|
||||
let ifr = parentWin.document.createElement('iframe');
|
||||
parentWin.document.body.appendChild(ifr);
|
||||
ifr.setAttribute('name', name);
|
||||
let deferred = Promise.defer();
|
||||
// We need to append 'name' to avoid running afoul of recursive frame detection.
|
||||
let frameURI = uri + "?name=" + name;
|
||||
navigateFrame(ifr, frameURI).then(function() {
|
||||
is(String(ifr.contentWindow.location), frameURI, "Successful load");
|
||||
is(!!ifr.contentWindow.wrappedJSObject.gFiredOnload, expectOnload,
|
||||
"onload should only fire when scripts are enabled");
|
||||
deferred.resolve();
|
||||
return new Promise(resolve => {
|
||||
// We need to append 'name' to avoid running afoul of recursive frame detection.
|
||||
let frameURI = uri + "?name=" + name;
|
||||
navigateFrame(ifr, frameURI).then(function() {
|
||||
is(String(ifr.contentWindow.location), frameURI, "Successful load");
|
||||
is(!!ifr.contentWindow.wrappedJSObject.gFiredOnload, expectOnload,
|
||||
"onload should only fire when scripts are enabled");
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function checkScriptEnabled(win, expectEnabled) {
|
||||
|
@ -99,17 +99,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=840488
|
|||
|
||||
function testList(expectEnabled, win, list, idx) {
|
||||
idx = idx || 0;
|
||||
let deferred = Promise.defer();
|
||||
let target = list[idx] + path;
|
||||
info("Testing scriptability for: " + target + ". expecting " + expectEnabled);
|
||||
navigateFrame(win.frameElement, target).then(function() {
|
||||
checkScriptEnabled(win, expectEnabled);
|
||||
if (idx == list.length - 1)
|
||||
deferred.resolve();
|
||||
else
|
||||
testList(expectEnabled, win, list, idx + 1).then(function() { deferred.resolve(); });
|
||||
return new Promise(resolve => {
|
||||
let target = list[idx] + path;
|
||||
info("Testing scriptability for: " + target + ". expecting " + expectEnabled);
|
||||
navigateFrame(win.frameElement, target).then(function() {
|
||||
checkScriptEnabled(win, expectEnabled);
|
||||
if (idx == list.length - 1)
|
||||
resolve();
|
||||
else
|
||||
testList(expectEnabled, win, list, idx + 1).then(function() { resolve(); });
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function testDomainPolicy(defaultScriptability, exceptions, superExceptions,
|
||||
|
@ -131,13 +131,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=840488
|
|||
}
|
||||
|
||||
function reloadFrame(frame) {
|
||||
let deferred = Promise.defer();
|
||||
frame.addEventListener('load', function onload() {
|
||||
deferred.resolve();
|
||||
frame.removeEventListener('load', onload);
|
||||
}, false);
|
||||
frame.contentWindow.location.reload(true);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
frame.addEventListener('load', function onload() {
|
||||
resolve();
|
||||
frame.removeEventListener('load', onload);
|
||||
}, false);
|
||||
frame.contentWindow.location.reload(true);
|
||||
});
|
||||
}
|
||||
|
||||
function go() {
|
||||
|
|
|
@ -22,22 +22,22 @@ var _pendingEmulatorCmdCount = 0;
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function runEmulatorCmdSafe(aCommand) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
++_pendingEmulatorCmdCount;
|
||||
runEmulatorCmd(aCommand, function(aResult) {
|
||||
--_pendingEmulatorCmdCount;
|
||||
++_pendingEmulatorCmdCount;
|
||||
runEmulatorCmd(aCommand, function(aResult) {
|
||||
--_pendingEmulatorCmdCount;
|
||||
|
||||
ok(true, "Emulator response: " + JSON.stringify(aResult));
|
||||
if (Array.isArray(aResult) &&
|
||||
aResult[aResult.length - 1] === "OK") {
|
||||
resolve(aResult);
|
||||
} else {
|
||||
reject(aResult);
|
||||
}
|
||||
});
|
||||
|
||||
ok(true, "Emulator response: " + JSON.stringify(aResult));
|
||||
if (Array.isArray(aResult) &&
|
||||
aResult[aResult.length - 1] === "OK") {
|
||||
deferred.resolve(aResult);
|
||||
} else {
|
||||
deferred.reject(aResult);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,14 +100,14 @@ function setEmulatorOrientationValues(aAzimuth, aPitch, aRoll) {
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function waitForWindowEvent(aEventName) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
window.addEventListener(aEventName, function(aEvent) {
|
||||
ok(true, "Window event '" + aEventName + "' got.");
|
||||
deferred.resolve(aEvent);
|
||||
}, {once: true});
|
||||
window.addEventListener(aEventName, function(aEvent) {
|
||||
ok(true, "Window event '" + aEventName + "' got.");
|
||||
resolve(aEvent);
|
||||
}, {once: true});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -227,18 +227,18 @@ function createFromPathHandler(server, path, href, lazyPing) {
|
|||
// page we can use as the href attribute for links. It returns a promise that
|
||||
// will be resolved once the page has been requested.
|
||||
function createToPathHandler(server, path) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
server.registerPathHandler(path, function (request, response) {
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.setHeader("Content-Type", "text/html;charset=utf-8", false);
|
||||
response.setHeader("Cache-Control", "no-cache", false);
|
||||
response.write("OK");
|
||||
server.registerPathHandler(path, function (request, response) {
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.setHeader("Content-Type", "text/html;charset=utf-8", false);
|
||||
response.setHeader("Cache-Control", "no-cache", false);
|
||||
response.write("OK");
|
||||
|
||||
resolve();
|
||||
});
|
||||
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Register multiple path handlers for the given server that will receive
|
||||
|
@ -255,47 +255,47 @@ function createPingPathHandlers(server, paths, lazyHeaders) {
|
|||
// are given as expected. It returns a promise that will be resolved once the
|
||||
// ping has been received.
|
||||
function createPingPathHandler(server, path, lazyHeaders) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
server.registerPathHandler(path, function (request, response) {
|
||||
let headers = lazyHeaders();
|
||||
server.registerPathHandler(path, function (request, response) {
|
||||
let headers = lazyHeaders();
|
||||
|
||||
is(request.method, "POST", "correct http method used");
|
||||
is(request.getHeader("Ping-To"), headers.to, "valid ping-to header");
|
||||
is(request.method, "POST", "correct http method used");
|
||||
is(request.getHeader("Ping-To"), headers.to, "valid ping-to header");
|
||||
|
||||
if ("from" in headers) {
|
||||
is(request.getHeader("Ping-From"), headers.from, "valid ping-from header");
|
||||
} else {
|
||||
ok(!request.hasHeader("Ping-From"), "no ping-from header");
|
||||
}
|
||||
if ("from" in headers) {
|
||||
is(request.getHeader("Ping-From"), headers.from, "valid ping-from header");
|
||||
} else {
|
||||
ok(!request.hasHeader("Ping-From"), "no ping-from header");
|
||||
}
|
||||
|
||||
if ("referrer" in headers) {
|
||||
is(request.getHeader("Referer"), headers.referrer, "valid referer header");
|
||||
} else {
|
||||
ok(!request.hasHeader("Referer"), "no referer header");
|
||||
}
|
||||
if ("referrer" in headers) {
|
||||
is(request.getHeader("Referer"), headers.referrer, "valid referer header");
|
||||
} else {
|
||||
ok(!request.hasHeader("Referer"), "no referer header");
|
||||
}
|
||||
|
||||
let bs = request.bodyInputStream;
|
||||
let body = NetUtil.readInputStreamToString(bs, bs.available());
|
||||
is(body, "PING", "correct body sent");
|
||||
let bs = request.bodyInputStream;
|
||||
let body = NetUtil.readInputStreamToString(bs, bs.available());
|
||||
is(body, "PING", "correct body sent");
|
||||
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.setHeader("Content-Type", "text/html;charset=utf-8", false);
|
||||
response.setHeader("Cache-Control", "no-cache", false);
|
||||
response.write("OK");
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.setHeader("Content-Type", "text/html;charset=utf-8", false);
|
||||
response.setHeader("Cache-Control", "no-cache", false);
|
||||
response.write("OK");
|
||||
|
||||
resolve();
|
||||
});
|
||||
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Returns a promise that is resolved when the given http server instance has
|
||||
// been stopped.
|
||||
function stopServer(server) {
|
||||
let deferred = Promise.defer();
|
||||
server.stop(deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
server.stop(resolve);
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
|
@ -32,21 +32,21 @@ let gTestSuite = (function() {
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function runEmulatorShellSafe(command) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
++pendingEmulatorShellCount;
|
||||
runEmulatorShell(command, function(aResult) {
|
||||
--pendingEmulatorShellCount;
|
||||
++pendingEmulatorShellCount;
|
||||
runEmulatorShell(command, function(aResult) {
|
||||
--pendingEmulatorShellCount;
|
||||
|
||||
ok(true, "Emulator shell response: " + JSON.stringify(aResult));
|
||||
if (Array.isArray(aResult)) {
|
||||
resolve(aResult);
|
||||
} else {
|
||||
reject(aResult);
|
||||
}
|
||||
});
|
||||
|
||||
ok(true, "Emulator shell response: " + JSON.stringify(aResult));
|
||||
if (Array.isArray(aResult)) {
|
||||
deferred.resolve(aResult);
|
||||
} else {
|
||||
deferred.reject(aResult);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -270,13 +270,13 @@ let gTestSuite = (function() {
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function scanInterfaces() {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
ethernetManager.scan(function onScan(list) {
|
||||
resolve(list);
|
||||
});
|
||||
|
||||
ethernetManager.scan(function onScan(list) {
|
||||
deferred.resolve(list);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -290,16 +290,16 @@ let gTestSuite = (function() {
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function addInterface(ifname) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
ethernetManager.addInterface(ifname, function onAdd(success, message) {
|
||||
ok(success, "Add interface " + ifname + " succeeded.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
ethernetManager.addInterface(ifname, function onAdd(success, message) {
|
||||
ok(success, "Add interface " + ifname + " succeeded.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
|
||||
resolve(success);
|
||||
});
|
||||
|
||||
deferred.resolve(success);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -313,16 +313,16 @@ let gTestSuite = (function() {
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function removeInterface(ifname) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
ethernetManager.removeInterface(ifname, function onRemove(success, message) {
|
||||
ok(success, "Remove interface " + ifname + " succeeded.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
ethernetManager.removeInterface(ifname, function onRemove(success, message) {
|
||||
ok(success, "Remove interface " + ifname + " succeeded.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
|
||||
resolve(success);
|
||||
});
|
||||
|
||||
deferred.resolve(success);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -336,16 +336,16 @@ let gTestSuite = (function() {
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function enableInterface(ifname) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
ethernetManager.enable(ifname, function onEnable(success, message) {
|
||||
ok(success, "Enable interface " + ifname + " succeeded.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
ethernetManager.enable(ifname, function onEnable(success, message) {
|
||||
ok(success, "Enable interface " + ifname + " succeeded.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
|
||||
resolve(success);
|
||||
});
|
||||
|
||||
deferred.resolve(success);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -359,16 +359,16 @@ let gTestSuite = (function() {
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function disableInterface(ifname) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
ethernetManager.disable(ifname, function onDisable(success, message) {
|
||||
ok(success, "Disable interface " + ifname + " succeeded.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
ethernetManager.disable(ifname, function onDisable(success, message) {
|
||||
ok(success, "Disable interface " + ifname + " succeeded.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
|
||||
resolve(success);
|
||||
});
|
||||
|
||||
deferred.resolve(success);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -382,16 +382,16 @@ let gTestSuite = (function() {
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function makeInterfaceConnect(ifname) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
ethernetManager.connect(ifname, function onConnect(success, message) {
|
||||
ok(success, "Interface " + ifname + " is connected successfully.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
ethernetManager.connect(ifname, function onConnect(success, message) {
|
||||
ok(success, "Interface " + ifname + " is connected successfully.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
|
||||
resolve(success);
|
||||
});
|
||||
|
||||
deferred.resolve(success);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -405,16 +405,16 @@ let gTestSuite = (function() {
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function makeInterfaceDisconnect(ifname) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
ethernetManager.disconnect(ifname, function onDisconnect(success, message) {
|
||||
ok(success, "Interface " + ifname + " is disconnected successfully.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
ethernetManager.disconnect(ifname, function onDisconnect(success, message) {
|
||||
ok(success, "Interface " + ifname + " is disconnected successfully.");
|
||||
is(message, "ok", "Message is as expected.");
|
||||
|
||||
resolve(success);
|
||||
});
|
||||
|
||||
deferred.resolve(success);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -434,18 +434,18 @@ let gTestSuite = (function() {
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function updateInterfaceConfig(ifname, config) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
ethernetManager.updateInterfaceConfig(ifname, config,
|
||||
function onUpdated(success, message) {
|
||||
ok(success, "Interface " + ifname + " config is updated successfully " +
|
||||
"with " + JSON.stringify(config));
|
||||
is(message, "ok", "Message is as expected.");
|
||||
ethernetManager.updateInterfaceConfig(ifname, config,
|
||||
function onUpdated(success, message) {
|
||||
ok(success, "Interface " + ifname + " config is updated successfully " +
|
||||
"with " + JSON.stringify(config));
|
||||
is(message, "ok", "Message is as expected.");
|
||||
|
||||
resolve(success);
|
||||
});
|
||||
|
||||
deferred.resolve(success);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -457,14 +457,14 @@ let gTestSuite = (function() {
|
|||
* @return A deferred promise.
|
||||
*/
|
||||
function waitForTimeout(timeout) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
setTimeout(function() {
|
||||
ok(true, "waitForTimeout " + timeout);
|
||||
deferred.resolve();
|
||||
}, timeout);
|
||||
setTimeout(function() {
|
||||
ok(true, "waitForTimeout " + timeout);
|
||||
resolve();
|
||||
}, timeout);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -133,63 +133,63 @@ function loadAddonManager() {
|
|||
// Install addon and return a Promise<boolean> that is
|
||||
// resolve with true on success, false otherwise.
|
||||
function installAddon(relativePath) {
|
||||
let deferred = Promise.defer();
|
||||
let success = () => deferred.resolve(true);
|
||||
let fail = () => deferred.resolve(false);
|
||||
let listener = {
|
||||
onDownloadCancelled: fail,
|
||||
onDownloadFailed: fail,
|
||||
onInstallCancelled: fail,
|
||||
onInstallFailed: fail,
|
||||
onInstallEnded: success,
|
||||
};
|
||||
return new Promise(resolve => {
|
||||
let success = () => resolve(true);
|
||||
let fail = () => resolve(false);
|
||||
let listener = {
|
||||
onDownloadCancelled: fail,
|
||||
onDownloadFailed: fail,
|
||||
onInstallCancelled: fail,
|
||||
onInstallFailed: fail,
|
||||
onInstallEnded: success,
|
||||
};
|
||||
|
||||
let installCallback = install => {
|
||||
install.addListener(listener);
|
||||
install.install();
|
||||
};
|
||||
let installCallback = install => {
|
||||
install.addListener(listener);
|
||||
install.install();
|
||||
};
|
||||
|
||||
let file = do_get_file(relativePath, false);
|
||||
AddonManager.getInstallForFile(file, installCallback,
|
||||
"application/x-xpinstall");
|
||||
let file = do_get_file(relativePath, false);
|
||||
AddonManager.getInstallForFile(file, installCallback,
|
||||
"application/x-xpinstall");
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
// Uninstall addon and return a Promise<boolean> that is
|
||||
// resolve with true on success, false otherwise.
|
||||
function uninstallAddon(id) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
AddonManager.getAddonByID(id, addon => {
|
||||
if (!addon) {
|
||||
deferred.resolve(false);
|
||||
}
|
||||
|
||||
let listener = {};
|
||||
let handler = addon => {
|
||||
if (addon.id !== id) {
|
||||
return;
|
||||
AddonManager.getAddonByID(id, addon => {
|
||||
if (!addon) {
|
||||
resolve(false);
|
||||
}
|
||||
|
||||
AddonManager.removeAddonListener(listener);
|
||||
deferred.resolve(true);
|
||||
};
|
||||
let listener = {};
|
||||
let handler = addon => {
|
||||
if (addon.id !== id) {
|
||||
return;
|
||||
}
|
||||
|
||||
listener.onUninstalled = handler;
|
||||
listener.onDisabled = handler;
|
||||
AddonManager.removeAddonListener(listener);
|
||||
resolve(true);
|
||||
};
|
||||
|
||||
listener.onUninstalled = handler;
|
||||
listener.onDisabled = handler;
|
||||
|
||||
AddonManager.addAddonListener(listener);
|
||||
addon.uninstall();
|
||||
});
|
||||
|
||||
AddonManager.addAddonListener(listener);
|
||||
addon.uninstall();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Returns a Promise<Addon> that is resolved with
|
||||
// the corresponding addon or rejected.
|
||||
function getAddonByID(id) {
|
||||
let deferred = Promise.defer();
|
||||
AddonManager.getAddonByID(id, addon => deferred.resolve(addon));
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
AddonManager.getAddonByID(id, addon => resolve(addon));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -30,18 +30,18 @@ versionAttr.setPropertyAsUint32("version", LATEST_VERSION);
|
|||
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
|
||||
function sleep(aMs) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
let timer = Cc["@mozilla.org/timer;1"]
|
||||
.createInstance(Ci.nsITimer);
|
||||
let timer = Cc["@mozilla.org/timer;1"]
|
||||
.createInstance(Ci.nsITimer);
|
||||
|
||||
timer.initWithCallback({
|
||||
notify: function () {
|
||||
deferred.resolve();
|
||||
},
|
||||
}, aMs, timer.TYPE_ONE_SHOT);
|
||||
timer.initWithCallback({
|
||||
notify: function () {
|
||||
resolve();
|
||||
},
|
||||
}, aMs, timer.TYPE_ONE_SHOT);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function MockFactory(aClass) {
|
||||
|
|
|
@ -13,25 +13,25 @@ function run_test() {
|
|||
}
|
||||
|
||||
function talk_with_worker(worker) {
|
||||
let deferred = Promise.defer();
|
||||
worker.onmessage = function(event) {
|
||||
let success = true;
|
||||
if (event.data == "OK") {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
success = false;
|
||||
deferred.reject(event);
|
||||
}
|
||||
do_check_true(success);
|
||||
worker.terminate();
|
||||
};
|
||||
worker.onerror = function(event) {
|
||||
let error = new Error(event.message, event.filename, event.lineno);
|
||||
worker.terminate();
|
||||
deferred.reject(error);
|
||||
};
|
||||
worker.postMessage("START");
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
worker.onmessage = function(event) {
|
||||
let success = true;
|
||||
if (event.data == "OK") {
|
||||
resolve();
|
||||
} else {
|
||||
success = false;
|
||||
reject(event);
|
||||
}
|
||||
do_check_true(success);
|
||||
worker.terminate();
|
||||
};
|
||||
worker.onerror = function(event) {
|
||||
let error = new Error(event.message, event.filename, event.lineno);
|
||||
worker.terminate();
|
||||
reject(error);
|
||||
};
|
||||
worker.postMessage("START");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,25 +13,25 @@ function run_test() {
|
|||
}
|
||||
|
||||
function talk_with_worker(worker) {
|
||||
let deferred = Promise.defer();
|
||||
worker.onmessage = function(event) {
|
||||
let success = true;
|
||||
if (event.data == "OK") {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
success = false;
|
||||
deferred.reject(event);
|
||||
}
|
||||
do_check_true(success);
|
||||
worker.terminate();
|
||||
};
|
||||
worker.onerror = function(event) {
|
||||
let error = new Error(event.message, event.filename, event.lineno);
|
||||
worker.terminate();
|
||||
deferred.reject(error);
|
||||
};
|
||||
worker.postMessage("START");
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
worker.onmessage = function(event) {
|
||||
let success = true;
|
||||
if (event.data == "OK") {
|
||||
resolve();
|
||||
} else {
|
||||
success = false;
|
||||
reject(event);
|
||||
}
|
||||
do_check_true(success);
|
||||
worker.terminate();
|
||||
};
|
||||
worker.onerror = function(event) {
|
||||
let error = new Error(event.message, event.filename, event.lineno);
|
||||
worker.terminate();
|
||||
reject(error);
|
||||
};
|
||||
worker.postMessage("START");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,9 +10,9 @@ const TEST_PERMISSION = "test-permission";
|
|||
Components.utils.import("resource://gre/modules/Promise.jsm");
|
||||
|
||||
function promiseTimeout(delay) {
|
||||
let deferred = Promise.defer();
|
||||
do_timeout(delay, deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
do_timeout(delay, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
@ -237,29 +237,29 @@ function findCapabilityViaEnum(origin = TEST_ORIGIN, type = TEST_PERMISSION) {
|
|||
// the permission manager update has completed - so we just retry a few times.
|
||||
// Returns a promise.
|
||||
function checkCapabilityViaDB(expected, origin = TEST_ORIGIN, type = TEST_PERMISSION) {
|
||||
let deferred = Promise.defer();
|
||||
let count = 0;
|
||||
let max = 20;
|
||||
let do_check = () => {
|
||||
let got = findCapabilityViaDB(origin, type);
|
||||
if (got == expected) {
|
||||
// the do_check_eq() below will succeed - which is what we want.
|
||||
do_check_eq(got, expected, "The database has the expected value");
|
||||
deferred.resolve();
|
||||
return;
|
||||
return new Promise(resolve => {
|
||||
let count = 0;
|
||||
let max = 20;
|
||||
let do_check = () => {
|
||||
let got = findCapabilityViaDB(origin, type);
|
||||
if (got == expected) {
|
||||
// the do_check_eq() below will succeed - which is what we want.
|
||||
do_check_eq(got, expected, "The database has the expected value");
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
// value isn't correct - see if we've retried enough
|
||||
if (count++ == max) {
|
||||
// the do_check_eq() below will fail - which is what we want.
|
||||
do_check_eq(got, expected, "The database wasn't updated with the expected value");
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
// we can retry...
|
||||
do_timeout(100, do_check);
|
||||
}
|
||||
// value isn't correct - see if we've retried enough
|
||||
if (count++ == max) {
|
||||
// the do_check_eq() below will fail - which is what we want.
|
||||
do_check_eq(got, expected, "The database wasn't updated with the expected value");
|
||||
deferred.resolve();
|
||||
return;
|
||||
}
|
||||
// we can retry...
|
||||
do_timeout(100, do_check);
|
||||
}
|
||||
do_check();
|
||||
return deferred.promise;
|
||||
do_check();
|
||||
});
|
||||
}
|
||||
|
||||
// use the DB to find the requested permission. Returns the permission
|
||||
|
|
|
@ -18,36 +18,36 @@ function makeBuffer(length) {
|
|||
* |false| if there was a warning.
|
||||
*/
|
||||
function checkWarning(pref, buffer) {
|
||||
let deferred = Promise.defer();
|
||||
let complete = false;
|
||||
let listener = {
|
||||
observe: function(event) {
|
||||
let message = event.message;
|
||||
if (!(message.startsWith("Warning: attempting to write")
|
||||
&& message.includes(pref))) {
|
||||
return;
|
||||
return new Promise(resolve => {
|
||||
let complete = false;
|
||||
let listener = {
|
||||
observe: function(event) {
|
||||
let message = event.message;
|
||||
if (!(message.startsWith("Warning: attempting to write")
|
||||
&& message.includes(pref))) {
|
||||
return;
|
||||
}
|
||||
if (complete) {
|
||||
return;
|
||||
}
|
||||
complete = true;
|
||||
do_print("Warning while setting " + pref);
|
||||
cs.unregisterListener(listener);
|
||||
resolve(true);
|
||||
}
|
||||
};
|
||||
do_timeout(1000, function() {
|
||||
if (complete) {
|
||||
return;
|
||||
}
|
||||
complete = true;
|
||||
do_print("Warning while setting " + pref);
|
||||
do_print("No warning while setting " + pref);
|
||||
cs.unregisterListener(listener);
|
||||
deferred.resolve(true);
|
||||
}
|
||||
};
|
||||
do_timeout(1000, function() {
|
||||
if (complete) {
|
||||
return;
|
||||
}
|
||||
complete = true;
|
||||
do_print("No warning while setting " + pref);
|
||||
cs.unregisterListener(listener);
|
||||
deferred.resolve(false);
|
||||
resolve(false);
|
||||
});
|
||||
cs.registerListener(listener);
|
||||
ps.setCharPref(pref, buffer);
|
||||
});
|
||||
cs.registerListener(listener);
|
||||
ps.setCharPref(pref, buffer);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
|
|
@ -170,9 +170,9 @@ function test_async_copy()
|
|||
let TEST_DATA = "[" + make_sample(text) + "]";
|
||||
let source = make_input(bufferedInput, TEST_DATA);
|
||||
let {file, sink} = make_output(bufferedOutput);
|
||||
let deferred = Promise.defer();
|
||||
NetUtil.asyncCopy(source, sink, deferred.resolve);
|
||||
let result = await deferred.promise;
|
||||
let result = await new Promise(resolve => {
|
||||
NetUtil.asyncCopy(source, sink, resolve);
|
||||
});
|
||||
|
||||
// Make sure the copy was successful!
|
||||
if (!Components.isSuccessCode(result)) {
|
||||
|
|
|
@ -104,25 +104,25 @@ function toHex(str) {
|
|||
* @rejects Never.
|
||||
*/
|
||||
function promiseVerifyContents(aFile, aExpectedContents) {
|
||||
let deferred = Promise.defer();
|
||||
NetUtil.asyncFetch({
|
||||
uri: NetUtil.newURI(aFile),
|
||||
loadUsingSystemPrincipal: true
|
||||
}, function(aInputStream, aStatus) {
|
||||
do_check_true(Components.isSuccessCode(aStatus));
|
||||
let contents = NetUtil.readInputStreamToString(aInputStream,
|
||||
aInputStream.available());
|
||||
if (contents.length <= TEST_DATA_SHORT.length * 2) {
|
||||
do_check_eq(contents, aExpectedContents);
|
||||
} else {
|
||||
// Do not print the entire content string to the test log.
|
||||
do_check_eq(contents.length, aExpectedContents.length);
|
||||
do_check_true(contents == aExpectedContents);
|
||||
}
|
||||
deferred.resolve();
|
||||
});
|
||||
return new Promise(resolve => {
|
||||
NetUtil.asyncFetch({
|
||||
uri: NetUtil.newURI(aFile),
|
||||
loadUsingSystemPrincipal: true
|
||||
}, function(aInputStream, aStatus) {
|
||||
do_check_true(Components.isSuccessCode(aStatus));
|
||||
let contents = NetUtil.readInputStreamToString(aInputStream,
|
||||
aInputStream.available());
|
||||
if (contents.length <= TEST_DATA_SHORT.length * 2) {
|
||||
do_check_eq(contents, aExpectedContents);
|
||||
} else {
|
||||
// Do not print the entire content string to the test log.
|
||||
do_check_eq(contents.length, aExpectedContents.length);
|
||||
do_check_true(contents == aExpectedContents);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,24 +138,24 @@ function promiseVerifyContents(aFile, aExpectedContents) {
|
|||
* @rejects With an exception, if onSaveComplete is called with a failure code.
|
||||
*/
|
||||
function promiseSaverComplete(aSaver, aOnTargetChangeFn) {
|
||||
let deferred = Promise.defer();
|
||||
aSaver.observer = {
|
||||
onTargetChange: function BFSO_onSaveComplete(aSaver, aTarget)
|
||||
{
|
||||
if (aOnTargetChangeFn) {
|
||||
aOnTargetChangeFn(aTarget);
|
||||
}
|
||||
},
|
||||
onSaveComplete: function BFSO_onSaveComplete(aSaver, aStatus)
|
||||
{
|
||||
if (Components.isSuccessCode(aStatus)) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject(new Components.Exception("Saver failed.", aStatus));
|
||||
}
|
||||
},
|
||||
};
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
aSaver.observer = {
|
||||
onTargetChange: function BFSO_onSaveComplete(aSaver, aTarget)
|
||||
{
|
||||
if (aOnTargetChangeFn) {
|
||||
aOnTargetChangeFn(aTarget);
|
||||
}
|
||||
},
|
||||
onSaveComplete: function BFSO_onSaveComplete(aSaver, aStatus)
|
||||
{
|
||||
if (Components.isSuccessCode(aStatus)) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Components.Exception("Saver failed.", aStatus));
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,24 +173,24 @@ function promiseSaverComplete(aSaver, aOnTargetChangeFn) {
|
|||
* @rejects With an exception, if the copy fails.
|
||||
*/
|
||||
function promiseCopyToSaver(aSourceString, aSaverOutputStream, aCloseWhenDone) {
|
||||
let deferred = Promise.defer();
|
||||
let inputStream = new StringInputStream(aSourceString, aSourceString.length);
|
||||
let copier = Cc["@mozilla.org/network/async-stream-copier;1"]
|
||||
.createInstance(Ci.nsIAsyncStreamCopier);
|
||||
copier.init(inputStream, aSaverOutputStream, null, false, true, 0x8000, true,
|
||||
aCloseWhenDone);
|
||||
copier.asyncCopy({
|
||||
onStartRequest: function () { },
|
||||
onStopRequest: function (aRequest, aContext, aStatusCode)
|
||||
{
|
||||
if (Components.isSuccessCode(aStatusCode)) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject(new Components.Exception(aResult));
|
||||
}
|
||||
},
|
||||
}, null);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
let inputStream = new StringInputStream(aSourceString, aSourceString.length);
|
||||
let copier = Cc["@mozilla.org/network/async-stream-copier;1"]
|
||||
.createInstance(Ci.nsIAsyncStreamCopier);
|
||||
copier.init(inputStream, aSaverOutputStream, null, false, true, 0x8000, true,
|
||||
aCloseWhenDone);
|
||||
copier.asyncCopy({
|
||||
onStartRequest: function () { },
|
||||
onStopRequest: function (aRequest, aContext, aStatusCode)
|
||||
{
|
||||
if (Components.isSuccessCode(aStatusCode)) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Components.Exception(aResult));
|
||||
}
|
||||
},
|
||||
}, null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,35 +209,35 @@ function promiseCopyToSaver(aSourceString, aSaverOutputStream, aCloseWhenDone) {
|
|||
*/
|
||||
function promisePumpToSaver(aSourceString, aSaverStreamListener,
|
||||
aCloseWhenDone) {
|
||||
let deferred = Promise.defer();
|
||||
aSaverStreamListener.QueryInterface(Ci.nsIStreamListener);
|
||||
let inputStream = new StringInputStream(aSourceString, aSourceString.length);
|
||||
let pump = Cc["@mozilla.org/network/input-stream-pump;1"]
|
||||
.createInstance(Ci.nsIInputStreamPump);
|
||||
pump.init(inputStream, -1, -1, 0, 0, true);
|
||||
pump.asyncRead({
|
||||
onStartRequest: function PPTS_onStartRequest(aRequest, aContext)
|
||||
{
|
||||
aSaverStreamListener.onStartRequest(aRequest, aContext);
|
||||
},
|
||||
onStopRequest: function PPTS_onStopRequest(aRequest, aContext, aStatusCode)
|
||||
{
|
||||
aSaverStreamListener.onStopRequest(aRequest, aContext, aStatusCode);
|
||||
if (Components.isSuccessCode(aStatusCode)) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject(new Components.Exception(aResult));
|
||||
}
|
||||
},
|
||||
onDataAvailable: function PPTS_onDataAvailable(aRequest, aContext,
|
||||
aInputStream, aOffset,
|
||||
aCount)
|
||||
{
|
||||
aSaverStreamListener.onDataAvailable(aRequest, aContext, aInputStream,
|
||||
aOffset, aCount);
|
||||
},
|
||||
}, null);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
aSaverStreamListener.QueryInterface(Ci.nsIStreamListener);
|
||||
let inputStream = new StringInputStream(aSourceString, aSourceString.length);
|
||||
let pump = Cc["@mozilla.org/network/input-stream-pump;1"]
|
||||
.createInstance(Ci.nsIInputStreamPump);
|
||||
pump.init(inputStream, -1, -1, 0, 0, true);
|
||||
pump.asyncRead({
|
||||
onStartRequest: function PPTS_onStartRequest(aRequest, aContext)
|
||||
{
|
||||
aSaverStreamListener.onStartRequest(aRequest, aContext);
|
||||
},
|
||||
onStopRequest: function PPTS_onStopRequest(aRequest, aContext, aStatusCode)
|
||||
{
|
||||
aSaverStreamListener.onStopRequest(aRequest, aContext, aStatusCode);
|
||||
if (Components.isSuccessCode(aStatusCode)) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Components.Exception(aResult));
|
||||
}
|
||||
},
|
||||
onDataAvailable: function PPTS_onDataAvailable(aRequest, aContext,
|
||||
aInputStream, aOffset,
|
||||
aCount)
|
||||
{
|
||||
aSaverStreamListener.onDataAvailable(aRequest, aContext, aInputStream,
|
||||
aOffset, aCount);
|
||||
},
|
||||
}, null);
|
||||
});
|
||||
}
|
||||
|
||||
var gStillRunning = true;
|
||||
|
|
|
@ -58,24 +58,24 @@ function getTempFile(aLeafName) {
|
|||
* @rejects With an exception, if onSaveComplete is called with a failure code.
|
||||
*/
|
||||
function promiseSaverComplete(aSaver, aOnTargetChangeFn) {
|
||||
let deferred = Promise.defer();
|
||||
aSaver.observer = {
|
||||
onTargetChange: function BFSO_onSaveComplete(aSaver, aTarget)
|
||||
{
|
||||
if (aOnTargetChangeFn) {
|
||||
aOnTargetChangeFn(aTarget);
|
||||
}
|
||||
},
|
||||
onSaveComplete: function BFSO_onSaveComplete(aSaver, aStatus)
|
||||
{
|
||||
if (Components.isSuccessCode(aStatus)) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject(new Components.Exception("Saver failed.", aStatus));
|
||||
}
|
||||
},
|
||||
};
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
aSaver.observer = {
|
||||
onTargetChange: function BFSO_onSaveComplete(aSaver, aTarget)
|
||||
{
|
||||
if (aOnTargetChangeFn) {
|
||||
aOnTargetChangeFn(aTarget);
|
||||
}
|
||||
},
|
||||
onSaveComplete: function BFSO_onSaveComplete(aSaver, aStatus)
|
||||
{
|
||||
if (Components.isSuccessCode(aStatus)) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Components.Exception("Saver failed.", aStatus));
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,24 +93,24 @@ function promiseSaverComplete(aSaver, aOnTargetChangeFn) {
|
|||
* @rejects With an exception, if the copy fails.
|
||||
*/
|
||||
function promiseCopyToSaver(aSourceString, aSaverOutputStream, aCloseWhenDone) {
|
||||
let deferred = Promise.defer();
|
||||
let inputStream = new StringInputStream(aSourceString, aSourceString.length);
|
||||
let copier = Cc["@mozilla.org/network/async-stream-copier;1"]
|
||||
.createInstance(Ci.nsIAsyncStreamCopier);
|
||||
copier.init(inputStream, aSaverOutputStream, null, false, true, 0x8000, true,
|
||||
aCloseWhenDone);
|
||||
copier.asyncCopy({
|
||||
onStartRequest: function () { },
|
||||
onStopRequest: function (aRequest, aContext, aStatusCode)
|
||||
{
|
||||
if (Components.isSuccessCode(aStatusCode)) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject(new Components.Exception(aResult));
|
||||
}
|
||||
},
|
||||
}, null);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
let inputStream = new StringInputStream(aSourceString, aSourceString.length);
|
||||
let copier = Cc["@mozilla.org/network/async-stream-copier;1"]
|
||||
.createInstance(Ci.nsIAsyncStreamCopier);
|
||||
copier.init(inputStream, aSaverOutputStream, null, false, true, 0x8000, true,
|
||||
aCloseWhenDone);
|
||||
copier.asyncCopy({
|
||||
onStartRequest: function () { },
|
||||
onStopRequest: function (aRequest, aContext, aStatusCode)
|
||||
{
|
||||
if (Components.isSuccessCode(aStatusCode)) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Components.Exception(aResult));
|
||||
}
|
||||
},
|
||||
}, null);
|
||||
});
|
||||
}
|
||||
|
||||
var gStillRunning = true;
|
||||
|
|
|
@ -247,103 +247,103 @@ function getTableRowCount(aTableName) {
|
|||
// Promise-Returning Functions
|
||||
|
||||
function asyncClone(db, readOnly) {
|
||||
let deferred = Promise.defer();
|
||||
db.asyncClone(readOnly, function(status, db2) {
|
||||
if (Components.isSuccessCode(status)) {
|
||||
deferred.resolve(db2);
|
||||
} else {
|
||||
deferred.reject(status);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
db.asyncClone(readOnly, function(status, db2) {
|
||||
if (Components.isSuccessCode(status)) {
|
||||
resolve(db2);
|
||||
} else {
|
||||
reject(status);
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function asyncClose(db) {
|
||||
let deferred = Promise.defer();
|
||||
db.asyncClose(function(status) {
|
||||
if (Components.isSuccessCode(status)) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject(status);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
db.asyncClose(function(status) {
|
||||
if (Components.isSuccessCode(status)) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(status);
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function openAsyncDatabase(file, options) {
|
||||
let deferred = Promise.defer();
|
||||
let properties;
|
||||
if (options) {
|
||||
properties = Cc["@mozilla.org/hash-property-bag;1"].
|
||||
createInstance(Ci.nsIWritablePropertyBag);
|
||||
for (let k in options) {
|
||||
properties.setProperty(k, options[k]);
|
||||
}
|
||||
}
|
||||
getService().openAsyncDatabase(file, properties, function(status, db) {
|
||||
if (Components.isSuccessCode(status)) {
|
||||
deferred.resolve(db.QueryInterface(Ci.mozIStorageAsyncConnection));
|
||||
} else {
|
||||
deferred.reject(status);
|
||||
return new Promise((resolve, reject) => {
|
||||
let properties;
|
||||
if (options) {
|
||||
properties = Cc["@mozilla.org/hash-property-bag;1"].
|
||||
createInstance(Ci.nsIWritablePropertyBag);
|
||||
for (let k in options) {
|
||||
properties.setProperty(k, options[k]);
|
||||
}
|
||||
}
|
||||
getService().openAsyncDatabase(file, properties, function(status, db) {
|
||||
if (Components.isSuccessCode(status)) {
|
||||
resolve(db.QueryInterface(Ci.mozIStorageAsyncConnection));
|
||||
} else {
|
||||
reject(status);
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function executeAsync(statement, onResult) {
|
||||
let deferred = Promise.defer();
|
||||
statement.executeAsync({
|
||||
handleError(error) {
|
||||
deferred.reject(error);
|
||||
},
|
||||
handleResult(result) {
|
||||
if (onResult) {
|
||||
onResult(result);
|
||||
return new Promise((resolve, reject) => {
|
||||
statement.executeAsync({
|
||||
handleError(error) {
|
||||
reject(error);
|
||||
},
|
||||
handleResult(result) {
|
||||
if (onResult) {
|
||||
onResult(result);
|
||||
}
|
||||
},
|
||||
handleCompletion(result) {
|
||||
resolve(result);
|
||||
}
|
||||
},
|
||||
handleCompletion(result) {
|
||||
deferred.resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function executeMultipleStatementsAsync(db, statements, onResult) {
|
||||
let deferred = Promise.defer();
|
||||
db.executeAsync(statements, statements.length, {
|
||||
handleError(error) {
|
||||
deferred.reject(error);
|
||||
},
|
||||
handleResult(result) {
|
||||
if (onResult) {
|
||||
onResult(result);
|
||||
return new Promise((resolve, reject) => {
|
||||
db.executeAsync(statements, statements.length, {
|
||||
handleError(error) {
|
||||
reject(error);
|
||||
},
|
||||
handleResult(result) {
|
||||
if (onResult) {
|
||||
onResult(result);
|
||||
}
|
||||
},
|
||||
handleCompletion(result) {
|
||||
resolve(result);
|
||||
}
|
||||
},
|
||||
handleCompletion(result) {
|
||||
deferred.resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function executeSimpleSQLAsync(db, query, onResult) {
|
||||
let deferred = Promise.defer();
|
||||
db.executeSimpleSQLAsync(query, {
|
||||
handleError(error) {
|
||||
deferred.reject(error);
|
||||
},
|
||||
handleResult(result) {
|
||||
if (onResult) {
|
||||
onResult(result);
|
||||
} else {
|
||||
do_throw("No results were expected");
|
||||
return new Promise((resolve, reject) => {
|
||||
db.executeSimpleSQLAsync(query, {
|
||||
handleError(error) {
|
||||
reject(error);
|
||||
},
|
||||
handleResult(result) {
|
||||
if (onResult) {
|
||||
onResult(result);
|
||||
} else {
|
||||
do_throw("No results were expected");
|
||||
}
|
||||
},
|
||||
handleCompletion(result) {
|
||||
resolve(result);
|
||||
}
|
||||
},
|
||||
handleCompletion(result) {
|
||||
deferred.resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
|
Загрузка…
Ссылка в новой задаче