Skip to content

Commit e96ef45

Browse files
committed
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.
1 parent 47fdac7 commit e96ef45

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Libraries/LibJS/Interpreter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,14 @@ void Interpreter::gather_roots(Badge<Heap>, HashTable<Cell*>& roots)
161161
}
162162
}
163163

164+
Value Interpreter::call(Function* function, Value this_value, const Vector<Value>& arguments)
165+
{
166+
auto& call_frame = push_call_frame();
167+
call_frame.this_value = this_value;
168+
call_frame.arguments = arguments;
169+
auto result = function->call(*this, call_frame.arguments);
170+
pop_call_frame();
171+
return result;
172+
}
173+
164174
}

Libraries/LibJS/Interpreter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class Interpreter {
8484
void enter_scope(const ScopeNode&, Vector<Argument>, ScopeType);
8585
void exit_scope(const ScopeNode&);
8686

87+
Value call(Function*, Value this_value, const Vector<Value>& arguments);
88+
8789
CallFrame& push_call_frame() { m_call_stack.append({ js_undefined(), {} }); return m_call_stack.last(); }
8890
void pop_call_frame() { m_call_stack.take_last(); }
8991
Value this_value() const

0 commit comments

Comments
 (0)