Add a callback which is called when Error objects are created (#4465)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-01-18 16:56:38 +01:00
committed by GitHub
parent e00964176d
commit 3b77117a2e
14 changed files with 249 additions and 51 deletions
+75
View File
@@ -586,6 +586,33 @@ typedef void (*jerry_object_native_free_callback_t) (void *native_p);
- [jerry_object_native_info_t](#jerry_object_native_info_t)
- [jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external)
## jerry_error_object_created_callback_t
**Summary**
Decorator callback for Error objects. This native callback is called every time when an Error
object is created and the decorator can create or update any properties of the newly created
Error object.
*Note*:
- The callback function cannot be called recursively, so the Error objects created
when the callback is running are not updated.
*New in version [[NEXT_RELEASE]]*.
**Prototype**
```c
typedef void (*jerry_error_object_created_callback_t) (const jerry_value_t error_object, void *user_p);
```
- `error_object` - the newly created Error object.
- `user_p` - pointer passed to [jerry_set_error_object_created_callback](#jerry_set_error_object_created_callback).
**See also**
- [jerry_set_error_object_created_callback](#jerry_set_error_object_created_callback)
## jerry_object_native_info_t
**Summary**
@@ -2996,6 +3023,54 @@ jerry_get_value_from_error (jerry_value_t value, bool release)
- [jerry_create_error_from_value](#jerry_create_error_from_value)
- [jerry_create_abort_from_value](#jerry_create_abort_from_value)
## jerry_set_error_object_created_callback
**Summary**
Set the decorator callback for newly created Error objects. The operation of the callback
is described in [jerry_error_object_created_callback_t](#jerry_error_object_created_callback_t).
**Prototype**
```c
void jerry_set_error_object_created_callback (jerry_error_object_created_callback_t callback, void *user_p);
```
- `callback` - callback function, the previously set value is overwritten, and setting NULL
disables the operation
- `user_p` - pointer passed to the callback function, can be NULL
*New in version [[NEXT_RELEASE]]*.
**Example**
```c
static void
error_object_created_callback (const jerry_value_t error_object) /**< new error object */
void *user_p) /**< user pointer */
{
(void) error_object;
(void) user_p;
printf ("Notification: a new error is created\n");
} /* error_object_created_callback */
void main(void)
{
jerry_init (JERRY_INIT_EMPTY);
jerry_set_error_object_created_callback (error_object_created_callback, NULL);
jerry_release_value (jerry_create_error (JERRY_ERROR_COMMON,
(const jerry_char_t *) "Message"));
jerry_cleanup ();
} /* main */
```
**See also**
- [jerry_error_object_created_callback_t](#jerry_error_object_created_callback_t)
# Getter functions of 'jerry_value_t'
Get raw data from API values.