Add custom dispatcher to builtin-json. (#4679)

JerryScript-DCO-1.0-Signed-off-by: Orkenyi Virag orkvi@inf.u-szeged.hu
This commit is contained in:
Virag Orkenyi
2021-07-20 11:32:20 +02:00
committed by GitHub
parent b25b640ff5
commit bbf1c0105b
2 changed files with 54 additions and 10 deletions
@@ -35,6 +35,21 @@
#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_JSON_ROUTINE_START = 0,
ECMA_BUILTIN_JSON_PARSE,
ECMA_BUILTIN_JSON_STRINGIFY,
};
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-json.inc.h"
#define BUILTIN_UNDERSCORED_ID json
#include "ecma-builtin-internal-routines-template.inc.h"
@@ -831,12 +846,9 @@ ecma_builtin_json_parse_buffer (const lit_utf8_byte_t * str_start_p, /**< String
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_json_parse (ecma_value_t this_arg, /**< 'this' argument */
ecma_value_t arg1, /**< string argument */
ecma_builtin_json_parse (ecma_value_t arg1, /**< string argument */
ecma_value_t arg2) /**< reviver argument */
{
JERRY_UNUSED (this_arg);
ecma_string_t *text_string_p = ecma_op_to_string (arg1);
if (JERRY_UNLIKELY (text_string_p == NULL))
@@ -1544,13 +1556,10 @@ ecma_builtin_json_stringify_no_opts (const ecma_value_t value) /**< value to str
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
ecma_value_t arg1, /**< value */
ecma_builtin_json_stringify (ecma_value_t arg1, /**< value */
ecma_value_t arg2, /**< replacer */
ecma_value_t arg3) /**< space */
{
JERRY_UNUSED (this_arg);
ecma_json_stringify_context_t context;
context.replacer_function_p = NULL;
context.property_list_p = NULL;
@@ -1789,6 +1798,41 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
return ret_value;
} /* ecma_builtin_json_stringify */
/**
* Dispatcher of the built-in's routines
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
ecma_value_t
ecma_builtin_json_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);
ecma_value_t arg1 = (arguments_number > 0) ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED;
ecma_value_t arg2 = (arguments_number > 1) ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED;
ecma_value_t arg3 = (arguments_number > 2) ? arguments_list_p[2] : ECMA_VALUE_UNDEFINED;
switch (builtin_routine_id)
{
case ECMA_BUILTIN_JSON_PARSE:
{
return ecma_builtin_json_parse (arg1, arg2);
}
case ECMA_BUILTIN_JSON_STRINGIFY:
{
return ecma_builtin_json_stringify (arg1, arg2, arg3);
}
default:
{
JERRY_UNREACHABLE ();
}
}
} /* ecma_builtin_json_dispatch_routine */
/**
* @}
* @}
@@ -30,8 +30,8 @@ STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (LIT_MAGIC_STRING_PARSE, ecma_builtin_json_parse, 2, 2)
ROUTINE (LIT_MAGIC_STRING_STRINGIFY, ecma_builtin_json_stringify, 3, 3)
ROUTINE (LIT_MAGIC_STRING_PARSE, ECMA_BUILTIN_JSON_PARSE, 2, 2)
ROUTINE (LIT_MAGIC_STRING_STRINGIFY, ECMA_BUILTIN_JSON_STRINGIFY, 3, 3)
#endif /* JERRY_BUILTIN_JSON */