1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:17:35 +00:00

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.
This commit is contained in:
Timothy Flynn 2023-06-24 11:27:30 -04:00 committed by Andreas Kling
parent 5736b53013
commit d9d245faa7
11 changed files with 299 additions and 0 deletions

View file

@ -126,6 +126,7 @@
#include <LibJS/Runtime/WeakRefPrototype.h>
#include <LibJS/Runtime/WeakSetConstructor.h>
#include <LibJS/Runtime/WeakSetPrototype.h>
#include <LibJS/Runtime/WrapForValidIteratorPrototype.h>
namespace JS {
@ -199,6 +200,7 @@ ThrowCompletionOr<void> Intrinsics::initialize_intrinsics(Realm& realm)
m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
m_generator_prototype = heap().allocate<GeneratorPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
m_wrap_for_valid_iterator_prototype = heap().allocate<WrapForValidIteratorPrototype>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
// These must be initialized before allocating...
// - AggregateErrorPrototype, which uses ErrorPrototype as its prototype
@ -356,6 +358,7 @@ void Intrinsics::visit_edges(Visitor& visitor)
visitor.visit(m_async_generator_prototype);
visitor.visit(m_generator_prototype);
visitor.visit(m_intl_segments_prototype);
visitor.visit(m_wrap_for_valid_iterator_prototype);
visitor.visit(m_eval_function);
visitor.visit(m_is_finite_function);
visitor.visit(m_is_nan_function);