-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall-stack.js
More file actions
79 lines (61 loc) · 1.49 KB
/
Copy pathcall-stack.js
File metadata and controls
79 lines (61 loc) · 1.49 KB
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
module.exports = CallStack
var createBlockStack = require('./block-stack.js')
var unwrap = require('./lib/unwrap-all.js')
function CallStack() {
if (!(this instanceof CallStack)) {
return new CallStack()
}
this._current = null
}
var proto = CallStack.prototype
proto.pushFrame = function(func, thisValue, args, isNew, block) {
this._current = new Frame(unwrap(func), thisValue, args, isNew, block, this._current)
}
proto.popFrame = function() {
this._current = this._current.parent
}
proto.current = function() {
return this._current
}
proto.info = function() {
var out = []
var current = this._current
while(current && current._func) {
out.push(current._func._name)
current = current.parent
}
return out.join('/')
}
proto.isRecursion = function(fn) {
var current = this._current
fn = unwrap(fn)
while(current && current._func) {
if (current._func._code === fn._code) {
return current._fromBlock || true
}
current = current.parent
}
return false
}
function Frame(func, thisValue, args, isNew, fromBlock, parent) {
this._func = func
this._thisValue = thisValue
this._args = args
this._isNew = isNew
this._fromBlock = fromBlock
this._stack = createBlockStack()
this.parent = parent
}
var proto = Frame.prototype
proto.getThis = function() {
return this._thisValue
}
proto.getArguments = function() {
return this._args
}
proto.getStack = function() {
return this._stack
}
proto.getFunction = function() {
return this._func
}