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: Consolidate GetOption usage #1531

Merged
merged 1 commit into from
Jun 8, 2021
Merged

Editorial: Consolidate GetOption usage #1531

merged 1 commit into from
Jun 8, 2021

Conversation

ptomato
Copy link
Collaborator

@ptomato ptomato commented Jun 4, 2021

Under the assumption that it's not a priority to move GetNumberOption
directly from ECMA-402 into ECMA-262, reorganize the GetOption operations:

  • Change the type string argument to GetOption, into a List of valid
    types, the last one of which will be coerced to if the value is none of
    them (and also not undefined).

  • In the Number case, call ToNumber on the value and throw if it is NaN.

  • Inline GetNumberOption as it's only called once.

  • Call GetOption in GetStringOrNumberOption.

  • Don't delete GetOption, GetNumberOption, and DefaultNumberOption from
    402, as they won't be replaced by anything in 262 at present.

Includes a fix to make the polyfill spec-compliant, and test262 tests
covering usages of GetOption (there are quite a lot of them.)

Closes: #1411

@ptomato ptomato requested a review from Ms2ger June 4, 2021 00:03
@ptomato
Copy link
Collaborator Author

ptomato commented Jun 4, 2021

This is the promised follow up from #1505. The spec text is identical to what was reviewed there. What has changed is a bug fix to make the polyfill spec-compliant, and the addition of all the test262 tests.

@codecov
Copy link

codecov bot commented Jun 4, 2021

Codecov Report

Merging #1531 (fc8547f) into main (2c8aa80) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head fc8547f differs from pull request most recent head 1f92033. Consider uploading reports for the commit 1f92033 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1531   +/-   ##
=======================================
  Coverage   95.64%   95.64%           
=======================================
  Files          19       19           
  Lines       10923    10927    +4     
  Branches     1715     1717    +2     
=======================================
+ Hits        10447    10451    +4     
  Misses        465      465           
  Partials       11       11           
Flag Coverage Δ
test262 70.63% <100.00%> (+0.68%) ⬆️
tests 91.61% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
polyfill/lib/ecmascript.mjs 95.17% <100.00%> (+<0.01%) ⬆️

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 2c8aa80...1f92033. Read the comment docs.

spec/abstractops.html Outdated Show resolved Hide resolved
spec/abstractops.html Outdated Show resolved Hide resolved
spec/abstractops.html Outdated Show resolved Hide resolved
1. Return ? DefaultNumberOption(_value_, _minimum_, _maximum_, _fallback_).
</emu-alg>
</emu-clause>

<emu-clause id="sec-getstringornumberoption" aoid="GetStringOrNumberOption">
<h1>GetStringOrNumberOption ( _options_, _property_, _stringValues_, _minimum_, _maximum_, _fallback_ )</h1>
Copy link
Member

Choose a reason for hiding this comment

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

there doesn't appear to be an assertion (in prose, or in the steps) that minimum and maximum is a Number, but without that assertion, the comparison to value would be incoherent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In #1413 it seems to be suggested that comparisons should be done on mathematical values, so I'll sort this out there.

spec/abstractops.html Outdated Show resolved Hide resolved
@@ -266,7 +240,9 @@ <h1>ToTemporalRoundingIncrement ( _normalizedOptions_, _dividend_, _inclusive_ )
1. Let _maximum_ be _dividend_ − 1.
1. Else,
1. Let _maximum_ be 1.
1. Let _increment_ be ? GetNumberOption(_normalizedOptions_, *"roundingIncrement"*, 1, _maximum_, 1).
1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, « Number », *undefined*, 1).
1. If _increment_ &lt; 1 or _increment_ &gt; _maximum_, throw a *RangeError* exception.
Copy link
Member

Choose a reason for hiding this comment

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

this also lacks an assertion that dividend is a Number (thus ensuring maximum is a Number), but also, 1 is a mathemetical value.

In other words, a series of assertions/conversions is required here so the number types are the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd rather do this as part of #1413, to keep the scope of this change from expanding more than it already has...

@@ -266,7 +240,9 @@ <h1>ToTemporalRoundingIncrement ( _normalizedOptions_, _dividend_, _inclusive_ )
1. Let _maximum_ be _dividend_ − 1.
1. Else,
1. Let _maximum_ be 1.
1. Let _increment_ be ? GetNumberOption(_normalizedOptions_, *"roundingIncrement"*, 1, _maximum_, 1).
1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, « Number », *undefined*, 1).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, « Number », *undefined*, 1).
1. Let _increment_ be ℝ(? GetOption(_normalizedOptions_, *"roundingIncrement"*, « Number », *undefined*, 1)).

perhaps? this way the comparisons below can be to mathematical values instead of to Numbers

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Likewise, I'll sort this out in #1413.

Under the assumption that it's not a priority to move GetNumberOption
directly from ECMA-402 into ECMA-262, reorganize the GetOption operations:

- Change the _type_ string argument to GetOption, into a List of valid
  types, the last one of which will be coerced to if the value is none of
  them (and also not undefined).

- In the Number case, call ToNumber on the value and throw if it is NaN.

- Inline GetNumberOption as it's only called once.

- Call GetOption in GetStringOrNumberOption.

- Don't delete GetOption, GetNumberOption, and DefaultNumberOption from
  402, as they won't be replaced by anything in 262 at present.

Includes a fix to make the polyfill spec-compliant, and test262 tests
covering usages of GetOption (there are quite a lot of them.)

Closes: #1411
@ptomato ptomato force-pushed the 1411-get-option branch from bb125ef to 1f92033 Compare June 4, 2021 17:28
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.

spec LGTM; #1413 can handle making the number stuff coherent

@ptomato ptomato merged commit 4b5f104 into main Jun 8, 2021
@ptomato ptomato deleted the 1411-get-option branch June 8, 2021 15:51
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.

editor review: misc
3 participants