2021-10-11 20:29:31 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, David Tuin <davidot@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2025-03-18 18:08:02 -05:00
|
|
|
#include <AK/FlyString.h>
|
2022-03-16 18:26:49 -06:00
|
|
|
#include <AK/StringView.h>
|
2021-11-10 11:05:21 +01:00
|
|
|
#include <AK/Vector.h>
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/CellAllocator.h>
|
2021-10-11 20:29:31 +02:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2025-06-28 21:39:13 -07:00
|
|
|
struct JS_API PrivateName {
|
2021-10-25 13:28:51 +02:00
|
|
|
PrivateName() = default;
|
2025-03-18 18:08:02 -05:00
|
|
|
PrivateName(u64 unique_id, FlyString description)
|
2021-10-11 20:29:31 +02:00
|
|
|
: unique_id(unique_id)
|
|
|
|
, description(move(description))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 unique_id { 0 };
|
2025-03-18 18:08:02 -05:00
|
|
|
FlyString description;
|
2021-10-11 20:29:31 +02:00
|
|
|
|
|
|
|
bool operator==(PrivateName const& rhs) const;
|
|
|
|
};
|
|
|
|
|
2025-06-28 21:39:13 -07:00
|
|
|
class JS_API PrivateEnvironment : public Cell {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_CELL(PrivateEnvironment, Cell);
|
|
|
|
GC_DECLARE_ALLOCATOR(PrivateEnvironment);
|
2022-08-28 22:11:20 +02:00
|
|
|
|
2021-10-11 20:29:31 +02:00
|
|
|
public:
|
2025-03-18 18:08:02 -05:00
|
|
|
PrivateName resolve_private_identifier(FlyString const& identifier) const;
|
2021-10-11 20:29:31 +02:00
|
|
|
|
2025-03-18 18:08:02 -05:00
|
|
|
void add_private_name(FlyString description);
|
2024-05-11 22:54:41 +00:00
|
|
|
|
|
|
|
PrivateEnvironment* outer_environment() { return m_outer_environment; }
|
|
|
|
PrivateEnvironment const* outer_environment() const { return m_outer_environment; }
|
2021-10-11 20:29:31 +02:00
|
|
|
|
|
|
|
private:
|
2022-08-28 23:51:28 +02:00
|
|
|
explicit PrivateEnvironment(PrivateEnvironment* parent);
|
|
|
|
|
2021-12-08 09:58:19 +01:00
|
|
|
virtual void visit_edges(Visitor&) override;
|
2021-10-11 20:29:31 +02:00
|
|
|
|
2025-03-18 18:08:02 -05:00
|
|
|
auto find_private_name(FlyString const& description) const
|
2021-10-11 20:29:31 +02:00
|
|
|
{
|
|
|
|
return m_private_names.find_if([&](PrivateName const& private_name) {
|
|
|
|
return private_name.description == description;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 s_next_id;
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<PrivateEnvironment> m_outer_environment; // [[OuterEnv]]
|
|
|
|
Vector<PrivateName> m_private_names; // [[Names]]
|
2021-10-11 20:29:31 +02:00
|
|
|
u64 m_unique_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|