Coverage Report

Created: 2026-02-14 08:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/WebAudio/OfflineAudioContext.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <LibWeb/Bindings/Intrinsics.h>
8
#include <LibWeb/HTML/EventNames.h>
9
#include <LibWeb/HTML/Window.h>
10
#include <LibWeb/WebAudio/OfflineAudioContext.h>
11
12
namespace Web::WebAudio {
13
14
JS_DEFINE_ALLOCATOR(OfflineAudioContext);
15
16
WebIDL::ExceptionOr<JS::NonnullGCPtr<OfflineAudioContext>> OfflineAudioContext::construct_impl(JS::Realm& realm, OfflineAudioContextOptions const& context_options)
17
0
{
18
0
    return construct_impl(realm, context_options.number_of_channels, context_options.length, context_options.sample_rate);
19
0
}
20
21
// https://webaudio.github.io/web-audio-api/#dom-offlineaudiocontext-offlineaudiocontext-numberofchannels-length-samplerate
22
WebIDL::ExceptionOr<JS::NonnullGCPtr<OfflineAudioContext>> OfflineAudioContext::construct_impl(JS::Realm& realm,
23
    WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate)
24
0
{
25
    // The OfflineAudioContext can be constructed with the same arguments as AudioContext.createBuffer.
26
    // A NotSupportedError exception MUST be thrown if any of the arguments is negative, zero, or outside its nominal range.
27
0
    TRY(verify_audio_options_inside_nominal_range(realm, number_of_channels, length, sample_rate));
28
29
0
    return realm.heap().allocate<OfflineAudioContext>(realm, realm, number_of_channels, length, sample_rate);
30
0
}
31
32
0
OfflineAudioContext::~OfflineAudioContext() = default;
33
34
// https://webaudio.github.io/web-audio-api/#dom-offlineaudiocontext-startrendering
35
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> OfflineAudioContext::start_rendering()
36
0
{
37
0
    return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement OfflineAudioContext::start_rendering"_string);
38
0
}
39
40
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> OfflineAudioContext::resume()
41
0
{
42
0
    return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement OfflineAudioContext::resume"_string);
43
0
}
44
45
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> OfflineAudioContext::suspend(double suspend_time)
46
0
{
47
0
    (void)suspend_time;
48
0
    return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement OfflineAudioContext::suspend"_string);
49
0
}
50
51
// https://webaudio.github.io/web-audio-api/#dom-offlineaudiocontext-length
52
WebIDL::UnsignedLong OfflineAudioContext::length() const
53
0
{
54
    // The size of the buffer in sample-frames. This is the same as the value of the length parameter for the constructor.
55
0
    return m_length;
56
0
}
57
58
// https://webaudio.github.io/web-audio-api/#dom-offlineaudiocontext-oncomplete
59
JS::GCPtr<WebIDL::CallbackType> OfflineAudioContext::oncomplete()
60
0
{
61
0
    return event_handler_attribute(HTML::EventNames::complete);
62
0
}
63
64
// https://webaudio.github.io/web-audio-api/#dom-offlineaudiocontext-oncomplete
65
void OfflineAudioContext::set_oncomplete(JS::GCPtr<WebIDL::CallbackType> value)
66
0
{
67
0
    set_event_handler_attribute(HTML::EventNames::complete, value);
68
0
}
69
70
OfflineAudioContext::OfflineAudioContext(JS::Realm& realm, OfflineAudioContextOptions const&)
71
0
    : BaseAudioContext(realm)
72
0
{
73
0
}
74
75
OfflineAudioContext::OfflineAudioContext(JS::Realm& realm, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate)
76
0
    : BaseAudioContext(realm, sample_rate)
77
0
    , m_length(length)
78
0
{
79
0
    (void)number_of_channels;
80
0
}
81
82
void OfflineAudioContext::initialize(JS::Realm& realm)
83
0
{
84
0
    Base::initialize(realm);
85
0
    WEB_SET_PROTOTYPE_FOR_INTERFACE(OfflineAudioContext);
86
0
}
87
88
void OfflineAudioContext::visit_edges(Cell::Visitor& visitor)
89
0
{
90
0
    Base::visit_edges(visitor);
91
0
}
92
93
}