From c7e6b65fd299e60385179f40a2cadee1fc28f77e Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sat, 12 Feb 2022 19:55:40 +0330 Subject: [PATCH] LibJS: Implement ClassExpression::generate_bytecode() ...and use that in ClassDeclaration::generate_bytecode(). --- Userland/Libraries/LibJS/AST.h | 1 + Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index fda6fe1e06..213aee655d 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -1373,6 +1373,7 @@ public: virtual Completion execute(Interpreter&, GlobalObject&) const override; virtual void dump(int indent) const override; + virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; bool has_name() const { return !m_name.is_empty(); } diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 15aadf65fe..1ba2a0e1c8 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1337,10 +1337,17 @@ Bytecode::CodeGenerationErrorOr SwitchStatement::generate_bytecode(Bytecod return {}; } -void ClassDeclaration::generate_bytecode(Bytecode::Generator& generator) const +Bytecode::CodeGenerationErrorOr ClassDeclaration::generate_bytecode(Bytecode::Generator& generator) const { - generator.emit(m_class_expression); - generator.emit(generator.intern_identifier(m_class_expression.ptr()->name())); + TRY(m_class_expression->generate_bytecode(generator)); + generator.emit(generator.intern_identifier(m_class_expression.ptr()->name()), Bytecode::Op::SetVariable::InitializationMode::Initialize); + return {}; +} + +Bytecode::CodeGenerationErrorOr ClassExpression::generate_bytecode(Bytecode::Generator& generator) const +{ + generator.emit(*this); + return {}; } Bytecode::CodeGenerationErrorOr ThisExpression::generate_bytecode(Bytecode::Generator& generator) const