2015-01-30 04:10:49 +03:00
|
|
|
/**
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-03-24 01:07:33 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-01-30 04:10:49 +03:00
|
|
|
*
|
2018-05-11 05:06:46 +03:00
|
|
|
* @format
|
2020-07-22 19:43:45 +03:00
|
|
|
* @flow strict
|
2015-01-30 04:10:49 +03:00
|
|
|
*/
|
2018-05-11 05:06:46 +03:00
|
|
|
|
2015-01-30 04:10:49 +03:00
|
|
|
'use strict';
|
|
|
|
|
2019-05-22 23:04:35 +03:00
|
|
|
import type {StackFrame} from '../NativeExceptionsManager';
|
2019-12-02 17:00:09 +03:00
|
|
|
import type {HermesParsedStack} from './parseHermesStack';
|
|
|
|
|
|
|
|
const parseHermesStack = require('./parseHermesStack');
|
2015-01-30 04:10:49 +03:00
|
|
|
|
2019-12-02 17:00:09 +03:00
|
|
|
function convertHermesStack(stack: HermesParsedStack): Array<StackFrame> {
|
|
|
|
const frames = [];
|
|
|
|
for (const entry of stack.entries) {
|
|
|
|
if (entry.type !== 'FRAME') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const {location, functionName} = entry;
|
|
|
|
if (location.type === 'NATIVE') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
frames.push({
|
|
|
|
methodName: functionName,
|
|
|
|
file: location.sourceUrl,
|
|
|
|
lineNumber: location.line1Based,
|
|
|
|
column:
|
|
|
|
location.type === 'SOURCE'
|
|
|
|
? location.column1Based - 1
|
|
|
|
: location.virtualOffset0Based,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return frames;
|
|
|
|
}
|
|
|
|
|
2020-07-27 23:56:14 +03:00
|
|
|
function parseErrorStack(errorStack?: string): Array<StackFrame> {
|
|
|
|
if (errorStack == null) {
|
2015-06-22 20:08:20 +03:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2017-06-14 19:16:26 +03:00
|
|
|
const stacktraceParser = require('stacktrace-parser');
|
2020-07-27 23:56:14 +03:00
|
|
|
const parsedStack = Array.isArray(errorStack)
|
|
|
|
? errorStack
|
2019-12-02 17:00:09 +03:00
|
|
|
: global.HermesInternal
|
2020-07-27 23:56:14 +03:00
|
|
|
? convertHermesStack(parseHermesStack(errorStack))
|
|
|
|
: stacktraceParser.parse(errorStack).map(frame => ({
|
2019-12-02 17:00:09 +03:00
|
|
|
...frame,
|
|
|
|
column: frame.column != null ? frame.column - 1 : null,
|
|
|
|
}));
|
2015-01-30 04:10:49 +03:00
|
|
|
|
2020-07-27 23:56:14 +03:00
|
|
|
return parsedStack;
|
2015-01-30 04:10:49 +03:00
|
|
|
}
|
|
|
|
|
2015-03-20 18:43:51 +03:00
|
|
|
module.exports = parseErrorStack;
|