<?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>244196</bug_id>
          
          <creation_ts>2022-08-22 04:27:04 -0700</creation_ts>
          <short_desc>String.prototype.includes incorrectly returns false when string is empty and position is past end of string</short_desc>
          <delta_ts>2022-09-09 12:47:02 -0700</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>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=144314</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>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="Darin Adler">darin</assigned_to>
          <cc>darin</cc>
    
    <cc>mark.lam</cc>
    
    <cc>saam</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1892934</commentid>
    <comment_count>0</comment_count>
    <who name="EntryHi">entryhii</who>
    <bug_when>2022-08-22 04:27:04 -0700</bug_when>
    <thetext>function foo(n) {
    return (&quot;aaa&quot;).includes(&quot;&quot;, n)
}
noInline(foo);
for (var m = 0; m &lt; 200; ++m) {
  print(foo(m));
}

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

According to ECMAScript Language Specification, when the first parameter of String.prototype.includes is empty, the result should be true regardless of whether the second parameter is greater than length. However, JSC prints false when n exceeds length.

The problem is in StringPrototype.cpp stringIncluesImpl. When positionArg is Int32, it should be clamped. Otherwise, the function findCommon will return notFound and the final result will be false.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1892971</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2022-08-22 08:48:07 -0700</bug_when>
    <thetext>On macOS, this prints 4x &quot;true&quot; and 196x &quot;false&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1892979</commentid>
    <comment_count>2</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2022-08-22 09:03:59 -0700</bug_when>
    <thetext>The suggested change sounds OK. There are other ways to fix it as well. Makes sense that JavaScript calls for this behavior, since it&apos;s consistent with indexOf.

I am surprised this is not covered by Test262. Maybe this function is too new?

It looks like the startsWith and endsWith implementations may have a similar bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1894482</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-08-29 04:28:16 -0700</bug_when>
    <thetext>&lt;rdar://problem/99271518&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1897326</commentid>
    <comment_count>4</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2022-09-09 11:40:11 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/4180</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1897363</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2022-09-09 12:46:59 -0700</bug_when>
    <thetext>Committed 254319@main (ebf196ed5724): &lt;https://commits.webkit.org/254319@main&gt;

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

    </bug>

</bugzilla>