summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-03-21 12:18:56 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-21 16:02:11 +0100
commit1603623772c689665904880f437e402d11e1cd53 (patch)
treedad0281c0faa38b1b1efee3b4d0526b40e97ead7
parentb3b8c01ebfa1289c87c166be2c31337cec327abf (diff)
downloadserenity-1603623772c689665904880f437e402d11e1cd53.zip
LibJS: Move AST node stack from VM to Interpreter
-rw-r--r--Userland/Libraries/LibJS/AST.cpp2
-rw-r--r--Userland/Libraries/LibJS/Interpreter.cpp4
-rw-r--r--Userland/Libraries/LibJS/Interpreter.h7
-rw-r--r--Userland/Libraries/LibJS/Runtime/Exception.cpp16
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.cpp7
-rw-r--r--Userland/Libraries/LibJS/Runtime/VM.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/VM.h6
7 files changed, 29 insertions, 19 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp
index f3268b0c48..58d98faae4 100644
--- a/Userland/Libraries/LibJS/AST.cpp
+++ b/Userland/Libraries/LibJS/AST.cpp
@@ -235,7 +235,7 @@ Value CallExpression::execute(Interpreter& interpreter, GlobalObject& global_obj
}
}
- vm.call_frame().current_node = vm.current_node();
+ vm.call_frame().current_node = interpreter.current_node();
Object* new_object = nullptr;
Value result;
if (is<NewExpression>(*this)) {
diff --git a/Userland/Libraries/LibJS/Interpreter.cpp b/Userland/Libraries/LibJS/Interpreter.cpp
index e773fbd34f..5750ecb129 100644
--- a/Userland/Libraries/LibJS/Interpreter.cpp
+++ b/Userland/Libraries/LibJS/Interpreter.cpp
@@ -146,12 +146,12 @@ void Interpreter::exit_scope(const ScopeNode& scope_node)
void Interpreter::enter_node(const ASTNode& node)
{
vm().call_frame().current_node = &node;
- vm().push_ast_node(node);
+ push_ast_node(node);
}
void Interpreter::exit_node(const ASTNode&)
{
- vm().pop_ast_node();
+ pop_ast_node();
}
void Interpreter::push_scope(ScopeFrame frame)
diff --git a/Userland/Libraries/LibJS/Interpreter.h b/Userland/Libraries/LibJS/Interpreter.h
index 5efb1428da..a2b801cefa 100644
--- a/Userland/Libraries/LibJS/Interpreter.h
+++ b/Userland/Libraries/LibJS/Interpreter.h
@@ -80,6 +80,12 @@ public:
void enter_node(const ASTNode&);
void exit_node(const ASTNode&);
+ void push_ast_node(const ASTNode& node) { m_ast_nodes.append(&node); }
+ void pop_ast_node() { m_ast_nodes.take_last(); }
+
+ const ASTNode* current_node() const { return !m_ast_nodes.is_empty() ? m_ast_nodes.last() : nullptr; }
+ const Vector<const ASTNode*>& node_stack() const { return m_ast_nodes; }
+
Value execute_statement(GlobalObject&, const Statement&, ScopeType = ScopeType::Block);
private:
@@ -88,6 +94,7 @@ private:
void push_scope(ScopeFrame frame);
Vector<ScopeFrame> m_scope_stack;
+ Vector<const ASTNode*> m_ast_nodes;
NonnullRefPtr<VM> m_vm;
diff --git a/Userland/Libraries/LibJS/Runtime/Exception.cpp b/Userland/Libraries/LibJS/Runtime/Exception.cpp
index b7769581a3..f8f0f0c4c8 100644
--- a/Userland/Libraries/LibJS/Runtime/Exception.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Exception.cpp
@@ -26,6 +26,7 @@
#include <AK/String.h>
#include <LibJS/AST.h>
+#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Exception.h>
#include <LibJS/Runtime/VM.h>
@@ -34,7 +35,8 @@ namespace JS {
Exception::Exception(Value value)
: m_value(value)
{
- auto& call_stack = vm().call_stack();
+ auto& vm = this->vm();
+ auto& call_stack = vm.call_stack();
for (ssize_t i = call_stack.size() - 1; i >= 0; --i) {
String function_name = call_stack[i]->function_name;
if (function_name.is_empty())
@@ -42,11 +44,13 @@ Exception::Exception(Value value)
m_trace.append(function_name);
}
- auto& node_stack = vm().node_stack();
- for (ssize_t i = node_stack.size() - 1; i >= 0; --i) {
- auto* node = node_stack[i];
- VERIFY(node);
- m_source_ranges.append(node->source_range());
+ if (auto* interpreter = vm.interpreter_if_exists()) {
+ auto& node_stack = interpreter->node_stack();
+ for (ssize_t i = node_stack.size() - 1; i >= 0; --i) {
+ auto* node = node_stack[i];
+ VERIFY(node);
+ m_source_ranges.append(node->source_range());
+ }
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp
index f828219e76..91b58f6717 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Object.cpp
@@ -28,6 +28,7 @@
#include <AK/String.h>
#include <AK/TemporaryChange.h>
#include <LibJS/Heap/Heap.h>
+#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Accessor.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/Error.h>
@@ -901,7 +902,8 @@ Value Object::call_native_property_getter(NativeProperty& property, Value this_v
{
auto& vm = this->vm();
CallFrame call_frame;
- call_frame.current_node = property.vm().current_node();
+ if (auto* interpreter = vm.interpreter_if_exists())
+ call_frame.current_node = interpreter->current_node();
call_frame.is_strict_mode = vm.in_strict_mode();
call_frame.this_value = this_value;
vm.push_call_frame(call_frame, global_object());
@@ -916,7 +918,8 @@ void Object::call_native_property_setter(NativeProperty& property, Value this_va
{
auto& vm = this->vm();
CallFrame call_frame;
- call_frame.current_node = property.vm().current_node();
+ if (auto* interpreter = vm.interpreter_if_exists())
+ call_frame.current_node = interpreter->current_node();
call_frame.is_strict_mode = vm.in_strict_mode();
call_frame.this_value = this_value;
vm.push_call_frame(call_frame, global_object());
diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp
index 894524f20d..38e4a395fc 100644
--- a/Userland/Libraries/LibJS/Runtime/VM.cpp
+++ b/Userland/Libraries/LibJS/Runtime/VM.cpp
@@ -213,7 +213,8 @@ Value VM::construct(Function& function, Function& new_target, Optional<MarkedVal
{
CallFrame call_frame;
call_frame.callee = &function;
- call_frame.current_node = current_node();
+ if (auto* interpreter = interpreter_if_exists())
+ call_frame.current_node = interpreter->current_node();
call_frame.is_strict_mode = function.is_strict_mode();
push_call_frame(call_frame, function.global_object());
@@ -338,7 +339,8 @@ Value VM::call_internal(Function& function, Value this_value, Optional<MarkedVal
CallFrame call_frame;
call_frame.callee = &function;
- call_frame.current_node = current_node();
+ if (auto* interpreter = interpreter_if_exists())
+ call_frame.current_node = interpreter->current_node();
call_frame.is_strict_mode = function.is_strict_mode();
call_frame.function_name = function.name();
call_frame.this_value = function.bound_this().value_or(this_value);
diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h
index 1dca17e66f..025d83e25e 100644
--- a/Userland/Libraries/LibJS/Runtime/VM.h
+++ b/Userland/Libraries/LibJS/Runtime/VM.h
@@ -128,15 +128,10 @@ public:
void pop_call_frame() { m_call_stack.take_last(); }
- void push_ast_node(const ASTNode& node) { m_ast_nodes.append(&node); }
- void pop_ast_node() { m_ast_nodes.take_last(); }
-
CallFrame& call_frame() { return *m_call_stack.last(); }
const CallFrame& call_frame() const { return *m_call_stack.last(); }
const Vector<CallFrame*>& call_stack() const { return m_call_stack; }
Vector<CallFrame*>& call_stack() { return m_call_stack; }
- const ASTNode* current_node() const { return !m_ast_nodes.is_empty() ? m_ast_nodes.last() : nullptr; }
- const Vector<const ASTNode*>& node_stack() const { return m_ast_nodes; }
const ScopeObject* current_scope() const { return call_frame().scope; }
ScopeObject* current_scope() { return call_frame().scope; }
@@ -256,7 +251,6 @@ private:
Vector<Interpreter*> m_interpreters;
Vector<CallFrame*> m_call_stack;
- Vector<const ASTNode*> m_ast_nodes;
Value m_last_value;
ScopeType m_unwind_until { ScopeType::None };