<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#c6">Comment # 6</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:ticaiolima&#64;gmail.com" title="Caio Lima &lt;ticaiolima&#64;gmail.com&gt;"> <span class="fn">Caio Lima</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=159385#c4">comment #4</a>)
<span class="quote">&gt; Comment on <span class="bz_obsolete"><a href="attachment.cgi?id=282639&amp;action=diff" name="attach_282639" title="RFC Patch">attachment 282639</a> <a href="attachment.cgi?id=282639&amp;action=edit" title="RFC Patch">[details]</a></span>
&gt; RFC Patch
&gt; 
&gt; View in context:
&gt; <a href="https://bugs.webkit.org/attachment.cgi?id=282639&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=282639&amp;action=review</a>
&gt; 
&gt; An implementation of TypedArray's includes, that's awesome!
&gt; 
&gt; Some comments bellow:
&gt; 
&gt; &gt; Source/JavaScriptCore/ChangeLog:10
&gt; &gt; +                                %TypedArray%.prototype.includes following spec 22.2.3.14
&gt; &gt; +                                <a href="https://tc39.github.io/ecma262/2016/#sec-%typedarray%.prototype.includes">https://tc39.github.io/ecma262/2016/#sec-%typedarray%.prototype.includes</a>
&gt; 
&gt; Be careful to use spaces for indentation.
&gt; We avoid mixing tabs and spaces, the rule is to always use spaces.</span >

Sorry, my vim is not configured correctly. Thanks for point it =).

<span class="quote">&gt; &gt; Source/JavaScriptCore/ChangeLog:19
&gt; &gt; +
&gt; 
&gt; Don't forget to add test coverage too!
&gt; 
&gt; You should have tests in LayoutTests/js that try various use cases and
&gt; verify the correctness.
&gt; There should also be a test getting the property descriptor and checking its
&gt; properties (name, enumerable, etc).</span >

I added coverage, but I didn't consider cases about property descriptor. I am going to update it soon.

<span class="quote">&gt; &gt; Source/JavaScriptCore/builtins/TypedArrayPrototype.js:355
&gt; &gt; +        fromIndex = arguments[1] | 0;
&gt; 
&gt; This looks suspicious to me.
&gt; 
&gt; The specs says:
&gt;     Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
&gt; produces the value 0.)
&gt; 
&gt; ToInteger() produces integer for values &gt; INT_MAX.
&gt; 
&gt; x | 0 is a ToInt32() on x. The bounds are [INT_MIN, INT_MAX]
&gt; 
&gt; Looking at Array.prototype, I suspect we have a bug there.</span >

I agree with you. I double checked the spec and confirm it. However, I am not sure if it is possible create an Array with length &gt; INT_MAX. I need to check it.

<span class="quote">&gt; &gt; Source/JavaScriptCore/builtins/TypedArrayPrototype.js:370
&gt; &gt; +        if (searchElement === currentElement || (searchElement !== searchElement &amp;&amp; currentElement !== currentElement))
&gt; 
&gt; The loop would benefit from being specialized on searchElement !==
&gt; searchElement.
&gt; 
&gt; if (searchElement === searchElement) {
&gt;     ... Loop searching for searchElement
&gt; } else {
&gt;     ... Loop searching for NaN
&gt; }</span >

Nice! However I decided pick the C++ version in the new Patch.

<span class="quote">&gt; &gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:222
&gt; &gt; +        if (array[index] == target)
&gt; 
&gt; Isn't that missing the NaN case?</span >

Now I am considering it. However I have a doubt with suspicious cases:

1. If the searchElement is an Object or a String? In IntXArray, they are converted to 0, so &quot;new UInt8Array([0, 1, 2]).includes(&quot;abc&quot;); // is true&quot;. It is not just the case of %TypedArray%.prototype.includes, but also %TypedArray%.prototype.indexOf. I didn't find any information about it in the Spec. I checked v8 implementation and they return false to these cases. IMHO, I think it is the best result, since &quot;new UInt8Array([0, 1, 2]).includes(&quot;abc&quot;);&quot; returning &quot;true&quot; is a potential unpredictable bug source.

<span class="quote">&gt; &gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:223
&gt; &gt; +            return JSValue::encode(JSValue(JSValue::JSTrue));
&gt; 
&gt; You can also use jsBoolean(true/false) to produce a boolean JSValue.</span >

Thank you for this Tip!</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>