@jdeighan/coffee-utils 6.0.4 → 6.0.7
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/call_stack.coffee +27 -4
- package/src/call_stack.js +34 -6
- package/src/log_utils.coffee +2 -0
- package/src/log_utils.js +3 -0
package/package.json
CHANGED
package/src/call_stack.coffee
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
# call_stack.coffee
|
2
2
|
|
3
|
-
import {undef, croak} from '@jdeighan/coffee-utils'
|
3
|
+
import {undef, croak, assert} from '@jdeighan/coffee-utils'
|
4
4
|
import {log, LOG} from '@jdeighan/coffee-utils/log'
|
5
5
|
|
6
|
+
doDebugStack = false
|
7
|
+
|
8
|
+
# ---------------------------------------------------------------------------
|
9
|
+
|
10
|
+
export debugStack = (flag=true) ->
|
11
|
+
|
12
|
+
doDebugStack = flag
|
13
|
+
return
|
14
|
+
|
6
15
|
# ---------------------------------------------------------------------------
|
7
16
|
|
8
17
|
export class CallStack
|
@@ -15,6 +24,9 @@ export class CallStack
|
|
15
24
|
|
16
25
|
call: (funcName, hInfo) ->
|
17
26
|
|
27
|
+
if doDebugStack
|
28
|
+
prefix = ' '.repeat(@lStack.length)
|
29
|
+
LOG "#{prefix}[> CALL #{funcName}]"
|
18
30
|
@lStack.push({funcName, hInfo})
|
19
31
|
return
|
20
32
|
|
@@ -26,15 +38,26 @@ export class CallStack
|
|
26
38
|
LOG "returnFrom('#{fName}') but stack is empty"
|
27
39
|
return undef
|
28
40
|
{funcName, hInfo} = @lStack.pop()
|
29
|
-
|
41
|
+
while (funcName != fName) && (@lStack.length > 0)
|
42
|
+
LOG "[MISSING RETURN FROM #{funcName} (return from #{fName})]"
|
43
|
+
{funcName, hInfo} = @lStack.pop()
|
44
|
+
|
45
|
+
if doDebugStack
|
46
|
+
prefix = ' '.repeat(@lStack.length)
|
47
|
+
LOG "#{prefix}[< BACK #{fName}]"
|
48
|
+
if (funcName == fName)
|
49
|
+
return hInfo
|
50
|
+
else
|
30
51
|
@dump()
|
31
|
-
LOG "returnFrom('#{fName}')
|
32
|
-
|
52
|
+
LOG "BAD returnFrom('#{fName}')"
|
53
|
+
return undef
|
33
54
|
|
34
55
|
# ........................................................................
|
35
56
|
|
36
57
|
reset: () ->
|
37
58
|
|
59
|
+
if doDebugStack
|
60
|
+
LOG "RESET STACK"
|
38
61
|
@lStack = []
|
39
62
|
|
40
63
|
# ........................................................................
|
package/src/call_stack.js
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
// Generated by CoffeeScript 2.6.1
|
2
|
-
|
2
|
+
// call_stack.coffee
|
3
|
+
var doDebugStack;
|
4
|
+
|
3
5
|
import {
|
4
6
|
undef,
|
5
|
-
croak
|
7
|
+
croak,
|
8
|
+
assert
|
6
9
|
} from '@jdeighan/coffee-utils';
|
7
10
|
|
8
11
|
import {
|
@@ -10,6 +13,13 @@ import {
|
|
10
13
|
LOG
|
11
14
|
} from '@jdeighan/coffee-utils/log';
|
12
15
|
|
16
|
+
doDebugStack = false;
|
17
|
+
|
18
|
+
// ---------------------------------------------------------------------------
|
19
|
+
export var debugStack = function(flag = true) {
|
20
|
+
doDebugStack = flag;
|
21
|
+
};
|
22
|
+
|
13
23
|
// ---------------------------------------------------------------------------
|
14
24
|
export var CallStack = class CallStack {
|
15
25
|
constructor() {
|
@@ -18,26 +28,44 @@ export var CallStack = class CallStack {
|
|
18
28
|
|
19
29
|
// ........................................................................
|
20
30
|
call(funcName, hInfo) {
|
31
|
+
var prefix;
|
32
|
+
if (doDebugStack) {
|
33
|
+
prefix = ' '.repeat(this.lStack.length);
|
34
|
+
LOG(`${prefix}[> CALL ${funcName}]`);
|
35
|
+
}
|
21
36
|
this.lStack.push({funcName, hInfo});
|
22
37
|
}
|
23
38
|
|
24
39
|
// ........................................................................
|
25
40
|
returnFrom(fName) {
|
26
|
-
var funcName, hInfo;
|
41
|
+
var funcName, hInfo, prefix;
|
27
42
|
if (this.lStack.length === 0) {
|
28
43
|
LOG(`returnFrom('${fName}') but stack is empty`);
|
29
44
|
return undef;
|
30
45
|
}
|
31
46
|
({funcName, hInfo} = this.lStack.pop());
|
32
|
-
|
47
|
+
while ((funcName !== fName) && (this.lStack.length > 0)) {
|
48
|
+
LOG(`[MISSING RETURN FROM ${funcName} (return from ${fName})]`);
|
49
|
+
({funcName, hInfo} = this.lStack.pop());
|
50
|
+
}
|
51
|
+
if (doDebugStack) {
|
52
|
+
prefix = ' '.repeat(this.lStack.length);
|
53
|
+
LOG(`${prefix}[< BACK ${fName}]`);
|
54
|
+
}
|
55
|
+
if (funcName === fName) {
|
56
|
+
return hInfo;
|
57
|
+
} else {
|
33
58
|
this.dump();
|
34
|
-
LOG(`returnFrom('${fName}')
|
59
|
+
LOG(`BAD returnFrom('${fName}')`);
|
60
|
+
return undef;
|
35
61
|
}
|
36
|
-
return hInfo;
|
37
62
|
}
|
38
63
|
|
39
64
|
// ........................................................................
|
40
65
|
reset() {
|
66
|
+
if (doDebugStack) {
|
67
|
+
LOG("RESET STACK");
|
68
|
+
}
|
41
69
|
return this.lStack = [];
|
42
70
|
}
|
43
71
|
|
package/src/log_utils.coffee
CHANGED
package/src/log_utils.js
CHANGED