diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h index ac0e8de028..e3ca74d91d 100644 --- a/Userland/Libraries/LibJS/Bytecode/Instruction.h +++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h @@ -40,6 +40,7 @@ O(Jump) \ O(JumpConditional) \ O(JumpNullish) \ + O(JumpUndefined) \ O(Call) \ O(NewFunction) \ O(Return) \ diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 6dfe48a42e..607878882a 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -195,6 +195,17 @@ void JumpNullish::execute_impl(Bytecode::Interpreter& interpreter) const interpreter.jump(m_false_target.value()); } +void JumpUndefined::execute_impl(Bytecode::Interpreter& interpreter) const +{ + VERIFY(m_true_target.has_value()); + VERIFY(m_false_target.has_value()); + auto result = interpreter.accumulator(); + if (result.is_undefined()) + interpreter.jump(m_true_target.value()); + else + interpreter.jump(m_false_target.value()); +} + void Call::execute_impl(Bytecode::Interpreter& interpreter) const { auto callee = interpreter.reg(m_callee); @@ -439,6 +450,13 @@ String JumpNullish::to_string_impl(Bytecode::Executable const&) const return String::formatted("JumpNullish null:{} nonnull:{}", true_string, false_string); } +String JumpUndefined::to_string_impl(Bytecode::Executable const&) const +{ + auto true_string = m_true_target.has_value() ? String::formatted("{}", *m_true_target) : ""; + auto false_string = m_false_target.has_value() ? String::formatted("{}", *m_false_target) : ""; + return String::formatted("JumpUndefined undefined:{} not undefined:{}", true_string, false_string); +} + String Call::to_string_impl(Bytecode::Executable const&) const { StringBuilder builder; diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 653b9d1889..af93adb28b 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -377,6 +377,17 @@ public: String to_string_impl(Bytecode::Executable const&) const; }; +class JumpUndefined final : public Jump { +public: + explicit JumpUndefined(Optional