@jdeighan/coffee-utils 7.0.56 → 7.0.57
Sign up to get free protection for your applications and to get access to all the features.
- package/Debugging.md +6 -0
- package/package.json +1 -1
- package/src/call_stack.coffee +5 -5
- package/src/call_stack.js +6 -5
- package/src/debug_utils.coffee +78 -99
- package/src/debug_utils.js +93 -113
- package/src/log_utils.coffee +2 -2
- package/src/log_utils.js +2 -2
package/Debugging.md
ADDED
package/package.json
CHANGED
package/src/call_stack.coffee
CHANGED
@@ -105,7 +105,7 @@ export class CallStack
|
|
105
105
|
LOG "[<-- BACK #{fName}]"
|
106
106
|
|
107
107
|
if @lStack.length == 0
|
108
|
-
LOG "ERROR: returnFrom('#{
|
108
|
+
LOG "ERROR: returnFrom('#{fName}') but stack is empty"
|
109
109
|
return
|
110
110
|
|
111
111
|
{fullName, isLogged} = @lStack.pop()
|
@@ -155,10 +155,10 @@ export class CallStack
|
|
155
155
|
|
156
156
|
dump: (prefix='', label='CALL STACK') ->
|
157
157
|
|
158
|
-
|
158
|
+
lLines = ["#{label}:"]
|
159
159
|
if @lStack.length == 0
|
160
|
-
|
160
|
+
lLines.push " <EMPTY>"
|
161
161
|
else
|
162
162
|
for item, i in @lStack
|
163
|
-
|
164
|
-
return
|
163
|
+
lLines.push " #{i}: #{item.fullName} #{item.isLogged}"
|
164
|
+
return lLines.join("\n") + "\n"
|
package/src/call_stack.js
CHANGED
@@ -107,7 +107,7 @@ export var CallStack = class CallStack {
|
|
107
107
|
LOG(`[<-- BACK ${fName}]`);
|
108
108
|
}
|
109
109
|
if (this.lStack.length === 0) {
|
110
|
-
LOG(`ERROR: returnFrom('${
|
110
|
+
LOG(`ERROR: returnFrom('${fName}') but stack is empty`);
|
111
111
|
return;
|
112
112
|
}
|
113
113
|
({fullName, isLogged} = this.lStack.pop());
|
@@ -160,17 +160,18 @@ export var CallStack = class CallStack {
|
|
160
160
|
// ........................................................................
|
161
161
|
// ........................................................................
|
162
162
|
dump(prefix = '', label = 'CALL STACK') {
|
163
|
-
var i, item, j, len, ref;
|
164
|
-
|
163
|
+
var i, item, j, lLines, len, ref;
|
164
|
+
lLines = [`${label}:`];
|
165
165
|
if (this.lStack.length === 0) {
|
166
|
-
|
166
|
+
lLines.push(" <EMPTY>");
|
167
167
|
} else {
|
168
168
|
ref = this.lStack;
|
169
169
|
for (i = j = 0, len = ref.length; j < len; i = ++j) {
|
170
170
|
item = ref[i];
|
171
|
-
|
171
|
+
lLines.push(` ${i}: ${item.fullName} ${item.isLogged}`);
|
172
172
|
}
|
173
173
|
}
|
174
|
+
return lLines.join("\n") + "\n";
|
174
175
|
}
|
175
176
|
|
176
177
|
};
|
package/src/debug_utils.coffee
CHANGED
@@ -17,15 +17,62 @@ import {
|
|
17
17
|
} from '@jdeighan/coffee-utils/log'
|
18
18
|
|
19
19
|
callStack = new CallStack()
|
20
|
-
doDebugDebug = false
|
21
20
|
|
22
|
-
|
21
|
+
# --- set in resetDebugging() and setDebugging()
|
22
|
+
export shouldLog = () -> undef
|
23
23
|
export lFuncList = []
|
24
24
|
|
25
|
+
# --- internal debugging
|
26
|
+
doDebugDebug = false
|
27
|
+
lFunctions = undef # --- only used when doDebugDebug is true
|
28
|
+
|
29
|
+
# ---------------------------------------------------------------------------
|
30
|
+
|
31
|
+
export setDebugDebugging = (value=true) ->
|
32
|
+
# --- value can be a boolean or string of words
|
33
|
+
|
34
|
+
if isBoolean(value)
|
35
|
+
doDebugDebug = value
|
36
|
+
else if isString(value)
|
37
|
+
doDebugDebug = true
|
38
|
+
lFunctions = words(value)
|
39
|
+
else
|
40
|
+
croak "Bad value: #{OL(value)}"
|
41
|
+
return
|
42
|
+
|
43
|
+
# ---------------------------------------------------------------------------
|
44
|
+
|
45
|
+
logif = (label, lObjects...) ->
|
46
|
+
|
47
|
+
if ! doDebugDebug
|
48
|
+
return
|
49
|
+
|
50
|
+
assert isString(label), "1st arg #{OL(label)} should be a string"
|
51
|
+
nObjects = lObjects.length
|
52
|
+
[type, funcName] = getType(label, nObjects)
|
53
|
+
switch type
|
54
|
+
when 'enter'
|
55
|
+
if defined(lFunctions) && (funcName not in lFunctions)
|
56
|
+
return
|
57
|
+
callStack.enter funcName
|
58
|
+
log label, lObjects...
|
59
|
+
when 'return'
|
60
|
+
if defined(lFunctions) && (funcName not in lFunctions)
|
61
|
+
return
|
62
|
+
log label, lObjects...
|
63
|
+
callStack.returnFrom funcName
|
64
|
+
when 'string'
|
65
|
+
log label, lObjects...
|
66
|
+
when 'objects'
|
67
|
+
log label, lObjects...
|
68
|
+
return
|
69
|
+
|
25
70
|
# ---------------------------------------------------------------------------
|
26
71
|
|
27
72
|
export debug = (label, lObjects...) ->
|
28
73
|
|
74
|
+
logif "enter debug(#{OL(label)})", lObjects...
|
75
|
+
|
29
76
|
assert isString(label), "1st arg #{OL(label)} should be a string"
|
30
77
|
|
31
78
|
# --- We want to allow objects to be undef. Therefore, we need to
|
@@ -34,9 +81,8 @@ export debug = (label, lObjects...) ->
|
|
34
81
|
|
35
82
|
# --- funcName is only set for types 'enter' and 'return'
|
36
83
|
[type, funcName] = getType(label, nObjects)
|
37
|
-
|
38
|
-
|
39
|
-
LOG "debug(): funcName = #{OL(funcName)}"
|
84
|
+
logif "type = #{OL(type)}"
|
85
|
+
logif "funcName = #{OL(funcName)}"
|
40
86
|
|
41
87
|
# --- function shouldLog() returns the (possibly modified) label
|
42
88
|
# if we should log this, else it returns undef
|
@@ -50,43 +96,43 @@ export debug = (label, lObjects...) ->
|
|
50
96
|
when 'string'
|
51
97
|
label = shouldLog(label, type, undef, callStack)
|
52
98
|
assert (nObjects == 0),
|
53
|
-
"
|
99
|
+
"Objects not allowed for #{OL(type)}"
|
54
100
|
when 'objects'
|
55
101
|
label = shouldLog(label, type, undef, callStack)
|
56
102
|
assert (nObjects > 0),
|
57
|
-
"
|
58
|
-
doLog = defined(label)
|
103
|
+
"Objects required for #{OL(type)}"
|
59
104
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
LOG "doLog = #{OL(doLog)}"
|
105
|
+
assert (label == undef) || isString(label),
|
106
|
+
"label not a string: #{OL(label)}"
|
107
|
+
doLog = defined(label)
|
108
|
+
logif "doLog = #{OL(doLog)}"
|
109
|
+
logif "#{nObjects} objects"
|
66
110
|
|
67
111
|
if doLog
|
68
112
|
level = callStack.getLevel()
|
69
113
|
prefix = getPrefix(level)
|
70
114
|
itemPrefix = removeLastVbar(prefix)
|
115
|
+
sep = dashes(itemPrefix, 40)
|
116
|
+
assert isString(sep), "sep is not a string"
|
71
117
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
118
|
+
logif "callStack", callStack
|
119
|
+
logif "level = #{OL(level)}"
|
120
|
+
logif "prefix = #{OL(prefix)}"
|
121
|
+
logif "itemPrefix = #{OL(itemPrefix)}"
|
122
|
+
logif "sep = #{OL(sep)}"
|
77
123
|
|
78
124
|
switch type
|
79
125
|
when 'enter'
|
80
126
|
log label, {prefix}
|
81
127
|
for obj,i in lObjects
|
82
128
|
if (i > 0)
|
83
|
-
log
|
129
|
+
log sep
|
84
130
|
logItem undef, obj, {itemPrefix}
|
85
131
|
when 'return'
|
86
132
|
log label, {prefix: addArrow(prefix)}
|
87
133
|
for obj,i in lObjects
|
88
134
|
if (i > 0)
|
89
|
-
log
|
135
|
+
log sep
|
90
136
|
logItem undef, obj, {itemPrefix}
|
91
137
|
when 'string'
|
92
138
|
log label, {prefix}
|
@@ -105,6 +151,7 @@ export debug = (label, lObjects...) ->
|
|
105
151
|
else if (type == 'return')
|
106
152
|
callStack.returnFrom funcName
|
107
153
|
|
154
|
+
logif "return from debug()"
|
108
155
|
return true # allow use in boolean expressions
|
109
156
|
|
110
157
|
# ---------------------------------------------------------------------------
|
@@ -125,10 +172,9 @@ export stdShouldLog = (label, type, funcName, stack) ->
|
|
125
172
|
assert funcName == undef, "func name #{OL(funcName)} not undef"
|
126
173
|
assert stack instanceof CallStack, "not a call stack object"
|
127
174
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
LOG "lFuncList", lFuncList
|
175
|
+
logif "stdShouldLog(#{OL(label)}, #{OL(type)}, #{OL(funcName)}, stack)"
|
176
|
+
logif "stack", stack
|
177
|
+
logif "lFuncList", lFuncList
|
132
178
|
|
133
179
|
switch type
|
134
180
|
when 'enter'
|
@@ -150,45 +196,19 @@ export stdShouldLog = (label, type, funcName, stack) ->
|
|
150
196
|
|
151
197
|
# ---------------------------------------------------------------------------
|
152
198
|
|
153
|
-
export debugDebug = (flag=true) ->
|
154
|
-
|
155
|
-
doDebugDebug = flag
|
156
|
-
if doDebugDebug
|
157
|
-
LOG "doDebugDebug = #{flag}"
|
158
|
-
return
|
159
|
-
|
160
|
-
# ---------------------------------------------------------------------------
|
161
|
-
|
162
|
-
resetDebugging = () ->
|
163
|
-
|
164
|
-
if doDebugDebug
|
165
|
-
LOG "resetDebugging()"
|
166
|
-
callStack.reset()
|
167
|
-
shouldLog = (label, type, funcName, stack) -> undef
|
168
|
-
return
|
169
|
-
|
170
|
-
# ---------------------------------------------------------------------------
|
171
|
-
|
172
199
|
export setDebugging = (option) ->
|
173
200
|
|
174
|
-
|
201
|
+
callStack.reset()
|
175
202
|
if isBoolean(option)
|
176
203
|
if option
|
177
204
|
shouldLog = (label, type, funcName, stack) -> label
|
178
205
|
else
|
179
206
|
shouldLog = (label, type, funcName, stack) -> undef
|
180
|
-
if doDebugDebug
|
181
|
-
LOG "setDebugging = #{option}"
|
182
207
|
else if isString(option)
|
183
208
|
lFuncList = getFuncList(option)
|
184
209
|
shouldLog = stdShouldLog
|
185
|
-
if doDebugDebug
|
186
|
-
LOG "setDebugging FUNCS: #{option}"
|
187
|
-
LOG 'lFuncList', lFuncList
|
188
210
|
else if isFunction(option)
|
189
211
|
shouldLog = option
|
190
|
-
if doDebugDebug
|
191
|
-
LOG "setDebugging to custom func"
|
192
212
|
else
|
193
213
|
croak "bad parameter #{OL(option)}"
|
194
214
|
return
|
@@ -232,22 +252,18 @@ export funcMatch = (stack, lFuncList) ->
|
|
232
252
|
assert isArray(lFuncList), "not an array #{OL(lFuncList)}"
|
233
253
|
|
234
254
|
curFunc = stack.curFunc()
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
LOG 'lFuncList', lFuncList
|
255
|
+
logif "funcMatch(): curFunc = #{OL(curFunc)}"
|
256
|
+
logif stack.dump(' ')
|
257
|
+
logif 'lFuncList', lFuncList
|
239
258
|
for h in lFuncList
|
240
259
|
{name, object, plus} = h
|
241
260
|
if (name == curFunc)
|
242
|
-
|
243
|
-
LOG " curFunc in lFuncList - match successful"
|
261
|
+
logif " curFunc in lFuncList - match successful"
|
244
262
|
return true
|
245
263
|
if plus && stack.isActive(name)
|
246
|
-
|
247
|
-
LOG " func #{OL(name)} is active - match successful"
|
264
|
+
logif " func #{OL(name)} is active - match successful"
|
248
265
|
return true
|
249
|
-
|
250
|
-
LOG " - no match"
|
266
|
+
logif " - no match"
|
251
267
|
return false
|
252
268
|
|
253
269
|
# ---------------------------------------------------------------------------
|
@@ -290,40 +306,3 @@ reMethod = ///^
|
|
290
306
|
|
291
307
|
# ---------------------------------------------------------------------------
|
292
308
|
|
293
|
-
export checkTrace = (block) ->
|
294
|
-
# --- export only to allow unit tests
|
295
|
-
|
296
|
-
lStack = []
|
297
|
-
|
298
|
-
for line in blockToArray(block)
|
299
|
-
if lMatches = line.match(///
|
300
|
-
enter
|
301
|
-
\s+
|
302
|
-
([A-Za-z_][A-Za-z0-9_\.]*)
|
303
|
-
///)
|
304
|
-
funcName = lMatches[1]
|
305
|
-
lStack.push funcName
|
306
|
-
else if lMatches = line.match(///
|
307
|
-
return
|
308
|
-
.*
|
309
|
-
from
|
310
|
-
\s+
|
311
|
-
([A-Za-z_][A-Za-z0-9_\.]*)
|
312
|
-
///)
|
313
|
-
funcName = lMatches[1]
|
314
|
-
len = lStack.length
|
315
|
-
if (len == 0)
|
316
|
-
log "return from #{funcName} with empty stack"
|
317
|
-
else if (lStack[len-1] == funcName)
|
318
|
-
lStack.pop()
|
319
|
-
else if (lStack[len-2] == funcName)
|
320
|
-
log "missing return from #{lStack[len-2]}"
|
321
|
-
lStack.pop()
|
322
|
-
lStack.pop()
|
323
|
-
else
|
324
|
-
log "return from #{funcName} - not found on stack"
|
325
|
-
return
|
326
|
-
|
327
|
-
# ---------------------------------------------------------------------------
|
328
|
-
|
329
|
-
resetDebugging()
|
package/src/debug_utils.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
|
-
// debug_utils.coffee
|
3
|
-
var callStack, doDebugDebug, reMethod,
|
2
|
+
// debug_utils.coffee
|
3
|
+
var callStack, doDebugDebug, lFunctions, logif, reMethod,
|
4
|
+
indexOf = [].indexOf;
|
4
5
|
|
5
6
|
import {
|
6
7
|
assert,
|
@@ -52,25 +53,76 @@ import {
|
|
52
53
|
|
53
54
|
callStack = new CallStack();
|
54
55
|
|
56
|
+
// --- set in resetDebugging() and setDebugging()
|
57
|
+
export var shouldLog = function() {
|
58
|
+
return undef;
|
59
|
+
};
|
60
|
+
|
61
|
+
export var lFuncList = [];
|
62
|
+
|
63
|
+
// --- internal debugging
|
55
64
|
doDebugDebug = false;
|
56
65
|
|
57
|
-
|
66
|
+
lFunctions = undef; // --- only used when doDebugDebug is true
|
58
67
|
|
59
|
-
|
68
|
+
|
69
|
+
// ---------------------------------------------------------------------------
|
70
|
+
export var setDebugDebugging = function(value = true) {
|
71
|
+
// --- value can be a boolean or string of words
|
72
|
+
if (isBoolean(value)) {
|
73
|
+
doDebugDebug = value;
|
74
|
+
} else if (isString(value)) {
|
75
|
+
doDebugDebug = true;
|
76
|
+
lFunctions = words(value);
|
77
|
+
} else {
|
78
|
+
croak(`Bad value: ${OL(value)}`);
|
79
|
+
}
|
80
|
+
};
|
81
|
+
|
82
|
+
// ---------------------------------------------------------------------------
|
83
|
+
logif = function(label, ...lObjects) {
|
84
|
+
var funcName, nObjects, type;
|
85
|
+
if (!doDebugDebug) {
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
assert(isString(label), `1st arg ${OL(label)} should be a string`);
|
89
|
+
nObjects = lObjects.length;
|
90
|
+
[type, funcName] = getType(label, nObjects);
|
91
|
+
switch (type) {
|
92
|
+
case 'enter':
|
93
|
+
if (defined(lFunctions) && (indexOf.call(lFunctions, funcName) < 0)) {
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
callStack.enter(funcName);
|
97
|
+
log(label, ...lObjects);
|
98
|
+
break;
|
99
|
+
case 'return':
|
100
|
+
if (defined(lFunctions) && (indexOf.call(lFunctions, funcName) < 0)) {
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
log(label, ...lObjects);
|
104
|
+
callStack.returnFrom(funcName);
|
105
|
+
break;
|
106
|
+
case 'string':
|
107
|
+
log(label, ...lObjects);
|
108
|
+
break;
|
109
|
+
case 'objects':
|
110
|
+
log(label, ...lObjects);
|
111
|
+
}
|
112
|
+
};
|
60
113
|
|
61
114
|
// ---------------------------------------------------------------------------
|
62
115
|
export var debug = function(label, ...lObjects) {
|
63
|
-
var doLog, funcName, i, itemPrefix, j, k, l, len1, len2,
|
116
|
+
var doLog, funcName, i, itemPrefix, j, k, l, len, len1, len2, level, nObjects, obj, prefix, sep, type;
|
117
|
+
logif(`enter debug(${OL(label)})`, ...lObjects);
|
64
118
|
assert(isString(label), `1st arg ${OL(label)} should be a string`);
|
65
119
|
// --- We want to allow objects to be undef. Therefore, we need to
|
66
120
|
// distinguish between 1 arg sent vs. 2 or more args sent
|
67
121
|
nObjects = lObjects.length;
|
68
122
|
// --- funcName is only set for types 'enter' and 'return'
|
69
123
|
[type, funcName] = getType(label, nObjects);
|
70
|
-
|
71
|
-
|
72
|
-
LOG(`debug(): funcName = ${OL(funcName)}`);
|
73
|
-
}
|
124
|
+
logif(`type = ${OL(type)}`);
|
125
|
+
logif(`funcName = ${OL(funcName)}`);
|
74
126
|
// --- function shouldLog() returns the (possibly modified) label
|
75
127
|
// if we should log this, else it returns undef
|
76
128
|
switch (type) {
|
@@ -83,38 +135,34 @@ export var debug = function(label, ...lObjects) {
|
|
83
135
|
break;
|
84
136
|
case 'string':
|
85
137
|
label = shouldLog(label, type, undef, callStack);
|
86
|
-
assert(nObjects === 0, `
|
138
|
+
assert(nObjects === 0, `Objects not allowed for ${OL(type)}`);
|
87
139
|
break;
|
88
140
|
case 'objects':
|
89
141
|
label = shouldLog(label, type, undef, callStack);
|
90
|
-
assert(nObjects > 0, `
|
142
|
+
assert(nObjects > 0, `Objects required for ${OL(type)}`);
|
91
143
|
}
|
144
|
+
assert((label === undef) || isString(label), `label not a string: ${OL(label)}`);
|
92
145
|
doLog = defined(label);
|
93
|
-
|
94
|
-
|
95
|
-
LOG(`debug(${OL(label)}) - 1 arg`);
|
96
|
-
} else {
|
97
|
-
LOG(`debug(${OL(label)}), ${nObjects} args`);
|
98
|
-
}
|
99
|
-
LOG(`doLog = ${OL(doLog)}`);
|
100
|
-
}
|
146
|
+
logif(`doLog = ${OL(doLog)}`);
|
147
|
+
logif(`${nObjects} objects`);
|
101
148
|
if (doLog) {
|
102
149
|
level = callStack.getLevel();
|
103
150
|
prefix = getPrefix(level);
|
104
151
|
itemPrefix = removeLastVbar(prefix);
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
}
|
152
|
+
sep = dashes(itemPrefix, 40);
|
153
|
+
assert(isString(sep), "sep is not a string");
|
154
|
+
logif("callStack", callStack);
|
155
|
+
logif(`level = ${OL(level)}`);
|
156
|
+
logif(`prefix = ${OL(prefix)}`);
|
157
|
+
logif(`itemPrefix = ${OL(itemPrefix)}`);
|
158
|
+
logif(`sep = ${OL(sep)}`);
|
111
159
|
switch (type) {
|
112
160
|
case 'enter':
|
113
161
|
log(label, {prefix});
|
114
|
-
for (i = j = 0,
|
162
|
+
for (i = j = 0, len = lObjects.length; j < len; i = ++j) {
|
115
163
|
obj = lObjects[i];
|
116
164
|
if (i > 0) {
|
117
|
-
log(
|
165
|
+
log(sep);
|
118
166
|
}
|
119
167
|
logItem(undef, obj, {itemPrefix});
|
120
168
|
}
|
@@ -123,10 +171,10 @@ export var debug = function(label, ...lObjects) {
|
|
123
171
|
log(label, {
|
124
172
|
prefix: addArrow(prefix)
|
125
173
|
});
|
126
|
-
for (i = k = 0,
|
174
|
+
for (i = k = 0, len1 = lObjects.length; k < len1; i = ++k) {
|
127
175
|
obj = lObjects[i];
|
128
176
|
if (i > 0) {
|
129
|
-
log(
|
177
|
+
log(sep);
|
130
178
|
}
|
131
179
|
logItem(undef, obj, {itemPrefix});
|
132
180
|
}
|
@@ -142,7 +190,7 @@ export var debug = function(label, ...lObjects) {
|
|
142
190
|
label += ':';
|
143
191
|
}
|
144
192
|
log(label, {prefix});
|
145
|
-
for (l = 0,
|
193
|
+
for (l = 0, len2 = lObjects.length; l < len2; l++) {
|
146
194
|
obj = lObjects[l];
|
147
195
|
logItem(undef, obj, {prefix});
|
148
196
|
}
|
@@ -154,6 +202,7 @@ export var debug = function(label, ...lObjects) {
|
|
154
202
|
} else if (type === 'return') {
|
155
203
|
callStack.returnFrom(funcName);
|
156
204
|
}
|
205
|
+
logif("return from debug()");
|
157
206
|
return true; // allow use in boolean expressions
|
158
207
|
};
|
159
208
|
|
@@ -175,11 +224,9 @@ export var stdShouldLog = function(label, type, funcName, stack) {
|
|
175
224
|
assert(funcName === undef, `func name ${OL(funcName)} not undef`);
|
176
225
|
}
|
177
226
|
assert(stack instanceof CallStack, "not a call stack object");
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
LOG("lFuncList", lFuncList);
|
182
|
-
}
|
227
|
+
logif(`stdShouldLog(${OL(label)}, ${OL(type)}, ${OL(funcName)}, stack)`);
|
228
|
+
logif("stack", stack);
|
229
|
+
logif("lFuncList", lFuncList);
|
183
230
|
switch (type) {
|
184
231
|
case 'enter':
|
185
232
|
if (funcMatch(stack, lFuncList)) {
|
@@ -202,28 +249,9 @@ export var stdShouldLog = function(label, type, funcName, stack) {
|
|
202
249
|
return undef;
|
203
250
|
};
|
204
251
|
|
205
|
-
// ---------------------------------------------------------------------------
|
206
|
-
export var debugDebug = function(flag = true) {
|
207
|
-
doDebugDebug = flag;
|
208
|
-
if (doDebugDebug) {
|
209
|
-
LOG(`doDebugDebug = ${flag}`);
|
210
|
-
}
|
211
|
-
};
|
212
|
-
|
213
|
-
// ---------------------------------------------------------------------------
|
214
|
-
resetDebugging = function() {
|
215
|
-
if (doDebugDebug) {
|
216
|
-
LOG("resetDebugging()");
|
217
|
-
}
|
218
|
-
callStack.reset();
|
219
|
-
shouldLog = function(label, type, funcName, stack) {
|
220
|
-
return undef;
|
221
|
-
};
|
222
|
-
};
|
223
|
-
|
224
252
|
// ---------------------------------------------------------------------------
|
225
253
|
export var setDebugging = function(option) {
|
226
|
-
|
254
|
+
callStack.reset();
|
227
255
|
if (isBoolean(option)) {
|
228
256
|
if (option) {
|
229
257
|
shouldLog = function(label, type, funcName, stack) {
|
@@ -234,21 +262,11 @@ export var setDebugging = function(option) {
|
|
234
262
|
return undef;
|
235
263
|
};
|
236
264
|
}
|
237
|
-
if (doDebugDebug) {
|
238
|
-
LOG(`setDebugging = ${option}`);
|
239
|
-
}
|
240
265
|
} else if (isString(option)) {
|
241
266
|
lFuncList = getFuncList(option);
|
242
267
|
shouldLog = stdShouldLog;
|
243
|
-
if (doDebugDebug) {
|
244
|
-
LOG(`setDebugging FUNCS: ${option}`);
|
245
|
-
LOG('lFuncList', lFuncList);
|
246
|
-
}
|
247
268
|
} else if (isFunction(option)) {
|
248
269
|
shouldLog = option;
|
249
|
-
if (doDebugDebug) {
|
250
|
-
LOG("setDebugging to custom func");
|
251
|
-
}
|
252
270
|
} else {
|
253
271
|
croak(`bad parameter ${OL(option)}`);
|
254
272
|
}
|
@@ -257,10 +275,10 @@ export var setDebugging = function(option) {
|
|
257
275
|
// ---------------------------------------------------------------------------
|
258
276
|
// --- export only to allow unit tests
|
259
277
|
export var getFuncList = function(str) {
|
260
|
-
var _, ident1, ident2, j, lMatches,
|
278
|
+
var _, ident1, ident2, j, lMatches, len, plus, ref, word;
|
261
279
|
lFuncList = [];
|
262
280
|
ref = words(str);
|
263
|
-
for (j = 0,
|
281
|
+
for (j = 0, len = ref.length; j < len; j++) {
|
264
282
|
word = ref[j];
|
265
283
|
if (lMatches = word.match(/^([A-Za-z_][A-Za-z0-9_]*)(?:\.([A-Za-z_][A-Za-z0-9_]*))?(\+)?$/)) {
|
266
284
|
[_, ident1, ident2, plus] = lMatches;
|
@@ -286,33 +304,25 @@ export var getFuncList = function(str) {
|
|
286
304
|
// ---------------------------------------------------------------------------
|
287
305
|
// --- export only to allow unit tests
|
288
306
|
export var funcMatch = function(stack, lFuncList) {
|
289
|
-
var curFunc, h, j,
|
307
|
+
var curFunc, h, j, len, name, object, plus;
|
290
308
|
assert(isArray(lFuncList), `not an array ${OL(lFuncList)}`);
|
291
309
|
curFunc = stack.curFunc();
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
}
|
297
|
-
for (j = 0, len1 = lFuncList.length; j < len1; j++) {
|
310
|
+
logif(`funcMatch(): curFunc = ${OL(curFunc)}`);
|
311
|
+
logif(stack.dump(' '));
|
312
|
+
logif('lFuncList', lFuncList);
|
313
|
+
for (j = 0, len = lFuncList.length; j < len; j++) {
|
298
314
|
h = lFuncList[j];
|
299
315
|
({name, object, plus} = h);
|
300
316
|
if (name === curFunc) {
|
301
|
-
|
302
|
-
LOG(" curFunc in lFuncList - match successful");
|
303
|
-
}
|
317
|
+
logif(" curFunc in lFuncList - match successful");
|
304
318
|
return true;
|
305
319
|
}
|
306
320
|
if (plus && stack.isActive(name)) {
|
307
|
-
|
308
|
-
LOG(` func ${OL(name)} is active - match successful`);
|
309
|
-
}
|
321
|
+
logif(` func ${OL(name)} is active - match successful`);
|
310
322
|
return true;
|
311
323
|
}
|
312
324
|
}
|
313
|
-
|
314
|
-
LOG(" - no match");
|
315
|
-
}
|
325
|
+
logif(" - no match");
|
316
326
|
return false;
|
317
327
|
};
|
318
328
|
|
@@ -336,33 +346,3 @@ export var getType = function(str, nObjects) {
|
|
336
346
|
reMethod = /^([A-Za-z_][A-Za-z0-9_]*)\.([A-Za-z_][A-Za-z0-9_]*)$/;
|
337
347
|
|
338
348
|
// ---------------------------------------------------------------------------
|
339
|
-
export var checkTrace = function(block) {
|
340
|
-
var funcName, j, lMatches, lStack, len, len1, line, ref;
|
341
|
-
// --- export only to allow unit tests
|
342
|
-
lStack = [];
|
343
|
-
ref = blockToArray(block);
|
344
|
-
for (j = 0, len1 = ref.length; j < len1; j++) {
|
345
|
-
line = ref[j];
|
346
|
-
if (lMatches = line.match(/enter\s+([A-Za-z_][A-Za-z0-9_\.]*)/)) {
|
347
|
-
funcName = lMatches[1];
|
348
|
-
lStack.push(funcName);
|
349
|
-
} else if (lMatches = line.match(/return.*from\s+([A-Za-z_][A-Za-z0-9_\.]*)/)) {
|
350
|
-
funcName = lMatches[1];
|
351
|
-
len = lStack.length;
|
352
|
-
if (len === 0) {
|
353
|
-
log(`return from ${funcName} with empty stack`);
|
354
|
-
} else if (lStack[len - 1] === funcName) {
|
355
|
-
lStack.pop();
|
356
|
-
} else if (lStack[len - 2] === funcName) {
|
357
|
-
log(`missing return from ${lStack[len - 2]}`);
|
358
|
-
lStack.pop();
|
359
|
-
lStack.pop();
|
360
|
-
} else {
|
361
|
-
log(`return from ${funcName} - not found on stack`);
|
362
|
-
}
|
363
|
-
}
|
364
|
-
}
|
365
|
-
};
|
366
|
-
|
367
|
-
// ---------------------------------------------------------------------------
|
368
|
-
resetDebugging();
|
package/src/log_utils.coffee
CHANGED
@@ -135,9 +135,9 @@ export log = (str, hOptions={}) ->
|
|
135
135
|
# --- valid options:
|
136
136
|
# prefix
|
137
137
|
|
138
|
+
assert isString(str), "log(): not a string: #{OL(str)}"
|
138
139
|
assert isFunction(putstr), "putstr not properly set"
|
139
|
-
assert
|
140
|
-
assert isHash(hOptions), "log(): arg 2 not a hash"
|
140
|
+
assert isHash(hOptions), "log(): arg 2 not a hash: #{OL(hOptions)}"
|
141
141
|
prefix = fixForTerminal(hOptions.prefix)
|
142
142
|
|
143
143
|
if doDebugLog
|
package/src/log_utils.js
CHANGED
@@ -158,9 +158,9 @@ export var log = function(str, hOptions = {}) {
|
|
158
158
|
var prefix;
|
159
159
|
// --- valid options:
|
160
160
|
// prefix
|
161
|
+
assert(isString(str), `log(): not a string: ${OL(str)}`);
|
161
162
|
assert(isFunction(putstr), "putstr not properly set");
|
162
|
-
assert(
|
163
|
-
assert(isHash(hOptions), "log(): arg 2 not a hash");
|
163
|
+
assert(isHash(hOptions), `log(): arg 2 not a hash: ${OL(hOptions)}`);
|
164
164
|
prefix = fixForTerminal(hOptions.prefix);
|
165
165
|
if (doDebugLog) {
|
166
166
|
LOG(`CALL log(${OL(str)}), prefix = ${OL(prefix)}`);
|