Skip to content

Commit 0b8d587

Browse files
committed
provide stack traces for browsers which don't have captureStackTrace
1 parent 5b09737 commit 0b8d587

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

assert.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ assert.AssertionError = function AssertionError(options) {
5858
if (Error.captureStackTrace) {
5959
Error.captureStackTrace(this, stackStartFunction);
6060
}
61+
else {
62+
// non v8 browsers so we can have a stacktrace
63+
var err = new Error();
64+
if (err.stack) {
65+
var out = err.stack;
66+
67+
// try to strip useless frames
68+
var fn_name = stackStartFunction.name;
69+
var idx = out.indexOf('\n' + fn_name);
70+
if (idx >= 0) {
71+
// once we have located the function frame
72+
// we need to strip out everything before it (and its line)
73+
var next_line = out.indexOf('\n', idx + 1);
74+
out = out.substring(next_line + 1);
75+
}
76+
77+
this.stack = out;
78+
}
79+
}
6180
};
6281

6382
// assert.AssertionError instanceof Error

0 commit comments

Comments
 (0)