diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-18 15:20:49 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-18 17:13:22 +0100 |
commit | e96ef450f6ffb049675dc033a561ad3791443f47 (patch) | |
tree | 8f23744315134dcc5c2625eb32729edff0f46076 | |
parent | 47fdac7cea45cd90fe0fc3900d13f6af2e00a33a (diff) | |
download | serenity-e96ef450f6ffb049675dc033a561ad3791443f47.zip |
LibJS: Add Interpreter::call(Function*, this_value, arguments)
This helper function takes care of pushing/popping a call frame so you
don't need to worry about it.
-rw-r--r-- | Libraries/LibJS/Interpreter.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibJS/Interpreter.h | 2 |
2 files changed, 12 insertions, 0 deletions
diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp index 8f36fe58e2..6c6b1563f2 100644 --- a/Libraries/LibJS/Interpreter.cpp +++ b/Libraries/LibJS/Interpreter.cpp @@ -161,4 +161,14 @@ void Interpreter::gather_roots(Badge<Heap>, HashTable<Cell*>& roots) } } +Value Interpreter::call(Function* function, Value this_value, const Vector<Value>& arguments) +{ + auto& call_frame = push_call_frame(); + call_frame.this_value = this_value; + call_frame.arguments = arguments; + auto result = function->call(*this, call_frame.arguments); + pop_call_frame(); + return result; +} + } diff --git a/Libraries/LibJS/Interpreter.h b/Libraries/LibJS/Interpreter.h index 727cc67629..fd4e92ecb8 100644 --- a/Libraries/LibJS/Interpreter.h +++ b/Libraries/LibJS/Interpreter.h @@ -84,6 +84,8 @@ public: void enter_scope(const ScopeNode&, Vector<Argument>, ScopeType); void exit_scope(const ScopeNode&); + Value call(Function*, Value this_value, const Vector<Value>& arguments); + CallFrame& push_call_frame() { m_call_stack.append({ js_undefined(), {} }); return m_call_stack.last(); } void pop_call_frame() { m_call_stack.take_last(); } Value this_value() const |