mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:17: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:
parent
0585029c30
commit
fc9d587e39
29 changed files with 243 additions and 217 deletions
|
@ -36,10 +36,10 @@ ThrowCompletionOr<Object*> promise_resolve(VM& vm, Object& constructor, Value va
|
|||
auto promise_capability = TRY(new_promise_capability(vm, &constructor));
|
||||
|
||||
// 3. Perform ? Call(promiseCapability.[[Resolve]], undefined, « x »).
|
||||
(void)TRY(call(vm, *promise_capability.resolve, js_undefined(), value));
|
||||
(void)TRY(call(vm, *promise_capability->resolve(), js_undefined(), value));
|
||||
|
||||
// 4. Return promiseCapability.[[Promise]].
|
||||
return promise_capability.promise;
|
||||
return promise_capability->promise().ptr();
|
||||
}
|
||||
|
||||
Promise* Promise::create(Realm& realm)
|
||||
|
@ -288,7 +288,7 @@ void Promise::trigger_reactions() const
|
|||
}
|
||||
|
||||
// 27.2.5.4.1 PerformPromiseThen ( promise, onFulfilled, onRejected [ , resultCapability ] ), https://tc39.es/ecma262/#sec-performpromisethen
|
||||
Value Promise::perform_then(Value on_fulfilled, Value on_rejected, Optional<PromiseCapability> result_capability)
|
||||
Value Promise::perform_then(Value on_fulfilled, Value on_rejected, GCPtr<PromiseCapability> result_capability)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
|
@ -377,7 +377,7 @@ Value Promise::perform_then(Value on_fulfilled, Value on_rejected, Optional<Prom
|
|||
m_is_handled = true;
|
||||
|
||||
// 13. If resultCapability is undefined, then
|
||||
if (!result_capability.has_value()) {
|
||||
if (result_capability == nullptr) {
|
||||
// a. Return undefined.
|
||||
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / perform_then()]: No result PromiseCapability, returning undefined", this);
|
||||
return js_undefined();
|
||||
|
@ -385,9 +385,8 @@ Value Promise::perform_then(Value on_fulfilled, Value on_rejected, Optional<Prom
|
|||
|
||||
// 14. Else,
|
||||
// a. Return resultCapability.[[Promise]].
|
||||
auto* promise = result_capability.value().promise;
|
||||
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / perform_then()]: Returning Promise @ {} from result PromiseCapability @ {}", this, promise, &result_capability.value());
|
||||
return promise;
|
||||
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / perform_then()]: Returning Promise @ {} from result PromiseCapability @ {}", this, result_capability->promise().ptr(), result_capability.ptr());
|
||||
return result_capability->promise();
|
||||
}
|
||||
|
||||
void Promise::visit_edges(Cell::Visitor& visitor)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue