-
Notifications
You must be signed in to change notification settings - Fork 683
Add acquire_value API to simplify caller code #944
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -634,8 +634,41 @@ jerry_api_release_object (jerry_api_object_t *object_p) /**< pointer acquired th | |
ecma_deref_object (object_p); | ||
} /* jerry_api_release_object */ | ||
|
||
/** | ||
* Acquire specified Jerry API value. | ||
* | ||
* Note: | ||
* For values of string and object types this acquires the underlying data, | ||
* for all other types it is a no-op. | ||
* | ||
* Warning: | ||
* Acquired pointer should be released with jerry_api_release_value | ||
* | ||
* @return pointer that may be used outside of the engine | ||
*/ | ||
jerry_api_value_t * | ||
jerry_api_acquire_value (jerry_api_value_t *value_p) /**< API value */ | ||
{ | ||
jerry_assert_api_available (); | ||
|
||
if (value_p->type == JERRY_API_DATA_TYPE_STRING) | ||
{ | ||
jerry_api_acquire_string (value_p->u.v_string); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duh. Sorry for the silly mistake. Added the return statement at the bottom of the function. |
||
} | ||
else if (value_p->type == JERRY_API_DATA_TYPE_OBJECT) | ||
{ | ||
jerry_api_acquire_object (value_p->u.v_object); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type of a jerry API value (given with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @akiss77 In my opinion, this is an implementation detail. Perhaps in the future, new data types have acquire/release semantics as well, in which case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I humbly disagree. Internal-only functions can be vague about implementation details (even though it's not ideal but that's how it works in practice) but this is the public API of jerry. It may be a no-op for everything beyond strings and objects but it must document this. (My comment above also mentioned "nor does it document".) And true enough, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough! I added documentation to both. |
||
|
||
return value_p; | ||
} /* jerry_api_acquire_value */ | ||
|
||
/** | ||
* Release specified Jerry API value | ||
* | ||
* Note: | ||
* For values of string and object types this releases the underlying data, | ||
* for all other types it is a no-op. | ||
*/ | ||
void | ||
jerry_api_release_value (jerry_api_value_t *value_p) /**< API value */ | ||
|
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.
Missing
@return ...
commentThere 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.
Added.