-
Notifications
You must be signed in to change notification settings - Fork 156
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
NaN, undefined, and Infinity in ToTemporalDurationRecord #1658
Comments
This is also mentioned in #1502 (long list of issues):
Regarding the second point you mention:
I also stumbled across this when implementing this part of Temporal in SerenityOS's LibJS, and chose to mirror the polyfill in the meantime: only doing the steps d, e, and f if the value from step b is not undefined.
i.e. in this case the polyfill's observable behavior differs from the spec as it does not throw a RangeError for undefined properties of the duration-like object. |
The reason I reaslize this issue is I implement my v8 prototype strickly follow the current spec text and it turn out it will always throw RangeError if I call Temporal.Duration.from({years: 1}) because while go down the table to call Get("monhts") it will get undefined as val and turn become NaN and floor(NaN) != NaN will cause the throw RangeError. Therefore, if we do not change the spec, we will throw on Temporal.Duration.from({}) unless all 10 fields are specified. I do not believe that was the intention of the Temporal spec but that could be an option we just not change Temporal since it is already in Stage 3 and always throw RangeError unless all 10 fileds are presented. |
ok, I have coded the test for the current spec text in tc39/test262#3068 . If the champion decide to take my PR in #1659 I could of course chagne 3068 to reflect that but otherwise, it could go in with the current spec text which mandate all fields are presented and are not undefined. |
This was obviously not the intention. This should go into the next batch of normative changes that we ask for consensus on. |
ToTemporalDurationRecord
https://tc39.es/proposal-temporal/#sec-temporal-totemporaldurationrecord
Let's say we have the following code
What should happen?
Temporal.Duration.from will pass the object to ToTemporalDuration(item).
https://tc39.es/proposal-temporal/#sec-temporal-totemporalduration
b. Let result be ? ToTemporalDurationRecord(item).
will call ToTemporalDurationRecord
https://tc39.es/proposal-temporal/#sec-temporal-totemporaldurationrecord
and step 5 will be run
b. Let val be ? Get(temporalDurationLike, prop).
will be called
and now val could be undefined, NaN or Infinity
then
d. Let val be ? ToNumber(val).
https://tc39.es/ecma262/#sec-tonumber
will be called and turn them into NaN, NaN, Infinity
right?
then the next line
e. If floor(val) ≠ val, then
i. Throw a RangeError exception.
now.... should we throw RangeError for them or not? I do not know what is the definintion of floor on NaN and Infinity.
If we throw RangeError for them, then any undefined will be thrown so {year:1} will also throw RangeError because the Get('month') will get undefined back.
Should we check the val is NaN or some special case first and skip that if check first?
@justingrant @ptomato @littledan @ljharb @Ms2ger @ryzokuken
The text was updated successfully, but these errors were encountered: