mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:17: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
27
Userland/Libraries/LibJS/Runtime/Iterator.cpp
Normal file
27
Userland/Libraries/LibJS/Runtime/Iterator.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/Iterator.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
ThrowCompletionOr<NonnullGCPtr<Iterator>> Iterator::create(Realm& realm, Object& prototype, IteratorRecord iterated)
|
||||
{
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<Iterator>(realm, prototype, move(iterated)));
|
||||
}
|
||||
|
||||
Iterator::Iterator(Object& prototype, IteratorRecord iterated)
|
||||
: Object(ConstructWithPrototypeTag::Tag, prototype)
|
||||
, m_iterated(move(iterated))
|
||||
{
|
||||
}
|
||||
|
||||
Iterator::Iterator(Object& prototype)
|
||||
: Iterator(prototype, {})
|
||||
{
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue