Skip to content

Commit

Permalink
Bug 1288440 P2 Don't leak existing windows in sdk/window/events. r=gabor
Browse files Browse the repository at this point in the history
  • Loading branch information
wanderview committed Jul 22, 2016
1 parent 869380e commit 94fe3ec
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions addon-sdk/source/lib/sdk/window/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,26 @@ function eventsFor(window) {
return map(changes, toEventWithDefaultViewTarget);
}

// In addition to observing windows that are open we also observe windows
// that are already already opened in case they're in process of loading.
var opened = windows(null, { includePrivate: true });
var currentEvents = merge(opened.map(eventsFor));
// Create our event channels. We do this in a separate function to
// minimize the chance of leaking intermediate objects on the global.
function makeEvents() {
// In addition to observing windows that are open we also observe windows
// that are already already opened in case they're in process of loading.
var opened = windows(null, { includePrivate: true });
var currentEvents = merge(opened.map(eventsFor));

// Register system event listeners for top level window open / close.
function rename({type, target, data}) {
return { type: rename[type], target: target, data: data }
}
rename.domwindowopened = "open";
rename.domwindowclosed = "close";
// Register system event listeners for top level window open / close.
function rename({type, target, data}) {
return { type: rename[type], target: target, data: data }
}
rename.domwindowopened = "open";
rename.domwindowclosed = "close";

var openEvents = map(observe("domwindowopened"), rename);
var closeEvents = map(observe("domwindowclosed"), rename);
var futureEvents = expand(openEvents, ({target}) => eventsFor(target));

var openEvents = map(observe("domwindowopened"), rename);
var closeEvents = map(observe("domwindowclosed"), rename);
var futureEvents = expand(openEvents, ({target}) => eventsFor(target));
return merge([currentEvents, futureEvents, openEvents, closeEvents]);
}

var channel = merge([currentEvents, futureEvents,
openEvents, closeEvents]);
exports.events = channel;
exports.events = makeEvents();

0 comments on commit 94fe3ec

Please sign in to comment.