@@ -78,17 +78,10 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
78
78
}
79
79
}
80
80
81
- if (arguments_list_len == 0 || ecma_is_value_undefined (arguments_list_p[0 ]))
81
+ if (ecma_is_value_object (pattern_value)
82
+ && ecma_object_get_class_name (ecma_get_object_from_value (pattern_value)) == LIT_MAGIC_STRING_REGEXP_UL)
82
83
{
83
- ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
84
- ret_value = ecma_op_create_regexp_object (magic_str_p, NULL );
85
- ecma_deref_ecma_string (magic_str_p);
86
- }
87
- else if (ecma_is_value_object (pattern_value)
88
- && ecma_object_get_class_name (ecma_get_object_from_value (pattern_value)) == LIT_MAGIC_STRING_REGEXP_UL)
89
- {
90
- if (arguments_list_len == 1
91
- || (arguments_list_len > 1 && ecma_is_value_undefined (flags_value)))
84
+ if (ecma_is_value_undefined (flags_value))
92
85
{
93
86
ret_value = ecma_make_normal_completion_value (ecma_copy_value (pattern_value, true ));
94
87
}
@@ -99,15 +92,32 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
99
92
}
100
93
else
101
94
{
102
- ECMA_TRY_CATCH (regexp_str_value,
103
- ecma_op_to_string (pattern_value),
104
- ret_value);
95
+ ecma_string_t *pattern_string_p = NULL ;
96
+ ecma_string_t *flags_string_p = NULL ;
105
97
106
- ecma_string_t *pattern_string_p = ecma_get_string_from_value (regexp_str_value);
98
+ if (!ecma_is_value_undefined (pattern_value))
99
+ {
100
+ ECMA_TRY_CATCH (regexp_str_value,
101
+ ecma_op_to_string (pattern_value),
102
+ ret_value);
107
103
108
- ecma_string_t *flags_string_p = NULL ;
104
+ if (ecma_string_get_length (ecma_get_string_from_value (regexp_str_value)) == 0 )
105
+ {
106
+ pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
107
+ }
108
+ else
109
+ {
110
+ pattern_string_p = ecma_copy_or_ref_ecma_string (ecma_get_string_from_value (regexp_str_value));
111
+ }
109
112
110
- if (arguments_list_len > 1 )
113
+ ECMA_FINALIZE (regexp_str_value);
114
+ }
115
+ else
116
+ {
117
+ pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
118
+ }
119
+
120
+ if (ecma_is_completion_value_empty (ret_value) && !ecma_is_value_undefined (flags_value))
111
121
{
112
122
ECMA_TRY_CATCH (flags_str_value,
113
123
ecma_op_to_string (flags_value),
@@ -119,24 +129,18 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
119
129
120
130
if (ecma_is_completion_value_empty (ret_value))
121
131
{
122
- if (ecma_string_get_length (pattern_string_p) == 0 )
123
- {
124
- ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
125
- ret_value = ecma_op_create_regexp_object (magic_str_p, flags_string_p);
126
- ecma_deref_ecma_string (magic_str_p);
127
- }
128
- else
129
- {
130
- ret_value = ecma_op_create_regexp_object (pattern_string_p, flags_string_p);
131
- }
132
+ ret_value = ecma_op_create_regexp_object (pattern_string_p, flags_string_p);
133
+ }
134
+
135
+ if (pattern_string_p != NULL )
136
+ {
137
+ ecma_deref_ecma_string (pattern_string_p);
132
138
}
133
139
134
140
if (flags_string_p != NULL )
135
141
{
136
142
ecma_deref_ecma_string (flags_string_p);
137
143
}
138
-
139
- ECMA_FINALIZE (regexp_str_value);
140
144
}
141
145
142
146
return ret_value;
0 commit comments