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

LibJS: Add function call spreading

Adds support for the following syntax:

    myFunction(...x, ...[1, 2, 3], ...o.foo, ...'abcd')
This commit is contained in:
Matthew Olsson 2020-05-05 22:36:24 -07:00 committed by Andreas Kling
parent 8fe821fae2
commit 107ca2e4ba
4 changed files with 72 additions and 14 deletions

View file

@ -567,7 +567,12 @@ private:
class CallExpression : public Expression {
public:
CallExpression(NonnullRefPtr<Expression> callee, NonnullRefPtrVector<Expression> arguments = {})
struct Argument {
NonnullRefPtr<Expression> value;
bool is_spread;
};
CallExpression(NonnullRefPtr<Expression> callee, Vector<Argument> arguments = {})
: m_callee(move(callee))
, m_arguments(move(arguments))
{
@ -586,12 +591,12 @@ private:
ThisAndCallee compute_this_and_callee(Interpreter&) const;
NonnullRefPtr<Expression> m_callee;
const NonnullRefPtrVector<Expression> m_arguments;
const Vector<Argument> m_arguments;
};
class NewExpression final : public CallExpression {
public:
NewExpression(NonnullRefPtr<Expression> callee, NonnullRefPtrVector<Expression> arguments = {})
NewExpression(NonnullRefPtr<Expression> callee, Vector<Argument> arguments = {})
: CallExpression(move(callee), move(arguments))
{
}