Implement getter function for external string user pointer (#4742)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-08-30 14:04:13 +02:00
committed by GitHub
parent 4175037fb0
commit 8cbe1b59c1
4 changed files with 143 additions and 1 deletions
+44
View File
@@ -3116,6 +3116,50 @@ jerry_string_set_external_free_callback (jerry_external_string_free_callback_t c
JERRY_CONTEXT (external_string_free_callback_p) = callback_p;
} /* jerry_string_set_external_free_callback */
/**
* Returns the user pointer assigned to an external string.
*
* @return user pointer, if value is an external string
* NULL, otherwise
*/
void *
jerry_string_get_external_user_pointer (const jerry_value_t value, /**< string value */
bool *is_external) /**< [out] true - if value is an external string,
* false - otherwise */
{
if (is_external != NULL)
{
*is_external = false;
}
if (!ecma_is_value_string (value))
{
return NULL;
}
ecma_string_t *string_p = ecma_get_string_from_value (value);
if (ECMA_IS_DIRECT_STRING (string_p)
|| ECMA_STRING_GET_CONTAINER (string_p) != ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING)
{
return NULL;
}
ecma_long_string_t *long_string_p = (ecma_long_string_t *) string_p;
if (long_string_p->string_p == ECMA_LONG_STRING_BUFFER_START (long_string_p))
{
return NULL;
}
if (is_external != NULL)
{
*is_external = true;
}
return ((ecma_external_string_t *) string_p)->user_p;
} /* jerry_string_get_external_user_pointer */
/**
* Checks whether the object or it's prototype objects have the given property.
*