ronantakizawa/codereview-bench huggingface dataset:
Repository: jerryscript-project/jerryscript
File: tests/jerry/es.next/array-prototype-includes.js (JavaScript)

Code before:
var obj_arr = [1, obj, 2];
var empry_arr = [];

assert(num_arr.includes(3) === true);
assert(num_arr.includes(3, 4) === false);
assert(num_arr.includes(3, -5) === true);
assert(num_arr.includes(undefined) === true);
assert(num_arr.includes(3, Infinity) === false);
assert(num_arr.includes(3, -0) === true);
assert(str_arr.includes(NaN) === true);
assert(str_arr.includes('foo', 4) === true);
assert(str_arr.includes('f') === false);
assert(obj_arr.includes(obj) === true);
assert(obj_arr.includes({}) === false);
assert(empry_arr.includes() === false);
assert(empry_arr.includes(3) === false);
assert([undefined].includes() === true);

try {
  num_arr.includes(new Symbol());
  assert(false);
} catch (e) {
  assert(e instanceof TypeError);
}

Object.defineProperty(num_arr, "get", function() {throw 42});

try {
  num_arr.includes(4);
} catch (e) {
  assert(e === 42);
}


Review comment (suggestion):
I think you meant:

```js
Object.defineProperty(num_arr, "1", { get: function() {throw 42} });
```

Code after:
var obj_arr = [1, obj, 2];
var empry_arr = [];

assert(num_arr.includes(3) === true);
assert(num_arr.includes(3, 4) === false);
assert(num_arr.includes(3, -5) === true);
assert(num_arr.includes(undefined) === true);
assert(num_arr.includes(3, Infinity) === false);
assert(num_arr.includes(3, -0) === true);
assert(str_arr.includes(NaN) === true);
assert(str_arr.includes('foo', 4) === true);
assert(str_arr.includes('f') === false);
assert(obj_arr.includes(obj) === true);
assert(obj_arr.includes({}) === false);
assert(empry_arr.includes() === false);
assert(empry_arr.includes(3) === false);
assert([undefined].includes() === true);

Object.defineProperty(num_arr, "1", { get: function() {throw 42}});

try {
  num_arr.includes(4);
  assert(false);
} catch (e) {
  assert(e === 42);
}

var sym = Symbol('foo');

try {
  num_arr.includes(3, sym);
  assert(false);
} catch (e) {
  assert(e instanceof TypeError);
}

// Remove the buffer
var array = [1, 2, 3, 4, 5];
var found = array.includes(4, {
    valueOf: function() {
        array.length = 0;
    }
})

assert(found === false);

