-
Notifications
You must be signed in to change notification settings - Fork 683
Add ArrayBuffer with user specified buffer #2162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ArrayBuffer with user specified buffer #2162
Conversation
Depends on: #2161 |
ae79e7a
to
1acb3be
Compare
#2161 landed. Please rebase. |
888edda
to
1bfd11b
Compare
PR rebased |
jerry-core/api/jerry.c
Outdated
* * Only valid for ArrayBuffers created with jerry_create_arraybuffer_external. | ||
* * This is a high-risk operation as the bounds are not checked | ||
* when accessing the pointer elements. | ||
* * jerry_release_value must be called when the pointer is no longer needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
release what?
jerry-core/ecma/base/ecma-globals.h
Outdated
typedef enum | ||
{ | ||
ECMA_ARRAYBUFFER_INTERNAL_MEMORY = 0u, /* ArrayBuffer memory is handled internally. */ | ||
ECMA_ARRAYBUFFER_EXTERNAL_MEMORY = (1u << 0), /* Memory provided by the developer. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: ArrayBuffer created by jerry_create_arraybuffer_external.
jerry-core/ecma/base/ecma-globals.h
Outdated
} ecma_arraybuffer_extra_flag_t; | ||
|
||
#define ECMA_ARRAYBUFFER_HAS_EXTERNAL_MEMORY(object_p) \ | ||
((((ecma_extended_object_t *) object_p)->u.class_prop.extra_info & ECMA_ARRAYBUFFER_EXTERNAL_MEMORY) == 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!= 0
is nicer than == 1
jerry-core/ecma/base/ecma-globals.h
Outdated
*/ | ||
typedef struct | ||
{ | ||
void *buffer_p; /**< external buffer pointer */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a better technique if the "base" structure is used as the first member. Reason: this ensures proper alignment for structure members.
1bfd11b
to
b7415b6
Compare
@zherczeg I've updated the PR based on the requests. |
b7415b6
to
95d1a06
Compare
docs/02.API-REFERENCE.md
Outdated
|
||
**Summary** | ||
|
||
The function allows acces to the contents of the Array Buffer directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
access
docs/02.API-REFERENCE.md
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the warning text bold: **WARNING!**
docs/02.API-REFERENCE.md
Outdated
|
||
**Summary** | ||
|
||
Create a jerry_value_t representing an ArrayBuffer object with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creates
* extend_part | ||
* arraybuffer external info part | ||
* | ||
* @return ecma_object_t * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@return Pointer to the created ArrayBuffer object if success, NULL otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NULL can't be returned here
New API functions: - jerry_create_arraybuffer_external - jerry_get_arraybuffer_pointer JerryScript-DCO-1.0-Signed-off-by: Peter Gal [email protected]
95d1a06
to
3b8f218
Compare
@LaszloLango I've updated the PR based on the requests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
New API functions: