1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

LibJS: Support "hello friends".length

The above snippet is a MemberExpression that necessitates the implicit
construction of a StringObject wrapper around a PrimitiveString.

We then do a property lookup (a "get") on the StringObject, where we
find the "length" property. This is pretty neat! :^)
This commit is contained in:
Andreas Kling 2020-03-11 18:58:19 +01:00
parent 6ec6fa1a02
commit 542108421e
6 changed files with 100 additions and 11 deletions

View file

@ -363,4 +363,22 @@ private:
virtual const char* class_name() const override { return "ObjectExpression"; }
};
class MemberExpression final : public Expression {
public:
MemberExpression(NonnullOwnPtr<Expression> object, NonnullOwnPtr<Expression> property)
: m_object(move(object))
, m_property(move(property))
{
}
virtual Value execute(Interpreter&) const override;
virtual void dump(int indent) const override;
private:
virtual const char* class_name() const override { return "MemberExpression"; }
NonnullOwnPtr<Expression> m_object;
NonnullOwnPtr<Expression> m_property;
};
}