@@ -20,15 +20,9 @@ var replace = uncurryThis(''.replace);
2020var stringSlice = uncurryThis ( '' . slice ) ;
2121var max = Math . max ;
2222
23- var stringIndexOf = function ( string , searchValue , fromIndex ) {
24- if ( fromIndex > string . length ) return - 1 ;
25- if ( searchValue === '' ) return fromIndex ;
26- return indexOf ( string , searchValue , fromIndex ) ;
27- } ;
28-
2923// `String.prototype.replaceAll` method
3024// https://tc39.es/ecma262/#sec-string.prototype.replaceall
31- $ ( { target : 'String' , proto : true } , {
25+ $ ( { target : 'String' , proto : true , forced : true } , {
3226 replaceAll : function replaceAll ( searchValue , replaceValue ) {
3327 var O = requireObjectCoercible ( this ) ;
3428 var IS_REG_EXP , flags , replacer , string , searchString , functionalReplace , searchLength , advanceBy , replacement ;
@@ -54,14 +48,14 @@ $({ target: 'String', proto: true }, {
5448 if ( ! functionalReplace ) replaceValue = toString ( replaceValue ) ;
5549 searchLength = searchString . length ;
5650 advanceBy = max ( 1 , searchLength ) ;
57- position = stringIndexOf ( string , searchString , 0 ) ;
51+ position = indexOf ( string , searchString ) ;
5852 while ( position !== - 1 ) {
5953 replacement = functionalReplace
6054 ? toString ( replaceValue ( searchString , position , string ) )
6155 : getSubstitution ( searchString , string , position , [ ] , undefined , replaceValue ) ;
6256 result += stringSlice ( string , endOfLastMatch , position ) + replacement ;
6357 endOfLastMatch = position + searchLength ;
64- position = stringIndexOf ( string , searchString , position + advanceBy ) ;
58+ position = position + advanceBy > string . length ? - 1 : indexOf ( string , searchString , position + advanceBy ) ;
6559 }
6660 if ( endOfLastMatch < string . length ) {
6761 result += stringSlice ( string , endOfLastMatch ) ;
0 commit comments