-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstack-generator-spec.js
More file actions
112 lines (96 loc) · 3.76 KB
/
Copy pathstack-generator-spec.js
File metadata and controls
112 lines (96 loc) · 3.76 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
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
describe('StackGenerator', function() {
describe('#backtrace', function() {
afterEach(function () {
window.onerror = null;
});
it('should generate backtrace for function declarations', function() {
var stackFrames = null;
function foo() {
bar('arg1', 42);
}
function bar() {
stackFrames = StackGenerator.backtrace();
}
foo();
expect(stackFrames).toBeTruthy();
expect(stackFrames[0].functionName).toBe('StackGenerator$$backtrace');
expect(stackFrames[0].args).toEqual([]);
expect(stackFrames[1].functionName).toBe('bar');
expect(stackFrames[1].args).toEqual(['arg1', 42]);
expect(stackFrames[2].functionName).toBe('foo');
expect(stackFrames[2].args).toEqual([]);
});
it('should generate backtrace for named function expressions', function() {
var stackFrames = null;
var foo = function foo() {
bar();
};
var bar = function bar() {
stackFrames = StackGenerator.backtrace();
};
foo();
expect(stackFrames).toBeTruthy();
expect(stackFrames[0].functionName).toBe('StackGenerator$$backtrace');
expect(stackFrames[0].args).toEqual([]);
expect(stackFrames[1].functionName).toBe('bar');
expect(stackFrames[1].args).toEqual([]);
expect(stackFrames[2].functionName).toBe('foo');
expect(stackFrames[2].args).toEqual([]);
});
it('should limit stack size given a max stack size', function() {
var stackFrames = null;
var foo = function foo() {
bar();
};
var bar = function() {
stackFrames = StackGenerator.backtrace({maxStackSize: 2});
};
foo();
expect(stackFrames).toBeTruthy();
expect(stackFrames.length).toBe(2);
});
it('should stop and not throw error when encountering a call to eval', function() {
var stackFrames = null;
var foo = function foo() {
eval('stackFrames = StackGenerator.backtrace({maxStackSize: 2});');
};
foo();
expect(stackFrames).toBeTruthy();
expect(stackFrames[0].functionName).toBe('StackGenerator$$backtrace');
});
it('should stop and not throw error when entering a strict-mode context', function() {
'use strict';
function _isStrictMode() {
return (eval('var __temp = null'), (typeof __temp === 'undefined'));
}
var stackFrames = null;
var foo = function() {
bar();
};
var bar = function bar() {
stackFrames = StackGenerator.backtrace({maxStackSize: 25});
};
foo();
expect(stackFrames).toBeTruthy();
if (_isStrictMode()) {
expect(stackFrames.length).toBe(1);
}
expect(stackFrames[0].functionName).toBe('StackGenerator$$backtrace');
});
it('should handle "null" callees', function(done) {
var errored = false;
window.onerror = function () {
try {
StackGenerator.backtrace();
} catch (e) {
errored = true;
}
expect(errored).toBe(false);
done();
};
var script = document.createElement('script');
script.src = '/base/spec/fixtures/a.js';
window.document.body.appendChild(script);
});
});
});