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

LibJS: Initial class implementation; allow super expressions in object

literal methods; add EnvrionmentRecord fields and methods to
LexicalEnvironment

Adding EnvrionmentRecord's fields and methods lets us throw an exception
when |this| is not initialized, which occurs when the super constructor
in a derived class has not yet been called, or when |this| has already
been initialized (the super constructor was already called).
This commit is contained in:
Jack Karamanian 2020-06-08 13:31:21 -05:00 committed by Andreas Kling
parent a535d58cac
commit 7533fd8b02
18 changed files with 967 additions and 92 deletions

View file

@ -35,6 +35,11 @@ class Function : public Object {
JS_OBJECT(Function, Object);
public:
enum class ConstructorKind {
Base,
Derived,
};
virtual ~Function();
virtual void initialize(Interpreter&, GlobalObject&) override { }
@ -49,15 +54,15 @@ public:
BoundFunction* bind(Value bound_this_value, Vector<Value> arguments);
Value bound_this() const
{
return m_bound_this;
}
Value bound_this() const { return m_bound_this; }
const Vector<Value>& bound_arguments() const
{
return m_bound_arguments;
}
const Vector<Value>& bound_arguments() const { return m_bound_arguments; }
Value home_object() const { return m_home_object; }
void set_home_object(Value home_object) { m_home_object = home_object; }
ConstructorKind constructor_kind() const { return m_constructor_kind; };
void set_constructor_kind(ConstructorKind constructor_kind) { m_constructor_kind = constructor_kind; }
protected:
explicit Function(Object& prototype);
@ -67,6 +72,8 @@ private:
virtual bool is_function() const final { return true; }
Value m_bound_this;
Vector<Value> m_bound_arguments;
Value m_home_object;
ConstructorKind m_constructor_kind = ConstructorKind::Base;
};
}