-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlong-stack-trace-zone.js
86 lines (77 loc) · 2.24 KB
/
long-stack-trace-zone.js
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
/*
* Wrapped stacktrace
*
* We need this because in some implementations, constructing a trace is slow
* and so we want to defer accessing the trace for as long as possible
*/
Zone.Stacktrace = function (e) {
this._e = e;
};
Zone.Stacktrace.prototype.get = function () {
if (zone.stackFramesFilter) {
return this._e.stack.
split('\n').
filter(zone.stackFramesFilter).
join('\n');
}
return this._e.stack;
}
Zone.getStacktrace = function () {
function getStacktraceWithUncaughtError () {
return new Zone.Stacktrace(new Error());
}
function getStacktraceWithCaughtError () {
try {
throw new Error();
} catch (e) {
return new Zone.Stacktrace(e);
}
}
// Some implementations of exception handling don't create a stack trace if the exception
// isn't thrown, however it's faster not to actually throw the exception.
var stack = getStacktraceWithUncaughtError();
if (stack && stack._e.stack) {
Zone.getStacktrace = getStacktraceWithUncaughtError;
return stack;
} else {
Zone.getStacktrace = getStacktraceWithCaughtError;
return Zone.getStacktrace();
}
};
Zone.longStackTraceZone = {
getLongStacktrace: function (exception) {
var trace = [];
var zone = this;
if (zone.stackFramesFilter) {
trace.push(exception.stack.split('\n').
filter(zone.stackFramesFilter).
join('\n'));
} else {
trace.push(exception.stack);
}
var now = Date.now();
while (zone && zone.constructedAtException) {
trace.push(
'--- ' + (Date(zone.constructedAtTime)).toString() +
' - ' + (now - zone.constructedAtTime) + 'ms ago',
zone.constructedAtException.get());
zone = zone.parent;
}
return trace.join('\n');
},
stackFramesFilter: function (line) {
return line.indexOf('zone.js') === -1;
},
onError: function (exception) {
var reporter = this.reporter || console.log.bind(console);
reporter(exception.toString());
reporter(this.getLongStacktrace(exception));
},
fork: function (locals) {
var newZone = this._fork(locals);
newZone.constructedAtException = Zone.getStacktrace();
newZone.constructedAtTime = Date.now();
return newZone;
},
_fork: zone.fork
};