<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [ES6] Add TypedArray.prototype functionality."
   href="https://bugs.webkit.org/show_bug.cgi?id=148035#c19">Comment # 19</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [ES6] Add TypedArray.prototype functionality."
   href="https://bugs.webkit.org/show_bug.cgi?id=148035">bug 148035</a>
              from <span class="vcard"><a class="email" href="mailto:keith_miller&#64;apple.com" title="Keith Miller &lt;keith_miller&#64;apple.com&gt;"> <span class="fn">Keith Miller</span></a>
</span></b>
        <pre>Comment on <span class=""><a href="attachment.cgi?id=259195&amp;action=diff" name="attach_259195" title="Patch">attachment 259195</a> <a href="attachment.cgi?id=259195&amp;action=edit" title="Patch">[details]</a></span>
Patch

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

<span class="quote">&gt;&gt; Source/JavaScriptCore/builtins/TypedArray.prototype.js:26
&gt;&gt; +// Note that the intrisic &#64;typedArrayLength checks the that the argument passed is a typed array.
&gt; 
&gt; Does it throw if not? You should say so.</span >

Fixed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/builtins/TypedArray.prototype.js:168
&gt;&gt; +        mergeSort(this, length, comparator);
&gt; 
&gt; Stray newline.
&gt; 
&gt; No braces for single-line block.</span >

Fixed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/builtins/TypedArray.prototype.js:191
&gt;&gt; +    else {
&gt; 
&gt; No braces for single-line block.</span >

Fixed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/builtins/TypedArray.prototype.js:217
&gt;&gt; +    else {
&gt; 
&gt; No braces for single-line block.</span >

Fixed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/builtins/TypedArray.prototype.js:238
&gt;&gt; +    // FIXME: This should be a species constructor
&gt; 
&gt; constructor =&gt; constructor.</span >

Fixed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/builtins/TypedArray.prototype.js:266
&gt;&gt; +    // FIXME: This should be a species constructor
&gt; 
&gt; constructor =&gt; constructor.</span >

Fixed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/builtins/TypedArray.prototype.js:269
&gt;&gt; +    for (var i = 0; i &lt; kept.length; i++) {
&gt; 
&gt; No braces for single-line block.</span >

Fixed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h:87
&gt;&gt; +void sortFloat(FloatType* floatArray, unsigned length)
&gt; 
&gt; I suggest you to write why this function works.
&gt; Or I suggest you to write this as a simple std::sort at first (and later, optimize it with the benchmark :D)
&gt; 
&gt; (the following one is my rough understanding),
&gt; 
&gt; IEEE 754 ensures that the mantissa and exponential part of the format (63bit) is ordered except for NaN.
&gt; Because IEEE 754 does not use complement representation for the negative values, the negative float numbers recognized as the integral numbers are reverse ordered.
&gt; We summarize the result of the comparison between the floating numbers recognized as the integral ones.
&gt; 
&gt; - &lt;=&gt; - = reversed (-30 &gt; -20 = true)
&gt; + &lt;=&gt; + = ordered (30 &gt; 20 = true)
&gt; - &lt;=&gt; + = ordered (-30 &gt; 20 = false)
&gt; + &lt;=&gt; - = ordered (30 &gt; -20 = true)
&gt; 
&gt; As a result, when sorting the array,
&gt; 1. unsigned numbers are correctly ordered.
&gt; 2. The order of unsigned and signed numbers are correctly kept.
&gt; 3. But the order between signed numbers are reversed.
&gt; 
&gt; 
&gt; 
&gt; For NaN, we normalize the NaN to the specific representation; sign bit is 0, all exponential part is 1 and the MSB of the mantissa is 1.
&gt; So NaN is recognized as the largest integral numbers.
&gt; 
&gt; I suggest you to test with the following edge numbers,
&gt; 
&gt; 1. positive infinity, negative infinity
&gt; 2. -0.0, +0.0
&gt; 3. NaN
&gt; 4. denormalized numbers</span >

Added Comment

<span class="quote">&gt;&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h:89
&gt;&gt; +
&gt; 
&gt; Stray newline.</span >

Fixed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h:225
&gt;&gt; +
&gt; 
&gt; Stray newline.</span >

Fixed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h:240
&gt;&gt; +        default: {
&gt; 
&gt; No braces for single line statement.</span >

Fixed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h:242
&gt;&gt; +            }
&gt; 
&gt; It's good to break, even at the end.</span >

Fixed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:108
&gt;&gt; +    long final = argumentClampedIndexFromStartOrEnd(exec, 2, length, length);
&gt; 
&gt; Why are they `long`?</span >

I made them long so no overflow would occur in computations for count.

<span class="quote">&gt;&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:185
&gt;&gt; +        separator = { &amp;comma, 1 };
&gt; 
&gt; Is this &amp;comma addressing safe? This comma address is the address of the stack.
&gt; When this brace is ended, the lifetime of the variable `comma` is finished.
&gt; I think we need to change it to the following.
&gt; 
&gt; const LChar* comma = &quot;,&quot;;
&gt; separator = { comma, 1 };
&gt; 
&gt; String Literal is allocated in the static area and its lifetime is the same to the program.</span >

I believe you are correct. I just copied this code from ArrayPrototype.cpp and didn't give it too much thought. We should probably fix this there as well.

<span class="quote">&gt;&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:190
&gt;&gt; +        separator = separatorString-&gt;view(exec);
&gt; 
&gt; If we would like to keep separator valid, we need to maintain separatorString alive.
&gt; I suggest you to move `JSString* separatorString` to the function top-level block to make it explicit that separatorString is alive during this function.</span >

I don't think there is an issue here. I believe JSString* lives in the js heap so it needs to be marked before it can be GCed.

<span class="quote">&gt;&gt; Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:207
&gt;&gt; +EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncToLocaleString(ExecState* exec)
&gt; 
&gt; No JavaScript action on this one? It would help with the function call.</span >

Yeah, you are probably right. I moved this to a builtin.

<span class="quote">&gt;&gt; Source/JavaScriptCore/runtime/JSTypedArrayViewPrototypeInlines.h:69
&gt;&gt; +        return throwVMError(exec, createTypeError(exec, &quot;Receiver should be a typed array view&quot;));
&gt; 
&gt; Could you add &quot;Receiver should be a typed array view but was not an object&quot; test cases for each function?</span >

Fixed.</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>