1
1
/*
2
2
* Functionality to generate error objects
3
3
*/
4
- function generateErrorObject ( err , context ) {
4
+ function generateErrorObject ( err , context ) {
5
5
// TODO: Pass context
6
- context = ( context !== undefined ) ? context : window ;
7
- const cleaned = cleanErrorStack ( err . stack )
6
+ context = context !== undefined ? context : window ;
7
+ const cleaned = cleanErrorStack ( err . stack ) ;
8
8
const stack = splitStack ( cleaned ) ;
9
9
const lineInfo = getLineInfo ( stack ) ;
10
10
const fileName = getFileName ( stack ) ;
11
- let fakeError ;
12
- try {
11
+ let fakeError : { lineNumber : any ; columnNumber : any } ;
12
+ try {
13
13
// fake type, message, filename, column and line
14
- const propertyName = "stack" ;
14
+ // const propertyName = "stack";
15
15
fakeError = new context . wrappedJSObject [ err . name ] ( err . message , fileName ) ;
16
16
fakeError . lineNumber = lineInfo . lineNumber ;
17
17
fakeError . columnNumber = lineInfo . columnNumber ;
18
- } catch ( error ) {
18
+ } catch ( error ) {
19
19
console . log ( "ERROR creation failed. Error was:" + error ) ;
20
20
}
21
21
return fakeError ;
@@ -26,10 +26,10 @@ function generateErrorObject(err, context){
26
26
*/
27
27
function cleanErrorStack ( stack ) {
28
28
const extensionID = browser . runtime . getURL ( "" ) ;
29
- const lines = ( typeof ( stack ) !== "string" ) ? stack : splitStack ( stack ) ;
30
- lines . forEach ( line => {
31
- if ( line . includes ( extensionID ) ) {
32
- stack = stack . replace ( line + "\n" , "" ) ;
29
+ const lines = typeof stack !== "string" ? stack : splitStack ( stack ) ;
30
+ lines . forEach ( ( line ) => {
31
+ if ( line . includes ( extensionID ) ) {
32
+ stack = stack . replace ( line + "\n" , "" ) ;
33
33
}
34
34
} ) ;
35
35
return stack ;
@@ -40,9 +40,9 @@ function cleanErrorStack(stack) {
40
40
*/
41
41
function getBeginOfScriptCalls ( stack ) {
42
42
const extensionID = browser . runtime . getURL ( "" ) ;
43
- const lines = ( typeof ( stack ) !== "string" ) ? stack : splitStack ( stack ) ;
44
- for ( let i = 0 ; i < lines . length ; i ++ ) {
45
- if ( ! lines [ i ] . includes ( extensionID ) ) {
43
+ const lines = typeof stack !== "string" ? stack : splitStack ( stack ) ;
44
+ for ( let i = 0 ; i < lines . length ; i ++ ) {
45
+ if ( ! lines [ i ] . includes ( extensionID ) ) {
46
46
return i ;
47
47
}
48
48
}
@@ -52,8 +52,10 @@ function getBeginOfScriptCalls(stack) {
52
52
/*
53
53
* Get the stack as array
54
54
*/
55
- function splitStack ( stack ) {
56
- return stack . split ( '\n' ) . map ( function ( line ) { return line . trim ( ) ; } ) ;
55
+ function splitStack ( stack ) {
56
+ return stack . split ( "\n" ) . map ( function ( line ) {
57
+ return line . trim ( ) ;
58
+ } ) ;
57
59
}
58
60
59
61
/*
@@ -64,15 +66,17 @@ function getLineInfo(stack) {
64
66
const firstLine = stack [ 0 ] ;
65
67
const matches = [ ...firstLine . matchAll ( ":" ) ] ;
66
68
const column = firstLine . slice (
67
- matches [ matches . length - 1 ] . index + 1 ,
68
- firstLine . length ) ;
69
+ matches [ matches . length - 1 ] . index + 1 ,
70
+ firstLine . length ,
71
+ ) ;
69
72
const line = firstLine . slice (
70
- matches [ matches . length - 2 ] . index + 1 ,
71
- matches [ matches . length - 1 ] . index ) ;
73
+ matches [ matches . length - 2 ] . index + 1 ,
74
+ matches [ matches . length - 1 ] . index ,
75
+ ) ;
72
76
return {
73
- " lineNumber" : line ,
74
- " columnNumber" : column
75
- }
77
+ lineNumber : line ,
78
+ columnNumber : column ,
79
+ } ;
76
80
}
77
81
78
82
/*
@@ -84,35 +88,34 @@ function getFileName(stack) {
84
88
const matches_at = [ ...firstLine . matchAll ( "@" ) ] ;
85
89
const matches_colon = [ ...firstLine . matchAll ( ":" ) ] ;
86
90
return firstLine . slice (
87
- matches_at [ matches_at . length - 1 ] . index + 1 ,
88
- matches_colon [ matches_colon . length - 2 ] . index
91
+ matches_at [ matches_at . length - 1 ] . index + 1 ,
92
+ matches_colon [ matches_colon . length - 2 ] . index ,
89
93
) ;
90
94
}
91
95
92
- function getOriginFromStackTrace ( err , includeStack ) {
93
- console . log ( err . stack ) ;
96
+ // function getOriginFromStackTrace(err, includeStack){
97
+ // console.log(err.stack);
94
98
95
- const stack = splitStack ( err . stack ) ;
96
- const lineInfo = getLineInfo ( stack ) ;
97
- const fileName = getFileName ( stack ) ;
98
-
99
- const callSite = stack [ 1 ] ;
100
- const callSiteParts = callSite . split ( "@" ) ;
101
- const funcName = callSiteParts [ 0 ] || "" ;
102
- const items = rsplit ( callSiteParts [ 1 ] , ":" , 2 ) ;
103
- const scriptFileName = items [ items . length - 3 ] || "" ;
99
+ // const stack = splitStack(err.stack);
100
+ // const lineInfo = getLineInfo(stack);
101
+ // const fileName = getFileName(stack);
104
102
105
- const callContext = {
106
- scriptUrl,
107
- scriptLine : lineInfo . lineNumber ,
108
- scriptCol : lineInfo . columnNumber ,
109
- funcName,
110
- scriptLocEval,
111
- callStack : includeStack ? trace . slice ( 3 ) . join ( "\n" ) . trim ( ) : "" ,
112
- } ;
103
+ // const callSite = stack[1];
104
+ // const callSiteParts = callSite.split("@");
105
+ // const funcName = callSiteParts[0] || "";
106
+ // const items = rsplit(callSiteParts[1], ":", 2);
107
+ // const scriptFileName = items[items.length - 3] || "";
113
108
114
- }
109
+ // const callContext = {
110
+ // scriptUrl,
111
+ // scriptLine: lineInfo.lineNumber,
112
+ // scriptCol: lineInfo.columnNumber,
113
+ // funcName,
114
+ // scriptLocEval,
115
+ // callStack: includeStack ? trace.slice(3).join("\n").trim() : "",
116
+ // };
115
117
118
+ // }
116
119
117
120
// Helper to get originating script urls
118
121
// Legacy code
@@ -128,5 +131,4 @@ function getStackTrace() {
128
131
return stack ;
129
132
}
130
133
131
-
132
- export { generateErrorObject , getBeginOfScriptCalls , getStackTrace } ;
134
+ export { generateErrorObject , getBeginOfScriptCalls , getStackTrace } ;
0 commit comments