summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorportix <none@none>2013-02-25 13:36:38 +0100
committerportix <none@none>2013-02-25 13:36:38 +0100
commitb843d5c2abeee780ec3ef2d14c61e185986e9509 (patch)
treed93e00649bb7801938bca0225402c8c7ec0b32f8 /scripts
parent73e4adf3a8f69b965e4b5e56b039ad5334ec6956 (diff)
downloaddwb-b843d5c2abeee780ec3ef2d14c61e185986e9509.zip
Let self.debug be more verbose
Diffstat (limited to 'scripts')
-rw-r--r--scripts/base.js4
-rw-r--r--scripts/lib/io.js89
2 files changed, 71 insertions, 22 deletions
diff --git a/scripts/base.js b/scripts/base.js
index 1a9f0b6a..d6a1d31b 100644
--- a/scripts/base.js
+++ b/scripts/base.js
@@ -138,9 +138,9 @@ Object.freeze((function () {
this.getStart = function(n)
{
var start = parseInt(Math.log(n) / Math.log(10), 10)*10;
- if (n > 10*start-start) {
+ if (n > 10*start-start)
start*=10;
- }
+
return Math.max(start, 1);
};
this.betterMatch = function(input)
diff --git a/scripts/lib/io.js b/scripts/lib/io.js
index 3d731e8b..e6f1c4de 100644
--- a/scripts/lib/io.js
+++ b/scripts/lib/io.js
@@ -5,35 +5,52 @@
var prefixStack = "\n==> DEBUG [STACK] : ";
var prefixArguments = "\n==> DEBUG [ARGUMENTS] : ";
var prefixCaller = "\n==> DEBUG [CALLER]";
+ var prefixSource = "\n==> DEBUG [SOURCE] : \n";
var prefixFunction = "\n------>";
var regHasDwb = new RegExp("[^]*/\\*<dwb\\*/([^]*)/\\*dwb>\\*/[^]*");
+ var formatLine = function(line, max)
+ {
+ var size = max - Math.max(1, Math.ceil(Math.log(line+1)/Math.log(10))) + 1;
+ return Array(size).join(" ") + line + " > ";
+ };
Object.defineProperties(io, {
"debug" :
{
value : function (params)
{
- var message = new String();
+ var outMessage = new String();
params = params || {};
var offset = params.offset || 0;
- var error;
- if (params instanceof Error)
+ var error, message;
+ var line = -1;
+ var showLine;
+ var caller, source;
+ var stack;
+
+ if (typeof params == "string")
+ message = params;
+ else if (params instanceof Error)
error = params;
- else {
+ else
+ {
if (params.message)
- {
- message += prefixMessage + params.message;
- }
+ message = params.message;
if (params.error instanceof Error)
error = params.error;
}
if (this.path)
- message += prefixFile + this.path;
+ outMessage += prefixFile + this.path;
+ if (message)
+ outMessage += prefixMessage + message;
if (error)
{
- var line = error.line || error.line === 0 ? error.line : "?";
+ if (error.line || error.line === 0)
+ line = showLine = error.line;
+ else
+ showLine = "?";
if (!error.stack)
{
try
@@ -46,8 +63,8 @@
}
offset += 1;
}
- message += prefixError + "Exception in line " + line + ": " + error.message +
- prefixStack + "[" + error.stack.match(/[^\n]+/g).slice(offset).join("] [")+"]";
+ outMessage += prefixError + "Exception in line " + showLine + ": " + error.message;
+ stack = "[" + error.stack.match(/[^\n]+/g).slice(offset).join("] [")+"]";
}
else
{
@@ -57,19 +74,51 @@
}
catch(e)
{
- message += prefixStack + "[" + e.stack.match(/[^\n]+/g).slice(offset + 1).join("] [")+"]";
+ stack = "[" + e.stack.match(/[^\n]+/g).slice(offset + 2).join("] [")+"]";
+ }
+ }
+ if (stack)
+ {
+ outMessage += prefixStack + stack;
+ }
+
+ if (this.arguments && line >= 0)
+ {
+ 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));
+
+ outMessage += prefixSource;
+ if (length >= line-3 && line-3 >= 0)
+ {
+ if (length >= line-4)
+ outMessage += "...\n";
+ outMessage += formatLine(line-1, max) + source[line-3] + "\n";
+ }
+ else
+ outMessage += formatLine(line-1, max) + "#!javascript\n";
+ if (length > line-2)
+ outMessage += formatLine(line, max) + source[line-2] + " <-----\n";
+ if (length > line-1 && length != line)
+ {
+ outMessage += formatLine(line+1, max) + source[line-1];
+ if (length > line + 1)
+ outMessage += "\n...";
}
+ else
+ outMessage += "EOF";
}
- if (params.arguments)
+ else 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;
+ outMessage += prefixArguments + JSON.stringify(params.arguments);
+ caller = String(params.arguments.callee.caller);
+ outMessage += prefixCaller;
+ outMessage += prefixFunction + "\n";
+ outMessage += caller.replace(regHasDwb, "$1").replace(/\n/gm, "\n ");
+ outMessage += prefixFunction;
}
- io.print(message + "\n", "stderr");
+ io.print(outMessage + "\n", "stderr");
}
}