Merge Map and Set Guards with Container (#4709)

Remove JERRY_BUILTIN_MAP/SET/WEAKMAP/WEAKSET
and replace them with JERRY_BUILTIN_CONTAINER.

JerryScript-DCO-1.0-Signed-off-by: Bela Toth tbela@inf.u-szeged.hu
This commit is contained in:
Tóth Béla
2021-07-12 11:20:38 +02:00
committed by GitHub
parent 7f6a699700
commit 305741a608
33 changed files with 106 additions and 268 deletions
@@ -184,7 +184,6 @@ ecma_op_container_entry_size (lit_magic_string_id_t lit_id) /**< class id */
return ECMA_CONTAINER_VALUE_SIZE;
} /* ecma_op_container_entry_size */
#if JERRY_BUILTIN_WEAKSET
/**
* Release the entries in the WeakSet container.
*/
@@ -213,9 +212,7 @@ ecma_op_container_free_weakset_entries (ecma_object_t *object_p, /**< object poi
*entry_p = ECMA_VALUE_EMPTY;
}
} /* ecma_op_container_free_weakset_entries */
#endif /* JERRY_BUILTIN_WEAKSET */
#if JERRY_BUILTIN_WEAKMAP
/**
* Release the entries in the WeakMap container.
*/
@@ -247,9 +244,7 @@ ecma_op_container_free_weakmap_entries (ecma_object_t *object_p, /**< object poi
entry_p->value = ECMA_VALUE_EMPTY;
}
} /* ecma_op_container_free_weakmap_entries */
#endif /* JERRY_BUILTIN_WEAKMAP */
#if JERRY_BUILTIN_SET
/**
* Release the entries in the Set container.
*/
@@ -274,9 +269,7 @@ ecma_op_container_free_set_entries (ecma_collection_t *container_p)
*entry_p = ECMA_VALUE_EMPTY;
}
} /* ecma_op_container_free_set_entries */
#endif /* JERRY_BUILTIN_SET */
#if JERRY_BUILTIN_MAP
/**
* Release the entries in the Map container.
*/
@@ -304,7 +297,6 @@ ecma_op_container_free_map_entries (ecma_collection_t *container_p)
entry_p->value = ECMA_VALUE_EMPTY;
}
} /* ecma_op_container_free_map_entries */
#endif /* JERRY_BUILTIN_MAP */
/**
* Release the internal buffer and the stored entries.
@@ -320,34 +312,26 @@ ecma_op_container_free_entries (ecma_object_t *object_p) /**< collection object
switch (map_object_p->u.cls.u2.container_id)
{
#if JERRY_BUILTIN_WEAKSET
case LIT_MAGIC_STRING_WEAKSET_UL:
{
ecma_op_container_free_weakset_entries (object_p, container_p);
break;
}
#endif /* JERRY_BUILTIN_WEAKSET */
#if JERRY_BUILTIN_WEAKMAP
case LIT_MAGIC_STRING_WEAKMAP_UL:
{
ecma_op_container_free_weakmap_entries (object_p, container_p);
break;
}
#endif /* JERRY_BUILTIN_WEAKMAP */
#if JERRY_BUILTIN_SET
case LIT_MAGIC_STRING_SET_UL:
{
ecma_op_container_free_set_entries (container_p);
break;
}
#endif /* JERRY_BUILTIN_SET */
#if JERRY_BUILTIN_MAP
case LIT_MAGIC_STRING_MAP_UL:
{
ecma_op_container_free_map_entries (container_p);
break;
}
#endif /* JERRY_BUILTIN_MAP */
default:
{
break;
@@ -610,12 +594,10 @@ ecma_op_container_get (ecma_extended_object_t *map_object_p, /**< map object */
ecma_value_t key_arg, /**< key argument */
lit_magic_string_id_t lit_id) /**< internal class id */
{
#if JERRY_BUILTIN_WEAKMAP
if (lit_id == LIT_MAGIC_STRING_WEAKMAP_UL && !ecma_is_value_object (key_arg))
{
return ECMA_VALUE_UNDEFINED;
}
#endif /* JERRY_BUILTIN_WEAKMAP */
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t,
map_object_p->u.cls.u3.value);
@@ -649,13 +631,11 @@ ecma_op_container_has (ecma_extended_object_t *map_object_p, /**< map object */
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t,
map_object_p->u.cls.u3.value);
#if JERRY_BUILTIN_WEAKMAP || JERRY_BUILTIN_WEAKSET
if ((map_object_p->u.cls.u1.container_flags & ECMA_CONTAINER_FLAGS_WEAK) != 0
&& !ecma_is_value_object (key_arg))
{
return ECMA_VALUE_FALSE;
}
#endif /* JERRY_BUILTIN_WEAKMAP || JERRY_BUILTIN_WEAKSET */
if (ECMA_CONTAINER_GET_SIZE (container_p) == 0)
{
@@ -707,13 +687,11 @@ ecma_op_container_set (ecma_extended_object_t *map_object_p, /**< map object */
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t,
map_object_p->u.cls.u3.value);
#if JERRY_BUILTIN_WEAKMAP || JERRY_BUILTIN_WEAKSET
if ((map_object_p->u.cls.u1.container_flags & ECMA_CONTAINER_FLAGS_WEAK) != 0
&& !ecma_is_value_object (key_arg))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Key must be an object"));
}
#endif /* JERRY_BUILTIN_WEAKMAP || JERRY_BUILTIN_WEAKSET */
ecma_value_t *entry_p = ecma_op_internal_buffer_find (container_p, key_arg, lit_id);
@@ -724,13 +702,11 @@ ecma_op_container_set (ecma_extended_object_t *map_object_p, /**< map object */
value_arg,
lit_id);
#if JERRY_BUILTIN_WEAKMAP || JERRY_BUILTIN_WEAKSET
if ((map_object_p->u.cls.u1.container_flags & ECMA_CONTAINER_FLAGS_WEAK) != 0)
{
ecma_object_t *key_p = ecma_get_object_from_value (key_arg);
ecma_op_object_set_weak (key_p, (ecma_object_t *) map_object_p);
}
#endif /* JERRY_BUILTIN_WEAKMAP || JERRY_BUILTIN_WEAKSET */
}
else
{
+2 -2
View File
@@ -135,7 +135,7 @@ ecma_op_same_value (ecma_value_t x, /**< ecma value */
return false;
} /* ecma_op_same_value */
#if JERRY_BUILTIN_MAP
#if JERRY_BUILTIN_CONTAINER
/**
* SameValueZero operation.
*
@@ -182,7 +182,7 @@ ecma_op_same_value_zero (ecma_value_t x, /**< ecma value */
return ecma_op_same_value (x, y);
} /* ecma_op_same_value_zero */
#endif /* JERRY_BUILTIN_MAP */
#endif /* JERRY_BUILTIN_CONTAINER */
/**
* ToPrimitive operation.
+2 -2
View File
@@ -49,9 +49,9 @@ typedef enum
bool ecma_op_require_object_coercible (ecma_value_t value);
bool ecma_op_same_value (ecma_value_t x, ecma_value_t y);
#if JERRY_BUILTIN_MAP
#if JERRY_BUILTIN_CONTAINER
bool ecma_op_same_value_zero (ecma_value_t x, ecma_value_t y, bool strict_equality);
#endif /* JERRY_BUILTIN_MAP */
#endif /* JERRY_BUILTIN_CONTAINER */
ecma_value_t ecma_op_to_primitive (ecma_value_t value, ecma_preferred_type_hint_t preferred_type);
bool ecma_op_to_boolean (ecma_value_t value);
ecma_value_t ecma_op_to_number (ecma_value_t value, ecma_number_t *number_p);
+7 -15
View File
@@ -2796,27 +2796,19 @@ ecma_object_check_class_name_is_object (ecma_object_t *obj_p) /**< object */
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_SYMBOL_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_ASYNC_FUNCTION_PROTOTYPE)
#endif /* JERRY_ESNEXT */
#if JERRY_BUILTIN_MAP
#if JERRY_BUILTIN_CONTAINER
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_MAP_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_SET_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_WEAKMAP_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_WEAKSET_PROTOTYPE)
#if JERRY_ESNEXT
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_MAP_ITERATOR_PROTOTYPE)
#endif /* JERRY_ESNEXT */
#endif /* JERRY_BUILTIN_MAP */
#if JERRY_BUILTIN_SET
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_SET_PROTOTYPE)
#if JERRY_ESNEXT
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_SET_ITERATOR_PROTOTYPE)
#endif /* JERRY_ESNEXT */
#endif /* JERRY_BUILTIN_SET */
#if JERRY_BUILTIN_WEAKMAP
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_WEAKMAP_PROTOTYPE)
#endif /* JERRY_BUILTIN_WEAKMAP */
#endif /* JERRY_BUILTIN_CONTAINER */
#if JERRY_BUILTIN_WEAKREF
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_WEAKREF_PROTOTYPE)
#endif /* JERRY_BUILTIN_WEAKREF */
#if JERRY_BUILTIN_WEAKSET
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_WEAKSET_PROTOTYPE)
#endif /* JERRY_BUILTIN_WEAKSET */
#if JERRY_BUILTIN_DATAVIEW
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_DATAVIEW_PROTOTYPE)
#endif /* JERRY_BUILTIN_DATAVIEW */
@@ -3430,7 +3422,7 @@ ecma_op_ordinary_object_has_own_property (ecma_object_t *object_p, /**< the obje
return property != ECMA_PROPERTY_TYPE_NOT_FOUND && property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP;
} /* ecma_op_ordinary_object_has_own_property */
#if JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_WEAKSET || JERRY_BUILTIN_WEAKMAP
#if JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_CONTAINER
/**
* Set a weak reference from a container or WeakRefObject to a key object
@@ -3505,7 +3497,7 @@ ecma_op_object_unref_weak (ecma_object_t *object_p, /**< this argument */
}
} /* ecma_op_object_unref_weak */
#endif /* JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_WEAKSET || JERRY_BUILTIN_WEAKMAP */
#endif /* JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_CONTAINER */
/**
* Raise property redefinition error
*
+2 -2
View File
@@ -111,10 +111,10 @@ ecma_value_t ecma_op_species_constructor (ecma_object_t *this_value, ecma_builti
ecma_value_t ecma_op_invoke_by_symbol_id (ecma_value_t object, lit_magic_string_id_t magic_string_id,
ecma_value_t *args_p, uint32_t args_len);
#endif /* JERRY_ESNEXT */
#if JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_WEAKSET || JERRY_BUILTIN_WEAKMAP
#if JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_CONTAINER
void ecma_op_object_set_weak (ecma_object_t *object_p, ecma_object_t *target_p);
void ecma_op_object_unref_weak (ecma_object_t *object_p, ecma_value_t ref_holder);
#endif /* JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_WEAKSET || JERRY_BUILTIN_WEAKMAP */
#endif /* JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_CONTAINER */
ecma_value_t ecma_op_invoke (ecma_value_t object, ecma_string_t *property_name_p, ecma_value_t *args_p,
uint32_t args_len);
ecma_value_t ecma_op_invoke_by_magic_id (ecma_value_t object, lit_magic_string_id_t magic_string_id,