Skip to content

Commit 6aed0cc

Browse files
committed
Add custom dispatcher to Set/Map/WeakSet/WeakMap
JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony [email protected]
1 parent fe09200 commit 6aed0cc

10 files changed

+238
-534
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-map-prototype.c

Lines changed: 18 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#define ECMA_BUILTINS_INTERNAL
2121
#include "ecma-builtins-internal.h"
2222

23+
/**
24+
* This object has a custom dispatch function.
25+
*/
26+
#define BUILTIN_CUSTOM_DISPATCH
2327
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-map-prototype.inc.h"
2428
#define BUILTIN_UNDERSCORED_ID map_prototype
2529
#include "ecma-builtin-internal-routines-template.inc.h"
@@ -35,179 +39,25 @@
3539
*/
3640

3741
/**
38-
* The Map.prototype object's 'clear' routine
39-
*
40-
* See also:
41-
* ECMA-262 v6, 23.1.3.1
42-
*
43-
* @return ecma value
44-
* Returned value must be freed with ecma_free_value.
45-
*/
46-
static ecma_value_t
47-
ecma_builtin_map_prototype_object_clear (ecma_value_t this_arg) /**< this argument */
48-
{
49-
return ecma_op_container_clear (this_arg, LIT_MAGIC_STRING_MAP_UL);
50-
} /* ecma_builtin_map_prototype_object_clear */
51-
52-
/**
53-
* The Map.prototype object's 'delete' routine
54-
*
55-
* See also:
56-
* ECMA-262 v6, 23.1.3.3
57-
*
58-
* @return ecma value
59-
* Returned value must be freed with ecma_free_value.
60-
*/
61-
static ecma_value_t
62-
ecma_builtin_map_prototype_object_delete (ecma_value_t this_arg, /**< this argument */
63-
ecma_value_t key_arg) /**< key argument */
64-
{
65-
return ecma_op_container_delete (this_arg, key_arg, LIT_MAGIC_STRING_MAP_UL);
66-
} /* ecma_builtin_map_prototype_object_delete */
67-
68-
/**
69-
* The Map.prototype object's 'forEach' routine
70-
*
71-
* See also:
72-
* ECMA-262 v6, 23.1.3.5
73-
*
74-
* @return ecma value
75-
* Returned value must be freed with ecma_free_value.
76-
*/
77-
static ecma_value_t
78-
ecma_builtin_map_prototype_object_foreach (ecma_value_t this_arg, /**< this argument */
79-
ecma_value_t predicate, /**< callback function */
80-
ecma_value_t predicate_this_arg) /**< this argument for
81-
* invoke predicate */
82-
{
83-
return ecma_op_container_foreach (this_arg, predicate, predicate_this_arg, LIT_MAGIC_STRING_MAP_UL);
84-
} /* ecma_builtin_map_prototype_object_foreach */
85-
86-
/**
87-
* The Map.prototype object's 'get' routine
88-
*
89-
* See also:
90-
* ECMA-262 v6, 23.1.3.6
91-
*
92-
* @return ecma value
93-
* Returned value must be freed with ecma_free_value.
94-
*/
95-
static ecma_value_t
96-
ecma_builtin_map_prototype_object_get (ecma_value_t this_arg, /**< this argument */
97-
ecma_value_t key_arg) /**< key argument */
98-
{
99-
return ecma_op_container_get (this_arg, key_arg, LIT_MAGIC_STRING_MAP_UL);
100-
} /* ecma_builtin_map_prototype_object_get */
101-
102-
/**
103-
* The Map.prototype object's 'has' routine
104-
*
105-
* See also:
106-
* ECMA-262 v6, 23.1.3.7
107-
*
108-
* @return ecma value
109-
* Returned value must be freed with ecma_free_value.
110-
*/
111-
static ecma_value_t
112-
ecma_builtin_map_prototype_object_has (ecma_value_t this_arg, /**< this argument */
113-
ecma_value_t key_arg) /**< key argument */
114-
{
115-
return ecma_op_container_has (this_arg, key_arg, LIT_MAGIC_STRING_MAP_UL);
116-
} /* ecma_builtin_map_prototype_object_has */
117-
118-
/**
119-
* The Map.prototype object's 'set' routine
120-
*
121-
* See also:
122-
* ECMA-262 v6, 23.1.3.9
123-
*
124-
* @return ecma value
125-
* Returned value must be freed with ecma_free_value.
126-
*/
127-
static ecma_value_t
128-
ecma_builtin_map_prototype_object_set (ecma_value_t this_arg, /**< this argument */
129-
ecma_value_t key_arg, /**< key argument */
130-
ecma_value_t value_arg) /**< value argument */
131-
{
132-
return ecma_op_container_set (this_arg, key_arg, value_arg, LIT_MAGIC_STRING_MAP_UL);
133-
} /* ecma_builtin_map_prototype_object_set */
134-
135-
/**
136-
* The Map.prototype object's 'size' getter
137-
*
138-
* See also:
139-
* ECMA-262 v6, 23.1.3.10
42+
* Dispatcher of the built-in's routines
14043
*
14144
* @return ecma value
14245
* Returned value must be freed with ecma_free_value.
14346
*/
144-
static ecma_value_t
145-
ecma_builtin_map_prototype_object_size_getter (ecma_value_t this_arg) /**< this argument */
47+
ecma_value_t
48+
ecma_builtin_map_prototype_dispatch_routine (uint16_t builtin_routine_id, /**< built-in wide routine
49+
* identifier */
50+
ecma_value_t this_arg, /**< 'this' argument value */
51+
const ecma_value_t arguments_list_p[], /**< list of arguments
52+
* passed to routine */
53+
ecma_length_t arguments_number) /**< length of arguments' list */
14654
{
147-
return ecma_op_container_size (this_arg, LIT_MAGIC_STRING_MAP_UL);
148-
} /* ecma_builtin_map_prototype_object_size_getter */
149-
150-
#if ENABLED (JERRY_ES2015)
151-
152-
/**
153-
* The Map.prototype object's 'entries' routine
154-
*
155-
* See also:
156-
* ECMA-262 v6, 23.1.3.4
157-
*
158-
* @return ecma value
159-
* Returned value must be freed with ecma_free_value.
160-
*/
161-
static ecma_value_t
162-
ecma_builtin_map_prototype_object_entries (ecma_value_t this_arg) /**< this argument */
163-
{
164-
return ecma_op_container_create_iterator (this_arg,
165-
ECMA_ITERATOR_KEYS_VALUES,
166-
LIT_MAGIC_STRING_MAP_UL,
167-
ECMA_BUILTIN_ID_MAP_ITERATOR_PROTOTYPE,
168-
ECMA_PSEUDO_MAP_ITERATOR);
169-
} /* ecma_builtin_map_prototype_object_entries */
170-
171-
/**
172-
* The Map.prototype object's 'keys' routine
173-
*
174-
* See also:
175-
* ECMA-262 v6, 23.1.3.8
176-
*
177-
* @return ecma value
178-
* Returned value must be freed with ecma_free_value.
179-
*/
180-
static ecma_value_t
181-
ecma_builtin_map_prototype_object_keys (ecma_value_t this_arg) /**< this argument */
182-
{
183-
return ecma_op_container_create_iterator (this_arg,
184-
ECMA_ITERATOR_KEYS,
185-
LIT_MAGIC_STRING_MAP_UL,
186-
ECMA_BUILTIN_ID_MAP_ITERATOR_PROTOTYPE,
187-
ECMA_PSEUDO_MAP_ITERATOR);
188-
} /* ecma_builtin_map_prototype_object_keys */
189-
190-
/**
191-
* The Map.prototype object's 'values' routine
192-
*
193-
* See also:
194-
* ECMA-262 v6, 23.1.3.11
195-
*
196-
* @return ecma value
197-
* Returned value must be freed with ecma_free_value.
198-
*/
199-
static ecma_value_t
200-
ecma_builtin_map_prototype_object_values (ecma_value_t this_arg) /**< this argument */
201-
{
202-
return ecma_op_container_create_iterator (this_arg,
203-
ECMA_ITERATOR_VALUES,
204-
LIT_MAGIC_STRING_MAP_UL,
205-
ECMA_BUILTIN_ID_MAP_ITERATOR_PROTOTYPE,
206-
ECMA_PSEUDO_MAP_ITERATOR);
207-
} /* ecma_builtin_map_prototype_object_values */
208-
209-
#endif /* ENABLED (JERRY_ES2015) */
210-
55+
JERRY_UNUSED (arguments_number);
56+
return ecma_builtin_container_dispatch_routine (builtin_routine_id,
57+
this_arg,
58+
arguments_list_p,
59+
LIT_MAGIC_STRING_MAP_UL);
60+
} /* ecma_builtin_map_prototype_dispatch_routine */
21161
/**
21262
* @}
21363
* @}

jerry-core/ecma/builtin-objects/ecma-builtin-map-prototype.inc.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
3838

3939
/* Routine properties:
4040
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
41-
ROUTINE (LIT_MAGIC_STRING_CLEAR, ecma_builtin_map_prototype_object_clear, 0, 0)
42-
ROUTINE (LIT_MAGIC_STRING_DELETE, ecma_builtin_map_prototype_object_delete, 1, 1)
43-
ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ecma_builtin_map_prototype_object_foreach, 2, 1)
44-
ROUTINE (LIT_MAGIC_STRING_GET, ecma_builtin_map_prototype_object_get, 1, 1)
45-
ROUTINE (LIT_MAGIC_STRING_HAS, ecma_builtin_map_prototype_object_has, 1, 1)
46-
ROUTINE (LIT_MAGIC_STRING_SET, ecma_builtin_map_prototype_object_set, 2, 2)
41+
ROUTINE (LIT_MAGIC_STRING_CLEAR, ECMA_CONTAINER_ROUTINE_CLEAR, 0, 0)
42+
ROUTINE (LIT_MAGIC_STRING_DELETE, ECMA_CONTAINER_ROUTINE_DELETE, 1, 1)
43+
ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ECMA_CONTAINER_ROUTINE_FOREACH, 2, 1)
44+
ROUTINE (LIT_MAGIC_STRING_GET, ECMA_CONTAINER_ROUTINE_GET, 1, 1)
45+
ROUTINE (LIT_MAGIC_STRING_HAS, ECMA_CONTAINER_ROUTINE_HAS, 1, 1)
46+
ROUTINE (LIT_MAGIC_STRING_SET, ECMA_CONTAINER_ROUTINE_SET, 2, 2)
4747
#if ENABLED (JERRY_ES2015)
48-
ROUTINE (LIT_MAGIC_STRING_ENTRIES, ecma_builtin_map_prototype_object_entries, 0, 0)
49-
ROUTINE (LIT_MAGIC_STRING_VALUES, ecma_builtin_map_prototype_object_values, 0, 0)
50-
ROUTINE (LIT_MAGIC_STRING_KEYS, ecma_builtin_map_prototype_object_keys, 0, 0)
51-
ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ecma_builtin_map_prototype_object_entries, 0, 0)
48+
ROUTINE (LIT_MAGIC_STRING_ENTRIES, ECMA_CONTAINER_ROUTINE_ENTRIES, 0, 0)
49+
ROUTINE (LIT_MAGIC_STRING_VALUES, ECMA_CONTAINER_ROUTINE_VALUES, 0, 0)
50+
ROUTINE (LIT_MAGIC_STRING_KEYS, ECMA_CONTAINER_ROUTINE_KEYS, 0, 0)
51+
ROUTINE (LIT_GLOBAL_SYMBOL_ITERATOR, ECMA_CONTAINER_ROUTINE_ENTRIES, 0, 0)
5252
#endif /* ENABLED (JERRY_ES2015) */
5353

5454
/* ECMA-262 v6, 23.1.3.10 */
5555
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_SIZE,
56-
ecma_builtin_map_prototype_object_size_getter,
56+
ECMA_CONTAINER_ROUTINE_SIZE_GETTER,
5757
ECMA_PROPERTY_FLAG_CONFIGURABLE)
5858

5959
#endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) */

0 commit comments

Comments
 (0)