Ignore:
Timestamp:
Nov 19, 2019, 9:12:14 PM (6 years ago)
Author:
Ross Kirsling
Message:

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:

  1. When the first argument is a string, all instances of the search string are replaced.
  2. 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/text/StringCommon.h:

(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...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r252680 r252683  
     12019-11-19  Ross Kirsling  <[email protected]>
     2
     3        Implement String.prototype.replaceAll
     4        https://bugs.webkit.org/show_bug.cgi?id=202471
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Implement the stage 3 proposal here:
     9        https://github.com/tc39/proposal-string-replaceall
     10
     11        String.prototype.replaceAll is the same as String.prototype.replace, except:
     12        1. When the first argument is a string, all instances of the search string are replaced.
     13        2. When the first argument is a non-global regular expression, a TypeError is thrown.
     14
     15        * builtins/BuiltinNames.h:
     16        * builtins/StringPrototype.js:
     17        (replaceAll): Added.
     18        * runtime/StringPrototype.cpp:
     19        (JSC::StringPrototype::finishCreation):
     20        (JSC::jsSpliceSubstringsWithSeparators): Add early out for single-replacement case.
     21        (JSC::replaceUsingStringSearch): Add global replacement logic, following replaceUsingRegExpSearch.
     22        (JSC::replace):
     23        (JSC::stringProtoFuncReplaceUsingStringSearch):
     24        (JSC::stringProtoFuncReplaceAllUsingStringSearch): Added.
     25
    1262019-11-19  Robin Morisset  <[email protected]>
    227
Note: See TracChangeset for help on using the changeset viewer.