1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:57:35 +00:00

LibJS: Make PromiseCapability GC-allocated

A struct with three raw pointers to other GC'd types is a pretty big
liability, let's just turn this into a Cell itself.
This comes with the additional benefit of being able to capture it in
a lambda effortlessly, without having to create handles for individual
members.
This commit is contained in:
Linus Groh 2022-10-02 12:11:30 +01:00
parent 0585029c30
commit fc9d587e39
29 changed files with 243 additions and 217 deletions

View file

@ -147,7 +147,7 @@ JS::NonnullGCPtr<JS::Promise> consume_body(JS::Realm& realm, BodyMixin const& ob
// 1. If object is unusable, then return a promise rejected with a TypeError.
if (object.is_unusable()) {
auto promise_capability = WebIDL::create_rejected_promise(realm, JS::TypeError::create(realm, "Body is unusable"sv));
return static_cast<JS::Promise&>(*promise_capability.promise);
return verify_cast<JS::Promise>(*promise_capability->promise().ptr());
}
// 2. Let promise be a promise resolved with an empty byte sequence.

View file

@ -40,7 +40,7 @@ WebIDL::ExceptionOr<Body> Body::clone() const
}
// https://fetch.spec.whatwg.org/#fully-reading-body-as-promise
JS::PromiseCapability Body::fully_read_as_promise() const
JS::NonnullGCPtr<JS::PromiseCapability> Body::fully_read_as_promise() const
{
auto& vm = Bindings::main_thread_vm();
auto& realm = *vm.current_realm();

View file

@ -31,7 +31,7 @@ public:
[[nodiscard]] WebIDL::ExceptionOr<Body> clone() const;
[[nodiscard]] JS::PromiseCapability fully_read_as_promise() const;
[[nodiscard]] JS::NonnullGCPtr<JS::PromiseCapability> fully_read_as_promise() const;
private:
// https://fetch.spec.whatwg.org/#concept-body-stream