From 986412d685610ee17c83247c274c6a1e165f7ff1 Mon Sep 17 00:00:00 2001 From: Orkenyi Virag Date: Sun, 11 Apr 2021 11:11:48 +0200 Subject: [PATCH] Add costum dispatcher to Arraybuffer & Arraybuffer_prototype JerryScript-DCO-1.0-Signed-off-by: Orkenyi Virag orkvi@inf.u-szeged.hu --- .../ecma-builtin-arraybuffer-prototype.c | 45 ++++++++++++++++ .../ecma-builtin-arraybuffer-prototype.inc.h | 4 +- .../ecma-builtin-arraybuffer.c | 52 ++++++++++++++++++- .../ecma-builtin-arraybuffer.inc.h | 4 +- 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c index 08067bbd0c..b01ddcb57d 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c @@ -31,6 +31,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_ARRAYBUFFER_PROTOTYPE_ROUTINE_START = 0, + ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_BYTELENGTH_GETTER, + ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_OBJECT_SLICE, +}; + #define BUILTIN_INC_HEADER_NAME "ecma-builtin-arraybuffer-prototype.inc.h" #define BUILTIN_UNDERSCORED_ID arraybuffer_prototype #include "ecma-builtin-internal-routines-template.inc.h" @@ -227,6 +242,36 @@ ecma_builtin_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< thi return ret_value; } /* ecma_builtin_arraybuffer_prototype_object_slice */ +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_arraybuffer_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in 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 */ +{ + switch (builtin_routine_id) + { + case ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_BYTELENGTH_GETTER: + { + return ecma_builtin_arraybuffer_prototype_bytelength_getter (this_arg); + } + case ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_OBJECT_SLICE: + { + return ecma_builtin_arraybuffer_prototype_object_slice (this_arg, arguments_list_p, arguments_number); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_arraybuffer_prototype_dispatch_routine */ + /** * @} * @} diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h index 6d77ed25bf..4bac0a9d77 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h @@ -30,7 +30,7 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, /* Readonly accessor properties */ ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL, - ecma_builtin_arraybuffer_prototype_bytelength_getter, + ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_BYTELENGTH_GETTER, ECMA_PROPERTY_FLAG_CONFIGURABLE) /* ECMA-262 v6, 24.1.4.4 */ @@ -40,7 +40,7 @@ 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_SLICE, ecma_builtin_arraybuffer_prototype_object_slice, NON_FIXED, 2) +ROUTINE (LIT_MAGIC_STRING_SLICE, ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_OBJECT_SLICE, NON_FIXED, 2) #endif /* JERRY_BUILTIN_TYPEDARRAY */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.c b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.c index 0cc315f51c..687425d102 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.c @@ -28,6 +28,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_ARRAYBUFFER_ROUTINE_START = 0, + ECMA_BUILTIN_ARRAYBUFFER_OBJECT_IS_VIEW, + ECMA_BUILTIN_ARRAYBUFFER_SPECIES_GET, +}; + #define BUILTIN_INC_HEADER_NAME "ecma-builtin-arraybuffer.inc.h" #define BUILTIN_UNDERSCORED_ID arraybuffer #include "ecma-builtin-internal-routines-template.inc.h" @@ -98,11 +113,44 @@ ecma_builtin_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_ * @return ecma_value * returned value must be freed with ecma_free_value */ +/* ecma_value_t -ecma_builtin_arraybuffer_species_get (ecma_value_t this_value) /**< This Value */ +ecma_builtin_arraybuffer_species_get (ecma_value_t this_value) < This Value { return ecma_copy_value (this_value); -} /* ecma_builtin_arraybuffer_species_get */ +} *//* ecma_builtin_arraybuffer_species_get */ + +/** + * Dispatcher of the built-in's routines + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +ecma_value_t +ecma_builtin_arraybuffer_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 (arguments_number); + + switch (builtin_routine_id) + { + case ECMA_BUILTIN_ARRAYBUFFER_OBJECT_IS_VIEW: + { + return ecma_builtin_arraybuffer_object_is_view (this_arg, arguments_list_p[0]); + } + case ECMA_BUILTIN_ARRAYBUFFER_SPECIES_GET: + { + return ecma_copy_value (this_arg); + } + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_arraybuffer_dispatch_routine */ /** * @} diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h index 0c05b869fb..7a653dce93 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h @@ -43,11 +43,11 @@ STRING_VALUE (LIT_MAGIC_STRING_NAME, * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ /* ES2015 24.1.3.1 */ -ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ecma_builtin_arraybuffer_object_is_view, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ECMA_BUILTIN_ARRAYBUFFER_OBJECT_IS_VIEW, 1, 1) /* ES2015 24.1.3.3 */ ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES, - ecma_builtin_arraybuffer_species_get, + ECMA_BUILTIN_ARRAYBUFFER_SPECIES_GET, ECMA_PROPERTY_FLAG_CONFIGURABLE) #endif /* JERRY_BUILTIN_TYPEDARRAY */