Bug 874502 part 2. Fix addon sdk to not assume synchronous closing of windows. r=mossop

This commit is contained in:
Bobby Holley 2013-09-17 17:45:47 -04:00
parent 356f3af0c9
commit f78b2f244c

View File

@ -5,6 +5,7 @@
const { defer } = require('../core/promise');
const events = require('../system/events');
const { setImmediate } = require('../timers');
const { open: openWindow, onFocus, getToplevelWindow,
isInteractive } = require('./utils');
@ -15,14 +16,18 @@ exports.open = open;
function close(window) {
// We shouldn't wait for unload, as it is dispatched
// before the window is actually closed.
// `domwindowclosed` is a better match.
// before the window is actually closed. 'domwindowclosed' isn't great either,
// because it's fired midway through window teardown (see bug 874502
// comment 15). We could go with xul-window-destroyed, but _that_ doesn't
// provide us with a subject by which to disambiguate notifications. So we
// end up just doing the dumb thing and round-tripping through the event loop
// with setImmediate.
let deferred = defer();
let toplevelWindow = getToplevelWindow(window);
events.on("domwindowclosed", function onclose({subject}) {
if (subject == toplevelWindow) {
events.off("domwindowclosed", onclose);
deferred.resolve(window);
setImmediate(function() deferred.resolve(window));
}
}, true);
window.close();