<?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>263954</bug_id>
          
          <creation_ts>2023-10-31 01:05:09 -0700</creation_ts>
          <short_desc>JSC should throw an exception when BigUint64Array copy value from Int32Array</short_desc>
          <delta_ts>2023-11-02 12:47:39 -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 Nightly Build</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <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="Yijia Huang">yijia_huang</assigned_to>
          <cc>mark.lam</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1988784</commentid>
    <comment_count>0</comment_count>
    <who name="EntryHi">entryhii</who>
    <bug_when>2023-10-31 01:05:09 -0700</bug_when>
    <thetext>====================test.js=========
for (let v0 = 1; v0 &lt; 100; v0++) {
  const v2 = [1000];
  const v4 = new BigUint64Array(v0);
  try {
    v4.set(v2);
    print(v4[0])
  } catch (e6) {print(e6)}
  Object.defineProperty(v2, 10, {writable: true,value: 10});
}

====================================

Run args: ./jsc -f test.js --useConcurrentJIT=0  --jitPolicyScale=0

JSC should throw an exception &quot;TypeError: Invalid argument type in ToBigInt operation&quot;, but it didn&apos;t actually. This bug exists even when jitPolicyScale=1.

This bug may be related to runtime/JSGenericTypedArrayViewInlines.h setFromArrayLike

```
    if constexpr (TypedArrayStorageType != TypeBigInt64 || TypedArrayStorageType != TypeBigUint64) {
        if (JSArray* array = jsDynamicCast&lt;JSArray*&gt;(object); LIKELY(array &amp;&amp; isJSArray(array))) {
            if (safeLength == length &amp;&amp; (safeLength + objectOffset) &lt;= array-&gt;length() &amp;&amp; array-&gt;isIteratorProtocolFastAndNonObservable()) {
                IndexingType indexingType = array-&gt;indexingType() &amp; IndexingShapeMask;
                if (indexingType == Int32Shape) {
                    copyFromInt32ShapeArray(offset, array, objectOffset, safeLength);
                    return true;
                }
                if (indexingType == DoubleShape) {
                    copyFromDoubleShapeArray(offset, array, objectOffset, safeLength);
                    return true;
                }
            }
        }
    }
```

In copyFromInt32ShapeArray does not assert even when typeValue == TypeBigInt64 becuase &apos;||&apos; in `ASSERT(Adaptor::typeValue != TypeBigInt64 || Adaptor::typeValue != TypeBigUint64)` , should this be a &apos;&amp;&amp;&apos;?


```
template&lt;typename Adaptor&gt;
void JSGenericTypedArrayView&lt;Adaptor&gt;::copyFromInt32ShapeArray(size_t offset, JSArray* array, size_t objectOffset, size_t length)
{
    ASSERT(canAccessRangeQuickly(offset, length));
    ASSERT((array-&gt;indexingType() &amp; IndexingShapeMask) == Int32Shape);
    ASSERT(Adaptor::typeValue != TypeBigInt64 || Adaptor::typeValue != TypeBigUint64);
    ASSERT((length + objectOffset) &lt;= array-&gt;length());
    ASSERT(array-&gt;isIteratorProtocolFastAndNonObservable());

    // If the destination is uint32_t or int32_t, we can use copyElements.
    // 1. int32_t -&gt; uint32_t conversion does not change any bit representation. So we can simply copy them.
    // 2. Hole is represented as JSEmpty in Int32Shape, which lower 32bits is zero. And we expect 0 for undefined, thus this copying simply works.
    if constexpr (Adaptor::typeValue == TypeUint8 || Adaptor::typeValue == TypeInt8) {
        WTF::copyElements(bitwise_cast&lt;uint8_t*&gt;(typedVector() + offset), bitwise_cast&lt;const uint64_t*&gt;(array-&gt;butterfly()-&gt;contiguous().data() + objectOffset), length);
        return;
    }
    if constexpr (Adaptor::typeValue == TypeUint16 || Adaptor::typeValue == TypeInt16) {
        WTF::copyElements(bitwise_cast&lt;uint16_t*&gt;(typedVector() + offset), bitwise_cast&lt;const uint64_t*&gt;(array-&gt;butterfly()-&gt;contiguous().data() + objectOffset), length);
        return;
    }
    if constexpr (Adaptor::typeValue == TypeUint32 || Adaptor::typeValue == TypeInt32) {
        WTF::copyElements(bitwise_cast&lt;uint32_t*&gt;(typedVector() + offset), bitwise_cast&lt;const uint64_t*&gt;(array-&gt;butterfly()-&gt;contiguous().data() + objectOffset), length);
        return;
    }
    for (size_t i = 0; i &lt; length; ++i) {
        JSValue value = array-&gt;butterfly()-&gt;contiguous().at(array, static_cast&lt;unsigned&gt;(i + objectOffset)).get();
        if (LIKELY(!!value))
            setIndexQuicklyToNativeValue(offset + i, Adaptor::toNativeFromInt32(value.asInt32()));
        else
            setIndexQuicklyToNativeValue(offset + i, Adaptor::toNativeFromUndefined());
    }
}
```

In copyFromInt32ShapeArray, when Adaptor::typeValue == TypeBigUint64, Int32 can not be convert to BigUint64 directly, it should throw an exception which is similar to `toNativeFromValue`.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1989266</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-11-01 14:44:40 -0700</bug_when>
    <thetext>&lt;rdar://problem/117816146&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1989309</commentid>
    <comment_count>2</comment_count>
    <who name="Yijia Huang">yijia_huang</who>
    <bug_when>2023-11-01 17:03:21 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/19868</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1989490</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-11-02 12:47:35 -0700</bug_when>
    <thetext>Committed 270133@main (0e5745978de8): &lt;https://commits.webkit.org/270133@main&gt;

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

    </bug>

</bugzilla>