mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:57:35 +00:00
LibJS: Add getter/setter support
This patch adds a GetterSetterPair object. Values can now store pointers to objects of this type. These objects are created when using Object.defineProperty and providing an accessor descriptor.
This commit is contained in:
parent
a4d04cc748
commit
45dfa094e9
7 changed files with 259 additions and 12 deletions
|
@ -45,6 +45,7 @@ public:
|
|||
Object,
|
||||
Boolean,
|
||||
Symbol,
|
||||
Accessor,
|
||||
};
|
||||
|
||||
bool is_empty() const { return m_type == Type::Empty; }
|
||||
|
@ -55,7 +56,8 @@ public:
|
|||
bool is_object() const { return m_type == Type::Object; }
|
||||
bool is_boolean() const { return m_type == Type::Boolean; }
|
||||
bool is_symbol() const { return m_type == Type::Symbol; }
|
||||
bool is_cell() const { return is_string() || is_object(); }
|
||||
bool is_accessor() const { return m_type == Type::Accessor; };
|
||||
bool is_cell() const { return is_string() || is_accessor() || is_object(); }
|
||||
bool is_array() const;
|
||||
bool is_function() const;
|
||||
|
||||
|
@ -119,6 +121,12 @@ public:
|
|||
m_value.as_symbol = symbol;
|
||||
}
|
||||
|
||||
Value(Accessor* accessor)
|
||||
: m_type(Type::Accessor)
|
||||
{
|
||||
m_value.as_accessor = accessor;
|
||||
}
|
||||
|
||||
explicit Value(Type type)
|
||||
: m_type(type)
|
||||
{
|
||||
|
@ -183,6 +191,7 @@ public:
|
|||
String to_string_without_side_effects() const;
|
||||
|
||||
Function& as_function();
|
||||
Accessor& as_accessor();
|
||||
|
||||
i32 as_i32() const;
|
||||
size_t as_size_t() const;
|
||||
|
@ -214,6 +223,7 @@ private:
|
|||
Symbol* as_symbol;
|
||||
Object* as_object;
|
||||
Cell* as_cell;
|
||||
Accessor* as_accessor;
|
||||
} m_value;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue