1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:57:45 +00:00

LibJS: Add AsyncIteratorPrototype

This commit is contained in:
davidot 2021-11-23 14:53:02 +01:00 committed by Linus Groh
parent da42c1552c
commit 7fd38eac98
5 changed files with 59 additions and 0 deletions

View file

@ -43,6 +43,7 @@ set(SOURCES
Runtime/AsyncFunctionPrototype.cpp Runtime/AsyncFunctionPrototype.cpp
Runtime/AsyncGeneratorFunctionConstructor.cpp Runtime/AsyncGeneratorFunctionConstructor.cpp
Runtime/AsyncGeneratorFunctionPrototype.cpp Runtime/AsyncGeneratorFunctionPrototype.cpp
Runtime/AsyncIteratorPrototype.cpp
Runtime/AtomicsObject.cpp Runtime/AtomicsObject.cpp
Runtime/BigInt.cpp Runtime/BigInt.cpp
Runtime/BigIntConstructor.cpp Runtime/BigIntConstructor.cpp

View file

@ -88,6 +88,7 @@
#define JS_ENUMERATE_ITERATOR_PROTOTYPES \ #define JS_ENUMERATE_ITERATOR_PROTOTYPES \
__JS_ENUMERATE(Iterator, iterator) \ __JS_ENUMERATE(Iterator, iterator) \
__JS_ENUMERATE(ArrayIterator, array_iterator) \ __JS_ENUMERATE(ArrayIterator, array_iterator) \
__JS_ENUMERATE(AsyncIterator, async_iterator) \
__JS_ENUMERATE(MapIterator, map_iterator) \ __JS_ENUMERATE(MapIterator, map_iterator) \
__JS_ENUMERATE(RegExpStringIterator, regexp_string_iterator) \ __JS_ENUMERATE(RegExpStringIterator, regexp_string_iterator) \
__JS_ENUMERATE(SetIterator, set_iterator) \ __JS_ENUMERATE(SetIterator, set_iterator) \

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2021, David Tuin <davidot@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/AsyncIteratorPrototype.h>
namespace JS {
AsyncIteratorPrototype::AsyncIteratorPrototype(GlobalObject& global_object)
: Object(*global_object.object_prototype())
{
}
void AsyncIteratorPrototype::initialize(GlobalObject& global_object)
{
auto& vm = this->vm();
Object::initialize(global_object);
u8 attr = Attribute::Writable | Attribute::Enumerable;
define_native_function(*vm.well_known_symbol_async_iterator(), symbol_async_iterator, 0, attr);
}
// 27.1.3.1 %AsyncIteratorPrototype% [ @@asyncIterator ] ( ), https://tc39.es/ecma262/#sec-asynciteratorprototype-asynciterator
JS_DEFINE_NATIVE_FUNCTION(AsyncIteratorPrototype::symbol_async_iterator)
{
// 1. Return the this value.
return vm.this_value(global_object);
}
}

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2021, David Tuin <davidot@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Runtime/PrototypeObject.h>
namespace JS {
class AsyncIteratorPrototype final : public Object {
JS_OBJECT(AsyncIteratorPrototype, Object)
public:
explicit AsyncIteratorPrototype(GlobalObject&);
virtual void initialize(GlobalObject&) override;
virtual ~AsyncIteratorPrototype() override = default;
private:
JS_DECLARE_NATIVE_FUNCTION(symbol_async_iterator);
};
}

View file

@ -24,6 +24,7 @@
#include <LibJS/Runtime/AsyncFunctionPrototype.h> #include <LibJS/Runtime/AsyncFunctionPrototype.h>
#include <LibJS/Runtime/AsyncGeneratorFunctionConstructor.h> #include <LibJS/Runtime/AsyncGeneratorFunctionConstructor.h>
#include <LibJS/Runtime/AsyncGeneratorFunctionPrototype.h> #include <LibJS/Runtime/AsyncGeneratorFunctionPrototype.h>
#include <LibJS/Runtime/AsyncIteratorPrototype.h>
#include <LibJS/Runtime/AtomicsObject.h> #include <LibJS/Runtime/AtomicsObject.h>
#include <LibJS/Runtime/BigIntConstructor.h> #include <LibJS/Runtime/BigIntConstructor.h>
#include <LibJS/Runtime/BigIntPrototype.h> #include <LibJS/Runtime/BigIntPrototype.h>