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

Code before:
 */

/**
 * Helper function: check if the value is Array or SharedArray buffer
 *
 * @return true - if value is an ArrayBuffer or SharedArrayBuffer object
 *         false - otherwise
 */
extern inline bool JERRY_ATTR_ALWAYS_INLINE
ecma_is_array_or_sharedarray_buffer (const jerry_value_t value) /**< the target value */
{
#if JERRY_BUILTIN_SHAREDARRAYBUFFER
  return (ecma_is_arraybuffer (value) || ecma_is_shared_arraybuffer (value));
#else /* !JERRY_BUILTIN_SHAREDARRAYBUFFER */
  return ecma_is_arraybuffer (value);
#endif /* !JERRY_BUILTIN_SHAREDARRAYBUFFER */
} /* ecma_is_array_or_sharedarray_buffer */

/**
 * Helper function: check if the value is array or sharedarray buffer object
 *
 * @return true - if object is an ArrayBuffer or SharedArrayBuffer object
 *         false - otherwise
 */
extern inline bool JERRY_ATTR_ALWAYS_INLINE
ecma_is_object_array_or_sharedarray_buffer (ecma_object_t *object) /**< the target object */
{
#if JERRY_BUILTIN_SHAREDARRAYBUFFER
  return (ecma_object_class_is (object, ECMA_OBJECT_CLASS_ARRAY_BUFFER)
          || ecma_object_class_is (object, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER));
#else /* !JERRY_BUILTIN_SHAREDARRAYBUFFER */
  return ecma_object_class_is (object, ECMA_OBJECT_CLASS_ARRAY_BUFFER);
#endif /* !JERRY_BUILTIN_SHAREDARRAYBUFFER */
} /* ecma_is_object_array_or_sharedarray_buffer */

/**
 * Helper function: create arraybuffer object based on the array length
 *
 * The struct of arraybuffer object:
 *   ecma_object_t
 *   extend_part
 *   data buffer
 *
 * @return ecma_object_t *
 */
ecma_object_t *
ecma_arraybuffer_new_object (uint32_t length) /**< length of the arraybuffer */
{
  ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE);
  ecma_object_t *object_p = ecma_create_object (prototype_obj_p,
                                                sizeof (ecma_extended_object_t) + length,

Review comment (suggestion):
imho: The `is` and `object` should be switched in the name. (Also the name is really weird, however I don't know any better at the moment.

Code after:
 */

/**
 * Helper function: create arraybuffer object based on the array length
 *
 * The struct of arraybuffer object:
 *   ecma_object_t
 *   extend_part
 *   data buffer
 *
 * @return ecma_object_t *
 */
ecma_object_t *
ecma_arraybuffer_new_object (uint32_t length) /**< length of the arraybuffer */
{
  ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE);
  ecma_object_t *object_p = ecma_create_object (prototype_obj_p,
                                                sizeof (ecma_extended_object_t) + length,
                                                ECMA_OBJECT_TYPE_CLASS);

  ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
  ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_ARRAY_BUFFER;
  ext_object_p->u.cls.u1.array_buffer_flags = ECMA_ARRAYBUFFER_INTERNAL_MEMORY;
  ext_object_p->u.cls.u3.length = length;

  lit_utf8_byte_t *buf = (lit_utf8_byte_t *) (ext_object_p + 1);
  memset (buf, 0, length);

  return object_p;
} /* ecma_arraybuffer_new_object */

/**
 * Helper function: create arraybuffer object with external buffer backing.
 *
 * The struct of external arraybuffer object:
 *   ecma_object_t
 *   extend_part
 *   arraybuffer external info part
 *
 * @return ecma_object_t *, pointer to the created ArrayBuffer object
 */
ecma_object_t *
ecma_arraybuffer_new_object_external (uint32_t length, /**< length of the buffer_p to use */
                                      void *buffer_p, /**< pointer for ArrayBuffer's buffer backing */
                                      jerry_value_free_callback_t free_cb) /**< buffer free callback */
{
  ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE);
  ecma_object_t *object_p = ecma_create_object (prototype_obj_p,
                                                sizeof (ecma_arraybuffer_external_info),
                                                ECMA_OBJECT_TYPE_CLASS);