summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/GeneratorObject.h
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/GeneratorObject.h')
-rw-r--r--Userland/Libraries/LibJS/Runtime/GeneratorObject.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.h b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h
new file mode 100644
index 0000000000..e25d8e8198
--- /dev/null
+++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibJS/Runtime/Object.h>
+#include <LibJS/Runtime/ScriptFunction.h>
+
+namespace JS {
+
+class GeneratorObject final : public Object {
+ JS_OBJECT(GeneratorObject, Object);
+
+public:
+ static GeneratorObject* create(GlobalObject&, Value, ScriptFunction*, ScopeObject*, Bytecode::RegisterWindow);
+ explicit GeneratorObject(GlobalObject&);
+ virtual void initialize(GlobalObject&) override;
+ virtual ~GeneratorObject() override;
+ void visit_edges(Cell::Visitor&) override;
+
+ static GeneratorObject* typed_this(VM&, GlobalObject&);
+
+private:
+ JS_DECLARE_NATIVE_FUNCTION(next);
+ JS_DECLARE_NATIVE_FUNCTION(return_);
+ JS_DECLARE_NATIVE_FUNCTION(throw_);
+
+ Value next_impl(VM&, GlobalObject&, Optional<Value> value_to_throw);
+
+ ScopeObject* m_scope { nullptr };
+ ScriptFunction* m_generating_function { nullptr };
+ Value m_previous_value;
+ Bytecode::RegisterWindow m_frame;
+ bool m_done { false };
+};
+
+}