List of lazy instantiated properties' names in ecma_op_object_get_property_names.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
# error "Please, define BUILTIN_INC_HEADER_NAME"
|
||||
#endif /* !BUILTIN_INC_HEADER_NAME */
|
||||
|
||||
#include "ecma-objects.h"
|
||||
|
||||
#define PASTE__(x, y) x ## y
|
||||
#define PASTE_(x, y) PASTE__ (x, y)
|
||||
#define PASTE(x, y) PASTE_ (x, y)
|
||||
@@ -29,6 +31,8 @@
|
||||
PASTE (PASTE (ecma_builtin_, builtin_underscored_id), _sort_property_names)
|
||||
#define TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME(builtin_underscored_id) \
|
||||
PASTE (PASTE (ecma_builtin_, builtin_underscored_id), _try_to_instantiate_property)
|
||||
#define LIST_LAZY_PROPERTY_NAMES_ROUTINE_NAME(builtin_underscored_id) \
|
||||
PASTE (PASTE (ecma_builtin_, builtin_underscored_id), _list_lazy_property_names)
|
||||
#define DISPATCH_ROUTINE_ROUTINE_NAME(builtin_underscored_id) \
|
||||
PASTE (PASTE (ecma_builtin_, builtin_underscored_id), _dispatch_routine)
|
||||
|
||||
@@ -268,6 +272,122 @@ TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME (BUILTIN_UNDERSCORED_ID) (ecma_object_t
|
||||
return prop_p;
|
||||
} /* TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME */
|
||||
|
||||
/**
|
||||
* List names of the built-in object's lazy instantiated properties
|
||||
*
|
||||
* See also:
|
||||
* TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME
|
||||
*
|
||||
* @return string values collection
|
||||
*/
|
||||
void
|
||||
LIST_LAZY_PROPERTY_NAMES_ROUTINE_NAME (BUILTIN_UNDERSCORED_ID) (ecma_object_t *object_p, /**< a built-in object */
|
||||
/** true - list enumerable properties
|
||||
* into main collection,
|
||||
* and non-enumerable to
|
||||
* collection of 'skipped
|
||||
* non-enumerable'
|
||||
* properties,
|
||||
* false - list all properties into
|
||||
* main collection.
|
||||
*/
|
||||
bool separate_enumerable,
|
||||
/** 'main' collection */
|
||||
ecma_collection_header_t *main_collection_p,
|
||||
/** skipped 'non-enumerable' collection */
|
||||
ecma_collection_header_t *non_enum_collection_p)
|
||||
{
|
||||
ecma_collection_header_t *for_enumerable_p = main_collection_p;
|
||||
(void) for_enumerable_p;
|
||||
|
||||
ecma_collection_header_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
#define OBJECT_ID(builtin_id) const ecma_builtin_id_t builtin_object_id = builtin_id;
|
||||
#include BUILTIN_INC_HEADER_NAME
|
||||
|
||||
JERRY_ASSERT (ecma_builtin_is (object_p, builtin_object_id));
|
||||
|
||||
const ecma_length_t properties_number = (ecma_length_t) (sizeof (ecma_builtin_property_names) /
|
||||
sizeof (ecma_builtin_property_names[0]));
|
||||
|
||||
for (ecma_length_t i = 0;
|
||||
i < properties_number;
|
||||
i++)
|
||||
{
|
||||
lit_magic_string_id_t name = ecma_builtin_property_names[i];
|
||||
|
||||
int32_t index;
|
||||
index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_property_names,
|
||||
properties_number,
|
||||
name);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (object_p, mask_prop_id);
|
||||
bool is_instantiated = false;
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
is_instantiated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
is_instantiated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_instantiated = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_existing;
|
||||
|
||||
ecma_string_t *name_p = ecma_get_magic_string (name);
|
||||
|
||||
if (!is_instantiated)
|
||||
{
|
||||
/* will be instantiated upon first request */
|
||||
is_existing = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ecma_op_object_get_own_property (object_p, name_p) == NULL)
|
||||
{
|
||||
is_existing = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_existing = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_existing)
|
||||
{
|
||||
ecma_append_to_values_collection (for_non_enumerable_p,
|
||||
ecma_make_string_value (name_p),
|
||||
true);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (name_p);
|
||||
}
|
||||
} /* LIST_LAZY_PROPERTY_NAMES_ROUTINE_NAME */
|
||||
|
||||
|
||||
/**
|
||||
* Dispatcher of the built-in's routines
|
||||
*
|
||||
|
||||
@@ -85,6 +85,11 @@ extern ecma_property_t * \
|
||||
ecma_builtin_ ## lowercase_name ## _try_to_instantiate_property (ecma_object_t *, \
|
||||
ecma_string_t *); \
|
||||
extern void \
|
||||
ecma_builtin_ ## lowercase_name ## _list_lazy_property_names (ecma_object_t *, \
|
||||
bool, \
|
||||
ecma_collection_header_t *, \
|
||||
ecma_collection_header_t *); \
|
||||
extern void \
|
||||
ecma_builtin_ ## lowercase_name ## _sort_property_names (void);
|
||||
#include "ecma-builtins.inc.h"
|
||||
|
||||
|
||||
@@ -378,6 +378,83 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
|
||||
}
|
||||
} /* ecma_builtin_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* List names of a built-in object's lazy instantiated properties
|
||||
*
|
||||
* See also:
|
||||
* ecma_builtin_try_to_instantiate_property
|
||||
*/
|
||||
void
|
||||
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in object */
|
||||
bool separate_enumerable, /**< true - list enumerable properties into
|
||||
* main collection, and non-enumerable
|
||||
* to collection of 'skipped non-enumerable'
|
||||
* properties,
|
||||
* false - list all properties into main collection.
|
||||
*/
|
||||
ecma_collection_header_t *main_collection_p, /**< 'main' collection */
|
||||
ecma_collection_header_t *non_enum_collection_p) /**< skipped 'non-enumerable'
|
||||
* collection */
|
||||
{
|
||||
const ecma_object_type_t type = ecma_get_object_type (object_p);
|
||||
|
||||
if (type == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION)
|
||||
{
|
||||
ecma_collection_header_t *for_enumerable_p = main_collection_p;
|
||||
(void) for_enumerable_p;
|
||||
|
||||
ecma_collection_header_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
|
||||
ecma_string_t *name_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
|
||||
ecma_append_to_values_collection (for_non_enumerable_p, ecma_make_string_value (name_p), true);
|
||||
ecma_deref_ecma_string (name_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_property_t *built_in_id_prop_p = ecma_get_internal_property (object_p,
|
||||
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID);
|
||||
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_id_prop_p->u.internal_property.value;
|
||||
|
||||
JERRY_ASSERT (ecma_builtin_is (object_p, builtin_id));
|
||||
|
||||
switch (builtin_id)
|
||||
{
|
||||
#define BUILTIN(builtin_id, \
|
||||
object_type, \
|
||||
object_prototype_builtin_id, \
|
||||
is_extensible, \
|
||||
is_static, \
|
||||
lowercase_name) \
|
||||
case builtin_id: \
|
||||
{ \
|
||||
ecma_builtin_ ## lowercase_name ## _list_lazy_property_names (object_p, \
|
||||
separate_enumerable, \
|
||||
main_collection_p, \
|
||||
non_enum_collection_p); \
|
||||
return; \
|
||||
}
|
||||
#include "ecma-builtins.inc.h"
|
||||
|
||||
case ECMA_BUILTIN_ID__COUNT:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
#ifdef CONFIG_ECMA_COMPACT_PROFILE
|
||||
JERRY_UNREACHABLE ();
|
||||
#else /* CONFIG_ECMA_COMPACT_PROFILE */
|
||||
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
|
||||
#endif /* !CONFIG_ECMA_COMPACT_PROFILE */
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
} /* ecma_builtin_list_and_lazy_property_names */
|
||||
|
||||
/**
|
||||
* Construct a Function object for specified built-in routine
|
||||
*
|
||||
|
||||
@@ -44,6 +44,11 @@ extern ecma_completion_value_t
|
||||
ecma_builtin_dispatch_construct (ecma_object_t *, ecma_collection_header_t *);
|
||||
extern ecma_property_t *
|
||||
ecma_builtin_try_to_instantiate_property (ecma_object_t *, ecma_string_t *);
|
||||
extern void
|
||||
ecma_builtin_list_lazy_property_names (ecma_object_t *,
|
||||
bool,
|
||||
ecma_collection_header_t *,
|
||||
ecma_collection_header_t *);
|
||||
extern bool
|
||||
ecma_builtin_is (ecma_object_t *, ecma_builtin_id_t);
|
||||
extern ecma_object_t *
|
||||
|
||||
Reference in New Issue
Block a user