Repository: jerryscript-project/jerryscript
File: jerry-core/api/jerryscript.c (C)

Code before:

/**
 * Checks whether the object has the given property.
 *
 * @return ECMA_VALUE_ERROR - if the operation raises error
 *         ECMA_VALUE_{TRUE, FALSE} - based on whether the property exists
 */
jerry_value_t
jerry_has_own_property (const jerry_value_t obj_val, /**< object value */
                        const jerry_value_t prop_name_val) /**< property name (string value) */
{
  jerry_assert_api_available ();

  if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val))
  {
    return ECMA_VALUE_FALSE;
  }

  ecma_object_t *obj_p = ecma_get_object_from_value (obj_val);
  ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (prop_name_val);

#if JERRY_BUILTIN_PROXY || JERRY_BUILTIN_TYPEDARRAY
  return jerry_return (ecma_op_object_has_own_property (obj_p, prop_name_p));
#else /* !JERRY_BUILTIN_PROXY && !JERRY_BUILTIN_TYPEDARRAY */
  return ecma_op_object_has_own_property (obj_p, prop_name_p);
#endif /* JERRY_BUILTIN_PROXY || JERRY_BUILTIN_TYPEDARRAY */
} /* jerry_has_own_property */

/**
 * Checks whether the object has the given internal property.
 *
 * @return true  - if the internal property exists
 *         false - otherwise
 */
bool
jerry_has_internal_property (const jerry_value_t obj_val, /**< object value */
                             const jerry_value_t prop_name_val) /**< property name value */
{
  jerry_assert_api_available ();

  if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val))
  {
    return false;
  }

  ecma_object_t *obj_p = ecma_get_object_from_value (obj_val);

  ecma_string_t *internal_string_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_API_INTERNAL);

  if (ecma_op_object_is_fast_array (obj_p))
  {

Review comment (refactor):
AFAIK we could simplify this to:
```c
return jerry_return(ecma_op_object_has_own_property(...));
```
I don't think the skipping of `jerry_return` call worth the extra #if-def guard.

Code after:
  jerry_assert_api_enabled ();

  if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key))
  {
    return false;
  }

  ecma_object_t *obj_p = ecma_get_object_from_value (object);

  ecma_string_t *internal_string_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_API_INTERNAL);

  if (ecma_op_object_is_fast_array (obj_p))
  {
    return false;
  }

  ecma_property_t *property_p = ecma_find_named_property (obj_p, internal_string_p);

  if (property_p == NULL)
  {
    return false;
  }

  ecma_object_t *internal_object_p = ecma_get_object_from_value (ECMA_PROPERTY_VALUE_PTR (property_p)->value);
  property_p = ecma_find_named_property (internal_object_p, ecma_get_prop_name_from_value (key));

  return property_p != NULL;
} /* jerry_object_has_internal */

/**
 * Delete a property from an object.
 *
 * @return boolean value - wether the property was deleted successfully
 *         exception - otherwise
 */
jerry_value_t
jerry_object_delete (const jerry_value_t object, /**< object value */
                     const jerry_value_t key) /**< property name (string value) */
{
  jerry_assert_api_enabled ();

  if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key))
  {
    return false;
  }

  return ecma_op_object_delete (ecma_get_object_from_value (object), ecma_get_prop_name_from_value (key), false);
} /* jerry_object_delete */

/**
 * Delete indexed property from the specified object.