Skip to content

Commit 45cc6ec

Browse files
authored
feat: Tracekit test coverage and eval/empty frames fixes (getsentry#2075)
* test: Added original Tracekit tests from their repository * test: Update original Tracekit tests for our needs * ref: Correctly report eval and function-less frames in Tracekit * ref: Fixed linters for trackit tests
1 parent 9cedeee commit 45cc6ec

File tree

5 files changed

+1976
-197
lines changed

5 files changed

+1976
-197
lines changed

packages/browser/src/tracekit.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ interface ComputeStackTrace {
3838
* @param {(string|number)=} depth
3939
*/
4040
(ex: Error, depth?: string | number): StackTrace;
41-
_computeStackTraceFromStackProp(ex: any): StackTrace;
4241
}
4342

4443
/**
@@ -479,7 +478,7 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() {
479478
// gecko regex: `(?:bundle|\d+\.js)`: `bundle` is for react native, `\d+\.js` also but specifically for ram bundles because it
480479
// generates filenames without a prefix like `file://` the filenames in the stacktrace are just 42.js
481480
// We need this specific case for now because we want no other regex to match.
482-
gecko = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|moz-extension).*?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js))(?::(\d+))?(?::(\d+))?\s*$/i,
481+
gecko = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:file|https?|blob|chrome|webpack|resource|moz-extension).*?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js))(?::(\d+))?(?::(\d+))?\s*$/i,
483482
winjs = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
484483
// Used to additionally parse URL/line/column from eval frames
485484
isEval,
@@ -494,6 +493,7 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() {
494493

495494
for (var i = 0, j = lines.length; i < j; ++i) {
496495
if ((parts = chrome.exec(lines[i]))) {
496+
var isNative = parts[2] && parts[2].indexOf('native') === 0; // start of line
497497
isEval = parts[2] && parts[2].indexOf('eval') === 0; // start of line
498498
if (isEval && (submatch = chromeEval.exec(parts[2]))) {
499499
// throw out eval line/column and use top-most line/column number
@@ -504,7 +504,7 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() {
504504
element = {
505505
url: parts[2],
506506
func: parts[1] || UNKNOWN_FUNCTION,
507-
args: [],
507+
args: isNative ? [parts[2]] : [],
508508
line: parts[3] ? +parts[3] : null,
509509
column: parts[4] ? +parts[4] : null,
510510
};
@@ -520,6 +520,7 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() {
520520
isEval = parts[3] && parts[3].indexOf(' > eval') > -1;
521521
if (isEval && (submatch = geckoEval.exec(parts[3]))) {
522522
// throw out eval line/column and use top-most line number
523+
parts[1] = parts[1] || `eval`;
523524
parts[3] = submatch[1];
524525
parts[4] = submatch[2];
525526
parts[5] = ''; // no column when eval

packages/browser/test/tracekit.test.ts

-194
This file was deleted.

0 commit comments

Comments
 (0)