Bug 797065 - Leak if I quit while Scratchpad is open. r=dcamp

This commit is contained in:
Anton Kovalyov 2012-12-19 13:39:00 +01:00
parent 3a740f52c0
commit 20e32c7b31

View File

@ -69,11 +69,29 @@ this.ScratchpadManager = {
saveOpenWindows: function SPM_saveOpenWindows() {
this._scratchpads = [];
function clone(src) {
let dest = {};
for (let key in src) {
if (src.hasOwnProperty(key)) {
dest[key] = src[key];
}
}
return dest;
}
// We need to clone objects we get from Scratchpad instances
// because such (cross-window) objects have a property 'parent'
// that holds on to a ChromeWindow instance. This means that
// such objects are not primitive-values-only anymore so they
// can leak.
let enumerator = Services.wm.getEnumerator("devtools:scratchpad");
while (enumerator.hasMoreElements()) {
let win = enumerator.getNext();
if (!win.closed && win.Scratchpad.initialized) {
this._scratchpads.push(win.Scratchpad.getState());
this._scratchpads.push(clone(win.Scratchpad.getState()));
}
}
},
@ -106,6 +124,7 @@ this.ScratchpadManager = {
let win = Services.ww.openWindow(null, SCRATCHPAD_WINDOW_URL, "_blank",
SCRATCHPAD_WINDOW_FEATURES, params);
// Only add the shutdown observer if we've opened a scratchpad window.
ShutdownObserver.init();
@ -128,6 +147,7 @@ var ShutdownObserver = {
}
Services.obs.addObserver(this, "quit-application-granted", false);
this._initialized = true;
},