Rewrite property get/put to not use ecma_op_object_get_own_property
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-function-object.h"
|
||||
@@ -150,176 +149,6 @@ ecma_op_general_object_get_own_property (ecma_object_t *obj_p, /**< the object *
|
||||
return ecma_find_named_property (obj_p, property_name_p);
|
||||
} /* ecma_op_general_object_get_own_property */
|
||||
|
||||
/**
|
||||
* [[Put]] ecma general object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 8.12.5
|
||||
* Also incorporates [[CanPut]] ECMA-262 v5, 8.12.4
|
||||
*
|
||||
* @return ecma value
|
||||
* The returned value must be freed with ecma_free_value.
|
||||
*
|
||||
* Returns with ECMA_SIMPLE_VALUE_TRUE if the operation is
|
||||
* successful. Otherwise it returns with an error object
|
||||
* or ECMA_SIMPLE_VALUE_FALSE.
|
||||
*
|
||||
* Note: even if is_throw is false, the setter can throw an
|
||||
* error, and this function returns with that error.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_general_object_put (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p, /**< property name */
|
||||
ecma_value_t value, /**< ecma value */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
JERRY_ASSERT (obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT (property_name_p != NULL);
|
||||
|
||||
ecma_object_t *setter_p = NULL;
|
||||
|
||||
ecma_property_t *prop_p = ecma_op_object_get_own_property (obj_p, property_name_p);
|
||||
|
||||
if (prop_p != NULL)
|
||||
{
|
||||
if (ECMA_PROPERTY_GET_TYPE (prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA)
|
||||
{
|
||||
if (ecma_is_property_writable (prop_p))
|
||||
{
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
|
||||
if (type == ECMA_OBJECT_TYPE_ARGUMENTS
|
||||
|| (type == ECMA_OBJECT_TYPE_ARRAY && ecma_string_is_length (property_name_p)))
|
||||
{
|
||||
/* These cases cannot be optimized. */
|
||||
ecma_property_descriptor_t value_desc = ecma_make_empty_property_descriptor ();
|
||||
|
||||
value_desc.is_value_defined = true;
|
||||
value_desc.value = value;
|
||||
|
||||
return ecma_op_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
&value_desc,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
/* There is no need for special casing arrays here because changing the
|
||||
* value of an existing property never changes the length of an array. */
|
||||
ecma_named_data_property_assign_value (obj_p, prop_p, value);
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
|
||||
|
||||
setter_p = ecma_get_named_accessor_property_setter (prop_p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *proto_p = ecma_get_object_prototype (obj_p);
|
||||
bool create_new_property = true;
|
||||
|
||||
if (proto_p != NULL)
|
||||
{
|
||||
ecma_property_t *inherited_prop_p = ecma_op_object_get_property (proto_p, property_name_p);
|
||||
|
||||
if (inherited_prop_p != NULL)
|
||||
{
|
||||
if (ECMA_PROPERTY_GET_TYPE (inherited_prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR)
|
||||
{
|
||||
setter_p = ecma_get_named_accessor_property_setter (inherited_prop_p);
|
||||
create_new_property = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
create_new_property = ecma_is_property_writable (inherited_prop_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (create_new_property
|
||||
&& ecma_get_object_extensible (obj_p))
|
||||
{
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
|
||||
if (type == ECMA_OBJECT_TYPE_ARGUMENTS)
|
||||
{
|
||||
return ecma_builtin_helper_def_prop (obj_p,
|
||||
property_name_p,
|
||||
value,
|
||||
true, /* Writable */
|
||||
true, /* Enumerable */
|
||||
true, /* Configurable */
|
||||
is_throw); /* Failure handling */
|
||||
}
|
||||
|
||||
uint32_t index;
|
||||
|
||||
if (type == ECMA_OBJECT_TYPE_ARRAY
|
||||
&& ecma_string_get_array_index (property_name_p, &index))
|
||||
{
|
||||
/* Since the length of an array is a non-configurable named data
|
||||
* property, the prop_p must be a non-NULL pointer for all arrays. */
|
||||
|
||||
JERRY_ASSERT (!ecma_string_is_length (property_name_p));
|
||||
|
||||
ecma_string_t magic_string_length;
|
||||
ecma_init_ecma_length_string (&magic_string_length);
|
||||
|
||||
ecma_property_t *len_prop_p = ecma_op_object_get_own_property (obj_p, &magic_string_length);
|
||||
|
||||
JERRY_ASSERT (len_prop_p != NULL
|
||||
&& ECMA_PROPERTY_GET_TYPE (len_prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA);
|
||||
|
||||
uint32_t old_len = ecma_get_uint32_from_value (ecma_get_named_data_property_value (len_prop_p));
|
||||
|
||||
if (index < UINT32_MAX
|
||||
&& index >= old_len)
|
||||
{
|
||||
if (!ecma_is_property_writable (len_prop_p))
|
||||
{
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
ecma_property_value_t *len_prop_value_p = ECMA_PROPERTY_VALUE_PTR (len_prop_p);
|
||||
ecma_value_assign_uint32 (&len_prop_value_p->value, index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *new_prop_p;
|
||||
new_prop_p = ecma_create_named_data_property (obj_p,
|
||||
property_name_p,
|
||||
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_undefined (ecma_get_named_data_property_value (new_prop_p)));
|
||||
ecma_set_named_data_property_value (new_prop_p, ecma_copy_value_if_not_object (value));
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
if (setter_p == NULL)
|
||||
{
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
ecma_value_t ret_value = ecma_op_function_call (setter_p,
|
||||
ecma_make_object_value (obj_p),
|
||||
&value,
|
||||
1);
|
||||
|
||||
if (!ECMA_IS_VALUE_ERROR (ret_value))
|
||||
{
|
||||
ecma_fast_free_value (ret_value);
|
||||
ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_general_object_put */
|
||||
|
||||
/**
|
||||
* [[Delete]] ecma general object's operation
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user