// Extend the buffer
var array = [1, 2, 3];
var found = array.includes(2, {
    valueOf: function() {
        array.length = 5;
Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/builtin-objects/ecma-builtin-symbol-prototype.c (C)

Code before:
 *
 * See also:
 *          ECMA-262 v6, 19.4.3.3
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_symbol_prototype_object_to_primitive (ecma_value_t this_arg) /**< this argument */
{
  return ecma_builtin_symbol_prototype_object_value_of (this_arg);
} /* ecma_builtin_symbol_prototype_object_to_primitive */

/**
 * The Symbol.prototype object's 'description' routine
 *
 * See also:
 *          ECMA-262 v11, 19.4.3.2
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_symbol_prototype_description_getter (ecma_value_t this_arg) /**< this argument */
{
  if (ecma_is_value_symbol (this_arg))
  {
    ecma_string_t *symbol_p = ecma_get_symbol_from_value (this_arg);
    ecma_string_t *desc_p = ecma_get_symbol_description (symbol_p);
    ecma_ref_ecma_string (desc_p);
    return ecma_make_string_value (desc_p);
  }

  if (ecma_is_value_object (this_arg))
  {
    ecma_object_t *object_p = ecma_get_object_from_value (this_arg);

    if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_CLASS)
    {
      ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;

      if (ext_object_p->u.class_prop.class_id == LIT_MAGIC_STRING_SYMBOL_UL)
      {
        ecma_string_t *symbol_p = ecma_get_symbol_from_value (ext_object_p->u.class_prop.u.value);
        ecma_string_t *desc_p = ecma_get_symbol_description (symbol_p);
        ecma_ref_ecma_string (desc_p);
        return ecma_make_string_value (desc_p);
      }
    }
  }


Review comment (refactor):
There is already a `ecma_symbol_to_string_helper` function which almost do the same. The second parameter of this function currently is boolean to decide whether `toString` or `valueOf` routine should be performed. Please change this boolean into an enum, and add `description` routine as well into this list. After that please modify this helper function according to it.

Code after:

  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) */
Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/operations/ecma-symbol-object.c (C)

Code before:
ecma_symbol_this_value (ecma_value_t this_arg) /**< this argument value */
{
  /* 1. */
  if (ecma_is_value_symbol (this_arg))
  {
    return this_arg;
  }

  /* 2. */
  if (ecma_is_value_object (this_arg))
  {
    ecma_object_t *object_p = ecma_get_object_from_value (this_arg);

    if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_CLASS)
    {
      ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;

      if (ext_obj_p->u.class_prop.class_id == LIT_MAGIC_STRING_SYMBOL_UL)
      {
        return ext_obj_p->u.class_prop.u.value;
      }
    }
  }

  /* 3. */
  return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is must be a Symbol."));
} /* ecma_symbol_this_value */
#endif /* ENABLED (JERRY_ESNEXT) */

/**
 * @}
 * @}
 */


Review comment (suggestion):
If we are modifying around this then the error message can be also fixed. The `is` in the sentence feels awkward imho.

Code after:
ecma_symbol_this_value (ecma_value_t this_arg) /**< this argument value */
{
  /* 1. */
  if (ecma_is_value_symbol (this_arg))
  {
    return this_arg;
  }

  /* 2. */
  if (ecma_is_value_object (this_arg))
  {
    ecma_object_t *object_p = ecma_get_object_from_value (this_arg);

    if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_CLASS)
    {
      ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;

      if (ext_obj_p->u.class_prop.class_id == LIT_MAGIC_STRING_SYMBOL_UL)
      {
        return ext_obj_p->u.class_prop.u.value;
      }
    }
  }

  /* 3. */
  return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' must be a Symbol."));
} /* ecma_symbol_this_value */
#endif /* ENABLED (JERRY_ESNEXT) */

/**
 * @}
 * @}
 */
Repository: jerryscript-project/jerryscript
File: tests/jerry/es.next/nullish-coalescing.js (JavaScript)

Code before:
assert(null ?? undefined ?? null ?? 10  == 10)
assert(null ?? (undefined || null) ?? 10  == 10)
assert(null ?? (undefined && null) ?? 10  == 10)
assert((null ?? true) && (true ?? null) == true)

//cannot evulate the right expression if left is not null or undefined
function poison()
{
  throw 23;
}
assert(true ?? poison())
assert(null ?? null ?? true ?? poison())


// invalid use cases
var headNullish1 = "(null ?? null || null )";
var headNullish2 = "(null ?? null && null )";
var tailNullish1 = "(null || null ?? null )";
var tailNullish2 = "(null || null ?? null )";


try {
  eval(headNullish1);
  assert(false);
} catch (e) {
  assert(e instanceof SyntaxError);
}
try {
  eval(headNullish2);
  assert(false);
} catch (e) {
  assert(e instanceof SyntaxError);
}

try {
  eval(tailNullish1);
  assert(false);
} catch (e) {
  assert(e instanceof SyntaxError);
}

try {
  eval(tailNullish2);
  assert(false);
} catch (e) {
  assert(e instanceof SyntaxError);
}


Review comment (suggestion):
```js
function checkSyntax (str) {
  try {
    eval (str);
    assert (false);
  } catch (e) {
    assert (e instanceof SyntaxError);
  }
}

checkSyntax ("(null ?? null || null )");
// ...
```
and so on.

Code after:
assert(null ?? undefined ?? null ?? 10  == 10)
assert(null ?? (undefined || null) ?? 10  == 10)
assert(null ?? (undefined && null) ?? 10  == 10)
assert((null ?? true) && (true ?? null) == true)

