Add allocate/free callbacks to ArrayBuffers (#4801)

Larger buffer allocations will throw error instead of calling jerry_fatal.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-10-28 13:51:34 +02:00
committed by GitHub
parent d2388e907f
commit a024eb2118
19 changed files with 1365 additions and 716 deletions
+7 -4
View File
@@ -374,8 +374,7 @@ void jerry_free_source_info (jerry_source_info_t *source_info_p);
bool jerry_value_is_arraybuffer (const jerry_value_t value);
jerry_value_t jerry_create_arraybuffer (const jerry_length_t size);
jerry_value_t jerry_create_arraybuffer_external (const jerry_length_t size,
uint8_t *buffer_p,
jerry_value_free_callback_t free_cb);
uint8_t *buffer_p, void *buffer_user_p);
jerry_length_t jerry_arraybuffer_write (const jerry_value_t value,
jerry_length_t offset,
const uint8_t *buf_p,
@@ -388,6 +387,11 @@ jerry_length_t jerry_get_arraybuffer_byte_length (const jerry_value_t value);
uint8_t *jerry_get_arraybuffer_pointer (const jerry_value_t value);
jerry_value_t jerry_is_arraybuffer_detachable (const jerry_value_t value);
jerry_value_t jerry_detach_arraybuffer (const jerry_value_t value);
bool jerry_arraybuffer_has_buffer (const jerry_value_t value);
void jerry_arraybuffer_set_compact_allocation_limit (const jerry_length_t allocation_limit);
void jerry_arraybuffer_set_allocator_callbacks (jerry_arraybuffer_allocate_t allocate_callback,
jerry_arraybuffer_free_t free_callback,
void *user_p);
/**
* SharedArrayBuffer components.
@@ -396,8 +400,7 @@ jerry_value_t jerry_detach_arraybuffer (const jerry_value_t value);
bool jerry_value_is_shared_arraybuffer (const jerry_value_t value);
jerry_value_t jerry_create_shared_arraybuffer (const jerry_length_t size);
jerry_value_t jerry_create_shared_arraybuffer_external (const jerry_length_t size,
uint8_t *buffer_p,
jerry_value_free_callback_t free_cb);
uint8_t *buffer_p, void *buffer_user_p);
/**
* DataView functions.
+25
View File
@@ -818,6 +818,31 @@ typedef struct
uint32_t source_range_length; /**< source length of the function in the source code */
} jerry_source_info_t;
/**
* Array buffer types.
*/
/**
* Type of an array buffer.
*/
typedef enum
{
JERRY_ARRAYBUFFER_TYPE_ARRAYBUFFER, /**< the object is an array buffer object */
JERRY_ARRAYBUFFER_TYPE_SHARED_ARRAYBUFFER, /**< the object is a shared array buffer object */
} jerry_arraybuffer_type_t;
/**
* Callback for allocating the backing store of array buffer or shared array buffer objects.
*/
typedef uint8_t *(*jerry_arraybuffer_allocate_t) (jerry_arraybuffer_type_t buffer_type, uint32_t buffer_size,
void **arraybuffer_user_p, void *user_p);
/**
* Callback for freeing the backing store of array buffer or shared array buffer objects.
*/
typedef void (*jerry_arraybuffer_free_t) (jerry_arraybuffer_type_t buffer_type, uint8_t *buffer_p,
uint32_t buffer_size, void *arraybuffer_user_p, void *user_p);
/**
* @}
*/