summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorportix <none@none>2012-05-09 01:58:30 +0200
committerportix <none@none>2012-05-09 01:58:30 +0200
commit9a0db1022c1c3375e9865a09fcce4de87f9d3304 (patch)
tree62c575c46cfffa4005fea94b8c98219271330922 /scripts
parent76f35a714a9eb14bec987c4e603ff1594b306ac8 (diff)
downloaddwb-9a0db1022c1c3375e9865a09fcce4de87f9d3304.zip
Freeze extensions and data object, real private properties for the signal object.
--HG-- branch : scripts
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/data.js1
-rw-r--r--scripts/lib/extensions.js70
-rw-r--r--scripts/lib/signals.js159
3 files changed, 116 insertions, 114 deletions
diff --git a/scripts/lib/data.js b/scripts/lib/data.js
index 1cfa800d..80e2eff5 100644
--- a/scripts/lib/data.js
+++ b/scripts/lib/data.js
@@ -32,3 +32,4 @@
"searchEngines" : { value : configDir + "/searchengines", enumerable : true }
});
})();
+Object.freeze(data);
diff --git a/scripts/lib/extensions.js b/scripts/lib/extensions.js
index 5f1f086f..2e6d163e 100644
--- a/scripts/lib/extensions.js
+++ b/scripts/lib/extensions.js
@@ -1,41 +1,40 @@
-Object.defineProperties(extensions, {
- "warning" : {
- value : function (name, message) {
- io.print("\033[1mDWB EXTENSION WARNING: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr");
- }
- },
- "error" : {
- value : function (name, message) {
- io.print("\033[31mDWB EXTENSION ERROR: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr");
+(function () {
+ var _config = undefined;
+ function getPlugin(name, filename) {
+ var ret = null;
+ try {
+ if (io.fileTest(filename, FileTest.exists)) {
+ ret = include(filename);
+ }
}
- },
- "message" : {
- value : function (name, message) {
- io.print("\033[1mDWB EXTENSION: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr");
+ catch(e) {
+ extensions.error(name, "Error in line " + e.line + " parsing " + filename);
}
- },
- "load" : {
- value : (function () {
- var _config = undefined;
- function getPlugin(name, filename) {
- var ret = null;
- try {
- if (io.fileTest(filename, FileTest.exists)) {
- ret = include(filename);
- }
- }
- catch(e) {
- extensions.error(name, "Error in line " + e.line + " parsing " + filename);
- }
- return ret;
+ return ret;
+ }
+ Object.defineProperties(extensions, {
+ "warning" : {
+ value : function (name, message) {
+ io.print("\033[1mDWB EXTENSION WARNING: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr");
}
-
- return function(name, c) {
+ },
+ "error" : {
+ value : function (name, message) {
+ io.print("\033[31mDWB EXTENSION ERROR: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr");
+ }
+ },
+ "message" : {
+ value : function (name, message) {
+ io.print("\033[1mDWB EXTENSION: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr");
+ }
+ },
+ "load" : {
+ value : function(name, c) {
var boldname = "\033[1m" + name + "\033[0m";
var config, dataBase, pluginPath, plugin = null;
var extConfig = null;
-
+
/* Get default config if the config hasn't been read yet */
if (arguments.length == 2) {
extConfig = c;
@@ -84,7 +83,8 @@ Object.defineProperties(extensions, {
extensions.error(name, "Initialization failed: " + e);
return false;
}
- };
- })()
- }
-});
+ }
+ }
+ });
+})();
+Object.freeze(extensions);
diff --git a/scripts/lib/signals.js b/scripts/lib/signals.js
index 303e823a..f254aea9 100644
--- a/scripts/lib/signals.js
+++ b/scripts/lib/signals.js
@@ -1,91 +1,92 @@
-Object.defineProperties(signals, {
- "_registered" : {
- value : {}
- },
- "emit" : {
- value : function(sig, args) {
- var sigs = signals._registered[sig];
- var ret = false;
- var i = 0;
- do {
- if (sigs[i].connected) {
- ret = sigs[i].callback.apply(this, args) || ret;
- i++;
- }
- else {
- sigs.splice(i, 1);
+(function () {
+ var _registered = {};
+ Object.defineProperties(signals, {
+ "emit" : {
+ value : function(sig, args) {
+ var sigs = _registered[sig];
+ var ret = false;
+ var i = 0;
+ do {
+ if (sigs[i].connected) {
+ ret = sigs[i].callback.apply(this, args) || ret;
+ i++;
+ }
+ else {
+ sigs.splice(i, 1);
+ }
+ } while (i<sigs.length);
+ if (_registered[sig].length === 0) {
+ signals[sig] = null;
}
- } while (i<sigs.length);
- if (signals._registered[sig].length === 0) {
- signals[sig] = null;
+ return ret;
}
- return ret;
- }
- },
- "connect" : {
- value : (function () {
- var id = 0;
- return function(sig, func) {
- ++id;
- if (signals._registered[sig] === undefined || signals._registered[sig] === null) {
- signals._registered[sig] = [];
- signals[sig] = function () { return signals.emit(sig, arguments); };
- }
- if (func === null || typeof func !== "function") {
- return -1;
- }
- signals._registered[sig].push({callback : func, id : id, connected : true });
- return id;
- };
- })()
- },
- "disconnect" : {
- value : function(id) {
- var sig, i, sigs;
- for (sig in signals._registered) {
- sigs = signals._registered[sig];
- for (i = 0; i<sigs.length; i++) {
- if (sigs[i].id == id) {
- if (signals._registered[sig].length === 1) {
- signals[sig] = null;
- }
- else {
- sigs[i].connected = false;
+ },
+ "connect" : {
+ value : (function () {
+ var id = 0;
+ return function(sig, func) {
+ ++id;
+ if (_registered[sig] === undefined || _registered[sig] === null) {
+ _registered[sig] = [];
+ signals[sig] = function () { return signals.emit(sig, arguments); };
+ }
+ if (func === null || typeof func !== "function") {
+ return -1;
+ }
+ _registered[sig].push({callback : func, id : id, connected : true });
+ return id;
+ };
+ })()
+ },
+ "disconnect" : {
+ value : function(id) {
+ var sig, i, sigs;
+ for (sig in _registered) {
+ sigs = _registered[sig];
+ for (i = 0; i<sigs.length; i++) {
+ if (sigs[i].id == id) {
+ if (_registered[sig].length === 1) {
+ signals[sig] = null;
+ }
+ else {
+ sigs[i].connected = false;
+ }
+ return true;
}
- return true;
}
}
+ return false;
}
- return false;
- }
- },
- "disconnectByFunction" : {
- value : function(func) {
- var sig, i, sigs, ret = false;
- for (sig in signals._registered) {
- sigs = signals._registered[sig];
- for (i = 0; i<sigs.length; i++) {
- if (sigs[i].callback == func) {
- if (signals._registered[sig].length === 1) {
- signals[sig] = null;
+ },
+ "disconnectByFunction" : {
+ value : function(func) {
+ var sig, i, sigs, ret = false;
+ for (sig in _registered) {
+ sigs = _registered[sig];
+ for (i = 0; i<sigs.length; i++) {
+ if (sigs[i].callback == func) {
+ if (_registered[sig].length === 1) {
+ signals[sig] = null;
+ }
+ else {
+ sigs[i].connected = false;
+ }
+ ret = true;
}
- else {
- sigs[i].connected = false;
- }
- ret = true;
}
}
+ return ret;
}
- return ret;
- }
- },
- "disconnectByName" : {
- value : function (name) {
- if (signals[name] !== null && signals[name] !== undefined) {
- signals[name] = null;
- return true;
+ },
+ "disconnectByName" : {
+ value : function (name) {
+ io.print(name);
+ if (signals[name] !== null && signals[name] !== undefined) {
+ signals[name] = null;
+ return true;
+ }
+ return false;
}
- return false;
}
- }
-});
+ });
+})();