//cannot evulate the right expression if left is not null or undefined
function poison () {
  throw 23;
}
assert(true ?? poison ())
assert(null ?? null ?? true ?? poison ())

function checkSyntax (str) {
  try {
    eval (str);
    assert (false);
  } catch (e) {
    assert (e instanceof SyntaxError);
  }
}

// invalid use cases
var headNullish1 = "(null ?? null || null )";
var headNullish2 = "(null ?? null && null )";
var tailNullish1 = "(null || null ?? null )";
var tailNullish2 = "(null || null ?? null )";

checkSyntax (headNullish1);
checkSyntax (headNullish2);
checkSyntax (tailNullish1);
checkSyntax (tailNullish2);
Repository: jerryscript-project/jerryscript
File: jerry-core/vm/vm.c (C)

Code before:

          bool boolean_value = ecma_op_to_boolean (value);

          if (opcode_flags & VM_OC_BRANCH_IF_FALSE_FLAG)
          {
            boolean_value = !boolean_value;
          }

          if (boolean_value)
          {
            byte_code_p = byte_code_start_p + branch_offset;
            if (opcode_flags & VM_OC_LOGICAL_BRANCH_FLAG)
            {
              /* "Push" the value back to the stack. */
              ++stack_top_p;
              continue;
            }
          }

          ecma_fast_free_value (value);
          continue;
        }
#if ENABLED (JERRY_ESNEXT)
        case VM_OC_BRANCH_IF_NULLISH:
        {
          ecma_value_t value = *(--stack_top_p);

          if (!ecma_is_value_null (value) && !ecma_is_value_undefined (value))
          {
            byte_code_p = byte_code_start_p + branch_offset;
            ++stack_top_p;
          }
          continue;
        }
#endif /* ENABLED (JERRY_ESNEXT) */
        case VM_OC_PLUS:
        case VM_OC_MINUS:
        {
          result = opfunc_unary_operation (left_value, VM_OC_GROUP_GET_INDEX (opcode_data) == VM_OC_PLUS);

          if (ECMA_IS_VALUE_ERROR (result))
          {
            goto error;
          }

          *stack_top_p++ = result;
          goto free_left_value;
        }
        case VM_OC_NOT:
        {
          *stack_top_p++ = ecma_make_boolean_value (!ecma_op_to_boolean (left_value));

Review comment (suggestion):
I'd reverse the logic. Instead of pop and push back, just read the stack_top[-1] and only pop, if it is undefined or null.

Code after:

          bool boolean_value = ecma_op_to_boolean (value);

          if (opcode_flags & VM_OC_BRANCH_IF_FALSE_FLAG)
          {
            boolean_value = !boolean_value;
          }

          if (boolean_value)
          {
            byte_code_p = byte_code_start_p + branch_offset;
            if (opcode_flags & VM_OC_LOGICAL_BRANCH_FLAG)
            {
              /* "Push" the value back to the stack. */
              ++stack_top_p;
              continue;
            }
          }

          ecma_fast_free_value (value);
          continue;
        }
#if ENABLED (JERRY_ESNEXT)
        case VM_OC_BRANCH_IF_NULLISH:
        {
          left_value = stack_top_p[-1];

          if (!ecma_is_value_null (left_value) && !ecma_is_value_undefined (left_value))
          {
            byte_code_p = byte_code_start_p + branch_offset;
            continue;
          }
          --stack_top_p;
          continue;
        }
#endif /* ENABLED (JERRY_ESNEXT) */
        case VM_OC_PLUS:
        case VM_OC_MINUS:
        {
          result = opfunc_unary_operation (left_value, VM_OC_GROUP_GET_INDEX (opcode_data) == VM_OC_PLUS);

          if (ECMA_IS_VALUE_ERROR (result))
          {
            goto error;
          }

          *stack_top_p++ = result;
          goto free_left_value;
        }
        case VM_OC_NOT:
        {
Repository: jerryscript-project/jerryscript
File: tests/jerry/es.next/tagged-template-literal.js (JavaScript)

Code before:
  templateObject = p;
})`str`;

