diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index f8dd6fe94f..a2b369c446 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -1003,6 +1003,10 @@ public: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; + FunctionExpression const& function_node() const { return m_function_node; } + Optional const& lhs_name() const { return m_lhs_name; } + Optional const& home_object() const { return m_home_object; } + private: FunctionExpression const& m_function_node; Optional m_lhs_name; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index b6ff7f89d5..a31f03b7d9 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -446,6 +446,30 @@ void Compiler::compile_new_array(Bytecode::Op::NewArray const& op) store_vm_register(Bytecode::Register::accumulator(), RET); } +Value cxx_new_function( + VM& vm, + FunctionExpression const& function_node, + Optional const& lhs_name, + Optional const& home_object) +{ + return Bytecode::new_function(vm, function_node, lhs_name, home_object); +} + +void Compiler::compile_new_function(Bytecode::Op::NewFunction const& op) +{ + m_assembler.mov( + Assembler::Operand::Register(ARG1), + Assembler::Operand::Imm64(bit_cast(&op.function_node()))); + m_assembler.mov( + Assembler::Operand::Register(ARG2), + Assembler::Operand::Imm64(bit_cast(&op.lhs_name()))); + m_assembler.mov( + Assembler::Operand::Register(ARG3), + Assembler::Operand::Imm64(bit_cast(&op.home_object()))); + m_assembler.native_call((void*)cxx_new_function); + store_vm_register(Bytecode::Register::accumulator(), RET); +} + static Value cxx_get_by_id(VM& vm, Value base, Bytecode::IdentifierTableIndex property, u32 cache_index) { return TRY_OR_SET_EXCEPTION(Bytecode::get_by_id(vm.bytecode_interpreter(), property, base, base, cache_index)); @@ -689,6 +713,9 @@ OwnPtr Compiler::compile(Bytecode::Executable& bytecode_execut case Bytecode::Instruction::Type::NewArray: compiler.compile_new_array(static_cast(op)); break; + case Bytecode::Instruction::Type::NewFunction: + compiler.compile_new_function(static_cast(op)); + break; case Bytecode::Instruction::Type::GetById: compiler.compile_get_by_id(static_cast(op)); break; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index 7570cc2ade..266045f663 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -63,6 +63,8 @@ private: void compile_new_string(Bytecode::Op::NewString const&); void compile_new_object(Bytecode::Op::NewObject const&); void compile_new_array(Bytecode::Op::NewArray const&); + void compile_new_function(Bytecode::Op::NewFunction const&); + void compile_get_by_id(Bytecode::Op::GetById const&); void compile_get_by_value(Bytecode::Op::GetByValue const&); void compile_get_global(Bytecode::Op::GetGlobal const&);