diff options
author | Zoltan Herczeg <zherczeg.u-szeged@partner.samsung.com> | 2021-03-03 18:02:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-03 18:02:40 +0100 |
commit | 29b7c8f8ff5d62872d85e2c47f64489e9f793b4e (patch) | |
tree | b78461152af328e23c64bb502d3b2aa66aff8b1c /docs/02.API-REFERENCE.md | |
parent | a95e3e37e1f7df431f6f34c4686199778ca89eb5 (diff) |
Implement jerry_get_own_property API function (#4612)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
Diffstat (limited to 'docs/02.API-REFERENCE.md')
-rw-r--r-- | docs/02.API-REFERENCE.md | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/docs/02.API-REFERENCE.md b/docs/02.API-REFERENCE.md index 0d230bdc..2b8f8e46 100644 --- a/docs/02.API-REFERENCE.md +++ b/docs/02.API-REFERENCE.md @@ -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** |