Skip to content

Commit

Permalink
Style fixes for RegExp.
Browse files Browse the repository at this point in the history
JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
  • Loading branch information
LaszloLango committed Jun 25, 2015
1 parent 065785b commit bdbe9e7
Show file tree
Hide file tree
Showing 23 changed files with 298 additions and 253 deletions.
2 changes: 1 addition & 1 deletion jerry-core/ecma/base/ecma-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ typedef enum
ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, /** One of built-in functions described in section 15
of ECMA-262 v5 specification */
ECMA_OBJECT_TYPE_ARGUMENTS, /**< Arguments object (10.6) */
ECMA_OBJECT_TYPE_ARRAY, /**< Array object (15.4) */
ECMA_OBJECT_TYPE_ARRAY /**< Array object (15.4) */
// ECMA_OBJECT_TYPE_HOST /**< Host object */
} ecma_object_type_t;

Expand Down
36 changes: 36 additions & 0 deletions jerry-core/ecma/base/ecma-helpers-char.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,42 @@ ecma_char_is_word_char (ecma_char_t c) /**< character value */
return false;
} /* ecma_char_is_word_char */

/**
* Convert a hex character to an unsigned integer
*
* @return unsigned integer
*/
uint32_t
ecma_char_hex_to_int (char hex)
{
switch (hex)
{
case '0': return 0x0;
case '1': return 0x1;
case '2': return 0x2;
case '3': return 0x3;
case '4': return 0x4;
case '5': return 0x5;
case '6': return 0x6;
case '7': return 0x7;
case '8': return 0x8;
case '9': return 0x9;
case 'a':
case 'A': return 0xA;
case 'b':
case 'B': return 0xB;
case 'c':
case 'C': return 0xC;
case 'd':
case 'D': return 0xD;
case 'e':
case 'E': return 0xE;
case 'f':
case 'F': return 0xF;
default: JERRY_UNREACHABLE ();
}
} /* ecma_char_hex_to_int */

/**
* @}
* @}
Expand Down
36 changes: 0 additions & 36 deletions jerry-core/ecma/base/ecma-helpers-conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1506,42 +1506,6 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
return length;
} /* ecma_number_to_zt_string */

/**
* Convert a hex character to an unsigned integer
*
* @return unsigned integer
*/
uint32_t
hex_to_int (char hex)
{
switch (hex)
{
case '0': return 0x0;
case '1': return 0x1;
case '2': return 0x2;
case '3': return 0x3;
case '4': return 0x4;
case '5': return 0x5;
case '6': return 0x6;
case '7': return 0x7;
case '8': return 0x8;
case '9': return 0x9;
case 'a':
case 'A': return 0xA;
case 'b':
case 'B': return 0xB;
case 'c':
case 'C': return 0xC;
case 'd':
case 'D': return 0xD;
case 'e':
case 'E': return 0xE;
case 'f':
case 'F': return 0xF;
default: JERRY_UNREACHABLE ();
}
} /* hex_to_int */

/**
* @}
* @}
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/ecma/base/ecma-helpers-string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ ecma_new_ecma_string (const ecma_char_t *string_p, /**< input string */
mem_heap_free_block (zt_str_p);
}

ecma_string_t* string_desc_p = ecma_alloc_string ();
ecma_string_t *string_desc_p = ecma_alloc_string ();
string_desc_p->refs = 1;
string_desc_p->is_stack_var = false;
string_desc_p->container = ECMA_STRING_CONTAINER_HEAP_CHUNKS;
Expand Down
14 changes: 7 additions & 7 deletions jerry-core/ecma/base/ecma-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
*/
#define ECMA_SET_POINTER(field, non_compressed_pointer) MEM_CP_SET_POINTER (field, non_compressed_pointer)

/* ecma-helpers-value.c */
/* ecma-helpers-value.cpp */
extern bool ecma_is_value_empty (ecma_value_t value);
extern bool ecma_is_value_undefined (ecma_value_t value);
extern bool ecma_is_value_null (ecma_value_t value);
Expand Down Expand Up @@ -109,7 +109,7 @@ extern bool ecma_is_completion_value_normal_true (ecma_completion_value_t value)
extern bool ecma_is_completion_value_normal_false (ecma_completion_value_t value);
extern bool ecma_is_completion_value_empty (ecma_completion_value_t value);

