Clean up property existence check inconsistencies (#1860)

`jerry_has_property ()` and `jerry_has_own_property ()` are inconsistent
in that they squash their return value into a `bool` when in fact it is
a `jerry_value_t`, thereby giving the wrong impression that a property
is there when it isn't and encouraging the leaking of `jerry_value_t`s
by disguising them as `bool`s.

Fixes https://github.com/jerryscript-project/jerryscript/issues/1859

JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
This commit is contained in:
Gabriel "_|Nix|_" Schulhof
2017-05-29 16:54:32 +03:00
committed by László Langó
parent b51b6824bb
commit 708b155f38
4 changed files with 92 additions and 11 deletions
+17 -7
View File
@@ -2767,19 +2767,22 @@ jerry_create_undefined (void);
**Summary**
Checks whether the object or it's prototype objects have the given property.
Checks whether the object or its prototype objects have the given property.
*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
is no longer needed.
**Prototype**
```c
bool
jerry_value_t
jerry_has_property (const jerry_value_t obj_val,
const jerry_value_t prop_name_val);
```
- `obj_val` - object value
- `prop_name_val` - property name
- return value
- return value - JavaScript boolean value that evaluates to
- true, if the property exists
- false, otherwise
@@ -2790,8 +2793,10 @@ jerry_has_property (const jerry_value_t obj_val,
jerry_value_t global_object = jerry_get_global_object ();
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "handler_field");
bool has_prop = jerry_has_property (global_object, prop_name);
jerry_value_t has_prop_js = jerry_has_property (global_object, prop_name);
bool has_prop = jerry_get_boolean_value (has_prop_js);
jerry_release_value (has_prop_js);
jerry_release_value (prop_name);
jerry_release_value (global_object);
}
@@ -2809,17 +2814,20 @@ jerry_has_property (const jerry_value_t obj_val,
Checks whether the object has the given property.
*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
is no longer needed.
**Prototype**
```c
bool
jerry_value_t
jerry_has_own_property (const jerry_value_t obj_val,
const jerry_value_t prop_name_val);
```
- `obj_val` - object value
- `prop_name_val` - property name
- return value
- return value - JavaScript boolean value that evaluates to
- true, if the property exists
- false, otherwise
@@ -2830,8 +2838,10 @@ jerry_has_own_property (const jerry_value_t obj_val,
jerry_value_t global_object = jerry_get_global_object ();
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "handler_field");
bool has_prop = jerry_has_own_property (global_object, prop_name);
jerry_value_t has_prop_js = jerry_has_own_property (global_object, prop_name);
bool has_prop = jerry_get_boolean_value (has_prop_js);
jerry_release_value (jas_prop_js);
jerry_release_value (prop_name);
jerry_release_value (global_object);
}