1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:18:12 +00:00

LibJS: Add argument(i) and argument_count() to Interpreter

Add some convenience accessors for retrieving arguments from the
current call frame.
This commit is contained in:
Andreas Kling 2020-04-01 22:38:59 +02:00
parent 1549c5c48b
commit cd1d369cdd
9 changed files with 49 additions and 34 deletions

View file

@ -107,6 +107,21 @@ public:
void pop_call_frame() { m_call_stack.take_last(); }
const CallFrame& call_frame() { return m_call_stack.last(); }
size_t argument_count() const
{
if (m_call_stack.is_empty())
return 0;
return m_call_stack.last().arguments.size();
}
Value argument(size_t index) const
{
if (m_call_stack.is_empty())
return {};
auto& arguments = m_call_stack.last().arguments;
return index < arguments.size() ? arguments[index] : js_undefined();
}
Value this_value() const
{
if (m_call_stack.is_empty())