Implement String.prototype.replaceAll
https://bugs.webkit.org/show_bug.cgi?id=202471
Reviewed by Yusuke Suzuki.
JSTests:
- stress/string-replaceall.js: Added.
Source/JavaScriptCore:
Implement the stage 3 proposal here:
https://github.com/tc39/proposal-string-replaceall
String.prototype.replaceAll is the same as String.prototype.replace, except:
- When the first argument is a string, all instances of the search string are replaced.
- When the first argument is a non-global regular expression, a TypeError is thrown.
- builtins/BuiltinNames.h:
- builtins/StringPrototype.js:
(replaceAll): Added.
- runtime/StringPrototype.cpp:
(JSC::StringPrototype::finishCreation):
(JSC::jsSpliceSubstringsWithSeparators): Add early out for single-replacement case.
(JSC::replaceUsingStringSearch): Add global replacement logic, following replaceUsingRegExpSearch.
(JSC::replace):
(JSC::stringProtoFuncReplaceUsingStringSearch):
(JSC::stringProtoFuncReplaceAllUsingStringSearch): Added.
Source/WTF:
(WTF::findCommon):
Fix logic: "start > length" early out should come before "empty search string" early out.
LayoutTests:
- js/Object-getOwnPropertyNames-expected.txt:
- js/script-tests/Object-getOwnPropertyNames.js:
Grrr, why is this a layout test...