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

LibJS: Split Function into subclasses NativeFunction and ScriptFunction

Both types of functions are now Function and implement calling via:

    virtual Value call(Interpreter&, Vector<Value> arguments);

This removes the need for CallExpression::execute() to care about which
kind of function it's calling. :^)
This commit is contained in:
Andreas Kling 2020-03-13 10:08:52 +01:00
parent de6f697eba
commit d9c7009604
9 changed files with 133 additions and 42 deletions

View file

@ -33,22 +33,16 @@ namespace JS {
class Function : public Object {
public:
Function(String name, const ScopeNode& body, Vector<String> parameters = {});
virtual ~Function();
const String& name() const { return m_name; }
const ScopeNode& body() const { return m_body; }
const Vector<String>& parameters() const { return m_parameters; };
virtual Value call(Interpreter&, Vector<Value>) = 0;
protected:
Function();
virtual const char* class_name() const override { return "Function"; }
private:
virtual bool is_function() const final { return true; }
String m_name;
const ScopeNode& m_body;
const Vector<String> m_parameters;
};
}