mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Rework Object's [[OwnPropertyKeys]] (#4001)
I've removed the ecma_op_object_get_property_names method, and implemented the following ones: - ecma_op_object_own_property_keys: this is now the internal [[OwnPropertyKeys]] method - ecma_op_object_enumerate: this is used for the for-in iterator - ecma_object_sort_property_names: this is used for sorting the property names of an object - ecma_object_list_lazy_property_names: this is for getting the lazy instantiated properties - ecma_object_prop_name_is_duplicated: this is for checking if a given property is duplicated in an object Also the for-in operation with Proxy object works with this patch, #3992 should be closed JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
parent
3f0f9589c4
commit
ff47c84bc4
@ -2922,8 +2922,21 @@ jerry_get_object_keys (const jerry_value_t obj_val) /**< object value */
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (wrong_args_msg_p)));
|
||||
}
|
||||
|
||||
return ecma_builtin_helper_object_get_properties (ecma_get_object_from_value (obj_val),
|
||||
ECMA_LIST_ENUMERABLE);
|
||||
ecma_collection_t *prop_names = ecma_op_object_get_enumerable_property_names (ecma_get_object_from_value (obj_val),
|
||||
ECMA_ENUMERABLE_PROPERTY_KEYS);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (JERRY_UNLIKELY (prop_names == NULL))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
|
||||
ecma_value_t result_array = ecma_op_create_array_object (prop_names->buffer_p, prop_names->item_count, false);
|
||||
|
||||
ecma_collection_free (prop_names);
|
||||
|
||||
return result_array;
|
||||
} /* jerry_get_object_keys */
|
||||
|
||||
/**
|
||||
@ -3219,7 +3232,7 @@ jerry_foreach_object_property (const jerry_value_t obj_val, /**< object value */
|
||||
}
|
||||
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (obj_val);
|
||||
ecma_collection_t *names_p = ecma_op_object_get_property_names (object_p, ECMA_LIST_ENUMERABLE_PROTOTYPE);
|
||||
ecma_collection_t *names_p = ecma_op_object_enumerate (object_p);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (names_p == NULL)
|
||||
|
||||
@ -1431,7 +1431,7 @@ typedef struct
|
||||
* Compute the total allocated size of the collection based on it's capacity
|
||||
*/
|
||||
#define ECMA_COLLECTION_ALLOCATED_SIZE(capacity) \
|
||||
(uint32_t) (sizeof (ecma_collection_t) + (capacity * sizeof (ecma_value_t)))
|
||||
(uint32_t) (capacity * sizeof (ecma_value_t))
|
||||
|
||||
/**
|
||||
* Initial allocated size of an ecma-collection
|
||||
@ -2066,6 +2066,17 @@ typedef struct
|
||||
} ecma_revocable_proxy_object_t;
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
|
||||
/**
|
||||
* Struct for counting the different types properties in objects
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t array_index_named_props; /**< number of array index named properties */
|
||||
uint32_t string_named_props; /**< number of string named properties */
|
||||
uint32_t symbol_named_props; /**< number of symbol named properties */
|
||||
uint32_t lazy_string_named_props; /**< number of lazy instantiated properties */
|
||||
} ecma_property_counter_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
@ -187,6 +188,61 @@ ecma_collection_append (ecma_collection_t *collection_p, /**< value collection *
|
||||
collection_p->item_count += count;
|
||||
} /* ecma_collection_append */
|
||||
|
||||
/**
|
||||
* Helper function to check if a given collection have duplicated properties or not
|
||||
*
|
||||
* @return true - if there are duplicated properties in the collection
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
ecma_collection_check_duplicated_entries (ecma_collection_t *collection_p) /**< prop name collection */
|
||||
{
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < collection_p->item_count - 1; i++)
|
||||
{
|
||||
ecma_string_t *current_name_p = ecma_get_prop_name_from_value (buffer_p[i]);
|
||||
|
||||
for (uint32_t j = i + 1; j < collection_p->item_count; j++)
|
||||
{
|
||||
if (ecma_compare_ecma_strings (current_name_p, ecma_get_prop_name_from_value (buffer_p[j])))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} /* ecma_collection_check_duplicated_entries */
|
||||
|
||||
/**
|
||||
* Check the string value existance in the collection.
|
||||
*
|
||||
* Used by:
|
||||
* - ecma_builtin_json_stringify step 4.b.ii.5
|
||||
* - ecma_op_object_enumerate
|
||||
*
|
||||
* @return true, if the string is already in the collection.
|
||||
*/
|
||||
bool
|
||||
ecma_collection_has_string_value (ecma_collection_t *collection_p, /**< collection */
|
||||
ecma_string_t *string_p) /**< string */
|
||||
{
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *current_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
if (ecma_compare_ecma_strings (current_p, string_p))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} /* ecma_collection_has_string_value */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@ -439,6 +439,8 @@ void ecma_collection_destroy (ecma_collection_t *collection_p);
|
||||
void ecma_collection_free (ecma_collection_t *collection_p);
|
||||
void ecma_collection_free_if_not_object (ecma_collection_t *collection_p);
|
||||
void ecma_collection_free_objects (ecma_collection_t *collection_p);
|
||||
bool ecma_collection_check_duplicated_entries (ecma_collection_t *collection_p);
|
||||
bool ecma_collection_has_string_value (ecma_collection_t *collection_p, ecma_string_t *string_p);
|
||||
|
||||
/* ecma-helpers.c */
|
||||
ecma_object_t *ecma_create_object (ecma_object_t *prototype_object_p, size_t ext_object_size, ecma_object_type_t type);
|
||||
|
||||
@ -1079,38 +1079,38 @@ ecma_builtin_array_prototype_object_sort (ecma_value_t this_arg, /**< this argum
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Compare function is not callable."));
|
||||
}
|
||||
|
||||
ecma_collection_t *array_index_props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ARRAY_INDICES);
|
||||
ecma_collection_t *array_index_props_p = ecma_new_collection ();
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (array_index_props_p == NULL)
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
ecma_string_t *prop_name_p = ecma_new_ecma_string_from_uint32 (i);
|
||||
|
||||
uint32_t defined_prop_count = 0;
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
ecma_value_t get_desc = ecma_op_object_get_own_property_descriptor (obj_p, prop_name_p, &prop_desc);
|
||||
|
||||
ecma_value_t *buffer_p = array_index_props_p->buffer_p;
|
||||
|
||||
/* Count properties with name that is array index less than len */
|
||||
for (uint32_t i = 0; i < array_index_props_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
uint32_t index = ecma_string_get_array_index (property_name_p);
|
||||
JERRY_ASSERT (index != ECMA_STRING_NOT_ARRAY_INDEX);
|
||||
|
||||
if (index < len)
|
||||
if (ECMA_IS_VALUE_ERROR (get_desc))
|
||||
{
|
||||
defined_prop_count++;
|
||||
ecma_collection_free (array_index_props_p);
|
||||
ecma_deref_ecma_string (prop_name_p);
|
||||
return get_desc;
|
||||
}
|
||||
|
||||
if (ecma_is_value_true (get_desc))
|
||||
{
|
||||
ecma_ref_ecma_string (prop_name_p);
|
||||
ecma_collection_push_back (array_index_props_p, ecma_make_string_value (prop_name_p));
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t defined_prop_count = array_index_props_p->item_count;
|
||||
|
||||
ecma_value_t ret_value = ECMA_VALUE_ERROR;
|
||||
uint32_t copied_num = 0;
|
||||
JMEM_DEFINE_LOCAL_ARRAY (values_buffer, defined_prop_count, ecma_value_t);
|
||||
|
||||
buffer_p = array_index_props_p->buffer_p;
|
||||
ecma_value_t *buffer_p = array_index_props_p->buffer_p;
|
||||
|
||||
/* Copy unsorted array into a native c array. */
|
||||
for (uint32_t i = 0; i < array_index_props_p->item_count; i++)
|
||||
@ -1184,8 +1184,7 @@ clean_up:
|
||||
JERRY_ASSERT (ecma_is_value_empty (ret_value));
|
||||
|
||||
/* Undefined properties should be in the back of the array. */
|
||||
|
||||
buffer_p = array_index_props_p->buffer_p;
|
||||
ecma_value_t *buffer_p = array_index_props_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < array_index_props_p->item_count; i++)
|
||||
{
|
||||
|
||||
@ -54,33 +54,6 @@ ecma_json_has_object_in_stack (ecma_json_occurence_stack_item_t *stack_p, /**< s
|
||||
return false;
|
||||
} /* ecma_json_has_object_in_stack */
|
||||
|
||||
/**
|
||||
* Check the string value existance in the collection.
|
||||
*
|
||||
* Used by:
|
||||
* - ecma_builtin_json_stringify step 4.b.ii.5
|
||||
*
|
||||
* @return true, if the string is already in the collection.
|
||||
*/
|
||||
bool
|
||||
ecma_has_string_value_in_collection (ecma_collection_t *collection_p, /**< collection */
|
||||
ecma_string_t *string_p) /**< string */
|
||||
{
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
|
||||
for (uint32_t i = 0; i < collection_p->item_count; i++)
|
||||
{
|
||||
ecma_string_t *current_p = ecma_get_string_from_value (buffer_p[i]);
|
||||
|
||||
if (ecma_compare_ecma_strings (current_p, string_p))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} /* ecma_has_string_value_in_collection */
|
||||
|
||||
#endif /* ENABLED (JERRY_BUILTIN_JSON) */
|
||||
|
||||
/**
|
||||
|
||||
@ -226,42 +226,6 @@ ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /**< th
|
||||
return ret_string_p;
|
||||
} /* ecma_builtin_helper_get_to_locale_string_at_index */
|
||||
|
||||
/**
|
||||
* The Object's 'getOwnPropertyNames' routine.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.4 steps 2-5
|
||||
*
|
||||
* @return ecma value - Array of property names.
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, /**< object */
|
||||
uint32_t opts) /**< any combination of ecma_list_properties_options_t */
|
||||
{
|
||||
JERRY_ASSERT (obj_p != NULL);
|
||||
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, opts);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (props_p == NULL)
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
|
||||
if (props_p->item_count == 0)
|
||||
{
|
||||
ecma_collection_destroy (props_p);
|
||||
return ecma_op_create_array_object (NULL, 0, false);
|
||||
}
|
||||
|
||||
ecma_value_t new_array = ecma_op_create_array_object (props_p->buffer_p, props_p->item_count, false);
|
||||
ecma_collection_free (props_p);
|
||||
|
||||
return new_array;
|
||||
} /* ecma_builtin_helper_object_get_properties */
|
||||
|
||||
/**
|
||||
* Helper function to normalizing an array index
|
||||
*
|
||||
|
||||
@ -46,8 +46,6 @@ ecma_builtin_helper_object_to_string (const ecma_value_t this_arg);
|
||||
ecma_string_t *
|
||||
ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, uint32_t index);
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, uint32_t opts);
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, uint32_t *length_p, ecma_value_t value);
|
||||
uint32_t
|
||||
ecma_builtin_helper_array_index_normalize (ecma_value_t arg, uint32_t length, uint32_t *number_p);
|
||||
@ -216,7 +214,6 @@ ecma_value_t ecma_builtin_json_parse_buffer (const lit_utf8_byte_t * str_start_p
|
||||
lit_utf8_size_t string_size);
|
||||
ecma_value_t ecma_builtin_json_stringify_no_opts (const ecma_value_t value);
|
||||
bool ecma_json_has_object_in_stack (ecma_json_occurence_stack_item_t *stack_p, ecma_object_t *object_p);
|
||||
bool ecma_has_string_value_in_collection (ecma_collection_t *collection_p, ecma_string_t *string_p);
|
||||
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_json_create_non_formatted_json (lit_utf8_byte_t left_bracket, lit_utf8_byte_t right_bracket,
|
||||
|
||||
@ -694,7 +694,8 @@ ecma_builtin_json_internalize_property (ecma_object_t *reviver_p, /**< reviver f
|
||||
/* 3.d */
|
||||
else
|
||||
{
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (object_p, ECMA_LIST_ENUMERABLE);
|
||||
ecma_collection_t *props_p = ecma_op_object_get_enumerable_property_names (object_p,
|
||||
ECMA_ENUMERABLE_PROPERTY_KEYS);
|
||||
|
||||
JERRY_ASSERT (props_p != NULL);
|
||||
|
||||
@ -983,7 +984,7 @@ ecma_builtin_json_serialize_object (ecma_json_stringify_context_t *context_p, /*
|
||||
/* 6. */
|
||||
else
|
||||
{
|
||||
property_keys_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ENUMERABLE);
|
||||
property_keys_p = ecma_op_object_get_enumerable_property_names (obj_p, ECMA_ENUMERABLE_PROPERTY_KEYS);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (property_keys_p == NULL)
|
||||
@ -1573,7 +1574,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
|
||||
JERRY_ASSERT (ecma_is_value_string (item));
|
||||
ecma_string_t *string_p = ecma_get_string_from_value (item);
|
||||
|
||||
if (!ecma_has_string_value_in_collection (context.property_list_p, string_p))
|
||||
if (!ecma_collection_has_string_value (context.property_list_p, string_p))
|
||||
{
|
||||
ecma_collection_push_back (context.property_list_p, item);
|
||||
}
|
||||
|
||||
@ -55,13 +55,15 @@ enum
|
||||
ECMA_OBJECT_ROUTINE_ASSIGN,
|
||||
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTOR,
|
||||
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_DESCRIPTORS,
|
||||
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES,
|
||||
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS,
|
||||
ECMA_OBJECT_ROUTINE_GET_PROTOTYPE_OF,
|
||||
ECMA_OBJECT_ROUTINE_KEYS,
|
||||
ECMA_OBJECT_ROUTINE_VALUES,
|
||||
ECMA_OBJECT_ROUTINE_ENTRIES,
|
||||
|
||||
/* These should be in this order. */
|
||||
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES,
|
||||
ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS,
|
||||
|
||||
/* These should be in this order. */
|
||||
ECMA_OBJECT_ROUTINE_FREEZE,
|
||||
ECMA_OBJECT_ROUTINE_PREVENT_EXTENSIONS,
|
||||
@ -289,40 +291,6 @@ ecma_builtin_object_object_set_proto (ecma_value_t arg1, /**< routine's first ar
|
||||
} /* ecma_builtin_object_object_set_proto */
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
/**
|
||||
* The Object object's 'getOwnPropertyNames' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.4
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_get_own_property_names (ecma_object_t *obj_p) /**< routine's argument */
|
||||
{
|
||||
return ecma_builtin_helper_object_get_properties (obj_p, ECMA_LIST_NO_OPTS);
|
||||
} /* ecma_builtin_object_object_get_own_property_names */
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
|
||||
/**
|
||||
* The Object object's 'getOwnPropertySymbols' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v6, 19.1.2.7
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_get_own_property_symbols (ecma_object_t *obj_p) /**< routine's argument */
|
||||
{
|
||||
return ecma_builtin_helper_object_get_properties (obj_p, ECMA_LIST_SYMBOLS_ONLY);
|
||||
} /* ecma_builtin_object_object_get_own_property_symbols */
|
||||
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
/**
|
||||
* SetIntegrityLevel operation
|
||||
*
|
||||
@ -349,20 +317,13 @@ ecma_builtin_object_set_integrity_level (ecma_object_t *obj_p, /**< object */
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
{
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
ecma_op_ordinary_object_prevent_extensions (obj_p);
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
|
||||
/* 6. */
|
||||
uint32_t opts = ECMA_LIST_CONVERT_FAST_ARRAYS;
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
opts |= ECMA_LIST_SYMBOLS;
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, opts);
|
||||
ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (props_p == NULL)
|
||||
@ -606,12 +567,10 @@ ecma_builtin_object_test_integrity_level (ecma_object_t *obj_p, /**< routine's a
|
||||
is_extensible = ecma_is_value_true (status);
|
||||
}
|
||||
else
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
{
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
is_extensible = ecma_op_ordinary_object_is_extensible (obj_p);
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
|
||||
if (is_extensible)
|
||||
{
|
||||
@ -622,7 +581,7 @@ ecma_builtin_object_test_integrity_level (ecma_object_t *obj_p, /**< routine's a
|
||||
ecma_value_t ret_value = ECMA_VALUE_TRUE;
|
||||
|
||||
/* 2. */
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_NO_OPTS);
|
||||
ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (props_p == NULL)
|
||||
@ -780,7 +739,7 @@ static ecma_value_t
|
||||
ecma_builtin_object_object_get_own_property_descriptors (ecma_object_t *obj_p) /**< routine's first argument */
|
||||
{
|
||||
/* 2 */
|
||||
ecma_collection_t *prop_names_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_SYMBOLS);
|
||||
ecma_collection_t *prop_names_p = ecma_op_object_own_property_keys (obj_p);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (prop_names_p == NULL)
|
||||
@ -841,6 +800,7 @@ ecma_builtin_object_object_get_own_property_descriptors (ecma_object_t *obj_p) /
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.7
|
||||
* ECMA-262 v11, 19.1.2.3.1
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
@ -858,14 +818,9 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
|
||||
}
|
||||
|
||||
ecma_object_t *props_p = ecma_get_object_from_value (props);
|
||||
|
||||
/* 3. */
|
||||
uint32_t options = ECMA_LIST_CONVERT_FAST_ARRAYS | ECMA_LIST_ENUMERABLE;
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
options |= ECMA_LIST_SYMBOLS;
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
ecma_collection_t *prop_names_p = ecma_op_object_get_property_names (props_p, options);
|
||||
ecma_collection_t *prop_names_p = ecma_op_object_own_property_keys (props_p);
|
||||
ecma_value_t ret_value = ECMA_VALUE_ERROR;
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
@ -881,40 +836,67 @@ ecma_builtin_object_object_define_properties (ecma_object_t *obj_p, /**< routine
|
||||
/* 4. */
|
||||
JMEM_DEFINE_LOCAL_ARRAY (property_descriptors, prop_names_p->item_count, ecma_property_descriptor_t);
|
||||
uint32_t property_descriptor_number = 0;
|
||||
ecma_collection_t *enum_prop_names = ecma_new_collection ();
|
||||
|
||||
/* 5. */
|
||||
for (uint32_t i = 0; i < prop_names_p->item_count; i++)
|
||||
{
|
||||
/* 5.a */
|
||||
ecma_value_t desc_obj = ecma_op_object_get (props_p, ecma_get_prop_name_from_value (buffer_p[i]));
|
||||
ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (buffer_p[i]);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (desc_obj))
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
ecma_value_t get_desc = ecma_op_object_get_own_property_descriptor (props_p,
|
||||
prop_name_p,
|
||||
&prop_desc);
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
if (ECMA_IS_VALUE_ERROR (get_desc))
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
/* 5.b */
|
||||
ecma_value_t conv_result = ecma_op_to_property_descriptor (desc_obj,
|
||||
&property_descriptors[property_descriptor_number]);
|
||||
|
||||
property_descriptors[property_descriptor_number].flags |= ECMA_PROP_IS_THROW;
|
||||
|
||||
ecma_free_value (desc_obj);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (conv_result))
|
||||
if (ecma_is_value_true (get_desc))
|
||||
{
|
||||
goto cleanup;
|
||||
if (prop_desc.flags & ECMA_PROP_IS_ENUMERABLE)
|
||||
{
|
||||
ecma_value_t desc_obj = ecma_op_object_get (props_p, prop_name_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (desc_obj))
|
||||
{
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ecma_value_t conv_result = ecma_op_to_property_descriptor (desc_obj,
|
||||
&property_descriptors[property_descriptor_number]);
|
||||
|
||||
property_descriptors[property_descriptor_number].flags |= ECMA_PROP_IS_THROW;
|
||||
|
||||
ecma_free_value (desc_obj);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (conv_result))
|
||||
{
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
property_descriptor_number++;
|
||||
ecma_free_value (conv_result);
|
||||
ecma_ref_ecma_string (prop_name_p);
|
||||
ecma_collection_push_back (enum_prop_names, buffer_p[i]);
|
||||
}
|
||||
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
}
|
||||
|
||||
property_descriptor_number++;
|
||||
|
||||
ecma_free_value (conv_result);
|
||||
}
|
||||
|
||||
/* 6. */
|
||||
for (uint32_t i = 0; i < prop_names_p->item_count; i++)
|
||||
for (uint32_t i = 0; i < enum_prop_names->item_count; i++)
|
||||
{
|
||||
ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (enum_prop_names->buffer_p[i]);
|
||||
|
||||
ecma_value_t define_own_prop_ret = ecma_op_object_define_own_property (obj_p,
|
||||
ecma_get_prop_name_from_value (buffer_p[i]),
|
||||
prop_name_p,
|
||||
&property_descriptors[i]);
|
||||
if (ECMA_IS_VALUE_ERROR (define_own_prop_ret))
|
||||
{
|
||||
@ -936,6 +918,8 @@ cleanup:
|
||||
ecma_free_property_descriptor (&property_descriptors[index]);
|
||||
}
|
||||
|
||||
ecma_collection_free (enum_prop_names);
|
||||
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (property_descriptors);
|
||||
|
||||
ecma_collection_free (prop_names_p);
|
||||
@ -1071,8 +1055,8 @@ ecma_builtin_object_object_assign (ecma_object_t *target_p, /**< target object *
|
||||
ecma_object_t *from_obj_p = ecma_get_object_from_value (from_value);
|
||||
|
||||
/* 5.b.iii */
|
||||
ecma_collection_t *props_p = ecma_op_object_get_property_names (from_obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS
|
||||
| ECMA_LIST_SYMBOLS);
|
||||
ecma_collection_t *props_p = ecma_op_object_own_property_keys (from_obj_p);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (props_p == NULL)
|
||||
{
|
||||
@ -1166,6 +1150,71 @@ ecma_builtin_object_object_is (ecma_value_t arg1, /**< routine's first argument
|
||||
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
/**
|
||||
* GetOwnPropertyKeys abstract method
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v11, 19.1.2.11.1
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_op_object_get_own_property_keys (ecma_value_t this_arg, /**< this argument */
|
||||
uint16_t type) /**< routine type */
|
||||
{
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
/* 1. */
|
||||
ecma_value_t object = ecma_op_to_object (this_arg);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (object))
|
||||
{
|
||||
return object;
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (object);
|
||||
|
||||
/* 2. */
|
||||
ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p);
|
||||
|
||||
if (props_p == NULL)
|
||||
{
|
||||
ecma_deref_object (obj_p);
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
/* 3. */
|
||||
ecma_collection_t *name_list = ecma_new_collection ();
|
||||
|
||||
/* 4. */
|
||||
for (uint32_t i = 0; i < props_p->item_count; i++)
|
||||
{
|
||||
ecma_value_t prop_name = props_p->buffer_p[i];
|
||||
ecma_string_t *name_p = ecma_get_prop_name_from_value (prop_name);
|
||||
|
||||
if ((ecma_prop_name_is_symbol (name_p) && type == ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS)
|
||||
|| (ecma_is_value_string (prop_name) && type == ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES))
|
||||
{
|
||||
ecma_ref_ecma_string (name_p);
|
||||
ecma_collection_push_back (name_list, prop_name);
|
||||
}
|
||||
}
|
||||
|
||||
ecma_value_t result_array = ecma_op_create_array_object (name_list->buffer_p, name_list->item_count, false);
|
||||
|
||||
ecma_deref_object (obj_p);
|
||||
ecma_collection_free (name_list);
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
JERRY_UNUSED (type);
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p);
|
||||
ecma_value_t result_array = ecma_op_create_array_object (props_p->buffer_p, props_p->item_count, false);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
ecma_collection_free (props_p);
|
||||
return result_array;
|
||||
} /* ecma_op_object_get_own_property_keys */
|
||||
|
||||
/**
|
||||
* Dispatcher of the built-in's routines
|
||||
*
|
||||
@ -1269,22 +1318,12 @@ ecma_builtin_object_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
|
||||
result = ecma_builtin_object_object_get_prototype_of (obj_p);
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES:
|
||||
{
|
||||
result = ecma_builtin_object_object_get_own_property_names (obj_p);
|
||||
break;
|
||||
}
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
case ECMA_OBJECT_ROUTINE_ASSIGN:
|
||||
{
|
||||
result = ecma_builtin_object_object_assign (obj_p, arguments_list_p + 1, arguments_number - 1);
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS:
|
||||
{
|
||||
result = ecma_builtin_object_object_get_own_property_symbols (obj_p);
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_ROUTINE_ENTRIES:
|
||||
case ECMA_OBJECT_ROUTINE_VALUES:
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
@ -1329,6 +1368,10 @@ ecma_builtin_object_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
return result;
|
||||
}
|
||||
else if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS)
|
||||
{
|
||||
return ecma_op_object_get_own_property_keys (arg1, builtin_routine_id);
|
||||
}
|
||||
else if (builtin_routine_id <= ECMA_OBJECT_ROUTINE_SEAL)
|
||||
{
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
|
||||
@ -165,8 +165,21 @@ ecma_builtin_reflect_dispatch_routine (uint16_t builtin_routine_id, /**< built-i
|
||||
|
||||
ecma_object_t *target_p = ecma_get_object_from_value (arguments_list[0]);
|
||||
|
||||
/* 2. 3. */
|
||||
return ecma_builtin_helper_object_get_properties (target_p, ECMA_LIST_SYMBOLS);
|
||||
/* 2. */
|
||||
ecma_collection_t *prop_names = ecma_op_object_own_property_keys (target_p);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (prop_names == NULL)
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
|
||||
/* 3. */
|
||||
ecma_value_t new_array = ecma_op_create_array_object (prop_names->buffer_p, prop_names->item_count, false);
|
||||
ecma_collection_free (prop_names);
|
||||
|
||||
return new_array;
|
||||
}
|
||||
|
||||
if (builtin_routine_id == ECMA_REFLECT_OBJECT_CONSTRUCT)
|
||||
|
||||
@ -1041,43 +1041,32 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
|
||||
*/
|
||||
void
|
||||
ecma_builtin_routine_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in object */
|
||||
uint32_t opts, /**< listing options using flags
|
||||
* from ecma_list_properties_options_t */
|
||||
ecma_collection_t *main_collection_p, /**< 'main' collection */
|
||||
ecma_collection_t *non_enum_collection_p) /**< skipped 'non-enumerable'
|
||||
* collection */
|
||||
ecma_collection_t *prop_names_p, /**< prop name collection */
|
||||
ecma_property_counter_t *prop_counter_p) /**< prop counter */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
|
||||
JERRY_ASSERT (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION);
|
||||
JERRY_ASSERT (ecma_builtin_function_is_routine (object_p));
|
||||
|
||||
const bool separate_enumerable = (opts & ECMA_LIST_ENUMERABLE) != 0;
|
||||
const bool is_array_indices_only = (opts & ECMA_LIST_ARRAY_INDICES) != 0;
|
||||
|
||||
ecma_collection_t *for_enumerable_p = main_collection_p;
|
||||
JERRY_UNUSED (for_enumerable_p);
|
||||
|
||||
ecma_collection_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
if (!is_array_indices_only)
|
||||
{
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
|
||||
if (!(ext_func_p->u.built_in.u.builtin_routine.bitset & ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED))
|
||||
{
|
||||
/* Unintialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
}
|
||||
if (!(ext_func_p->u.built_in.u.builtin_routine.bitset & ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED))
|
||||
{
|
||||
/* Unintialized 'name' property is non-enumerable (ECMA-262 v6, 19.2.4.2) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_NAME));
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
|
||||
if (!(ext_func_p->u.built_in.u.builtin_routine.bitset & ECMA_BUILTIN_ROUTINE_LENGTH_INITIALIZED))
|
||||
{
|
||||
/* Unintialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
prop_counter_p->string_named_props++;
|
||||
}
|
||||
if (!(ext_func_p->u.built_in.u.builtin_routine.bitset & ECMA_BUILTIN_ROUTINE_NAME_INITIALIZED))
|
||||
{
|
||||
/* Unintialized 'name' property is non-enumerable (ECMA-262 v6, 19.2.4.2) */
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_NAME));
|
||||
prop_counter_p->string_named_props++;
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
prop_counter_p->string_named_props++;
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
} /* ecma_builtin_routine_list_lazy_property_names */
|
||||
|
||||
/**
|
||||
@ -1088,19 +1077,13 @@ ecma_builtin_routine_list_lazy_property_names (ecma_object_t *object_p, /**< a b
|
||||
*/
|
||||
void
|
||||
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in object */
|
||||
uint32_t opts, /**< listing options using flags
|
||||
* from ecma_list_properties_options_t */
|
||||
ecma_collection_t *main_collection_p, /**< 'main' collection */
|
||||
ecma_collection_t *non_enum_collection_p) /**< skipped 'non-enumerable'
|
||||
* collection */
|
||||
ecma_collection_t *prop_names_p, /**< prop name collection */
|
||||
ecma_property_counter_t *prop_counter_p) /**< prop counter */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
|
||||
JERRY_ASSERT (ecma_get_object_type (object_p) != ECMA_OBJECT_TYPE_FUNCTION
|
||||
|| !ecma_builtin_function_is_routine (object_p));
|
||||
|
||||
const bool separate_enumerable = (opts & ECMA_LIST_ENUMERABLE) != 0;
|
||||
const bool is_array_indices_only = (opts & ECMA_LIST_ARRAY_INDICES) != 0;
|
||||
|
||||
ecma_built_in_props_t *built_in_props_p;
|
||||
ecma_object_type_t object_type = ecma_get_object_type (object_p);
|
||||
|
||||
@ -1123,9 +1106,6 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
|
||||
uint32_t index = 0;
|
||||
uint32_t *bitset_p = built_in_props_p->u.instantiated_bitset;
|
||||
|
||||
ecma_collection_t *for_non_enumerable_p = (separate_enumerable ? non_enum_collection_p
|
||||
: main_collection_p);
|
||||
|
||||
while (curr_property_p->magic_string_id != LIT_MAGIC_STRING__COUNT)
|
||||
{
|
||||
if (index == 32)
|
||||
@ -1145,28 +1125,13 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
|
||||
|
||||
ecma_string_t *name_p = ecma_get_magic_string ((lit_magic_string_id_t) curr_property_p->magic_string_id);
|
||||
|
||||
if (is_array_indices_only && ecma_string_get_array_index (name_p) == ECMA_STRING_NOT_ARRAY_INDEX)
|
||||
{
|
||||
curr_property_p++;
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t bit_for_index = (uint32_t) 1u << index;
|
||||
|
||||
if (!(*bitset_p & bit_for_index) || ecma_op_ordinary_object_has_own_property (object_p, name_p))
|
||||
{
|
||||
ecma_value_t name = ecma_make_magic_string_value ((lit_magic_string_id_t) curr_property_p->magic_string_id);
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
if (curr_property_p->attributes & ECMA_PROPERTY_FLAG_ENUMERABLE)
|
||||
{
|
||||
ecma_collection_push_back (main_collection_p, name);
|
||||
}
|
||||
else
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
{
|
||||
ecma_collection_push_back (for_non_enumerable_p, name);
|
||||
}
|
||||
ecma_collection_push_back (prop_names_p, name);
|
||||
prop_counter_p->string_named_props++;
|
||||
}
|
||||
|
||||
curr_property_p++;
|
||||
|
||||
@ -93,14 +93,12 @@ ecma_property_t *
|
||||
ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, ecma_string_t *string_p);
|
||||
void
|
||||
ecma_builtin_routine_list_lazy_property_names (ecma_object_t *object_p,
|
||||
uint32_t opts,
|
||||
ecma_collection_t *main_collection_p,
|
||||
ecma_collection_t *non_enum_collection_p);
|
||||
ecma_collection_t *prop_names_p,
|
||||
ecma_property_counter_t *prop_counter_p);
|
||||
void
|
||||
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p,
|
||||
uint32_t opts,
|
||||
ecma_collection_t *main_collection_p,
|
||||
ecma_collection_t *non_enum_collection_p);
|
||||
ecma_collection_t *prop_names_p,
|
||||
ecma_property_counter_t *prop_counter_p);
|
||||
bool
|
||||
ecma_builtin_is (ecma_object_t *obj_p, ecma_builtin_id_t builtin_id);
|
||||
ecma_object_t *
|
||||
|
||||
@ -511,61 +511,35 @@ ecma_fast_array_set_length (ecma_object_t *object_p, /**< fast access mode array
|
||||
* @return collection of strings - property names
|
||||
*/
|
||||
ecma_collection_t *
|
||||
ecma_fast_array_get_property_names (ecma_object_t *object_p, /**< fast access mode array object */
|
||||
uint32_t opts) /**< any combination of ecma_list_properties_options_t values */
|
||||
ecma_fast_array_object_own_property_keys (ecma_object_t *object_p) /**< fast access mode array object */
|
||||
{
|
||||
JERRY_ASSERT (ecma_op_object_is_fast_array (object_p));
|
||||
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;
|
||||
ecma_collection_t *ret_p = ecma_new_collection ();
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
if (opts & ECMA_LIST_SYMBOLS_ONLY)
|
||||
{
|
||||
return ret_p;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
uint32_t length = ext_obj_p->u.array.length;
|
||||
|
||||
bool append_length = (!(opts & ECMA_LIST_ENUMERABLE) && !(opts & ECMA_LIST_ARRAY_INDICES));
|
||||
|
||||
if (length == 0)
|
||||
if (length != 0)
|
||||
{
|
||||
if (append_length)
|
||||
ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp);
|
||||
|
||||
for (uint32_t i = 0; i < length; i++)
|
||||
{
|
||||
ecma_collection_push_back (ret_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
if (ecma_is_value_array_hole (values_p[i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (i);
|
||||
|
||||
ecma_collection_push_back (ret_p, ecma_make_string_value (index_str_p));
|
||||
}
|
||||
|
||||
return ret_p;
|
||||
}
|
||||
|
||||
ecma_value_t *values_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, object_p->u1.property_list_cp);
|
||||
|
||||
for (uint32_t i = 0; i < length; i++)
|
||||
{
|
||||
if (ecma_is_value_array_hole (values_p[i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (i);
|
||||
|
||||
ecma_collection_push_back (ret_p, ecma_make_string_value (index_str_p));
|
||||
}
|
||||
|
||||
if (append_length)
|
||||
{
|
||||
ecma_collection_push_back (ret_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
}
|
||||
|
||||
if (opts & ECMA_LIST_CONVERT_FAST_ARRAYS)
|
||||
{
|
||||
ecma_fast_array_convert_to_normal (object_p);
|
||||
}
|
||||
ecma_collection_push_back (ret_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
|
||||
return ret_p;
|
||||
} /* ecma_fast_array_get_property_names */
|
||||
} /* ecma_fast_array_object_own_property_keys */
|
||||
|
||||
/**
|
||||
* Array object creation operation.
|
||||
@ -1240,30 +1214,6 @@ ecma_array_object_to_string (ecma_value_t this_arg) /**< this argument */
|
||||
return ret_value;
|
||||
} /* ecma_array_object_to_string */
|
||||
|
||||
/**
|
||||
* List names of a String object's lazy instantiated properties
|
||||
*
|
||||
* @return string values collection
|
||||
*/
|
||||
void
|
||||
ecma_op_array_list_lazy_property_names (ecma_object_t *obj_p, /**< a String object */
|
||||
uint32_t opts, /**< listing options using flags
|
||||
* from ecma_list_properties_options_t */
|
||||
ecma_collection_t *main_collection_p, /**< 'main' collection */
|
||||
ecma_collection_t *non_enum_collection_p) /**< skipped
|
||||
* 'non-enumerable'
|
||||
* collection */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY);
|
||||
|
||||
ecma_collection_t *for_non_enumerable_p = (opts & ECMA_LIST_ENUMERABLE) ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
if ((opts & ECMA_LIST_ARRAY_INDICES) == 0)
|
||||
{
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
}
|
||||
} /* ecma_op_array_list_lazy_property_names */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@ -90,7 +90,7 @@ uint32_t
|
||||
ecma_delete_fast_array_properties (ecma_object_t *object_p, uint32_t new_length);
|
||||
|
||||
ecma_collection_t *
|
||||
ecma_fast_array_get_property_names (ecma_object_t *object_p, uint32_t opts);
|
||||
ecma_fast_array_object_own_property_keys (ecma_object_t *object_p);
|
||||
|
||||
void
|
||||
ecma_fast_array_convert_to_normal (ecma_object_t *object_p);
|
||||
@ -121,12 +121,6 @@ uint32_t ecma_array_get_length (ecma_object_t *array_p);
|
||||
ecma_value_t
|
||||
ecma_array_object_to_string (ecma_value_t this_arg);
|
||||
|
||||
void
|
||||
ecma_op_array_list_lazy_property_names (ecma_object_t *obj_p,
|
||||
uint32_t opts,
|
||||
ecma_collection_t *main_collection_p,
|
||||
ecma_collection_t *non_enum_collection_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@ -1747,27 +1747,21 @@ ecma_op_bound_function_try_to_lazy_instantiate_property (ecma_object_t *object_p
|
||||
*/
|
||||
void
|
||||
ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functionobject */
|
||||
uint32_t opts, /**< listing options using flags
|
||||
* from ecma_list_properties_options_t */
|
||||
ecma_collection_t *main_collection_p, /**< 'main' collection */
|
||||
ecma_collection_t *non_enum_collection_p) /**< skipped
|
||||
* 'non-enumerable'
|
||||
* collection */
|
||||
ecma_collection_t *prop_names_p, /**< prop name collection */
|
||||
ecma_property_counter_t *prop_counter_p) /**< prop counter */
|
||||
{
|
||||
JERRY_UNUSED (main_collection_p);
|
||||
|
||||
ecma_collection_t *for_non_enumerable_p = (opts & ECMA_LIST_ENUMERABLE) ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
|
||||
if (!ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (ext_func_p->u.function.scope_cp))
|
||||
{
|
||||
/* Unintialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
prop_counter_p->string_named_props++;
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
/* 'length' property is non-enumerable (ECMA-262 v5, 13.2.5) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
prop_counter_p->string_named_props++;
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
const ecma_compiled_code_t *bytecode_data_p;
|
||||
@ -1781,7 +1775,8 @@ ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functio
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
/* 'prototype' property is non-enumerable (ECMA-262 v5, 13.2.18) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_PROTOTYPE));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_PROTOTYPE));
|
||||
prop_counter_p->string_named_props++;
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
bool append_caller_and_arguments = !(bytecode_data_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE);
|
||||
@ -1792,10 +1787,12 @@ ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functio
|
||||
if (append_caller_and_arguments)
|
||||
{
|
||||
/* 'caller' property is non-enumerable (ECMA-262 v5, 13.2.5) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_CALLER));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_CALLER));
|
||||
|
||||
/* 'arguments' property is non-enumerable (ECMA-262 v5, 13.2.5) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_ARGUMENTS));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_ARGUMENTS));
|
||||
|
||||
prop_counter_p->string_named_props += 2;
|
||||
}
|
||||
} /* ecma_op_function_list_lazy_property_names */
|
||||
|
||||
@ -1808,16 +1805,9 @@ ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functio
|
||||
*/
|
||||
void
|
||||
ecma_op_external_function_list_lazy_property_names (ecma_object_t *object_p, /**< function object */
|
||||
uint32_t opts, /**< listing options using flags
|
||||
* from ecma_list_properties_options_t */
|
||||
ecma_collection_t *main_collection_p, /**< 'main' collection */
|
||||
ecma_collection_t *non_enum_collection_p) /**< skipped
|
||||
* collection */
|
||||
ecma_collection_t *prop_names_p, /**< prop name collection */
|
||||
ecma_property_counter_t *prop_counter_p) /**< prop counter */
|
||||
{
|
||||
JERRY_UNUSED (main_collection_p);
|
||||
|
||||
ecma_collection_t *for_non_enumerable_p = (opts & ECMA_LIST_ENUMERABLE) ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
#if !ENABLED (JERRY_ESNEXT)
|
||||
JERRY_UNUSED (object_p);
|
||||
#else /* ENABLED (JERRY_ESNEXT) */
|
||||
@ -1825,7 +1815,8 @@ ecma_op_external_function_list_lazy_property_names (ecma_object_t *object_p, /**
|
||||
#endif /* !ENABLED (JERRY_ESNEXT) */
|
||||
{
|
||||
/* 'prototype' property is non-enumerable (ECMA-262 v5, 13.2.18) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_PROTOTYPE));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_PROTOTYPE));
|
||||
prop_counter_p->string_named_props++;
|
||||
}
|
||||
} /* ecma_op_external_function_list_lazy_property_names */
|
||||
|
||||
@ -1838,35 +1829,31 @@ ecma_op_external_function_list_lazy_property_names (ecma_object_t *object_p, /**
|
||||
*/
|
||||
void
|
||||
ecma_op_bound_function_list_lazy_property_names (ecma_object_t *object_p, /**< bound function object*/
|
||||
uint32_t opts, /**< listing options using flags
|
||||
* from ecma_list_properties_options_t */
|
||||
ecma_collection_t *main_collection_p, /**< 'main' collection */
|
||||
ecma_collection_t *non_enum_collection_p) /**< skipped
|
||||
* 'non-enumerable'
|
||||
* collection */
|
||||
ecma_collection_t *prop_names_p, /**< prop name collection */
|
||||
ecma_property_counter_t *prop_counter_p) /**< prop counter */
|
||||
{
|
||||
JERRY_UNUSED (main_collection_p);
|
||||
|
||||
ecma_collection_t *for_non_enumerable_p = (opts & ECMA_LIST_ENUMERABLE) ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
/* Unintialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */
|
||||
ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p;
|
||||
if (!ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (bound_func_p->header.u.bound_function.target_function))
|
||||
{
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
prop_counter_p->string_named_props++;
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
JERRY_UNUSED (object_p);
|
||||
/* 'length' property is non-enumerable (ECMA-262 v5, 13.2.5) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
prop_counter_p->string_named_props++;
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
/* 'caller' property is non-enumerable (ECMA-262 v5, 13.2.5) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_CALLER));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_CALLER));
|
||||
|
||||
/* 'arguments' property is non-enumerable (ECMA-262 v5, 13.2.5) */
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_ARGUMENTS));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_ARGUMENTS));
|
||||
|
||||
prop_counter_p->string_named_props += 2;
|
||||
} /* ecma_op_bound_function_list_lazy_property_names */
|
||||
|
||||
/**
|
||||
|
||||
@ -89,21 +89,18 @@ ecma_op_bound_function_try_to_lazy_instantiate_property (ecma_object_t *object_p
|
||||
|
||||
void
|
||||
ecma_op_function_list_lazy_property_names (ecma_object_t *object_p,
|
||||
uint32_t opts,
|
||||
ecma_collection_t *main_collection_p,
|
||||
ecma_collection_t *non_enum_collection_p);
|
||||
ecma_collection_t *prop_names_p,
|
||||
ecma_property_counter_t *prop_counter_p);
|
||||
|
||||
void
|
||||
ecma_op_external_function_list_lazy_property_names (ecma_object_t *object_p,
|
||||
uint32_t opts,
|
||||
ecma_collection_t *main_collection_p,
|
||||
ecma_collection_t *non_enum_collection_p);
|
||||
ecma_collection_t *prop_names_p,
|
||||
ecma_property_counter_t *prop_counter_p);
|
||||
|
||||
void
|
||||
ecma_op_bound_function_list_lazy_property_names (ecma_object_t *object_p,
|
||||
uint32_t opts,
|
||||
ecma_collection_t *main_collection_p,
|
||||
ecma_collection_t *non_enum_collection_p);
|
||||
ecma_collection_t *prop_names_p,
|
||||
ecma_property_counter_t *prop_counter_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -67,9 +67,10 @@ ecma_value_t ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p
|
||||
ecma_property_descriptor_t *prop_desc_p);
|
||||
ecma_value_t ecma_op_object_has_instance (ecma_object_t *obj_p, ecma_value_t value);
|
||||
ecma_value_t ecma_op_object_is_prototype_of (ecma_object_t *base_p, ecma_object_t *target_p);
|
||||
ecma_collection_t * ecma_op_object_get_property_names (ecma_object_t *obj_p, uint32_t opts);
|
||||
ecma_collection_t * ecma_op_object_get_enumerable_property_names (ecma_object_t *obj_p,
|
||||
ecma_enumerable_property_names_options_t option);
|
||||
ecma_collection_t *ecma_op_object_own_property_keys (ecma_object_t *obj_p);
|
||||
ecma_collection_t *ecma_op_object_enumerate (ecma_object_t *obj_p);
|
||||
|
||||
lit_magic_string_id_t ecma_object_get_class_name (ecma_object_t *obj_p);
|
||||
bool ecma_object_class_is (ecma_object_t *object_p, uint32_t class_id);
|
||||
|
||||
@ -1396,25 +1396,6 @@ ecma_proxy_object_delete_property (ecma_object_t *obj_p, /**< proxy object */
|
||||
return ret_value;
|
||||
} /* ecma_proxy_object_delete_property */
|
||||
|
||||
/**
|
||||
* The Proxy object [[Enumerate]] internal routine
|
||||
*
|
||||
* See also:
|
||||
* ECMAScript v6, 9.5.11
|
||||
*
|
||||
* Note: Returned value must be freed with ecma_free_value.
|
||||
*
|
||||
* @return ECMA_VALUE_ERROR - if the operation fails
|
||||
* ecma-object - otherwise
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_proxy_object_enumerate (ecma_object_t *obj_p) /**< proxy object */
|
||||
{
|
||||
JERRY_ASSERT (ECMA_OBJECT_IS_PROXY (obj_p));
|
||||
JERRY_UNUSED (obj_p);
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy.[[Enumerate]]"));
|
||||
} /* ecma_proxy_object_enumerate */
|
||||
|
||||
/**
|
||||
* Helper method for the Proxy object [[OwnPropertyKeys]] operation
|
||||
*
|
||||
@ -1532,7 +1513,7 @@ ecma_proxy_check_invariants_for_own_prop_keys (ecma_collection_t *trap_result,
|
||||
* The Proxy object [[OwnPropertyKeys]] internal routine
|
||||
*
|
||||
* See also:
|
||||
* ECMAScript v6, 9.5.12
|
||||
* ECMAScript v11, 9.5.11
|
||||
*
|
||||
* Note: If the returned collection is not NULL, it must be freed with
|
||||
* ecma_collection_free if it is no longer needed
|
||||
@ -1553,7 +1534,6 @@ ecma_proxy_object_own_property_keys (ecma_object_t *obj_p) /**< proxy object */
|
||||
/* 2-5. */
|
||||
ecma_value_t trap = ecma_validate_proxy_object (handler, LIT_MAGIC_STRING_OWN_KEYS_UL);
|
||||
|
||||
/* 6. */
|
||||
if (ECMA_IS_VALUE_ERROR (trap))
|
||||
{
|
||||
return NULL;
|
||||
@ -1562,15 +1542,15 @@ ecma_proxy_object_own_property_keys (ecma_object_t *obj_p) /**< proxy object */
|
||||
ecma_value_t target = proxy_obj_p->target;
|
||||
ecma_object_t *target_obj_p = ecma_get_object_from_value (target);
|
||||
|
||||
/* 7. */
|
||||
/* 6. */
|
||||
if (ecma_is_value_undefined (trap))
|
||||
{
|
||||
return ecma_op_object_get_property_names (target_obj_p, ECMA_LIST_SYMBOLS);
|
||||
return ecma_op_object_own_property_keys (target_obj_p);
|
||||
}
|
||||
|
||||
ecma_object_t *func_obj_p = ecma_get_object_from_value (trap);
|
||||
|
||||
/* 8. */
|
||||
/* 7. */
|
||||
ecma_value_t trap_result_array = ecma_op_function_call (func_obj_p, handler, &target, 1);
|
||||
|
||||
ecma_deref_object (func_obj_p);
|
||||
@ -1580,46 +1560,51 @@ ecma_proxy_object_own_property_keys (ecma_object_t *obj_p) /**< proxy object */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 9. */
|
||||
/* 8. */
|
||||
ecma_collection_t *trap_result = ecma_op_create_list_from_array_like (trap_result_array, true);
|
||||
|
||||
ecma_free_value (trap_result_array);
|
||||
|
||||
/* 10. */
|
||||
if (trap_result == NULL)
|
||||
{
|
||||
return trap_result;
|
||||
}
|
||||
|
||||
/* 11. */
|
||||
/* 9. */
|
||||
if (ecma_collection_check_duplicated_entries (trap_result))
|
||||
{
|
||||
ecma_collection_free (trap_result);
|
||||
ecma_raise_type_error (ECMA_ERR_MSG ("Trap returned duplicate entries"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 10. */
|
||||
ecma_value_t extensible_target = ecma_builtin_object_object_is_extensible (target_obj_p);
|
||||
|
||||
/* 12. */
|
||||
if (ECMA_IS_VALUE_ERROR (extensible_target))
|
||||
{
|
||||
ecma_collection_free (trap_result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 13. */
|
||||
ecma_collection_t *target_keys = ecma_op_object_get_property_names (target_obj_p, ECMA_LIST_SYMBOLS);
|
||||
/* 11. */
|
||||
ecma_collection_t *target_keys = ecma_op_object_own_property_keys (target_obj_p);
|
||||
|
||||
/* 14. */
|
||||
if (target_keys == NULL)
|
||||
{
|
||||
ecma_collection_free (trap_result);
|
||||
return target_keys;
|
||||
}
|
||||
|
||||
/* 16. */
|
||||
/* 14. */
|
||||
ecma_collection_t *target_configurable_keys = ecma_new_collection ();
|
||||
|
||||
/* 17. */
|
||||
/* 15. */
|
||||
ecma_collection_t *target_non_configurable_keys = ecma_new_collection ();
|
||||
|
||||
ecma_collection_t *ret_value = NULL;
|
||||
|
||||
/* 18. */
|
||||
/* 16. */
|
||||
for (uint32_t i = 0; i < target_keys->item_count; i++)
|
||||
{
|
||||
ecma_property_descriptor_t target_desc;
|
||||
@ -1654,12 +1639,12 @@ ecma_proxy_object_own_property_keys (ecma_object_t *obj_p) /**< proxy object */
|
||||
}
|
||||
}
|
||||
|
||||
/* 19. */
|
||||
/* 17. */
|
||||
if (ecma_is_value_true (extensible_target) && target_non_configurable_keys->item_count == 0)
|
||||
{
|
||||
ret_value = trap_result;
|
||||
}
|
||||
/* 20-25. */
|
||||
/* 18-22. */
|
||||
else if (ecma_proxy_check_invariants_for_own_prop_keys (trap_result,
|
||||
target_non_configurable_keys,
|
||||
target_configurable_keys,
|
||||
@ -1678,6 +1663,7 @@ free_target_collections:
|
||||
ecma_collection_free (target_configurable_keys);
|
||||
ecma_collection_free (target_non_configurable_keys);
|
||||
|
||||
/* 23. */
|
||||
return ret_value;
|
||||
} /* ecma_proxy_object_own_property_keys */
|
||||
|
||||
|
||||
@ -92,9 +92,6 @@ ecma_value_t
|
||||
ecma_proxy_object_delete_property (ecma_object_t *obj_p,
|
||||
ecma_string_t *prop_name_p);
|
||||
|
||||
ecma_value_t
|
||||
ecma_proxy_object_enumerate (ecma_object_t *obj_p);
|
||||
|
||||
ecma_collection_t *
|
||||
ecma_proxy_object_own_property_keys (ecma_object_t *obj_p);
|
||||
|
||||
|
||||
@ -84,19 +84,11 @@ ecma_op_create_string_object (const ecma_value_t *arguments_list_p, /**< list of
|
||||
*/
|
||||
void
|
||||
ecma_op_string_list_lazy_property_names (ecma_object_t *obj_p, /**< a String object */
|
||||
uint32_t opts, /**< listing options using flags
|
||||
* from ecma_list_properties_options_t */
|
||||
ecma_collection_t *main_collection_p, /**< 'main' collection */
|
||||
ecma_collection_t *non_enum_collection_p) /**< skipped
|
||||
* 'non-enumerable'
|
||||
* collection */
|
||||
ecma_collection_t *prop_names_p, /**< prop name collection */
|
||||
ecma_property_counter_t *prop_counter_p) /**< prop counter */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_CLASS);
|
||||
|
||||
ecma_collection_t *for_enumerable_p = main_collection_p;
|
||||
|
||||
ecma_collection_t *for_non_enumerable_p = (opts & ECMA_LIST_ENUMERABLE) ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
|
||||
JERRY_ASSERT (ext_object_p->u.class_prop.class_id == LIT_MAGIC_STRING_STRING_UL);
|
||||
|
||||
@ -109,13 +101,13 @@ ecma_op_string_list_lazy_property_names (ecma_object_t *obj_p, /**< a String obj
|
||||
ecma_string_t *name_p = ecma_new_ecma_string_from_uint32 (i);
|
||||
|
||||
/* the properties are enumerable (ECMA-262 v5, 15.5.5.2.9) */
|
||||
ecma_collection_push_back (for_enumerable_p, ecma_make_string_value (name_p));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_string_value (name_p));
|
||||
}
|
||||
|
||||
if ((opts & ECMA_LIST_ARRAY_INDICES) == 0)
|
||||
{
|
||||
ecma_collection_push_back (for_non_enumerable_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
}
|
||||
prop_counter_p->array_index_named_props += length;
|
||||
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH));
|
||||
prop_counter_p->string_named_props++;
|
||||
} /* ecma_op_string_list_lazy_property_names */
|
||||
|
||||
/**
|
||||
|
||||
@ -30,9 +30,8 @@ ecma_op_create_string_object (const ecma_value_t *arguments_list_p, uint32_t arg
|
||||
|
||||
void
|
||||
ecma_op_string_list_lazy_property_names (ecma_object_t *obj_p,
|
||||
uint32_t opts,
|
||||
ecma_collection_t *main_collection_p,
|
||||
ecma_collection_t *non_enum_collection_p);
|
||||
ecma_collection_t *prop_names_p,
|
||||
ecma_property_counter_t *prop_counter_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@ -1300,7 +1300,8 @@ ecma_is_typedarray (ecma_value_t value) /**< the target need to be checked */
|
||||
*/
|
||||
void
|
||||
ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p, /**< a TypedArray object */
|
||||
ecma_collection_t *main_collection_p) /**< 'main' collection */
|
||||
ecma_collection_t *prop_names_p, /**< prop name collection */
|
||||
ecma_property_counter_t *prop_counter_p) /**< prop counter */
|
||||
{
|
||||
JERRY_ASSERT (ecma_object_is_typedarray (obj_p));
|
||||
|
||||
@ -1309,9 +1310,10 @@ ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p, /**< a TypedA
|
||||
for (uint32_t i = 0; i < array_length; i++)
|
||||
{
|
||||
ecma_string_t *name_p = ecma_new_ecma_string_from_uint32 (i);
|
||||
|
||||
ecma_collection_push_back (main_collection_p, ecma_make_string_value (name_p));
|
||||
ecma_collection_push_back (prop_names_p, ecma_make_string_value (name_p));
|
||||
}
|
||||
|
||||
prop_counter_p->array_index_named_props += array_length;
|
||||
} /* ecma_op_typedarray_list_lazy_property_names */
|
||||
|
||||
/**
|
||||
|
||||
@ -64,7 +64,8 @@ ecma_typedarray_iterators_helper (ecma_value_t this_arg, ecma_iterator_kind_t ki
|
||||
bool ecma_object_is_typedarray (ecma_object_t *obj_p);
|
||||
bool ecma_is_typedarray (ecma_value_t target);
|
||||
void ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p,
|
||||
ecma_collection_t *main_collection_p);
|
||||
ecma_collection_t *prop_names_p,
|
||||
ecma_property_counter_t *prop_counter_p);
|
||||
bool ecma_op_typedarray_define_index_prop (ecma_object_t *obj_p,
|
||||
uint32_t index,
|
||||
const ecma_property_descriptor_t *property_desc_p);
|
||||
|
||||
@ -345,10 +345,7 @@ opfunc_for_in (ecma_value_t left_value, /**< left value */
|
||||
/* ecma_op_to_object will only raise error on null/undefined values but those are handled above. */
|
||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (obj_expr_value));
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_expr_value);
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (obj_p));
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
ecma_collection_t *prop_names_p = ecma_op_object_get_property_names (obj_p, ECMA_LIST_ENUMERABLE_PROTOTYPE);
|
||||
ecma_collection_t *prop_names_p = ecma_op_object_enumerate (obj_p);
|
||||
|
||||
if (prop_names_p->item_count != 0)
|
||||
{
|
||||
|
||||
@ -1773,7 +1773,8 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (result);
|
||||
ecma_collection_t *names_p = ecma_op_object_get_property_names (object_p, ECMA_LIST_ENUMERABLE);
|
||||
ecma_collection_t *names_p = ecma_op_object_get_enumerable_property_names (object_p,
|
||||
ECMA_ENUMERABLE_PROPERTY_KEYS);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (names_p == NULL)
|
||||
@ -3712,21 +3713,6 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
|
||||
JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p);
|
||||
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (ecma_is_value_object (value)
|
||||
&& ECMA_OBJECT_IS_PROXY (ecma_get_object_from_value (value)))
|
||||
{
|
||||
/* Note: - For proxy objects we should create a new object which implements the iterable protocol,
|
||||
and iterates through the enumerated collection below.
|
||||
- This inkoves that the VM context type should be adjusted and checked in all FOR-IN related
|
||||
instruction.
|
||||
- For other objects we should keep the current implementation due to performance reasons.*/
|
||||
result = ecma_raise_type_error (ECMA_ERR_MSG ("UNIMPLEMENTED: Proxy support in for-in."));
|
||||
ecma_free_value (value);
|
||||
goto error;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
|
||||
ecma_value_t expr_obj_value = ECMA_VALUE_UNDEFINED;
|
||||
ecma_collection_t *prop_names_p = opfunc_for_in (value, &expr_obj_value);
|
||||
ecma_free_value (value);
|
||||
@ -3784,9 +3770,6 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
ecma_value_t *buffer_p = collection_p->buffer_p;
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (stack_top_p[-4]);
|
||||
uint32_t index = stack_top_p[-3];
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
JERRY_ASSERT (!ECMA_OBJECT_IS_PROXY (object_p));
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
|
||||
while (index < collection_p->item_count)
|
||||
{
|
||||
|
||||
24
tests/jerry/es.next/array-prototype-sort.js
Normal file
24
tests/jerry/es.next/array-prototype-sort.js
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var proxy = new Proxy({length: 5}, {
|
||||
getOwnPropertyDescriptor() { throw 42.5; }
|
||||
})
|
||||
|
||||
try {
|
||||
Array.prototype.sort.call(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e === 42.5);
|
||||
}
|
||||
@ -39,7 +39,7 @@ assert(getProperties(func) == "dummy");
|
||||
|
||||
var bound_func = (function() {}).bind(null);
|
||||
Object.setPrototypeOf(bound_func, prototype_obj);
|
||||
assert(getProperties(bound_func) == "dummy prototype");
|
||||
assert(getProperties(bound_func) == "dummy caller arguments prototype");
|
||||
|
||||
// 'print' is an external function
|
||||
Object.setPrototypeOf(print, prototype_obj);
|
||||
|
||||
@ -124,7 +124,6 @@ assert (object[symbol] === "a symbol");
|
||||
assert (object.bar === 42);
|
||||
assert (object[symbol] === undefined);
|
||||
|
||||
// This code should throw TypeError
|
||||
var object = {};
|
||||
var props = {
|
||||
[symbol]: {
|
||||
@ -142,9 +141,9 @@ var props = {
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
Object.defineProperties(object, props);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
Object.defineProperties(object, props);
|
||||
var bar_desc = Object.getOwnPropertyDescriptor(object, 'bar');
|
||||
assert(bar_desc.value === 2);
|
||||
assert(bar_desc.writable === true);
|
||||
assert(object.prop1 === undefined);
|
||||
assert(object[symbol] === undefined);
|
||||
|
||||
@ -31,14 +31,6 @@ var handler = { ownKeys (target) {
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
try {
|
||||
// Array.prototype.sort
|
||||
Array.prototype.sort.call(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e === 42);
|
||||
}
|
||||
|
||||
try {
|
||||
// 19.1.2.14.4
|
||||
Object.keys(proxy);
|
||||
@ -63,6 +55,14 @@ try {
|
||||
assert(e === 42);
|
||||
}
|
||||
|
||||
var handler = { ownKeys (target) {
|
||||
return ["a"];
|
||||
}};
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
var sort_result = Array.prototype.sort.call(proxy);
|
||||
assert(Object.keys(sort_result).length === 0);
|
||||
|
||||
// test basic functionality
|
||||
var symA = Symbol("smA");
|
||||
var symB = Symbol("smB");
|
||||
@ -149,16 +149,18 @@ try {
|
||||
}
|
||||
|
||||
// test with duplicated keys
|
||||
var target = { prop1: "prop1", prop2: "prop2"};
|
||||
var handler = {
|
||||
var p = new Proxy({}, {
|
||||
ownKeys: function(target) {
|
||||
return ["a", "a", "a"];
|
||||
}
|
||||
};
|
||||
return ["foo", "foo"];
|
||||
}
|
||||
});
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
assert(JSON.stringify(Object.getOwnPropertyNames(proxy)) === '["a","a","a"]');
|
||||
try {
|
||||
Object.keys(p);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
// test with lots of keys
|
||||
var keyslist = [];
|
||||
@ -240,4 +242,4 @@ var handler = {
|
||||
var proxy = new Proxy(object, handler);
|
||||
|
||||
assert(Object.keys(proxy).length === 1);
|
||||
assert(Object.keys(proxy)[0] === "b");
|
||||
assert(Object.keys(proxy)[0] === "b");
|
||||
@ -12,11 +12,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var a = new Proxy({}, {});
|
||||
var a = new Proxy({ a : 4, b :4}, {});
|
||||
var reached = false;
|
||||
|
||||
try {
|
||||
for (var $ in a);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
for (var $ in a)
|
||||
{
|
||||
reached = true;
|
||||
}
|
||||
|
||||
assert (reached === true);
|
||||
|
||||
@ -174,7 +174,6 @@ assert (obj.a === "b");
|
||||
assert (obj.bar === 42);
|
||||
assert (obj.a === undefined);
|
||||
|
||||
// This code should throw TypeError
|
||||
var obj = {};
|
||||
var props = {
|
||||
prop1: {
|
||||
@ -196,9 +195,15 @@ var props = {
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
Object.defineProperties(obj, props);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
Object.defineProperties(obj, props);
|
||||
var bar_desc = Object.getOwnPropertyDescriptor(obj, 'bar');
|
||||
assert(bar_desc.value === 2);
|
||||
assert(bar_desc.writable === true);
|
||||
assert(obj.prop2 === undefined);
|
||||
|
||||
var prop1_desc = Object.getOwnPropertyDescriptor(obj, 'prop1');
|
||||
var prop3_desc = Object.getOwnPropertyDescriptor(obj, 'prop3');
|
||||
assert(prop1_desc.value === 1);
|
||||
assert(prop1_desc.writable === true);
|
||||
assert(prop3_desc.value === 4);
|
||||
assert(prop3_desc.writable === true);
|
||||
|
||||
@ -64,10 +64,15 @@
|
||||
<test id="built-ins/Promise/race/species-get-error.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/call-parameters.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/return-is-abrupt.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/result-not-an-object-throws-boolean.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/result-not-an-object-throws-number.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/result-not-an-object-throws-string.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/result-not-an-object-throws-symbol.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/result-not-an-object-throws-undefined.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/null-handler.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/return-trap-result.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/return-trap-result-no-value.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/trap-is-undefined.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/getOwnPropertyDescriptor/trap-is-undefined.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/trap-is-not-callable.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Reflect/enumerate/does-not-iterate-over-symbol-properties.js"><reason></reason></test>
|
||||
<test id="built-ins/Reflect/enumerate/enumerate.js"><reason></reason></test>
|
||||
<test id="built-ins/Reflect/enumerate/length.js"><reason></reason></test>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user