X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=js%2Fdebug.js;fp=js%2Fdebug.js;h=a644d271484f5f766e215da268d71cae2818a84e;hb=7e02cae82befa6d101d43d97fb8bd79dedba54a4;hp=0000000000000000000000000000000000000000;hpb=8875fb445d47bb0925ef46a131a9bc4dec004b49;p=euphorik.git diff --git a/js/debug.js b/js/debug.js new file mode 100644 index 0000000..a644d27 --- /dev/null +++ b/js/debug.js @@ -0,0 +1,72 @@ +/** + * Affiche un objet quelconque sur la sortie du navigateur. + */ +var dumpObj = function(obj, name) +{ + if (typeof(dump) == "undefined") + return + + dump("---" + (name == undefined ? "" : " : " + name) + "\n") + dump(obj2text(obj)) + dump("\n---\n") +} + +var obj2text = function(obj, curDepth) +{ + if (curDepth == undefined) + curDepth = 0; + + var acc = "" + + if (obj == undefined) + { + acc += "" + } + else if (typeof(obj) == "string") + { + acc += "\"" + obj + "\"" + } + else if (obj.length != undefined) // array + { + acc += "[" + + var i = 0 + for (; i < obj.length; i++) + { + if (i != 0) acc += "," + acc += "\n" + indent(curDepth + 1, obj2text(obj[i], curDepth + 1)) + } + + acc += (i == 0 ? "]" : "\n" + indent(curDepth, "]")) + } + else if (typeof(obj) == "object") + { + acc += "{" + var i = 0 + for (prop in obj) + { + if (i != 0) acc += "," + acc += "\n" + indent(curDepth + 1, prop + " : " + obj2text(obj[prop], curDepth + 1)) + i += 1 + } + acc += "\n" + indent(curDepth, "}") + } + else if (typeof(obj) == "function") + { + acc += "" + } + else // value + { + acc += obj + } + + return acc +} + +var indent = function(depth, text) +{ + var indentText = "" + for (var i = 0; i < depth * 3; i++) + indentText += " " + return indentText + text +}