Polyfill: Replace unreachable retry with assertion in NudgeToCalendarUnit#3291
Polyfill: Replace unreachable retry with assertion in NudgeToCalendarUnit#3291jessealama wants to merge 2 commits intotc39:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3291 +/- ##
==========================================
+ Coverage 97.83% 98.00% +0.16%
==========================================
Files 22 22
Lines 10725 10711 -14
Branches 1856 1855 -1
==========================================
+ Hits 10493 10497 +4
+ Misses 215 197 -18
Partials 17 17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This change was originally in #3289 (where it was simply deleted, without even an assertion in place). |
|
I think if we assume this code can't be reached by any JS code, we should change the spec text accordingly to have an assertion there as well, and submit it as an editorial change. (Could possibly also be done after stage 4.) I have a hunch that the reason the nudge window only needs to be retried when moving forwards, is because the reason for the retry is when the edge of the window lands in a DST gap. The |
…Unit The retry path for negative durations appears unreachable: end-of-month constraining reduces the day, which for negative durations pushes the endpoint further from the origin, so the nudge window always contains the destination. Closes tc39#3235
ff81f17 to
8588270
Compare
…rUnit For negative durations, end-of-month constraining can only reduce the day number, which moves the endpoint further from the origin, so the nudge window always contains destEpochNs without an additional shift. Replace the unreachable conditional retry block with an assertion and a NOTE explaining the invariant. See tc39#3235, tc39#3291.
I've tweaked the spec text to add an assertion, matching the polyfill code. I've added a note there. I'm happy to open an issue (which this PR would close) where we can try to think out loud about why this behavior is impossible. How does that sound? |
The retry path for negative durations appears unreachable: end-of-month constraining reduces the day, which for negative durations pushes the endpoint further from the origin, so the nudge window always contains the destination.
This isn't a rigorous proof of unreachability, but we haven't been able to construct a test case that exercises this path. Replace the retry block with an assertion guarding the invariant, so that if we're wrong, we'll get a clear error rather than silent misbehavior.
Closes #3235