-
Notifications
You must be signed in to change notification settings - Fork 167
Normative: Validate unit-valued options after all options are read #3130
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3130 +/- ##
=======================================
Coverage 96.85% 96.85%
=======================================
Files 21 21
Lines 9983 9983
Branches 1829 1829
=======================================
Hits 9669 9669
Misses 268 268
Partials 46 46 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
70fa5fa
to
b3f6a0f
Compare
The code that changes behavior with this PR is something like: obj = {
get largestUnit() {
console.log("get largestUnit");
return "years";
},
get smallestUnit() {
console.log("get smallestUnit");
return "seconds";
},
}
Temporal.PlainTime.from("00:00").round(obj) Current behavior: console logs "get largestUnit" and then RangeError is thrown. New behavior: console logs both "get largestUnit" and "get smallestUnit", and then RangeError is thrown. Note: the RangeError is because PlainTime does not allow (as noted previously, there doesn't appear to be Test262 coverage for this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intended changes as I understand them do seem both reasonable and narrow, but I think the algorithms steps fail to properly implement them.
1. Let _allowedStrings_ be a new empty List. | ||
1. Append *"auto"* to _allowedStrings_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested simplification:
1. Let _allowedStrings_ be a new empty List. | |
1. Append *"auto"* to _allowedStrings_. | |
1. Let _allowedStrings_ be « *"auto"* ». |
1. Let _allowedValues_ be a new empty List. | ||
1. For each row of <emu-xref href="#table-temporal-units"></emu-xref>, except the header row, in table order, do | ||
1. Let _unit_ be the value in the "Value" column of the row. | ||
1. If the "Category" column of the row is ~date~ and _unitGroup_ is ~date~ or ~datetime~, append _unit_ to _allowedValues_. | ||
1. Else if the "Category" column of the row is ~time~ and _unitGroup_ is ~time~ or ~datetime~, append _unit_ to _allowedValues_. | ||
1. If _extraValues_ is present, then | ||
1. Set _allowedValues_ to the list-concatenation of _allowedValues_ and _extraValues_. | ||
1. If _allowedValues_ does not contain _value_, throw a RangeError exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it makes sense to keep the allowedValues list at all.
1. Let _allowedValues_ be a new empty List. | |
1. For each row of <emu-xref href="#table-temporal-units"></emu-xref>, except the header row, in table order, do | |
1. Let _unit_ be the value in the "Value" column of the row. | |
1. If the "Category" column of the row is ~date~ and _unitGroup_ is ~date~ or ~datetime~, append _unit_ to _allowedValues_. | |
1. Else if the "Category" column of the row is ~time~ and _unitGroup_ is ~time~ or ~datetime~, append _unit_ to _allowedValues_. | |
1. If _extraValues_ is present, then | |
1. Set _allowedValues_ to the list-concatenation of _allowedValues_ and _extraValues_. | |
1. If _allowedValues_ does not contain _value_, throw a RangeError exception. | |
1. If _extraValues_ is present and _extraValues_ contains _value_, return ~unused~. | |
1. Let _category_ be the value in the “Category” column of the row of <emu-xref href="#table-temporal-units"></emu-xref> whose “Value” column contains _value_. If there is no such row, throw a RangeError exception. | |
1. If _category_ is ~date~ and _unitGroup_ is ~date~ or ~datetime~, return ~unused~. | |
1. If _category_ is ~time~ and _unitGroup_ is ~time~ or ~datetime~, return ~unused~. | |
1. Throw a RangeError exception. |
1. Perform ? ValidateTemporalUnitValue(_largestUnit_, _unitGroup_). | ||
1. If _largestUnit_ is ~unset~, then | ||
1. Set _largestUnit_ to ~auto~. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right to me... if largestUnit is ~unset~, wouldn't ValidateTemporalUnitValue(largestUnit, unitGroup) have already rejected it?
1. Perform ? ValidateTemporalUnitValue(_largestUnit_, _unitGroup_). | |
1. If _largestUnit_ is ~unset~, then | |
1. Set _largestUnit_ to ~auto~. | |
1. If _largestUnit_ is ~unset~ or ~auto~, set _largestUnit_ to ~auto~. | |
1. Else, perform ? ValidateTemporalUnitValue(_largestUnit_, _unitGroup_). |
And likewise for the other call sites.
1. Perform ? ValidateTemporalUnitValue(_largestUnit_, ~datetime~, « ~auto~ »). | ||
1. Perform ? ValidateTemporalUnitValue(_smallestUnit_, ~datetime~). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted above, it seems like these calls will reject ~unset~ values.
See #3116
This preserves the original call to
GetOption
, but it always calls it with the full list of units, and I pull the subset-checking logic into a separate AO.I have two commits: an editorial change to split the AO in two, and a small normative change to move the validation later down at the call sites.
@nekevss @Manishearth