2022-01-09 19:12:24 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
2023-06-24 10:01:04 -04:00
|
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
2022-01-09 19:12:24 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-06-24 10:01:04 -04:00
|
|
|
#include <LibJS/Runtime/Completion.h>
|
2022-01-09 19:12:24 +01:00
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
#include <LibJS/Runtime/Value.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2022-02-18 08:46:32 -05:00
|
|
|
// 7.4.1 Iterator Records, https://tc39.es/ecma262/#sec-iterator-records
|
2023-06-23 15:35:19 -04:00
|
|
|
struct IteratorRecord {
|
2023-02-26 16:09:02 -07:00
|
|
|
GCPtr<Object> iterator; // [[Iterator]]
|
|
|
|
Value next_method; // [[NextMethod]]
|
|
|
|
bool done { false }; // [[Done]]
|
2022-01-09 19:12:24 +01:00
|
|
|
};
|
|
|
|
|
2023-06-24 10:01:04 -04:00
|
|
|
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]]
|
|
|
|
};
|
|
|
|
|
2022-01-09 19:12:24 +01:00
|
|
|
}
|