Coverage Report

Created: 2026-06-07 07:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibJS/Runtime/Intrinsics.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <LibJS/Forward.h>
10
#include <LibJS/Heap/Cell.h>
11
12
namespace JS {
13
14
class Intrinsics final : public Cell {
15
    JS_CELL(Intrinsics, Cell);
16
    JS_DECLARE_ALLOCATOR(Intrinsics);
17
18
public:
19
    static ThrowCompletionOr<NonnullGCPtr<Intrinsics>> create(Realm&);
20
21
12.9k
    NonnullGCPtr<Shape> empty_object_shape() { return *m_empty_object_shape; }
22
23
0
    NonnullGCPtr<Shape> new_object_shape() { return *m_new_object_shape; }
24
25
0
    [[nodiscard]] NonnullGCPtr<Shape> iterator_result_object_shape() { return *m_iterator_result_object_shape; }
26
0
    [[nodiscard]] u32 iterator_result_object_value_offset() { return m_iterator_result_object_value_offset; }
27
0
    [[nodiscard]] u32 iterator_result_object_done_offset() { return m_iterator_result_object_done_offset; }
28
29
    // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
30
0
    NonnullGCPtr<ProxyConstructor> proxy_constructor() { return *m_proxy_constructor; }
31
32
    // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor
33
0
    NonnullGCPtr<Object> async_from_sync_iterator_prototype() { return *m_async_from_sync_iterator_prototype; }
34
52
    NonnullGCPtr<Object> async_generator_prototype() { return *m_async_generator_prototype; }
35
52
    NonnullGCPtr<Object> generator_prototype() { return *m_generator_prototype; }
36
0
    NonnullGCPtr<Object> wrap_for_valid_iterator_prototype() { return *m_wrap_for_valid_iterator_prototype; }
37
38
    // Alias for the AsyncGenerator Prototype Object used by the spec (%AsyncGeneratorFunction.prototype.prototype%)
39
0
    NonnullGCPtr<Object> async_generator_function_prototype_prototype() { return *m_async_generator_prototype; }
40
    // Alias for the Generator Prototype Object used by the spec (%GeneratorFunction.prototype.prototype%)
41
0
    NonnullGCPtr<Object> generator_function_prototype_prototype() { return *m_generator_prototype; }
42
43
    // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
44
0
    NonnullGCPtr<Object> intl_segments_prototype() { return *m_intl_segments_prototype; }
45
46
    // Global object functions
47
52
    NonnullGCPtr<FunctionObject> eval_function() const { return *m_eval_function; }
48
52
    NonnullGCPtr<FunctionObject> is_finite_function() const { return *m_is_finite_function; }
49
52
    NonnullGCPtr<FunctionObject> is_nan_function() const { return *m_is_nan_function; }
50
52
    NonnullGCPtr<FunctionObject> parse_float_function() const { return *m_parse_float_function; }
51
52
    NonnullGCPtr<FunctionObject> parse_int_function() const { return *m_parse_int_function; }
52
52
    NonnullGCPtr<FunctionObject> decode_uri_function() const { return *m_decode_uri_function; }
53
52
    NonnullGCPtr<FunctionObject> decode_uri_component_function() const { return *m_decode_uri_component_function; }
54
52
    NonnullGCPtr<FunctionObject> encode_uri_function() const { return *m_encode_uri_function; }
55
52
    NonnullGCPtr<FunctionObject> encode_uri_component_function() const { return *m_encode_uri_component_function; }
56
52
    NonnullGCPtr<FunctionObject> escape_function() const { return *m_escape_function; }
57
52
    NonnullGCPtr<FunctionObject> unescape_function() const { return *m_unescape_function; }
58
59
    // Namespace/constructor object functions
60
0
    NonnullGCPtr<FunctionObject> array_prototype_values_function() const { return *m_array_prototype_values_function; }
61
0
    NonnullGCPtr<FunctionObject> date_constructor_now_function() const { return *m_date_constructor_now_function; }
62
0
    NonnullGCPtr<FunctionObject> json_parse_function() const { return *m_json_parse_function; }
63
0
    NonnullGCPtr<FunctionObject> json_stringify_function() const { return *m_json_stringify_function; }
64
0
    NonnullGCPtr<FunctionObject> object_prototype_to_string_function() const { return *m_object_prototype_to_string_function; }
65
52
    NonnullGCPtr<FunctionObject> throw_type_error_function() const { return *m_throw_type_error_function; }
66
67
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
68
    NonnullGCPtr<ConstructorName> snake_name##_constructor();                            \
69
    NonnullGCPtr<Object> snake_name##_prototype();
70
    JS_ENUMERATE_BUILTIN_TYPES
71
#undef __JS_ENUMERATE
72
73
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
74
    NonnullGCPtr<Intl::ConstructorName> intl_##snake_name##_constructor();    \
75
    NonnullGCPtr<Object> intl_##snake_name##_prototype();
76
    JS_ENUMERATE_INTL_OBJECTS
77
#undef __JS_ENUMERATE
78
79
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName)      \
80
    NonnullGCPtr<Temporal::ConstructorName> temporal_##snake_name##_constructor(); \
81
    NonnullGCPtr<Object> temporal_##snake_name##_prototype();
82
    JS_ENUMERATE_TEMPORAL_OBJECTS
83
#undef __JS_ENUMERATE
84
85
#define __JS_ENUMERATE(ClassName, snake_name) \
86
    NonnullGCPtr<ClassName> snake_name##_object();
87
    JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
88
#undef __JS_ENUMERATE
89
90
#define __JS_ENUMERATE(ClassName, snake_name)     \
91
    NonnullGCPtr<Object> snake_name##_prototype() \
92
104
    {                                             \
93
104
        return *m_##snake_name##_prototype;       \
94
104
    }
Unexecuted instantiation: JS::Intrinsics::array_iterator_prototype()
JS::Intrinsics::async_iterator_prototype()
Line
Count
Source
92
104
    {                                             \
93
104
        return *m_##snake_name##_prototype;       \
94
104
    }
Unexecuted instantiation: JS::Intrinsics::intl_segment_iterator_prototype()
Unexecuted instantiation: JS::Intrinsics::iterator_helper_prototype()
Unexecuted instantiation: JS::Intrinsics::map_iterator_prototype()
Unexecuted instantiation: JS::Intrinsics::regexp_string_iterator_prototype()
Unexecuted instantiation: JS::Intrinsics::set_iterator_prototype()
Unexecuted instantiation: JS::Intrinsics::string_iterator_prototype()
95
    JS_ENUMERATE_ITERATOR_PROTOTYPES
96
#undef __JS_ENUMERATE
97
98
private:
99
    Intrinsics(Realm& realm)
100
52
        : m_realm(realm)
101
52
    {
102
52
    }
103
104
    virtual void visit_edges(Visitor&) override;
105
106
    ThrowCompletionOr<void> initialize_intrinsics(Realm&);
107
108
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
109
    void initialize_##snake_name();
110
    JS_ENUMERATE_BUILTIN_TYPES
111
#undef __JS_ENUMERATE
112
113
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
114
    void initialize_intl_##snake_name();
115
    JS_ENUMERATE_INTL_OBJECTS
116
#undef __JS_ENUMERATE
117
118
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
119
    void initialize_temporal_##snake_name();
120
    JS_ENUMERATE_TEMPORAL_OBJECTS
121
#undef __JS_ENUMERATE
122
123
    NonnullGCPtr<Realm> m_realm;
124
125
    GCPtr<Shape> m_empty_object_shape;
126
    GCPtr<Shape> m_new_object_shape;
127
128
    GCPtr<Shape> m_iterator_result_object_shape;
129
    u32 m_iterator_result_object_value_offset { 0 };
130
    u32 m_iterator_result_object_done_offset { 0 };
131
132
    // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
133
    GCPtr<ProxyConstructor> m_proxy_constructor;
134
135
    // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor
136
    GCPtr<Object> m_async_from_sync_iterator_prototype;
137
    GCPtr<Object> m_async_generator_prototype;
138
    GCPtr<Object> m_generator_prototype;
139
    GCPtr<Object> m_wrap_for_valid_iterator_prototype;
140
141
    // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
142
    GCPtr<Object> m_intl_segments_prototype;
143
144
    // Global object functions
145
    GCPtr<FunctionObject> m_eval_function;
146
    GCPtr<FunctionObject> m_is_finite_function;
147
    GCPtr<FunctionObject> m_is_nan_function;
148
    GCPtr<FunctionObject> m_parse_float_function;
149
    GCPtr<FunctionObject> m_parse_int_function;
150
    GCPtr<FunctionObject> m_decode_uri_function;
151
    GCPtr<FunctionObject> m_decode_uri_component_function;
152
    GCPtr<FunctionObject> m_encode_uri_function;
153
    GCPtr<FunctionObject> m_encode_uri_component_function;
154
    GCPtr<FunctionObject> m_escape_function;
155
    GCPtr<FunctionObject> m_unescape_function;
156
157
    // Namespace/constructor object functions
158
    GCPtr<FunctionObject> m_array_prototype_values_function;
159
    GCPtr<FunctionObject> m_date_constructor_now_function;
160
    GCPtr<FunctionObject> m_json_parse_function;
161
    GCPtr<FunctionObject> m_json_stringify_function;
162
    GCPtr<FunctionObject> m_object_prototype_to_string_function;
163
    GCPtr<FunctionObject> m_throw_type_error_function;
164
165
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
166
    GCPtr<ConstructorName> m_##snake_name##_constructor;                                 \
167
    GCPtr<Object> m_##snake_name##_prototype;
168
    JS_ENUMERATE_BUILTIN_TYPES
169
#undef __JS_ENUMERATE
170
171
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
172
    GCPtr<Intl::ConstructorName> m_intl_##snake_name##_constructor;           \
173
    GCPtr<Object> m_intl_##snake_name##_prototype;
174
    JS_ENUMERATE_INTL_OBJECTS
175
#undef __JS_ENUMERATE
176
177
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
178
    GCPtr<Temporal::ConstructorName> m_temporal_##snake_name##_constructor;   \
179
    GCPtr<Object> m_temporal_##snake_name##_prototype;
180
    JS_ENUMERATE_TEMPORAL_OBJECTS
181
#undef __JS_ENUMERATE
182
183
#define __JS_ENUMERATE(ClassName, snake_name) \
184
    GCPtr<ClassName> m_##snake_name##_object;
185
    JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
186
#undef __JS_ENUMERATE
187
188
#define __JS_ENUMERATE(ClassName, snake_name) \
189
    GCPtr<Object> m_##snake_name##_prototype;
190
    JS_ENUMERATE_ITERATOR_PROTOTYPES
191
#undef __JS_ENUMERATE
192
};
193
194
void add_restricted_function_properties(FunctionObject&, Realm&);
195
196
}