Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Bug 648244: Infinite loop on tabs.onActivate if accessing windows.act…
Browse files Browse the repository at this point in the history
…iveWindow (new window) r+a=myk
  • Loading branch information
ochameau committed Apr 29, 2011
1 parent 5e28d81 commit 5f18555
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/addon-kit/lib/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ const BrowserWindowTrait = Trait.compose(
* @param {nsIWindow} window
*/
constructor: function BrowserWindow(options) {
// Register this window ASAP, in order to avoid loop that would try
// to create this window instance over and over (see bug 648244)
windows.push(this);

// make sure we don't have unhandled errors
this.on('error', console.exception.bind(console));

Expand Down Expand Up @@ -145,7 +149,6 @@ function BrowserWindow(options) {
return window._public
}
let window = BrowserWindowTrait(options);
windows.push(window);
return window._public;
}
// to have proper `instanceof` behavior will go away when #596248 is fixed.
Expand Down
21 changes: 21 additions & 0 deletions packages/addon-kit/tests/test-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ exports.testActiveTab_getter = function(test) {
});
};

// test 'BrowserWindow' instance creation on tab 'activate' event
// See bug 648244: there was a infinite loop.
exports.testBrowserWindowCreationOnActivate = function(test) {
test.waitUntilDone();

let windows = require("windows").browserWindows;
let tabs = require("tabs");

let gotActivate = false;

tabs.on('activate', function onActivate(eventTab) {
test.assert(windows.activeWindow, "Is able to fetch activeWindow");
gotActivate = true;
});

openBrowserWindow(function(window, browser) {
test.assert(gotActivate, "Received activate event before openBrowserWindow's callback is called");
closeBrowserWindow(window, function () test.done());
});
}

// test tab.activeTab setter
exports.testActiveTab_setter = function(test) {
test.waitUntilDone();
Expand Down

0 comments on commit 5f18555

Please sign in to comment.