/* ecma-helpers-string.c */
/* ecma-helpers-string.cpp */
extern ecma_string_t* ecma_new_ecma_string (const ecma_char_t *string_p, const ecma_length_t length);
extern ecma_string_t* ecma_new_ecma_string (const ecma_char_t *string_p);
extern ecma_string_t* ecma_new_ecma_string_from_uint32 (uint32_t uint_number);
Expand Down Expand Up @@ -162,7 +162,7 @@ extern bool ecma_is_zt_ex_string_magic (const ecma_char_t *zt_string_p, ecma_mag
extern ecma_string_hash_t ecma_string_hash (const ecma_string_t *string_p);
extern ecma_string_hash_t ecma_chars_buffer_calc_hash_last_chars (const ecma_char_t *chars, ecma_length_t length);

/* ecma-helpers-number.c */
/* ecma-helpers-number.cpp */
extern const ecma_number_t ecma_number_relative_eps;

extern ecma_number_t ecma_number_make_nan (void);
Expand Down Expand Up @@ -200,7 +200,7 @@ extern void ecma_number_to_decimal (ecma_number_t num,
int32_t *out_digits_num_p,
int32_t *out_decimal_exp_p);

/* ecma-helpers-values-collection.c */
/* ecma-helpers-values-collection.cpp */

extern ecma_collection_header_t *ecma_new_values_collection (const ecma_value_t values_buffer[],
ecma_length_t values_number,
Expand Down Expand Up @@ -228,7 +228,7 @@ ecma_collection_iterator_init (ecma_collection_iterator_t *iterator_p,
extern bool
ecma_collection_iterator_next (ecma_collection_iterator_t *iterator_p);

/* ecma-helpers.c */
/* ecma-helpers.cpp */
extern ecma_object_t* ecma_create_object (ecma_object_t *prototype_object_p,
bool is_extensible,
ecma_object_type_t type);
Expand Down Expand Up @@ -309,7 +309,7 @@ extern ecma_property_descriptor_t ecma_make_empty_property_descriptor (void);
extern void ecma_free_property_descriptor (ecma_property_descriptor_t *prop_desc_p);
extern ecma_property_descriptor_t ecma_get_property_descriptor_from_property (ecma_property_t *prop_p);

/* ecma-helpers-external-pointers.c */
/* ecma-helpers-external-pointers.cpp */
extern bool
ecma_create_external_pointer_property (ecma_object_t *obj_p,
ecma_internal_property_id_t id,
Expand All @@ -329,13 +329,13 @@ extern int32_t ecma_number_to_int32 (ecma_number_t value);
extern ecma_number_t ecma_int32_to_number (int32_t value);
extern ecma_number_t ecma_uint32_to_number (uint32_t value);
extern ecma_length_t ecma_number_to_zt_string (ecma_number_t num, ecma_char_t *buffer_p, ssize_t buffer_size);
extern uint32_t hex_to_int (char hex);

/* ecma-helpers-char.cpp */
extern bool ecma_char_is_new_line (ecma_char_t c);
extern bool ecma_char_is_carriage_return (ecma_char_t c);
extern bool ecma_char_is_line_terminator (ecma_char_t c);
extern bool ecma_char_is_word_char (ecma_char_t c);
extern uint32_t ecma_char_hex_to_int (char hex);

#endif /* !JERRY_ECMA_HELPERS_H */

Expand Down
4 changes: 4 additions & 0 deletions jerry-core/ecma/base/ecma-magic-strings.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EXEC, "exec")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TEST, "test")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NAME, "name")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MESSAGE, "message")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_G_CHAR, "g")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_I_CHAR, "i")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_M_CHAR, "m")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SLASH_CHAR, "/")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP, "(?:)")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LEFT_SQUARE_CHAR, "[")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_RIGHT_SQUARE_CHAR, "]")
Expand Down
26 changes: 14 additions & 12 deletions jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value);

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

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

ECMA_FINALIZE (obj_this);
}

return ret_value;
} /* ecma_builtin_regexp_prototype_exec */

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

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

/* Check the global flag */
magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_GLOBAL);
ecma_property_t *global_prop = ecma_op_object_get_property (obj_p, magic_string_p);
ecma_property_t *global_prop_p = ecma_op_object_get_property (obj_p, magic_string_p);
ecma_deref_ecma_string (magic_string_p);

if (ecma_is_value_true (global_prop->u.named_data_property.value))
if (ecma_is_value_true (global_prop_p->u.named_data_property.value))
{
ecma_string_t *g_flag_str_p = ecma_new_ecma_string ((ecma_char_t *) "g");
ecma_string_t *g_flag_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_G_CHAR);
concat_p = ecma_concat_ecma_strings (output_str_p, g_flag_str_p);
ecma_deref_ecma_string (output_str_p);
ecma_deref_ecma_string (g_flag_str_p);
Expand All @@ -185,12 +186,12 @@ ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argume

/* Check the ignoreCase flag */
magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_IGNORECASE_UL);
ecma_property_t *ignorecase_prop = ecma_op_object_get_property (obj_p, magic_string_p);
ecma_property_t *ignorecase_prop_p = ecma_op_object_get_property (obj_p, magic_string_p);
ecma_deref_ecma_string (magic_string_p);

