mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:47:35 +00:00
LibJS: Add an Iterator constructor and object
The Iterator object cannot be constructed directly but can be subclassed or created with `Iterator.from` (not implemented here).
This commit is contained in:
parent
428109e709
commit
5736b53013
9 changed files with 165 additions and 1 deletions
|
@ -1,11 +1,13 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
|
||||
|
@ -18,4 +20,19 @@ struct IteratorRecord {
|
|||
bool done { false }; // [[Done]]
|
||||
};
|
||||
|
||||
class Iterator : public Object {
|
||||
JS_OBJECT(Iterator, Object);
|
||||
|
||||
public:
|
||||
static ThrowCompletionOr<NonnullGCPtr<Iterator>> create(Realm&, Object& prototype, IteratorRecord iterated);
|
||||
|
||||
IteratorRecord const& iterated() const { return m_iterated; }
|
||||
|
||||
private:
|
||||
Iterator(Object& prototype, IteratorRecord iterated);
|
||||
explicit Iterator(Object& prototype);
|
||||
|
||||
IteratorRecord m_iterated; // [[Iterated]]
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue