Introducing ecma_is_magic_string routine.

This commit is contained in:
Ruben Ayrapetyan 2014-09-17 18:00:11 +04:00
parent 70d76efc98
commit 24fc505440
2 changed files with 35 additions and 1 deletions

View File

@ -53,6 +53,7 @@ ecma_get_magic_string_zt (ecma_magic_string_id_t id) /**< magic string id */
case ECMA_MAGIC_STRING_LENGTH: return (ecma_char_t*) "length";
case ECMA_MAGIC_STRING_NAN: return (ecma_char_t*) "NaN";
case ECMA_MAGIC_STRING_INFINITY: return (ecma_char_t*) "Infinity";
case ECMA_MAGIC_STRING__COUNT: break;
}
JERRY_UNREACHABLE();
@ -69,6 +70,37 @@ ecma_get_magic_string (ecma_magic_string_id_t id) /**< magic string id */
return ecma_new_ecma_string (ecma_get_magic_string_zt (id));
} /* ecma_get_magic_string */
/**
* Check if passed string equals to one of magic strings
* and if equal magic string was found, return it's id in 'out_id_p' argument.
*
* @return true - if magic string equal to passed string was found,
* false - otherwise.
*/
bool
ecma_is_magic_string (ecma_char_t *zt_string_p, /**< zero-terminated string */
ecma_magic_string_id_t *out_id_p) /**< out: magic string's id */
{
TODO (Improve performance of search);
for (ecma_magic_string_id_t id = 0;
id < ECMA_MAGIC_STRING__COUNT;
id++)
{
if (ecma_compare_zt_strings (zt_string_p, ecma_get_magic_string_zt (id)))
{
*out_id_p = id;
return true;
}
}
*out_id_p = ECMA_MAGIC_STRING__COUNT;
return false;
} /* ecma_is_magic_string */
/**
* @}
* @}

View File

@ -46,11 +46,13 @@ typedef enum
ECMA_MAGIC_STRING_FUNCTION, /**< "function" */
ECMA_MAGIC_STRING_LENGTH, /**< "length" */
ECMA_MAGIC_STRING_NAN, /**< "NaN" */
ECMA_MAGIC_STRING_INFINITY /**< "Infinity" */
ECMA_MAGIC_STRING_INFINITY, /**< "Infinity" */
ECMA_MAGIC_STRING__COUNT /**< number of magic strings */
} ecma_magic_string_id_t;
extern const ecma_char_t* ecma_get_magic_string_zt (ecma_magic_string_id_t id);
extern ecma_string_t* ecma_get_magic_string (ecma_magic_string_id_t id);
extern bool ecma_is_magic_string (ecma_char_t *zt_string_p, ecma_magic_string_id_t *out_id_p);
/**
* @}