Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: e1fdc80a34f021efa512e23d136c5727b18687e8
      
https://github.com/WebKit/WebKit/commit/e1fdc80a34f021efa512e23d136c5727b18687e8
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-08-21 (Fri, 21 Aug 2026)

  Changed paths:
    A JSTests/stress/date-get-day-full-range.js
    A JSTests/stress/temporal-plaindate-dayofweek-full-range.js
    M Source/JavaScriptCore/runtime/ISO8601.cpp
    M Source/WTF/wtf/DateMath.h

  Log Message:
  -----------
  [JSC] `WTF::weekDay` overflows for days near `INT32_MAX` and is duplicated in 
Temporal
https://bugs.webkit.org/show_bug.cgi?id=322247

Reviewed by Yusuke Suzuki.

WTF::weekDay computed (days + 4) % 7, which is signed overflow for
days > INT32_MAX - 4. No caller reaches that today because days is
clipped to +-1e8, but the function is declared for any int32_t.
ISO8601::dayOfWeek carried its own copy of the same modulo, converting
the day count through double and Int128 on the way.

Compute the weekday with the multiply-and-shift from Ben Joffe's
article [1]: since 7 = 2^3 - 1, x mod 7 equals floor(x * 8 / 7) mod 8,
so a 64-bit multiply by ceil(2^40 / 7) << 24, an add of the Thursday
offset and a shift by 61 yield the weekday. Every step is unsigned
arithmetic, so the result is defined for the whole int32_t range; all
2^32 inputs were checked against the old formula evaluated in int64_t.
On arm64 this is sxtw / madd / lsr instead of a magic-number division
with cmp/csel.

Make ISO8601::dayOfWeek build the day count with daysFromYearMonth, as
TemporalZonedDateTimePrototype already does, and call WTF::weekDay.
Remove msToWeekDay, which has no callers.

[1]: https://www.benjoffe.com/fast-day-of-week

Tests: JSTests/stress/date-get-day-full-range.js
       JSTests/stress/temporal-plaindate-dayofweek-full-range.js

* JSTests/stress/date-get-day-full-range.js: Added.
(shouldBe):
* JSTests/stress/temporal-plaindate-dayofweek-full-range.js: Added.
(shouldBe):
(expected.of.cases.dayOfWeekFromLegacy):
* Source/JavaScriptCore/runtime/ISO8601.cpp:
(JSC::ISO8601::dayOfWeek):
* Source/WTF/wtf/DateMath.h:
(WTF::weekDay):
(WTF::msToWeekDay): Deleted.

Canonical link: https://commits.webkit.org/319583@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to