From acd08c96dd6c2e6f3dcf3f7016e2ab1241e0ddcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yves=20G=C3=A9rardy?= Date: Thu, 30 Nov 2017 22:37:16 +0100 Subject: [PATCH] Make the stack trace cleaner IE9 compatible (err.stack is null) --- ospec/ospec.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ospec/ospec.js b/ospec/ospec.js index 1c7cb94c..4ab57ab3 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -9,7 +9,7 @@ else window.o = m() if (name != null) spec[name] = ctx = {} try {throw new Error} catch (e) { - var ospecFileName = e.stack.match(/[\/\\](.*?):\d+:\d+/)[1] + var ospecFileName = e.stack && (/[\/\\](.*?):\d+:\d+/).test(e.stack) ? e.stack.match(/[\/\\](.*?):\d+:\d+/)[1] : null } function o(subject, predicate) { if (predicate === undefined) { @@ -55,6 +55,8 @@ else window.o = m() return spy } o.cleanStackTrace = function(error) { + // For IE 10+ in quirks mode, and IE 9- in any mode, errors don't have a stack + if (error.stack == null) return "" var i = 0, header = error.message ? error.name + ": " + error.message : error.name, stack // some environments add the name and message to the stack trace if (error.stack.indexOf(header) === 0) { @@ -63,6 +65,7 @@ else window.o = m() } else { stack = error.stack.split(/\r?\n/) } + if (ospecFileName == null) return stack.join("\n") // skip ospec-related entries on the stack while (stack[i].indexOf(ospecFileName) !== -1) i++ // now we're in user code