1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 09:44:58 +00:00
serenity/Userland/Libraries/LibJS/Runtime/IteratorConstructor.h
Timothy Flynn d9d245faa7 LibJS: Implement Iterator.from and the WrapForValidIteratorPrototype
Iterator.from creates an Iterator from either an existing iterator or
an iterator-like object. In the latter case, it sets the prototype of
the returned iterator to WrapForValidIteratorPrototype to wrap around
the iterator-like object's iteration methods.
2023-06-26 10:39:07 +02:00

31 lines
710 B
C++

/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Forward.h>
#include <LibJS/Runtime/NativeFunction.h>
namespace JS {
class IteratorConstructor : public NativeFunction {
JS_OBJECT(IteratorConstructor, NativeFunction);
public:
virtual ThrowCompletionOr<void> initialize(Realm&) override;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
private:
explicit IteratorConstructor(Realm&);
virtual bool has_constructor() const override { return true; }
JS_DECLARE_NATIVE_FUNCTION(from);
};
}