Closed Bug 1540021 Opened 1 year ago Closed 3 months ago

Implement the String.prototype.replaceAll proposal

Categories

(Core :: JavaScript: Standard Library, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla72
Tracking Status
firefox72 --- fixed

People

(Reporter: alex.fdm, Assigned: anba)

References

(Blocks 2 open bugs, )

Details

(Keywords: dev-doc-needed)

Attachments

(1 file)

The proposal is now on Stage 2.

Priority: -- → P3

The proposal advanced to stage 3 at today’s TC39 meeting.

Component: JavaScript Engine → JavaScript: Standard Library

This change doesn't include the String.prototype.matchAll modifications, because
those are already part of the main spec.

MCallOptimize.cpp:

  • The inlining is more conservative than inlineIsRegExpObject, because it's not
    clear at this point we need the extra features from inlineIsRegExpObject.

String.js:

  • The self-hosted part is slightly different than the current spec text, because
    it combines the match and replace loops. The non-functional replace part is
    implemented in C++, so we can reuse the existing C++ matcher functions.

String.cpp:

  • Added some extra assertions to AppendDollarReplacement and also had to change
    the infallibleAppend call into a normal append call, because when called
    from replaceAll, we may not have reserved enough space in the StringBuffer.
  • replaceAll has a specialised implementation when the pattern is the empty
    string, because in that case the pattern is interleaved in-between each
    character, so we don't need to find the next match and can also directly reserve
    the correct string length (when no '$' characters are present in the replacement
    string). This should allow users to update from the previous
    str.split("").join(r) pattern to str.replaceAll("", r) without loss of
    performance.
  • When the pattern isn't the empty string, we reuse the existing StringMatch
    and AppendDollarReplacement functions to match and replace the pattern.

This feature is still restricted to Nightly, because no test262 tests are
currently available.

Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
Pushed by csabou@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/705533ca2ccb
Implement String.prototype.replaceAll proposal. r=jorendorff
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla72

Thanks for submitting this, André. We really appreciate it.

Blocks: 1608168
You need to log in before you can comment on or make changes to this bug.