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.
This commit is contained in:
parent
7a87e920f2
commit
9ccc2f6c4d
Notes:
sideshowbarker
2024-07-18 11:37:45 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9ccc2f6c4d4
8 changed files with 25 additions and 18 deletions
|
@ -50,6 +50,7 @@ public:
|
|||
virtual ~Visitor() = default;
|
||||
};
|
||||
|
||||
virtual bool is_environment_record() const { return false; }
|
||||
virtual void visit_edges(Visitor&) { }
|
||||
|
||||
Heap& heap() const;
|
||||
|
|
|
@ -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(); }
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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(); }
|
||||
|
||||
}
|
||||
|
|
|
@ -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(); }
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue