Introduce new API function to obtain well-known symbols (#4163)
- jerry_get_well_known_symbol JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -3766,6 +3766,36 @@ jerry_get_promise_state (const jerry_value_t promise) /**< promise object to get
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROMISE) */
|
||||
} /* jerry_get_promise_state */
|
||||
|
||||
/**
|
||||
* Get the well-knwon symbol represented by the given `symbol` enum value.
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_release_value, when it is no longer needed.
|
||||
*
|
||||
* @return undefined value - if invalid well-known symbol was requested
|
||||
* well-known symbol value - otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_get_well_known_symbol (jerry_well_known_symbol_t symbol) /**< jerry_well_known_symbol_t enum value */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
lit_magic_string_id_t id = (lit_magic_string_id_t) (LIT_GLOBAL_SYMBOL__FISRT + symbol);
|
||||
|
||||
if (!LIT_IS_GLOBAL_SYMBOL (id))
|
||||
{
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
return ecma_make_symbol_value (ecma_op_get_global_symbol (id));
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
JERRY_UNUSED (symbol);
|
||||
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
} /** jerry_get_well_known_symbol */
|
||||
|
||||
/**
|
||||
* Call the SymbolDescriptiveString ecma builtin operation on the symbol value.
|
||||
*
|
||||
|
||||
@@ -650,6 +650,27 @@ jerry_promise_state_t jerry_get_promise_state (const jerry_value_t promise);
|
||||
/**
|
||||
* Symbol functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of well-known symbols.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
JERRY_SYMBOL_HAS_INSTANCE, /**< @@hasInstance well-known symbol */
|
||||
JERRY_SYMBOL_IS_CONCAT_SPREADABLE, /**< @@isConcatSpreadable well-known symbol */
|
||||
JERRY_SYMBOL_ITERATOR, /**< @@iterator well-known symbol */
|
||||
JERRY_SYMBOL_ASYNC_ITERATOR, /**< @@asyncIterator well-known symbol */
|
||||
JERRY_SYMBOL_MATCH, /**< @@match well-known symbol */
|
||||
JERRY_SYMBOL_REPLACE, /**< @@replace well-known symbol */
|
||||
JERRY_SYMBOL_SEARCH, /**< @@search well-known symbol */
|
||||
JERRY_SYMBOL_SPECIES, /**< @@species well-known symbol */
|
||||
JERRY_SYMBOL_SPLIT, /**< @@split well-known symbol */
|
||||
JERRY_SYMBOL_TO_PRIMITIVE, /**< @@toPrimitive well-known symbol */
|
||||
JERRY_SYMBOL_TO_STRING_TAG, /**< @@toStringTag well-known symbol */
|
||||
JERRY_SYMBOL_UNSCOPABLES, /**< @@unscopables well-known symbol */
|
||||
} jerry_well_known_symbol_t;
|
||||
|
||||
jerry_value_t jerry_get_well_known_symbol (jerry_well_known_symbol_t symbol);
|
||||
jerry_value_t jerry_get_symbol_descriptive_string (const jerry_value_t symbol);
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,6 +48,7 @@ typedef enum
|
||||
LIT_INTERNAL_MAGIC_PROMISE_CAPABILITY, /**< PromiseCapability record */
|
||||
/* List of well known symbols */
|
||||
LIT_GLOBAL_SYMBOL_HAS_INSTANCE, /**< @@hasInstance well known symbol */
|
||||
LIT_GLOBAL_SYMBOL__FISRT = LIT_GLOBAL_SYMBOL_HAS_INSTANCE, /**< first global symbol */
|
||||
LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE, /**< @@isConcatSpreadable well known symbol */
|
||||
LIT_GLOBAL_SYMBOL_ITERATOR, /**< @@iterator well known symbol */
|
||||
LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR, /**< @@asyncIterator well known symbol */
|
||||
@@ -59,6 +60,7 @@ typedef enum
|
||||
LIT_GLOBAL_SYMBOL_TO_PRIMITIVE, /**< @@toPrimitive well known symbol */
|
||||
LIT_GLOBAL_SYMBOL_TO_STRING_TAG, /**< @@toStringTag well known symbol */
|
||||
LIT_GLOBAL_SYMBOL_UNSCOPABLES, /**< @@unscopables well known symbol */
|
||||
LIT_GLOBAL_SYMBOL__LAST = LIT_GLOBAL_SYMBOL_UNSCOPABLES, /**< last global symbol */
|
||||
LIT_GC_MARK_REQUIRED_MAGIC_STRING__COUNT, /**< number of internal magic strings which will be used as
|
||||
* property names, and their values need to be marked during gc. */
|
||||
LIT_INTERNAL_MAGIC_STRING_DELETED = LIT_GC_MARK_REQUIRED_MAGIC_STRING__COUNT, /**< special value for
|
||||
@@ -75,7 +77,7 @@ typedef enum
|
||||
/**
|
||||
* Checks whether the given id corresponds to a global symbol
|
||||
*/
|
||||
#define LIT_IS_GLOBAL_SYMBOL(id) ((id) >= LIT_GLOBAL_SYMBOL_HAS_INSTANCE && (id) <= LIT_GLOBAL_SYMBOL_UNSCOPABLES)
|
||||
#define LIT_IS_GLOBAL_SYMBOL(id) ((id) >= LIT_GLOBAL_SYMBOL__FISRT && (id) <= LIT_GLOBAL_SYMBOL__LAST)
|
||||
|
||||
/**
|
||||
* Identifiers of implementation-defined external magic string constants
|
||||
|
||||
Reference in New Issue
Block a user