Repository: jerryscript-project/jerryscript
File: jerry-main/main-utils.c (C)

Code before:
            const jerry_value_t this_p, /**< this arg */
            const jerry_value_t args_p[], /**< function arguments */
            const jerry_length_t args_cnt) /**< number of function arguments */
{
  (void) func_obj_val; /* unused */
  (void) this_p; /* unused */
  (void) args_p; /* unused */
  (void) args_cnt; /* unused */

  jerry_gc (JERRY_GC_PRESSURE_LOW);
  return jerry_create_undefined ();
} /* test262_gc */

/**
 * Init the $262 object
 */
static void
register_test262 (void)
{
  jerry_value_t global_obj = jerry_get_global_object ();
  jerry_value_t test262_object = jerry_create_object ();

  test262_register_function (test262_object, "createRealm", test262_create_realm);
  test262_register_function (test262_object, "detachArrayBuffer", test262_detach_array_buffer);
  test262_register_function (test262_object, "evalScript", test262_eval_script);
  test262_register_function (test262_object, "gc", test262_gc);

  jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "global");
  jerry_set_property (test262_object, prop_name, global_obj);

  // register_report_error (result_val, "global");
  jerry_release_value (prop_name);

  prop_name = jerry_create_string ((const jerry_char_t *) "$262");
  jerry_set_property (global_obj, prop_name, test262_object);

  // register_report_error (result_val, "$262");
  jerry_release_value (prop_name);

  jerry_release_value (global_obj);
  jerry_release_value (test262_object);
} /* register_test262 */
#endif /* defined (JERRY_TEST262) && (JERRY_TEST262 == 1) */

/**
 * Inits the engine and the debugger
 */
void
main_init_engine (main_args_t *arguments_p) /** main arguments */
{
  jerry_init (arguments_p->init_flags);

Review comment (suggestion):
For the gc we already have a handler `jerryx_handler_gc`

Code after:
    {
      protocol = jerryx_debugger_tcp_create (arguments_p->debug_port);
    }
    else
    {
      assert (!strcmp (arguments_p->debug_protocol, "serial"));
      protocol = jerryx_debugger_serial_create (arguments_p->debug_serial_config);
    }

    if (!strcmp (arguments_p->debug_channel, "rawpacket"))
    {
      jerryx_debugger_after_connect (protocol && jerryx_debugger_rp_create ());
    }
    else
    {
      assert (!strcmp (arguments_p->debug_channel, "websocket"));
      jerryx_debugger_after_connect (protocol && jerryx_debugger_ws_create ());
    }
  }
  if (arguments_p->option_flags & OPT_FLAG_TEST262_OBJECT)
  {
    register_test262 ();
  }
  main_register_global_function ("assert", jerryx_handler_assert);
  main_register_global_function ("gc", jerryx_handler_gc);
  main_register_global_function ("print", jerryx_handler_print);
  main_register_global_function ("resourceName", jerryx_handler_resource_name);
} /* main_init_engine */

/**
 * Print an error value.
 *
 * Note: the error value will be released.
 */
void
main_print_unhandled_exception (jerry_value_t error_value) /**< error value */
{
  assert (jerry_value_is_error (error_value));
  error_value = jerry_get_value_from_error (error_value, true);

  jerry_char_t err_str_buf[256];

  jerry_value_t err_str_val = jerry_value_to_string (error_value);
  jerry_size_t err_str_size = jerry_get_utf8_string_size (err_str_val);

  if (err_str_size >= 256)
  {
    const char msg[] = "[Error message too long]";
    err_str_size = sizeof (msg) / sizeof (char) - 1;
    memcpy (err_str_buf, msg, err_str_size + 1);
  }