Add ecma_raise_* helpers for raising ECMA exceptions.

JerryScript-DCO-1.0-Signed-off-by: Szilard Ledan szledan.u-szeged@partner.samsung.com
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
László Langó 2015-06-25 23:26:16 +03:00
parent f849cc6283
commit 6511f0e1ba
2 changed files with 122 additions and 1 deletions

View File

@ -130,6 +130,118 @@ ecma_new_standard_error_with_message (ecma_standard_error_t error_type, /**< nat
return new_error_obj_p;
} /* ecma_new_standard_error_with_message */
/**
* Raise a standard ecma-error with the given type and message.
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_standard_error (ecma_standard_error_t error_type, /**< error type */
const ecma_char_t *msg_p) /**< error message */
{
ecma_string_t *error_msg_p = ecma_new_ecma_string (msg_p);
ecma_object_t *error_obj_p = ecma_new_standard_error_with_message (error_type, error_msg_p);
ecma_deref_ecma_string (error_msg_p);
return ecma_make_throw_obj_completion_value (error_obj_p);
} /* ecma_raise_standard_error */
/**
* Raise a common error with the given message.
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_common_error (const ecma_char_t *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_COMMON, msg_p);
} /* ecma_raise_common_error */
/**
* Raise an EvalError with the given message.
*
* See also: ECMA-262 v5, 15.11.6.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_eval_error (const ecma_char_t *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_EVAL, msg_p);
} /* ecma_raise_eval_error */
/**
* Raise a RangeError with the given message.
*
* See also: ECMA-262 v5, 15.11.6.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_range_error (const ecma_char_t *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_RANGE, msg_p);
} /* ecma_raise_range_error */
/**
* Raise a ReferenceError with the given message.
*
* See also: ECMA-262 v5, 15.11.6.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_reference_error (const ecma_char_t *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_REFERENCE, msg_p);
} /* ecma_raise_reference_error */
/**
* Raise a SyntaxError with the given message.
*
* See also: ECMA-262 v5, 15.11.6.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_syntax_error (const ecma_char_t *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_SYNTAX, msg_p);
} /* ecma_raise_syntax_error */
/**
* Raise a TypeError with the given message.
*
* See also: ECMA-262 v5, 15.11.6.5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_type_error (const ecma_char_t *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_TYPE, msg_p);
} /* ecma_raise_type_error */
/**
* Raise a URIError with the given message.
*
* See also: ECMA-262 v5, 15.11.6.6
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_uri_error (const ecma_char_t *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_URI, msg_p);
} /* ecma_raise_uri_error */
/**
* @}
* @}

View File

@ -45,8 +45,17 @@ typedef enum
} ecma_standard_error_t;
extern ecma_object_t *ecma_new_standard_error (ecma_standard_error_t error_type);
extern ecma_object_t* ecma_new_standard_error_with_message (ecma_standard_error_t error_type,
extern ecma_object_t *ecma_new_standard_error_with_message (ecma_standard_error_t error_type,
ecma_string_t *message_string_p);
extern ecma_completion_value_t ecma_raise_standard_error (ecma_standard_error_t error_type,
const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_common_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_eval_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_range_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_reference_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_syntax_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_type_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_uri_error (const ecma_char_t *msg_p);
/**
* @}