1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

LibJS: Implement array destructuring for the bytecode interpreter

This commit is contained in:
Matthew Olsson 2021-06-13 13:40:48 -07:00 committed by Andreas Kling
parent 14fff5df06
commit 7983324639
4 changed files with 267 additions and 50 deletions

View file

@ -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";
}
}