فهرست منبع

LibJS/Bytecode: Move iterator_to_object to CommonImplementations

Simon Wanner 1 سال پیش
والد
کامیت
d416cef9bb

+ 12 - 0
Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp

@@ -523,4 +523,16 @@ ThrowCompletionOr<NonnullGCPtr<Object>> 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;
+}
+
 }

+ 1 - 0
Userland/Libraries/LibJS/Bytecode/CommonImplementations.h

@@ -35,5 +35,6 @@ MarkedVector<Value> argument_list_evaluation(Bytecode::Interpreter&);
 ThrowCompletionOr<void> create_variable(VM&, DeprecatedFlyString const& name, Op::EnvironmentMode, bool is_global, bool is_immutable, bool is_strict);
 ThrowCompletionOr<ECMAScriptFunctionObject*> new_class(VM&, ClassExpression const&, Optional<IdentifierTableIndex> const& lhs_name);
 ThrowCompletionOr<NonnullGCPtr<Object>> super_call_with_argument_array(VM&, Value argument_array, bool is_synthetic);
+Object* iterator_to_object(VM&, IteratorRecord);
 
 }

+ 0 - 12
Userland/Libraries/LibJS/Bytecode/Interpreter.cpp

@@ -645,18 +645,6 @@ ThrowCompletionOr<void> 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 {