mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:27:44 +00:00
LibJS: Add object literal getter/setter shorthand
Adds support for the following syntax: let foo = { get x() { // ... }, set x(value) { // ... } }
This commit is contained in:
parent
3a90a01dd4
commit
c35732c011
4 changed files with 117 additions and 16 deletions
|
@ -722,17 +722,24 @@ private:
|
|||
|
||||
class ObjectProperty final : public ASTNode {
|
||||
public:
|
||||
ObjectProperty(NonnullRefPtr<Expression> key, NonnullRefPtr<Expression> value)
|
||||
enum class Type {
|
||||
KeyValue,
|
||||
Getter,
|
||||
Setter,
|
||||
Spread,
|
||||
};
|
||||
|
||||
ObjectProperty(NonnullRefPtr<Expression> key, NonnullRefPtr<Expression> value, Type property_type)
|
||||
: m_key(move(key))
|
||||
, m_value(move(value))
|
||||
, m_property_type(property_type)
|
||||
{
|
||||
}
|
||||
|
||||
const Expression& key() const { return m_key; }
|
||||
const Expression& value() const { return m_value; }
|
||||
|
||||
bool is_spread() const { return m_is_spread; }
|
||||
void set_is_spread() { m_is_spread = true; }
|
||||
Type type() const { return m_property_type; }
|
||||
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Value execute(Interpreter&) const override;
|
||||
|
@ -742,7 +749,7 @@ private:
|
|||
|
||||
NonnullRefPtr<Expression> m_key;
|
||||
NonnullRefPtr<Expression> m_value;
|
||||
bool m_is_spread { false };
|
||||
Type m_property_type;
|
||||
};
|
||||
|
||||
class ObjectExpression : public Expression {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue