diff options
author | Andreas Kling <kling@serenityos.org> | 2021-06-23 13:04:52 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-23 13:08:27 +0200 |
commit | 9ccc2f6c4d4a60acb0ea992df85e09cee650a193 (patch) | |
tree | 89b80dfe5339e2d8e0ac8d5fdee548c5766f12c8 /Userland | |
parent | 7a87e920f2d46d467aebfd58af93a585f514a76e (diff) | |
download | serenity-9ccc2f6c4d4a60acb0ea992df85e09cee650a193.zip |
LibJS: Make EnvironmentRecord inherit directly from Cell
Previously, EnvironmentRecord was a JS::Object. This was done because
GlobalObject inherited from EnvironmentRecord. Now that this is no
longer the case, we can simplify things by making EnvironmentRecord
inherit from Cell directly.
This also removes the need for environment records to have a shape,
which was awkward. This will be removed in the following patch.
Diffstat (limited to 'Userland')
8 files changed, 25 insertions, 18 deletions
diff --git a/Userland/Libraries/LibJS/Heap/Cell.h b/Userland/Libraries/LibJS/Heap/Cell.h index 16d72c24de..3e320d8172 100644 --- a/Userland/Libraries/LibJS/Heap/Cell.h +++ b/Userland/Libraries/LibJS/Heap/Cell.h @@ -50,6 +50,7 @@ public: virtual ~Visitor() = default; }; + virtual bool is_environment_record() const { return false; } virtual void visit_edges(Visitor&) { } Heap& heap() const; diff --git a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.h b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.h index f6cfb493df..e82a1b3341 100644 --- a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.h +++ b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironmentRecord.h @@ -22,7 +22,7 @@ struct Binding { }; class DeclarativeEnvironmentRecord : public EnvironmentRecord { - JS_OBJECT(DeclarativeEnvironmentRecord, EnvironmentRecord); + JS_ENVIRONMENT_RECORD(DeclarativeEnvironmentRecord, EnvironmentRecord); public: enum class EnvironmentRecordType { @@ -68,6 +68,6 @@ private: }; template<> -inline bool Object::fast_is<DeclarativeEnvironmentRecord>() const { return is_declarative_environment_record(); } +inline bool EnvironmentRecord::fast_is<DeclarativeEnvironmentRecord>() const { return is_declarative_environment_record(); } } diff --git a/Userland/Libraries/LibJS/Runtime/EnvironmentRecord.cpp b/Userland/Libraries/LibJS/Runtime/EnvironmentRecord.cpp index 47acfa5f56..fc9e5687f4 100644 --- a/Userland/Libraries/LibJS/Runtime/EnvironmentRecord.cpp +++ b/Userland/Libraries/LibJS/Runtime/EnvironmentRecord.cpp @@ -10,20 +10,19 @@ namespace JS { EnvironmentRecord::EnvironmentRecord(EnvironmentRecord* outer_environment) - : Object(vm().environment_record_shape()) - , m_outer_environment(outer_environment) + : m_outer_environment(outer_environment) { } void EnvironmentRecord::initialize(GlobalObject& global_object) { m_global_object = &global_object; - Base::initialize(global_object); + Cell::initialize(global_object); } void EnvironmentRecord::visit_edges(Visitor& visitor) { - Base::visit_edges(visitor); + Cell::visit_edges(visitor); visitor.visit(m_outer_environment); } diff --git a/Userland/Libraries/LibJS/Runtime/EnvironmentRecord.h b/Userland/Libraries/LibJS/Runtime/EnvironmentRecord.h index a8341dbe7a..f4a13278b8 100644 --- a/Userland/Libraries/LibJS/Runtime/EnvironmentRecord.h +++ b/Userland/Libraries/LibJS/Runtime/EnvironmentRecord.h @@ -15,9 +15,12 @@ struct Variable { DeclarationKind declaration_kind; }; -class EnvironmentRecord : public Object { - JS_OBJECT(EnvironmentRecord, Object); +#define JS_ENVIRONMENT_RECORD(class_, base_class) \ +public: \ + using Base = base_class; \ + virtual char const* class_name() const override { return #class_; } +class EnvironmentRecord : public Cell { public: GlobalObject& global_object() { return *m_global_object; } GlobalObject const& global_object() const { return *m_global_object; } @@ -43,6 +46,15 @@ public: EnvironmentRecord* outer_environment() { return m_outer_environment; } EnvironmentRecord const* outer_environment() const { return m_outer_environment; } + virtual bool is_global_environment_record() const { return false; } + virtual bool is_declarative_environment_record() const { return false; } + virtual bool is_function_environment_record() const { return false; } + + template<typename T> + bool fast_is() const = delete; + + virtual char const* class_name() const override { return "EnvironmentRecord"; } + protected: explicit EnvironmentRecord(EnvironmentRecord* parent); diff --git a/Userland/Libraries/LibJS/Runtime/FunctionEnvironmentRecord.h b/Userland/Libraries/LibJS/Runtime/FunctionEnvironmentRecord.h index fe66b3c6da..0caf784b8c 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionEnvironmentRecord.h +++ b/Userland/Libraries/LibJS/Runtime/FunctionEnvironmentRecord.h @@ -11,7 +11,7 @@ namespace JS { class FunctionEnvironmentRecord final : public DeclarativeEnvironmentRecord { - JS_OBJECT(FunctionEnvironmentRecord, DeclarativeEnvironmentRecord); + JS_ENVIRONMENT_RECORD(FunctionEnvironmentRecord, DeclarativeEnvironmentRecord); public: enum class ThisBindingStatus : u8 { @@ -61,6 +61,6 @@ private: }; template<> -inline bool Object::fast_is<FunctionEnvironmentRecord>() const { return is_function_environment_record(); } +inline bool EnvironmentRecord::fast_is<FunctionEnvironmentRecord>() const { return is_function_environment_record(); } } diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironmentRecord.h b/Userland/Libraries/LibJS/Runtime/GlobalEnvironmentRecord.h index 0ce1b850e6..093a1ba57d 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironmentRecord.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironmentRecord.h @@ -11,7 +11,7 @@ namespace JS { class GlobalEnvironmentRecord final : public EnvironmentRecord { - JS_OBJECT(GlobalEnvironmentRecord, EnvironmentRecord); + JS_ENVIRONMENT_RECORD(GlobalEnvironmentRecord, EnvironmentRecord); public: explicit GlobalEnvironmentRecord(GlobalObject&); @@ -59,6 +59,5 @@ private: }; template<> -inline bool Object::fast_is<GlobalEnvironmentRecord>() const { return is_global_environment_record(); } - +inline bool EnvironmentRecord::fast_is<GlobalEnvironmentRecord>() const { return is_global_environment_record(); } } diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index fdd43bf3b3..91f47be76c 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -108,10 +108,6 @@ public: virtual bool is_global_object() const { return false; } virtual bool is_proxy_object() const { return false; } virtual bool is_native_function() const { return false; } - virtual bool is_environment_record() const { return false; } - virtual bool is_global_environment_record() const { return false; } - virtual bool is_declarative_environment_record() const { return false; } - virtual bool is_function_environment_record() const { return false; } // B.3.7 The [[IsHTMLDDA]] Internal Slot, https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot virtual bool is_htmldda() const { return false; } diff --git a/Userland/Libraries/LibJS/Runtime/ObjectEnvironmentRecord.h b/Userland/Libraries/LibJS/Runtime/ObjectEnvironmentRecord.h index e1487ebbd8..f9780f0fb5 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectEnvironmentRecord.h +++ b/Userland/Libraries/LibJS/Runtime/ObjectEnvironmentRecord.h @@ -11,7 +11,7 @@ namespace JS { class ObjectEnvironmentRecord : public EnvironmentRecord { - JS_OBJECT(ObjectEnvironmentRecord, EnvironmentRecord); + JS_ENVIRONMENT_RECORD(ObjectEnvironmentRecord, EnvironmentRecord); public: ObjectEnvironmentRecord(Object&, EnvironmentRecord* parent_scope); |