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: Fix out-of-range NaNs in date set methods #2136

Merged
merged 1 commit into from
Feb 3, 2022

Conversation

devsnek
Copy link
Member

@devsnek devsnek commented Aug 15, 2020

Marked as editoral due to current text being nonsensical and new text matching implementations.

@bakkot
Copy link
Contributor

bakkot commented Aug 15, 2020

Looks good. Couple of consistency things:

  • setFullYear, setUTCFullYear, and setYear already have guards on NaN. In those cases the guard isn't side-effecting, and hence can come either before or after the observable ToNumber coercions. Those existing ones are written before the coercion, whereas the new ones are after. It'd be good to move the existing ones to after as well, so they match.
  • I think we should also avoid passing NaN to LocalTime. In other places that's explicitly prevented. So it would be good to move the call to LocalTime after the NaN check, as in
1. Let _t_ be ? thisTimeValue(*this* value).
1. Let _dt_ be ? ToNumber(_date_).
1. If _t_ is *NaN*, return *NaN*
1. Set _t_ to LocalTime(_t_).

@michaelficarra
Copy link
Member

Is this editorial?

@bakkot
Copy link
Contributor

bakkot commented Aug 17, 2020

Is this editorial?

I think so: the current state is nonsensical by a strict reading and the only plausible interpretation by a loose reading (that floor(NaN), etc, return NaN) matches the semantics in this PR.

@ljharb
Copy link
Member

ljharb commented Aug 17, 2020

hmm - DateFromTime takes a time value which is allowed to be NaN, for example - so i think that the fix isn't "don't call DateFromTime with NaN", it's maybe "add an explicit step inside each of these operations that returns NaN if NaN is provided"?

(similarly for the other examples in this PR)

@bakkot
Copy link
Contributor

bakkot commented Aug 17, 2020

I would strongly prefer to filter out NaN as early and explicitly as possible, rather than adding a special case for it in each intermediate operation.

@ljharb
Copy link
Member

ljharb commented Aug 17, 2020

These operations already are defined to accept a time value, which allows NaN - so if we want to make that change, we also have to redefine all of them to only accept integers.

@bakkot
Copy link
Contributor

bakkot commented Aug 17, 2020

I am happy to additionally add the word "finite" before the words "time value" in the headers of the various intermediate operations, sure.

@bakkot bakkot changed the title Editorial: Fix out-of-range NaNs in date set methods Normative: Fix out-of-range NaNs in date set methods Sep 20, 2020
@bakkot bakkot added needs consensus This needs committee consensus before it can be eligible to be merged. needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 labels Sep 20, 2020
@bakkot
Copy link
Contributor

bakkot commented Sep 20, 2020

I've updated this to be more thorough. Unfortunately, in some of these cases there were multiple plausible interpretations and engines do not agree, so I've marked this as normative.

Specifically, when invoking the set methods which have optional higher-precision arguments (like setHour) on an invalid Date object, there is not agreement on which arguments should be coerced before returning. For example,

(new Date(NaN)).setHours(
  { valueOf(){ print('coerced hour'); } },
  { valueOf(){ print('coerced min'); } },
  { valueOf(){ print('coerced sec'); } },
  { valueOf(){ print('coerced ms'); } },
);

produces

┌─────┬──────────────┐
│ ch  │ coerced hour │
│ v8  │              │
├─────┼──────────────┤
│ jsc │              │
├─────┼──────────────┤
│ sm  │ coerced hour │
│ xs  │ coerced min  │
│     │ coerced sec  │
│     │ coerced ms   │
└─────┴──────────────┘

The semantics I've specified in this PR match Spidermonkey's behavior, since it seemed the most natural to me and because I believe it matches the intent of the the spec as written.

@ljharb ljharb added the normative change Affects behavior required to correctly evaluate some ECMAScript source text label Sep 20, 2020
@bakkot bakkot added has consensus This has committee consensus. and removed needs consensus This needs committee consensus before it can be eligible to be merged. labels Nov 16, 2020
@bakkot bakkot added the es2021 label Feb 8, 2021
spec.html Outdated
1. If _min_ is not present, let _m_ be MinFromTime(_t_).
1. If _sec_ is not present, let _s_ be SecFromTime(_t_).
1. If _ms_ is not present, let _milli_ be msFromTime(_t_).
1. Let _date_ be MakeDate(Day(_t_), MakeTime(_h_, _m_, _s_, _milli_)).
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer if we consistently named these newDate.

@ljharb ljharb force-pushed the master branch 3 times, most recently from 3d0c24c to 7a79833 Compare June 29, 2021 02:21
@ljharb ljharb added editor call to be discussed in the next editor call and removed editor call to be discussed in the next editor call labels Sep 8, 2021
@bakkot
Copy link
Contributor

bakkot commented Dec 30, 2021

Rebased. I've also opened a PR with tests: tc39/test262#3362. Once those land, so can this.

Edit: landed.

@bakkot bakkot added editor call to be discussed in the next editor call has test262 tests and removed needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 labels Jan 4, 2022
@ljharb ljharb requested a review from a team January 5, 2022 22:51
@michaelficarra michaelficarra requested review from syg and removed request for a team January 5, 2022 22:51
@bakkot bakkot requested a review from a team January 5, 2022 22:51
@bakkot bakkot removed the editor call to be discussed in the next editor call label Jan 5, 2022
webkit-commit-queue pushed a commit to WebKit/WebKit that referenced this pull request Jan 15, 2022
https://bugs.webkit.org/show_bug.cgi?id=235271

Reviewed by Alexey Shvayka.

JSTests:

* test262/expectations.yaml:

Source/JavaScriptCore:

Even if the input Date is NaN or the result looks like NaN, we need to coerce passed
arguments to Number[1] since it has observable side effect.

[1]: tc39/ecma262#2136

* runtime/DatePrototype.cpp:
(JSC::applyToNumbersToTrashedArguments):
(JSC::fillStructuresUsingTimeArgs):
(JSC::fillStructuresUsingDateArgs):
(JSC::setNewValueFromTimeArgs):
(JSC::setNewValueFromDateArgs):


Canonical link: https://commits.webkit.org/246086@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288066 268f45cc-cd09-0410-ab3c-d52691b4dbfc
annulen pushed a commit to qtwebkit/qtwebkit that referenced this pull request Jan 16, 2022
https://bugs.webkit.org/show_bug.cgi?id=235271

Reviewed by Alexey Shvayka.

JSTests:

* test262/expectations.yaml:

Source/JavaScriptCore:

Even if the input Date is NaN or the result looks like NaN, we need to coerce passed
arguments to Number[1] since it has observable side effect.

[1]: tc39/ecma262#2136

* runtime/DatePrototype.cpp:
(JSC::applyToNumbersToTrashedArguments):
(JSC::fillStructuresUsingTimeArgs):
(JSC::fillStructuresUsingDateArgs):
(JSC::setNewValueFromTimeArgs):
(JSC::setNewValueFromDateArgs):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@288066 268f45cc-cd09-0410-ab3c-d52691b4dbfc
@ljharb ljharb removed the es2021 label Jan 17, 2022
@bakkot bakkot added the es2022 label Jan 19, 2022
Copy link
Contributor

@syg syg left a comment

Choose a reason for hiding this comment

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

lgtm

@bakkot bakkot added the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label Feb 3, 2022
@ljharb ljharb merged commit ca53334 into tc39:main Feb 3, 2022
@devsnek devsnek deleted the fix-date-set branch February 3, 2022 18:37
anba added a commit to anba/test262 that referenced this pull request Oct 10, 2024
ptomato pushed a commit to tc39/test262 that referenced this pull request Oct 11, 2024
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Oct 12, 2024
…onkey-reviewers,jandem

We never implemented this spec change, which introduced some subtle changes how
`NaN` values have to be treated. This part updates all Date setters to match the
current spec text.

Normative change from: tc39/ecma262#2136

Tests are in: tc39/test262#4258

Differential Revision: https://phabricator.services.mozilla.com/D225248
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this pull request Oct 12, 2024
…onkey-reviewers,jandem

We never implemented this spec change, which introduced some subtle changes how
`NaN` values have to be treated. This part updates all Date setters to match the
current spec text.

Normative change from: tc39/ecma262#2136

Tests are in: tc39/test262#4258

Differential Revision: https://phabricator.services.mozilla.com/D225248
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 15, 2024
…onkey-reviewers,jandem

We never implemented this spec change, which introduced some subtle changes how
`NaN` values have to be treated. This part updates all Date setters to match the
current spec text.

Normative change from: tc39/ecma262#2136

Tests are in: tc39/test262#4258

Differential Revision: https://phabricator.services.mozilla.com/D225248

UltraBlame original commit: 8887a6541d7abe020db25a831b41c32498324702
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 15, 2024
…onkey-reviewers,jandem

We never implemented this spec change, which introduced some subtle changes how
`NaN` values have to be treated. This part updates all Date setters to match the
current spec text.

Normative change from: tc39/ecma262#2136

Tests are in: tc39/test262#4258

Differential Revision: https://phabricator.services.mozilla.com/D225248

UltraBlame original commit: 8887a6541d7abe020db25a831b41c32498324702
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 15, 2024
…onkey-reviewers,jandem

We never implemented this spec change, which introduced some subtle changes how
`NaN` values have to be treated. This part updates all Date setters to match the
current spec text.

Normative change from: tc39/ecma262#2136

Tests are in: tc39/test262#4258

Differential Revision: https://phabricator.services.mozilla.com/D225248

UltraBlame original commit: 8887a6541d7abe020db25a831b41c32498324702
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has consensus This has committee consensus. has test262 tests normative change Affects behavior required to correctly evaluate some ECMAScript source text ready to merge Editors believe this PR needs no further reviews, and is ready to land. spec bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants