From 8cde1fdcddffe4efd719113f7794b7d7a1c82d31 Mon Sep 17 00:00:00 2001 From: Roman Shtylman Date: Sat, 28 Dec 2013 21:38:32 -0500 Subject: [PATCH] provide stack traces for browsers which don't have captureStackTrace --- assert.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/assert.js b/assert.js index 97cd8db..40a3a85 100644 --- a/assert.js +++ b/assert.js @@ -58,6 +58,23 @@ assert.AssertionError = function AssertionError(options) { if (Error.captureStackTrace) { Error.captureStackTrace(this, stackStartFunction); } + else { + // non v8 browsers so we can have a stacktrace + var err = new Error(); + if (err.stack) { + var out = err.stack; + + // try to strip useless frames + var fn_name = stackStartFunction.name; + var idx = out.indexOf('\n' + fn_name); + if (idx >= 0) { + idx = out.indexOf('\n', idx + 1); + out = out.substring(idx + 1); + } + + this.stack = out; + } + } }; // assert.AssertionError instanceof Error