-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.js
74 lines (63 loc) · 1.49 KB
/
debug.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* jsSudoku
*
* Copyright(C)2008 by Friedrich Gräter
* Published under the terms of the GNU General Public License V2
*
* debug.js
* Helper functions for debugging
*
*/
/*
* var_dump(object, output, depth)
*
* Dumps an object "object" to a container "output".
* If the object contains nested structures, the dump function
* will dump them up to level "depth".
*
*/
function var_dump(object, output, depth)
{
var container = document.createElement("div");
var color = 100 + depth;
container.setAttribute("style", "border: 1px solid; background-color:rgb(160, 0, "+(color)+")");
output.appendChild(container);
var content;
var info;
for (var member in object)
{
content = document.createElement("div");
switch(typeof(object[member]))
{
case "boolean" :
case "string" :
case "number" :
{
info = document.createTextNode(member+": "+object[member]);
content.appendChild(info);
break;
}
case "function" :
{
info = document.createTextNode(member+"()");
content.appendChild(info);
break;
}
case "object" :
{
info = document.createTextNode(member+":");
content.appendChild(info);
var_dump(object[member], content, depth + 30);
content.setAttribute("style", "margin-left: 8px");
break;
}
default :
{
info = document.createTextNode(member+": UNKNOWN_TYPE ("+typeof(object[member])+")");
content.appendChild(info);
break;
}
}
container.appendChild(content);
}
}