2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2015-03-23 22:07:33 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
2015-03-20 15:43:51 +00:00
|
|
|
* @providesModule parseErrorStack
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var stacktraceParser = require('stacktrace-parser');
|
|
|
|
|
|
|
|
function resolveSourceMaps(sourceMapInstance, stackFrame) {
|
|
|
|
try {
|
|
|
|
var orig = sourceMapInstance.originalPositionFor({
|
|
|
|
line: stackFrame.lineNumber,
|
|
|
|
column: stackFrame.column,
|
|
|
|
});
|
|
|
|
if (orig) {
|
|
|
|
stackFrame.file = orig.source;
|
|
|
|
stackFrame.lineNumber = orig.line;
|
|
|
|
stackFrame.column = orig.column;
|
|
|
|
}
|
|
|
|
} catch (innerEx) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-20 15:43:51 +00:00
|
|
|
function parseErrorStack(e, sourceMapInstance) {
|
2015-06-22 17:08:20 +00:00
|
|
|
if (!e || !e.stack) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2015-08-17 09:05:29 +00:00
|
|
|
var stack = Array.isArray(e.stack) ? e.stack : stacktraceParser.parse(e.stack);
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
var framesToPop = e.framesToPop || 0;
|
|
|
|
while (framesToPop--) {
|
|
|
|
stack.shift();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sourceMapInstance) {
|
|
|
|
stack.forEach(resolveSourceMaps.bind(null, sourceMapInstance));
|
|
|
|
}
|
|
|
|
|
2015-03-20 15:43:51 +00:00
|
|
|
return stack;
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 15:43:51 +00:00
|
|
|
module.exports = parseErrorStack;
|