mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:37:35 +00:00
LibJS: Implement generator functions (only in bytecode mode)
This commit is contained in:
parent
c53a86a3fe
commit
3234697eca
21 changed files with 407 additions and 34 deletions
40
Userland/Libraries/LibJS/Runtime/GeneratorObject.h
Normal file
40
Userland/Libraries/LibJS/Runtime/GeneratorObject.h
Normal file
|
@ -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 };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue