diff --git a/source-map-support.js b/source-map-support.js index 794fa51..9e686cc 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -335,8 +335,13 @@ function cloneCallSite(frame) { return object; } -function wrapCallSite(frame) { +function wrapCallSite(frame, state) { + // provides interface backward compatibility + if (state === undefined) { + state = { nextPosition: null, curPosition: null } + } if(frame.isNative()) { + state.curPosition = null; return frame; } @@ -360,9 +365,15 @@ function wrapCallSite(frame) { line: line, column: column }); + state.curPosition = position; frame = cloneCallSite(frame); var originalFunctionName = frame.getFunctionName; - frame.getFunctionName = function() { return position.name || originalFunctionName(); }; + frame.getFunctionName = function() { + if (state.nextPosition === null) { + return originalFunctionName(); + } + return state.nextPosition.name || originalFunctionName(); + }; frame.getFileName = function() { return position.source; }; frame.getLineNumber = function() { return position.line; }; frame.getColumnNumber = function() { return position.column + 1; }; @@ -395,9 +406,14 @@ function prepareStackTrace(error, stack) { var message = error.message || ''; var errorString = name + ": " + message; - return errorString + stack.map(function(frame) { - return '\n at ' + wrapCallSite(frame); - }).join(''); + var state = { nextPosition: null, curPosition: null }; + var processedStack = []; + for (var i = stack.length - 1; i >= 0; i--) { + processedStack.push('\n at ' + wrapCallSite(stack[i], state)); + state.nextPosition = state.curPosition; + } + state.curPosition = state.nextPosition = null; + return errorString + processedStack.reverse().join(''); } // Generate position and snippet of original source with pointer @@ -561,7 +577,7 @@ exports.resetRetrieveHandlers = function() { retrieveFileHandlers = originalRetrieveFileHandlers.slice(0); retrieveMapHandlers = originalRetrieveMapHandlers.slice(0); - + retrieveSourceMap = handlerExec(retrieveMapHandlers); retrieveFile = handlerExec(retrieveFileHandlers); } diff --git a/test.js b/test.js index a1d32cf..6219b7c 100644 --- a/test.js +++ b/test.js @@ -331,7 +331,12 @@ it('maps original name from source', function() { generated: { line: 2, column: 8 }, original: { line: 1000, column: 10 }, source: '.original.js', - name: 'myOriginalName' + }); + sourceMap.addMapping({ + generated: { line: 4, column: 0 }, + original: { line: 1002, column: 1 }, + source: ".original.js", + name: "myOriginalName" }); compareStackTrace(sourceMap, [ 'function foo() {', @@ -341,7 +346,7 @@ it('maps original name from source', function() { ], [ 'Error: test', /^ at myOriginalName \((?:.*[/\\])?\.original.js:1000:11\)$/, - /^ at Object\.exports\.test \((?:.*[/\\])?\.generated.js:4:1\)$/ + /^ at Object\.exports\.test \((?:.*[/\\])?\.original.js:1002:2\)$/ ]); });