mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-06 17:35:50 +01:00
Add reference counts for globally active style hives.
--HG-- branch : groups
This commit is contained in:
@@ -130,11 +130,14 @@ var Contexts = Module("contexts", {
|
|||||||
this.builtinGroups = [this.builtin, this.user];
|
this.builtinGroups = [this.builtin, this.user];
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy: function () {
|
cleanup: function () {
|
||||||
for (let hive in values(this.groupList)) {
|
for (let hive in values(this.groupList))
|
||||||
dactyl.trapErrors("cleanup", hive);
|
dactyl.trapErrors("cleanup", hive);
|
||||||
|
},
|
||||||
|
|
||||||
|
destroy: function () {
|
||||||
|
for (let hive in values(this.groupList))
|
||||||
dactyl.trapErrors("destroy", hive);
|
dactyl.trapErrors("destroy", hive);
|
||||||
}
|
|
||||||
|
|
||||||
for (let plugin in values(plugins.contexts))
|
for (let plugin in values(plugins.contexts))
|
||||||
if (plugin.onUnload)
|
if (plugin.onUnload)
|
||||||
@@ -191,8 +194,7 @@ var Contexts = Module("contexts", {
|
|||||||
if (group) {
|
if (group) {
|
||||||
name = group.name;
|
name = group.name;
|
||||||
this.groupList.splice(this.groupList.indexOf(group), 1);
|
this.groupList.splice(this.groupList.indexOf(group), 1);
|
||||||
group.cleanup();
|
dactyl.trapErrors("destroy", group);
|
||||||
group.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.context && this.context.group === group)
|
if (this.context && this.context.group === group)
|
||||||
@@ -295,18 +297,25 @@ var Contexts = Module("contexts", {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let name = isPlugin ? file.getRelativeDescriptor(isPlugin).replace(File.PATH_SEP, "-") : file.leafName;
|
let name = isPlugin ? file.getRelativeDescriptor(isPlugin).replace(File.PATH_SEP, "-") : file.leafName;
|
||||||
|
|
||||||
self = update(modules.newContext.apply(null, args || [userContext]), {
|
self = update(modules.newContext.apply(null, args || [userContext]), {
|
||||||
NAME: Const(name.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase())),
|
NAME: Const(name.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase())),
|
||||||
|
|
||||||
PATH: Const(file.path),
|
PATH: Const(file.path),
|
||||||
|
|
||||||
CONTEXT: Const(self),
|
CONTEXT: Const(self),
|
||||||
|
|
||||||
unload: Const(function unload() {
|
unload: Const(function unload() {
|
||||||
if (plugins[this.NAME] === this || plugins[this.PATH] === this)
|
if (plugins[this.NAME] === this || plugins[this.PATH] === this)
|
||||||
if (this.onUnload)
|
if (this.onUnload)
|
||||||
this.onUnload();
|
this.onUnload();
|
||||||
|
|
||||||
if (plugins[this.NAME] === this)
|
if (plugins[this.NAME] === this)
|
||||||
delete plugins[this.NAME];
|
delete plugins[this.NAME];
|
||||||
|
|
||||||
if (plugins[this.PATH] === this)
|
if (plugins[this.PATH] === this)
|
||||||
delete plugins[this.PATH];
|
delete plugins[this.PATH];
|
||||||
|
|
||||||
if (!this.GROUP.builtin)
|
if (!this.GROUP.builtin)
|
||||||
contexts.removeGroup(this.GROUP);
|
contexts.removeGroup(this.GROUP);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ if (!Object.defineProperties)
|
|||||||
for (let [k, v] in Iterator(props))
|
for (let [k, v] in Iterator(props))
|
||||||
Object.defineProperty(obj, k, v);
|
Object.defineProperty(obj, k, v);
|
||||||
}
|
}
|
||||||
|
if (!Object.freeze)
|
||||||
|
Object.freeze = function freeze(obj) {};
|
||||||
if (!Object.getOwnPropertyDescriptor)
|
if (!Object.getOwnPropertyDescriptor)
|
||||||
Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(obj, prop) {
|
Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(obj, prop) {
|
||||||
if (!hasOwnProperty.call(obj, prop))
|
if (!hasOwnProperty.call(obj, prop))
|
||||||
@@ -101,13 +103,15 @@ if (!Object.keys)
|
|||||||
Object.keys = function keys(obj)
|
Object.keys = function keys(obj)
|
||||||
Object.getOwnPropertyNames(obj).filter(function (k) objproto.propertyIsEnumerable.call(obj, k));
|
Object.getOwnPropertyNames(obj).filter(function (k) objproto.propertyIsEnumerable.call(obj, k));
|
||||||
|
|
||||||
|
let getGlobalForObject = Cu.getGlobalForObject || function (obj) obj.__parent__;
|
||||||
|
|
||||||
let use = {};
|
let use = {};
|
||||||
let loaded = {};
|
let loaded = {};
|
||||||
let currentModule;
|
let currentModule;
|
||||||
let global = this;
|
let global = this;
|
||||||
function defineModule(name, params, module) {
|
function defineModule(name, params, module) {
|
||||||
if (!module)
|
if (!module)
|
||||||
module = Cu.getGlobalForObject ? Cu.getGlobalForObject(params) : params.__parent__;
|
module = getGlobalForObject(params);
|
||||||
|
|
||||||
module.NAME = name;
|
module.NAME = name;
|
||||||
module.EXPORTED_SYMBOLS = params.exports || [];
|
module.EXPORTED_SYMBOLS = params.exports || [];
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ Highlight.liveProperty = function (name, prop) {
|
|||||||
val = Array.slice(val);
|
val = Array.slice(val);
|
||||||
else
|
else
|
||||||
val = update({}, val);
|
val = update({}, val);
|
||||||
if (Object.freeze)
|
Object.freeze(val);
|
||||||
Object.freeze(val);
|
|
||||||
}
|
}
|
||||||
this.set(name, val);
|
this.set(name, val);
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Sheet.liveProperty = function (name) {
|
|||||||
this.prototype.__defineSetter__(name, function (val) {
|
this.prototype.__defineSetter__(name, function (val) {
|
||||||
if (isArray(val))
|
if (isArray(val))
|
||||||
val = Array.slice(val);
|
val = Array.slice(val);
|
||||||
if (isArray(val) && Object.freeze)
|
if (isArray(val))
|
||||||
Object.freeze(val);
|
Object.freeze(val);
|
||||||
this[i] = val;
|
this[i] = val;
|
||||||
this.enabled = this.enabled;
|
this.enabled = this.enabled;
|
||||||
@@ -87,13 +87,25 @@ var Hive = Class("Hive", {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.sheets = [];
|
this.sheets = [];
|
||||||
this.names = {};
|
this.names = {};
|
||||||
|
this.refs = [];
|
||||||
|
},
|
||||||
|
|
||||||
|
addRef: function (obj) {
|
||||||
|
this.refs.push(Cu.getWeakReference(obj));
|
||||||
|
this.dropRef(null);
|
||||||
|
},
|
||||||
|
dropRef: function (obj) {
|
||||||
|
this.refs = this.refs.filter(function (ref) ref.get() && ref.get() !== obj);
|
||||||
|
if (!this.refs.length) {
|
||||||
|
this.cleanup();
|
||||||
|
styles.hives = styles.hives.filter(function (h) h !== this, this);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
cleanup: function cleanup() {
|
cleanup: function cleanup() {
|
||||||
for (let sheet in values(this.sheets))
|
for (let sheet in values(this.sheets))
|
||||||
sheet.enabled = false;
|
sheet.enabled = false;
|
||||||
},
|
},
|
||||||
destroy: function destroy() {},
|
|
||||||
|
|
||||||
__iterator__: function () Iterator(this.sheets),
|
__iterator__: function () Iterator(this.sheets),
|
||||||
|
|
||||||
@@ -220,7 +232,6 @@ var Hive = Class("Hive", {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
|
||||||
/**
|
/**
|
||||||
* Manages named and unnamed user style sheets, which apply to both
|
* Manages named and unnamed user style sheets, which apply to both
|
||||||
* chrome and content pages.
|
* chrome and content pages.
|
||||||
@@ -230,7 +241,6 @@ try {
|
|||||||
var Styles = Module("Styles", {
|
var Styles = Module("Styles", {
|
||||||
init: function () {
|
init: function () {
|
||||||
this._id = 0;
|
this._id = 0;
|
||||||
this.hives = [];
|
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
this.allSheets = {};
|
this.allSheets = {};
|
||||||
|
|
||||||
@@ -244,17 +254,20 @@ var Styles = Module("Styles", {
|
|||||||
|
|
||||||
cleanup: function cleanup() {
|
cleanup: function cleanup() {
|
||||||
for each (let hive in this.hives)
|
for each (let hive in this.hives)
|
||||||
hive.cleanup();
|
util.trapErrors("cleanup", hive);
|
||||||
this.user = this.addHive("user");
|
this.hives = [];
|
||||||
this.system = this.addHive("system");
|
this.user = this.addHive("user", this);
|
||||||
|
this.system = this.addHive("system", this);
|
||||||
},
|
},
|
||||||
|
|
||||||
addHive: function addHive(name) {
|
addHive: function addHive(name, ref) {
|
||||||
let hive = array.nth(this.hives, function (h) h.name === name, 0);
|
let hive = array.nth(this.hives, function (h) h.name === name, 0);
|
||||||
if (!hive) {
|
if (!hive) {
|
||||||
hive = Hive(name);
|
hive = Hive(name);
|
||||||
this.hives.push(hive);
|
this.hives.push(hive);
|
||||||
}
|
}
|
||||||
|
if (ref)
|
||||||
|
hive.addRef(ref);
|
||||||
return hive;
|
return hive;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -601,7 +614,23 @@ var Styles = Module("Styles", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
contexts: function (dactyl, modules, window) {
|
contexts: function (dactyl, modules, window) {
|
||||||
modules.Group.Hives("styles", function (group) styles.addHive(group.name));
|
modules.Group.Hives("styles",
|
||||||
|
Class("LocalHive", modules.Group.Hive, {
|
||||||
|
init: function init(group) {
|
||||||
|
init.superapply(this, arguments);
|
||||||
|
|
||||||
|
this.hive = styles.addHive(group.name);
|
||||||
|
this.hive.addRef(this);
|
||||||
|
},
|
||||||
|
|
||||||
|
__noSuchMethod__: function __noSuchMethod__(meth, args) {
|
||||||
|
return this.hive[meth].apply(this.hive, args);
|
||||||
|
},
|
||||||
|
|
||||||
|
destroy: function () {
|
||||||
|
this.hive.dropRef(this);
|
||||||
|
}
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
completion: function (dactyl, modules, window) {
|
completion: function (dactyl, modules, window) {
|
||||||
const names = Array.slice(util.computedStyle(window.document.createElement("div")));
|
const names = Array.slice(util.computedStyle(window.document.createElement("div")));
|
||||||
@@ -658,6 +687,6 @@ var Styles = Module("Styles", {
|
|||||||
|
|
||||||
endModule();
|
endModule();
|
||||||
|
|
||||||
} catch(e){dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack);}
|
// catch(e){dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack);}
|
||||||
|
|
||||||
// vim: set fdm=marker sw=4 ts=4 et ft=javascript:
|
// vim: set fdm=marker sw=4 ts=4 et ft=javascript:
|
||||||
|
|||||||
Reference in New Issue
Block a user