Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions jerry-core/jerry.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,7 @@ jerry_api_convert_api_value_to_ecma_value (ecma_value_t *out_value_p, /**< [out]
* Convert completion of 'eval' to API value and completion code
*
* Note:
* if the output value contains string / object, it should be freed
* with jerry_api_release_string / jerry_api_release_object,
* just when it becomes unnecessary.
* The value returned in 'retval_p' should be freed with jerry_api_release_value
*
* @return completion code
*/
Expand All @@ -526,22 +524,9 @@ jerry_api_convert_eval_completion_to_retval (jerry_api_value_t *retval_p, /**< [
ecma_value_t completion) /**< completion of 'eval'-mode
* code execution */
{
jerry_completion_code_t ret_code;

if (!ecma_is_value_error (completion))
{
jerry_api_convert_ecma_value_to_api_value (retval_p, completion);

ret_code = JERRY_COMPLETION_CODE_OK;
}
else
{
jerry_api_convert_ecma_value_to_api_value (retval_p, ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED));
jerry_api_convert_ecma_value_to_api_value (retval_p, completion);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this function is being touched, it would be nice to update its doc comment. The "Note:" part could better be referring to jerry_api_release_value.

Another stylistic suggestion: the below 10 lines could be written in a single line...

return !ecma_is_value_error (completion) ? JERRY_COMPLETION_CODE_OK : JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;

Much cleaner. (And still within the 120 chars-per-line limit.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akiss77, +1

If it is too long, then write like this:

return !ecma_is_value_error (completion) ? JERRY_COMPLETION_CODE_OK
                                         : JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;


ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;
}

return ret_code;
return (ecma_is_value_error (completion)) ? JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION : JERRY_COMPLETION_CODE_OK;
} /* jerry_api_convert_eval_completion_to_retval */

/**
Expand Down
21 changes: 7 additions & 14 deletions main-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ main (int argc,

printf ("%s", prompt);

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

if (len > 0)
{
// evaluate the line
/* Evaluate the line */
jerry_api_value_t ret_val;
ret_code = jerry_api_eval (buffer, len, false, false, &ret_val);

if (ret_code == JERRY_COMPLETION_CODE_OK)
/* Print return value */
const jerry_api_value_t args[] = { ret_val };
jerry_api_value_t ret_val_print;
if (jerry_api_call_function (print_function.u.v_object, NULL, &ret_val_print, args, 1))
{
// print return value
const jerry_api_value_t args[] = {ret_val};
jerry_api_value_t ret_val_print;
if (jerry_api_call_function (print_function.u.v_object, NULL, &ret_val_print, args, 1))
{
jerry_api_release_value (&ret_val_print);
}
}
else
{
printf ("JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION\n");
jerry_api_release_value (&ret_val_print);
}

jerry_api_release_value (&ret_val);
Expand Down