Skip to content

Implemented [[HasProperty]] for Objects. #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions jerry-core/ecma/operations/ecma-objects-arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,25 @@ ecma_op_arguments_object_define_own_property (ecma_object_t *obj_p, /**< the obj
return ret_value;
} /* ecma_op_arguments_object_define_own_property */

/**
* [[HasProperty]] ecma Arguments object's operation
*
* See also:
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
*
* @return true - if property exists,
* false - otherwise
*/
bool
ecma_op_arguments_object_has_property (ecma_object_t *obj_p, /**< the object */
ecma_string_t *property_name_p) /**< property name */
{
// 1.
ecma_property_t *desc_p = ecma_op_general_object_get_own_property (obj_p, property_name_p);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Dániel!

Why the implementation of [[HasProperty]] for Arguments object is different from implementation for other object types?


return !!desc_p;
} /* ecma_op_arguments_object_has_property */

/**
* [[Delete]] ecma Arguments object's operation
*
Expand Down
2 changes: 2 additions & 0 deletions jerry-core/ecma/operations/ecma-objects-arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ extern ecma_completion_value_t ecma_op_arguments_object_get (ecma_object_t *obj_
ecma_string_t *property_name_p);
extern ecma_property_t *ecma_op_arguments_object_get_own_property (ecma_object_t *obj_p,
ecma_string_t *property_name_p);
extern bool ecma_op_arguments_object_has_property (ecma_object_t *obj_p,
ecma_string_t *property_name_p);
extern ecma_completion_value_t ecma_op_arguments_object_delete (ecma_object_t *obj_p,
ecma_string_t *property_name_p,
bool is_throw);
Expand Down
23 changes: 23 additions & 0 deletions jerry-core/ecma/operations/ecma-objects-general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,29 @@ ecma_op_general_object_can_put (ecma_object_t *obj_p, /**< the object */
JERRY_UNREACHABLE();
} /* ecma_op_general_object_can_put */

/**
* [[HasProperty]] ecma general object's operation
*
* See also:
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
* ECMA-262 v5, 8.12.6
*
* @return true - if property exists,
* false - otherwise.
*/
bool
ecma_op_general_object_has_property (ecma_object_t *obj_p, /**< the object */
ecma_string_t *property_name_p) /**< property name */
{
JERRY_ASSERT(obj_p != NULL
&& !ecma_is_lexical_environment (obj_p));
JERRY_ASSERT(property_name_p != NULL);

ecma_property_t *prop_p = ecma_op_object_get_own_property (obj_p, property_name_p);

return !!prop_p;
} /* ecma_op_general_object_has_property */

/**
* [[Delete]] ecma general object's operation
*
Expand Down
2 changes: 2 additions & 0 deletions jerry-core/ecma/operations/ecma-objects-general.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ extern ecma_completion_value_t ecma_op_general_object_put (ecma_object_t *obj_p,
bool is_throw);
extern bool ecma_op_general_object_can_put (ecma_object_t *obj_p,
ecma_string_t *property_name_p);
extern bool ecma_op_general_object_has_property (ecma_object_t *obj_p,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[[HasProperty]] method of objects was inlined in places where the [[HasProperty]] should be called, i.e. instead of
if (ecma_op_object_has_property (...)),
something like the following is used:
if (ecma_op_object_get_property (...) != NULL).

The practice could be changed, if it is necessary or worthwhile.

In the case, please, place calls to the introduced ecma_op_object_has_property in currently implemented functionality, where calls to [[HasProperty]] are supposed by ECMA.

ecma_string_t *property_name_p);
extern ecma_completion_value_t ecma_op_general_object_delete (ecma_object_t *obj_p,
ecma_string_t *property_name_p,
bool is_throw);
Expand Down
44 changes: 44 additions & 0 deletions jerry-core/ecma/operations/ecma-objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,50 @@ ecma_op_object_can_put (ecma_object_t *obj_p, /**< the object */
return ecma_op_general_object_can_put (obj_p, property_name_p);
} /* ecma_op_object_can_put */

/**
* [[HasProperty]] ecma object's operation
*
* See also:
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
*
* @return true - if property exists,
* false - otherwise
*/
bool
ecma_op_object_has_property (ecma_object_t *obj_p, /**< the object */
ecma_string_t *property_name_p) /**< property name */
{
JERRY_ASSERT(obj_p != NULL
&& !ecma_is_lexical_environment (obj_p));
JERRY_ASSERT(property_name_p != NULL);

const ecma_object_type_t type = ecma_get_object_type (obj_p);
ecma_assert_object_type_is_valid (type);


switch (type)
{
case ECMA_OBJECT_TYPE_GENERAL:
case ECMA_OBJECT_TYPE_ARRAY:
case ECMA_OBJECT_TYPE_FUNCTION:
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
case ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION:
case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION:
case ECMA_OBJECT_TYPE_EXTENSION:
case ECMA_OBJECT_TYPE_STRING:
{
return ecma_op_general_object_has_property (obj_p, property_name_p);
}

case ECMA_OBJECT_TYPE_ARGUMENTS:
{
return ecma_op_arguments_object_has_property (obj_p, property_name_p);
}
}

JERRY_UNREACHABLE();
} /* ecma_op_object_has_property */

/**
* [[Delete]] ecma object's operation
*
Expand Down
1 change: 1 addition & 0 deletions jerry-core/ecma/operations/ecma-objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern ecma_completion_value_t ecma_op_object_put (ecma_object_t *obj_p,
ecma_value_t value,
bool is_throw);
extern bool ecma_op_object_can_put (ecma_object_t *obj_p, ecma_string_t *property_name_p);
extern bool ecma_op_object_has_property (ecma_object_t *obj_p, ecma_string_t *property_name_p);
extern ecma_completion_value_t ecma_op_object_delete (ecma_object_t *obj_p,
ecma_string_t *property_name_p,
bool is_throw);
Expand Down