var desc = Object.getOwnPropertyDescriptor(templateObject, '0');
assert(desc.writable === false);
assert(desc.enumerable === true);
assert(desc.configurable === false);

(function () {
  function f (strings, ...args) {
    return function () {
      return Array(...args);
    };
  }

  var a = new f`${1}${2}${3}`;
  assert(a.length === 3);
  assert(a[0] === 1);
  assert(a[1] === 2);
  assert(a[2] === 3);

  function g (strings, ...args) {
    return Array;
  }

  a = new g`${1}${2}${3}`(4, 5, 6);
  assert(a.length === 3);
  assert(a[0] === 4);
  assert(a[1] === 5);
  assert(a[2] === 6);

  function h (strings, ...args) {
    return 5;
  }

  try {
    new h`foo`;
    assert(false);
  } catch (e) {
    assert (e instanceof TypeError);
  }
})();


Review comment (suggestion):
We could add a testcase: 
```js
new (g`${1}${2}${3}`(4, 5, 6)); // -> TypeError.
```

Code after:
  templateObject = p;
})`str`;

var desc = Object.getOwnPropertyDescriptor(templateObject, '0');
assert(desc.writable === false);
assert(desc.enumerable === true);
assert(desc.configurable === false);

(function () {
  function f (strings, ...args) {
    return function () {
      return Array(...args);
    };
  }

  var a = new f`${1}${2}${3}`;
  assert(a.length === 3);
  assert(a[0] === 1);
  assert(a[1] === 2);
  assert(a[2] === 3);

  function g (strings, ...args) {
    return Array;
  }

  a = new g`${1}${2}${3}`(4, 5, 6);
  assert(a.length === 3);
  assert(a[0] === 4);
  assert(a[1] === 5);
  assert(a[2] === 6);

  try {
    new (g`${1}${2}${3}`(4, 5, 6));
    assert(false);
  } catch (e) {
    assert (e instanceof TypeError);
  }

  function h (strings, ...args) {
    return 5;
  }

  try {
    new h`foo`;
    assert(false);
  } catch (e) {
    assert (e instanceof TypeError);
  }
})();
Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/base/ecma-helpers-string.c (C)

Code before:
    {
      return original_string_p;
    }
  }
  ECMA_STRING_TO_UTF8_STRING (filler_p, start_p, buffer_p);

  /* 9 */
  uint32_t fillLen = int_max_length - string_length;

  /* 10 */
  uint32_t append_number = fillLen / (ecma_string_get_length (filler_p));
  ecma_stringbuilder_t builder = ecma_stringbuilder_create ();
  if (!pad_on_start)
  {
    ecma_stringbuilder_append (&builder, original_str_val_p);
  }

  for (uint32_t i = 0; i < append_number; i++)
  {
    ecma_stringbuilder_append (&builder, filler_p);
  }

  lit_utf8_size_t read_size;
  ecma_char_t ch;

  uint32_t remaining = fillLen - (append_number * (ecma_string_get_length (filler_p)));

  while (remaining > 0)
  {
    read_size = lit_read_code_unit_from_utf8 (start_p, &ch);
    ecma_stringbuilder_append_char (&builder, ch);
    start_p += read_size;
    remaining--;
  }

  /* 11 - 12 */
  if (pad_on_start)
  {
    ecma_stringbuilder_append (&builder, original_str_val_p);
  }
  ECMA_FINALIZE_UTF8_STRING (start_p, buffer_p);
  ecma_deref_ecma_string (filler_p);
  return ecma_make_string_value (ecma_stringbuilder_finalize (&builder));;

} /* ecma_string_stringPad */
#endif /* ENABLED (JERRY_ESNEXT) */
/**
 * Create an empty string builder
 *
 * @return new string builder
 */

Review comment (suggestion):
The `...get_length` is already invoked in line 2477 for the "filler_p". Maybe we should have a variable to hold the value to avoid the double method call.

