diff --git a/jerry-core/ecma/operations/ecma-exceptions.cpp b/jerry-core/ecma/operations/ecma-exceptions.cpp index 4fbe2ab6e..565803704 100644 --- a/jerry-core/ecma/operations/ecma-exceptions.cpp +++ b/jerry-core/ecma/operations/ecma-exceptions.cpp @@ -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 */ + /** * @} * @} diff --git a/jerry-core/ecma/operations/ecma-exceptions.h b/jerry-core/ecma/operations/ecma-exceptions.h index b29ed14c7..e93eaed83 100644 --- a/jerry-core/ecma/operations/ecma-exceptions.h +++ b/jerry-core/ecma/operations/ecma-exceptions.h @@ -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); /** * @}