Skip to content

Commit 811fd4c

Browse files
authored
Add custom dispatcher to builtin_string (#4661)
JerryScript-DCO-1.0-Signed-off-by: Orkenyi Virag [email protected]
1 parent 8f71871 commit 811fd4c

File tree

2 files changed

+60
-15
lines changed

2 files changed

+60
-15
lines changed

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

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@
3333
#define ECMA_BUILTINS_INTERNAL
3434
#include "ecma-builtins-internal.h"
3535

36+
/**
37+
* This object has a custom dispatch function.
38+
*/
39+
#define BUILTIN_CUSTOM_DISPATCH
40+
41+
/**
42+
* List of built-in routine identifiers.
43+
*/
44+
enum
45+
{
46+
ECMA_BUILTIN_STRING_ROUTINE_START = 0,
47+
ECMA_BUILTIN_STRING_OBJECT_FROM_CHAR_CODE,
48+
ECMA_BUILTIN_STRING_OBJECT_FROM_CODE_POINT,
49+
ECMA_BUILTIN_STRING_OBJECT_RAW,
50+
};
51+
3652
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-string.inc.h"
3753
#define BUILTIN_UNDERSCORED_ID string
3854
#include "ecma-builtin-internal-routines-template.inc.h"
@@ -57,12 +73,9 @@
5773
* Returned value must be freed with ecma_free_value.
5874
*/
5975
static ecma_value_t
60-
ecma_builtin_string_object_from_char_code (ecma_value_t this_arg, /**< 'this' argument */
61-
const ecma_value_t args[], /**< arguments list */
76+
ecma_builtin_string_object_from_char_code (const ecma_value_t args[], /**< arguments list */
6277
uint32_t args_number) /**< number of arguments */
6378
{
64-
JERRY_UNUSED (this_arg);
65-
6679
if (args_number == 0)
6780
{
6881
return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
@@ -120,12 +133,9 @@ ecma_builtin_string_object_from_char_code (ecma_value_t this_arg, /**< 'this' ar
120133
* Returned value must be freed with ecma_free_value.
121134
*/
122135
static ecma_value_t
123-
ecma_builtin_string_object_raw (ecma_value_t this_arg, /**< 'this' argument */
124-
const ecma_value_t args[], /**< arguments list */
136+
ecma_builtin_string_object_raw (const ecma_value_t args[], /**< arguments list */
125137
uint32_t args_number) /**< number of arguments */
126138
{
127-
JERRY_UNUSED (this_arg);
128-
129139
/* 1 - 2. */
130140
const ecma_value_t *substitutions;
131141
uint32_t number_of_substitutions;
@@ -274,12 +284,9 @@ ecma_builtin_string_object_raw (ecma_value_t this_arg, /**< 'this' argument */
274284
* Returned value must be freed with ecma_free_value.
275285
*/
276286
static ecma_value_t
277-
ecma_builtin_string_object_from_code_point (ecma_value_t this_arg, /**< 'this' argument */
278-
const ecma_value_t args[], /**< arguments list */
287+
ecma_builtin_string_object_from_code_point (const ecma_value_t args[], /**< arguments list */
279288
uint32_t args_number) /**< number of arguments */
280289
{
281-
JERRY_UNUSED (this_arg);
282-
283290
if (args_number == 0)
284291
{
285292
return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
@@ -387,6 +394,44 @@ ecma_builtin_string_dispatch_construct (const ecma_value_t *arguments_list_p, /*
387394
return ecma_op_create_string_object (arguments_list_p, arguments_list_len);
388395
} /* ecma_builtin_string_dispatch_construct */
389396

397+
/**
398+
* Dispatcher of the built-in's routines
399+
*
400+
* @return ecma value
401+
* Returned value must be freed with ecma_free_value.
402+
*/
403+
ecma_value_t
404+
ecma_builtin_string_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */
405+
ecma_value_t this_arg, /**< 'this' argument value */
406+
const ecma_value_t arguments_list_p[], /**< list of arguments
407+
* passed to routine */
408+
uint32_t arguments_number) /**< length of arguments' list */
409+
{
410+
JERRY_UNUSED (this_arg);
411+
412+
switch (builtin_routine_id)
413+
{
414+
case ECMA_BUILTIN_STRING_OBJECT_FROM_CHAR_CODE:
415+
{
416+
return ecma_builtin_string_object_from_char_code (arguments_list_p, arguments_number);
417+
}
418+
#if JERRY_ESNEXT
419+
case ECMA_BUILTIN_STRING_OBJECT_FROM_CODE_POINT:
420+
{
421+
return ecma_builtin_string_object_from_code_point (arguments_list_p, arguments_number);
422+
}
423+
case ECMA_BUILTIN_STRING_OBJECT_RAW:
424+
{
425+
return ecma_builtin_string_object_raw (arguments_list_p, arguments_number);
426+
}
427+
#endif /* JERRY_ESNEXT */
428+
default:
429+
{
430+
JERRY_UNREACHABLE ();
431+
}
432+
}
433+
} /* ecma_builtin_string_dispatch_routine */
434+
390435
/**
391436
* @}
392437
* @}

jerry-core/ecma/builtin-objects/ecma-builtin-string.inc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ STRING_VALUE (LIT_MAGIC_STRING_NAME,
4444

4545
/* Routine properties:
4646
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
47-
ROUTINE (LIT_MAGIC_STRING_FROM_CHAR_CODE_UL, ecma_builtin_string_object_from_char_code, NON_FIXED, 1)
47+
ROUTINE (LIT_MAGIC_STRING_FROM_CHAR_CODE_UL, ECMA_BUILTIN_STRING_OBJECT_FROM_CHAR_CODE, NON_FIXED, 1)
4848

4949
#if JERRY_ESNEXT
50-
ROUTINE (LIT_MAGIC_STRING_FROM_CODE_POINT_UL, ecma_builtin_string_object_from_code_point, NON_FIXED, 1)
51-
ROUTINE (LIT_MAGIC_STRING_RAW, ecma_builtin_string_object_raw, NON_FIXED, 1)
50+
ROUTINE (LIT_MAGIC_STRING_FROM_CODE_POINT_UL, ECMA_BUILTIN_STRING_OBJECT_FROM_CODE_POINT, NON_FIXED, 1)
51+
ROUTINE (LIT_MAGIC_STRING_RAW, ECMA_BUILTIN_STRING_OBJECT_RAW, NON_FIXED, 1)
5252
#endif /* JERRY_ESNEXT */
5353

5454
#endif /* JERRY_BUILTIN_STRING */

0 commit comments

Comments
 (0)