Title: [271217] trunk/Source
Revision
271217
Author
[email protected]
Date
2021-01-06 15:39:18 -0800 (Wed, 06 Jan 2021)

Log Message

[JSC] Replace JSBigInt::toUint64 with JSBigInt::toBigUInt64
https://bugs.webkit.org/show_bug.cgi?id=220378

Reviewed by Darin Adler.

Source/_javascript_Core:

This patch replaces JSBigInt::toUint64 with JSBigInt::toBigUInt64.
Rough purposes of these functions are the same, and  JSBigInt::toBigUInt64
has the semantics defined in the ECMA262 spec. While the behavior is
slightly different[1], this difference does not matter for the clients of
JSBigInt::toUint64.

[1]: JSBigInt::toUint64 fails conversion if JSBigInt is out of range of uint64_t,
     while JSBigInt::toBigUInt64 always generates uint64_t by computing mod UINT64_MAX.

* runtime/JSBigInt.cpp:
(JSC::JSBigInt::toUint64Heap): Deleted.
* runtime/JSBigInt.h:

Source/WebKit:

* WebProcess/WebPage/IPCTestingAPI.cpp:
(WebKit::IPCTestingAPI::convertToUint64):
(WebKit::IPCTestingAPI::encodeNumericType):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (271216 => 271217)


--- trunk/Source/_javascript_Core/ChangeLog	2021-01-06 23:28:43 UTC (rev 271216)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-01-06 23:39:18 UTC (rev 271217)
@@ -1,3 +1,23 @@
+2021-01-06  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Replace JSBigInt::toUint64 with JSBigInt::toBigUInt64
+        https://bugs.webkit.org/show_bug.cgi?id=220378
+
+        Reviewed by Darin Adler.
+
+        This patch replaces JSBigInt::toUint64 with JSBigInt::toBigUInt64.
+        Rough purposes of these functions are the same, and  JSBigInt::toBigUInt64
+        has the semantics defined in the ECMA262 spec. While the behavior is
+        slightly different[1], this difference does not matter for the clients of
+        JSBigInt::toUint64.
+
+        [1]: JSBigInt::toUint64 fails conversion if JSBigInt is out of range of uint64_t,
+             while JSBigInt::toBigUInt64 always generates uint64_t by computing mod UINT64_MAX.
+
+        * runtime/JSBigInt.cpp:
+        (JSC::JSBigInt::toUint64Heap): Deleted.
+        * runtime/JSBigInt.h:
+
 2021-01-05  Yusuke Suzuki  <[email protected]>
 
         [JSC] DFG/FTL DirectCall need to respect Wasm IC

Modified: trunk/Source/_javascript_Core/runtime/JSBigInt.cpp (271216 => 271217)


--- trunk/Source/_javascript_Core/runtime/JSBigInt.cpp	2021-01-06 23:28:43 UTC (rev 271216)
+++ trunk/Source/_javascript_Core/runtime/JSBigInt.cpp	2021-01-06 23:39:18 UTC (rev 271217)
@@ -3062,29 +3062,6 @@
     return ~(value - 1); // To avoid undefined behavior, we compute two's compliment by hand in C while this is simply `-value`.
 }
 
-Optional<uint64_t> JSBigInt::toUint64Heap(JSBigInt* bigInt)
-{
-    auto length = bigInt->length();
-    if (!length)
-        return 0;
-    if (bigInt->sign())
-        return WTF::nullopt;
-
-    static_assert(sizeof(uint64_t) == sizeof(Digit) || sizeof(uint64_t) == sizeof(Digit) * 2, "Digit must be either 32-bit or 64-bit");
-    if (sizeof(uint64_t) == sizeof(Digit)) {
-        if (length > 1)
-            return WTF::nullopt;
-        return bigInt->digit(0);
-    }
-
-    if (length > 2)
-        return WTF::nullopt;
-    uint64_t result = bigInt->digit(0);
-    if (length == 1)
-        result += static_cast<uint64_t>(bigInt->digit(0)) << 32;
-    return result;
-}
-
 static ALWAYS_INLINE unsigned computeHash(JSBigInt::Digit* digits, unsigned length, bool sign)
 {
     Hasher hasher;

Modified: trunk/Source/_javascript_Core/runtime/JSBigInt.h (271216 => 271217)


--- trunk/Source/_javascript_Core/runtime/JSBigInt.h	2021-01-06 23:28:43 UTC (rev 271216)
+++ trunk/Source/_javascript_Core/runtime/JSBigInt.h	2021-01-06 23:39:18 UTC (rev 271217)
@@ -440,20 +440,6 @@
         return static_cast<int64_t>(toBigUInt64Heap(bigInt.asHeapBigInt()));
     }
 
-    static Optional<uint64_t> toUint64(JSValue bigInt)
-    {
-        ASSERT(bigInt.isBigInt());
-#if USE(BIGINT32)
-        if (bigInt.isBigInt32()) {
-            auto value = bigInt.bigInt32AsInt32();
-            if (value < 0)
-                return WTF::nullopt;
-            return value;
-        }
-#endif
-        return toUint64Heap(jsCast<JSBigInt*>(bigInt));
-    }
-
     Digit digit(unsigned);
     void setDigit(unsigned, Digit); // Use only when initializing.
     JS_EXPORT_PRIVATE JSBigInt* rightTrim(JSGlobalObject*);

Modified: trunk/Source/WebKit/ChangeLog (271216 => 271217)


--- trunk/Source/WebKit/ChangeLog	2021-01-06 23:28:43 UTC (rev 271216)
+++ trunk/Source/WebKit/ChangeLog	2021-01-06 23:39:18 UTC (rev 271217)
@@ -1,3 +1,14 @@
+2021-01-06  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Replace JSBigInt::toUint64 with JSBigInt::toBigUInt64
+        https://bugs.webkit.org/show_bug.cgi?id=220378
+
+        Reviewed by Darin Adler.
+
+        * WebProcess/WebPage/IPCTestingAPI.cpp:
+        (WebKit::IPCTestingAPI::convertToUint64):
+        (WebKit::IPCTestingAPI::encodeNumericType):
+
 2021-01-06  Andy Estes  <[email protected]>
 
         [Mac] Replace most uses of HAVE(MT_PLUGIN_FORMAT_READER) with ENABLE(WEBM_FORMAT_READER)

Modified: trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp (271216 => 271217)


--- trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp	2021-01-06 23:28:43 UTC (rev 271216)
+++ trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp	2021-01-06 23:39:18 UTC (rev 271217)
@@ -193,7 +193,7 @@
         return value;
     }
     if (jsValue.isBigInt())
-        return JSC::JSBigInt::toUint64(jsValue);
+        return JSC::JSBigInt::toBigUInt64(jsValue);
     return WTF::nullopt;
 }
 
@@ -352,10 +352,8 @@
 {
     if (jsValue.isBigInt()) {
         // FIXME: Support negative BigInt.
-        auto result = JSC::JSBigInt::toUint64(jsValue);
-        if (!result)
-            return false;
-        encoder << static_cast<IntegralType>(*result);
+        uint64_t result = JSC::JSBigInt::toBigUInt64(jsValue);
+        encoder << static_cast<IntegralType>(result);
         return true;
     }
     if (!jsValue.isNumber())
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to