mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-10 18:44:11 +01:00
Bootstrap cleanup work.
--HG-- branch : bootstrapped
This commit is contained in:
@@ -98,6 +98,7 @@ let loaded = {};
|
||||
let currentModule;
|
||||
function defineModule(name, params) {
|
||||
let module = Cu.getGlobalForObject ? Cu.getGlobalForObject(params) : params.__parent__;
|
||||
defineModule.globals.push(module);
|
||||
module.NAME = name;
|
||||
module.EXPORTED_SYMBOLS = params.exports || [];
|
||||
defineModule.loadLog.push("defineModule " + name);
|
||||
@@ -114,6 +115,7 @@ function defineModule(name, params) {
|
||||
currentModule = module;
|
||||
}
|
||||
|
||||
defineModule.globals = [];
|
||||
defineModule.loadLog = [];
|
||||
Object.defineProperty(defineModule.loadLog, "push", {
|
||||
value: function (val) { defineModule.dump(val + "\n"); this[this.length] = val; }
|
||||
|
||||
@@ -42,6 +42,10 @@ const BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver),
|
||||
services.bookmarks.addObserver(this, false);
|
||||
},
|
||||
|
||||
cleanup: function cleanup() {
|
||||
services.bookmarks.removeObserver(this);
|
||||
},
|
||||
|
||||
__iterator__: function () (val for ([, val] in Iterator(bookmarkcache.bookmarks))),
|
||||
|
||||
get bookmarks() Class.replaceProperty(this, "bookmarks", this.load()),
|
||||
|
||||
@@ -28,6 +28,10 @@ const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference
|
||||
this.restore();
|
||||
},
|
||||
|
||||
cleanup: function cleanup() {
|
||||
this._branch.removeObserver("", this);
|
||||
},
|
||||
|
||||
observe: {
|
||||
"nsPref:changed": function (subject, data) {
|
||||
let observers = this._observers[data];
|
||||
|
||||
@@ -961,9 +961,21 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
|
||||
observe: {
|
||||
"dactyl-cleanup": function () {
|
||||
for (let module in values(defineModule.modules))
|
||||
if (module.cleanup)
|
||||
module.cleanup();
|
||||
// Let window cleanup functions run synchronously before we
|
||||
// destroy modules.
|
||||
util.timeout(function () {
|
||||
for (let module in values(defineModule.modules))
|
||||
if (module.cleanup)
|
||||
module.cleanup();
|
||||
|
||||
let getOwnPropertyNames = Object.getOwnPropertyNames;
|
||||
for each (let global in defineModule.globals.reverse())
|
||||
for each (let k in getOwnPropertyNames(global))
|
||||
try {
|
||||
delete global[k];
|
||||
}
|
||||
catch (e) {}
|
||||
});
|
||||
},
|
||||
"toplevel-window-ready": function (window, data) {
|
||||
window.addEventListener("DOMContentLoaded", wrapCallback(function listener(event) {
|
||||
@@ -1141,6 +1153,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
}
|
||||
catch (e) {
|
||||
this.dump(e);
|
||||
try { util.dump(e.stack) } catch (e) {}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user