summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorportix <none@none>2012-05-30 15:46:14 +0200
committerportix <none@none>2012-05-30 15:46:14 +0200
commit49a4945074f6c8007bd79e7a52527f415ea11873 (patch)
treeac5615fec15464a967762e70c666a2ff5d42029c /scripts
parent5de803da7bde5953b33fb13bf8f5bf7f0e81fc32 (diff)
downloaddwb-49a4945074f6c8007bd79e7a52527f415ea11873.zip
New function io.debug; print debug messages in all scripts in XDG_CONFIG_HOME/dwb/userscripts
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/io.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/lib/io.js b/scripts/lib/io.js
new file mode 100644
index 00000000..61b4b5e0
--- /dev/null
+++ b/scripts/lib/io.js
@@ -0,0 +1,34 @@
+Object.defineProperties(io, {
+ "debug" : {
+ value : function () {
+ var message = null;
+ if (arguments.length === 0) {
+ return;
+ }
+ else if (arguments.length === 1) {
+ if (arguments[0] instanceof Error) {
+ message = "\nSCRIPT DEBUG: \tException in line " + (arguments[0].line + 1) + ": " + arguments[0].message + "\n" +
+ "STACK: \t\t[" + arguments[0].stack.match(/[^\n]+/g).slice(0).join("] [")+"]\n";
+ }
+ else {
+ try {
+ throw new Error(arguments[0]);
+ }
+ catch (e) {
+ message = "\nSCRIPT DEBUG: \t" + e.message + "\n" +
+ "STACK: \t\t[" + e.stack.match(/[^\n]+/g).slice(1).join("] [")+"]\n";
+ }
+ }
+ }
+ else {
+ message = "\nSCRIPT DEBUG: \t" + arguments[0] + "\n";
+ if (arguments[1] instanceof Error) {
+ message += "SCRIPT DEBUG: \tException in line " + (arguments[1].line + 1) + ": " + arguments[1].message + "\n";
+ message += "STACK: \t\t[" + arguments[1].stack.match(/[^\n]+/g).slice(0).join("] [")+"]\n";
+ }
+ }
+ io.print(message, "stderr");
+ }
+ }
+});
+Object.freeze(io);