<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>246274</bug_id>
          
          <creation_ts>2022-10-10 04:52:57 -0700</creation_ts>
          <short_desc>String.prototype.replace should not take fast path if the pattern is RegExp Object and the lastIndex is not numeric</short_desc>
          <delta_ts>2024-02-23 13:29:34 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Local Build</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="EntryHi">entryhii</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>karlcow</cc>
    
    <cc>mark.lam</cc>
    
    <cc>msaboff</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1904460</commentid>
    <comment_count>0</comment_count>
    <who name="EntryHi">entryhii</who>
    <bug_when>2022-10-10 04:52:57 -0700</bug_when>
    <thetext>for (let i = 0; i &lt; 3000; ++i) {
  let r = /abcd/;
  regexLastIndex = {};
  regexLastIndex.toString = function () {
    print(i)
    return &quot;1&quot;;
  };
  r.lastIndex = regexLastIndex;
  &quot;test&quot;.replace(r, &quot;cons&quot;)
}

With the above script as input to JSC, run JSC with the following parameters:
./jsc test.js --useConcurrentJIT=0

This bug is similar to 191731, but they are different. The above js scripts should print 0-2999, but jsc only prints 0-2209.

In DFGBytecodeParser, replace is inlined into StringReplace node. In DFGStrengthReduction, StringReplace is converted to Identity.
So after DFG, lastIndex is no longer read and updated. Therefore, regexLastIndex.toString is no longer invoked.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1905300</commentid>
    <comment_count>1</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2022-10-13 03:07:42 -0700</bug_when>
    <thetext>Modified to run in the browser console. 

```
for (let i = 0; i &lt; 3000; ++i) {
  let r = /abcd/;
  regexLastIndex = {};
  regexLastIndex.toString = function () {
    console.log(i)
    return &quot;1&quot;;
  };
  r.lastIndex = regexLastIndex;
  &quot;test&quot;.replace(r, &quot;cons&quot;)
}
```

Safari result is random
Both Firefox and Chrome print until 2999.

Tested on macOS 13.0
---
Safari Technology Preview  155           18615.1.7.1
Firefox Nightly            107.0a1       10722.10.4
Google Chrome Canary       108.0.5355.0  5355.0</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1905314</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-10-13 05:28:55 -0700</bug_when>
    <thetext>&lt;rdar://problem/101122567&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2016120</commentid>
    <comment_count>3</comment_count>
    <who name="Sosuke Suzuki">sosuke</who>
    <bug_when>2024-02-22 10:51:10 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/24959</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2016471</commentid>
    <comment_count>4</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-02-23 13:29:32 -0800</bug_when>
    <thetext>Committed 275255@main (3790f1e3cc0a): &lt;https://commits.webkit.org/275255@main&gt;

Reviewed commits have been landed. Closing PR #24959 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>