Skip to content

Commit a026a7d

Browse files
authored
Fix releasing 'exec' in regexp replace fast path (#3913)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent e0b2f8e commit a026a7d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,6 +2793,7 @@ ecma_regexp_replace_helper (ecma_value_t this_arg, /**< this argument */
27932793
if (ecma_object_class_is (this_obj_p, LIT_MAGIC_STRING_REGEXP_UL)
27942794
&& ecma_builtin_is_regexp_exec (function_p))
27952795
{
2796+
ecma_deref_object ((ecma_object_t *) function_p);
27962797
result = ecma_op_object_get_by_magic_id (this_obj_p, LIT_MAGIC_STRING_STICKY);
27972798
if (ECMA_IS_VALUE_ERROR (result))
27982799
{
@@ -2817,8 +2818,6 @@ ecma_regexp_replace_helper (ecma_value_t this_arg, /**< this argument */
28172818

28182819
if (replace_ctx.index > string_length)
28192820
{
2820-
ecma_deref_object ((ecma_object_t *) function_p);
2821-
28222821
result = ecma_op_object_put (this_obj_p,
28232822
ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
28242823
ecma_make_uint32_value (0),
@@ -2840,7 +2839,6 @@ ecma_regexp_replace_helper (ecma_value_t this_arg, /**< this argument */
28402839
string_p,
28412840
replace_arg);
28422841

2843-
ecma_deref_object ((ecma_object_t *) function_p);
28442842
goto cleanup_replace;
28452843
}
28462844
}

tests/jerry/es.next/symbol-replace.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,3 +672,17 @@ class Regexplike2 {
672672
}
673673
re = new Regexplike2();
674674
assert (replace.call (re, "1") === "undefined");
675+
676+
var abruptStickyRegexp = /./;
677+
Object.defineProperty(abruptStickyRegexp, 'sticky', {
678+
get: function() {
679+
throw "abrupt sticky";
680+
}
681+
});
682+
683+
try {
684+
abruptStickyRegexp[Symbol.replace]();
685+
assert(false);
686+
} catch (e) {
687+
assert(e === "abrupt sticky");
688+
}

0 commit comments

Comments
 (0)