Skip to content

Commit 43f80dc

Browse files
committed
Style fixes for RegExp.
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
1 parent 065785b commit 43f80dc

23 files changed

+297
-252
lines changed

jerry-core/ecma/base/ecma-globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ typedef enum
401401
ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, /** One of built-in functions described in section 15
402402
of ECMA-262 v5 specification */
403403
ECMA_OBJECT_TYPE_ARGUMENTS, /**< Arguments object (10.6) */
404-
ECMA_OBJECT_TYPE_ARRAY, /**< Array object (15.4) */
404+
ECMA_OBJECT_TYPE_ARRAY /**< Array object (15.4) */
405405
// ECMA_OBJECT_TYPE_HOST /**< Host object */
406406
} ecma_object_type_t;
407407

jerry-core/ecma/base/ecma-helpers-char.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,42 @@ ecma_char_is_word_char (ecma_char_t c) /**< character value */
8484
return false;
8585
} /* ecma_char_is_word_char */
8686

87+
/**
88+
* Convert a hex character to an unsigned integer
89+
*
90+
* @return unsigned integer
91+
*/
92+
uint32_t
93+
ecma_char_hex_to_int (char hex)
94+
{
95+
switch (hex)
96+
{
97+
case '0': return 0x0;
98+
case '1': return 0x1;
99+
case '2': return 0x2;
100+
case '3': return 0x3;
101+
case '4': return 0x4;
102+
case '5': return 0x5;
103+
case '6': return 0x6;
104+
case '7': return 0x7;
105+
case '8': return 0x8;
106+
case '9': return 0x9;
107+
case 'a':
108+
case 'A': return 0xA;
109+
case 'b':
110+
case 'B': return 0xB;
111+
case 'c':
112+
case 'C': return 0xC;
113+
case 'd':
114+
case 'D': return 0xD;
115+
case 'e':
116+
case 'E': return 0xE;
117+
case 'f':
118+
case 'F': return 0xF;
119+
default: JERRY_UNREACHABLE ();
120+
}
121+
} /* ecma_char_hex_to_int */
122+
87123
/**
88124
* @}
89125
* @}

jerry-core/ecma/base/ecma-helpers-conversion.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,42 +1506,6 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
15061506
return length;
15071507
} /* ecma_number_to_zt_string */
15081508

1509-
/**
1510-
* Convert a hex character to an unsigned integer
1511-
*
1512-
* @return unsigned integer
1513-
*/
1514-
uint32_t
1515-
hex_to_int (char hex)
1516-
{
1517-
switch (hex)
1518-
{
1519-
case '0': return 0x0;
1520-
case '1': return 0x1;
1521-
case '2': return 0x2;
1522-
case '3': return 0x3;
1523-
case '4': return 0x4;
1524-
case '5': return 0x5;
1525-
case '6': return 0x6;
1526-
case '7': return 0x7;
1527-
case '8': return 0x8;
1528-
case '9': return 0x9;
1529-
case 'a':
1530-
case 'A': return 0xA;
1531-
case 'b':
1532-
case 'B': return 0xB;
1533-
case 'c':
1534-
case 'C': return 0xC;
1535-
case 'd':
1536-
case 'D': return 0xD;
1537-
case 'e':
1538-
case 'E': return 0xE;
1539-
case 'f':
1540-
case 'F': return 0xF;
1541-
default: JERRY_UNREACHABLE ();
1542-
}
1543-
} /* hex_to_int */
1544-
15451509
/**
15461510
* @}
15471511
* @}

jerry-core/ecma/base/ecma-helpers-string.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ ecma_new_ecma_string (const ecma_char_t *string_p, /**< input string */
490490
mem_heap_free_block (zt_str_p);
491491
}
492492

493-
ecma_string_t* string_desc_p = ecma_alloc_string ();
493+
ecma_string_t *string_desc_p = ecma_alloc_string ();
494494
string_desc_p->refs = 1;
495495
string_desc_p->is_stack_var = false;
496496
string_desc_p->container = ECMA_STRING_CONTAINER_HEAP_CHUNKS;

