From d416cef9bb6a71d624495713ca4841bdcc74c900 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Sun, 29 Oct 2023 15:52:54 +0100 Subject: [PATCH] LibJS/Bytecode: Move iterator_to_object to CommonImplementations --- .../LibJS/Bytecode/CommonImplementations.cpp | 12 ++++++++++++ .../Libraries/LibJS/Bytecode/CommonImplementations.h | 1 + Userland/Libraries/LibJS/Bytecode/Interpreter.cpp | 12 ------------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp index d931bfe3df..c902cdc38f 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp @@ -523,4 +523,16 @@ ThrowCompletionOr> super_call_with_argument_array(VM& vm, V return result; } +// FIXME: Since the accumulator is a Value, we store an object there and have to convert back and forth between that an Iterator records. Not great. +// Make sure to put this into the accumulator before the iterator object disappears from the stack to prevent the members from being GC'd. +Object* iterator_to_object(VM& vm, IteratorRecord iterator) +{ + auto& realm = *vm.current_realm(); + auto object = Object::create(realm, nullptr); + object->define_direct_property(vm.names.iterator, iterator.iterator, 0); + object->define_direct_property(vm.names.next, iterator.next_method, 0); + object->define_direct_property(vm.names.done, Value(iterator.done), 0); + return object; +} + } diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h index 3f1d6e54d3..f8ee84bec6 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h @@ -35,5 +35,6 @@ MarkedVector argument_list_evaluation(Bytecode::Interpreter&); ThrowCompletionOr create_variable(VM&, DeprecatedFlyString const& name, Op::EnvironmentMode, bool is_global, bool is_immutable, bool is_strict); ThrowCompletionOr new_class(VM&, ClassExpression const&, Optional const& lhs_name); ThrowCompletionOr> super_call_with_argument_array(VM&, Value argument_array, bool is_synthetic); +Object* iterator_to_object(VM&, IteratorRecord); } diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 7ede7e46af..69d8cf8557 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -645,18 +645,6 @@ ThrowCompletionOr ImportCall::execute_impl(Bytecode::Interpreter& interpre return {}; } -// FIXME: Since the accumulator is a Value, we store an object there and have to convert back and forth between that an Iterator records. Not great. -// Make sure to put this into the accumulator before the iterator object disappears from the stack to prevent the members from being GC'd. -static Object* iterator_to_object(VM& vm, IteratorRecord iterator) -{ - auto& realm = *vm.current_realm(); - auto object = Object::create(realm, nullptr); - object->define_direct_property(vm.names.iterator, iterator.iterator, 0); - object->define_direct_property(vm.names.next, iterator.next_method, 0); - object->define_direct_property(vm.names.done, Value(iterator.done), 0); - return object; -} - static IteratorRecord object_to_iterator(VM& vm, Object& object) { return IteratorRecord {