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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
define(function(){
function dump(arg, space, colors, arraynames){
if(!colors) colors = dump_plain
if(space === undefined) space = 100000
if(space <= 0) return ''
if(arg === undefined) return colors.undefined
if(arg === null) return colors.null
if(typeof arg === 'boolean'){
if(arg === true) return colors.true
if(arg === false) return colors.false
}
if(typeof arg === 'number'){
if(isNaN(arg)) return colors.NaN
return colors.numstart + arg + colors.numend
}
if(typeof arg === 'string'){
var str = arg
if(arg.length > space) str = arg.slice(0, space) + colors.elip
str = str.replace(/\r/g,'\\r').replace(/\n/g,'\\n').replace(/\t/g,'\\t')
return colors.strstart + str + colors.strend
}
if(typeof arg === 'function'){
if(arg.module) return colors.class + define.fileName(arg.module.filename)
return colors.function
}
if(Array.isArray(arg)){
var out = arraynames?'':colors.arrstart
for(var i = 0; i<arg.length; i++){
if(i) out += colors.arrsep
if(arraynames){
if(i < arraynames.length) out += colors.argstart + arraynames[i]+colors.argend+colors.argis
else out += colors.argstart + 'arguments['+String(i)+']' + colors.argend +colors.argis
}
out += dump(arg[i], (space - out.length)/2, colors)
if(space - out.length <= 0){
out += colors.elip
break
}
}
out += arraynames?'':colors.arrend
return out
}
if(typeof arg === 'object'){
if(Object.getPrototypeOf(arg) === Object.prototype){
var out = colors.objstart
for(var key in arg){
if(arg.__lookupGetter__(key)) continue
if(out !== colors.objstart) out += ','
out += colors.keystart + key + colors.keyend + colors.keysep + dump(arg[key], (space - out.length)/2, colors)
if(space - out.length<0){
out += colors.elip
break
}
}
out += colors.objend
return out
}
else{
var constructor = Object.getPrototypeOf(arg).constructor
var module = constructor && constructor.module
if(module) return colors.instance + colors.insstart + define.fileName(module.filename) + colors.insend
if(constructor){
var name = constructor.toString().match(/function\s+([^\()]*?)\(/)
if(name) return colors.instance + colors.insstart + name[1] + colors.insend
}
return colors.instance + colors.insstart + 'unknown' + colors.insend
}
return out
}
return typeof arg
}
dump.plain = {
'undefined':'undefined',
'null':'null',
'true':'true',
'false':'false',
'NaN':'NaN',
'strstart':"'",
'strend':"'",
'function':'function',
'class':'class:',
'arrstart':'[',
'arrend':']',
'arrsep':',',
'argstart':'',
'argend':'',
'argis':'=',
'objstart':'{',
'objend':'}',
'keystart':'',
'keyend':'',
'keysep':':',
'instance':'instance:',
'insstart':'',
'insend':'',
'numstart':'',
'numend':'',
'elip':'..'
}
dump.colors = {
'undefined':'~m~undefined~~',
'null':'~m~null~~',
'true':'~m~true~~',
'false':'~m~false~~',
'NaN':'~m~NaN~~',
'strstart':"~g~'",
'strend':"~g~'~~",
'function':'~m~function~~',
'class':'~by~class:~~',
'arrstart':'~bw~[~~',
'arrend':'~bw~]~~',
'arrsep':'~bw~,~~',
'argstart':'~w~',
'argend':'~~',
'argis':'~y~=~~',
'objstart':'~bw~{~~',
'objend':'~bw~}~~',
'keystart':'',
'keyend':'',
'keysep':':',
'instance':'instance:',
'insstart':'',
'insend':'',
'numstart':'~c~',
'numend':'~~',
'elip':'~br~..~~'
}
return dump
}) |