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/WebIDL/Buffers.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2023, Shannon Booth <shannon@serenityos.org>
3
 * Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>
4
 *
5
 * SPDX-License-Identifier: BSD-2-Clause
6
 */
7
8
#include <LibJS/Runtime/DataView.h>
9
#include <LibJS/Runtime/TypedArray.h>
10
#include <LibWeb/WebIDL/Buffers.h>
11
12
namespace Web::WebIDL {
13
14
JS_DEFINE_ALLOCATOR(BufferableObjectBase);
15
JS_DEFINE_ALLOCATOR(ArrayBufferView);
16
JS_DEFINE_ALLOCATOR(BufferSource);
17
18
u32 BufferableObjectBase::byte_length() const
19
0
{
20
0
    return m_bufferable_object.visit(
21
0
        [](JS::NonnullGCPtr<JS::TypedArrayBase> typed_array) {
22
0
            auto typed_array_record = JS::make_typed_array_with_buffer_witness_record(typed_array, JS::ArrayBuffer::Order::SeqCst);
23
0
            return JS::typed_array_byte_length(typed_array_record);
24
0
        },
25
0
        [](JS::NonnullGCPtr<JS::DataView> data_view) {
26
0
            auto view_record = JS::make_data_view_with_buffer_witness_record(data_view, JS::ArrayBuffer::Order::SeqCst);
27
0
            return JS::get_view_byte_length(view_record);
28
0
        },
29
0
        [](JS::NonnullGCPtr<JS::ArrayBuffer> array_buffer) { return static_cast<u32>(array_buffer->byte_length()); });
30
0
}
31
32
JS::NonnullGCPtr<JS::Object> BufferableObjectBase::raw_object()
33
0
{
34
0
    return m_bufferable_object.visit([](auto const& obj) -> JS::NonnullGCPtr<JS::Object> { return obj; });
Unexecuted instantiation: Buffers.cpp:JS::NonnullGCPtr<JS::Object> Web::WebIDL::BufferableObjectBase::raw_object()::$_0::operator()<JS::NonnullGCPtr<JS::TypedArrayBase> >(JS::NonnullGCPtr<JS::TypedArrayBase> const&) const
Unexecuted instantiation: Buffers.cpp:JS::NonnullGCPtr<JS::Object> Web::WebIDL::BufferableObjectBase::raw_object()::$_0::operator()<JS::NonnullGCPtr<JS::DataView> >(JS::NonnullGCPtr<JS::DataView> const&) const
Unexecuted instantiation: Buffers.cpp:JS::NonnullGCPtr<JS::Object> Web::WebIDL::BufferableObjectBase::raw_object()::$_0::operator()<JS::NonnullGCPtr<JS::ArrayBuffer> >(JS::NonnullGCPtr<JS::ArrayBuffer> const&) const
35
0
}
36
37
JS::GCPtr<JS::ArrayBuffer> BufferableObjectBase::viewed_array_buffer()
38
0
{
39
0
    return m_bufferable_object.visit(
40
0
        [](JS::NonnullGCPtr<JS::ArrayBuffer> array_buffer) -> JS::GCPtr<JS::ArrayBuffer> { return array_buffer; },
41
0
        [](auto const& view) -> JS::GCPtr<JS::ArrayBuffer> { return view->viewed_array_buffer(); });
Unexecuted instantiation: Buffers.cpp:JS::GCPtr<JS::ArrayBuffer> Web::WebIDL::BufferableObjectBase::viewed_array_buffer()::$_1::operator()<JS::NonnullGCPtr<JS::TypedArrayBase> >(JS::NonnullGCPtr<JS::TypedArrayBase> const&) const
Unexecuted instantiation: Buffers.cpp:JS::GCPtr<JS::ArrayBuffer> Web::WebIDL::BufferableObjectBase::viewed_array_buffer()::$_1::operator()<JS::NonnullGCPtr<JS::DataView> >(JS::NonnullGCPtr<JS::DataView> const&) const
42
0
}
43
44
BufferableObject BufferableObjectBase::bufferable_object_from_raw_object(JS::NonnullGCPtr<JS::Object> object)
45
0
{
46
0
    if (is<JS::TypedArrayBase>(*object))
47
0
        return JS::NonnullGCPtr { static_cast<JS::TypedArrayBase&>(*object) };
48
49
0
    if (is<JS::DataView>(*object))
50
0
        return JS::NonnullGCPtr { static_cast<JS::DataView&>(*object) };
51
52
0
    if (is<JS::ArrayBuffer>(*object))
53
0
        return JS::NonnullGCPtr { static_cast<JS::ArrayBuffer&>(*object) };
54
55
0
    VERIFY_NOT_REACHED();
56
0
}
57
58
BufferableObjectBase::BufferableObjectBase(JS::NonnullGCPtr<JS::Object> object)
59
0
    : m_bufferable_object(bufferable_object_from_raw_object(object))
60
0
{
61
0
}
62
63
bool BufferableObjectBase::is_typed_array_base() const
64
0
{
65
0
    return m_bufferable_object.has<JS::NonnullGCPtr<JS::TypedArrayBase>>();
66
0
}
67
68
bool BufferableObjectBase::is_data_view() const
69
0
{
70
0
    return m_bufferable_object.has<JS::NonnullGCPtr<JS::DataView>>();
71
0
}
72
73
bool BufferableObjectBase::is_array_buffer() const
74
0
{
75
0
    return m_bufferable_object.has<JS::NonnullGCPtr<JS::ArrayBuffer>>();
76
0
}
77
78
void BufferableObjectBase::visit_edges(Visitor& visitor)
79
0
{
80
0
    Base::visit_edges(visitor);
81
0
    m_bufferable_object.visit([&](auto& obj) { visitor.visit(obj); });
Unexecuted instantiation: Buffers.cpp:auto Web::WebIDL::BufferableObjectBase::visit_edges(JS::Cell::Visitor&)::$_0::operator()<JS::NonnullGCPtr<JS::TypedArrayBase> >(JS::NonnullGCPtr<JS::TypedArrayBase>&) const
Unexecuted instantiation: Buffers.cpp:auto Web::WebIDL::BufferableObjectBase::visit_edges(JS::Cell::Visitor&)::$_0::operator()<JS::NonnullGCPtr<JS::DataView> >(JS::NonnullGCPtr<JS::DataView>&) const
Unexecuted instantiation: Buffers.cpp:auto Web::WebIDL::BufferableObjectBase::visit_edges(JS::Cell::Visitor&)::$_0::operator()<JS::NonnullGCPtr<JS::ArrayBuffer> >(JS::NonnullGCPtr<JS::ArrayBuffer>&) const
82
0
}
83
84
0
ArrayBufferView::~ArrayBufferView() = default;
85
86
u32 ArrayBufferView::byte_offset() const
87
0
{
88
0
    return m_bufferable_object.visit(
89
0
        [](JS::NonnullGCPtr<JS::ArrayBuffer>) -> u32 { VERIFY_NOT_REACHED(); },
90
0
        [](auto& view) -> u32 { return static_cast<u32>(view->byte_offset()); });
Unexecuted instantiation: Buffers.cpp:unsigned int Web::WebIDL::ArrayBufferView::byte_offset() const::$_1::operator()<JS::NonnullGCPtr<JS::TypedArrayBase> const>(JS::NonnullGCPtr<JS::TypedArrayBase> const&) const
Unexecuted instantiation: Buffers.cpp:unsigned int Web::WebIDL::ArrayBufferView::byte_offset() const::$_1::operator()<JS::NonnullGCPtr<JS::DataView> const>(JS::NonnullGCPtr<JS::DataView> const&) const
91
0
}
92
93
0
BufferSource::~BufferSource() = default;
94
95
}