Skip to content
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

Audit of user code calls, part 1 #2645

Merged
merged 7 commits into from
Aug 16, 2023
Merged

Audit of user code calls, part 1 #2645

merged 7 commits into from
Aug 16, 2023

Conversation

ptomato
Copy link
Collaborator

@ptomato ptomato commented Aug 11, 2023

#2519 is a large pull request that touches everything, and it's difficult to keep rebasing it while I work on the test coverage. I'd like to split it into parts, instead, and land each part as soon as the test coverage is ready. This first part consists of commits that already have complete test coverage, in tc39/test262#3894.

These commits have already been reviewed in #2519. The only change aside from rebasing them was to address Richard's comment about the order in which ToTemporalOverflow is called in the "Normative: Copy options object..." commits.

@codecov
Copy link

codecov bot commented Aug 11, 2023

Codecov Report

Merging #2645 (dc7a33b) into main (27e0452) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

❗ Current head dc7a33b differs from pull request most recent head bef16c9. Consider uploading reports for the commit bef16c9 to get more accurate results

@@            Coverage Diff             @@
##             main    #2645      +/-   ##
==========================================
- Coverage   96.06%   96.04%   -0.03%     
==========================================
  Files          20       20              
  Lines       11594    11584      -10     
  Branches     2192     2195       +3     
==========================================
- Hits        11138    11126      -12     
- Misses        393      395       +2     
  Partials       63       63              
Files Changed Coverage Δ
polyfill/lib/calendar.mjs 86.78% <100.00%> (-0.07%) ⬇️
polyfill/lib/ecmascript.mjs 98.38% <100.00%> (-0.06%) ⬇️
polyfill/lib/plaindate.mjs 99.67% <100.00%> (ø)
polyfill/lib/plaindatetime.mjs 97.23% <100.00%> (-0.02%) ⬇️
polyfill/lib/plainmonthday.mjs 97.50% <100.00%> (ø)
polyfill/lib/plainyearmonth.mjs 98.27% <100.00%> (ø)
polyfill/lib/zoneddatetime.mjs 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Copy link
Collaborator

@justingrant justingrant left a comment

Choose a reason for hiding this comment

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

I had one question about SnapshotOwnProperties, otherwise looks great.

Good idea to split up this monster PR.

spec/instant.html Outdated Show resolved Hide resolved
If we convert an exact time into a PlainDateTime, we're already
calculating the time zone's UTC offset for that exact time. In the case
where we need the UTC offset for another purpose in the same method, we
should not call the time zone method again to recalculate it. Instead, we
call the getOffsetNanosecondsFor method once, and pass the result to the
GetPlainDateTimeFor abstract operation.

This affects the following methods, removing an observable property Get
and observable Call to getOffsetNanosecondsFor:
- Temporal.Instant.prototype.toString
- Temporal.ZonedDateTime.prototype.toString
- Temporal.ZonedDateTime.prototype.round
- Temporal.ZonedDateTime.prototype.getISOFields
Time units are no longer included in the array passed as the argument of
Calendar.p.fields(). (And as long as we're doing this, we may as well
limit fields() so that it doesn't accept time units. They are never used.)

This doesn't eliminate any user-visible calls by itself, but is a
prerequisite for eliminating the visible Gets of time unit properties on
the receiver of PlainDateTime.p.with() and ZonedDateTime.p.with().
In PlainDateTime.p.with() and ZonedDateTime.p.with(), avoid calling the
property getters to obtain the values for the time units, since they do
not need to go through the calendar; we can unobservably get the same
values from the receiver's internal slots.

In ZonedDateTime.p.with(), additionally we don't need to call the getter
for the `offset` property. Since we have the offset nanoseconds already,
we can do what the getter does and format an offset string with
FormatTimeZoneOffsetString.
…with()

Instead of calling PrepareTemporalFields on the receiver in
ZonedDateTime.p.with() to get the values of the date units, first create
a PlainDateTime from the ZonedDateTime's exact time and time zone, and
call PrepareTemporalFields on that.

This still calls the corresponding calendar method for each field, but
avoids calling the time zone's getOffsetNanosecondsFor() method
redundantly for each field.
Following the precedent set in #2447, if we're going to pass the options
object to a calendar method we should make a copy of it. Also flatten the
'options' property once it's read and converted to a string in
InterpretTemporalDateTimeFields, so that it doesn't have to be observably
converted to a string again in Calendar.p.dateFromFields().

In PlainDateTime.from, delay validation of the options until after
validation of the ISO string, for consistency with ZonedDateTime.from and
in accordance with our general principle of validating arguments in order.

This affects the following APIs, which are all callers of
InterpretTemporalDateTimeFields:
- Temporal.PlainDateTime.from()
- Temporal.PlainDateTime.prototype.with()
- Temporal.ZonedDateTime.from()
- Temporal.ZonedDateTime.prototype.with()

It does not affect ToRelativeTemporalObject, even though that also calls
InterpretTemporalDateTimeFields, because it does not take an options
object from userland.
…m,p.with}

Also following the precedent set in #2447, this preserves consistency with
analogous from/with operations in {Plain,Zoned}DateTime that need to read
the overflow option twice in order to deal with time and date units
separately.
@ptomato ptomato force-pushed the user-code-calls-part-1 branch from dc7a33b to bef16c9 Compare August 16, 2023 21:52
@ptomato ptomato merged commit 04f9544 into main Aug 16, 2023
@ptomato ptomato deleted the user-code-calls-part-1 branch August 16, 2023 21:58
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