/src/serenity/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibJS/Runtime/Environment.h> |
10 | | |
11 | | namespace JS { |
12 | | |
13 | | class ObjectEnvironment final : public Environment { |
14 | | JS_ENVIRONMENT(ObjectEnvironment, Environment); |
15 | | JS_DECLARE_ALLOCATOR(ObjectEnvironment); |
16 | | |
17 | | public: |
18 | | enum class IsWithEnvironment { |
19 | | No, |
20 | | Yes, |
21 | | }; |
22 | | |
23 | | virtual ThrowCompletionOr<bool> has_binding(DeprecatedFlyString const& name, Optional<size_t>* = nullptr) const override; |
24 | | virtual ThrowCompletionOr<void> create_mutable_binding(VM&, DeprecatedFlyString const& name, bool can_be_deleted) override; |
25 | | virtual ThrowCompletionOr<void> create_immutable_binding(VM&, DeprecatedFlyString const& name, bool strict) override; |
26 | | virtual ThrowCompletionOr<void> initialize_binding(VM&, DeprecatedFlyString const& name, Value, Environment::InitializeBindingHint) override; |
27 | | virtual ThrowCompletionOr<void> set_mutable_binding(VM&, DeprecatedFlyString const& name, Value, bool strict) override; |
28 | | virtual ThrowCompletionOr<Value> get_binding_value(VM&, DeprecatedFlyString const& name, bool strict) override; |
29 | | virtual ThrowCompletionOr<bool> delete_binding(VM&, DeprecatedFlyString const& name) override; |
30 | | |
31 | | // 9.1.1.2.10 WithBaseObject ( ), https://tc39.es/ecma262/#sec-object-environment-records-withbaseobject |
32 | | virtual Object* with_base_object() const override |
33 | 0 | { |
34 | 0 | if (is_with_environment()) |
35 | 0 | return m_binding_object; |
36 | 0 | return nullptr; |
37 | 0 | } |
38 | | |
39 | | // [[BindingObject]], The binding object of this Environment Record. |
40 | 0 | Object& binding_object() { return m_binding_object; } |
41 | | |
42 | | // [[IsWithEnvironment]], Indicates whether this Environment Record is created for a with statement. |
43 | 0 | bool is_with_environment() const { return m_with_environment; } |
44 | | |
45 | | private: |
46 | | ObjectEnvironment(Object& binding_object, IsWithEnvironment, Environment* outer_environment); |
47 | | |
48 | | virtual void visit_edges(Visitor&) override; |
49 | | |
50 | | NonnullGCPtr<Object> m_binding_object; |
51 | | bool m_with_environment { false }; |
52 | | }; |
53 | | |
54 | | } |