Repository: jerryscript-project/jerryscript
File: jerry-core/api/jerry.c (C)

Code before:
  JERRY_UNUSED (parse_opts);

  return jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG (error_parser_not_supported_p)));
#endif /* JERRY_PARSER */
} /* jerry_parse_function */

/**
 * Run an EcmaScript function created by jerry_parse.
 *
 * Note:
 *      returned value must be freed with jerry_release_value, when it is no longer needed.
 *
 * @return result of bytecode - if run was successful
 *         thrown error - otherwise
 */
jerry_value_t
jerry_run (const jerry_value_t func_val) /**< function to run */
{
  jerry_assert_api_available ();

  if (!ecma_is_value_object (func_val))
  {
    return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (wrong_args_msg_p)));
  }

  ecma_object_t *object_p = ecma_get_object_from_value (func_val);

  if (ecma_get_object_type (object_p) != ECMA_OBJECT_TYPE_CLASS)
  {
    return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (wrong_args_msg_p)));
  }

  ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;

#if JERRY_MODULE_SYSTEM
  if (ext_object_p->u.class_prop.class_id == LIT_MAGIC_STRING_MODULE_UL)
  {
    ecma_module_t *root_module_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_module_t, ext_object_p->u.class_prop.u.value);

#if JERRY_BUILTIN_REALMS
    ecma_object_t *global_object_p = (ecma_object_t *) ecma_op_function_get_realm (root_module_p->compiled_code_p);
#else /* !JERRY_BUILTIN_REALMS */
    ecma_object_t *global_object_p = ecma_builtin_get_global ();
#endif /* JERRY_BUILTIN_REALMS */

    ecma_create_global_lexical_block (global_object_p);
    root_module_p->scope_p = ecma_get_global_scope (global_object_p);

    return jerry_return (vm_run_module (root_module_p));
  }
#endif /* JERRY_MODULE_SYSTEM */

Review comment (suggestion):
I'd also update the doc of this function here and in the API doc a bit, since we no longer title script/modules functions anymore.

`Run an EcmaScript function created by jerry_parse` -> `Run a script/module created by jerry_parse`
`/**< function to run */` -> /**< script/module to run */



Code after:
  JERRY_UNUSED (parse_opts);

  return jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG (error_parser_not_supported_p)));
#endif /* JERRY_PARSER */
} /* jerry_parse_function */

/**
 * Run a Script or Module created by jerry_parse.
 *
 * Note:
 *      returned value must be freed with jerry_release_value, when it is no longer needed.
 *
 * @return result of bytecode - if run was successful
 *         thrown error - otherwise
 */
jerry_value_t
jerry_run (const jerry_value_t func_val) /**< function to run */
{
  jerry_assert_api_available ();

  if (!ecma_is_value_object (func_val))
  {
    return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (wrong_args_msg_p)));
  }

  ecma_object_t *object_p = ecma_get_object_from_value (func_val);

  if (ecma_get_object_type (object_p) != ECMA_OBJECT_TYPE_CLASS)
  {
    return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (wrong_args_msg_p)));
  }

  ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;

#if JERRY_MODULE_SYSTEM
  if (ext_object_p->u.class_prop.class_id == LIT_MAGIC_STRING_MODULE_UL)
  {
    ecma_module_t *root_module_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_module_t, ext_object_p->u.class_prop.u.value);

#if JERRY_BUILTIN_REALMS
    ecma_object_t *global_object_p = (ecma_object_t *) ecma_op_function_get_realm (root_module_p->compiled_code_p);
#else /* !JERRY_BUILTIN_REALMS */
    ecma_object_t *global_object_p = ecma_builtin_get_global ();
#endif /* JERRY_BUILTIN_REALMS */

    ecma_create_global_lexical_block (global_object_p);
    root_module_p->scope_p = ecma_get_global_scope (global_object_p);

    return jerry_return (vm_run_module (root_module_p));
  }
#endif /* JERRY_MODULE_SYSTEM */