Merge m-c to m-i

This commit is contained in:
Phil Ringnalda 2017-02-05 18:19:27 -08:00
commit 42403c9edc
2 changed files with 24 additions and 28 deletions

View File

@ -23,7 +23,6 @@ _register_modules_protocol_handler();
var _Promise = Components.utils.import("resource://gre/modules/Promise.jsm", {}).Promise;
var _PromiseTestUtils = Components.utils.import("resource://testing-common/PromiseTestUtils.jsm", {}).PromiseTestUtils;
var _Task = Components.utils.import("resource://gre/modules/Task.jsm", {}).Task;
Components.utils.importGlobalProperties(["XMLHttpRequest"]);
// Support a common assertion library, Assert.jsm.
@ -595,22 +594,27 @@ function _execute_test() {
});
};
let complete = _cleanupFunctions.length == 0;
_Task.spawn(function*() {
for (let func of _cleanupFunctions.reverse()) {
try {
yield func();
} catch (ex) {
reportCleanupError(ex);
let func;
while ((func = _cleanupFunctions.pop())) {
let result;
try {
result = func();
} catch (ex) {
reportCleanupError(ex);
continue;
}
if (result && typeof result == "object"
&& "then" in result && typeof result.then == "function") {
// This is a promise, wait until it is satisfied before proceeding
let complete = false;
let promise = result.then(null, reportCleanupError);
promise = promise.then(() => complete = true);
let thr = Components.classes["@mozilla.org/thread-manager;1"]
.getService().currentThread;
while (!complete) {
thr.processNextEvent(true);
}
}
_cleanupFunctions = [];
}.bind(this)).catch(reportCleanupError)
.then(() => complete = true);
let thr = Components.classes["@mozilla.org/thread-manager;1"]
.getService().currentThread;
while (!complete) {
thr.processNextEvent(true);
}
// Restore idle service to avoid leaks.
@ -1508,6 +1512,7 @@ function add_task(funcOrProperties, func) {
add_task.only = _add_only.bind(undefined, add_task);
add_task.skip = _add_skip.bind(undefined, add_task);
var _Task = Components.utils.import("resource://gre/modules/Task.jsm", {}).Task;
_Task.Debugging.maintainStack = true;

View File

@ -301,22 +301,12 @@ function run_test() {
// Cleanup tasks, in reverse order
do_register_cleanup(function cleanup_checkout() {
do_check_eq(checkpoints.join(""), "123456");
do_check_eq(checkpoints.join(""), "1234");
do_print("At this stage, the test has succeeded");
do_throw("Throwing an error to force displaying the log");
});
do_register_cleanup(function sync_cleanup_2() {
checkpoints.push(6);
});
do_register_cleanup(async function async_cleanup_4() {
await undefined;
checkpoints.push(5);
});
do_register_cleanup(function* async_cleanup_3() {
yield undefined;
checkpoints.push(4);
});
@ -1194,12 +1184,13 @@ add_test({
def testAsyncCleanup(self):
"""
Check that do_register_cleanup handles nicely async cleanup tasks
Check that do_register_cleanup handles nicely cleanup tasks that
return a promise
"""
self.writeFile("test_asyncCleanup.js", ASYNC_CLEANUP)
self.writeManifest(["test_asyncCleanup.js"])
self.assertTestResult(False)
self.assertInLog("\"123456\" == \"123456\"")
self.assertInLog("\"1234\" == \"1234\"")
self.assertInLog("At this stage, the test has succeeded")
self.assertInLog("Throwing an error to force displaying the log")