@@ -150,8 +150,7 @@ str_to_uint (const char *num_str_p) /**< string to convert */
150150 * Print error value
151151 */
152152static void
153- print_unhandled_exception (jerry_value_t error_value , /**< error value */
154- const jerry_char_t * source_p ) /**< source_p */
153+ print_unhandled_exception (jerry_value_t error_value ) /**< error value */
155154{
156155 assert (jerry_value_is_error (error_value ));
157156
@@ -179,40 +178,46 @@ print_unhandled_exception (jerry_value_t error_value, /**< error value */
179178 {
180179 uint32_t err_line = 0 ;
181180 uint32_t err_col = 0 ;
181+ char * path_str_p = NULL ;
182+ size_t path_str_end = 0 ;
182183
183184 /* 1. parse column and line information */
184185 for (uint32_t i = 0 ; i < sz ; i ++ )
185186 {
186- if (! strncmp (( char * ) ( err_str_buf + i ), "[line: " , 7 ) )
187+ if (err_str_buf [ i ] == '[' )
187188 {
188- i += 7 ;
189+ i ++ ;
189190
190- char num_str [8 ];
191- uint32_t j = 0 ;
191+ if (err_str_buf [i ] == '<' )
192+ {
193+ break ;
194+ }
192195
193- while (i < sz && err_str_buf [i ] != ',' )
196+ path_str_p = (char * ) (err_str_buf + i );
197+ while (i < sz && err_str_buf [i ] != ':' )
194198 {
195- num_str [j ] = (char ) err_str_buf [i ];
196- j ++ ;
197199 i ++ ;
198200 }
199- num_str [j ] = '\0' ;
200201
201- err_line = str_to_uint ( num_str ) ;
202+ path_str_end = i ++ ;
202203
203- if (strncmp ((char * ) (err_str_buf + i ), ", column: " , 10 ))
204+ char num_str [8 ];
205+ uint32_t j = 0 ;
206+
207+ while (i < sz && err_str_buf [i ] != ':' )
204208 {
205- break ; /* wrong position info format */
209+ num_str [ j ++ ] = ( char ) err_str_buf [ i ++ ];
206210 }
211+ num_str [j ] = '\0' ;
207212
208- i += 10 ;
213+ err_line = str_to_uint (num_str );
214+
215+ i ++ ;
209216 j = 0 ;
210217
211218 while (i < sz && err_str_buf [i ] != ']' )
212219 {
213- num_str [j ] = (char ) err_str_buf [i ];
214- j ++ ;
215- i ++ ;
220+ num_str [j ++ ] = (char ) err_str_buf [i ++ ];
216221 }
217222 num_str [j ] = '\0' ;
218223
@@ -228,6 +233,15 @@ print_unhandled_exception (jerry_value_t error_value, /**< error value */
228233 bool is_printing_context = false;
229234 uint32_t pos = 0 ;
230235
236+ /* Temporarily modify the error message, so we can use the path. */
237+ err_str_buf [path_str_end ] = '\0' ;
238+
239+ size_t source_size ;
240+ const jerry_char_t * source_p = read_file (path_str_p , & source_size );
241+
242+ /* Revert the error message. */
243+ err_str_buf [path_str_end ] = ':' ;
244+
231245 /* 2. seek and print */
232246 while (source_p [pos ] != '\0' )
233247 {
@@ -419,6 +433,7 @@ int jerry_main (int argc, char *argv[])
419433 source_p ,
420434 source_size ,
421435 JERRY_PARSE_NO_OPTS );
436+ free ((void * ) source_p );
422437
423438 if (!jerry_value_is_error (ret_value ))
424439 {
@@ -429,14 +444,10 @@ int jerry_main (int argc, char *argv[])
429444
430445 if (jerry_value_is_error (ret_value ))
431446 {
432- print_unhandled_exception (ret_value , source_p );
433- free ((void * ) source_p );
434-
447+ print_unhandled_exception (ret_value );
435448 break ;
436449 }
437450
438- free ((void * ) source_p );
439-
440451 jerry_release_value (ret_value );
441452 ret_value = jerry_create_undefined ();
442453 }
0 commit comments