Make the underlying buffer of the ArrayBuffer accessible. (#2836)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
@@ -6426,16 +6426,13 @@ jerry_arraybuffer_write (const jerry_value_t value,
|
||||
**Summary**
|
||||
|
||||
The function allows access to the contents of the Array Buffer directly.
|
||||
Only allowed for Array Buffers which were created with
|
||||
[jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external)
|
||||
function calls. In any other case this function will return `NULL`.
|
||||
|
||||
After using the pointer the [jerry_release_value](#jerry_release_value)
|
||||
function must be called.
|
||||
|
||||
**WARNING!** This operation is for expert use only! The programmer must
|
||||
ensure that the returned memory area is used correctly. That is
|
||||
there is no out of bounds reads or writes.
|
||||
there is no out of bounds reads or writes. The lifetime of the underlying
|
||||
data buffer is managed by the ArrayBuffer value. Make sure to acquire the
|
||||
value with [`jerry_acquire_value`](#jerry_acquire_value) if the data
|
||||
buffer is needed later.
|
||||
|
||||
**Prototype**
|
||||
|
||||
@@ -6447,26 +6444,22 @@ jerry_get_arraybuffer_pointer (const jerry_value_t value);
|
||||
- `value` - Array Buffer object.
|
||||
- return value
|
||||
- pointer to the Array Buffer's data area.
|
||||
- NULL if the `value` is not an Array Buffer object with external memory.
|
||||
- NULL if the `value` is not an Array Buffer object.
|
||||
|
||||
**Example**
|
||||
|
||||
```c
|
||||
{
|
||||
jerry_value_t buffer;
|
||||
|
||||
// acquire buffer somewhere which was created by a jerry_create_array_buffer_external call.
|
||||
// create the ArrayBuffer
|
||||
jerry_value_t buffer = jerry_create_arraybuffer (16);
|
||||
|
||||
uint8_t *const data = jerry_get_arraybuffer_pointer (buffer);
|
||||
|
||||
for (int i = 0; i < 22; i++)
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
data[i] = (uint8_t) (i + 4);
|
||||
}
|
||||
|
||||
// required after jerry_get_arraybuffer_pointer call.
|
||||
jerry_release_value (buffer);
|
||||
|
||||
// use the Array Buffer
|
||||
|
||||
// release buffer as it is not needed after this point
|
||||
|
||||
Reference in New Issue
Block a user