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: FlattenIntoArray: add assertions #1620

Merged
merged 1 commit into from
Jul 18, 2019

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Jul 10, 2019

Add some assertions to clarify the intended usage of this abstract operation.

I wanted to assert that target is an Array exotic object, but I think because of ArraySpeciesCreate I can't.

jmdyck
jmdyck previously requested changes Jul 10, 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.

I wanted to assert that _target_ is an Array exotic object, but I think because of ArraySpeciesCreate I can't.

I think you're right. That is, the result of ArraySpeciesCreate (ignoring abrupts) isn't guaranteed to be an Array (despite what its preamble says), because a subclass of Array could override its @@species property to return a non-Array constructor?

spec.html Outdated Show resolved Hide resolved
spec.html Outdated
1. Assert: Type(_source_) is Object.
1. Assert: _sourceLen_ is an integer Number ≥ 0.
1. Assert: _start_ is an integer Number ≥ 0.
1. Assert: _depth_ is an integer Number ≥ 0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

When A.p.flat invokes this operation, the value passed to _depth_ can be any normal return from ToInteger, which includes negative integers and also some odd values like +/- zero and +/- infinity. The infinities fail the "integer" part of this assertion, and the negative integers fail the ≥ 0 part. Maybe change to:

Assert: _depth_ is an integer Number or *+∞* or *-∞*.

Alternatively, A.p.flat could at least map all negatives to (positive) zero. Then you could say:

Assert: _depth_ is either *+∞* or an integer Number ≥ 0.

(Tangent: I was going to complain about _depth_ - 1 when _depth_ is +infinity, but I guess it became well-defined with the merge of PR #1135 ("an operation with no subscript is interpreted to be a Number operation"). However, it might be worth a Note.)

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, A.p.flat could at least map all negatives to (positive) zero.

I like this suggestion a lot.

@ljharb ljharb force-pushed the flattenintoarray_assertions branch 2 times, most recently from eb35757 to e893b3b Compare July 10, 2019 19:32
ljharb added a commit to ljharb/ecma262 that referenced this pull request Jul 10, 2019
@ljharb ljharb requested a review from jmdyck July 10, 2019 19:32
spec.html Outdated Show resolved Hide resolved
@ljharb ljharb force-pushed the flattenintoarray_assertions branch from e893b3b to 6136ace Compare July 11, 2019 22:41
ljharb added a commit to ljharb/ecma262 that referenced this pull request Jul 11, 2019
@ljharb ljharb requested a review from jmdyck July 11, 2019 22:41
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.

Looks okay to me.

spec.html Outdated Show resolved Hide resolved
@ljharb ljharb self-assigned this Jul 17, 2019
@ljharb ljharb force-pushed the flattenintoarray_assertions branch from 6136ace to 4bac90f Compare July 18, 2019 06:21
@ljharb ljharb merged commit 4bac90f into tc39:master Jul 18, 2019
@ljharb ljharb deleted the flattenintoarray_assertions branch July 18, 2019 06:22
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