From 9a0db1022c1c3375e9865a09fcce4de87f9d3304 Mon Sep 17 00:00:00 2001 From: portix Date: Wed, 9 May 2012 01:58:30 +0200 Subject: Freeze extensions and data object, real private properties for the signal object. --HG-- branch : scripts --- scripts/lib/data.js | 1 + scripts/lib/extensions.js | 70 ++++++++++---------- scripts/lib/signals.js | 159 +++++++++++++++++++++++----------------------- 3 files changed, 116 insertions(+), 114 deletions(-) (limited to 'scripts') 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