if (ecma_is_value_true (ignorecase_prop->u.named_data_property.value))
if (ecma_is_value_true (ignorecase_prop_p->u.named_data_property.value))
{
ecma_string_t *ic_flag_str_p = ecma_new_ecma_string ((ecma_char_t *) "i");
ecma_string_t *ic_flag_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_I_CHAR);
concat_p = ecma_concat_ecma_strings (output_str_p, ic_flag_str_p);
ecma_deref_ecma_string (output_str_p);
ecma_deref_ecma_string (ic_flag_str_p);
Expand All @@ -199,12 +200,12 @@ ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argume

/* Check the global flag */
magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_MULTILINE);
ecma_property_t *multiline_prop = ecma_op_object_get_property (obj_p, magic_string_p);
ecma_property_t *multiline_prop_p = ecma_op_object_get_property (obj_p, magic_string_p);
ecma_deref_ecma_string (magic_string_p);

if (ecma_is_value_true (multiline_prop->u.named_data_property.value))
if (ecma_is_value_true (multiline_prop_p->u.named_data_property.value))
{
ecma_string_t *m_flag_str_p = ecma_new_ecma_string ((ecma_char_t *) "m");
ecma_string_t *m_flag_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_M_CHAR);
concat_p = ecma_concat_ecma_strings (output_str_p, m_flag_str_p);
ecma_deref_ecma_string (output_str_p);
ecma_deref_ecma_string (m_flag_str_p);
Expand All @@ -215,6 +216,7 @@ ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argume

ECMA_FINALIZE (obj_this);
}

return ret_value;
} /* ecma_builtin_regexp_prototype_to_string */

Expand Down
25 changes: 19 additions & 6 deletions jerry-core/ecma/builtin-objects/ecma-builtin-regexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,33 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
ecma_length_t arguments_list_len) /**< number of arguments */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ecma_value_t pattern_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
ecma_value_t flags_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);

if (arguments_list_len > 0)
{
/* pattern string or RegExp object */
pattern_value = arguments_list_p[0];

if (arguments_list_len > 1)
{
flags_value = arguments_list_p[1];
}
}

if (arguments_list_len == 0)
{
ecma_string_t *magic_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
ret_value = ecma_op_create_regexp_object (magic_str_p, NULL);
ecma_deref_ecma_string (magic_str_p);
}
else if (ecma_is_value_object (arguments_list_p[0])
&& ecma_object_get_class_name (ecma_get_object_from_value (arguments_list_p[0])) == ECMA_MAGIC_STRING_REGEXP_UL)
else if (ecma_is_value_object (pattern_value)
&& ecma_object_get_class_name (ecma_get_object_from_value (pattern_value)) == ECMA_MAGIC_STRING_REGEXP_UL)
{
if (arguments_list_len == 1
|| (arguments_list_len > 1 && ecma_is_value_undefined (arguments_list_p[1])))
|| (arguments_list_len > 1 && ecma_is_value_undefined (flags_value)))
{
ret_value = ecma_make_normal_completion_value (ecma_copy_value (arguments_list_p[0], true));
ret_value = ecma_make_normal_completion_value (ecma_copy_value (pattern_value, true));
}
else
{
Expand All @@ -87,7 +100,7 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
else
{
ECMA_TRY_CATCH (regexp_str_value,
ecma_op_to_string (arguments_list_p[0]),
ecma_op_to_string (pattern_value),
ret_value);

ecma_string_t *pattern_string_p = ecma_get_string_from_value (regexp_str_value);
Expand All @@ -97,7 +110,7 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
if (arguments_list_len > 1)
{
ECMA_TRY_CATCH (flags_str_value,
ecma_op_to_string (arguments_list_p[1]),
ecma_op_to_string (flags_value),
ret_value);

flags_string_p = ecma_copy_or_ref_ecma_string (ecma_get_string_from_value (flags_str_value));
Expand Down
16 changes: 8 additions & 8 deletions jerry-core/ecma/operations/ecma-exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ ecma_raise_standard_error (ecma_standard_error_t error_type, /**< error type */
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.
Expand All @@ -156,7 +156,7 @@ 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.
Expand All @@ -170,7 +170,7 @@ 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.
Expand All @@ -184,7 +184,7 @@ 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.
Expand All @@ -198,7 +198,7 @@ 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.
Expand All @@ -212,7 +212,7 @@ 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.
Expand All @@ -226,7 +226,7 @@ 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.
Expand All @@ -240,7 +240,7 @@ 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 */

/**
* @}
Expand Down
Loading

0 comments on commit bdbe9e7

Please sign in to comment.