Closed Bug 1797724 Opened 4 years ago Closed 4 years ago

Clean-up and improve spec-compliance for Array.fromAsync

Categories

(Core :: JavaScript: Standard Library, task)

task

Tracking

()

RESOLVED FIXED
108 Branch
Tracking Status
firefox108 --- fixed

People

(Reporter: anba, Assigned: anba)

References

Details

Attachments

(10 external files)

Clean-up Array.fromAsync to use consistent error reporting compared to other iteration code (for-of loops and Array.from), change the implementation to use a for-await loop, and properly unwrap Promise values from sync iterators.

Reverts the whitespace change from the original Array.fromAsync patch.

Later patches will rearrange this code again.

Depends on D160475

Part 8 will actually remove the entire method.

Depends on D160476

Noticed this when adding a test for the next part.

Depends on D160477

This ensures Array.fromAsync uses the same error message as Array.from and
normal iteration (for-of and for-await-of).

This let's us also remove the GetIterator self-hosted function.

Also renamed asyncIterator to iterator, because the returned iterator isn't
an async iterator.

Depends on D160478

asyncFromSyncIteratorObject[ASYNC_FROM_SYNC_ITERATOR_OBJECT_ITERATOR_SLOT] is
the iterator passed to CreateAsyncFromSyncIterator(), but we actually need to
use asyncFromSyncIteratorObject for the iteratorRecord to correctly unwrap
Promise values. (Same applies for the next method.)

Depends on D160479

Change allowContentIterWith to support async iteration in preparation for the
next patch.

Depends on D160480

Change Array.fromAsync to use a for-await loop. Simplifies the code and
should ensure Array.fromAsync handles iteration similar to other async
iteration code.

Depends on D160481

Reorders steps 3.j-k to appear in the correct order and allows to remove some
empty blocks.

Depends on D160482

Inlines GetMethod to ensure we can report JSMSG_NOT_ITERABLE, similar to
normal iteration or Array.from().

Depends on D160483

Pushed by andre.bargull@gmail.com: https://hg.mozilla.org/integration/autoland/rev/b6fe2484d1d2 Part 1: Delete leading whitespace before preprocessor definitions. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/65dd948e3a52 Part 2: Use an 'else' statement to avoid an unnecessary comparison. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/f2b0dfce1304 Part 3: Avoid unnecessary rooting in intrinsic_CreateAsyncFromSyncIterator. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/bfcb3e8f4a95 Part 4: Use correct error message when 'Symbol.asyncIterator' returns a non-object. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/6eab189d4307 Part 5: Use consistent error messages when iterator method returns a non-object. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/77964262799c Part 6: Correctly use AsyncFromSyncIterator to unwrap Promise values. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/5461f671181d Part 7: Support allowContentIterWith for async iteration. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/b0f341e0cc09 Part 8: Use a for-await loop for Array.fromAsync. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/f46ce4f4052a Part 9: Reorder steps 3.j and 3.k. r=mgaudet https://hg.mozilla.org/integration/autoland/rev/8e24f1f58e0a Part 10: Ensure more consistent error reporting. r=mgaudet
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: