Editorial: Update GetOption to throw a TypeError when a required option is missing - #1068
Conversation
…on is missing TypeError rather than RangeError is in better alignment with other parts of the spec where a required parameter or option is missing: * [ECMA-262 GroupBy](https://tc39.es/ecma262/#sec-groupby) * [ECMA-262 Object static functions](https://tc39.es/ecma262/#sec-properties-of-the-object-constructor) * [ECMA-262 RegExp.escape](https://tc39.es/ecma262/#sec-regexp.escape) * [ECMA-262 Array.prototype.every](https://tc39.es/ecma262/#sec-array.prototype.every) et al. * Also {Map,Set}.prototype.{forEach,getOrInsertComputed} * [ECMA-262 Uint8Array static methods](https://tc39.es/ecma262/#sec-additional-properties-of-the-uint8array-constructor) * ECMA-262 Set.prototype.{difference,intersection,union,...} * ECMA-262 [WeakMap methods](https://tc39.es/ecma262/#sec-properties-of-the-weakmap-prototype-object) and [WeakSet methods](https://tc39.es/ecma262/#sec-properties-of-the-weakset-prototype-object) * [ECMA-262 Promise](https://tc39.es/ecma262/#sec-promise-constructor) * [ECMA-262 Reflect functions](https://tc39.es/ecma262/#sec-reflect-object) * [Intl.DateTimeFormat.prototype.{formatRange,formatRangeToParts}](https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.formatRange) * Also [Intl.NumberFormat.prototype.{formatRange,formatRangeToParts}](https://tc39.es/ecma402/#sec-intl.numberformat.prototype.formatrange) and [Intl.PluralRules.prototype.selectRange](https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.selectrange) * [Intl.DisplayNames](https://tc39.es/ecma402/#sec-Intl.DisplayNames) (which should actually be updated to `Let _type_ be ? GetOption(_options_, *"type"*, ~string~, « *"language"*, *"region"*, *"script"*, *"currency"*, *"calendar"*, *"dateTimeField"* », ~required~).`) * [Intl.DurationFormat.prototype.{format,formatToParts}](https://tc39.es/ecma402/#sec-Intl.DurationFormat.prototype.format) * [Intl.Locale](https://tc39.es/ecma402/#sec-Intl.Locale) * [SetNumberFormatUnitOptions](https://tc39.es/ecma402/#sec-setnumberformatunitoptions) as exercised by e.g. `new Intl.NumberFormat("en", { style: "currency" })` and `new Intl.NumberFormat("en", { style: "unit" })` Fortunately, this change is editorial because no current site calls GetOption with _default_ ~required~, although I expect proposals like [Amount](https://github.com/tc39/proposal-amount) to do so.
Yes, I remember that... most of #687 was subsequently reverted in #822, but not that part.
AFAICT, it's actually not... I don't see any uses of GetOption in #1044, and tc39/ecma262#3759 is no longer introducing GetOption to ECMA-262, instead having its own GetTemporalUnitValuedOption for reading But you're right to single out Temporal here, and it is odd that it diverges in this way. It seems like the Temporal RangeErrors were introduced without scrutiny in ToSmallestTemporalUnit by tc39/proposal-temporal#886 (where they were appropriate for «If disallowedUnits contains smallestUnit» but not for «If smallestUnit is "not present"») and Temporal.Duration.prototype.total by tc39/proposal-temporal#1064 (later moved into ToTemporalDurationTotalUnit by tc39/proposal-temporal#1599), carried forward without comment into GetTemporalUnit by tc39/proposal-temporal#2248 , rolled into GetOption by #687 , and then Temporal subsequently abandoned GetOption but kept the behavior. I'm still very much in favor of having the more standard behavior here, and will see what can be done to bring Temporal in line (although it looks like there is some test262 coverage:
|
Ah, I see. I didn't know that this changed in the ECMA262 spec PR when compared to what's on https://tc39.es/proposal-temporal. |
Yeah, we're in an awkward state right now where the source of truth for Temporal is at tc39/ecma262#3759 (and its ECMA-402 sibling at #1044 ). |
sffc
left a comment
There was a problem hiding this comment.
Yes, if a required option is missing, it is a TypeError. If Temporal is doing something different, then it is a bug in Temporal.
TypeError rather than RangeError is in better alignment with other parts of the spec where a required parameter or option is missing:
new Intl.NumberFormat("en", { style: "currency" })andnew Intl.NumberFormat("en", { style: "unit" })Fortunately, this change is editorial because no current site calls GetOption with default ~required~, although I expect proposals like Amount to do so.