diff options
author | Matthew Olsson <matthewcolsson@gmail.com> | 2021-06-13 13:40:48 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-19 09:38:26 +0200 |
commit | 79833246397359cceb83350dff8848d159c9eb29 (patch) | |
tree | c5e9d9120e46f699b3304a5b4f497b17bed79d5e /Userland/Libraries/LibJS/Bytecode/Op.cpp | |
parent | 14fff5df06afb574e2a1a2df8c9f1c1ea5668f66 (diff) | |
download | serenity-79833246397359cceb83350dff8848d159c9eb29.zip |
LibJS: Implement array destructuring for the bytecode interpreter
Diffstat (limited to 'Userland/Libraries/LibJS/Bytecode/Op.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Op.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
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 <LibJS/Runtime/Array.h> #include <LibJS/Runtime/BigInt.h> #include <LibJS/Runtime/GlobalObject.h> +#include <LibJS/Runtime/IteratorOperations.h> #include <LibJS/Runtime/LexicalEnvironment.h> #include <LibJS/Runtime/ScopeObject.h> #include <LibJS/Runtime/ScriptFunction.h> @@ -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"; +} + } |