summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-06-11 10:46:46 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-11 10:46:46 +0200
commitaf48a066c6c92377bb01d50c83c5a8a6b89ffd27 (patch)
tree9d802003dc3e81af02b40745225724a84a27581f /Userland/Libraries
parent749a3b9245d83101ea6ef19c7a4be2ed454ed292 (diff)
downloadserenity-af48a066c6c92377bb01d50c83c5a8a6b89ffd27.zip
LibJS: Add bytecode generation for FunctionExpression :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/AST.h2
-rw-r--r--Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp5
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp2
3 files changed, 8 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h
index ebc5967c03..25ba50f0c9 100644
--- a/Userland/Libraries/LibJS/AST.h
+++ b/Userland/Libraries/LibJS/AST.h
@@ -308,6 +308,8 @@ public:
bool cannot_auto_rename() const { return m_cannot_auto_rename; }
void set_cannot_auto_rename() { m_cannot_auto_rename = true; }
+ virtual void generate_bytecode(Bytecode::Generator&) const override;
+
private:
bool m_cannot_auto_rename { false };
};
diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
index 9b0c95b749..e9e82a6484 100644
--- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
@@ -605,6 +605,11 @@ void FunctionDeclaration::generate_bytecode(Bytecode::Generator&) const
{
}
+void FunctionExpression::generate_bytecode(Bytecode::Generator& generator) const
+{
+ generator.emit<Bytecode::Op::NewFunction>(*this);
+}
+
void VariableDeclaration::generate_bytecode(Bytecode::Generator& generator) const
{
for (auto& declarator : m_declarations) {
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp
index 265556b9b1..3776197f58 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp
@@ -218,7 +218,7 @@ void Call::execute(Bytecode::Interpreter& interpreter) const
void NewFunction::execute(Bytecode::Interpreter& interpreter) const
{
auto& vm = interpreter.vm();
- interpreter.accumulator() = ScriptFunction::create(interpreter.global_object(), m_function_node.name(), m_function_node.body(), m_function_node.parameters(), m_function_node.function_length(), vm.current_scope(), m_function_node.is_generator(), m_function_node.is_strict_mode());
+ interpreter.accumulator() = ScriptFunction::create(interpreter.global_object(), m_function_node.name(), m_function_node.body(), m_function_node.parameters(), m_function_node.function_length(), vm.current_scope(), m_function_node.is_generator(), m_function_node.is_strict_mode(), m_function_node.is_arrow_function());
}
void Return::execute(Bytecode::Interpreter& interpreter) const