Code after:
      return original_string_p;
    }
  }

  /* 9 */
  uint32_t fill_len = int_max_length - string_length;

  /* 10 */
  uint32_t filler_length = ecma_string_get_length (filler_p);
  uint32_t prepend_count = fill_len / filler_length;
  ecma_stringbuilder_t builder = ecma_stringbuilder_create ();

  if (!pad_on_start)
  {
    ecma_stringbuilder_append (&builder, original_str_val_p);
  }

  for (uint32_t i = 0; i < prepend_count; i++)
  {
    ecma_stringbuilder_append (&builder, filler_p);
  }

  lit_utf8_size_t read_size;
  ecma_char_t ch;

  uint32_t remaining = fill_len - (prepend_count * filler_length);

  ECMA_STRING_TO_UTF8_STRING (filler_p, start_p, utf8_str_size);
  while (remaining > 0)
  {
    read_size = lit_read_code_unit_from_utf8 (start_p, &ch);
    ecma_stringbuilder_append_char (&builder, ch);
    start_p += read_size;
    remaining--;
  }
  ECMA_FINALIZE_UTF8_STRING (start_p, utf8_str_size);
  ecma_deref_ecma_string (filler_p);

  /* 11 - 12 */
  if (pad_on_start)
  {
    ecma_stringbuilder_append (&builder, original_str_val_p);
  }

  return ecma_make_string_value (ecma_stringbuilder_finalize (&builder));
} /* ecma_string_pad */
#endif /* ENABLED (JERRY_ESNEXT) */

/**
 * Create an empty string builder
 *
Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/base/ecma-helpers-string.c (C)

Code before:
  if (int_max_length <= string_length)
  {
    return original_string_p;
  }

  ecma_string_t *filler_p = ecma_get_magic_string (LIT_MAGIC_STRING_SPACE_CHAR);
  /* 6 - 7 */
  if (!ecma_is_value_undefined (fill_string))
  {
    filler_p = ecma_op_to_string (fill_string);
    if (filler_p == NULL)
    {
      return ECMA_VALUE_ERROR;
    }
    if (ecma_string_is_empty (filler_p))
    {
      return original_string_p;
    }
  }
  ECMA_STRING_TO_UTF8_STRING (filler_p, start_p, buffer_p);

  /* 9 */
  uint32_t fillLen = int_max_length - string_length;

  /* 10 */
  uint32_t append_number = fillLen / (ecma_string_get_length (filler_p));
  ecma_stringbuilder_t builder = ecma_stringbuilder_create ();
  if (!pad_on_start)
  {
    ecma_stringbuilder_append (&builder, original_str_val_p);
  }

  for (uint32_t i = 0; i < append_number; i++)
  {
    ecma_stringbuilder_append (&builder, filler_p);
  }

  lit_utf8_size_t read_size;
  ecma_char_t ch;

  uint32_t remaining = fillLen - (append_number * (ecma_string_get_length (filler_p)));

  while (remaining > 0)
  {
    read_size = lit_read_code_unit_from_utf8 (start_p, &ch);
    ecma_stringbuilder_append_char (&builder, ch);
    start_p += read_size;
    remaining--;
  }

  /* 11 - 12 */

Review comment (suggestion):
As we are adding characters to the start the `prepend_count` variable name would be a better indicator for this.

Code after:
    return original_string_p;
  }

  ecma_string_t *filler_p = ecma_get_magic_string (LIT_MAGIC_STRING_SPACE_CHAR);
  /* 6 - 7 */
  if (!ecma_is_value_undefined (fill_string))
  {
    filler_p = ecma_op_to_string (fill_string);
    if (filler_p == NULL)
    {
      return ECMA_VALUE_ERROR;
    }
    if (ecma_string_is_empty (filler_p))
    {
      ecma_ref_ecma_string (original_str_val_p);
      return original_string_p;
    }
  }

  /* 9 */
  uint32_t fill_len = int_max_length - string_length;

  /* 10 */
  uint32_t filler_length = ecma_string_get_length (filler_p);
  uint32_t prepend_count = fill_len / filler_length;
  ecma_stringbuilder_t builder = ecma_stringbuilder_create ();

  if (!pad_on_start)
  {
    ecma_stringbuilder_append (&builder, original_str_val_p);
  }

  for (uint32_t i = 0; i < prepend_count; i++)
  {
    ecma_stringbuilder_append (&builder, filler_p);
  }

  lit_utf8_size_t read_size;
  ecma_char_t ch;

  uint32_t remaining = fill_len - (prepend_count * filler_length);

  ECMA_STRING_TO_UTF8_STRING (filler_p, start_p, utf8_str_size);
  while (remaining > 0)
  {
    read_size = lit_read_code_unit_from_utf8 (start_p, &ch);
    ecma_stringbuilder_append_char (&builder, ch);
    start_p += read_size;
    remaining--;
  }
  ECMA_FINALIZE_UTF8_STRING (start_p, utf8_str_size);
Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/base/ecma-helpers-string.c (C)

Code before:
  }

  /* 4 */
  ecma_string_t *original_str_val_p = ecma_get_string_from_value (original_string_p);
  const ecma_length_t string_length = ecma_string_get_length (original_str_val_p);
  /* 5 */
  if (int_max_length <= string_length)
  {
    return original_string_p;
  }

  ecma_string_t *filler_p = ecma_get_magic_string (LIT_MAGIC_STRING_SPACE_CHAR);
  /* 6 - 7 */
  if (!ecma_is_value_undefined (fill_string))
  {
    filler_p = ecma_op_to_string (fill_string);
    if (filler_p == NULL)
    {
      return ECMA_VALUE_ERROR;
    }
    if (ecma_string_is_empty (filler_p))
    {
      return original_string_p;
    }
  }
  ECMA_STRING_TO_UTF8_STRING (filler_p, start_p, buffer_p);

  /* 9 */
  uint32_t fillLen = int_max_length - string_length;

  /* 10 */
  uint32_t append_number = fillLen / (ecma_string_get_length (filler_p));
  ecma_stringbuilder_t builder = ecma_stringbuilder_create ();
  if (!pad_on_start)
  {
    ecma_stringbuilder_append (&builder, original_str_val_p);
  }

  for (uint32_t i = 0; i < append_number; i++)
  {
    ecma_stringbuilder_append (&builder, filler_p);
  }

  lit_utf8_size_t read_size;
  ecma_char_t ch;

  uint32_t remaining = fillLen - (append_number * (ecma_string_get_length (filler_p)));

  while (remaining > 0)
  {
    read_size = lit_read_code_unit_from_utf8 (start_p, &ch);

Review comment (suggestion):
The 3rd arg of the macro represents the size of the underlying character buffer. The `buffer_p` name is misleading.

Code after:
  ecma_string_t *original_str_val_p = ecma_get_string_from_value (original_string_p);
  const uint32_t string_length = ecma_string_get_length (original_str_val_p);
  /* 5 */
  if (int_max_length <= string_length)
  {
    ecma_ref_ecma_string (original_str_val_p);
    return original_string_p;
  }

  ecma_string_t *filler_p = ecma_get_magic_string (LIT_MAGIC_STRING_SPACE_CHAR);
  /* 6 - 7 */
  if (!ecma_is_value_undefined (fill_string))
  {
    filler_p = ecma_op_to_string (fill_string);
    if (filler_p == NULL)
    {
      return ECMA_VALUE_ERROR;
    }
    if (ecma_string_is_empty (filler_p))
    {
      ecma_ref_ecma_string (original_str_val_p);
      return original_string_p;
    }
  }

  /* 9 */
  uint32_t fill_len = int_max_length - string_length;

  /* 10 */
  uint32_t filler_length = ecma_string_get_length (filler_p);
  uint32_t prepend_count = fill_len / filler_length;
  ecma_stringbuilder_t builder = ecma_stringbuilder_create ();

  if (!pad_on_start)
  {
    ecma_stringbuilder_append (&builder, original_str_val_p);
  }

  for (uint32_t i = 0; i < prepend_count; i++)
  {
    ecma_stringbuilder_append (&builder, filler_p);
  }

  lit_utf8_size_t read_size;
  ecma_char_t ch;

  uint32_t remaining = fill_len - (prepend_count * filler_length);

  ECMA_STRING_TO_UTF8_STRING (filler_p, start_p, utf8_str_size);
  while (remaining > 0)
  {