diff options
author | Daniella Barsony <bella@inf.u-szeged.hu> | 2020-10-29 10:49:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-29 10:49:36 +0100 |
commit | 72c92d6b36b2c7b82ba06c3249463909ddd812a6 (patch) | |
tree | 259e00ca0c56304234b96dbfe65656f9c90d1b56 | |
parent | c7986fd2c5fab138bd630f47564808345aebbaae (diff) |
Add Array Builtin Dispatcher (#4310)
JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
-rw-r--r-- | jerry-core/ecma/builtin-objects/ecma-builtin-array.c | 91 | ||||
-rw-r--r-- | jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h | 8 |
2 files changed, 66 insertions, 33 deletions
diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-array.c b/jerry-core/ecma/builtin-objects/ecma-builtin-array.c index 82d79274..e930c0f1 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-array.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-array.c @@ -33,6 +33,25 @@ #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_ARRAY_ROUTINE_START = ECMA_BUILTIN_ID__COUNT - 1, + ECMA_ARRAY_ROUTINE_IS_ARRAY, +#if ENABLED (JERRY_ESNEXT) + ECMA_ARRAY_ROUTINE_FROM, + ECMA_ARRAY_ROUTINE_OF, + ECMA_ARRAY_ROUTINE_SPECIES_GET +#endif /* ENABLED (JERRY_ESNEXT) */ +}; + #define BUILTIN_INC_HEADER_NAME "ecma-builtin-array.inc.h" #define BUILTIN_UNDERSCORED_ID array #include "ecma-builtin-internal-routines-template.inc.h" @@ -47,24 +66,6 @@ * @{ */ -/** - * The Array object's 'isArray' routine - * - * See also: - * ECMA-262 v5, 15.4.3.2 - * - * @return ecma value - * Returned value must be freed with ecma_free_value. - */ -static ecma_value_t -ecma_builtin_array_object_is_array (ecma_value_t this_arg, /**< 'this' argument */ - ecma_value_t arg) /**< first argument */ -{ - JERRY_UNUSED (this_arg); - - return ecma_is_value_array (arg); -} /* ecma_builtin_array_object_is_array */ - #if ENABLED (JERRY_ESNEXT) /** * The Array object's 'from' routine @@ -467,17 +468,6 @@ ecma_builtin_array_object_of (ecma_value_t this_arg, /**< 'this' argument */ return ecma_make_object_value (obj_p); } /* ecma_builtin_array_object_of */ -/** - * 22.1.2.5 get Array [ @@species ] accessor - * - * @return ecma_value - * returned value must be freed with ecma_free_value - */ -ecma_value_t -ecma_builtin_array_species_get (ecma_value_t this_value) /**< This Value */ -{ - return ecma_copy_value (this_value); -} /* ecma_builtin_array_species_get */ #endif /* ENABLED (JERRY_ESNEXT) */ /** @@ -548,6 +538,49 @@ ecma_builtin_array_dispatch_construct (const ecma_value_t *arguments_list_p, /** } /* ecma_builtin_array_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_array_dispatch_routine (uint16_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 */ +{ + switch (builtin_routine_id) + { + case ECMA_ARRAY_ROUTINE_IS_ARRAY: + { + JERRY_UNUSED (this_arg); + + return arguments_number > 0 ? ecma_is_value_array (arguments_list_p[0]) : ECMA_VALUE_FALSE; + } +#if ENABLED (JERRY_ESNEXT) + case ECMA_ARRAY_ROUTINE_FROM: + { + return ecma_builtin_array_object_from (this_arg, arguments_list_p, arguments_number); + } + case ECMA_ARRAY_ROUTINE_OF: + { + return ecma_builtin_array_object_of (this_arg, arguments_list_p, arguments_number); + } + case ECMA_ARRAY_ROUTINE_SPECIES_GET: + { + return ecma_copy_value (this_arg); + } +#endif /* ENABLED (JERRY_ESNEXT) */ + default: + { + JERRY_UNREACHABLE (); + } + } +} /* ecma_builtin_array_dispatch_routine */ + +/** * @} * @} * @} diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h index a8ed2043..1ddcd663 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h @@ -44,14 +44,14 @@ 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_IS_ARRAY_UL, ecma_builtin_array_object_is_array, 1, 1) +ROUTINE (LIT_MAGIC_STRING_IS_ARRAY_UL, ECMA_ARRAY_ROUTINE_IS_ARRAY, 1, 1) #if ENABLED (JERRY_ESNEXT) -ROUTINE (LIT_MAGIC_STRING_FROM, ecma_builtin_array_object_from, NON_FIXED, 1) -ROUTINE (LIT_MAGIC_STRING_OF, ecma_builtin_array_object_of, NON_FIXED, 0) +ROUTINE (LIT_MAGIC_STRING_FROM, ECMA_ARRAY_ROUTINE_FROM, NON_FIXED, 1) +ROUTINE (LIT_MAGIC_STRING_OF, ECMA_ARRAY_ROUTINE_OF, NON_FIXED, 0) /* ECMA-262 v6, 22.1.2.5 */ ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES, - ecma_builtin_array_species_get, + ECMA_ARRAY_ROUTINE_SPECIES_GET, ECMA_PROPERTY_FLAG_CONFIGURABLE) #endif /* ENABLED (JERRY_ESNEXT) */ |