Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/builtin-objects/ecma-builtin-symbol-prototype.c (C)

Code before:
 */

/**
 * Dispatcher of the Symbol built-in's routines
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_builtin_symbol_prototype_dispatch_routine (uint16_t builtin_routine_id, /**< built-in wide routine
                                                                     *   identifier */
                                                ecma_value_t this_arg, /**< 'this' argument value */
                                                const ecma_value_t arguments_list[], /**< list of arguments
                                                                             *   passed to routine */
                                                ecma_length_t arguments_number) /**< length of arguments' list */
{
  JERRY_UNUSED_2 (arguments_list, arguments_number);

  ecma_value_t sym = ecma_symbol_this_value (this_arg);

  if (builtin_routine_id < ECMA_SYMBOL_PROTOTYPE_TO_STRING)
  {
    return ecma_copy_value (sym);
  }

  if (ECMA_IS_VALUE_ERROR (sym))
  {
    return sym;
  }

  if (builtin_routine_id == ECMA_SYMBOL_PROTOTYPE_TO_STRING)
  {
    return ecma_get_symbol_descriptive_string (sym);
  }

  JERRY_ASSERT (builtin_routine_id == ECMA_SYMBOL_PROTOTYPE_DESCRIPTION);
  ecma_string_t *symbol_p = ecma_get_symbol_from_value (sym);
  ecma_string_t *desc_p = ecma_get_symbol_description (symbol_p);
  ecma_ref_ecma_string (desc_p);
  return ecma_make_string_value (desc_p);
} /* ecma_builtin_symbol_prototype_dispatch_routine */

/**
 * @}
 * @}
 * @}
 */

#endif /* ENABLED (JERRY_ESNEXT) */


Review comment (suggestion):
This check should be before `if (builtin_routine_id < ECMA_SYMBOL_PROTOTYPE_TO_STRING)`

Code after:
 */

/**
 * Dispatcher of the Symbol built-in's routines
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_builtin_symbol_prototype_dispatch_routine (uint16_t builtin_routine_id, /**< built-in wide routine
                                                                     *   identifier */
                                                ecma_value_t this_arg, /**< 'this' argument value */
                                                const ecma_value_t arguments_list[], /**< list of arguments
                                                                             *   passed to routine */
                                                ecma_length_t arguments_number) /**< length of arguments' list */
{
  JERRY_UNUSED_2 (arguments_list, arguments_number);

  ecma_value_t sym = ecma_symbol_this_value (this_arg);

  if (ECMA_IS_VALUE_ERROR (sym))
  {
    return sym;
  }

  if (builtin_routine_id < ECMA_SYMBOL_PROTOTYPE_TO_STRING)
  {
    return ecma_copy_value (sym);
  }

  if (builtin_routine_id == ECMA_SYMBOL_PROTOTYPE_TO_STRING)
  {
    return ecma_get_symbol_descriptive_string (sym);
  }

  JERRY_ASSERT (builtin_routine_id == ECMA_SYMBOL_PROTOTYPE_DESCRIPTION);
  ecma_string_t *symbol_p = ecma_get_symbol_from_value (sym);
  ecma_string_t *desc_p = ecma_get_symbol_description (symbol_p);
  ecma_ref_ecma_string (desc_p);

  return ecma_make_string_value (desc_p);
} /* ecma_builtin_symbol_prototype_dispatch_routine */

/**
 * @}
 * @}
 * @}
 */

#endif /* ENABLED (JERRY_ESNEXT) */