-
Notifications
You must be signed in to change notification settings - Fork 158
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: Get the month from the internal result directly #1673
Conversation
Since the step 4 stement in CalendarDateUntil is 4. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). _untilResult_ is guarantee to be a TemporalDuration object and there are no need to call Get - which could return any kind of values, but only need to acecss [[Months]] which is guarantee for certain type and range.
I think this Editoral change @ptomato @jugglinmike @ljharb @justingrant Is it correct? |
Codecov Report
@@ Coverage Diff @@
## main #1673 +/- ##
==========================================
- Coverage 95.02% 91.09% -3.94%
==========================================
Files 19 17 -2
Lines 10778 10768 -10
Branches 1725 1608 -117
==========================================
- Hits 10242 9809 -433
- Misses 523 945 +422
- Partials 13 14 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
CalendarDateUntil ensures the result has the [[InitializedTemporalDuration]] slot, so theoretically that’s always something with a [[Months]] slot. However, since this calls user code, it could return an object with a [[Months]] slot but that has a .months property/accessor that provides a different value - so i think this is actually both normative, and hostile to subclassing? |
you are right! It is a normative change. I think what I think is this access should NOT need to be observable but it is now observable via Get. But if we look at other places in the Temporal after calling CalendarDateUntil, we always use direct access in the following places in stead of Get() . so unlike there is a very good reason we like to let the Calendar to observe such access, we may want to change this place like other places with direct access to internal slot.
|
I mean, the good reason is so subclasses can’t override the months value. Implementations can of course optimize the current spec to an internal slot access when they know that the object has the native months getter, so I’m not sure what the value is of removing the subclassing hook In other words, if there’s a chance that the other places using the slot should be doing a Get, perhaps those should be changed to a Get instead? |
Actually the origional reason I disconvered this is not becaue I like to have direct access but I realize after the Get, there are no type/range checking before treating it as numeric value. I was intending to file a fix for that but then I realize maybe the right way is to directly access the internal slot since the CalendarDateUntil already gunarantee it has those values in the internal slot in the correct type/range. We do need range/type check and throw we call Get. Direct access won't need those. But if we want to keep using the Get(), I believe we should
7.5.11 UnbalanceDurationRelative ( years, months, weeks, days, largestUnit, relativeTo )
what is the result of months after ix. if Get return non numeric value? (undefind, String, Symbol, etc) 7.5.12 BalanceDurationRelative ( years, months, weeks, days, largestUnit, relativeTo )
What is abs of non numeric value? (undefind, String, Symbol, etc) and the resul tof months... The subclass could return value other than what is stored in [[Months]] right? therefore it could any kind of values. So if we really want to let subclass of Duration to return differnt value, we need to range/type check and convert after the Get, right? |
I would expect typechecking after the Get, certainly. I agree it makes sense to have consistent treatment here - either always get the fields and typecheck/coerce, or always read the slots. I assume the temporal champions have an overarching ethos here and the inconsistency is an oversight, but i don’t know which matches their intention. |
It looks like this partly overlaps with #1616 which was already on the queue for normative changes. Would it be possible to add a test for these other instances?
Indeed, this was an oversight. The intention was to always read the slots. (See #231). Subclasses of Temporal.Duration could still override the |
(Converted to draft so the normative change isn't accidentally merged without consensus) |
I've copied this one over to #1616 since they are very similar, and added tests there, so closing. (Less work for delegates to review) |
thanks |
Since the step 4 stement in CalendarDateUntil is
4. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
untilResult is guarantee to be a TemporalDuration object and there are no need to call Get - which could return any kind of values, but
only need to acecss [[Months]] which is guarantee for certain type and range.