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

Code before:

  if (JERRY_UNLIKELY (result_value_p == NULL))
  {
    return ecma_bigint_raise_memory_error ();
  }

  if (sign)
  {
    result_value_p->u.bigint_sign_and_size |= ECMA_BIGINT_SIGN;
  }

  *ECMA_BIGINT_GET_DIGITS (result_value_p, 0) = digit;
  return ecma_make_extended_primitive_value (result_value_p, ECMA_TYPE_BIGINT);
} /* ecma_bigint_create_from_digit */

/**
 * Parse a string and create a BigInt value
 *
 * @return ecma BigInt value or a special value allowed by the option flags
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_bigint_parse_string (const lit_utf8_byte_t *string_p, /**< string represenation of the BigInt */
                          lit_utf8_size_t size, /**< string size */
                          uint32_t options, /**< ecma_bigint_parse_string_options_t option bits */
                          bool allow_underscore) /**< string can contains "_" character */
{
  ecma_bigint_digit_t radix = 10;
  uint32_t sign = (options & ECMA_BIGINT_PARSE_SET_NEGATIVE) ? ECMA_BIGINT_SIGN : 0;

  if (size >= 3 && string_p[0] == LIT_CHAR_0)
  {
    if (string_p[1] == LIT_CHAR_LOWERCASE_X || string_p[1] == LIT_CHAR_UPPERCASE_X)
    {
      radix = 16;
      string_p += 2;
      size -= 2;
    }
    else if (string_p[1] == LIT_CHAR_LOWERCASE_O || string_p[1] == LIT_CHAR_UPPERCASE_O)
    {
      radix = 8;
      string_p += 2;
      size -= 2;
    }
    else if (string_p[1] == LIT_CHAR_LOWERCASE_B || string_p[1] == LIT_CHAR_UPPERCASE_B)
    {
      radix = 2;
      string_p += 2;
      size -= 2;
    }
  }

Review comment (suggestion):
This should not be a new argument, please extend `ecma_bigint_parse_string_options_t` with a new option bit.

Code after:

  if (JERRY_UNLIKELY (result_value_p == NULL))
  {
    return ecma_bigint_raise_memory_error ();
  }

  if (sign)
  {
    result_value_p->u.bigint_sign_and_size |= ECMA_BIGINT_SIGN;
  }

  *ECMA_BIGINT_GET_DIGITS (result_value_p, 0) = digit;
  return ecma_make_extended_primitive_value (result_value_p, ECMA_TYPE_BIGINT);
} /* ecma_bigint_create_from_digit */

/**
 * Parse a string and create a BigInt value
 *
 * @return ecma BigInt value or a special value allowed by the option flags
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_bigint_parse_string (const lit_utf8_byte_t *string_p, /**< string represenation of the BigInt */
                          lit_utf8_size_t size, /**< string size */
                          uint32_t options) /**< ecma_bigint_parse_string_options_t option bits */
{
  ecma_bigint_digit_t radix = 10;
  uint32_t sign = (options & ECMA_BIGINT_PARSE_SET_NEGATIVE) ? ECMA_BIGINT_SIGN : 0;
  bool allow_underscore = options & ECMA_BIGINT_PARSE_ALLOW_UNDERSCORE;

  const lit_utf8_byte_t *string_end_p = string_p + size;
  string_p = ecma_string_trim_front (string_p, string_p + size);
  size = (lit_utf8_size_t) (string_end_p - string_p);

  if (size >= 3 && string_p[0] == LIT_CHAR_0)
  {
    if (string_p[1] == LIT_CHAR_LOWERCASE_X || string_p[1] == LIT_CHAR_UPPERCASE_X)
    {
      radix = 16;
      string_p += 2;
      size -= 2;
    }
    else if (string_p[1] == LIT_CHAR_LOWERCASE_O || string_p[1] == LIT_CHAR_UPPERCASE_O)
    {
      radix = 8;
      string_p += 2;
      size -= 2;
    }
    else if (string_p[1] == LIT_CHAR_LOWERCASE_B || string_p[1] == LIT_CHAR_UPPERCASE_B)
    {
      radix = 2;