mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Add acquire_value API to simplify caller code
JerryScript-DCO-1.0-Signed-off-by: François Baldassari francois@pebble.com
This commit is contained in:
parent
66c94b7d9b
commit
7b047d4b20
@ -272,6 +272,7 @@ jerry_api_value_t jerry_api_create_string_value (jerry_api_string_t *value);
|
||||
jerry_api_size_t jerry_api_string_to_char_buffer (const jerry_api_string_t *, jerry_api_char_t *, jerry_api_size_t);
|
||||
jerry_api_string_t *jerry_api_acquire_string (jerry_api_string_t *);
|
||||
jerry_api_object_t *jerry_api_acquire_object (jerry_api_object_t *);
|
||||
jerry_api_value_t *jerry_api_acquire_value (jerry_api_value_t *);
|
||||
|
||||
void jerry_api_release_object (jerry_api_object_t *);
|
||||
void jerry_api_release_string (jerry_api_string_t *);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
else if (value_p->type == JERRY_API_DATA_TYPE_OBJECT)
|
||||
{
|
||||
jerry_api_acquire_object (value_p->u.v_object);
|
||||
}
|
||||
|
||||
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 */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user