jerry-core/ecma/base/ecma-helpers.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
*/
5252
#define ECMA_SET_POINTER(field, non_compressed_pointer) MEM_CP_SET_POINTER (field, non_compressed_pointer)
5353

54-
/* ecma-helpers-value.c */
54+
/* ecma-helpers-value.cpp */
5555
extern bool ecma_is_value_empty (ecma_value_t value);
5656
extern bool ecma_is_value_undefined (ecma_value_t value);
5757
extern bool ecma_is_value_null (ecma_value_t value);
@@ -109,7 +109,7 @@ extern bool ecma_is_completion_value_normal_true (ecma_completion_value_t value)
109109
extern bool ecma_is_completion_value_normal_false (ecma_completion_value_t value);
110110
extern bool ecma_is_completion_value_empty (ecma_completion_value_t value);
111111

112-
/* ecma-helpers-string.c */
112+
/* ecma-helpers-string.cpp */
113113
extern ecma_string_t* ecma_new_ecma_string (const ecma_char_t *string_p, const ecma_length_t length);
114114
extern ecma_string_t* ecma_new_ecma_string (const ecma_char_t *string_p);
115115
extern ecma_string_t* ecma_new_ecma_string_from_uint32 (uint32_t uint_number);
@@ -162,7 +162,7 @@ extern bool ecma_is_zt_ex_string_magic (const ecma_char_t *zt_string_p, ecma_mag
162162
extern ecma_string_hash_t ecma_string_hash (const ecma_string_t *string_p);
163163
extern ecma_string_hash_t ecma_chars_buffer_calc_hash_last_chars (const ecma_char_t *chars, ecma_length_t length);
164164

165-
/* ecma-helpers-number.c */
165+
/* ecma-helpers-number.cpp */
166166
extern const ecma_number_t ecma_number_relative_eps;
167167

168168
extern ecma_number_t ecma_number_make_nan (void);
@@ -200,7 +200,7 @@ extern void ecma_number_to_decimal (ecma_number_t num,
200200
int32_t *out_digits_num_p,
201201
int32_t *out_decimal_exp_p);
202202

203-
/* ecma-helpers-values-collection.c */
203+
/* ecma-helpers-values-collection.cpp */
204204

205205
extern ecma_collection_header_t *ecma_new_values_collection (const ecma_value_t values_buffer[],
206206
ecma_length_t values_number,
@@ -228,7 +228,7 @@ ecma_collection_iterator_init (ecma_collection_iterator_t *iterator_p,
228228
extern bool
229229
ecma_collection_iterator_next (ecma_collection_iterator_t *iterator_p);
230230

231-
/* ecma-helpers.c */
231+
/* ecma-helpers.cpp */
232232
extern ecma_object_t* ecma_create_object (ecma_object_t *prototype_object_p,
233233
bool is_extensible,
234234
ecma_object_type_t type);
@@ -309,7 +309,7 @@ extern ecma_property_descriptor_t ecma_make_empty_property_descriptor (void);
309309
extern void ecma_free_property_descriptor (ecma_property_descriptor_t *prop_desc_p);
310310
extern ecma_property_descriptor_t ecma_get_property_descriptor_from_property (ecma_property_t *prop_p);
311311

312-
/* ecma-helpers-external-pointers.c */
312+
/* ecma-helpers-external-pointers.cpp */
313313
extern bool
314314
ecma_create_external_pointer_property (ecma_object_t *obj_p,
315315
ecma_internal_property_id_t id,
@@ -329,13 +329,13 @@ extern int32_t ecma_number_to_int32 (ecma_number_t value);
329329
extern ecma_number_t ecma_int32_to_number (int32_t value);
330330
extern ecma_number_t ecma_uint32_to_number (uint32_t value);
331331
extern ecma_length_t ecma_number_to_zt_string (ecma_number_t num, ecma_char_t *buffer_p, ssize_t buffer_size);
332-
extern uint32_t hex_to_int (char hex);
333332

334333
/* ecma-helpers-char.cpp */
335334
extern bool ecma_char_is_new_line (ecma_char_t c);
336335
extern bool ecma_char_is_carriage_return (ecma_char_t c);
337336
extern bool ecma_char_is_line_terminator (ecma_char_t c);
338337
extern bool ecma_char_is_word_char (ecma_char_t c);
338+
extern uint32_t ecma_char_hex_to_int (char hex);
339339

340340
#endif /* !JERRY_ECMA_HELPERS_H */
341341

jerry-core/ecma/base/ecma-magic-strings.inc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EXEC, "exec")
213213
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TEST, "test")
214214
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NAME, "name")
215215
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MESSAGE, "message")
216+
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_G_CHAR, "g")
217+
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_I_CHAR, "i")
218+
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_M_CHAR, "m")
219+
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SLASH_CHAR, "/")
216220
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP, "(?:)")
217221
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LEFT_SQUARE_CHAR, "[")
218222
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_RIGHT_SQUARE_CHAR, "]")

jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
6767
ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value);
6868

6969
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
70-
ecma_property_t *bytecode_prop = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
71-
re_bytecode_t *bytecode_p = ECMA_GET_POINTER (re_bytecode_t, bytecode_prop->u.internal_property.value);
70+
ecma_property_t *bytecode_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
71+
re_bytecode_t *bytecode_p = ECMA_GET_POINTER (re_bytecode_t, bytecode_prop_p->u.internal_property.value);
7272

7373
ECMA_TRY_CATCH (input_str_value,
7474
ecma_op_to_string (arg),
@@ -92,6 +92,7 @@ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
9292

9393
ECMA_FINALIZE (obj_this);
9494
}
95+
9596
return ret_value;
9697
} /* ecma_builtin_regexp_prototype_exec */
9798

@@ -159,7 +160,7 @@ ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argume
159160
ecma_property_t *source_prop_p = ecma_op_object_get_property (obj_p, magic_string_p);
160161
ecma_deref_ecma_string (magic_string_p);
161162

162-
ecma_string_t *src_sep_str_p = ecma_new_ecma_string ((ecma_char_t *) "/");
163+
ecma_string_t *src_sep_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_SLASH_CHAR);
163164
ecma_string_t *source_str_p = ecma_get_string_from_value (source_prop_p->u.named_data_property.value);
164165
ecma_string_t *output_str_p = ecma_concat_ecma_strings (src_sep_str_p, ecma_copy_or_ref_ecma_string (source_str_p));
165166
ecma_deref_ecma_string (source_str_p);
@@ -171,12 +172,12 @@ ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argume
171172

172173
/* Check the global flag */
173174
magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_GLOBAL);
174-
ecma_property_t *global_prop = ecma_op_object_get_property (obj_p, magic_string_p);
175+
ecma_property_t *global_prop_p = ecma_op_object_get_property (obj_p, magic_string_p);
175176
ecma_deref_ecma_string (magic_string_p);
176177

177-
if (ecma_is_value_true (global_prop->u.named_data_property.value))
178+
if (ecma_is_value_true (global_prop_p->u.named_data_property.value))
178179
{
179-
ecma_string_t *g_flag_str_p = ecma_new_ecma_string ((ecma_char_t *) "g");
180+
ecma_string_t *g_flag_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_G_CHAR);
180181
concat_p = ecma_concat_ecma_strings (output_str_p, g_flag_str_p);
181182
ecma_deref_ecma_string (output_str_p);
182183
ecma_deref_ecma_string (g_flag_str_p);
@@ -185,12 +186,12 @@ ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argume
185186

