From 49a4945074f6c8007bd79e7a52527f415ea11873 Mon Sep 17 00:00:00 2001 From: portix Date: Wed, 30 May 2012 15:46:14 +0200 Subject: New function io.debug; print debug messages in all scripts in XDG_CONFIG_HOME/dwb/userscripts --- scripts/lib/io.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 scripts/lib/io.js (limited to 'scripts') 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); -- cgit v1.2.3