Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/operations/ecma-function-object.c (C)

Code before:
  ecma_object_t *global_object_p = ecma_builtin_get_global ();

#if ENABLED (JERRY_BUILTIN_REALMS)
  JERRY_ASSERT (global_object_p == (ecma_object_t *) ecma_op_function_get_realm (bytecode_p));
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */

  ecma_object_t *global_env_p = ecma_get_global_environment (global_object_p);
  ecma_builtin_id_t fallback_proto = ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE;

#if ENABLED (JERRY_ESNEXT)
  ecma_object_t *new_target_p = JERRY_CONTEXT (current_new_target_p);

  if (JERRY_UNLIKELY (parse_opts & (ECMA_PARSE_GENERATOR_FUNCTION | ECMA_PARSE_ASYNC_FUNCTION)))
  {
    fallback_proto = ECMA_BUILTIN_ID_GENERATOR;

    if (parse_opts & ECMA_PARSE_ASYNC_FUNCTION && !(parse_opts & ECMA_PARSE_GENERATOR_FUNCTION))
    {
      fallback_proto = ECMA_BUILTIN_ID_ASYNC_FUNCTION_PROTOTYPE;

      if (new_target_p == NULL)
      {
        new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_ASYNC_FUNCTION);
      }
    }
    else if (parse_opts & ECMA_PARSE_ASYNC_FUNCTION)
    {
      fallback_proto = ECMA_BUILTIN_ID_ASYNC_GENERATOR;

      if (new_target_p == NULL)
      {
        new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_ASYNC_GENERATOR_FUNCTION);
      }
    }
    else if (new_target_p == NULL)
    {
      new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_GENERATOR_FUNCTION);
    }
  }
  else if (new_target_p == NULL)
  {
    new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION);
  }

  ecma_object_t *proto = ecma_op_get_prototype_from_constructor (new_target_p, fallback_proto);

  if (JERRY_UNLIKELY (proto == NULL))
  {
    ecma_bytecode_deref (bytecode_p);
    return ECMA_VALUE_ERROR;
  }

Review comment (suggestion):
I would put the above block inside the if, so no need to check `(parse_opts & ECMA_PARSE_ASYNC_FUNCTION)` twice

Code after:
  ecma_object_t *global_object_p = ecma_builtin_get_global ();

#if ENABLED (JERRY_BUILTIN_REALMS)
  JERRY_ASSERT (global_object_p == (ecma_object_t *) ecma_op_function_get_realm (bytecode_p));
#endif /* ENABLED (JERRY_BUILTIN_REALMS) */

  ecma_object_t *global_env_p = ecma_get_global_environment (global_object_p);
  ecma_builtin_id_t fallback_proto = ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE;

#if ENABLED (JERRY_ESNEXT)
  ecma_object_t *new_target_p = JERRY_CONTEXT (current_new_target_p);
  ecma_builtin_id_t fallback_ctor = ECMA_BUILTIN_ID_FUNCTION;

  if (JERRY_UNLIKELY (parse_opts & (ECMA_PARSE_GENERATOR_FUNCTION | ECMA_PARSE_ASYNC_FUNCTION)))
  {
    fallback_proto = ECMA_BUILTIN_ID_ASYNC_GENERATOR;
    fallback_ctor = ECMA_BUILTIN_ID_ASYNC_GENERATOR_FUNCTION;

    if (!(parse_opts & ECMA_PARSE_GENERATOR_FUNCTION))
    {
      fallback_proto = ECMA_BUILTIN_ID_ASYNC_FUNCTION_PROTOTYPE;
      fallback_ctor = ECMA_BUILTIN_ID_ASYNC_FUNCTION;
    }
    else if (!(parse_opts & ECMA_PARSE_ASYNC_FUNCTION))
    {
      fallback_proto = ECMA_BUILTIN_ID_GENERATOR;
      fallback_ctor = ECMA_BUILTIN_ID_GENERATOR_FUNCTION;
    }
  }

  if (new_target_p == NULL)
  {
    new_target_p = ecma_builtin_get (fallback_ctor);
  }

  ecma_object_t *proto = ecma_op_get_prototype_from_constructor (new_target_p, fallback_proto);

  if (JERRY_UNLIKELY (proto == NULL))
  {
    ecma_bytecode_deref (bytecode_p);
    return ECMA_VALUE_ERROR;
  }
#endif /* ENABLED (JERRY_ESNEXT) */

  ecma_object_t *func_obj_p = ecma_op_create_function_object (global_env_p, bytecode_p, fallback_proto);

#if ENABLED (JERRY_ESNEXT)
  ECMA_SET_NON_NULL_POINTER (func_obj_p->u2.prototype_cp, proto);
  ecma_deref_object (proto);
#endif /* ENABLED (JERRY_ESNEXT) */