186187
/* Check the ignoreCase flag */
187188
magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_IGNORECASE_UL);
188-
ecma_property_t *ignorecase_prop = ecma_op_object_get_property (obj_p, magic_string_p);
189+
ecma_property_t *ignorecase_prop_p = ecma_op_object_get_property (obj_p, magic_string_p);
189190
ecma_deref_ecma_string (magic_string_p);
190191

191-
if (ecma_is_value_true (ignorecase_prop->u.named_data_property.value))
192+
if (ecma_is_value_true (ignorecase_prop_p->u.named_data_property.value))
192193
{
193-
ecma_string_t *ic_flag_str_p = ecma_new_ecma_string ((ecma_char_t *) "i");
194+
ecma_string_t *ic_flag_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_I_CHAR);
194195
concat_p = ecma_concat_ecma_strings (output_str_p, ic_flag_str_p);
195196
ecma_deref_ecma_string (output_str_p);
196197
ecma_deref_ecma_string (ic_flag_str_p);
@@ -199,12 +200,12 @@ ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argume
199200

200201
/* Check the global flag */
201202
magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_MULTILINE);
202-
ecma_property_t *multiline_prop = ecma_op_object_get_property (obj_p, magic_string_p);
203+
ecma_property_t *multiline_prop_p = ecma_op_object_get_property (obj_p, magic_string_p);
203204
ecma_deref_ecma_string (magic_string_p);
204205

205-
if (ecma_is_value_true (multiline_prop->u.named_data_property.value))
206+
if (ecma_is_value_true (multiline_prop_p->u.named_data_property.value))
206207
{
207-
ecma_string_t *m_flag_str_p = ecma_new_ecma_string ((ecma_char_t *) "m");
208+
ecma_string_t *m_flag_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_M_CHAR);
208209
concat_p = ecma_concat_ecma_strings (output_str_p, m_flag_str_p);
209210
ecma_deref_ecma_string (output_str_p);
210211
ecma_deref_ecma_string (m_flag_str_p);
@@ -215,6 +216,7 @@ ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argume
215216

216217
ECMA_FINALIZE (obj_this);
217218
}
219+
218220
return ret_value;
219221
} /* ecma_builtin_regexp_prototype_to_string */
220222

