MOD le logo devient un protoype pour le design officiel
[euphorik.git] / js / debug.js
1 /**
2 * Affiche un objet quelconque sur la sortie du navigateur.
3 */
4 var dumpObj = function(obj, name)
5 {
6 if (typeof(dump) == "undefined")
7 return
8
9 dump("---" + (name == undefined ? "" : " : " + name) + "\n")
10 dump(obj2text(obj))
11 dump("\n---\n")
12 }
13
14 var obj2text = function(obj, curDepth)
15 {
16 if (curDepth == undefined)
17 curDepth = 0;
18
19 var acc = ""
20
21 if (obj == undefined)
22 {
23 acc += "<undefined>"
24 }
25 else if (typeof(obj) == "string")
26 {
27 acc += "\"" + obj + "\""
28 }
29 else if (obj.length != undefined) // array
30 {
31 acc += "["
32
33 var i = 0
34 for (; i < obj.length; i++)
35 {
36 if (i != 0) acc += ","
37 acc += "\n" + indent(curDepth + 1, obj2text(obj[i], curDepth + 1))
38 }
39
40 acc += (i == 0 ? "]" : "\n" + indent(curDepth, "]"))
41 }
42 else if (typeof(obj) == "object")
43 {
44 acc += "{"
45 var i = 0
46 for (prop in obj)
47 {
48 if (i != 0) acc += ","
49 acc += "\n" + indent(curDepth + 1, prop + " : " + obj2text(obj[prop], curDepth + 1))
50 i += 1
51 }
52 acc += "\n" + indent(curDepth, "}")
53 }
54 else if (typeof(obj) == "function")
55 {
56 acc += "<function>"
57 }
58 else // value
59 {
60 acc += obj
61 }
62
63 return acc
64 }
65
66 var indent = function(depth, text)
67 {
68 var indentText = ""
69 for (var i = 0; i < depth * 3; i++)
70 indentText += " "
71 return indentText + text
72 }