Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/operations/ecma-proxy-object.c (C)

Code before:
  /* 18. */
  if (ECMA_IS_VALUE_ERROR (result_val))
  {
    if (ecma_is_value_true (target_status))
    {
      ecma_free_property_descriptor (&target_desc);
    }
    return result_val;
  }

  /* 20. */
  bool is_extensible = ecma_is_value_true (extensible_target);

  bool is_valid;
  if (ecma_is_value_true (target_status))
  {
    is_valid = ecma_op_is_compatible_property_descriptor (prop_desc_p, &target_desc, is_extensible);
  }
  else
  {
    is_valid = ecma_op_is_compatible_property_descriptor (prop_desc_p, NULL, is_extensible);
  }

  /* 21. */
  if (!is_valid)
  {
    if (ecma_is_value_true (target_status))
    {
      ecma_free_property_descriptor (&target_desc);
    }
    ecma_free_property_descriptor (prop_desc_p);
    return ecma_raise_type_error (ECMA_ERR_MSG ("The two descriptors are not compatible."));
  }

  /* 22. */
  if (!(prop_desc_p->flags & ECMA_PROP_IS_CONFIGURABLE))
  {
    if (ecma_is_value_false (target_status) || (target_desc.flags & ECMA_PROP_IS_CONFIGURABLE))
    {
      if (ecma_is_value_true (target_status))
      {
        ecma_free_property_descriptor (&target_desc);
      }
      ecma_free_property_descriptor (prop_desc_p);
      return ecma_raise_type_error (ECMA_ERR_MSG ("Not compatible."));
    }
  }

  if (ecma_is_value_true (target_status))
  {
    ecma_free_property_descriptor (&target_desc);

Review comment (refactor):
Maybe we could extract a bit of common part (the `target_desc` freeing). like:
```c

bool target_has_desc = ecma_is_value_true (target_status);
bool target_is_configurable = false;

if (target_has_desc)
{
  target_is_configurable = ((target_desc.flags & ECMA_PROP_IS_CONFIGURABLE) != 0);
  ecma_free_property_descriptor (&target_desc);
}

/* 21. */
if (!is_valid)
{
  ecma_free_property_descriptor (prop_desc_p);
  return ecma_raise_type_error (ECMA_ERR_MSG ("The two descriptors are not compatible."));
}

/* 22. */
else if (!(prop_desc_p->flags & ECMA_PROP_IS_CONFIGURABLE))
{
  if (!target_has_desc || target_is_configurable)
  {
    ecma_free_property_descriptor (prop_desc_p);
    return ecma_raise_type_error (ECMA_ERR_MSG ("Not compatible."));
  }
}
```

what do you think?

Code after:
  if (ECMA_IS_VALUE_ERROR (result_val))
  {
    if (ecma_is_value_true (target_status))
    {
      ecma_free_property_descriptor (&target_desc);
    }
    return result_val;
  }

  /* 20. */
  bool is_extensible = ecma_is_value_true (extensible_target);

  bool is_valid = ecma_op_is_compatible_property_descriptor (prop_desc_p,
                                                             (ecma_is_value_true (target_status) ? &target_desc : NULL),
                                                             is_extensible);

  bool target_has_desc = ecma_is_value_true (target_status);
  bool target_is_configurable = false;

  if (target_has_desc)
  {
    target_is_configurable = ((target_desc.flags & ECMA_PROP_IS_CONFIGURABLE) != 0);
    ecma_free_property_descriptor (&target_desc);
  }

  /* 21. */
  if (!is_valid)
  {
    ecma_free_property_descriptor (prop_desc_p);
    return ecma_raise_type_error (ECMA_ERR_MSG ("The two descriptors are not compatible."));
  }

  /* 22. */
  else if (!(prop_desc_p->flags & ECMA_PROP_IS_CONFIGURABLE))
  {
    if (!target_has_desc || target_is_configurable)
    {
      ecma_free_property_descriptor (prop_desc_p);
      return ecma_raise_type_error (ECMA_ERR_MSG ("Not compatible."));
    }
  }
  return ECMA_VALUE_TRUE;
} /* ecma_proxy_object_get_own_property_descriptor */

/**
 * The Proxy object [[DefineOwnProperty]] internal routine
 *
 * See also:
 *          ECMAScript v6, 9.5.6
 *
 * Note: Returned value is always a simple value so freeing it is unnecessary.