Skip to content

Commit 6d9d232

Browse files
authored
Fix built-in RegExp allocation with default constructor (#3883)
Fixes #3880. Fixes #3881. JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
1 parent dba9533 commit 6d9d232

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

jerry-core/ecma/operations/ecma-regexp-object.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -210,32 +210,14 @@ ecma_object_t *
210210
ecma_op_regexp_alloc (ecma_object_t *ctr_obj_p) /**< constructor object pointer */
211211
{
212212
#if ENABLED (JERRY_ES2015)
213-
bool default_alloc = false;
214-
215213
if (ctr_obj_p == NULL)
216214
{
217-
ecma_object_t *re_prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE);
218-
219-
ecma_value_t ctr_value = ecma_op_object_get_by_magic_id (re_prototype_obj_p, LIT_MAGIC_STRING_CONSTRUCTOR);
220-
221-
if (ECMA_IS_VALUE_ERROR (ctr_value))
222-
{
223-
return NULL;
224-
}
225-
226-
ctr_obj_p = ecma_get_object_from_value (ctr_value);
227-
228-
default_alloc = true;
215+
ctr_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP);
229216
}
230217

231218
ecma_object_t *proto_obj_p = ecma_op_get_prototype_from_constructor (ctr_obj_p,
232219
ECMA_BUILTIN_ID_REGEXP_PROTOTYPE);
233220

234-
if (default_alloc)
235-
{
236-
ecma_deref_object (ctr_obj_p);
237-
}
238-
239221
if (JERRY_UNLIKELY (proto_obj_p == NULL))
240222
{
241223
return proto_obj_p;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
RegExp.prototype.constructor = ""
16+
var r = /a/;
17+
assert (r.test ("a"));
18+
19+
RegExp.prototype.constructor = {}
20+
r = /b/;
21+
assert (r.test ("b"));

0 commit comments

Comments
 (0)