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

Editorial: Refactor add/subtract to common AOs #2166

Merged
merged 10 commits into from
May 5, 2022

Conversation

FrankYFTang
Copy link
Contributor

Most of the operations between add and subtract are the same except negative value. Refactor to shared AOs between them with a sign which either 1 or -1.

@FrankYFTang
Copy link
Contributor Author

@ptomato @ryzokuken

@codecov
Copy link

codecov bot commented Apr 29, 2022

Codecov Report

Merging #2166 (9f2cd69) into main (3e5ef6a) will decrease coverage by 0.02%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #2166      +/-   ##
==========================================
- Coverage   90.03%   90.00%   -0.03%     
==========================================
  Files          19       19              
  Lines       10905    10905              
  Branches     1693     1686       -7     
==========================================
- Hits         9818     9815       -3     
- Misses       1073     1076       +3     
  Partials       14       14              
Flag Coverage Δ
test262 83.48% <ø> (+0.04%) ⬆️
tests 80.57% <ø> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
polyfill/lib/duration.mjs 83.85% <0.00%> (-0.20%) ⬇️
polyfill/lib/ecmascript.mjs 95.82% <0.00%> (-0.05%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e5ef6a...9f2cd69. Read the comment docs.

1. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_).
1. Let _result_ be ? AddDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _other_.[[Years]], _other_.[[Months]], _other_.[[Weeks]], _other_.[[Days]], _other_.[[Hours]], _other_.[[Minutes]], _other_.[[Seconds]], _other_.[[Milliseconds]], _other_.[[Microseconds]], _other_.[[Nanoseconds]], _relativeTo_).
1. Return ! CreateTemporalDuration(_result_.[[Years]], _result_.[[Months]], _result_.[[Weeks]], _result_.[[Days]], _result_.[[Hours]], _result_.[[Minutes]], _result_.[[Seconds]], _result_.[[Milliseconds]], _result_.[[Microseconds]], _result_.[[Nanoseconds]]).
1. Return ! AddTemporalDuration(1, _duration_, _other_, _options_).
Copy link
Member

Choose a reason for hiding this comment

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

if all of the removed lines can throw, how come this one can't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

opps. sorry, forget to change that.

Copy link
Member

@linusg linusg left a comment

Choose a reason for hiding this comment

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

This should also be updated to reflect the changes made in #2162.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

This is great!

spec/duration.html Outdated Show resolved Hide resolved
spec/instant.html Outdated Show resolved Hide resolved
spec/plaindatetime.html Outdated Show resolved Hide resolved
spec/instant.html Outdated Show resolved Hide resolved
spec/plaintime.html Outdated Show resolved Hide resolved
spec/plainyearmonth.html Outdated Show resolved Hide resolved
spec/zoneddatetime.html Outdated Show resolved Hide resolved
@FrankYFTang FrankYFTang changed the title Editoral: Refactor add/subtract to common AOs Editorial: Refactor add/subtract to common AOs Apr 29, 2022
@FrankYFTang
Copy link
Contributor Author

PTAL

@FrankYFTang FrankYFTang requested a review from ljharb April 29, 2022 21:46
@ljharb
Copy link
Member

ljharb commented Apr 29, 2022

LGTM!

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Thanks! This looks like an improvement.

I don't think the <h1>s will render correctly unless we have type="abstract operation" in the <emu-clause> and also the <dl class="header"> element. (See https://tc39.es/ecmarkup/#emu-clause-structured-headers)

Since a description is needed in the <dl class="header"> element, I think it's probably good to make clear what the distinction is between e.g. AddTemporalInstant and AddInstant. So, for the description of AddTemporalInstant you could say something like "It implements the validation of the arguments and return value for Temporal.Instant.prototype.add and Temporal.Instant.prototype.subtract, around a call to AddInstant which performs the actual arithmetic.", etc. for the other types.

As for the -1/+1 vs enumeration, I commented on #2167 - let's see if anyone has more to say on that.

spec/duration.html Outdated Show resolved Hide resolved
spec/instant.html Outdated Show resolved Hide resolved
spec/plaindatetime.html Outdated Show resolved Hide resolved
spec/plaintime.html Outdated Show resolved Hide resolved
spec/plainyearmonth.html Outdated Show resolved Hide resolved
spec/zoneddatetime.html Outdated Show resolved Hide resolved
@FrankYFTang
Copy link
Contributor Author

ok, I correct the structure header, change to use enum and improve the readability of the AO name
PTAL

@ljharb
Copy link
Member

ljharb commented May 3, 2022

LGTM

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Thanks!

spec/duration.html Outdated Show resolved Hide resolved
spec/plaindatetime.html Outdated Show resolved Hide resolved
spec/plainyearmonth.html Outdated Show resolved Hide resolved
spec/zoneddatetime.html Outdated Show resolved Hide resolved
FrankYFTang and others added 4 commits May 4, 2022 15:12
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
@FrankYFTang FrankYFTang requested a review from ptomato May 4, 2022 22:13
Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Sorry, a couple more things that I didn't spot the first time. If you don't mind, I'll just accept these suggestions right away and merge the PR so we don't need to hold it up any longer. Thanks for working on this!

spec/plainyearmonth.html Outdated Show resolved Hide resolved
spec/plainyearmonth.html Outdated Show resolved Hide resolved
spec/plaindatetime.html Outdated Show resolved Hide resolved
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.

LGTM. Thanks!

@ptomato ptomato merged commit 2f96efc into tc39:main May 5, 2022
@FrankYFTang
Copy link
Contributor Author

sorry, my bad. Thaks @ptomato for the correction

@FrankYFTang FrankYFTang deleted the RefactorAdd branch May 5, 2022 22:24
linusg added a commit to linusg/proposal-temporal that referenced this pull request May 6, 2022
…PlainTime

This fixes a 'normative typo' introduced in tc39#2166.
Instead of passing temporalTime twice, we need to also pass
temporalDurationLike.
ptomato pushed a commit that referenced this pull request May 6, 2022
* Editorial: Rename AddTemporalPlainYearMonth to AddDurationToOrSubtractDurationFromPlainYearMonth

This AO has both addition and subtraction behavior, based on the first
argument. Update the name accordingly and bring it in line with these
similar AOs:

- AddDurationToOrSubtractDurationFromDuration
- AddDurationToOrSubtractDurationFromInstant
- AddDurationToOrSubtractDurationFromPlainDateTime
- AddDurationToOrSubtractDurationFromPlainTime
- AddDurationToOrSubtractDurationFromZonedDateTime

* Editorial: Fix rendering of 'subtract' in structured header

* Editorial: Pass correct values to AddDurationToOrSubtractDurationFromPlainTime

This fixes a 'normative typo' introduced in #2166.
Instead of passing temporalTime twice, we need to also pass
temporalDurationLike.
@ptomato ptomato added the spec-text Specification text involved label May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec-text Specification text involved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants