Bug 262743 - Have the ability to dispatch NativePromise directly to an EventLoop
Summary: Have the ability to dispatch NativePromise directly to an EventLoop
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jean-Yves Avenard [:jya]
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-10-05 15:59 PDT by Jean-Yves Avenard [:jya]
Modified: 2023-10-05 16:04 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Yves Avenard [:jya] 2023-10-05 15:59:05 PDT
Currently, a NativePromise takes a SerialFunctionDispatcher.

There are cases where we want when the NativePromise settle to resolve the DOMPromise on a particular event loop.

Right now, this requires to call `queueTaskKeepingObjectAlive` within the resolve/reject callback like so
https://searchfox.org/wubkat/rev/ba90462eb61f1fb629a567d01716a8e20c261060/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp#303-318

```
    p->whenSettled(RunLoop::main(), [this, activity = makePendingActivity(*this), successCallback = WTFMove(successCallback), errorCallback = WTFMove(errorCallback), promise = WTFMove(promise)] (DecodingTaskPromise::Result&& result) mutable {
        queueTaskKeepingObjectAlive(*this, TaskSource::InternalAsyncTask, [successCallback = WTFMove(successCallback), errorCallback = WTFMove(errorCallback), promise = WTFMove(promise), result = WTFMove(result)]() mutable {
            if (!result) {
                if (promise)
                    promise.value()->reject(Exception { result.error(), "Decoding failed"_s });
                if (errorCallback)
                    errorCallback->handleEvent(nullptr);
                return;
            }
            auto audioBuffer = WTFMove(result.value());
            if (promise)
                promise.value()->resolve<IDLInterface<AudioBuffer>>(audioBuffer.get());
            if (successCallback)
                successCallback->handleEvent(audioBuffer.ptr());
        });
    });
```
`
Ideally, you would be able to get a ref-counted SerialFunctionDispatcher from the ActiveDOMOBject where the dispatch method would perform the same as `queueTaskKeepingObjectAlive` (wrap the dispatched runnable into a EventLoopTask and dispatch it.
Comment 1 Radar WebKit Bug Importer 2023-10-05 16:04:01 PDT
<rdar://problem/116548105>