From 79833246397359cceb83350dff8848d159c9eb29 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sun, 13 Jun 2021 13:40:48 -0700 Subject: LibJS: Implement array destructuring for the bytecode interpreter --- Userland/Libraries/LibJS/Bytecode/Op.cpp | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'Userland/Libraries/LibJS/Bytecode/Op.cpp') diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 607878882a..32a70f534c 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -358,6 +359,29 @@ void LoadArgument::execute_impl(Bytecode::Interpreter& interpreter) const interpreter.accumulator() = interpreter.vm().argument(m_index); } +void GetIterator::execute_impl(Bytecode::Interpreter& interpreter) const +{ + interpreter.accumulator() = get_iterator(interpreter.global_object(), interpreter.accumulator()); +} + +void IteratorNext::execute_impl(Bytecode::Interpreter& interpreter) const +{ + if (auto* object = interpreter.accumulator().to_object(interpreter.global_object())) + interpreter.accumulator() = iterator_next(*object); +} + +void IteratorResultDone::execute_impl(Bytecode::Interpreter& interpreter) const +{ + if (auto* iterator_result = interpreter.accumulator().to_object(interpreter.global_object())) + interpreter.accumulator() = Value(iterator_complete(interpreter.global_object(), *iterator_result)); +} + +void IteratorResultValue::execute_impl(Bytecode::Interpreter& interpreter) const +{ + if (auto* iterator_result = interpreter.accumulator().to_object(interpreter.global_object())) + interpreter.accumulator() = iterator_value(interpreter.global_object(), *iterator_result); +} + String Load::to_string_impl(Bytecode::Executable const&) const { return String::formatted("Load {}", m_src); @@ -552,4 +576,24 @@ String LoadArgument::to_string_impl(const Bytecode::Executable&) const return String::formatted("LoadArgument {}", m_index); } +String GetIterator::to_string_impl(Executable const&) const +{ + return "GetIterator"; +} + +String IteratorNext::to_string_impl(Executable const&) const +{ + return "IteratorNext"; +} + +String IteratorResultDone::to_string_impl(Executable const&) const +{ + return "IteratorResultDone"; +} + +String IteratorResultValue::to_string_impl(Executable const&) const +{ + return "IteratorResultValue"; +} + } -- cgit v1.2.3