Fix leaking lastIndex values in RegExp built-ins (#4166)

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu
This commit is contained in:
Dániel Bátyai
2020-08-28 13:09:53 +02:00
committed by GitHub
parent 6d0e948bef
commit e98f5342f9
3 changed files with 58 additions and 17 deletions
+30 -1
View File
@@ -721,4 +721,33 @@ assert(r[Symbol.replace]("aaaa", function(match, index) {
}) === "baaa");
assert (replaceCalled);
assert (r.lastIndex === 2)
assert (r.lastIndex === 2);
(function () {
var r = /./g;
var execWasCalled = false;
var coercibleIndex = {
valueOf: function() {
return Math.pow(2, 54);
},
};
var result = {
length: 1,
0: '',
index: 0,
};
r.exec = function() {
if (execWasCalled) {
return null;
}
r.lastIndex = coercibleIndex;
execWasCalled = true;
return result;
};
assert(r[Symbol.replace]('', '') === '');
assert(r.lastIndex === Math.pow(2, 53));
})();