Implement Symbol.prototype.description (#3995)

The algorithm is based on ECMA-262 v11, 19.4.3.2

Also added a custom dispatcher for the Symbol prototype

JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
Szilagyi Adam
2020-07-20 13:47:25 +02:00
committed by GitHub
parent 74781c28c2
commit e8c5c46894
7 changed files with 149 additions and 53 deletions
@@ -30,6 +30,23 @@
#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_SYMBOL_PROTOTYPE_ROUTINE_START = ECMA_BUILTIN_ID__COUNT - 1,
ECMA_SYMBOL_PROTOTYPE_VALUE_OF, /**< ECMA-262 v11, 19.4.3.4 */
ECMA_SYMBOL_PROTOTYPE_TO_PRIMITIVE, /**< ECMA-262 v11, 19.4.3.5 */
ECMA_SYMBOL_PROTOTYPE_TO_STRING, /**< ECMA-262 v11, 19.4.3.3 */
ECMA_SYMBOL_PROTOTYPE_DESCRIPTION, /**< ECMA-262 v11, 19.4.3.2 */
};
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-symbol-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID symbol_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
@@ -45,49 +62,45 @@
*/
/**
* The Symbol.prototype object's 'toString' routine
*
* See also:
* ECMA-262 v6, 19.4.3.2
* Dispatcher of the Symbol built-in's routines
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_symbol_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */
ecma_value_t
ecma_builtin_symbol_prototype_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[], /**< list of arguments
* passed to routine */
ecma_length_t arguments_number) /**< length of arguments' list */
{
return ecma_symbol_to_string_helper (this_arg, true);
} /* ecma_builtin_symbol_prototype_object_to_string */
JERRY_UNUSED_2 (arguments_list, arguments_number);
/**
* The Symbol.prototype object's 'valueOf' routine
*
* See also:
* ECMA-262 v6, 19.4.3.3
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_symbol_prototype_object_value_of (ecma_value_t this_arg) /**< this argument */
{
return ecma_symbol_to_string_helper (this_arg, false);
} /* ecma_builtin_symbol_prototype_object_value_of */
ecma_value_t sym = ecma_symbol_this_value (this_arg);
/**
* The Symbol.prototype object's '@@toPrimitive' routine
*
* See also:
* ECMA-262 v6, 19.4.3.3
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_symbol_prototype_object_to_primitive (ecma_value_t this_arg) /**< this argument */
{
return ecma_builtin_symbol_prototype_object_value_of (this_arg);
} /* ecma_builtin_symbol_prototype_object_to_primitive */
if (ECMA_IS_VALUE_ERROR (sym))
{
return sym;
}
if (builtin_routine_id < ECMA_SYMBOL_PROTOTYPE_TO_STRING)
{
return ecma_copy_value (sym);
}
if (builtin_routine_id == ECMA_SYMBOL_PROTOTYPE_TO_STRING)
{
return ecma_get_symbol_descriptive_string (sym);
}
JERRY_ASSERT (builtin_routine_id == ECMA_SYMBOL_PROTOTYPE_DESCRIPTION);
ecma_string_t *symbol_p = ecma_get_symbol_from_value (sym);
ecma_string_t *desc_p = ecma_get_symbol_description (symbol_p);
ecma_ref_ecma_string (desc_p);
return ecma_make_string_value (desc_p);
} /* ecma_builtin_symbol_prototype_dispatch_routine */
/**
* @}
@@ -28,10 +28,10 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
ECMA_BUILTIN_ID_SYMBOL,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_symbol_prototype_object_to_string, 0, 0)
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_symbol_prototype_object_value_of, 0, 0)
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_SYMBOL_PROTOTYPE_TO_STRING, 0, 0)
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ECMA_SYMBOL_PROTOTYPE_VALUE_OF, 0, 0)
ROUTINE_CONFIGURABLE_ONLY (LIT_GLOBAL_SYMBOL_TO_PRIMITIVE,
ecma_builtin_symbol_prototype_object_to_primitive,
ECMA_SYMBOL_PROTOTYPE_TO_PRIMITIVE,
0,
1)
@@ -40,6 +40,10 @@ STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
LIT_MAGIC_STRING_SYMBOL_UL,
ECMA_PROPERTY_FLAG_CONFIGURABLE)
/* ECMA-262, v11, 19.4.3.2 */
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_DESCRIPTION,
ECMA_SYMBOL_PROTOTYPE_DESCRIPTION,
ECMA_PROPERTY_FLAG_CONFIGURABLE)
#endif /* ENABLED (JERRY_ESNEXT) */
#include "ecma-builtin-helpers-macro-undefs.inc.h"