1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 10:01:13 +09:00
ladybird/Userland/Libraries/LibWeb/WebAudio/OfflineAudioContext.h
Andrew Kaster 2c3531ab78 LibWeb: Move JS::Promise <-> WebIDL conversion into IDL
This change also removes as much direct use of JS::Promise in LibWeb
as possible. When specs refer to `Promise<T>` they should be assumed
to be referring to the WebIDL Promise type, not the JS::Promise type.

The one exception is the HostPromiseRejectionTracker hook on the JS
VM. This facility and its associated sets and events are intended to
expose the exact opaque object handles that were rejected to author
code. This is not possible with the WebIDL Promise type, so we have
to use JS::Promise or JS::Object to hold onto the promises.

It also exposes which specs need some updates in the area of
promises. WebDriver stands out in this regard. WebAudio could use
some more cross-references to WebIDL as well to clarify things.
2024-10-25 14:04:21 -06:00

54 lines
1.9 KiB
C++

/*
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/OfflineAudioContextPrototype.h>
#include <LibWeb/HighResolutionTime/DOMHighResTimeStamp.h>
#include <LibWeb/WebAudio/BaseAudioContext.h>
#include <LibWeb/WebIDL/Types.h>
namespace Web::WebAudio {
// https://webaudio.github.io/web-audio-api/#OfflineAudioContextOptions
struct OfflineAudioContextOptions {
WebIDL::UnsignedLong number_of_channels { 1 };
WebIDL::UnsignedLong length {};
float sample_rate {};
};
// https://webaudio.github.io/web-audio-api/#OfflineAudioContext
class OfflineAudioContext final : public BaseAudioContext {
WEB_PLATFORM_OBJECT(OfflineAudioContext, BaseAudioContext);
JS_DECLARE_ALLOCATOR(OfflineAudioContext);
public:
static WebIDL::ExceptionOr<JS::NonnullGCPtr<OfflineAudioContext>> construct_impl(JS::Realm&, OfflineAudioContextOptions const&);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<OfflineAudioContext>> construct_impl(JS::Realm&,
WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate);
virtual ~OfflineAudioContext() override;
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> start_rendering();
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> resume();
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> suspend(double suspend_time);
WebIDL::UnsignedLong length() const;
JS::GCPtr<WebIDL::CallbackType> oncomplete();
void set_oncomplete(JS::GCPtr<WebIDL::CallbackType>);
private:
OfflineAudioContext(JS::Realm&, OfflineAudioContextOptions const&);
OfflineAudioContext(JS::Realm&, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
WebIDL::UnsignedLong m_length {};
};
}