Skip to content

Add custom dispatcher to builtin_string #4661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 57 additions & 12 deletions jerry-core/ecma/builtin-objects/ecma-builtin-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"

/**
* This object has a custom dispatch function.
*/
#define BUILTIN_CUSTOM_DISPATCH

/**
* List of built-in routine identifiers.
*/
enum
{
ECMA_BUILTIN_STRING_ROUTINE_START = 0,
ECMA_BUILTIN_STRING_OBJECT_FROM_CHAR_CODE,
ECMA_BUILTIN_STRING_OBJECT_FROM_CODE_POINT,
ECMA_BUILTIN_STRING_OBJECT_RAW,
};

#define BUILTIN_INC_HEADER_NAME "ecma-builtin-string.inc.h"
#define BUILTIN_UNDERSCORED_ID string
#include "ecma-builtin-internal-routines-template.inc.h"
Expand All @@ -57,12 +73,9 @@
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_string_object_from_char_code (ecma_value_t this_arg, /**< 'this' argument */
const ecma_value_t args[], /**< arguments list */
ecma_builtin_string_object_from_char_code (const ecma_value_t args[], /**< arguments list */
uint32_t args_number) /**< number of arguments */
{
JERRY_UNUSED (this_arg);

if (args_number == 0)
{
return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
Expand Down Expand Up @@ -120,12 +133,9 @@ ecma_builtin_string_object_from_char_code (ecma_value_t this_arg, /**< 'this' ar
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_string_object_raw (ecma_value_t this_arg, /**< 'this' argument */
const ecma_value_t args[], /**< arguments list */
ecma_builtin_string_object_raw (const ecma_value_t args[], /**< arguments list */
uint32_t args_number) /**< number of arguments */
{
JERRY_UNUSED (this_arg);

/* 1 - 2. */
const ecma_value_t *substitutions;
uint32_t number_of_substitutions;
Expand Down Expand Up @@ -274,12 +284,9 @@ ecma_builtin_string_object_raw (ecma_value_t this_arg, /**< 'this' argument */
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_string_object_from_code_point (ecma_value_t this_arg, /**< 'this' argument */
const ecma_value_t args[], /**< arguments list */
ecma_builtin_string_object_from_code_point (const ecma_value_t args[], /**< arguments list */
uint32_t args_number) /**< number of arguments */
{
JERRY_UNUSED (this_arg);

if (args_number == 0)
{
return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
Expand Down Expand Up @@ -387,6 +394,44 @@ ecma_builtin_string_dispatch_construct (const ecma_value_t *arguments_list_p, /*
return ecma_op_create_string_object (arguments_list_p, arguments_list_len);
} /* ecma_builtin_string_dispatch_construct */

/**
* Dispatcher of the built-in's routines
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
ecma_value_t
ecma_builtin_string_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */
ecma_value_t this_arg, /**< 'this' argument value */
const ecma_value_t arguments_list_p[], /**< list of arguments
* passed to routine */
uint32_t arguments_number) /**< length of arguments' list */
{
JERRY_UNUSED (this_arg);

switch (builtin_routine_id)
{
case ECMA_BUILTIN_STRING_OBJECT_FROM_CHAR_CODE:
{
return ecma_builtin_string_object_from_char_code (arguments_list_p, arguments_number);
}
#if JERRY_ESNEXT
case ECMA_BUILTIN_STRING_OBJECT_FROM_CODE_POINT:
{
return ecma_builtin_string_object_from_code_point (arguments_list_p, arguments_number);
}
case ECMA_BUILTIN_STRING_OBJECT_RAW:
{
return ecma_builtin_string_object_raw (arguments_list_p, arguments_number);
}
#endif /* JERRY_ESNEXT */
default:
{
JERRY_UNREACHABLE ();
}
}
} /* ecma_builtin_string_dispatch_routine */

/**
* @}
* @}
Expand Down
6 changes: 3 additions & 3 deletions jerry-core/ecma/builtin-objects/ecma-builtin-string.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ STRING_VALUE (LIT_MAGIC_STRING_NAME,

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

#if JERRY_ESNEXT
ROUTINE (LIT_MAGIC_STRING_FROM_CODE_POINT_UL, ecma_builtin_string_object_from_code_point, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_RAW, ecma_builtin_string_object_raw, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_FROM_CODE_POINT_UL, ECMA_BUILTIN_STRING_OBJECT_FROM_CODE_POINT, NON_FIXED, 1)
ROUTINE (LIT_MAGIC_STRING_RAW, ECMA_BUILTIN_STRING_OBJECT_RAW, NON_FIXED, 1)
#endif /* JERRY_ESNEXT */

#endif /* JERRY_BUILTIN_STRING */
Expand Down