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

from(): Close synchronous iterators properly #192

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

domfarolino
Copy link
Collaborator

@domfarolino domfarolino commented Jan 27, 2025

This PR fixes Observable.from()'s synchronous iteration to respond to aborted signals properly, and close the iterator accordingly. Upon subscription, this PR adds checks to see whether the subscriber's signal is aborted:

  1. The first is initially upon subscription. Consistent with Chromium implementation and tests (tests are being modified here).
  2. The second is after the iterator is obtained, since this runs script and therefore could conceivably abort the subscription. This is consistent with the Chromium implementation and tests (tests are being modified here).
  3. During the iteration, after a value has been pulled out and reported via Subscriber#next(), but before the next iteration starts. This is consistent with the Chromium implementation and tests.

Furthermore, after the two checks, the subscription algorithm to run the IteratorRecord's "return" function is also added to the signal. This is also consistent with the Chromium implementation and tested by the above tests.


Preview | Diff

@domfarolino domfarolino merged commit 8a8c950 into master Jan 27, 2025
2 checks passed
@domfarolino domfarolino deleted the from-iterable-respect-signal branch January 27, 2025 18:56
github-actions bot added a commit that referenced this pull request Jan 27, 2025
SHA: 8a8c950
Reason: push, by domfarolino

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
aarongable pushed a commit to chromium/chromium that referenced this pull request Jan 28, 2025
This CL adds and supplements a few tests:

  1. First we modify the existing "subscribe with aborted signal" tests.
     Specifically, we expand their assertions to not only assert that
     `next()` isn't ever called, but make more assertions about the
     iterator protocol getter and function invocations in general.
  2. Second, we modify the test that asserts `next()` is not called
     when you subscribe with an unaborted signal, but that signal gets
     aborted while the iterator protocol methods are called during
     subscription of the Observable. We expand the assertions in the
     same way as (1), and combine the two separate tests into one that
     covers both sync and async iterators, also to match (1).
  3. Finally, this CL adds a sync iterable version of the test added in
     https://crrev.com/c/6199630. The test scenario is: you subscribe to
     a sync iterable with an unaborted signal that gets aborted while
     obtaining the iterator (just like (2)), BUT while getting the
     iterator, an error is thrown. The tests asserts that the error is
     reported to the global before we consult the aborted signal and
     stop the subscription process. This ensures that the exception is
     not swallowed, but is appropriately surfaced, even though the
     subscription is aborted.

This corresponds with the spec PR:
WICG/observable#192.

R=masonf

Bug: 363015168
Change-Id: Ida605c49a2d73cd407a9dc3c392d6b2f338855be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6202182
Commit-Queue: Dominic Farolino <[email protected]>
Reviewed-by: Mason Freed <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1412315}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jan 28, 2025
This CL adds and supplements a few tests:

  1. First we modify the existing "subscribe with aborted signal" tests.
     Specifically, we expand their assertions to not only assert that
     `next()` isn't ever called, but make more assertions about the
     iterator protocol getter and function invocations in general.
  2. Second, we modify the test that asserts `next()` is not called
     when you subscribe with an unaborted signal, but that signal gets
     aborted while the iterator protocol methods are called during
     subscription of the Observable. We expand the assertions in the
     same way as (1), and combine the two separate tests into one that
     covers both sync and async iterators, also to match (1).
  3. Finally, this CL adds a sync iterable version of the test added in
     https://crrev.com/c/6199630. The test scenario is: you subscribe to
     a sync iterable with an unaborted signal that gets aborted while
     obtaining the iterator (just like (2)), BUT while getting the
     iterator, an error is thrown. The tests asserts that the error is
     reported to the global before we consult the aborted signal and
     stop the subscription process. This ensures that the exception is
     not swallowed, but is appropriately surfaced, even though the
     subscription is aborted.

This corresponds with the spec PR:
WICG/observable#192.

R=masonf

Bug: 363015168
Change-Id: Ida605c49a2d73cd407a9dc3c392d6b2f338855be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6202182
Commit-Queue: Dominic Farolino <[email protected]>
Reviewed-by: Mason Freed <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1412315}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jan 28, 2025
This CL adds and supplements a few tests:

  1. First we modify the existing "subscribe with aborted signal" tests.
     Specifically, we expand their assertions to not only assert that
     `next()` isn't ever called, but make more assertions about the
     iterator protocol getter and function invocations in general.
  2. Second, we modify the test that asserts `next()` is not called
     when you subscribe with an unaborted signal, but that signal gets
     aborted while the iterator protocol methods are called during
     subscription of the Observable. We expand the assertions in the
     same way as (1), and combine the two separate tests into one that
     covers both sync and async iterators, also to match (1).
  3. Finally, this CL adds a sync iterable version of the test added in
     https://crrev.com/c/6199630. The test scenario is: you subscribe to
     a sync iterable with an unaborted signal that gets aborted while
     obtaining the iterator (just like (2)), BUT while getting the
     iterator, an error is thrown. The tests asserts that the error is
     reported to the global before we consult the aborted signal and
     stop the subscription process. This ensures that the exception is
     not swallowed, but is appropriately surfaced, even though the
     subscription is aborted.

This corresponds with the spec PR:
WICG/observable#192.

R=masonf

Bug: 363015168
Change-Id: Ida605c49a2d73cd407a9dc3c392d6b2f338855be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6202182
Commit-Queue: Dominic Farolino <[email protected]>
Reviewed-by: Mason Freed <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1412315}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jan 31, 2025
… a=testonly

Automatic update from web-platform-tests
DOM: Add more Observable iterable tests

This CL adds and supplements a few tests:

  1. First we modify the existing "subscribe with aborted signal" tests.
     Specifically, we expand their assertions to not only assert that
     `next()` isn't ever called, but make more assertions about the
     iterator protocol getter and function invocations in general.
  2. Second, we modify the test that asserts `next()` is not called
     when you subscribe with an unaborted signal, but that signal gets
     aborted while the iterator protocol methods are called during
     subscription of the Observable. We expand the assertions in the
     same way as (1), and combine the two separate tests into one that
     covers both sync and async iterators, also to match (1).
  3. Finally, this CL adds a sync iterable version of the test added in
     https://crrev.com/c/6199630. The test scenario is: you subscribe to
     a sync iterable with an unaborted signal that gets aborted while
     obtaining the iterator (just like (2)), BUT while getting the
     iterator, an error is thrown. The tests asserts that the error is
     reported to the global before we consult the aborted signal and
     stop the subscription process. This ensures that the exception is
     not swallowed, but is appropriately surfaced, even though the
     subscription is aborted.

This corresponds with the spec PR:
WICG/observable#192.

R=masonf

Bug: 363015168
Change-Id: Ida605c49a2d73cd407a9dc3c392d6b2f338855be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6202182
Commit-Queue: Dominic Farolino <[email protected]>
Reviewed-by: Mason Freed <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1412315}

--

wpt-commits: ea15691f277a5e965d90f9c0167638559ff62f0d
wpt-pr: 50338
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.

1 participant