2020-11-28 15:14:26 +00:00
|
|
|
/*
|
2021-06-21 21:17:24 +00:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2020-11-28 15:14:26 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-28 15:14:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-07-01 10:24:46 +00:00
|
|
|
#include <LibJS/Runtime/Environment.h>
|
2020-11-28 15:14:26 +00:00
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2023-08-13 10:53:46 +00:00
|
|
|
class ObjectEnvironment final : public Environment {
|
2021-07-01 10:24:46 +00:00
|
|
|
JS_ENVIRONMENT(ObjectEnvironment, Environment);
|
2023-11-19 08:45:05 +00:00
|
|
|
JS_DECLARE_ALLOCATOR(ObjectEnvironment);
|
2020-11-28 15:14:26 +00:00
|
|
|
|
|
|
|
public:
|
2021-06-24 11:24:44 +00:00
|
|
|
enum class IsWithEnvironment {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
2020-11-28 15:14:26 +00:00
|
|
|
|
2023-01-09 00:23:00 +00:00
|
|
|
virtual ThrowCompletionOr<bool> has_binding(DeprecatedFlyString const& name, Optional<size_t>* = nullptr) const override;
|
|
|
|
virtual ThrowCompletionOr<void> create_mutable_binding(VM&, DeprecatedFlyString const& name, bool can_be_deleted) override;
|
|
|
|
virtual ThrowCompletionOr<void> create_immutable_binding(VM&, DeprecatedFlyString const& name, bool strict) override;
|
2022-12-14 12:26:10 +00:00
|
|
|
virtual ThrowCompletionOr<void> initialize_binding(VM&, DeprecatedFlyString const& name, Value, Environment::InitializeBindingHint) override;
|
2023-01-09 00:23:00 +00:00
|
|
|
virtual ThrowCompletionOr<void> set_mutable_binding(VM&, DeprecatedFlyString const& name, Value, bool strict) override;
|
|
|
|
virtual ThrowCompletionOr<Value> get_binding_value(VM&, DeprecatedFlyString const& name, bool strict) override;
|
|
|
|
virtual ThrowCompletionOr<bool> delete_binding(VM&, DeprecatedFlyString const& name) override;
|
2021-06-23 10:26:37 +00:00
|
|
|
|
2021-06-24 11:24:44 +00: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 23:09:02 +00:00
|
|
|
return m_binding_object;
|
2021-06-24 11:24:44 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-06-26 08:38:36 +00:00
|
|
|
// [[BindingObject]], The binding object of this Environment Record.
|
|
|
|
Object& binding_object() { return m_binding_object; }
|
2021-06-24 11:24:44 +00:00
|
|
|
|
2021-06-26 08:38:36 +00: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 15:16:08 +00:00
|
|
|
|
2020-11-28 15:14:26 +00:00
|
|
|
private:
|
2022-08-28 21:51:28 +00:00
|
|
|
ObjectEnvironment(Object& binding_object, IsWithEnvironment, Environment* outer_environment);
|
|
|
|
|
2020-11-28 15:14:26 +00:00
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
|
2023-02-26 23:09:02 +00:00
|
|
|
NonnullGCPtr<Object> m_binding_object;
|
2021-06-24 11:24:44 +00:00
|
|
|
bool m_with_environment { false };
|
2020-11-28 15:14:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|