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

Code before:
  JERRY_ASSERT (symbol_p != NULL);
  JERRY_ASSERT (ecma_prop_name_is_symbol (symbol_p));

  return ((ecma_extended_string_t *) symbol_p)->u.symbol_descriptor;
} /* ecma_get_symbol_description */

/**
 * Get the descriptive string of the Symbol.
 *
 * See also: ECMA-262 v6, 19.4.3.2.1
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_get_symbol_descriptive_string (ecma_value_t symbol_value) /**< symbol to stringify */
{
  /* 1. */
  JERRY_ASSERT (ecma_is_value_symbol (symbol_value));

  /* 2 - 3. */
  ecma_string_t *symbol_p = ecma_get_symbol_from_value (symbol_value);
  ecma_value_t string_desc = ecma_get_symbol_description (symbol_p);
  ecma_stringbuilder_t builder = ecma_stringbuilder_create_raw ((lit_utf8_byte_t *) ("Symbol("), 7);

  if (ecma_is_value_undefined (string_desc))
  {
    ecma_stringbuilder_append_byte (&builder, LIT_CHAR_RIGHT_PAREN);
    return ecma_make_string_value (ecma_stringbuilder_finalize (&builder));
  }

  ecma_string_t *string_desc_p = ecma_get_string_from_value (string_desc);
  /* 5. */
  ecma_stringbuilder_append (&builder, string_desc_p);
  ecma_stringbuilder_append_byte (&builder, LIT_CHAR_RIGHT_PAREN);

  return ecma_make_string_value (ecma_stringbuilder_finalize (&builder));
} /* ecma_get_symbol_descriptive_string */

/**
 * thisSymbolValue abstract operation
 *
 * See also:
 *          ECMA-262 v11, 19.4.3
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_symbol_this_value (ecma_value_t this_arg) /**< this argument value */
{

Review comment (refactor):
Do not duplicate this part.

```c
ecma_stringbuilder_t builder = ecma_stringbuilder_create_raw ((lit_utf8_byte_t *) ("Symbol("), 7);

if (ecma_is_value_undefined (string_desc))
{
  ecma_string_t *string_desc_p = ecma_get_string_from_value (string_desc);
  ecma_stringbuilder_append (&builder, string_desc_p);
}

ecma_stringbuilder_append_byte (&builder, LIT_CHAR_RIGHT_PAREN);
return ecma_make_string_value (ecma_stringbuilder_finalize (&builder));
```

Code after:
  JERRY_ASSERT (symbol_p != NULL);
  JERRY_ASSERT (ecma_prop_name_is_symbol (symbol_p));

  return ((ecma_extended_string_t *) symbol_p)->u.symbol_descriptor;
} /* ecma_get_symbol_description */

/**
 * Get the descriptive string of the Symbol.
 *
 * See also: ECMA-262 v6, 19.4.3.2.1
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_get_symbol_descriptive_string (ecma_value_t symbol_value) /**< symbol to stringify */
{
  /* 1. */
  JERRY_ASSERT (ecma_is_value_symbol (symbol_value));

  /* 2 - 3. */
  ecma_string_t *symbol_p = ecma_get_symbol_from_value (symbol_value);
  ecma_value_t string_desc = ecma_get_symbol_description (symbol_p);
  ecma_stringbuilder_t builder = ecma_stringbuilder_create_raw ((lit_utf8_byte_t *) ("Symbol("), 7);

  if (!ecma_is_value_undefined (string_desc))
  {
    ecma_string_t *string_desc_p = ecma_get_string_from_value (string_desc);
    ecma_stringbuilder_append (&builder, string_desc_p);
  }

  ecma_stringbuilder_append_byte (&builder, LIT_CHAR_RIGHT_PAREN);
  return ecma_make_string_value (ecma_stringbuilder_finalize (&builder));
} /* ecma_get_symbol_descriptive_string */

/**
 * thisSymbolValue abstract operation
 *
 * See also:
 *          ECMA-262 v11, 19.4.3
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_symbol_this_value (ecma_value_t this_arg) /**< this argument value */
{
  /* 1. */
  if (ecma_is_value_symbol (this_arg))
  {
    return this_arg;