mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-04 13:35:46 +01:00
Constify certain script global properties. Provide 'unload' method.
--HG-- branch : groups
This commit is contained in:
@@ -157,6 +157,8 @@ var Contexts = Module("contexts", {
|
||||
}
|
||||
}, {
|
||||
Context: modules.Script = function Context(file, group, args) {
|
||||
function Const(val) Class.Property({ enumerable: true, value: val });
|
||||
|
||||
let isPlugin = io.getRuntimeDirectories("plugins")
|
||||
.some(function (dir) dir.contains(file, false))
|
||||
|
||||
@@ -167,9 +169,18 @@ var Contexts = Module("contexts", {
|
||||
}
|
||||
else {
|
||||
self = update(modules.newContext.apply(null, args || [userContext]), {
|
||||
NAME: file.leafName.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase()),
|
||||
PATH: file.path,
|
||||
CONTEXT: self
|
||||
NAME: Const(file.leafName.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase())),
|
||||
PATH: Const(file.path),
|
||||
CONTEXT: Const(self),
|
||||
unload: Const(function unload() {
|
||||
if (plugins[this.NAME] === this || plugins[this.PATH] === this)
|
||||
if (this.onUnload)
|
||||
this.onUnload();
|
||||
if (plugins[this.NAME] === this)
|
||||
delete plugins[this.NAME];
|
||||
if (plugins[this.PATH] === this)
|
||||
delete plugins[this.PATH];
|
||||
})
|
||||
});
|
||||
Class.replaceProperty(plugins, file.path, self);
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ var IO = Module("io", {
|
||||
params = params || {};
|
||||
|
||||
let time = Date.now();
|
||||
contexts.withSavedValues(["context"], function _source() {
|
||||
return contexts.withSavedValues(["context"], function _source() {
|
||||
contexts.context = null;
|
||||
try {
|
||||
var file = util.getFile(filename) || io.File(filename);
|
||||
@@ -172,7 +172,8 @@ var IO = Module("io", {
|
||||
// handle pure JavaScript files specially
|
||||
if (/\.js$/.test(filename)) {
|
||||
try {
|
||||
dactyl.loadScript(uri.spec, Contexts.Script(file, params.group));
|
||||
var context = Contexts.Script(file, params.group);
|
||||
dactyl.loadScript(uri.spec, context);
|
||||
dactyl.helpInitialized = false;
|
||||
}
|
||||
catch (e) {
|
||||
@@ -190,7 +191,7 @@ var IO = Module("io", {
|
||||
else if (/\.css$/.test(filename))
|
||||
styles.registerSheet(uri.spec, false, true);
|
||||
else {
|
||||
let context = Contexts.Context(file, params.group);
|
||||
context = Contexts.Context(file, params.group);
|
||||
modules.commands.execute(file.read(), null, params.silent || "loud",
|
||||
null, {
|
||||
context: context,
|
||||
@@ -206,6 +207,7 @@ var IO = Module("io", {
|
||||
dactyl.echomsg("finished sourcing " + filename.quote(), 2);
|
||||
|
||||
dactyl.log("Sourced: " + filename, 3);
|
||||
return context;
|
||||
}
|
||||
catch (e) {
|
||||
if (!(e instanceof FailedAssertion))
|
||||
|
||||
Reference in New Issue
Block a user