summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorportix <none@none>2012-05-13 23:29:27 +0200
committerportix <none@none>2012-05-13 23:29:27 +0200
commit04ff76857b387dde944593e6924f4b3887164430 (patch)
treeb219992ed13f41397a3d780196a006a116329ceb /scripts
parentbe78918ae7b99a43ce985f57337a50f46652489f (diff)
downloaddwb-04ff76857b387dde944593e6924f4b3887164430.zip
Implementing @match-rules in userscripts
--HG-- branch : scripts
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/extensions.js44
1 files changed, 42 insertions, 2 deletions
diff --git a/scripts/lib/extensions.js b/scripts/lib/extensions.js
index 2e6d163e..339803e5 100644
--- a/scripts/lib/extensions.js
+++ b/scripts/lib/extensions.js
@@ -1,5 +1,6 @@
(function () {
var _config = undefined;
+ var _debug = false;
function getPlugin(name, filename) {
var ret = null;
try {
@@ -12,15 +13,54 @@
}
return ret;
}
+ function getStack(offset) {
+ if (arguments.length === 0) {
+ offset = 0;
+ }
+ try {
+ throw Error (message);
+ }
+ catch (e) {
+ var stack = e.stack.match(/[^\n]+/g);
+ return "STACK: [" + stack.slice(offset+1).join("] [")+"]";
+ }
+ }
Object.defineProperties(extensions, {
"warning" : {
value : function (name, message) {
io.print("\033[1mDWB EXTENSION WARNING: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr");
}
},
- "error" : {
+ "enableDebugging" : {
+ set : function (value) {
+ if (typeof value == "boolean")
+ _debug = value;
+ }
+ },
+ "debug" : {
value : function (name, message) {
- io.print("\033[31mDWB EXTENSION ERROR: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr");
+ if (_debug) {
+ io.print("\033[1mDWB EXTENSION DEBUG: \033[0mextension \033[1m" + name + "\033[0m\n" + getStack(1), "stderr");
+ }
+ }
+ },
+ "error" : {
+ value : function (name, a, b) {
+ var message = "";
+ if (a instanceof Error) {
+ if (a.message) {
+ message = a.message;
+ }
+ else if (arguments.length > 2)
+ message = b;
+ else
+ b = "";
+ io.print("\033[31mDWB EXTENSION ERROR: \033[0mextension \033[1m" + name + "\033[0m in line " + a.line + ": " +
+ message + "\nSTACK: [" + a.stack.match(/[^\n]+/g).join("] [") + "]", "stderr");
+ }
+ else {
+ io.print("\033[31mDWB EXTENSION ERROR: \033[0mextension \033[1m" + name + "\033[0m: " + a + "\n" + getStack(1), "stderr");
+ }
}
},
"message" : {