Introducing ECMA_OP_TO_NUMBER_TRY_CATCH and ECMA_OP_TO_NUMBER_FINALIZE macroses.

- the ECMA_OP_TO_NUMBER_TRY_CATCH macro gets number from given value,
    converting the value to number if it's type is different,
    and catching possible conversion exceptions;

  - using the macroses instead of ecma_op_to_number to reduce allocator invocations
    in several routines with arguments that are likely to be numbers.
This commit is contained in:
Ruben Ayrapetyan
2014-12-15 22:52:07 +03:00
parent 386a530d4d
commit d836dc32af
8 changed files with 187 additions and 188 deletions
@@ -50,4 +50,49 @@
#define ECMA_FINALIZE(var) } \
ecma_free_completion_value (var)
/**
* The macro defines try-block that tries to perform ToNumber operation on given value
* and checks for exceptions that might be thrown during the operation.
*
* If no exception was thrown, then code after the try-block is executed.
* Otherwise, throw-completion value is just copied to return_value.
*
* Note:
* Each ECMA_OP_TO_NUMBER_TRY_CATCH should have it's own corresponding ECMA_OP_TO_NUMBER_FINALIZE
* statement with same argument as corresponding ECMA_OP_TO_NUMBER_TRY_CATCH's first argument.
*/
#define ECMA_OP_TO_NUMBER_TRY_CATCH(num_var, value, return_value) \
JERRY_ASSERT (ecma_is_completion_value_empty (return_value)); \
ecma_number_t num_var = ecma_number_make_nan (); \
if (ecma_is_value_number (value)) \
{ \
num_var = *ecma_get_number_from_value (value); \
} \
else \
{ \
ECMA_TRY_CATCH (to_number_completion_value, \
ecma_op_to_number (value), \
return_value); \
\
num_var = *ecma_get_number_from_completion_value (to_number_completion_value); \
\
ECMA_FINALIZE (to_number_completion_value); \
} \
\
if (ecma_is_completion_value_empty (return_value)) \
{
/**
* The macro marks end of code block that is defined by corresponding ECMA_OP_TO_NUMBER_TRY_CATCH.
*
* Note:
* Each ECMA_OP_TO_NUMBER_TRY_CATCH should be followed by ECMA_OP_TO_NUMBER_FINALIZE
* with same argument as corresponding ECMA_OP_TO_NUMBER_TRY_CATCH's first argument.
*/
#define ECMA_OP_TO_NUMBER_FINALIZE(num_var) } \
else \
{ \
JERRY_ASSERT (ecma_number_is_nan (num_var)); \
}
#endif /* !ECMA_TRY_CATCH_MACRO_H */