diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index c0e0252a41..121e15ae90 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -851,6 +851,7 @@ public: } StringView name() const { return m_name; } + RefPtr constructor() const { return m_constructor; } virtual Value execute(Interpreter&, GlobalObject&) const override; virtual void dump(int indent) const override; @@ -872,6 +873,7 @@ public: virtual Value execute(Interpreter&, GlobalObject&) const override; virtual void dump(int indent) const override; + virtual void generate_bytecode(Bytecode::Generator&) const override; private: NonnullRefPtr m_class_expression; diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 7f02bb0d56..6418a56a5d 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1300,4 +1300,10 @@ void SwitchStatement::generate_bytecode(Bytecode::Generator& generator) const generator.switch_to_basic_block(end_block); } +void ClassDeclaration::generate_bytecode(Bytecode::Generator& generator) const +{ + generator.emit(m_class_expression); + generator.emit(generator.intern_string(m_class_expression.ptr()->name())); +} + } diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h index 2064c4a2b1..ae98f0a5a5 100644 --- a/Userland/Libraries/LibJS/Bytecode/Instruction.h +++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h @@ -72,7 +72,8 @@ O(GetIterator) \ O(IteratorNext) \ O(IteratorResultDone) \ - O(IteratorResultValue) + O(IteratorResultValue) \ + O(NewClass) namespace JS::Bytecode { diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index c4c6be890f..e56924adc8 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -452,6 +452,11 @@ void IteratorResultValue::execute_impl(Bytecode::Interpreter& interpreter) const interpreter.accumulator() = iterator_value(interpreter.global_object(), *iterator_result); } +void NewClass::execute_impl(Bytecode::Interpreter&) const +{ + TODO(); +} + String Load::to_string_impl(Bytecode::Executable const&) const { return String::formatted("Load {}", m_src); @@ -598,6 +603,11 @@ String NewFunction::to_string_impl(Bytecode::Executable const&) const return "NewFunction"; } +String NewClass::to_string_impl(Bytecode::Executable const&) const +{ + return "NewClass"; +} + String Return::to_string_impl(Bytecode::Executable const&) const { return "Return"; diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index eafbda878f..7785ed88fe 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -484,6 +484,22 @@ private: Register m_arguments[]; }; +class NewClass final : public Instruction { +public: + explicit NewClass(ClassExpression const& class_expression) + : Instruction(Type::NewClass) + , m_class_expression(class_expression) + { + } + + void execute_impl(Bytecode::Interpreter&) const; + String to_string_impl(Bytecode::Executable const&) const; + void replace_references_impl(BasicBlock const&, BasicBlock const&) { } + +private: + ClassExpression const& m_class_expression; +}; + class NewFunction final : public Instruction { public: explicit NewFunction(FunctionNode const& function_node) diff --git a/Userland/Libraries/LibJS/Forward.h b/Userland/Libraries/LibJS/Forward.h index 3519a7e521..e10a0f74e9 100644 --- a/Userland/Libraries/LibJS/Forward.h +++ b/Userland/Libraries/LibJS/Forward.h @@ -119,6 +119,7 @@ class BigInt; class BoundFunction; class Cell; class CellAllocator; +class ClassExpression; class Console; class DeclarativeEnvironment; class DeferGC;