1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:27:46 +00:00

LibJS: Convert IteratorHelper to be a GeneratorObject

This is required for %IteratorHelperPrototype%.return, which needs to
operate on the internal slots of the base GeneratorObject. Doing so also
provides us with the appropriate VM to be used in invocations to the
overridden IteratorHelper::execute.
This commit is contained in:
Timothy Flynn 2023-07-16 15:04:59 -04:00 committed by Linus Groh
parent 82df3cee66
commit c04476f09d
4 changed files with 40 additions and 42 deletions

View file

@ -7,35 +7,34 @@
#pragma once
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/GeneratorObject.h>
#include <LibJS/Runtime/Iterator.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/SafeFunction.h>
namespace JS {
class IteratorHelper final : public Object {
JS_OBJECT(IteratorHelper, Object);
class IteratorHelper final : public GeneratorObject {
JS_OBJECT(IteratorHelper, GeneratorObject);
public:
using Closure = JS::SafeFunction<ThrowCompletionOr<Value>(IteratorHelper&)>;
using Closure = JS::SafeFunction<ThrowCompletionOr<Value>(VM&, IteratorHelper&)>;
static ThrowCompletionOr<NonnullGCPtr<IteratorHelper>> create(Realm&, IteratorRecord, Closure);
IteratorRecord const& underlying_iterator() const { return m_underlying_iterator; }
Closure& closure() { return m_closure; }
size_t counter() const { return m_counter; }
void increment_counter() { ++m_counter; }
Value result(Value);
ThrowCompletionOr<Value> close_result(Completion);
bool done() const { return m_done; }
ThrowCompletionOr<Value> close_result(VM&, Completion);
private:
IteratorHelper(Object& prototype, IteratorRecord, Closure);
IteratorHelper(Realm&, Object& prototype, IteratorRecord, Closure);
virtual void visit_edges(Visitor&) override;
virtual ThrowCompletionOr<Value> execute(VM&, JS::Completion const& completion) override;
IteratorRecord m_underlying_iterator; // [[UnderlyingIterator]]
Closure m_closure;