jerry-core/ecma/builtin-objects/ecma-builtin-regexp.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,33 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
6464
ecma_length_t arguments_list_len) /**< number of arguments */
6565
{
6666
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
67+
ecma_value_t pattern_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
68+
ecma_value_t flags_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
69+
70+
if (arguments_list_len > 0)
71+
{
72+
/* pattern string or RegExp object */
73+
pattern_value = arguments_list_p[0];
74+
75+
if (arguments_list_len > 1)
76+
{
77+
flags_value = arguments_list_p[1];
78+
}
79+
}
6780

6881
if (arguments_list_len == 0)
6982
{
7083
ecma_string_t *magic_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
7184
ret_value = ecma_op_create_regexp_object (magic_str_p, NULL);
7285
ecma_deref_ecma_string (magic_str_p);
7386
}
74-
else if (ecma_is_value_object (arguments_list_p[0])
75-
&& ecma_object_get_class_name (ecma_get_object_from_value (arguments_list_p[0])) == ECMA_MAGIC_STRING_REGEXP_UL)
87+
else if (ecma_is_value_object (pattern_value)
88+
&& ecma_object_get_class_name (ecma_get_object_from_value (pattern_value)) == ECMA_MAGIC_STRING_REGEXP_UL)
7689
{
7790
if (arguments_list_len == 1
78-
|| (arguments_list_len > 1 && ecma_is_value_undefined (arguments_list_p[1])))
91+
|| (arguments_list_len > 1 && ecma_is_value_undefined (flags_value)))
7992
{
80-
ret_value = ecma_make_normal_completion_value (ecma_copy_value (arguments_list_p[0], true));
93+
ret_value = ecma_make_normal_completion_value (ecma_copy_value (pattern_value, true));
8194
}
8295
else
8396
{
@@ -87,7 +100,7 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
87100
else
88101
{
89102
ECMA_TRY_CATCH (regexp_str_value,
90-
ecma_op_to_string (arguments_list_p[0]),
103+
ecma_op_to_string (pattern_value),
91104
ret_value);
92105

93106
ecma_string_t *pattern_string_p = ecma_get_string_from_value (regexp_str_value);
@@ -97,7 +110,7 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
97110
if (arguments_list_len > 1)
98111
{
99112
ECMA_TRY_CATCH (flags_str_value,
100-
ecma_op_to_string (arguments_list_p[1]),
113+
ecma_op_to_string (flags_value),
101114
ret_value);
102115

103116
flags_string_p = ecma_copy_or_ref_ecma_string (ecma_get_string_from_value (flags_str_value));

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ ecma_raise_standard_error (ecma_standard_error_t error_type, /**< error type */
144144
ecma_object_t *error_obj_p = ecma_new_standard_error_with_message (error_type, error_msg_p);
145145
ecma_deref_ecma_string (error_msg_p);
146146
return ecma_make_throw_obj_completion_value (error_obj_p);
147-
}
147+
} /* ecma_raise_standard_error */
148148

149149
/**
150150
* Raise a common error with the given message.
@@ -156,7 +156,7 @@ ecma_completion_value_t
156156
ecma_raise_common_error (const ecma_char_t *msg_p) /**< error message */
157157
{
158158
return ecma_raise_standard_error (ECMA_ERROR_COMMON, msg_p);
159-
}
159+
} /* ecma_raise_common_error */
160160

161161
/**
162162
* Raise an EvalError with the given message.
@@ -170,7 +170,7 @@ ecma_completion_value_t
170170
ecma_raise_eval_error (const ecma_char_t *msg_p) /**< error message */
171171
{
172172
return ecma_raise_standard_error (ECMA_ERROR_EVAL, msg_p);
173-
}
173+
} /* ecma_raise_eval_error */
174174

175175
/**
176176
* Raise a RangeError with the given message.
@@ -184,7 +184,7 @@ ecma_completion_value_t
184184
ecma_raise_range_error (const ecma_char_t *msg_p) /**< error message */
185185
{
186186
return ecma_raise_standard_error (ECMA_ERROR_RANGE, msg_p);
187-
}
187+
} /* ecma_raise_range_error */
188188

189189
/**
190190
* Raise a ReferenceError with the given message.
@@ -198,7 +198,7 @@ ecma_completion_value_t
198198
ecma_raise_reference_error (const ecma_char_t *msg_p) /**< error message */
199199
{
200200
return ecma_raise_standard_error (ECMA_ERROR_REFERENCE, msg_p);
201-
}
201+
} /* ecma_raise_reference_error */
202202

203203
/**
204204
* Raise a SyntaxError with the given message.
@@ -212,7 +212,7 @@ ecma_completion_value_t
212212
ecma_raise_syntax_error (const ecma_char_t *msg_p) /**< error message */
213213
{
214214
return ecma_raise_standard_error (ECMA_ERROR_SYNTAX, msg_p);
215-
}
215+
} /* ecma_raise_syntax_error */
216216

217217
/**
218218
* Raise a TypeError with the given message.
@@ -226,7 +226,7 @@ ecma_completion_value_t
226226
ecma_raise_type_error (const ecma_char_t *msg_p) /**< error message */
227227
{
228228
return ecma_raise_standard_error (ECMA_ERROR_TYPE, msg_p);
229-
}
229+
} /* ecma_raise_type_error */
230230

231231
/**
232232
* Raise a URIError with the given message.
@@ -240,7 +240,7 @@ ecma_completion_value_t
240240
ecma_raise_uri_error (const ecma_char_t *msg_p) /**< error message */
241241
{
242242
return ecma_raise_standard_error (ECMA_ERROR_URI, msg_p);
243-
}
243+
} /* ecma_raise_uri_error */
244244

245245
/**
246246
* @}

0 commit comments

Comments
 (0)