Bug 1343363 - Check RegExp wasn't modified in RegExp.p.@@replace global elem-base optimized path. r=till

This commit is contained in:
André Bargull 2017-06-05 13:23:01 +02:00
parent 10b72ec89d
commit 760dd32599
2 changed files with 24 additions and 2 deletions

View File

@ -31,7 +31,7 @@ function FUNC_NAME(rx, S, lengthS, replaceValue, fullUnicode
var lastIndex = 0;
rx.lastIndex = 0;
#if defined(FUNCTIONAL)
#if defined(FUNCTIONAL) || defined(ELEMBASE)
// Save the original source and flags, so we can check if the replacer
// function recompiled the regexp.
var originalSource = UnsafeGetStringFromReservedSlot(rx, REGEXP_SOURCE_SLOT);
@ -109,7 +109,7 @@ function FUNC_NAME(rx, S, lengthS, replaceValue, fullUnicode
break;
}
#if defined(FUNCTIONAL)
#if defined(FUNCTIONAL) || defined(ELEMBASE)
// Ensure the current source and flags match the original regexp, the
// replaceValue function may have called RegExp#compile.
if (UnsafeGetStringFromReservedSlot(rx, REGEXP_SOURCE_SLOT) !== originalSource ||

View File

@ -0,0 +1,22 @@
(function() {
var rx = /a/g;
var b = {
get a() {
rx.compile("b");
return "A";
}
};
// Replacer function which is applicable for the elem-base optimization in
// RegExp.prototype.@@replace.
function replacer(a) {
return b[a];
}
var result = rx[Symbol.replace]("aaa", replacer);
assertEq(result, "AAA");
})();
if (typeof reportCompare === "function")
reportCompare(true, true);