Skip to content

Commit 37333e2

Browse files
committed
Print unhandled errors in REPL mode
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
1 parent 7b10f91 commit 37333e2

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

jerry-core/jerry.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,7 @@ jerry_api_convert_api_value_to_ecma_value (ecma_value_t *out_value_p, /**< [out]
515515
* Convert completion of 'eval' to API value and completion code
516516
*
517517
* Note:
518-
* if the output value contains string / object, it should be freed
519-
* with jerry_api_release_string / jerry_api_release_object,
520-
* just when it becomes unnecessary.
518+
* The value returned in 'retval_p' should be freed with jerry_api_release_value
521519
*
522520
* @return completion code
523521
*/
@@ -526,22 +524,9 @@ jerry_api_convert_eval_completion_to_retval (jerry_api_value_t *retval_p, /**< [
526524
ecma_value_t completion) /**< completion of 'eval'-mode
527525
* code execution */
528526
{
529-
jerry_completion_code_t ret_code;
530-
531-
if (!ecma_is_value_error (completion))
532-
{
533-
jerry_api_convert_ecma_value_to_api_value (retval_p, completion);
534-
535-
ret_code = JERRY_COMPLETION_CODE_OK;
536-
}
537-
else
538-
{
539-
jerry_api_convert_ecma_value_to_api_value (retval_p, ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED));
527+
jerry_api_convert_ecma_value_to_api_value (retval_p, completion);
540528

541-
ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;
542-
}
543-
544-
return ret_code;
529+
return (ecma_is_value_error (completion)) ? JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION : JERRY_COMPLETION_CODE_OK;
545530
} /* jerry_api_convert_eval_completion_to_retval */
546531

547532
/**

main-unix.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ main (int argc,
537537

538538
printf ("%s", prompt);
539539

540-
// input a line
540+
/* Read a line */
541541
while (true)
542542
{
543543
if (fread (source_buffer_tail, 1, 1, stdin) != 1 && len == 0)
@@ -556,23 +556,16 @@ main (int argc,
556556

557557
if (len > 0)
558558
{
559-
// evaluate the line
559+
/* Evaluate the line */
560560
jerry_api_value_t ret_val;
561561
ret_code = jerry_api_eval (buffer, len, false, false, &ret_val);
562562

563-
if (ret_code == JERRY_COMPLETION_CODE_OK)
563+
/* Print return value */
564+
const jerry_api_value_t args[] = { ret_val };
565+
jerry_api_value_t ret_val_print;
566+
if (jerry_api_call_function (print_function.u.v_object, NULL, &ret_val_print, args, 1))
564567
{
565-
// print return value
566-
const jerry_api_value_t args[] = {ret_val};
567-
jerry_api_value_t ret_val_print;
568-
if (jerry_api_call_function (print_function.u.v_object, NULL, &ret_val_print, args, 1))
569-
{
570-
jerry_api_release_value (&ret_val_print);
571-
}
572-
}
573-
else
574-
{
575-
printf ("JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION\n");
568+
jerry_api_release_value (&ret_val_print);
576569
}
577570

578571
jerry_api_release_value (&ret_val);

0 commit comments

Comments
 (0)