Implement jerry_get_own_property API function (#4612)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-03-03 18:02:40 +01:00
committed by GitHub
parent a95e3e37e1
commit 29b7c8f8ff
5 changed files with 346 additions and 0 deletions
+71
View File
@@ -6994,6 +6994,77 @@ jerry_get_property_by_index (const jerry_value_t obj_val,
- [jerry_set_property](#jerry_set_property)
- [jerry_set_property_by_index](#jerry_set_property_by_index)
## jerry_get_own_property
**Summary**
Get the own property value of an object with the given name. The function tells
whether the property is found, and the receiver object can be specified as well.
The receiver is passed as the `this` argument for getters, and the receiver
argument for Proxy `get` traps.
*Notes*:
- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it is no longer needed.
- The `found_p` argument is ignored if its value is NULL.
- The target value of `found_p` argument is set to false when the arguments are invalid, e.g. `obj_val` is not an object.
**Prototype**
```c
jerry_value_t
jerry_get_own_property (const jerry_value_t obj_val,
const jerry_value_t prop_name_val,
const jerry_value_t receiver_val,
bool *found_p);
```
- `obj_val` - object value
- `prop_name_val` - property name
- `receiver_val` - receiver object
- `found_p` - [out] true, if the property is found or obj_val is a Proxy object, false otherwise
- return value
- value of property, if success
- thrown error, otherwise
**Example**
[doctest]: # ()
```c
#include "jerryscript.h"
#include "stdio.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerry_value_t global_object = jerry_get_global_object ();
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "Object");
bool found;
jerry_value_t prop_value = jerry_get_own_property (global_object, prop_name, global_object, &found);
if (found)
{
printf ("Property is found!\n");
}
/* use "prop_value" then release it. */
jerry_release_value (prop_value);
jerry_release_value (prop_name);
jerry_release_value (global_object);
return 0;
}
```
**See also**
- [jerry_get_property](#jerry_get_property)
- [jerry_get_property_by_index](#jerry_get_property_by_index)
## jerry_get_internal_property
**Summary**