diff options
author | portix <none@none> | 2013-02-25 19:05:40 +0100 |
---|---|---|
committer | portix <none@none> | 2013-02-25 19:05:40 +0100 |
commit | f1398192ecd1af3f205f7e6edf4e2fed54c89f2c (patch) | |
tree | 7e4d4aa8bc5a7bdb317705acba33fdb3f488a4fa /scripts | |
parent | 4135423628e5d83fa2715d286a5a8b9eacd27090 (diff) | |
download | dwb-f1398192ecd1af3f205f7e6edf4e2fed54c89f2c.zip |
Simplify Function.debug, format debug messages
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/dwb.js | 20 | ||||
-rw-r--r-- | scripts/lib/io.js | 21 |
2 files changed, 17 insertions, 24 deletions
diff --git a/scripts/lib/dwb.js b/scripts/lib/dwb.js index 8691ab9e..e2c04448 100644 --- a/scripts/lib/dwb.js +++ b/scripts/lib/dwb.js @@ -218,27 +218,19 @@ Object.defineProperty(Function.prototype, "debug", { value : function(scope) { - var callee, path; - var self = this; - if (scope) - { - if (scope.arguments && scope.arguments.callee) - callee = String(scope.arguments.callee); - if (scope.path) - path = scope.path; - } return function() { try { - self.apply(self, arguments); + this.apply(this, arguments); } catch (e) { - e.callee = callee || undefined; - e.path = path || undefined; - io.debug(e); + if (scope) + scope.debug(e); + else + io.debug(e); } - }; + }.bind(this); } }); } diff --git a/scripts/lib/io.js b/scripts/lib/io.js index 4f1686c1..578268ae 100644 --- a/scripts/lib/io.js +++ b/scripts/lib/io.js @@ -8,11 +8,12 @@ var prefixSource = "\n==> DEBUG [SOURCE]\n"; var prefixFunction = "\n------>"; var regHasDwb = new RegExp("[^]*/\\*<dwb\\*/([^]*)/\\*dwb>\\*/[^]*"); - var prefixEditor = " "; + var prefixEditor = " "; + var prefixHighlight = "--> "; var formatLine = function(line, max) { var size = max - Math.ceil(Math.log(line+1)/Math.log(10)) + 1; - return prefixEditor + Array(size).join(" ") + line + " > "; + return Array(size).join(" ") + line + " > "; }; Object.defineProperties(io, { @@ -41,8 +42,8 @@ error = params.error; } - if (params.path || this.path) - outMessage += prefixFile + (params.path || this.path); + if (this.path) + outMessage += prefixFile + this.path; if (message) outMessage += prefixMessage + message; @@ -83,9 +84,9 @@ outMessage += prefixStack + stack; } - if ((params.callee || this.arguments) && line >= 0) + if (this._arguments && line >= 0) { - caller = (params.callee || String(this.arguments.callee)).replace(regHasDwb, "$1", ""); + caller = String(this._arguments.callee).replace(regHasDwb, "$1", ""); source = caller.split("\n"); var length = source.length; var max = Math.ceil(Math.log(source.length+1)/Math.log(10)); @@ -95,15 +96,15 @@ { if (length >= line-4) outMessage += prefixEditor + "...\n"; - outMessage += formatLine(line-1, max) + source[line-3] + "\n"; + outMessage += prefixEditor + formatLine(line-1, max) + source[line-3] + "\n"; } else - outMessage += formatLine(line-1, max) + "#!javascript\n"; + outMessage += prefixEditor + formatLine(line-1, max) + "#!javascript\n"; if (length > line-2) - outMessage += formatLine(line, max) + source[line-2] + " <-----\n"; + outMessage += prefixHighlight + formatLine(line, max) + source[line-2] + "\n"; if (length > line-1 && length != line) { - outMessage += formatLine(line+1, max) + source[line-1]; + outMessage += prefixEditor + formatLine(line+1, max) + source[line-1]; if (length > line + 1) outMessage += "\n" + prefixEditor + "..."; else |