Permalink
Browse files

Bug 689532 (leak): Clean up the style element from importCss

We needed to change the implementation to actually return it
  • Loading branch information...
1 parent 1bc7e82 commit 99d01e660310a04c52a09ff2684b34c6ee2592cf @joewalker committed Sep 29, 2011
View
7 lib/gcli/ui/arg_fetch.js
@@ -44,7 +44,7 @@ function ArgFetcher(document, requisition) {
// Pull the HTML into the DOM, but don't add it to the document
if (editorCss != null) {
- dom.importCssString(editorCss, this.document);
+ this.style = dom.importCss(editorCss, this.document);
}
var templates = dom.createElement(this.document, 'div');
@@ -62,6 +62,11 @@ ArgFetcher.prototype.destroy = function() {
this.requisition.inputChange.remove(this.onInputChange, this);
this.requisition.commandChange.remove(this.onCommandChange, this);
+ if (this.style) {
+ this.style.parentNode.removeChild(this.style);
+ delete this.style;
+ }
+
delete this.document;
delete this.element;
delete this.okElement;
View
7 lib/gcli/ui/command_output_view.js
@@ -73,7 +73,7 @@ function CommandOutputListView(options) {
this.commandOutputManager.addListener(this.onOutputCommandChange, this);
if (commandOutputViewCss != null) {
- dom.importCssString(commandOutputViewCss, this.listView.document);
+ this.style = dom.importCss(commandOutputViewCss, this.listView.document);
}
var templates = dom.createElement(this.listView.document, 'div');
@@ -85,6 +85,11 @@ function CommandOutputListView(options) {
* Avoid memory leaks
*/
CommandOutputListView.prototype.destroy = function() {
+ if (this.style) {
+ this.style.parentNode.removeChild(this.style);
+ delete this.style;
+ }
+
delete this.document;
delete this._row;
};
View
7 lib/gcli/ui/hinter.js
@@ -25,7 +25,7 @@ function Hinter(options) {
this.requisition = options.requisition;
if (hinterCss != null) {
- dom.importCssString(hinterCss, this.document);
+ this.style = dom.importCss(hinterCss, this.document);
}
this.menu = options.menu || new CommandMenu(this.document, this.requisition);
@@ -56,6 +56,11 @@ function Hinter(options) {
* Avoid memory leaks
*/
Hinter.prototype.destroy = function() {
+ if (this.style) {
+ this.style.parentNode.removeChild(this.style);
+ delete this.style;
+ }
+
delete this.document;
delete this.element;
delete this.hinter;
View
7 lib/gcli/ui/inputter.js
@@ -40,7 +40,7 @@ function Inputter(options) {
}
if (inputterCss != null) {
- dom.importCssString(inputterCss, this.document);
+ this.style = dom.importCss(inputterCss, this.document);
}
this.element.spellcheck = false;
@@ -101,6 +101,11 @@ Inputter.prototype.destroy = function() {
this.history.destroy();
this.completer.destroy();
+ if (this.style) {
+ this.style.parentNode.removeChild(this.style);
+ delete this.style;
+ }
+
delete this.document;
delete this.element;
};
View
7 lib/gcli/ui/menu.js
@@ -36,7 +36,7 @@ function Menu(document, options) {
// Pull the HTML into the DOM, but don't add it to the document
if (menuCss != null) {
- dom.importCssString(menuCss, document);
+ this.style = dom.importCss(menuCss, document);
}
var templates = dom.createElement(document, 'div');
@@ -51,6 +51,11 @@ function Menu(document, options) {
* Avoid memory leaks
*/
Menu.prototype.destroy = function() {
+ if (this.style) {
+ this.style.parentNode.removeChild(this.style);
+ delete this.style;
+ }
+
delete this.element;
delete this.items;
delete this.optTempl;
View
18 lib/gcli/util.js
@@ -219,20 +219,16 @@ dom.setCssClass = function(node, className, include) {
* @param cssText The CSS declarations to append
* @param doc The document element to work from
*/
-dom.importCssString = function(cssText, doc) {
+dom.importCss = function(cssText, doc) {
doc = doc || document;
- if (doc.createStyleSheet) {
- var sheet = doc.createStyleSheet();
- sheet.cssText = cssText;
- }
- else {
- var style = dom.createElement(doc, 'style');
- style.appendChild(doc.createTextNode(cssText));
+ var style = dom.createElement(doc, 'style');
+ style.appendChild(doc.createTextNode(cssText));
- var head = doc.getElementsByTagName('head')[0] || doc.documentElement;
- head.appendChild(style);
- }
+ var head = doc.getElementsByTagName('head')[0] || doc.documentElement;
+ head.appendChild(style);
+
+ return style;
};
/**
View
2 lib/test/index.js
@@ -28,7 +28,7 @@ var testCommandSpec = {
params: [],
exec: function(env, context) {
if (!template) {
- dom.importCssString(testCss, context.document);
+ dom.importCss(testCss, context.document);
template = dom.createElement(context.document, 'div');
dom.setInnerHtml(template, testHtml);
}

0 comments on commit 99d01e6

Please sign in to comment.