Skip to content

Commit 14599ed

Browse files
committed
Rework own property enumeration
Properry name filtering is done during the enumeration. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent d368ecd commit 14599ed

10 files changed

+318
-199
lines changed

jerry-core/api/jerry.c

+8-29
Original file line numberDiff line numberDiff line change
@@ -4604,6 +4604,12 @@ jerry_object_get_property_names (const jerry_value_t obj_val, /**< object */
46044604

46054605
ecma_ref_object (obj_iter_p);
46064606

4607+
if ((filter & JERRY_PROPERTY_FILTER_EXLCUDE_STRINGS)
4608+
&& !(filter & JERRY_PROPERTY_FILTER_INTEGER_INDICES_AS_NUMBER))
4609+
{
4610+
filter |= JERRY_PROPERTY_FILTER_EXLCUDE_INTEGER_INDICES;
4611+
}
4612+
46074613
while (true)
46084614
{
46094615
/* Step 1. Get Object.[[OwnKeys]] */
@@ -4623,34 +4629,7 @@ jerry_object_get_property_names (const jerry_value_t obj_val, /**< object */
46234629
ecma_string_t *key_p = ecma_get_prop_name_from_value (key);
46244630
uint32_t index = ecma_string_get_array_index (key_p);
46254631

4626-
/* Step 2. Filter by key type */
4627-
if (filter & (JERRY_PROPERTY_FILTER_EXLCUDE_STRINGS
4628-
| JERRY_PROPERTY_FILTER_EXLCUDE_SYMBOLS
4629-
| JERRY_PROPERTY_FILTER_EXLCUDE_INTEGER_INDICES))
4630-
{
4631-
if (ecma_is_value_symbol (key))
4632-
{
4633-
if (filter & JERRY_PROPERTY_FILTER_EXLCUDE_SYMBOLS)
4634-
{
4635-
continue;
4636-
}
4637-
}
4638-
else if (index != ECMA_STRING_NOT_ARRAY_INDEX)
4639-
{
4640-
if ((filter & JERRY_PROPERTY_FILTER_EXLCUDE_INTEGER_INDICES)
4641-
|| ((filter & JERRY_PROPERTY_FILTER_EXLCUDE_STRINGS)
4642-
&& !(filter & JERRY_PROPERTY_FILTER_INTEGER_INDICES_AS_NUMBER)))
4643-
{
4644-
continue;
4645-
}
4646-
}
4647-
else if (filter & JERRY_PROPERTY_FILTER_EXLCUDE_STRINGS)
4648-
{
4649-
continue;
4650-
}
4651-
}
4652-
4653-
/* Step 3. Filter property attributes */
4632+
/* Step 2. Filter property attributes */
46544633
if (filter & (JERRY_PROPERTY_FILTER_EXLCUDE_NON_CONFIGURABLE
46554634
| JERRY_PROPERTY_FILTER_EXLCUDE_NON_ENUMERABLE
46564635
| JERRY_PROPERTY_FILTER_EXLCUDE_NON_WRITABLE))
@@ -4729,7 +4708,7 @@ jerry_object_get_property_names (const jerry_value_t obj_val, /**< object */
47294708

47304709
ecma_collection_free (prop_names_p);
47314710

4732-
/* Step 4: Traverse prototype chain */
4711+
/* Step 3: Traverse prototype chain */
47334712

47344713
if ((filter & JERRY_PROPERTY_FILTER_TRAVERSE_PROTOTYPE_CHAIN) != JERRY_PROPERTY_FILTER_TRAVERSE_PROTOTYPE_CHAIN)
47354714
{

jerry-core/ecma/base/ecma-globals.h

-2
Original file line numberDiff line numberDiff line change
@@ -2439,8 +2439,6 @@ typedef struct
24392439
uint32_t array_index_named_props; /**< number of array index named properties */
24402440
uint32_t string_named_props; /**< number of string named properties */
24412441
uint32_t symbol_named_props; /**< number of symbol named properties */
2442-
uint32_t lazy_string_named_props; /**< number of lazy instantiated string properties */
2443-
uint32_t lazy_symbol_named_props; /**< number of lazy instantiated symbol properties */
24442442
} ecma_property_counter_t;
24452443

24462444
/**

jerry-core/ecma/base/ecma-module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ ecma_module_heap_sort_shift_down (ecma_value_t *buffer_p, /**< array of items */
670670
while (true)
671671
{
672672
uint32_t highest_index = item_index;
673-
uint32_t current_index = item_index * 2 + 2;
673+
uint32_t current_index = (item_index << 1) + 2;
674674

675675
if (current_index >= item_count)
676676
{

jerry-core/ecma/builtin-objects/ecma-builtin-object.c

+2-24
Original file line numberDiff line numberDiff line change
@@ -1336,36 +1336,14 @@ ecma_op_object_get_own_property_keys (ecma_value_t this_arg, /**< this argument
13361336
}
13371337

13381338
ecma_collection_t *props_p = ecma_op_object_own_property_keys (obj_p, filter);
1339+
ecma_deref_object (obj_p);
13391340

13401341
if (props_p == NULL)
13411342
{
1342-
ecma_deref_object (obj_p);
13431343
return ECMA_VALUE_ERROR;
13441344
}
13451345

1346-
/* 3. */
1347-
ecma_collection_t *name_list_p = ecma_new_collection ();
1348-
1349-
/* 4. */
1350-
for (uint32_t i = 0; i < props_p->item_count; i++)
1351-
{
1352-
ecma_value_t prop_name = props_p->buffer_p[i];
1353-
ecma_string_t *name_p = ecma_get_prop_name_from_value (prop_name);
1354-
1355-
if ((ecma_prop_name_is_symbol (name_p) && type == ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_SYMBOLS)
1356-
|| (ecma_is_value_string (prop_name) && type == ECMA_OBJECT_ROUTINE_GET_OWN_PROPERTY_NAMES))
1357-
{
1358-
ecma_ref_ecma_string (name_p);
1359-
ecma_collection_push_back (name_list_p, prop_name);
1360-
}
1361-
}
1362-
1363-
ecma_value_t result_array = ecma_op_new_array_object_from_collection (name_list_p, false);
1364-
1365-
ecma_deref_object (obj_p);
1366-
ecma_collection_free (props_p);
1367-
1368-
return result_array;
1346+
return ecma_op_new_array_object_from_collection (props_p, false);
13691347
#else /* !JERRY_ESNEXT */
13701348
JERRY_UNUSED (type);
13711349
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);

jerry-core/ecma/builtin-objects/ecma-builtin-reflect.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ ecma_builtin_reflect_dispatch_routine (uint8_t builtin_routine_id, /**< built-in
206206
return ecma_raise_type_error (ECMA_ERR_MSG ("Reflect.construct expects an object as second argument"));
207207
}
208208

209-
ecma_collection_t *coll_p = ecma_op_create_list_from_array_like (arguments_list[1], false);
209+
ecma_collection_t *coll_p = ecma_op_create_list_from_array_like (arguments_list[1], ECMA_FROM_ARRAY_LIKE_ANY);
210210

211211
if (coll_p == NULL)
212212
{

jerry-core/ecma/operations/ecma-conversion.c

+57-4
Original file line numberDiff line numberDiff line change
@@ -1083,8 +1083,7 @@ ecma_op_to_index (ecma_value_t value, /**< ecma value */
10831083
*/
10841084
ecma_collection_t *
10851085
ecma_op_create_list_from_array_like (ecma_value_t arr, /**< array value */
1086-
bool prop_names_only) /**< true - accept only property names
1087-
false - otherwise */
1086+
uint32_t options) /**< from array like and property name filter flags */
10881087
{
10891088
/* 1. */
10901089
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (arr));
@@ -1095,10 +1094,12 @@ ecma_op_create_list_from_array_like (ecma_value_t arr, /**< array value */
10951094
ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_argument_is_not_an_object));
10961095
return NULL;
10971096
}
1097+
10981098
ecma_object_t *obj_p = ecma_get_object_from_value (arr);
10991099

11001100
/* 4. 5. */
11011101
ecma_length_t len;
1102+
11021103
if (ECMA_IS_VALUE_ERROR (ecma_op_object_get_length (obj_p, &len)))
11031104
{
11041105
return NULL;
@@ -1107,18 +1108,69 @@ ecma_op_create_list_from_array_like (ecma_value_t arr, /**< array value */
11071108
/* 6. */
11081109
ecma_collection_t *list_ptr = ecma_new_collection ();
11091110

1111+
if (!(options & ECMA_FROM_ARRAY_LIKE_ONLY_PROP_NAMES))
1112+
{
1113+
/* 7. 8. */
1114+
for (ecma_length_t idx = 0; idx < len; idx++)
1115+
{
1116+
ecma_value_t next = ecma_op_object_get_by_index (obj_p, idx);
1117+
1118+
if (ECMA_IS_VALUE_ERROR (next))
1119+
{
1120+
ecma_collection_free (list_ptr);
1121+
return NULL;
1122+
}
1123+
1124+
ecma_collection_push_back (list_ptr, next);
1125+
}
1126+
1127+
/* 9. */
1128+
return list_ptr;
1129+
}
1130+
11101131
/* 7. 8. */
11111132
for (ecma_length_t idx = 0; idx < len; idx++)
11121133
{
11131134
ecma_value_t next = ecma_op_object_get_by_index (obj_p, idx);
1135+
11141136
if (ECMA_IS_VALUE_ERROR (next))
11151137
{
11161138
ecma_collection_free (list_ptr);
11171139
return NULL;
11181140
}
11191141

1120-
if (prop_names_only
1121-
&& !ecma_is_value_prop_name (next))
1142+
if (ecma_is_value_string (next))
1143+
{
1144+
jerry_property_filter_t non_symbol_mask = (JERRY_PROPERTY_FILTER_EXLCUDE_STRINGS
1145+
| JERRY_PROPERTY_FILTER_EXLCUDE_INTEGER_INDICES);
1146+
1147+
if (options & non_symbol_mask)
1148+
{
1149+
if ((options & non_symbol_mask) == non_symbol_mask)
1150+
{
1151+
ecma_free_value (next);
1152+
continue;
1153+
}
1154+
1155+
uint32_t index = ecma_string_get_array_index (ecma_get_string_from_value (next));
1156+
1157+
if ((index != ECMA_STRING_NOT_ARRAY_INDEX && (options & JERRY_PROPERTY_FILTER_EXLCUDE_INTEGER_INDICES))
1158+
|| (index == ECMA_STRING_NOT_ARRAY_INDEX && (options & JERRY_PROPERTY_FILTER_EXLCUDE_STRINGS)))
1159+
{
1160+
ecma_free_value (next);
1161+
continue;
1162+
}
1163+
}
1164+
}
1165+
else if (ecma_is_value_symbol (next))
1166+
{
1167+
if (options & JERRY_PROPERTY_FILTER_EXLCUDE_SYMBOLS)
1168+
{
1169+
ecma_free_value (next);
1170+
continue;
1171+
}
1172+
}
1173+
else
11221174
{
11231175
ecma_free_value (next);
11241176
ecma_collection_free (list_ptr);
@@ -1132,6 +1184,7 @@ ecma_op_create_list_from_array_like (ecma_value_t arr, /**< array value */
11321184
/* 9. */
11331185
return list_ptr;
11341186
} /* ecma_op_create_list_from_array_like */
1187+
11351188
#endif /* JERRY_ESNEXT */
11361189

11371190
/**

jerry-core/ecma/operations/ecma-conversion.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ typedef enum
4747
ECMA_TO_NUMERIC_ALLOW_BIGINT = (1 << 0), /**< allow BigInt values (ignored if BigInts are disabled) */
4848
} ecma_to_numeric_options_t;
4949

50+
#if JERRY_ESNEXT
51+
52+
/**
53+
* Option bits for ecma_op_create_list_from_array_like.
54+
*/
55+
typedef enum
56+
{
57+
ECMA_FROM_ARRAY_LIKE_ANY = 0, /**< copy all items of the array */
58+
ECMA_FROM_ARRAY_LIKE_ONLY_PROP_NAMES = (1 << 0), /**< only property names allowed */
59+
/* Further options: */
60+
/* JERRY_PROPERTY_FILTER_EXLCUDE_STRINGS */
61+
/* JERRY_PROPERTY_FILTER_EXLCUDE_SYMBOLS */
62+
/* JERRY_PROPERTY_FILTER_EXLCUDE_INTEGER_INDICES */
63+
} ecma_from_array_like_options_t;
64+
65+
#endif /* JERRY_ESNEXT */
66+
5067
bool ecma_op_require_object_coercible (ecma_value_t value);
5168
bool ecma_op_same_value (ecma_value_t x, ecma_value_t y);
5269
#if JERRY_BUILTIN_CONTAINER
@@ -64,7 +81,7 @@ ecma_value_t ecma_op_to_integer (ecma_value_t value, ecma_number_t *number_p);
6481
ecma_value_t ecma_op_to_length (ecma_value_t value, ecma_length_t *length);
6582
#if JERRY_ESNEXT
6683
ecma_value_t ecma_op_to_index (ecma_value_t value, ecma_number_t *index);
67-
ecma_collection_t *ecma_op_create_list_from_array_like (ecma_value_t arr, bool prop_names_only);
84+
ecma_collection_t *ecma_op_create_list_from_array_like (ecma_value_t arr, uint32_t options);
6885
#endif /* JERRY_ESNEXT */
6986

7087
ecma_object_t *ecma_op_from_property_descriptor (const ecma_property_descriptor_t *src_prop_desc_p);

0 commit comments

Comments
 (0)