<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <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#c19">Comment # 19</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=282752&amp;action=diff" name="attach_282752" title="Patch">attachment 282752</a> <a href="attachment.cgi?id=282752&amp;action=edit" title="Patch">[details]</a></span>
Patch

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

Second round of review:

<span class="quote">&gt; Source/JavaScriptCore/ChangeLog:6
&gt; +        Reviewed by Benjamin Poulain.</span >

You don't need to modify this field.

The tool that lands the page (webkit-patch) replaces &quot;NOBODY (OOPS!)&quot; by the name of the reviewer found on bugzilla.

<span class="quote">&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:211
&gt; +    TypedArrayType arrayType = exec-&gt;thisValue().getObject()-&gt;classInfo()-&gt;typedArrayStorageType;</span >

This is less efficient than it should.

You are getting the array type at runtime.
This condition can be fully determined at compile time from the template argument ViewClass.

<span class="quote">&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:216
&gt; +    if (!valueToFind.isNumber() &amp;&amp; !valueToFind.isDouble())</span >

Isn't &quot;isNumber()&quot; a superset of &quot;isDouble()&quot;?

valueToFind.isNumber() false implies valueToFind.isDouble() false.

<span class="quote">&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:222
&gt; +    typename ViewClass::ElementType target = ViewClass::toAdaptorNativeFromValue(exec, valueToFind);</span >

I don't think that works for includes.

For example, Uint8ClampedAdaptor will clamp positive values to 255, that's not what we need here.
IntegralTypedArrayAdaptor does ToInt32 on the input, that's not what we need either.

Your test should have extensive coverage of those crazy cases.

----

What you probably need is a new Adaptor function that returns a value in the right type or an error.

For example, if you pass a double to an integer type array, it returns the integer if it fits in the array type or fail.
E.g.:
    -The double 256.0 works for int16, fails for int8
    -The double 254.1 fails for all integers.

<span class="quote">&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:226
&gt; +    if (std::isnan(target)) {</span >

This can be eliminated at compile time with the test described above for ViewClass.

<span class="quote">&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:236
&gt; +            if (JSValue::strictEqual(exec, currentValue, valueToFind))</span >

I think it is not a good idea to use strictEqual() for performance.
The type of the Array is known, and the type of the valueToFind can be converted to that type.

<span class="quote">&gt; LayoutTests/ChangeLog:13
&gt; +        * js/regress/script-tests/typed-array-includes.js: Added.</span >

Any reason this is in js/regress and not in js/

<span class="quote">&gt; LayoutTests/js/regress/script-tests/typed-array-includes.js:1
&gt; +function assert(a) {</span >

You can use shouldBeTrue(), available in js-test-pre.js.

<span class="quote">&gt; LayoutTests/js/regress/script-tests/typed-array-includes.js:22
&gt; +    assert(!tArray.includes(&quot;abc&quot;));</span >

It is worth testing all the types: undefined, null, empty string, regular object.

<span class="quote">&gt; LayoutTests/js/regress/script-tests/typed-array-includes.js:96
&gt; +</span >

Some things worth checking too:
Object.getPrototypeOf(TypedArray).prototype.name === &quot;includes&quot;
Object.getPrototypeOf(TypedArray).prototype.length === 1</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>