1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

LibJS: Implement proper Iterator records

Instead of using plain objects as Iterator records, causes confusion
about the object itself actually being its [[Iterator]] slot, and
requires non-standard type conversion shenanigans fpr the [[NextValue]]
and [[Done]] internal slots,  implement a proper Iterator record struct
and use it throughout.

Also annotate the remaining Iterator AOs with spec comments while we're
here.
This commit is contained in:
Linus Groh 2022-01-09 19:12:24 +01:00
parent e141f1e976
commit 09a11fa6ea
17 changed files with 337 additions and 209 deletions

View file

@ -1,11 +1,13 @@
/*
* Copyright (c) 2021, David Tuin <davidot@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Runtime/Iterator.h>
#include <LibJS/Runtime/Object.h>
namespace JS {
@ -15,18 +17,19 @@ class AsyncFromSyncIterator final : public Object {
JS_OBJECT(AsyncFromSyncIterator, Object);
public:
static AsyncFromSyncIterator* create(GlobalObject&, Object* sync_iterator_record);
static AsyncFromSyncIterator* create(GlobalObject&, Iterator sync_iterator_record);
explicit AsyncFromSyncIterator(GlobalObject&, Object* sync_iterator_record);
explicit AsyncFromSyncIterator(GlobalObject&, Iterator sync_iterator_record);
virtual void initialize(GlobalObject&) override;
virtual ~AsyncFromSyncIterator() override = default;
void visit_edges(Visitor& visitor) override;
Object& sync_iterator_record() const { return *m_sync_iterator_record; }
Iterator& sync_iterator_record() { return m_sync_iterator_record; }
Iterator const& sync_iterator_record() const { return m_sync_iterator_record; }
private:
Object* m_sync_iterator_record { nullptr }; // [[SyncIteratorRecord]]
Iterator m_sync_iterator_record; // [[SyncIteratorRecord]]
};
}