diff options
Diffstat (limited to 'common/modules/main.jsm')
-rw-r--r-- | common/modules/main.jsm | 334 |
1 files changed, 168 insertions, 166 deletions
diff --git a/common/modules/main.jsm b/common/modules/main.jsm index 248f1067..45d63757 100644 --- a/common/modules/main.jsm +++ b/common/modules/main.jsm @@ -195,200 +195,202 @@ var Modules = function Modules(window) { config.loadStyles(); overlay.overlayWindow(Object.keys(config.overlays), - function _overlay(window) ({ - ready: function onInit(document) { - const modules = Modules(window); - modules.moduleManager = this; - this.modules = modules; - this.jsmodules = modules.jsmodules; - - window.dactyl = { modules: modules }; - - defineModule.time("load", null, function _load() { - config.modules.global - .forEach(function (name) { - if (!isArray(name)) - defineModule.time("load", name, require, null, name, modules.jsmodules); - else - lazyRequire(name[0], name.slice(1), modules.jsmodules); - }); - - config.modules.window - .forEach(name => { defineModule.time("load", name, modules.load, modules, name); }); - }, this); - }, - - load: function onLoad(document) { - let self = this; - - var { modules } = this.modules; - delete window.dactyl; - - this.startTime = Date.now(); - this.deferredInit = { load: {} }; - this.seen = new RealSet; - this.loaded = new RealSet; - modules.loaded = this.loaded; - - this.modules = modules; - - this.scanModules(); - this.initDependencies("init"); - - modules.config.scripts.forEach(modules.load); - - this.scanModules(); - - defineModule.modules.forEach(function defModule({ lazyInit, constructor: { className } }) { - if (!lazyInit) { - Class.replaceProperty(modules, className, modules[className]); - this.initDependencies(className); - } - else - modules.__defineGetter__(className, () => { - let module = modules.jsmodules[className]; - Class.replaceProperty(modules, className, module); - if (module.reallyInit) - module.reallyInit(); // :( - - if (!module.lazyDepends) - self.initDependencies(className); - return module; - }); - }, this); - }, + function _overlay(window) { + return { + ready: function onInit(document) { + const modules = Modules(window); + modules.moduleManager = this; + this.modules = modules; + this.jsmodules = modules.jsmodules; + + window.dactyl = { modules: modules }; + + defineModule.time("load", null, function _load() { + config.modules.global + .forEach(function (name) { + if (!isArray(name)) + defineModule.time("load", name, require, null, name, modules.jsmodules); + else + lazyRequire(name[0], name.slice(1), modules.jsmodules); + }); + + config.modules.window + .forEach(name => { defineModule.time("load", name, modules.load, modules, name); }); + }, this); + }, - cleanup: function cleanup(window) { - overlay.windows.delete(window); + load: function onLoad(document) { + let self = this; - JSMLoader.atexit(() => { - Cu.nukeSandbox(this.jsmodules); - }); - }, + var { modules } = this.modules; + delete window.dactyl; - unload: function unload(window) { - for (let mod of this.modules.moduleList.reverse()) { - mod.stale = true; + this.startTime = Date.now(); + this.deferredInit = { load: {} }; + this.seen = new RealSet; + this.loaded = new RealSet; + modules.loaded = this.loaded; - if ("destroy" in mod) - util.trapErrors("destroy", mod); - } - }, + this.modules = modules; - visible: function visible(window) { - // Module.list.forEach(load); - this.initDependencies("load"); - this.modules.times = update({}, defineModule.times); + this.scanModules(); + this.initDependencies("init"); - defineModule.loadLog.push("Loaded in " + (Date.now() - this.startTime) + "ms"); + modules.config.scripts.forEach(modules.load); - overlay.windows.add(window); - }, + this.scanModules(); - loadModule: function loadModule(module, prereq, frame) { - let { loaded, seen } = this; - let { Module, modules } = this.modules; + defineModule.modules.forEach(function defModule({ lazyInit, constructor: { className } }) { + if (!lazyInit) { + Class.replaceProperty(modules, className, modules[className]); + this.initDependencies(className); + } + else + modules.__defineGetter__(className, () => { + let module = modules.jsmodules[className]; + Class.replaceProperty(modules, className, module); + if (module.reallyInit) + module.reallyInit(); // :( + + if (!module.lazyDepends) + self.initDependencies(className); + return module; + }); + }, this); + }, - if (isString(module)) { - if (!Module.constructors.hasOwnProperty(module)) - modules.load(module); - module = Module.constructors[module]; - } + cleanup: function cleanup(window) { + overlay.windows.delete(window); - try { - if (loaded.has(module.className)) - return; + JSMLoader.atexit(() => { + Cu.nukeSandbox(this.jsmodules); + }); + }, - if (seen.add(module.className)) - throw Error("Module dependency loop."); + unload: function unload(window) { + for (let mod of this.modules.moduleList.reverse()) { + mod.stale = true; - for (let dep of module.requires) - this.loadModule(Module.constructors[dep], module.className); + if ("destroy" in mod) + util.trapErrors("destroy", mod); + } + }, - defineModule.loadLog.push( - "Load" + (isString(prereq) ? " " + prereq + " dependency: " : ": ") - + module.className); + visible: function visible(window) { + // Module.list.forEach(load); + this.initDependencies("load"); + this.modules.times = update({}, defineModule.times); - if (frame && frame.filename) - defineModule.loadLog.push(" from: " + util.fixURI(frame.filename) + ":" + frame.lineNumber); + defineModule.loadLog.push("Loaded in " + (Date.now() - this.startTime) + "ms"); - let obj = defineModule.time(module.className, "init", module); - Class.replaceProperty(modules, module.className, obj); + overlay.windows.add(window); + }, - loaded.add(module.className); + loadModule: function loadModule(module, prereq, frame) { + let { loaded, seen } = this; + let { Module, modules } = this.modules; - if (loaded.has("dactyl") && obj.signals) - modules.dactyl.registerObservers(obj); + if (isString(module)) { + if (!Module.constructors.hasOwnProperty(module)) + modules.load(module); + module = Module.constructors[module]; + } - if (!module.lazyDepends) - this.initDependencies(module.className); - } - catch (e) { - util.dump("Loading " + (module && module.className) + ":"); - util.reportError(e); - } - return modules[module.className]; - }, + try { + if (loaded.has(module.className)) + return; - deferInit: function deferInit(name, INIT, mod) { - let { modules } = this.modules; + if (seen.add(module.className)) + throw Error("Module dependency loop."); - let init = this.deferredInit[name] || {}; - this.deferredInit[name] = init; + for (let dep of module.requires) + this.loadModule(Module.constructors[dep], module.className); - let className = mod.className || mod.constructor.className; + defineModule.loadLog.push( + "Load" + (isString(prereq) ? " " + prereq + " dependency: " : ": ") + + module.className); - if (!hasOwnProperty(init, className)) { - init[className] = function callee() { - function finish() { - this.currentDependency = className; - defineModule.time(className, name, INIT[name], mod, - modules.dactyl, modules, window); - } - if (!callee.frobbed) { - callee.frobbed = true; - if (modules[name] instanceof Class) - modules[name].withSavedValues(["currentDependency"], finish); - else - finish.call({}); - } - }; + if (frame && frame.filename) + defineModule.loadLog.push(" from: " + util.fixURI(frame.filename) + ":" + frame.lineNumber); - INIT[name].require = name => { init[name](); }; - } - }, + let obj = defineModule.time(module.className, "init", module); + Class.replaceProperty(modules, module.className, obj); - scanModules: function scanModules() { - let { Module, modules } = this.modules; + loaded.add(module.className); - defineModule.modules.forEach(mod => { - let names = new RealSet(Object.keys(mod.INIT)); - if ("init" in mod.INIT) - names.add("init"); + if (loaded.has("dactyl") && obj.signals) + modules.dactyl.registerObservers(obj); - for (let name of names) - this.deferInit(name, mod.INIT, mod); - }); + if (!module.lazyDepends) + this.initDependencies(module.className); + } + catch (e) { + util.dump("Loading " + (module && module.className) + ":"); + util.reportError(e); + } + return modules[module.className]; + }, - Module.list.forEach(mod => { - if (!mod.frobbed) { - modules.__defineGetter__(mod.className, () => { - delete modules[mod.className]; - return this.loadModule(mod.className, null, Components.stack.caller); - }); - Object.keys(mod.prototype.INIT) - .forEach(name => { this.deferInit(name, mod.prototype.INIT, mod); }); + deferInit: function deferInit(name, INIT, mod) { + let { modules } = this.modules; + + let init = this.deferredInit[name] || {}; + this.deferredInit[name] = init; + + let className = mod.className || mod.constructor.className; + + if (!hasOwnProperty(init, className)) { + init[className] = function callee() { + function finish() { + this.currentDependency = className; + defineModule.time(className, name, INIT[name], mod, + modules.dactyl, modules, window); + } + if (!callee.frobbed) { + callee.frobbed = true; + if (modules[name] instanceof Class) + modules[name].withSavedValues(["currentDependency"], finish); + else + finish.call({}); + } + }; + + INIT[name].require = name => { init[name](); }; } - mod.frobbed = true; - }); - }, - - initDependencies: function initDependencies(name, parents) { - for (let [k, v] of iter(this.deferredInit[name] || {})) - if (!parents || ~parents.indexOf(k)) - util.trapErrors(v); - } -})); + }, + + scanModules: function scanModules() { + let { Module, modules } = this.modules; + + defineModule.modules.forEach(mod => { + let names = new RealSet(Object.keys(mod.INIT)); + if ("init" in mod.INIT) + names.add("init"); + + for (let name of names) + this.deferInit(name, mod.INIT, mod); + }); + + Module.list.forEach(mod => { + if (!mod.frobbed) { + modules.__defineGetter__(mod.className, () => { + delete modules[mod.className]; + return this.loadModule(mod.className, null, Components.stack.caller); + }); + Object.keys(mod.prototype.INIT) + .forEach(name => { this.deferInit(name, mod.prototype.INIT, mod); }); + } + mod.frobbed = true; + }); + }, + + initDependencies: function initDependencies(name, parents) { + for (let [k, v] of iter(this.deferredInit[name] || {})) + if (!parents || ~parents.indexOf(k)) + util.trapErrors(v); + } + }; +}); endModule(); |