3333 * @{
3434 */
3535
36- /**
37- * Creates an empty object for the map/set object's internal slot.
38- *
39- * Note: The created object is not registered to the GC.
40- *
41- * @return ecma value of the created object
42- */
43- static ecma_value_t
44- ecma_op_container_create_internal_object (void )
45- {
46- ecma_object_t * internal_object_p = ecma_alloc_object ();
47- internal_object_p -> type_flags_refs = (ECMA_OBJECT_TYPE_GENERAL | ECMA_OBJECT_FLAG_EXTENSIBLE | ECMA_OBJECT_REF_ONE );
48- internal_object_p -> property_list_or_bound_object_cp = JMEM_CP_NULL ;
49- internal_object_p -> prototype_or_outer_reference_cp = JMEM_CP_NULL ;
50-
51- return ecma_make_object_value (internal_object_p );
52- } /* ecma_op_container_create_internal_object */
53-
5436/**
5537 * Handle calling [[Construct]] of built-in map/set like objects
5638 *
@@ -64,15 +46,19 @@ ecma_op_container_create (const ecma_value_t *arguments_list_p, /**< arguments l
6446{
6547 JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL );
6648
49+ ecma_object_t * internal_object_p = ecma_create_object (NULL , 0 , ECMA_OBJECT_TYPE_GENERAL );
50+
6751 ecma_object_t * object_p = ecma_create_object (ecma_builtin_get (proto_id ),
6852 sizeof (ecma_map_object_t ),
6953 ECMA_OBJECT_TYPE_CLASS );
7054
7155 ecma_map_object_t * map_obj_p = (ecma_map_object_t * ) object_p ;
7256 map_obj_p -> header .u .class_prop .class_id = (uint16_t ) lit_id ;
73- map_obj_p -> header .u .class_prop .u .value = ecma_op_container_create_internal_object ( );
57+ map_obj_p -> header .u .class_prop .u .value = ecma_make_object_value ( internal_object_p );
7458 map_obj_p -> size = 0 ;
7559
60+ ecma_deref_object (internal_object_p );
61+
7662 ecma_value_t set_value = ecma_make_object_value (object_p );
7763
7864#if ENABLED (JERRY_ES2015_BUILTIN_SYMBOL )
@@ -433,54 +419,6 @@ ecma_op_container_set (ecma_value_t this_arg, /**< this argument */
433419 return this_arg ;
434420} /* ecma_op_container_set */
435421
436- /**
437- * Low-level function to clear all items from a map/set
438- */
439- void
440- ecma_op_container_clear_map (ecma_map_object_t * map_object_p ) /**< map object */
441- {
442- ecma_object_t * object_p = ecma_get_object_from_value (map_object_p -> header .u .class_prop .u .value );
443-
444- JERRY_ASSERT (object_p -> type_flags_refs >= ECMA_OBJECT_REF_ONE );
445-
446- ecma_property_header_t * prop_iter_p = ecma_get_property_list (object_p );
447-
448- if (prop_iter_p != NULL && prop_iter_p -> types [0 ] == ECMA_PROPERTY_TYPE_HASHMAP )
449- {
450- ecma_property_hashmap_free (object_p );
451- prop_iter_p = ecma_get_property_list (object_p );
452- }
453-
454- while (prop_iter_p != NULL )
455- {
456- JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p ));
457-
458- /* Both cannot be deleted. */
459- JERRY_ASSERT (prop_iter_p -> types [0 ] != ECMA_PROPERTY_TYPE_DELETED
460- || prop_iter_p -> types [1 ] != ECMA_PROPERTY_TYPE_DELETED );
461-
462- ecma_property_pair_t * prop_pair_p = (ecma_property_pair_t * ) prop_iter_p ;
463-
464- for (int i = 0 ; i < ECMA_PROPERTY_PAIR_ITEM_COUNT ; i ++ )
465- {
466- ecma_property_t * property_p = (ecma_property_t * ) (prop_iter_p -> types + i );
467- jmem_cpointer_t name_cp = prop_pair_p -> names_cp [i ];
468-
469- if (prop_iter_p -> types [i ] != ECMA_PROPERTY_TYPE_DELETED )
470- {
471- ecma_free_property (object_p , name_cp , property_p );
472- }
473- }
474-
475- prop_iter_p = ECMA_GET_POINTER (ecma_property_header_t ,
476- prop_iter_p -> next_property_cp );
477-
478- ecma_dealloc_property_pair (prop_pair_p );
479- }
480-
481- ecma_dealloc_object (object_p );
482- } /* ecma_op_container_clear_map */
483-
484422/**
485423 * The generic map/set prototype object's 'forEach' routine
486424 *
@@ -592,11 +530,12 @@ ecma_op_container_clear (ecma_value_t this_arg, /**< this argument */
592530 return ECMA_VALUE_ERROR ;
593531 }
594532
595- ecma_op_container_clear_map (map_object_p );
596-
597- map_object_p -> header .u .class_prop .u .value = ecma_op_container_create_internal_object ();
533+ ecma_object_t * internal_object_p = ecma_create_object (NULL , 0 , ECMA_OBJECT_TYPE_GENERAL );
534+ map_object_p -> header .u .class_prop .u .value = ecma_make_object_value (internal_object_p );
598535 map_object_p -> size = 0 ;
599536
537+ ecma_deref_object (internal_object_p );
538+
600539 return ECMA_VALUE_UNDEFINED ;
601540} /* ecma_op_container_clear */
602541
0 commit comments