@@ -80,46 +80,42 @@ export class Evaluator {
8080 return this . evalBlock ( ast , blockContext ) ;
8181 }
8282
83- private invokeFunction ( func : ( ...args : unknown [ ] ) => unknown , fps : unknown [ ] ,
84- loc : { moduleName : string , line : number , column : number } ) : unknown {
85- try {
86- if ( fps . length === 0 ) { return func ( ) ; }
87- if ( fps . length === 1 ) { return func ( fps [ 0 ] ) ; }
88- if ( fps . length === 2 ) { return func ( fps [ 0 ] , fps [ 1 ] ) ; }
89- if ( fps . length === 3 ) { return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] ) ; }
90- if ( fps . length === 4 ) {
91- return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] ) ;
92- }
93- if ( fps . length === 5 ) {
94- return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] ) ;
95- }
83+ private invokeFunction ( func : ( ...args : unknown [ ] ) => unknown , fps : unknown [ ] ,
84+ loc : { moduleName : string , line : number , column : number } ) : unknown {
85+
86+ if ( fps . length === 0 ) { return func ( ) ; }
87+ if ( fps . length === 1 ) { return func ( fps [ 0 ] ) ; }
88+ if ( fps . length === 2 ) { return func ( fps [ 0 ] , fps [ 1 ] ) ; }
89+ if ( fps . length === 3 ) { return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] ) ; }
90+ if ( fps . length === 4 ) {
91+ return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] ) ;
92+ }
93+ if ( fps . length === 5 ) {
94+ return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] ) ;
95+ }
9696
97- if ( fps . length === 6 ) {
98- return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] , fps [ 5 ] ) ;
99- }
97+ if ( fps . length === 6 ) {
98+ return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] , fps [ 5 ] ) ;
99+ }
100100
101- if ( fps . length === 7 ) {
102- return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] , fps [ 5 ] , fps [ 6 ] ) ;
103- }
101+ if ( fps . length === 7 ) {
102+ return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] , fps [ 5 ] , fps [ 6 ] ) ;
103+ }
104104
105- if ( fps . length === 8 ) {
106- return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] , fps [ 5 ] , fps [ 6 ] , fps [ 7 ] ) ;
107- }
105+ if ( fps . length === 8 ) {
106+ return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] , fps [ 5 ] , fps [ 6 ] , fps [ 7 ] ) ;
107+ }
108108
109- if ( fps . length === 9 ) {
110- return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] , fps [ 5 ] , fps [ 6 ] , fps [ 7 ] , fps [ 8 ] ) ;
111- }
109+ if ( fps . length === 9 ) {
110+ return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] , fps [ 5 ] , fps [ 6 ] , fps [ 7 ] , fps [ 8 ] ) ;
111+ }
112112
113- if ( fps . length === 10 ) {
114- return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] , fps [ 5 ] , fps [ 6 ] , fps [ 7 ] , fps [ 8 ] , fps [ 9 ] ) ;
115- }
113+ if ( fps . length === 10 ) {
114+ return func ( fps [ 0 ] , fps [ 1 ] , fps [ 2 ] , fps [ 3 ] , fps [ 4 ] , fps [ 5 ] , fps [ 6 ] , fps [ 7 ] , fps [ 8 ] , fps [ 9 ] ) ;
115+ }
116116
117- if ( fps . length > 10 ) {
118- throw Error ( 'Function has too many parameters. Current limitation is 10' ) ;
119- }
120- } catch ( err ) {
121- var jspyError = new JspyError ( loc ?. moduleName || 'js-func-error.jspy' , loc ?. line || 0 , loc ?. column || 0 , 'FuncCall' , err . message || err ) ;
122- throw jspyError ;
117+ if ( fps . length > 10 ) {
118+ throw Error ( 'Function has too many parameters. Current limitation is 10' ) ;
123119 }
124120
125121 }
@@ -161,23 +157,18 @@ export class Evaluator {
161157 }
162158 }
163159 catch ( err ) {
164- if ( err instanceof JspyEvalError ) {
165- // evaluation error should not be handled
166- throw err ;
167- } else {
168- const name = ( err instanceof JspyError ) ? ( err as JspyError ) . name : typeof ( err ) ;
169- const message = ( err instanceof JspyError ) ? ( err as JspyError ) . message : err ?? err . message ;
170- const moduleName = ( err instanceof JspyError ) ? ( err as JspyError ) . module : 0 ;
171- const line = ( err instanceof JspyError ) ? ( err as JspyError ) . line : 0 ;
172- const column = ( err instanceof JspyError ) ? ( err as JspyError ) . column : 0 ;
173-
174- const firstExept = tryNode . exepts [ 0 ] ;
175- const catchBody = firstExept . body ;
176- const ctx = blockContext ; // cloneContext(blockContext);
177- ctx . blockScope . set ( firstExept . error ?. alias || "error" , { name, message, line, column, moduleName } )
178- this . evalBlock ( { name : blockContext . moduleName , type : 'trycatch' , body : catchBody } as AstBlock , ctx ) ;
179- ctx . blockScope . set ( firstExept . error ?. alias || "error" , null )
180- }
160+ const name = ( err instanceof JspyError ) ? ( err as JspyError ) . name : typeof ( err ) ;
161+ const message = ( err instanceof JspyError ) ? ( err as JspyError ) . message : err ?. message ?? String ( err ) ;
162+ const moduleName = ( err instanceof JspyError ) ? ( err as JspyError ) . module : 0 ;
163+ const line = ( err instanceof JspyError ) ? ( err as JspyError ) . line : 0 ;
164+ const column = ( err instanceof JspyError ) ? ( err as JspyError ) . column : 0 ;
165+
166+ const firstExept = tryNode . exepts [ 0 ] ;
167+ const catchBody = firstExept . body ;
168+ const ctx = blockContext ; // cloneContext(blockContext);
169+ ctx . blockScope . set ( firstExept . error ?. alias || "error" , { name, message, line, column, moduleName } )
170+ this . evalBlock ( { name : blockContext . moduleName , type : 'trycatch' , body : catchBody } as AstBlock , ctx ) ;
171+ ctx . blockScope . set ( firstExept . error ?. alias || "error" , null )
181172 }
182173 finally {
183174 if ( tryNode . finallyBody ?. length || 0 > 0 ) {
0 commit comments