summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Bytecode/Generator.h
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-11-11 00:46:07 +0330
committerLinus Groh <mail@linusgroh.de>2021-11-12 13:01:59 +0000
commit3b0bf05fa54d173c9f2143732326b7c7454063ab (patch)
treeb013d5e9d60370b4c7b58609607b0dca9772ef83 /Userland/Libraries/LibJS/Bytecode/Generator.h
parentc604e95993875b1824ef94eba5e474ea2981cea3 (diff)
downloadserenity-3b0bf05fa54d173c9f2143732326b7c7454063ab.zip
LibJS: Implement async functions as generator functions in BC mode
This applies a simple transformation, and adds a simple wrapper that translates the generator interface to the async function interface.
Diffstat (limited to 'Userland/Libraries/LibJS/Bytecode/Generator.h')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Generator.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/Generator.h b/Userland/Libraries/LibJS/Bytecode/Generator.h
index 669f05a327..6e5f520c79 100644
--- a/Userland/Libraries/LibJS/Bytecode/Generator.h
+++ b/Userland/Libraries/LibJS/Bytecode/Generator.h
@@ -17,12 +17,13 @@
#include <LibJS/Bytecode/Register.h>
#include <LibJS/Bytecode/StringTable.h>
#include <LibJS/Forward.h>
+#include <LibJS/Runtime/FunctionKind.h>
namespace JS::Bytecode {
class Generator {
public:
- static Executable generate(ASTNode const&, bool is_in_generator_function = false);
+ static Executable generate(ASTNode const&, FunctionKind = FunctionKind::Regular);
Register allocate_register();
@@ -111,9 +112,9 @@ public:
return m_identifier_table->insert(move(string));
}
- bool is_in_generator_function() const { return m_is_in_generator_function; }
- void enter_generator_context() { m_is_in_generator_function = true; }
- void leave_generator_context() { m_is_in_generator_function = false; }
+ bool is_in_generator_or_async_function() const { return m_enclosing_function_kind == FunctionKind::Async || m_enclosing_function_kind == FunctionKind::Generator; }
+ bool is_in_generator_function() const { return m_enclosing_function_kind == FunctionKind::Generator; }
+ bool is_in_async_function() const { return m_enclosing_function_kind == FunctionKind::Async; }
private:
Generator();
@@ -129,7 +130,7 @@ private:
u32 m_next_register { 2 };
u32 m_next_block { 1 };
- bool m_is_in_generator_function { false };
+ FunctionKind m_enclosing_function_kind { FunctionKind::Regular };
Vector<Label> m_continuable_scopes;
Vector<Label> m_breakable_scopes;
};