Skip to content

Conversation

@anonrig
Copy link
Member

@anonrig anonrig commented Dec 29, 2025

This change fixes 3 edge cases in ReadableStream.from cancel behavior.

  1. When iterator's return property exists but is not callable, cancel now rejects with TypeError.
  2. When return rejects, the rejection is now propagated directly without calling throw on the iterator.
  3. When return fulfills with a non-object, the error is now properly propagated.

@anonrig anonrig requested a review from jasnell December 29, 2025 19:54
@anonrig anonrig requested review from a team as code owners December 29, 2025 19:54
@github-actions
Copy link

github-actions bot commented Dec 29, 2025

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@anonrig anonrig force-pushed the yagiz/fix-cancel-wpt branch from 770b7d6 to b25e45c Compare December 29, 2025 20:11
@jasnell
Copy link
Collaborator

jasnell commented Dec 29, 2025

The plan is to eventually add a default-on date for pedanticWpt, we're just not there yet.

Copy link
Collaborator

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

I believe this should be addressed in the impl of return_(...) more generally rather than being specific to ReadableStream.from().

@anonrig anonrig force-pushed the yagiz/fix-cancel-wpt branch from 6fd01d4 to 59907b7 Compare December 29, 2025 23:19
@jasnell
Copy link
Collaborator

jasnell commented Dec 29, 2025

It would be good to update the generator tests directly in addition to just enabling the streams related wpts.

@anonrig anonrig force-pushed the yagiz/fix-cancel-wpt branch from 59907b7 to c041446 Compare December 30, 2025 15:19
@anonrig anonrig enabled auto-merge December 30, 2025 15:19
@anonrig
Copy link
Member Author

anonrig commented Dec 30, 2025

@jasnell please take a look, i've addressed your review

Co-authored-by: James M Snell <jsnell@cloudflare.com>
Co-authored-by: James M Snell <jsnell@cloudflare.com>
Co-authored-by: James M Snell <jsnell@cloudflare.com>
Co-authored-by: James M Snell <jsnell@cloudflare.com>
anonrig and others added 3 commits December 30, 2025 10:27
Co-authored-by: James M Snell <jsnell@cloudflare.com>
Co-authored-by: James M Snell <jsnell@cloudflare.com>
Co-authored-by: James M Snell <jsnell@cloudflare.com>
maybeThrow(tryGetGeneratorFunction<ThrowSignature, TypeWrapper>(js, object, "throw"_kj)) {
// Check if return property exists but isn't callable (per GetMethod spec)
returnExistsButNotCallable =
maybeReturn == kj::none && !object.get(js, "return"_kj).isNullOrUndefined();
Copy link
Collaborator

@jasnell jasnell Dec 30, 2025

Choose a reason for hiding this comment

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

This is a bit non-obvious. The variable is called ...NotCallable but it's being set with a call to isNullOrUndefined. This could use a bit more explanation to be clearer explaining that if return is not a function, maybeReturn will be kj::none and that the additional check here is just an indicator of whether the property actually existed or not (using a has(...) might be better if we keep this check to avoid the additional handle creation?).

Also, the fact that the return property is being looked up twice is rather unfortunate, especially given that the lookup could have side effects in some edge cases and subsequent accesses are not necessarily always guaranteed to yield the same value.

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.

3 participants