⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 271217 in webkit


Ignore:
Timestamp:
Jan 6, 2021, 3:39:18 PM (6 years ago)
Author:
ysuzuki@apple.com
Message:

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

Reviewed by Darin Adler.

Source/JavaScriptCore:

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):

Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r271186 r271217  
     12021-01-06  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Replace JSBigInt::toUint64 with JSBigInt::toBigUInt64
     4        https://bugs.webkit.org/show_bug.cgi?id=220378
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch replaces JSBigInt::toUint64 with JSBigInt::toBigUInt64.
     9        Rough purposes of these functions are the same, and  JSBigInt::toBigUInt64
     10        has the semantics defined in the ECMA262 spec. While the behavior is
     11        slightly different[1], this difference does not matter for the clients of
     12        JSBigInt::toUint64.
     13
     14        [1]: JSBigInt::toUint64 fails conversion if JSBigInt is out of range of uint64_t,
     15             while JSBigInt::toBigUInt64 always generates uint64_t by computing mod UINT64_MAX.
     16
     17        * runtime/JSBigInt.cpp:
     18        (JSC::JSBigInt::toUint64Heap): Deleted.
     19        * runtime/JSBigInt.h:
     20
    1212021-01-05  Yusuke Suzuki  <ysuzuki@apple.com>
    222
  • trunk/Source/JavaScriptCore/runtime/JSBigInt.cpp

    r271168 r271217  
    30633063}
    30643064
    3065 Optional<uint64_t> JSBigInt::toUint64Heap(JSBigInt* bigInt)
    3066 {
    3067     auto length = bigInt->length();
    3068     if (!length)
    3069         return 0;
    3070     if (bigInt->sign())
    3071         return WTF::nullopt;
    3072 
    3073     static_assert(sizeof(uint64_t) == sizeof(Digit) || sizeof(uint64_t) == sizeof(Digit) * 2, "Digit must be either 32-bit or 64-bit");
    3074     if (sizeof(uint64_t) == sizeof(Digit)) {
    3075         if (length > 1)
    3076             return WTF::nullopt;
    3077         return bigInt->digit(0);
    3078     }
    3079 
    3080     if (length > 2)
    3081         return WTF::nullopt;
    3082     uint64_t result = bigInt->digit(0);
    3083     if (length == 1)
    3084         result += static_cast<uint64_t>(bigInt->digit(0)) << 32;
    3085     return result;
    3086 }
    3087 
    30883065static ALWAYS_INLINE unsigned computeHash(JSBigInt::Digit* digits, unsigned length, bool sign)
    30893066{
  • trunk/Source/JavaScriptCore/runtime/JSBigInt.h

    r271168 r271217  
    441441    }
    442442
    443     static Optional<uint64_t> toUint64(JSValue bigInt)
    444     {
    445         ASSERT(bigInt.isBigInt());
    446 #if USE(BIGINT32)
    447         if (bigInt.isBigInt32()) {
    448             auto value = bigInt.bigInt32AsInt32();
    449             if (value < 0)
    450                 return WTF::nullopt;
    451             return value;
    452         }
    453 #endif
    454         return toUint64Heap(jsCast<JSBigInt*>(bigInt));
    455     }
    456 
    457443    Digit digit(unsigned);
    458444    void setDigit(unsigned, Digit); // Use only when initializing.
  • trunk/Source/WebKit/ChangeLog

    r271214 r271217  
     12021-01-06  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Replace JSBigInt::toUint64 with JSBigInt::toBigUInt64
     4        https://bugs.webkit.org/show_bug.cgi?id=220378
     5
     6        Reviewed by Darin Adler.
     7
     8        * WebProcess/WebPage/IPCTestingAPI.cpp:
     9        (WebKit::IPCTestingAPI::convertToUint64):
     10        (WebKit::IPCTestingAPI::encodeNumericType):
     11
    1122021-01-06  Andy Estes  <aestes@apple.com>
    213
  • trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp

    r269348 r271217  
    194194    }
    195195    if (jsValue.isBigInt())
    196         return JSC::JSBigInt::toUint64(jsValue);
     196        return JSC::JSBigInt::toBigUInt64(jsValue);
    197197    return WTF::nullopt;
    198198}
     
    353353    if (jsValue.isBigInt()) {
    354354        // FIXME: Support negative BigInt.
    355         auto result = JSC::JSBigInt::toUint64(jsValue);
    356         if (!result)
    357             return false;
    358         encoder << static_cast<IntegralType>(*result);
     355        uint64_t result = JSC::JSBigInt::toBigUInt64(jsValue);
     356        encoder << static_cast<IntegralType>(result);
    359357        return true;
    360358    }
Note: See TracChangeset for help on using the changeset viewer.