Coverage Report

Created: 2026-02-16 07:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/Optional.h>
10
#include <AK/String.h>
11
#include <LibJS/Forward.h>
12
#include <LibJS/Runtime/Value.h>
13
14
namespace JS {
15
16
// 6.2.5 The Property Descriptor Specification Type, https://tc39.es/ecma262/#sec-property-descriptor-specification-type
17
18
Value from_property_descriptor(VM&, Optional<PropertyDescriptor> const&);
19
ThrowCompletionOr<PropertyDescriptor> to_property_descriptor(VM&, Value);
20
21
class PropertyDescriptor {
22
public:
23
    [[nodiscard]] bool is_accessor_descriptor() const;
24
    [[nodiscard]] bool is_data_descriptor() const;
25
    [[nodiscard]] bool is_generic_descriptor() const;
26
27
    [[nodiscard]] PropertyAttributes attributes() const;
28
29
    void complete();
30
31
    // Not a standard abstract operation, but "If every field in Desc is absent".
32
    [[nodiscard]] bool is_empty() const
33
0
    {
34
0
        return !value.has_value() && !get.has_value() && !set.has_value() && !writable.has_value() && !enumerable.has_value() && !configurable.has_value() && !unimplemented.has_value();
35
0
    }
36
37
    Optional<Value> value {};
38
    Optional<GCPtr<FunctionObject>> get {};
39
    Optional<GCPtr<FunctionObject>> set {};
40
    Optional<bool> writable {};
41
    Optional<bool> enumerable {};
42
    Optional<bool> configurable {};
43
    Optional<bool> unimplemented {};
44
45
    Optional<u32> property_offset {};
46
};
47
48
}
49
50
namespace AK {
51
52
template<>
53
struct Formatter<JS::PropertyDescriptor> : Formatter<StringView> {
54
    ErrorOr<void> format(FormatBuilder& builder, JS::PropertyDescriptor const& property_descriptor)
55
0
    {
56
0
        Vector<String> parts;
57
0
        if (property_descriptor.value.has_value())
58
0
            TRY(parts.try_append(TRY(String::formatted("[[Value]]: {}", property_descriptor.value->to_string_without_side_effects()))));
59
0
        if (property_descriptor.get.has_value())
60
0
            TRY(parts.try_append(TRY(String::formatted("[[Get]]: JS::Function* @ {:p}", property_descriptor.get->ptr()))));
61
0
        if (property_descriptor.set.has_value())
62
0
            TRY(parts.try_append(TRY(String::formatted("[[Set]]: JS::Function* @ {:p}", property_descriptor.set->ptr()))));
63
0
        if (property_descriptor.writable.has_value())
64
0
            TRY(parts.try_append(TRY(String::formatted("[[Writable]]: {}", *property_descriptor.writable))));
65
0
        if (property_descriptor.enumerable.has_value())
66
0
            TRY(parts.try_append(TRY(String::formatted("[[Enumerable]]: {}", *property_descriptor.enumerable))));
67
0
        if (property_descriptor.configurable.has_value())
68
0
            TRY(parts.try_append(TRY(String::formatted("[[Configurable]]: {}", *property_descriptor.configurable))));
69
0
        if (property_descriptor.unimplemented.has_value())
70
0
            TRY(parts.try_append(TRY(String::formatted("[[Unimplemented]]: {}", *property_descriptor.unimplemented))));
71
0
        return Formatter<StringView>::format(builder, TRY(String::formatted("PropertyDescriptor {{ {} }}", TRY(String::join(", "sv, parts)))));
72
0
    }
73
};
74
75
}