diff options
author | portix <none@none> | 2012-12-05 11:14:05 +0100 |
---|---|---|
committer | portix <none@none> | 2012-12-05 11:14:05 +0100 |
commit | 86194c6f8f633b2ea74572eb15719ed2c801f085 (patch) | |
tree | da28e8997c2a8e30f15c055382ab61a2ad355fa8 /scripts | |
parent | 1f221322310ef74c40b46ddba5c692be0294f823 (diff) | |
download | dwb-86194c6f8f633b2ea74572eb15719ed2c801f085.zip |
Creating _initBefore that is executed before userscripts are executed
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/dwb.js | 37 | ||||
-rw-r--r-- | scripts/lib/io.js | 114 | ||||
-rw-r--r-- | scripts/lib/signals.js | 4 |
3 files changed, 92 insertions, 63 deletions
diff --git a/scripts/lib/dwb.js b/scripts/lib/dwb.js index a6a1edac..f40848b7 100644 --- a/scripts/lib/dwb.js +++ b/scripts/lib/dwb.js @@ -29,7 +29,7 @@ }; var _privProps = []; - function _getPrivateIdx(object, key, identifier) + var _getPrivateIdx = function(object, key, identifier) { var p; for (var i=0, l=_privProps.length; i<l; ++i) @@ -39,7 +39,9 @@ return i; } return -1; - } + }; + var _contexts; + Object.defineProperties(this, { "provide" : { @@ -49,7 +51,8 @@ { io.debug({ offset : 1, arguments : arguments, - error : new Error("provide: Module " + name + " is already defined!") + error : new Error("provide: Module " + + name + " is already defined!") }); } else @@ -77,7 +80,12 @@ { if (names !== null && ! (names instanceof Array)) { - io.debug({ error : new Error("require : invalid argument (" + JSON.stringify(names) + ")"), offset : 1, arguments : arguments }); + io.debug({ + error : new Error("require : invalid argument (" + + JSON.stringify(names) + ")"), + offset : 1, + arguments : arguments + }); return; } @@ -90,7 +98,7 @@ // Called after all scripts have been loaded and executed // Immediately deleted from the global object, so it is not callable // from other scripts - "_init" : + "_initAfter" : { value : function() { @@ -101,15 +109,21 @@ Object.freeze(this); }, configurable : true + }, + "_initBefore" : + { + value : function(contexts) + { + _contexts = contexts; + }, + configurable : true } }); - Object.defineProperties(GObject.prototype, - { + Object.defineProperties(GObject.prototype, { "setPrivate" : { value : function(key, value, identifier) { - io.print(this instanceof WebKitWebView); if (!(identifier instanceof Object) && !(identifier instanceof Function)) throw new Error("[setPrivate] identifier is not an Object or Function"); @@ -117,7 +131,12 @@ if (i === -1) { if (value !== undefined && value !== null) - _privProps.push({ object : this, key : key, identifier : identifier, value : value }); + _privProps.push({ + object : this, + key : key, + identifier : identifier, + value : value + }); } else if (value !== null) { diff --git a/scripts/lib/io.js b/scripts/lib/io.js index dfb2dc99..c4857711 100644 --- a/scripts/lib/io.js +++ b/scripts/lib/io.js @@ -1,57 +1,67 @@ (function () { - var prefixMessage = "\n==> DEBUG [MESSAGE] : "; - var prefixError = "\n==> DEBUG [ERROR] : "; - var prefixStack = "\n==> DEBUG [STACK] : "; - var prefixArguments = "\n==> DEBUG [ARGUMENTS] : "; - var prefixCaller = "\n==> DEBUG [CALLER]"; - var prefixFunction = "\n------>"; - var regHasDwb = new RegExp("[^]*/\\*<dwb\\*/([^]*)/\\*dwb>\\*/[^]*"); + var prefixMessage = "\n==> DEBUG [MESSAGE] : "; + var prefixError = "\n==> DEBUG [ERROR] : "; + var prefixStack = "\n==> DEBUG [STACK] : "; + var prefixArguments = "\n==> DEBUG [ARGUMENTS] : "; + var prefixCaller = "\n==> DEBUG [CALLER]"; + var prefixFunction = "\n------>"; + var regHasDwb = new RegExp("[^]*/\\*<dwb\\*/([^]*)/\\*dwb>\\*/[^]*"); - Object.defineProperties(io, { - "debug" : { - value : function (params) { - var message = new String(); - params = params || {}; - var offset = params.offset || 0; - if (params.message) { - message += prefixMessage + params.message; - } - if (params.error && params.error instanceof Error) { - var line = params.error.line || params.error.line === 0 ? params.error.line : "?"; - var error = params.error; - if (!error.stack) { - try { - throw new Error(error.message); - } - catch(e) { - error = e; - } - offset += 1; - } - message += prefixError + "Exception in line " + line + ": " + error.message + - prefixStack + "[" + error.stack.match(/[^\n]+/g).slice(offset).join("] [")+"]"; - } - else { - try { - throw new Error(); - } - catch(e) { - message += prefixStack + "[" + e.stack.match(/[^\n]+/g).slice(offset + 1).join("] [")+"]"; - } - } - if (params.arguments) - { - message += prefixArguments + JSON.stringify(params.arguments); - var caller = String(params.arguments.callee.caller); - message += prefixCaller; - message += prefixFunction + "\n"; - message += caller.replace(regHasDwb, "$1").replace(/\n/gm, "\n "); - message += prefixFunction; - } - io.print(message + "\n", "stderr"); - } + Object.defineProperties(io, { + "debug" : + { + value : function (params) + { + var message = new String(); + params = params || {}; + var offset = params.offset || 0; + if (params.message) + { + message += prefixMessage + params.message; + } + if (params.error && params.error instanceof Error) + { + var line = params.error.line || params.error.line === 0 ? params.error.line : "?"; + var error = params.error; + if (!error.stack) + { + try + { + throw new Error(error.message); + } + catch(e) + { + error = e; + } + offset += 1; + } + message += prefixError + "Exception in line " + line + ": " + error.message + + prefixStack + "[" + error.stack.match(/[^\n]+/g).slice(offset).join("] [")+"]"; + } + else + { + try + { + throw new Error(); + } + catch(e) + { + message += prefixStack + "[" + e.stack.match(/[^\n]+/g).slice(offset + 1).join("] [")+"]"; + } + } + if (params.arguments) + { + message += prefixArguments + JSON.stringify(params.arguments); + var caller = String(params.arguments.callee.caller); + message += prefixCaller; + message += prefixFunction + "\n"; + message += caller.replace(regHasDwb, "$1").replace(/\n/gm, "\n "); + message += prefixFunction; + } + io.print(message + "\n", "stderr"); + } - } - }); + } + }); })(); Object.freeze(io); diff --git a/scripts/lib/signals.js b/scripts/lib/signals.js index 53df11a5..3de9e8f1 100644 --- a/scripts/lib/signals.js +++ b/scripts/lib/signals.js @@ -38,7 +38,7 @@ { var sigs = _registered[sig]; var ret = false; - var i = 0; + var i = 0, l=sigs.length; do { if (sigs[i].connected) @@ -50,7 +50,7 @@ { sigs.splice(i, 1); } - } while (i<sigs.length); + } while (i<l); if (_registered[sig].length === 0) { |