mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
LibJS: Support array rest elements in the bytecode interpreter
This commit is contained in:
committed by
Andreas Kling
parent
7983324639
commit
57b9a228ab
Notes:
sideshowbarker
2024-07-18 12:02:22 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/57b9a228ab7 Pull-request: https://github.com/SerenityOS/serenity/pull/8033 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling
@@ -124,6 +124,40 @@ void NewArray::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
interpreter.accumulator() = Array::create_from(interpreter.global_object(), elements);
|
||||
}
|
||||
|
||||
void IteratorToArray::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& vm = interpreter.vm();
|
||||
auto iterator = interpreter.accumulator().to_object(global_object);
|
||||
if (vm.exception())
|
||||
return;
|
||||
|
||||
auto array = Array::create(global_object);
|
||||
size_t index = 0;
|
||||
|
||||
while (true) {
|
||||
auto iterator_result = iterator_next(*iterator);
|
||||
if (!iterator_result)
|
||||
return;
|
||||
|
||||
auto complete = iterator_complete(global_object, *iterator_result);
|
||||
if (vm.exception())
|
||||
return;
|
||||
|
||||
if (complete) {
|
||||
interpreter.accumulator() = array;
|
||||
return;
|
||||
}
|
||||
|
||||
auto value = iterator_value(global_object, *iterator_result);
|
||||
if (vm.exception())
|
||||
return;
|
||||
|
||||
array->put(index, value);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
void NewString::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
interpreter.accumulator() = js_string(interpreter.vm(), interpreter.current_executable().get_string(m_string));
|
||||
@@ -418,6 +452,11 @@ String NewArray::to_string_impl(Bytecode::Executable const&) const
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
String IteratorToArray::to_string_impl(const Bytecode::Executable&) const
|
||||
{
|
||||
return "IteratorToArray";
|
||||
}
|
||||
|
||||
String NewString::to_string_impl(Bytecode::Executable const& executable) const
|
||||
{
|
||||
return String::formatted("NewString {} (\"{}\")", m_string, executable.string_table->get(m_string));
|
||||
|
||||
Reference in New Issue
Block a user