2020-07-09 14:58:20 -07:00
|
|
|
/*
|
2021-04-22 16:53:07 -07:00
|
|
|
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
2020-07-09 14:58:20 -07:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-09 14:58:20 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2020-07-13 08:27:20 -07:00
|
|
|
#include <AK/Function.h>
|
2021-10-20 12:10:23 -04:00
|
|
|
#include <AK/Optional.h>
|
2021-10-20 08:24:54 -04:00
|
|
|
#include <LibJS/Runtime/Completion.h>
|
2020-07-09 14:58:20 -07:00
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
2021-06-13 00:22:35 +01:00
|
|
|
// 7.4 Operations on Iterator Objects, https://tc39.es/ecma262/#sec-operations-on-iterator-objects
|
2020-07-09 14:58:20 -07:00
|
|
|
|
2021-06-02 20:52:46 +01:00
|
|
|
enum class IteratorHint {
|
|
|
|
|
Sync,
|
|
|
|
|
Async,
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-20 08:24:54 -04:00
|
|
|
ThrowCompletionOr<Object*> get_iterator(GlobalObject&, Value value, IteratorHint hint = IteratorHint::Sync, Value method = {});
|
2021-10-20 08:44:30 -04:00
|
|
|
ThrowCompletionOr<Object*> iterator_next(Object& iterator, Value value = {});
|
2021-10-20 08:56:01 -04:00
|
|
|
ThrowCompletionOr<Object*> iterator_step(GlobalObject&, Object& iterator);
|
2021-10-20 09:00:37 -04:00
|
|
|
ThrowCompletionOr<bool> iterator_complete(GlobalObject&, Object& iterator_result);
|
2021-10-20 09:05:52 -04:00
|
|
|
ThrowCompletionOr<Value> iterator_value(GlobalObject&, Object& iterator_result);
|
2021-10-20 13:36:14 -04:00
|
|
|
Completion iterator_close(Object& iterator, Completion completion);
|
2021-09-28 02:03:42 +03:00
|
|
|
Object* create_iterator_result_object(GlobalObject&, Value value, bool done);
|
2021-10-20 13:41:27 -04:00
|
|
|
ThrowCompletionOr<MarkedValueList> iterable_to_list(GlobalObject&, Value iterable, Value method = {});
|
2021-04-16 23:54:41 +03:00
|
|
|
|
2021-10-20 12:10:23 -04:00
|
|
|
using IteratorValueCallback = Function<Optional<Completion>(Value)>;
|
|
|
|
|
Completion get_iterator_values(GlobalObject& global_object, Value iterable, IteratorValueCallback callback, Value method = {});
|
2020-07-13 08:27:20 -07:00
|
|
|
|
2020-07-09 14:58:20 -07:00
|
|
|
}
|