Coverage Report

Created: 2025-08-28 06:26

/src/serenity/Userland/Libraries/LibJS/Runtime/ModuleEnvironment.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2022, David Tuin <davidot@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <LibJS/Module.h>
10
#include <LibJS/Runtime/DeclarativeEnvironment.h>
11
#include <LibJS/Runtime/Environment.h>
12
13
namespace JS {
14
15
// 9.1.1.5 Module Environment Records, https://tc39.es/ecma262/#sec-module-environment-records
16
class ModuleEnvironment final : public DeclarativeEnvironment {
17
    JS_ENVIRONMENT(ModuleEnvironment, DeclarativeEnvironment);
18
    JS_DECLARE_ALLOCATOR(ModuleEnvironment);
19
20
public:
21
    // Note: Module Environment Records support all of the declarative Environment Record methods listed
22
    //       in Table 18 and share the same specifications for all of those methods except for
23
    //       GetBindingValue, DeleteBinding, HasThisBinding and GetThisBinding.
24
    //       In addition, module Environment Records support the methods listed in Table 24.
25
    virtual ThrowCompletionOr<Value> get_binding_value(VM&, DeprecatedFlyString const& name, bool strict) override;
26
    virtual ThrowCompletionOr<bool> delete_binding(VM&, DeprecatedFlyString const& name) override;
27
0
    virtual bool has_this_binding() const final { return true; }
28
    virtual ThrowCompletionOr<Value> get_this_binding(VM&) const final;
29
    ThrowCompletionOr<void> create_import_binding(DeprecatedFlyString name, Module* module, DeprecatedFlyString binding_name);
30
31
private:
32
    explicit ModuleEnvironment(Environment* outer_environment);
33
34
    virtual void visit_edges(Visitor&) override;
35
36
    struct IndirectBinding {
37
        DeprecatedFlyString name;
38
        GCPtr<Module> module;
39
        DeprecatedFlyString binding_name;
40
    };
41
    IndirectBinding const* get_indirect_binding(DeprecatedFlyString const& name) const;
42
43
    virtual Optional<BindingAndIndex> find_binding_and_index(DeprecatedFlyString const& name) const override;
44
45
    // FIXME: Since we always access this via the name this could be a map.
46
    Vector<IndirectBinding> m_indirect_bindings;
47
};
48
49
}