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 index checking for Integer-Indexed exotic objects #1752

Merged
merged 1 commit into from
Oct 30, 2019

Conversation

syg
Copy link
Contributor

@syg syg commented Oct 24, 2019

This refactor was prompted by the confusing -0 check in Integer-Indexed exotic objects' [[DefineOwnProperty]] trap. Usually the index validity checking is done in IntegerIndexedElementGet and IntegerIndexedElementSet, but that trap does some extra checks because it might not fall through to IntegerIndexedElementSet due to a non-data property descriptor.

@syg syg requested review from ljharb and bakkot October 24, 2019 00:55
@anba
Copy link
Contributor

anba commented Oct 24, 2019

The index check in [[DefineOwnProperty]] must be kept at the same position, otherwise this is a normative change, because the ToNumber/ToBigInt conversion in IntegerIndexedElementSet is observable.

@syg
Copy link
Contributor Author

syg commented Oct 25, 2019 via email

@syg syg force-pushed the editorial-ta-neg-zero branch from 6771108 to e1a23f9 Compare October 25, 2019 03:40
@syg
Copy link
Contributor Author

syg commented Oct 25, 2019

Addressed review.

@syg syg force-pushed the editorial-ta-neg-zero branch 2 times, most recently from 2da977e to 82a6d7d Compare October 25, 2019 23:16
@ljharb ljharb requested a review from jmdyck October 26, 2019 05:52
@ljharb ljharb self-assigned this Oct 26, 2019
Copy link
Collaborator

@jmdyck jmdyck left a comment

Choose a reason for hiding this comment

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

The copy-paste error in the attributes of the new <emu-clause> tag needs to be fixed. The other stuff is optional.

It looks like a correct refactoring to me.

spec.html Outdated
Comment on lines 9473 to 9474
1. Assert: Type(_index_) is Number.
1. Assert: _O_ is an Integer-Indexed exotic object.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would make more sense to have the parameter-asserts in the same order as the parameters. (Despite that IntegerIndexedElementGet/Set have them in the above order.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll reorder all the relevant asserts.

@syg syg force-pushed the editorial-ta-neg-zero branch from 82a6d7d to c6cce63 Compare October 28, 2019 18:51
<emu-alg>
1. Assert: _O_ is an Integer-Indexed exotic object.
1. Assert: Type(_index_) is Number.
1. If IsInteger(_index_) is *false*, return *false*.
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. If IsInteger(_index_) is *false*, return *false*.
1. If ! IsInteger(_index_) is *false*, return *false*.

1. If _index_ = *-0*, return *undefined*.
1. Let _length_ be _O_.[[ArrayLength]].
1. If _index_ &lt; 0 or _index_ &ge; _length_, return *undefined*.
1. If IsValidIntegerIndex(_O_, _index_) is *false*, return *undefined*.
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. If IsValidIntegerIndex(_O_, _index_) is *false*, return *undefined*.
1. If ! IsValidIntegerIndex(_O_, _index_) is *false*, return *undefined*.

1. If _index_ = *-0*, return *false*.
1. Let _length_ be _O_.[[ArrayLength]].
1. If _index_ &lt; 0 or _index_ &ge; _length_, return *false*.
1. If IsValidIntegerIndex(_O_, _index_) is *false*, return *false*.
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. If IsValidIntegerIndex(_O_, _index_) is *false*, return *false*.
1. If ! IsValidIntegerIndex(_O_, _index_) is *false*, return *false*.

1. If _numericIndex_ &lt; 0, return *false*.
1. Let _length_ be _O_.[[ArrayLength]].
1. If _numericIndex_ &ge; _length_, return *false*.
1. If IsValidIntegerIndex(_O_, _numericIndex_) is *false*, return *false*.
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. If IsValidIntegerIndex(_O_, _numericIndex_) is *false*, return *false*.
1. If ! IsValidIntegerIndex(_O_, _numericIndex_) is *false*, return *false*.

1. If _numericIndex_ = *-0*, return *false*.
1. If _numericIndex_ &lt; 0, return *false*.
1. If _numericIndex_ &ge; _O_.[[ArrayLength]], return *false*.
1. If IsValidIntegerIndex(_O_, _numericIndex_) is *false*, return *false*.
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. If IsValidIntegerIndex(_O_, _numericIndex_) is *false*, return *false*.
1. If ! IsValidIntegerIndex(_O_, _numericIndex_) is *false*, return *false*.

@ljharb ljharb requested a review from jmdyck October 29, 2019 05:18
@syg
Copy link
Contributor Author

syg commented Oct 30, 2019

@ljharb You know, in general I don't agree with the editorial direction that ! be prefixed on invocations of AOs that cannot throw because they do not return completion values. ! and ? telegraph to me that the AO returns a completion value, since those are shorthands for unwrapping, and I'd prefer to use ! only for an AO that can throw, but will not for that particular invocation.

That said, there is so much prior use of ! in the way I disagree with, I'll incorporate your desired changes here.

@ljharb
Copy link
Member

ljharb commented Oct 30, 2019

Every abstract op always returns a completion value, implicitly.

The drive for using ! or ? at callsites is that, otherwise, you can't possibly know if an abstract op call "can throw" or not, so the ! gives you the only info you need: either that it can't throw, or that it won't throw with these arguments. Whether it can throw in other cases isn't helpful information.

@ljharb ljharb closed this Oct 30, 2019
@ljharb ljharb reopened this Oct 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants