-
Notifications
You must be signed in to change notification settings - Fork 510
fix ReadableStream.from() cancel behavior per WPT spec #5794
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
c041446
d62fb77
b706464
c8c314b
d19b8f2
723a48a
e42d5b9
807915e
f39c0c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -205,8 +205,17 @@ class AsyncGenerator final { | |
| } | ||
|
|
||
| // If nothing is returned, the generator is complete. | ||
| // Per GetMethod spec (https://262.ecma-international.org/#sec-getmethod), if the 'return' | ||
| // property exists but is not callable, we throw a TypeError. | ||
| Promise<kj::Maybe<T>> return_(Lock& js, kj::Maybe<T> maybeValue = kj::none) { | ||
| KJ_IF_SOME(active, maybeActive) { | ||
| // Per GetMethod spec: if property exists but is not callable, throw TypeError | ||
| if (active.returnExistsButNotCallable) { | ||
| maybeActive = kj::none; | ||
| return js.rejectedPromise<kj::Maybe<T>>( | ||
| js.typeError("property 'return' is not a function"_kj)); | ||
anonrig marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| KJ_IF_SOME(return_, active.maybeReturn) { | ||
| auto& selfRef = KJ_ASSERT_NONNULL(maybeSelfRef); | ||
| return js.tryCatch([&] { | ||
|
|
@@ -217,17 +226,13 @@ class AsyncGenerator final { | |
| } | ||
| return js.resolvedPromise(kj::mv(result.value)); | ||
| }, [ref = selfRef.addRef()](Lock& js, Value exception) { | ||
| Promise<kj::Maybe<T>> retPromise = nullptr; | ||
| if (ref->runIfAlive([&](AsyncGenerator& self) { | ||
| retPromise = self.throw_(js, kj::mv(exception)); | ||
| })) { | ||
| return kj::mv(retPromise); | ||
| } | ||
| // Per spec, rejections from return() should be propagated directly | ||
| ref->runIfAlive([&](AsyncGenerator& self) { self.maybeActive = kj::none; }); | ||
| return js.rejectedPromise<kj::Maybe<T>>(kj::mv(exception)); | ||
| }); | ||
| }, [&](Value exception) { | ||
| maybeActive = kj::none; | ||
| return throw_(js, kj::mv(exception)); | ||
| return js.rejectedPromise<kj::Maybe<T>>(kj::mv(exception)); | ||
| }); | ||
| } | ||
| maybeActive = kj::none; | ||
|
|
@@ -276,13 +281,19 @@ class AsyncGenerator final { | |
| kj::Maybe<NextSignature> maybeNext; | ||
| kj::Maybe<ReturnSignature> maybeReturn; | ||
| kj::Maybe<ThrowSignature> maybeThrow; | ||
| // Per GetMethod spec, if property exists but is not callable, we should throw TypeError. | ||
| // We track this state to defer the error to when return_() is actually called. | ||
| bool returnExistsButNotCallable = false; | ||
|
|
||
| template <typename TypeWrapper> | ||
| Active(Lock& js, JsObject object, TypeWrapper*) | ||
| : maybeNext(tryGetGeneratorFunction<NextSignature, TypeWrapper>(js, object, "next"_kj)), | ||
| maybeReturn( | ||
| tryGetGeneratorFunction<ReturnSignature, TypeWrapper>(js, object, "return"_kj)), | ||
| 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(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit non-obvious. The variable is called Also, the fact that the |
||
| } | ||
| Active(Active&&) = default; | ||
| Active& operator=(Active&&) = default; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.