-
Notifications
You must be signed in to change notification settings - Fork 157
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: Validate receiver fields before fields of any param objects #2478
Conversation
1. Let _partialTime_ be ? ToTemporalTimeRecord(_temporalTimeLike_, ~partial~). | ||
1. Set _options_ to ? GetOptionsObject(_options_). | ||
1. Let _overflow_ be ? ToTemporalOverflow(_options_). | ||
1. Let _partialTime_ be ? ToTemporalTimeRecord(_temporalTimeLike_, ~partial~). |
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.
It's debatable whether we'd want to make this change to PlainTime, which doesn't use PrepareTemporalFields, but it seems most consistent with the form suggested by Richard in #2462 (comment)
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.
👍
But if this is awkward and options never affects the interpretation of the first argument, then it would also be coherent to move every Set _options_ to ? GetOptionsObject(_options_).
to follow full consumption (with constituent validation) of the first argument by PrepareTemporalFields/ToTemporalTimeRecord/etc.—although that is not my preference because it's not clear to me in that case whether GetOptionsObject should precede or follow integration of receiver and argument data in e.g. CalendarMergeFields.
Codecov Report
@@ Coverage Diff @@
## main #2478 +/- ##
==========================================
- Coverage 94.97% 94.95% -0.03%
==========================================
Files 20 20
Lines 10907 10817 -90
Branches 1996 1957 -39
==========================================
- Hits 10359 10271 -88
Misses 487 487
+ Partials 61 59 -2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
The with() methods, as well as PlainYearMonth's since() and until(), were adjusted to read the receiver's fields before the fields of any objects provided as arguments. This change is observable, so affects several tests that test the observed order of operations. Normative PR: tc39/proposal-temporal#2478
Test262 updates are in tc39/test262#3769 |
1. Let _partialTime_ be ? ToTemporalTimeRecord(_temporalTimeLike_, ~partial~). | ||
1. Set _options_ to ? GetOptionsObject(_options_). | ||
1. Let _overflow_ be ? ToTemporalOverflow(_options_). | ||
1. Let _partialTime_ be ? ToTemporalTimeRecord(_temporalTimeLike_, ~partial~). |
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.
👍
But if this is awkward and options never affects the interpretation of the first argument, then it would also be coherent to move every Set _options_ to ? GetOptionsObject(_options_).
to follow full consumption (with constituent validation) of the first argument by PrepareTemporalFields/ToTemporalTimeRecord/etc.—although that is not my preference because it's not clear to me in that case whether GetOptionsObject should precede or follow integration of receiver and argument data in e.g. CalendarMergeFields.
1. Let _thisFields_ be ? PrepareTemporalFields(_yearMonth_, _fieldNames_, «»). | ||
1. Perform ! CreateDataPropertyOrThrow(_thisFields_, *"day"*, *1*<sub>𝔽</sub>). | ||
1. Let _thisDate_ be ? CalendarDateFromFields(_calendar_, _thisFields_). | ||
1. Let _otherFields_ be ? PrepareTemporalFields(_other_, _fieldNames_, «»). | ||
1. Perform ! CreateDataPropertyOrThrow(_otherFields_, *"day"*, *1*<sub>𝔽</sub>). | ||
1. Let _otherDate_ be ? CalendarDateFromFields(_calendar_, _otherFields_). | ||
1. Let _untilOptions_ be OrdinaryObjectCreate(*null*). | ||
1. Perform ? CopyDataProperties(_untilOptions_, _settings_.[[Options]], « »). |
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.
It is curious that this step can throw; is that a bug in failure to properly consume options earlier on?
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 don't think it's a bug - we have to perform CopyDataProperties on options at some point, so that we can pass an options object to CalendarDateUntil with a modified largestUnit
property. options is a user-provided object so it may have accessor properties.
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.
Right, I'm saying that the bug is consuming it so deep in the spec algorithms rather than in initial processing—and in particular in performing CopyDataProperties after GetDifferenceSettings has read several properties on its own.
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 could see this going either way - it'd be good to eliminate the duplicate reads, but on the other hand we'd introduce an inconsistency where we'd copy the options object in the since/until methods of PlainDate, PlainDateTime, PlainYearMonth, and ZonedDateTime; and not copy it in the since/until methods of PlainTime and Instant.
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.
Wouldn't options be copied in all since/until methods?
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.
Only the ones where a modified options object needs to be passed on to calendar.dateUntil()
. Otherwise, we just read only the needed properties in alphabetical order.
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.
Well, either that serves as explanation of the inconsistency or we'd copy options in all since/until methods even though some technically don't need it.
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.
Do you have a concrete proposal for this? If we can manage to write that additional change before TC39's review deadline, I wouldn't be opposed to including it here. Otherwise I think it can be done as part of #2289 or left as is.
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.
Concretely, I'm proposing 1. Perform ? CopyDataProperties(_optionsCopy_, _options_, « »).
in every DifferenceTemporal<Type> operation immediately after validating other and use of optionsCopy rather than options in every subsequent step. But I'm also comfortable with a compromise in which that change is omitted in DifferenceTemporalInstant and DifferenceTemporalPlainTime, ideally replaced with a NOTE step explaining its omission.
I agree that it is logically part of the fixes for #2289, but will still try to put up a narrow PR since it has been specifically identified (and in fact already has a comment: #2289 (comment) ).
Draft until presented at the next TC39 plenary meeting. |
In ZonedDateTime with(), the 'timeZone' field was observably read from the receiver and from the object returned from mergeFields(), but never used. This is not only an unnecessary user call, it becomes a bug when we remove the ZonedDateTime.p.timeZone property in order to replace it with .timeZoneId and .getTimeZone(). Also part of #2478
ad0283a
to
f35fc58
Compare
In ZonedDateTime with(), the 'timeZone' field was observably read from the receiver and from the object returned from mergeFields(), but never used. This is not only an unnecessary user call, it becomes a bug when we remove the ZonedDateTime.p.timeZone property in order to replace it with .timeZoneId and .getTimeZone(). Also part of #2478
In ZonedDateTime with(), the 'timeZone' field was observably read from the receiver and from the object returned from mergeFields(), but never used. This is not only an unnecessary user call, it becomes a bug when we remove the ZonedDateTime.p.timeZone property in order to replace it with .timeZoneId and .getTimeZone(). Also part of #2478
The with() methods, as well as PlainYearMonth's since() and until(), were adjusted to read the receiver's fields before the fields of any objects provided as arguments. This change is observable, so affects several tests that test the observed order of operations. Normative PR: tc39/proposal-temporal#2478
The with() methods, as well as PlainYearMonth's since() and until(), were adjusted to read the receiver's fields before the fields of any objects provided as arguments. This change is observable, so affects several tests that test the observed order of operations. Normative PR: tc39/proposal-temporal#2478
The with() methods, as well as PlainYearMonth's since() and until(), were adjusted to read the receiver's fields before the fields of any objects provided as arguments. This change is observable, so affects several tests that test the observed order of operations. Normative PR: tc39/proposal-temporal#2478
In ZonedDateTime with(), the 'timeZone' field was observably read from the receiver and from the object returned from mergeFields(), but never used. This is an unnecessary user call.
Changes to the order of observable operations in - PlainDate.p.with - PlainDateTime.p.with - PlainMonthDay.p.with - PlainTime.p.with - PlainYearMonth.p.since - PlainYearMonth.p.until - PlainYearMonth.p.with - ZonedDateTime.p.with Swapping the PrepareTemporalFields calls in ZonedDateTime.p.with exposed another unnecessary user call: the 'timeZone' field was observably read from the receiver and from the object returned from mergeFields(), but never used. This is fixed as well. Closes: #2462
f35fc58
to
7aaab13
Compare
This change achieved consensus at the 2023-01-31 TC39 plenary meeting. Test262 PR has been merged already. |
Changes to the order of observable operations in
Swapping the PrepareTemporalFields calls in ZonedDateTime.p.with exposed another unnecessary user call: the 'timeZone' field was observably read from the receiver and from the object returned from mergeFields(), but never used. This is fixed as well.
Closes: #2462