38
38
* @{
39
39
*/
40
40
41
- /**
42
- * Map error type to error prototype.
43
- */
44
- typedef struct
45
- {
46
- jerry_error_t error_type ; /**< Native error type */
47
- ecma_builtin_id_t error_prototype_id ; /**< ID of the error prototype */
48
- } ecma_error_mapping_t ;
49
-
50
- /**
51
- * List of error type mappings
52
- */
53
- const ecma_error_mapping_t ecma_error_mappings [] =
54
- {
55
- #define ERROR_ELEMENT (TYPE , ID ) { TYPE , ID }
56
- ERROR_ELEMENT (JERRY_ERROR_COMMON , ECMA_BUILTIN_ID_ERROR_PROTOTYPE ),
57
-
58
- #if JERRY_BUILTIN_ERRORS
59
- ERROR_ELEMENT (JERRY_ERROR_EVAL , ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE ),
60
- ERROR_ELEMENT (JERRY_ERROR_RANGE , ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE ),
61
- ERROR_ELEMENT (JERRY_ERROR_REFERENCE , ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE ),
62
- ERROR_ELEMENT (JERRY_ERROR_TYPE , ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE ),
63
- ERROR_ELEMENT (JERRY_ERROR_URI , ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE ),
64
- ERROR_ELEMENT (JERRY_ERROR_SYNTAX , ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE ),
65
- #if JERRY_BUILTIN_PROMISE
66
- ERROR_ELEMENT (JERRY_ERROR_AGGREGATE , ECMA_BUILTIN_ID_AGGREGATE_ERROR_PROTOTYPE ),
67
- #endif /* JERRY_BUILTIN_PROMISE */
68
- #endif /* JERRY_BUILTIN_ERRORS */
69
-
70
- #undef ERROR_ELEMENT
71
- };
72
-
73
41
/**
74
42
* Standard ecma-error object constructor.
75
43
*
@@ -150,16 +118,18 @@ ecma_new_standard_error (jerry_error_t error_type, /**< native error type */
150
118
151
119
ecma_object_t * prototype_obj_p = ecma_builtin_get (prototype_id );
152
120
153
- ecma_object_t * new_error_obj_p = ecma_create_object (prototype_obj_p ,
154
- sizeof (ecma_extended_object_t ),
155
- ECMA_OBJECT_TYPE_CLASS );
121
+ ecma_object_t * error_object_p = ecma_create_object (prototype_obj_p ,
122
+ sizeof (ecma_extended_object_t ),
123
+ ECMA_OBJECT_TYPE_CLASS );
156
124
157
- ((ecma_extended_object_t * ) new_error_obj_p )-> u .cls .type = ECMA_OBJECT_CLASS_ERROR ;
125
+ ecma_extended_object_t * extended_object_p = (ecma_extended_object_t * ) error_object_p ;
126
+ extended_object_p -> u .cls .type = ECMA_OBJECT_CLASS_ERROR ;
127
+ extended_object_p -> u .cls .u1 .error_type = (uint8_t ) error_type ;
158
128
159
129
if (message_string_p != NULL )
160
130
{
161
131
ecma_property_value_t * prop_value_p ;
162
- prop_value_p = ecma_create_named_data_property (new_error_obj_p ,
132
+ prop_value_p = ecma_create_named_data_property (error_object_p ,
163
133
ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE ),
164
134
ECMA_PROPERTY_CONFIGURABLE_WRITABLE ,
165
135
NULL );
@@ -173,7 +143,7 @@ ecma_new_standard_error (jerry_error_t error_type, /**< native error type */
173
143
&& !(JERRY_CONTEXT (status_flags ) & ECMA_STATUS_ERROR_UPDATE ))
174
144
{
175
145
JERRY_CONTEXT (status_flags ) |= ECMA_STATUS_ERROR_UPDATE ;
176
- JERRY_CONTEXT (error_object_created_callback_p ) (ecma_make_object_value (new_error_obj_p ),
146
+ JERRY_CONTEXT (error_object_created_callback_p ) (ecma_make_object_value (error_object_p ),
177
147
JERRY_CONTEXT (error_object_created_callback_user_p ));
178
148
JERRY_CONTEXT (status_flags ) &= (uint32_t ) ~ECMA_STATUS_ERROR_UPDATE ;
179
149
}
@@ -183,7 +153,7 @@ ecma_new_standard_error (jerry_error_t error_type, /**< native error type */
183
153
/* Default decorator when line info is enabled. */
184
154
ecma_string_t * stack_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_STACK );
185
155
186
- ecma_property_value_t * prop_value_p = ecma_create_named_data_property (new_error_obj_p ,
156
+ ecma_property_value_t * prop_value_p = ecma_create_named_data_property (error_object_p ,
187
157
stack_str_p ,
188
158
ECMA_PROPERTY_CONFIGURABLE_WRITABLE ,
189
159
NULL );
@@ -196,7 +166,7 @@ ecma_new_standard_error (jerry_error_t error_type, /**< native error type */
196
166
#endif /* JERRY_LINE_INFO */
197
167
}
198
168
199
- return new_error_obj_p ;
169
+ return error_object_p ;
200
170
} /* ecma_new_standard_error */
201
171
202
172
#if JERRY_BUILTIN_PROMISE
@@ -312,26 +282,14 @@ ecma_new_aggregate_error (ecma_value_t error_list_val, /**< errors list */
312
282
* if it is not an Error object then JERRY_ERROR_NONE will be returned
313
283
*/
314
284
jerry_error_t
315
- ecma_get_error_type (ecma_object_t * error_object ) /**< possible error object */
285
+ ecma_get_error_type (ecma_object_t * error_object_p ) /**< possible error object */
316
286
{
317
- if (error_object -> u2 . prototype_cp == JMEM_CP_NULL || ECMA_OBJECT_IS_PROXY ( error_object ))
287
+ if (! ecma_object_class_is ( error_object_p , ECMA_OBJECT_CLASS_ERROR ))
318
288
{
319
289
return JERRY_ERROR_NONE ;
320
290
}
321
291
322
- ecma_object_t * prototype_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t , error_object -> u2 .prototype_cp );
323
-
324
- uint8_t builtin_id = ecma_get_object_builtin_id (prototype_p );
325
-
326
- for (uint8_t idx = 0 ; idx < sizeof (ecma_error_mappings ) / sizeof (ecma_error_mappings [0 ]); idx ++ )
327
- {
328
- if (ecma_error_mappings [idx ].error_prototype_id == builtin_id )
329
- {
330
- return ecma_error_mappings [idx ].error_type ;
331
- }
332
- }
333
-
334
- return JERRY_ERROR_NONE ;
292
+ return (jerry_error_t ) ((ecma_extended_object_t * ) error_object_p )-> u .cls .u1 .error_type ;
335
293
} /* ecma_get_error_type */
336
294
337
295
/**
0 commit comments