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