// Tests for String.prototype builtins with custom regexp symbols on // RegExp.prototype. // Use fresh globals because this pops realm fuses.
// Custom RegExp.prototype[@@match].
newGlobal().evaluate(`(function() { var s = "foobar"; var re = /abc.+/; var count = 0; for (var i = 0; i < 200; i++) {
s.match(re); if (i === 150) {
RegExp.prototype[Symbol.match] = function() {
count++; returnnull;
};
}
}
assertEq(count, 49);
})();`);
// Custom RegExp.prototype[@@matchAll].
newGlobal().evaluate(`(function() { var s = "foobar"; var re = /abc.+/g; var count = 0; for (var i = 0; i < 200; i++) {
s.matchAll(re); if (i === 150) {
RegExp.prototype[Symbol.matchAll] = function() {
count++; returnnull;
};
}
}
assertEq(count, 49);
})();`);
// Custom RegExp.prototype[@@replace] for replace.
newGlobal().evaluate(`(function() { var s = "foobar"; var re = /abc.+/; var count = 0; for (var i = 0; i < 200; i++) {
s.replace(re, ""); if (i === 150) {
RegExp.prototype[Symbol.replace] = function() {
count++; return"";
};
}
}
assertEq(count, 49);
})();`);
// Custom RegExp.prototype[@@replace] for replaceAll.
newGlobal().evaluate(`(function() { var s = "foobar"; var re = /abc.+/g; var count = 0; for (var i = 0; i < 200; i++) {
s.replaceAll(re, ""); if (i === 150) {
RegExp.prototype[Symbol.replace] = function() {
count++; return"";
};
}
}
assertEq(count, 49);
})();`);
// Custom RegExp.prototype[@@search].
newGlobal().evaluate(`(function() { var s = "foobar"; var re = /abc.+/g; var count = 0; for (var i = 0; i < 200; i++) {
s.search(re); if (i === 150) {
RegExp.prototype[Symbol.search] = function() {
count++; return -1;
};
}
}
assertEq(count, 49);
})();`);
// Custom RegExp.prototype[@@split].
newGlobal().evaluate(`(function() { var s = "foobar"; var re = /abc.+/; var count = 0; for (var i = 0; i < 200; i++) {
s.split(re); if (i === 150) {
RegExp.prototype[Symbol.split] = function() {
count++; return [];
};
}
}
assertEq(count, 49);
})();`);
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.