|
18 | 18 | #include "ecma-conversion.h" |
19 | 19 | #include "ecma-globals.h" |
20 | 20 | #include "ecma-helpers.h" |
| 21 | +#include "ecma-objects.h" |
21 | 22 | #include "ecma-try-catch-macro.h" |
22 | 23 |
|
23 | 24 | #ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN |
@@ -86,6 +87,133 @@ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */ |
86 | 87 | return ret_value; |
87 | 88 | } /* ecma_builtin_regexp_prototype_exec */ |
88 | 89 |
|
| 90 | +/** |
| 91 | + * @} |
| 92 | + * @} |
| 93 | + * @} |
| 94 | + */ |
| 95 | + |
| 96 | +/** |
| 97 | + * The RegExp.prototype object's 'test' routine |
| 98 | + * |
| 99 | + * See also: |
| 100 | + * ECMA-262 v5, 15.10.6.3 |
| 101 | + * |
| 102 | + * @return completion value |
| 103 | + * Returned value must be freed with ecma_free_completion_value. |
| 104 | + */ |
| 105 | +static ecma_completion_value_t |
| 106 | +ecma_builtin_regexp_prototype_test (ecma_value_t this_arg, /**< this argument */ |
| 107 | + ecma_value_t arg) /**< routine's argument */ |
| 108 | +{ |
| 109 | + ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); |
| 110 | + |
| 111 | + ECMA_TRY_CATCH (match_value, |
| 112 | + ecma_builtin_regexp_prototype_exec (this_arg, arg), |
| 113 | + ret_value); |
| 114 | + if (ecma_is_value_undefined (match_value)) |
| 115 | + { |
| 116 | + ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE); |
| 117 | + } |
| 118 | + else |
| 119 | + { |
| 120 | + ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); |
| 121 | + } |
| 122 | + ECMA_FINALIZE (match_value); |
| 123 | + |
| 124 | + return ret_value; |
| 125 | +} /* ecma_builtin_regexp_prototype_test */ |
| 126 | + |
| 127 | +/** |
| 128 | + * @} |
| 129 | + * @} |
| 130 | + * @} |
| 131 | + */ |
| 132 | + |
| 133 | +/** |
| 134 | + * The RegExp.prototype object's 'toString' routine |
| 135 | + * |
| 136 | + * See also: |
| 137 | + * ECMA-262 v5, 15.10.6.4 |
| 138 | + * |
| 139 | + * @return completion value |
| 140 | + * Returned value must be freed with ecma_free_completion_value. |
| 141 | + */ |
| 142 | +static ecma_completion_value_t |
| 143 | +ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argument */ |
| 144 | +{ |
| 145 | + ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); |
| 146 | + |
| 147 | + ECMA_TRY_CATCH (obj_this, |
| 148 | + ecma_op_to_object (this_arg), |
| 149 | + ret_value); |
| 150 | + |
| 151 | + ecma_object_t *obj_p = ecma_get_object_from_value (obj_this); |
| 152 | + |
| 153 | + /* Get RegExp source from the source property */ |
| 154 | + ecma_string_t *magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_SOURCE); |
| 155 | + ecma_property_t* source_prop = ecma_op_object_get_property (obj_p, magic_string_p); |
| 156 | + ecma_deref_ecma_string (magic_string_p); |
| 157 | + |
| 158 | + ecma_string_t *src_sep_str_p = ecma_new_ecma_string ((ecma_char_t *) "/"); |
| 159 | + ecma_string_t *source_str_p = ecma_get_string_from_value (source_prop->u.named_data_property.value); |
| 160 | + ecma_string_t *output_str_p = ecma_concat_ecma_strings (src_sep_str_p, ecma_copy_or_ref_ecma_string (source_str_p)); |
| 161 | + ecma_deref_ecma_string (source_str_p); |
| 162 | + |
| 163 | + ecma_string_t *concat_p = ecma_concat_ecma_strings (output_str_p, src_sep_str_p); |
| 164 | + ecma_deref_ecma_string (src_sep_str_p); |
| 165 | + ecma_deref_ecma_string (output_str_p); |
| 166 | + output_str_p = concat_p; |
| 167 | + |
| 168 | + /* Check the global flag */ |
| 169 | + magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_GLOBAL); |
| 170 | + ecma_property_t* global_prop = ecma_op_object_get_property (obj_p, magic_string_p); |
| 171 | + ecma_deref_ecma_string (magic_string_p); |
| 172 | + |
| 173 | + if (ecma_is_value_true (global_prop->u.named_data_property.value)) |
| 174 | + { |
| 175 | + ecma_string_t *g_flag_str_p = ecma_new_ecma_string ((ecma_char_t *) "g"); |
| 176 | + concat_p = ecma_concat_ecma_strings (output_str_p, g_flag_str_p); |
| 177 | + ecma_deref_ecma_string (output_str_p); |
| 178 | + ecma_deref_ecma_string (g_flag_str_p); |
| 179 | + output_str_p = concat_p; |
| 180 | + } |
| 181 | + |
| 182 | + /* Check the ignoreCase flag */ |
| 183 | + magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_IGNORECASE); |
| 184 | + ecma_property_t* ignorecase_prop = ecma_op_object_get_property (obj_p, magic_string_p); |
| 185 | + ecma_deref_ecma_string (magic_string_p); |
| 186 | + |
| 187 | + if (ecma_is_value_true (ignorecase_prop->u.named_data_property.value)) |
| 188 | + { |
| 189 | + ecma_string_t *ic_flag_str_p = ecma_new_ecma_string ((ecma_char_t *) "i"); |
| 190 | + concat_p = ecma_concat_ecma_strings (output_str_p, ic_flag_str_p); |
| 191 | + ecma_deref_ecma_string (output_str_p); |
| 192 | + ecma_deref_ecma_string (ic_flag_str_p); |
| 193 | + output_str_p = concat_p; |
| 194 | + } |
| 195 | + |
| 196 | + /* Check the global flag */ |
| 197 | + magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_MULTILINE); |
| 198 | + ecma_property_t* multiline_prop = ecma_op_object_get_property (obj_p, magic_string_p); |
| 199 | + ecma_deref_ecma_string (magic_string_p); |
| 200 | + |
| 201 | + if (ecma_is_value_true (multiline_prop->u.named_data_property.value)) |
| 202 | + { |
| 203 | + ecma_string_t *m_flag_str_p = ecma_new_ecma_string ((ecma_char_t *) "m"); |
| 204 | + concat_p = ecma_concat_ecma_strings (output_str_p, m_flag_str_p); |
| 205 | + ecma_deref_ecma_string (output_str_p); |
| 206 | + ecma_deref_ecma_string (m_flag_str_p); |
| 207 | + output_str_p = concat_p; |
| 208 | + } |
| 209 | + |
| 210 | + ret_value = ecma_make_normal_completion_value (ecma_make_string_value (output_str_p)); |
| 211 | + |
| 212 | + ECMA_FINALIZE (obj_this); |
| 213 | + |
| 214 | + return ret_value; |
| 215 | +} /* ecma_builtin_regexp_prototype_to_string */ |
| 216 | + |
89 | 217 | /** |
90 | 218 | * @} |
91 | 219 | * @} |
|
0 commit comments