mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:47:44 +00:00
LibJS: Handle abrupt closures from Iterator.prototype.flatMap
This is in preparation of implementing %IteratorHelperPrototype%.return. That will invoke GeneratorResumeAbrupt, which will execute the generator with an abrupt completion. At that time, we must take care to close the current inner iterator.
This commit is contained in:
parent
c04476f09d
commit
57e7112a20
3 changed files with 40 additions and 11 deletions
|
@ -19,8 +19,9 @@ class IteratorHelper final : public GeneratorObject {
|
|||
|
||||
public:
|
||||
using Closure = JS::SafeFunction<ThrowCompletionOr<Value>(VM&, IteratorHelper&)>;
|
||||
using AbruptClosure = JS::SafeFunction<ThrowCompletionOr<Value>(VM&, IteratorHelper&, Completion const&)>;
|
||||
|
||||
static ThrowCompletionOr<NonnullGCPtr<IteratorHelper>> create(Realm&, IteratorRecord, Closure);
|
||||
static ThrowCompletionOr<NonnullGCPtr<IteratorHelper>> create(Realm&, IteratorRecord, Closure, Optional<AbruptClosure> = {});
|
||||
|
||||
IteratorRecord const& underlying_iterator() const { return m_underlying_iterator; }
|
||||
|
||||
|
@ -31,13 +32,14 @@ public:
|
|||
ThrowCompletionOr<Value> close_result(VM&, Completion);
|
||||
|
||||
private:
|
||||
IteratorHelper(Realm&, Object& prototype, IteratorRecord, Closure);
|
||||
IteratorHelper(Realm&, Object& prototype, IteratorRecord, Closure, Optional<AbruptClosure>);
|
||||
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
virtual ThrowCompletionOr<Value> execute(VM&, JS::Completion const& completion) override;
|
||||
|
||||
IteratorRecord m_underlying_iterator; // [[UnderlyingIterator]]
|
||||
Closure m_closure;
|
||||
Optional<AbruptClosure> m_abrupt_closure;
|
||||
|
||||
size_t m_counter { 0 };
|
||||
bool m_done { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue