Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duration.prototype.{round,total}: Missing checks for too large date-time values #3015

Closed
anba opened this issue Oct 21, 2024 · 3 comments
Closed
Assignees
Labels
editorial spec-text Specification text involved

Comments

@anba
Copy link
Contributor

anba commented Oct 21, 2024

Temporal.Duration.prototype.round, steps 27.f-h:

f. Let isoDateTime be CombineISODateAndTimeRecord(plainRelativeTo.[[ISODate]], MidnightTimeRecord()).
g. Let targetDateTime be CombineISODateAndTimeRecord(targetDate, targetTime).
h. Set internalDuration to ? DifferencePlainDateTimeWithRounding(isoDateTime, targetDateTime, calendar, largestUnit, roundingIncrement, smallestUnit, roundingMode).

Temporal.Duration.prototype.total, steps 12.f-h:

f. Let isoDateTime be CombineISODateAndTimeRecord(plainRelativeTo.[[ISODate]], MidnightTimeRecord()).
g. Let targetDateTime be CombineISODateAndTimeRecord(targetDate, targetTime).
h. Let total be ? DifferencePlainDateTimeWithTotal(isoDateTime, targetDateTime, calendar, unit).

isoDateTime and targetDateTime can be be outside the valid date-time limits, which breaks assertions in DifferencePlainDateTimeWithRounding and DifferencePlainDateTimeWithTotal when calling DifferenceISODateTime.

(This is already covered by test262 tests, but probably didn't get noticed because the polyfill doesn't implement the assertion steps.)

@ptomato ptomato self-assigned this Oct 26, 2024
@ptomato ptomato added spec-text Specification text involved editorial labels Oct 26, 2024
@ptomato
Copy link
Collaborator

ptomato commented Oct 26, 2024

@anba Are you sure it already has test coverage? I tried adding the assertion steps to the polyfill, and got no new test failures. Which ones fail on your end?

@anba
Copy link
Contributor Author

anba commented Oct 28, 2024

After updating more code to match the current spec text, the assertions no longer trigger. So you're correct, this is missing test262 coverage.

Edit: Forgot to reenable the test262 tests which were failing because of this missing check. 😅

This is covered by

  • built-ins/Temporal/Duration/prototype/total/relativeto-string-limits.js
  • built-ins/Temporal/Duration/prototype/round/relativeto-string-limits.js

When the input is "-271821-04-19", this step:

Let isoDateTime be CombineISODateAndTimeRecord(plainRelativeTo.[[ISODate]], MidnightTimeRecord()).

creates a date-time valid outside the valid ISO date-time valids, because the time part is midnight.

ptomato added a commit that referenced this issue Oct 31, 2024
See #3015, which posits that these assertions are hit in existing test262
tests.
ptomato added a commit that referenced this issue Nov 1, 2024
See #3015, which posits that these assertions are hit in existing test262
tests.
ptomato added a commit that referenced this issue Nov 11, 2024
See #3015, which posits that these assertions are hit in existing test262
tests.
ptomato added a commit that referenced this issue Nov 11, 2024
See #3015, which posits that these assertions are hit in existing test262
tests.
@ptomato
Copy link
Collaborator

ptomato commented Dec 5, 2024

So here's what I think is happening. The assertion is not tripped in those two test262 tests because the duration is zero, and DifferencePlainDateTimeWithRounding/DifferencePlainDateTimeWithTotal have an early return for the case of two identical PlainDateTimes. However, if you run the same operations with e.g. const instance = new Temporal.Duration(0, 0, 0, 0, 0, /* minutes = */ 5); the assertion is tripped. So I think there really is no test coverage for this, and maybe your code skipped the early return?

I will first adapt the three relativeto-string-limits.js tests so that they would cover this situation.

ptomato added a commit to ptomato/test262 that referenced this issue Dec 5, 2024
These tests did not fully cover Temporal.Duration.prototype.round and
Temporal.Duration.prototype.total because they called those methods on a
blank duration (all components zero), for which there is an early return
in round() and total().

This meant that we missed an assertion that would be hit after the early
return.

This makes sure to test both blank and non-blank Durations with these
relativeTo strings, and expect some strings to fail at different steps
with the two cases.

See: tc39/proposal-temporal#3015
Ms2ger pushed a commit to tc39/test262 that referenced this issue Dec 5, 2024
These tests did not fully cover Temporal.Duration.prototype.round and
Temporal.Duration.prototype.total because they called those methods on a
blank duration (all components zero), for which there is an early return
in round() and total().

This meant that we missed an assertion that would be hit after the early
return.

This makes sure to test both blank and non-blank Durations with these
relativeTo strings, and expect some strings to fail at different steps
with the two cases.

See: tc39/proposal-temporal#3015
ptomato added a commit that referenced this issue Dec 5, 2024
DifferenceISODateTime asserts that the ISO Date-Time Records passed to it
are within limits. Previously there were two places where this was not
guaranteed to be the case. Add checks that throw RangeError so the
assertion is not hit.

Closes: #3015
@Ms2ger Ms2ger closed this as completed in b5da334 Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial spec-text Specification text involved
Projects
None yet
Development

No branches or pull requests

2 participants