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

Normative: Validate fractionalSecondDigits after truncation #2297

Merged

Conversation

gibson042
Copy link
Collaborator

Fixes #2296

The result is consistent with my ECMA-402 proposal at tc39/ecma402#691 (reject non-numeric input and perform validation of numeric input after truncation).

@gibson042 gibson042 added spec-text Specification text involved normative Would be a normative change to the proposal labels Jun 13, 2022
@gibson042 gibson042 requested a review from ptomato June 13, 2022 20:19
@codecov
Copy link

codecov bot commented Jun 13, 2022

Codecov Report

Merging #2297 (a56bdfc) into main (5b9d76a) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2297      +/-   ##
==========================================
- Coverage   91.08%   91.08%   -0.01%     
==========================================
  Files          19       19              
  Lines       10558    10566       +8     
  Branches     1695     1695              
==========================================
+ Hits         9617     9624       +7     
- Misses        931      932       +1     
  Partials       10       10              
Flag Coverage Δ
test262 83.94% <100.00%> (+0.48%) ⬆️
tests 81.83% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
polyfill/lib/ecmascript.mjs 93.33% <100.00%> (+0.01%) ⬆️
polyfill/lib/instant.mjs 90.54% <0.00%> (-0.50%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5b9d76a...a56bdfc. Read the comment docs.

@@ -749,10 +749,10 @@ export const ES = ObjectAssign({}, ES2020, {
if (digits === 'auto') return { precision: 'auto', unit: 'nanosecond', increment: 1 };
throw new RangeError(`fractionalSecondDigits must be 'auto' or 0 through 9, not ${digits}`);
}
if (NumberIsNaN(digits) || digits < 0 || digits > 9) {
const precision = ES.ToInteger(digits);
if (!NumberIsFinite(digits) || precision < 0 || precision > 9) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the NumberIsFinite check needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be NumberIsNaN instead, but this aligns better with the spec text.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure ToInteger should return zero for NaN

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ES.ToInteger(NaN) does return 0, but note that the NumberIsFinite check is against its input rather than its output. The spec text here calls for a RangeError when fractionalDigitsVal is not finite or ToIntegerOrInfinity(fractionalDigitsVal) is out of bounds, which is equivalent to this code in the polyfill that throws a RangeError when digits is not finite or ES.ToInteger(digits) is out of bounds.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eek. I think I'd prefer moving the NumberIsFinite call before the ToInteger call, then. Also, I think we can use MathTrunc instead of ToInteger.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ptomato ptomato marked this pull request as draft June 14, 2022 14:29
Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to present this in July or do we need to wait until tc39/ecma402#691 is discussed in TG2?

@gibson042
Copy link
Collaborator Author

I have a preference for discussing it in July no matter what, but would be willing to wait if someone feels strongly about it.

@@ -749,10 +749,10 @@ export const ES = ObjectAssign({}, ES2020, {
if (digits === 'auto') return { precision: 'auto', unit: 'nanosecond', increment: 1 };
throw new RangeError(`fractionalSecondDigits must be 'auto' or 0 through 9, not ${digits}`);
}
if (NumberIsNaN(digits) || digits < 0 || digits > 9) {
const precision = ES.ToInteger(digits);
if (!NumberIsFinite(digits) || precision < 0 || precision > 9) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eek. I think I'd prefer moving the NumberIsFinite call before the ToInteger call, then. Also, I think we can use MathTrunc instead of ToInteger.

spec/abstractops.html Outdated Show resolved Hide resolved
Co-authored-by: Ms2ger <Ms2ger@gmail.com>
ptomato added a commit to ptomato/test262 that referenced this pull request Jul 28, 2022
…nalSecondDigits

This implements the normative change in
tc39/proposal-temporal#2297 which reached
consensus at the July 2022 TC39 meeting.

Values given as the fractionalSecondDigits option are now truncated to
integers before they are compared to the allowable range.
@ptomato ptomato marked this pull request as ready for review July 28, 2022 20:20
@ptomato
Copy link
Collaborator

ptomato commented Jul 28, 2022

This change reached consensus at the July 2022 TC39 meeting. Tests are in tc39/test262#3621

@ptomato ptomato merged commit 273cb2e into tc39:main Jul 28, 2022
ptomato added a commit to tc39/test262 that referenced this pull request Jul 29, 2022
…nalSecondDigits

This implements the normative change in
tc39/proposal-temporal#2297 which reached
consensus at the July 2022 TC39 meeting.

Values given as the fractionalSecondDigits option are now truncated to
integers before they are compared to the allowable range.
pull bot pushed a commit to jamlee-t/v8 that referenced this pull request Aug 30, 2022
Validate fractionalSecondDigits after truncation

tc39/proposal-temporal#2297

Spec text:
https://tc39.es/proposal-temporal/#sec-temporal-tosecondsstringprecision

Bug: v8:11544
Change-Id: I648f087f4fa2cfd6245c7946cfa625a7c5e3b3b9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3855702
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82801}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
normative Would be a normative change to the proposal spec-text Specification text involved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fractionalSecondDigits range validation should follow truncation to integer
3 participants