mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:58:11 +00:00
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.
This commit is contained in:
parent
47fdac7cea
commit
e96ef450f6
2 changed files with 12 additions and 0 deletions
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,8 @@ public:
|
||||||
void enter_scope(const ScopeNode&, Vector<Argument>, ScopeType);
|
void enter_scope(const ScopeNode&, Vector<Argument>, ScopeType);
|
||||||
void exit_scope(const ScopeNode&);
|
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(); }
|
CallFrame& push_call_frame() { m_call_stack.append({ js_undefined(), {} }); return m_call_stack.last(); }
|
||||||
void pop_call_frame() { m_call_stack.take_last(); }
|
void pop_call_frame() { m_call_stack.take_last(); }
|
||||||
Value this_value() const
|
Value this_value() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue