2020-11-28 12:14:26 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <andreas@ladybird.org>
|
2020-11-28 12:14:26 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-28 12:14:26 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-07-01 07:24:46 -03:00
|
|
|
#include <LibJS/Runtime/Environment.h>
|
2020-11-28 12:14:26 -03:00
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
2025-07-19 14:41:08 -03:00
|
|
|
class ObjectEnvironment final : public Environment {
|
2021-07-01 07:24:46 -03:00
|
|
|
JS_ENVIRONMENT(ObjectEnvironment, Environment);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(ObjectEnvironment);
|
2020-11-28 12:14:26 -03:00
|
|
|
|
|
|
|
|
public:
|
2021-06-24 08:24:44 -03:00
|
|
|
enum class IsWithEnvironment {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
2020-11-28 12:14:26 -03:00
|
|
|
|
2025-08-02 20:27:29 -03:00
|
|
|
virtual ThrowCompletionOr<bool> has_binding(Utf16FlyString const& name, Optional<size_t>* = nullptr) const override;
|
|
|
|
|
virtual ThrowCompletionOr<void> create_mutable_binding(VM&, Utf16FlyString const& name, bool can_be_deleted) override;
|
|
|
|
|
virtual ThrowCompletionOr<void> create_immutable_binding(VM&, Utf16FlyString const& name, bool strict) override;
|
|
|
|
|
virtual ThrowCompletionOr<void> initialize_binding(VM&, Utf16FlyString const& name, Value, Environment::InitializeBindingHint) override;
|
|
|
|
|
virtual ThrowCompletionOr<void> set_mutable_binding(VM&, Utf16FlyString const& name, Value, bool strict) override;
|
|
|
|
|
virtual ThrowCompletionOr<Value> get_binding_value(VM&, Utf16FlyString const& name, bool strict) override;
|
|
|
|
|
virtual ThrowCompletionOr<bool> delete_binding(VM&, Utf16FlyString const& name) override;
|
2021-06-23 07:26:37 -03:00
|
|
|
|
2021-06-24 08:24:44 -03:00
|
|
|
// 9.1.1.2.10 WithBaseObject ( ), https://tc39.es/ecma262/#sec-object-environment-records-withbaseobject
|
|
|
|
|
virtual Object* with_base_object() const override
|
|
|
|
|
{
|
|
|
|
|
if (is_with_environment())
|
2023-02-26 20:09:02 -03:00
|
|
|
return m_binding_object;
|
2021-06-24 08:24:44 -03:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 05:38:36 -03:00
|
|
|
// [[BindingObject]], The binding object of this Environment Record.
|
|
|
|
|
Object& binding_object() { return m_binding_object; }
|
2021-06-24 08:24:44 -03:00
|
|
|
|
2021-06-26 05:38:36 -03:00
|
|
|
// [[IsWithEnvironment]], Indicates whether this Environment Record is created for a with statement.
|
|
|
|
|
bool is_with_environment() const { return m_with_environment; }
|
2021-06-22 12:16:08 -03:00
|
|
|
|
2020-11-28 12:14:26 -03:00
|
|
|
private:
|
2022-08-28 18:51:28 -03:00
|
|
|
ObjectEnvironment(Object& binding_object, IsWithEnvironment, Environment* outer_environment);
|
|
|
|
|
|
2020-11-28 12:14:26 -03:00
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<Object> m_binding_object;
|
2021-06-24 08:24:44 -03:00
|
|
|
bool m_with_environment { false };
|
2020-11-28 12:14:26 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|