Skip to content

Various fixes#107

Merged
ryzokuken merged 26 commits intotc39:mainfrom
anba:misc-fixes
Aug 3, 2022
Merged

Various fixes#107
ryzokuken merged 26 commits intotc39:mainfrom
anba:misc-fixes

Conversation

@anba
Copy link
Contributor

@anba anba commented Jul 25, 2022

Various small fixes. I've left two TODO notes, because fixing them requires larger changes.

anba added 26 commits July 25, 2022 09:38
Also change `value` computation to reduce indentation.
…c" or "2-digit"

```js
new Intl.DurationFormat("en", {
  hours: "2-digit",
});
```

throws `RangeError: invalid value long for option minutes` according to the
original text, because the `baseStyle` is `"long"`, so when the default
`style` for the missing `"minutes"` option is computed, we use `"long"`,
which is incompatible with the `prevStyle` of `"2-digit"`.
spec.emu Outdated
1. Let _style_ be the current value of the _styleSlot_ slot of _durationFormat_.
1. Let _nextStyle_ be the current value of the _nextStyleSlot_ slot of _durationFormat_.
1. Let _style_ be _durationFormat_.[[<_styleSlot_>]].
1. Let _nextStyle_ be _durationFormat_[[<_nextStyleSlot_>]].
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is missing a dot before [[ here and below. Later commits fix these errors.

Copy link
Member

@ryzokuken ryzokuken left a comment

Choose a reason for hiding this comment

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

Thanks for all your amazing work! I see you're either a git add --patch fan or just really organized (it was really helpful). Either way, I left some comments, a subset of which might require some discussion.

spec.emu Outdated
1. If _style_ is `"2-digit"`, then
1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, `"minimumIntegerDigits"`, `2`).
1. If _value_ is *+0*<sub>𝔽</sub> or *-0*<sub>𝔽</sub> and _display_ is `"auto"`, then
1. If _value_ is 0 and _display_ is `"auto"`, then
Copy link
Member

Choose a reason for hiding this comment

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

I suppose I keep falling in the JavaScript trap of "this will be freed once out of scope" 🤦

spec.emu Outdated
1. Skip to the next iteration.
1. Let _nf_ be ! Construct(%NumberFormat%, &laquo; _durationFormat_.[[Locale]], _nfOpts_ &raquo;).
1. Let _num_ be ! FormatNumeric(_durationFormat_.[[NumberFormat]], 𝔽(_value_)).
1. Let _num_ be ! FormatNumeric(_nf_, 𝔽(_value_)).
Copy link
Member

Choose a reason for hiding this comment

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

I suppose I missed this when I moved from a single (cached) numberformat instance to dynamic one based on the style.

1. Let _unit_ be the Unit value.
1. Let _style_ be the current value of the _styleSlot_ slot of _durationFormat_.
1. Let _nextStyle_ be the current value of the _nextStyleSlot_ slot of _durationFormat_.
1. Let _style_ be _durationFormat_.[[&lt;_styleSlot_&gt;]].
Copy link
Member

Choose a reason for hiding this comment

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

I did it this way previously, but @bakkot asked me to switch. I don't mind either, but let's make sure we're all onboard with this style (fwiw, it's commonly used across 402).

Copy link
Member

Choose a reason for hiding this comment

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

Did I? I don't recall. Given that this will go in 402 I'm fine with matching the prevailing editorial conventions of 402.

1. If 𝔽(_v_) is not finite, return *false*.
1. Let _valueSlot_ be the Value Slot value of the current row.
1. Let _v_ be _record_.[[&lt;_valueSlot_&gt;]].
1. Assert: 𝔽(_v_) is finite.
Copy link
Member

Choose a reason for hiding this comment

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

Is this a normative change? Although I'm not sure if we should cater to infinite values...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Duration records in Intl.DurationFormat are always created through ToDurationRecord, which rejects infinite values (through the IsIntegralNumber check). I only performed this change, because we can't currently have infinite values, so it seems better to me to use an assertion.

1. Let _numberingSystem_ be ? GetOption(_options_, *"numberingSystem"*, *"string"*, *undefined*, *undefined*).
1. If _numberingSystem_ is not *undefined, then
1. If _numberingSystem_ does not match the Unicode Locale Identifier `type` nonterminal, throw a `RangeError` exception.
1. If _numberingSystem_ does not match the Unicode Locale Identifier `type` nonterminal, throw a *RangeError* exception.
Copy link
Member

Choose a reason for hiding this comment

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

Regarding this and the previous two commits, I believe I switched from asterisks to backticks on @rbuckton's advice. That said, I'd be happy to do either as long as we have a clear contender.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The style changed at some point → tc39/ecma402#396, which links to other discussions and the corresponding PR for ECMA-262.

spec.emu Outdated
1. Skip to the next iteration.
1. Let _nf_ be ? Construct(%NumberFormat%, &laquo; _durationFormat_.[[Locale]], _nfOpts_ &raquo;).
1. Let _num_ be ! FormatNumeric(_durationFormat_.[[NumberFormat]], _value_).
1. Let _num_ be ! FormatNumeric(_durationFormat_.[[NumberFormat]], 𝔽(_value_)).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

𝔽 will need to be removed after Intl.NumberFormat V3 lands. But this will lead to a different output for some inputs, so if we care about the exact same output, this line will need to be changed to 𝔽(ℝ(value)).

Or alternatively we could make Intl.DurationFormat dependent on Intl.NumberFormat V3.

I guess it's better to open a separate issue about the precision, because Temporal typically generates the precise result.

Copy link
Member

Choose a reason for hiding this comment

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

Ping @sffc. How do you think we should proceed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#110 has a concrete example to show the possible precision loss.

@ryzokuken ryzokuken merged commit 8ad7a89 into tc39:main Aug 3, 2022
@anba anba deleted the misc-fixes branch October 18, 2023 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants