Skip to content

Commit 6511f0e

Browse files
committed
Add ecma_raise_* helpers for raising ECMA exceptions.
JerryScript-DCO-1.0-Signed-off-by: Szilard Ledan [email protected] JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
1 parent f849cc6 commit 6511f0e

File tree

2 files changed

+122
-1
lines changed

2 files changed

+122
-1
lines changed

jerry-core/ecma/operations/ecma-exceptions.cpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,118 @@ ecma_new_standard_error_with_message (ecma_standard_error_t error_type, /**< nat
130130
return new_error_obj_p;
131131
} /* ecma_new_standard_error_with_message */
132132

133+
/**
134+
* Raise a standard ecma-error with the given type and message.
135+
*
136+
* @return completion value
137+
* Returned value must be freed with ecma_free_completion_value
138+
*/
139+
ecma_completion_value_t
140+
ecma_raise_standard_error (ecma_standard_error_t error_type, /**< error type */
141+
const ecma_char_t *msg_p) /**< error message */
142+
{
143+
ecma_string_t *error_msg_p = ecma_new_ecma_string (msg_p);
144+
ecma_object_t *error_obj_p = ecma_new_standard_error_with_message (error_type, error_msg_p);
145+
ecma_deref_ecma_string (error_msg_p);
146+
return ecma_make_throw_obj_completion_value (error_obj_p);
147+
} /* ecma_raise_standard_error */
148+
149+
/**
150+
* Raise a common error with the given message.
151+
*
152+
* @return completion value
153+
* Returned value must be freed with ecma_free_completion_value
154+
*/
155+
ecma_completion_value_t
156+
ecma_raise_common_error (const ecma_char_t *msg_p) /**< error message */
157+
{
158+
return ecma_raise_standard_error (ECMA_ERROR_COMMON, msg_p);
159+
} /* ecma_raise_common_error */
160+
161+
/**
162+
* Raise an EvalError with the given message.
163+
*
164+
* See also: ECMA-262 v5, 15.11.6.1
165+
*
166+
* @return completion value
167+
* Returned value must be freed with ecma_free_completion_value
168+
*/
169+
ecma_completion_value_t
170+
ecma_raise_eval_error (const ecma_char_t *msg_p) /**< error message */
171+
{
172+
return ecma_raise_standard_error (ECMA_ERROR_EVAL, msg_p);
173+
} /* ecma_raise_eval_error */
174+
175+
/**
176+
* Raise a RangeError with the given message.
177+
*
178+
* See also: ECMA-262 v5, 15.11.6.2
179+
*
180+
* @return completion value
181+
* Returned value must be freed with ecma_free_completion_value
182+
*/
183+
ecma_completion_value_t
184+
ecma_raise_range_error (const ecma_char_t *msg_p) /**< error message */
185+
{
186+
return ecma_raise_standard_error (ECMA_ERROR_RANGE, msg_p);
187+
} /* ecma_raise_range_error */
188+
189+
/**
190+
* Raise a ReferenceError with the given message.
191+
*
192+
* See also: ECMA-262 v5, 15.11.6.3
193+
*
194+
* @return completion value
195+
* Returned value must be freed with ecma_free_completion_value
196+
*/
197+
ecma_completion_value_t
198+
ecma_raise_reference_error (const ecma_char_t *msg_p) /**< error message */
199+
{
200+
return ecma_raise_standard_error (ECMA_ERROR_REFERENCE, msg_p);
201+
} /* ecma_raise_reference_error */
202+
203+
/**
204+
* Raise a SyntaxError with the given message.
205+
*
206+
* See also: ECMA-262 v5, 15.11.6.4
207+
*
208+
* @return completion value
209+
* Returned value must be freed with ecma_free_completion_value
210+
*/
211+
ecma_completion_value_t
212+
ecma_raise_syntax_error (const ecma_char_t *msg_p) /**< error message */
213+
{
214+
return ecma_raise_standard_error (ECMA_ERROR_SYNTAX, msg_p);
215+
} /* ecma_raise_syntax_error */
216+
217+
/**
218+
* Raise a TypeError with the given message.
219+
*
220+
* See also: ECMA-262 v5, 15.11.6.5
221+
*
222+
* @return completion value
223+
* Returned value must be freed with ecma_free_completion_value
224+
*/
225+
ecma_completion_value_t
226+
ecma_raise_type_error (const ecma_char_t *msg_p) /**< error message */
227+
{
228+
return ecma_raise_standard_error (ECMA_ERROR_TYPE, msg_p);
229+
} /* ecma_raise_type_error */
230+
231+
/**
232+
* Raise a URIError with the given message.
233+
*
234+
* See also: ECMA-262 v5, 15.11.6.6
235+
*
236+
* @return completion value
237+
* Returned value must be freed with ecma_free_completion_value
238+
*/
239+
ecma_completion_value_t
240+
ecma_raise_uri_error (const ecma_char_t *msg_p) /**< error message */
241+
{
242+
return ecma_raise_standard_error (ECMA_ERROR_URI, msg_p);
243+
} /* ecma_raise_uri_error */
244+
133245
/**
134246
* @}
135247
* @}

jerry-core/ecma/operations/ecma-exceptions.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,17 @@ typedef enum
4545
} ecma_standard_error_t;
4646

4747
extern ecma_object_t *ecma_new_standard_error (ecma_standard_error_t error_type);
48-
extern ecma_object_t* ecma_new_standard_error_with_message (ecma_standard_error_t error_type,
48+
extern ecma_object_t *ecma_new_standard_error_with_message (ecma_standard_error_t error_type,
4949
ecma_string_t *message_string_p);
50+
extern ecma_completion_value_t ecma_raise_standard_error (ecma_standard_error_t error_type,
51+
const ecma_char_t *msg_p);
52+
extern ecma_completion_value_t ecma_raise_common_error (const ecma_char_t *msg_p);
53+
extern ecma_completion_value_t ecma_raise_eval_error (const ecma_char_t *msg_p);
54+
extern ecma_completion_value_t ecma_raise_range_error (const ecma_char_t *msg_p);
55+
extern ecma_completion_value_t ecma_raise_reference_error (const ecma_char_t *msg_p);
56+
extern ecma_completion_value_t ecma_raise_syntax_error (const ecma_char_t *msg_p);
57+
extern ecma_completion_value_t ecma_raise_type_error (const ecma_char_t *msg_p);
58+
extern ecma_completion_value_t ecma_raise_uri_error (const ecma_char_t *msg_p);
5059

5160
/**
5261
* @}

0 commit comments

Comments
 (0)