Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
feat: add stackFramesFilter to longStackTraceZone
Browse files Browse the repository at this point in the history
  • Loading branch information
btford committed May 7, 2014
1 parent 39b1513 commit 7133de0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
25 changes: 17 additions & 8 deletions long-stack-trace-zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ Zone.Stacktrace = function (e) {
this._e = e;
};
Zone.Stacktrace.prototype.get = function () {
var frames = this._e.stack.split('\n');

var markerIndex;
for (var markerIndex = frames.length - 1; markerIndex >= 0; markerIndex -= 1) {
if (frames[markerIndex].indexOf('marker@') === 0) {
return frames.slice(markerIndex+1).join('\n');
}
if (zone.stackFramesFilter) {
return this._e.stack.
split('\n').
filter(zone.stackFramesFilter).
join('\n');
}
return this._e.stack;
}
Expand Down Expand Up @@ -46,8 +44,15 @@ Zone.getStacktrace = function () {

Zone.longStackTraceZone = {
getLongStacktrace: function (exception) {
var trace = [exception.stack];
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(
Expand All @@ -59,6 +64,10 @@ Zone.longStackTraceZone = {
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());
Expand Down
18 changes: 18 additions & 0 deletions test/long-stack-trace-zone.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,22 @@ describe('Zone.patch', function () {
expect(log[0]).toBe('Error: hello');
expect(log[1].split('--- ').length).toBe(4);
});


it('should filter based on stackFramesFilter', function () {
lstz.fork({
stackFramesFilter: function (line) {
return line.indexOf('jasmine.js') === -1;
}
}).run(function () {
setTimeout(function () {
setTimeout(function () {
throw new Error('hello');
}, 0);
}, 0);
});

jasmine.Clock.tick(0);
expect(log[1]).not.toContain('jasmine.js');
});
});

0 comments on commit 7133de0

Please sign in to comment.