11/*
22 * Functionality to generate error objects
33 */
4- function generateErrorObject ( err , context ) {
4+ function generateErrorObject ( err , context ) {
55 // 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 ) ;
88 const stack = splitStack ( cleaned ) ;
99 const lineInfo = getLineInfo ( stack ) ;
1010 const fileName = getFileName ( stack ) ;
11- let fakeError ;
12- try {
11+ let fakeError : { lineNumber : any ; columnNumber : any } ;
12+ try {
1313 // fake type, message, filename, column and line
14- const propertyName = "stack" ;
14+ // const propertyName = "stack";
1515 fakeError = new context . wrappedJSObject [ err . name ] ( err . message , fileName ) ;
1616 fakeError . lineNumber = lineInfo . lineNumber ;
1717 fakeError . columnNumber = lineInfo . columnNumber ;
18- } catch ( error ) {
18+ } catch ( error ) {
1919 console . log ( "ERROR creation failed. Error was:" + error ) ;
2020 }
2121 return fakeError ;
@@ -26,10 +26,10 @@ function generateErrorObject(err, context){
2626 */
2727function cleanErrorStack ( stack ) {
2828 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" , "" ) ;
3333 }
3434 } ) ;
3535 return stack ;
@@ -40,9 +40,9 @@ function cleanErrorStack(stack) {
4040 */
4141function getBeginOfScriptCalls ( stack ) {
4242 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 ) ) {
4646 return i ;
4747 }
4848 }
@@ -52,8 +52,10 @@ function getBeginOfScriptCalls(stack) {
5252/*
5353 * Get the stack as array
5454 */
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+ } ) ;
5759}
5860
5961/*
@@ -64,15 +66,17 @@ function getLineInfo(stack) {
6466 const firstLine = stack [ 0 ] ;
6567 const matches = [ ...firstLine . matchAll ( ":" ) ] ;
6668 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+ ) ;
6972 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+ ) ;
7276 return {
73- " lineNumber" : line ,
74- " columnNumber" : column
75- }
77+ lineNumber : line ,
78+ columnNumber : column ,
79+ } ;
7680}
7781
7882/*
@@ -84,35 +88,34 @@ function getFileName(stack) {
8488 const matches_at = [ ...firstLine . matchAll ( "@" ) ] ;
8589 const matches_colon = [ ...firstLine . matchAll ( ":" ) ] ;
8690 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 ,
8993 ) ;
9094}
9195
92- function getOriginFromStackTrace ( err , includeStack ) {
93- console . log ( err . stack ) ;
96+ // function getOriginFromStackTrace(err, includeStack){
97+ // console.log(err.stack);
9498
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);
104102
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] || "";
113108
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+ // };
115117
118+ // }
116119
117120// Helper to get originating script urls
118121// Legacy code
@@ -128,5 +131,4 @@ function getStackTrace() {
128131 return stack ;
129132}
130133
131-
132- export { generateErrorObject , getBeginOfScriptCalls , getStackTrace } ;
134+ export { generateErrorObject , getBeginOfScriptCalls , getStackTrace } ;
0 commit comments