@@ -335,8 +335,13 @@ function cloneCallSite(frame) {
335
335
return object ;
336
336
}
337
337
338
- function wrapCallSite ( frame ) {
338
+ function wrapCallSite ( frame , state ) {
339
+ // provides interface backward compatibility
340
+ if ( state === undefined ) {
341
+ state = { nextPosition : null , curPosition : null }
342
+ }
339
343
if ( frame . isNative ( ) ) {
344
+ state . curPosition = null ;
340
345
return frame ;
341
346
}
342
347
@@ -360,9 +365,15 @@ function wrapCallSite(frame) {
360
365
line : line ,
361
366
column : column
362
367
} ) ;
368
+ state . curPosition = position ;
363
369
frame = cloneCallSite ( frame ) ;
364
370
var originalFunctionName = frame . getFunctionName ;
365
- frame . getFunctionName = function ( ) { return position . name || originalFunctionName ( ) ; } ;
371
+ frame . getFunctionName = function ( ) {
372
+ if ( state . nextPosition === null ) {
373
+ return originalFunctionName ( ) ;
374
+ }
375
+ return state . nextPosition . name || originalFunctionName ( ) ;
376
+ } ;
366
377
frame . getFileName = function ( ) { return position . source ; } ;
367
378
frame . getLineNumber = function ( ) { return position . line ; } ;
368
379
frame . getColumnNumber = function ( ) { return position . column + 1 ; } ;
@@ -395,9 +406,14 @@ function prepareStackTrace(error, stack) {
395
406
var message = error . message || '' ;
396
407
var errorString = name + ": " + message ;
397
408
398
- return errorString + stack . map ( function ( frame ) {
399
- return '\n at ' + wrapCallSite ( frame ) ;
400
- } ) . join ( '' ) ;
409
+ var state = { nextPosition : null , curPosition : null } ;
410
+ var processedStack = [ ] ;
411
+ for ( var i = stack . length - 1 ; i >= 0 ; i -- ) {
412
+ processedStack . push ( '\n at ' + wrapCallSite ( stack [ i ] , state ) ) ;
413
+ state . nextPosition = state . curPosition ;
414
+ }
415
+ state . curPosition = state . nextPosition = null ;
416
+ return errorString + processedStack . reverse ( ) . join ( '' ) ;
401
417
}
402
418
403
419
// Generate position and snippet of original source with pointer
@@ -561,7 +577,7 @@ exports.resetRetrieveHandlers = function() {
561
577
562
578
retrieveFileHandlers = originalRetrieveFileHandlers . slice ( 0 ) ;
563
579
retrieveMapHandlers = originalRetrieveMapHandlers . slice ( 0 ) ;
564
-
580
+
565
581
retrieveSourceMap = handlerExec ( retrieveMapHandlers ) ;
566
582
retrieveFile = handlerExec ( retrieveFileHandlers ) ;
567
583
}
0 commit comments