<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:benjamin&#64;webkit.org" title="Benjamin Poulain &lt;benjamin&#64;webkit.org&gt;"> <span class="fn">Benjamin Poulain</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - ECMAScript 2016: %TypedArray%.prototype.includes implementation"
   href="https://bugs.webkit.org/show_bug.cgi?id=159385">bug 159385</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Attachment #283116 Flags</td>
           <td>review?
           </td>
           <td>review-
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - ECMAScript 2016: %TypedArray%.prototype.includes implementation"
   href="https://bugs.webkit.org/show_bug.cgi?id=159385#c38">Comment # 38</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - ECMAScript 2016: %TypedArray%.prototype.includes implementation"
   href="https://bugs.webkit.org/show_bug.cgi?id=159385">bug 159385</a>
              from <span class="vcard"><a class="email" href="mailto:benjamin&#64;webkit.org" title="Benjamin Poulain &lt;benjamin&#64;webkit.org&gt;"> <span class="fn">Benjamin Poulain</span></a>
</span></b>
        <pre>Comment on <span class=""><a href="attachment.cgi?id=283116&amp;action=diff" name="attach_283116" title="Patch">attachment 283116</a> <a href="attachment.cgi?id=283116&amp;action=edit" title="Patch">[details]</a></span>
Patch

View in context: <a href="https://bugs.webkit.org/attachment.cgi?id=283116&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=283116&amp;action=review</a>

Third review round.
This is getting in really good shape. But I think I found a couple of bugs:

<span class="quote">&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:209
&gt; +    if (!valueToFind.isNumber())
&gt; +        return JSValue::encode(jsBoolean(false));</span >

I believe having this here is a bug. It is not spec compliant.

If you check <a href="https://tc39.github.io/ecma262/2016/#sec-array.prototype.includes">https://tc39.github.io/ecma262/2016/#sec-array.prototype.includes</a>, step 4. is calling ToInteger() on the index.
Here, if the argument zero is not a number, we exit *before* calling ToInteger.

Why is that important?
The second argument can be an object with &quot;valueOf&quot;. This optimization will skip the call to valueOf.

You should add a test verifying that passing a string as first argument and an object as second argument calls valueOf() exactly once on the object.

<span class="quote">&gt; Source/JavaScriptCore/runtime/ToNativeFromValue.h:58
&gt; +    return Adaptor::toNativeFromDouble(value.toNumber(exec), result);</span >

I think this is a bug too.

You are calling toNumber() on the value.
If valueToFind is an Object, that will call valueOf() on it. If it's null or undefined, it will be converted to number too.

You just need to return false here.

You need a test covering this case.

<span class="quote">&gt; Source/JavaScriptCore/runtime/TypedArrayAdaptors.h:104
&gt; +        Type ans = static_cast&lt;Type&gt;(value);</span >

Rename ans-&gt;integer?

<span class="quote">&gt; Source/JavaScriptCore/runtime/TypedArrayAdaptors.h:163
&gt; +    static Type toNativeFromUint32(uint32_t value, Type&amp; result)</span >

Is this needed? Where is it called?

<span class="quote">&gt; Source/JavaScriptCore/runtime/TypedArrayAdaptors.h:177
&gt; +        if (value &lt; minValue || value &gt; maxValue)
&gt; +            return false;</span >

This is not really enough because of double-&gt;float conversion.

A double can be bigger than minValue and less than maxValue yet not convert cleanly to a float. This happens if the double has a higher precision than the float.

What we need is (static_cast&lt;double&gt;(static_cast&lt;Type&gt;(value)) == value).
This ensure that the conversion to float and back to double does not lose precision.
This is valid because you have a NaN check above so we don't have to deal with non-finite numbers.

It's probably possible to write a test covering this.

<span class="quote">&gt; Source/JavaScriptCore/runtime/TypedArrayAdaptors.h:278
&gt; +    static bool toNativeFromUint32(uint32_t value, Type&amp; result)</span >

Is this needed?

<span class="quote">&gt; Source/JavaScriptCore/runtime/TypedArrayAdaptors.h:290
&gt; +        int32_t ans = static_cast&lt;int32_t&gt;(value);</span >

Rename ans-&gt;integer.
I believe you could even type it uint8_t and skip the &quot;if (ans &gt; maxValue || ans &lt; minValue)&quot; below.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>