LibJS: Teach Reference to access call frame arguments directly

This commit is contained in:
Andreas Kling 2021-06-14 10:52:15 +02:00
parent 91fbeeab72
commit 6e0e8a8242
Notes: sideshowbarker 2024-07-18 12:15:51 +09:00
3 changed files with 20 additions and 0 deletions

View file

@ -668,6 +668,8 @@ Reference Expression::to_reference(Interpreter&, GlobalObject&) const
Reference Identifier::to_reference(Interpreter& interpreter, GlobalObject&) const
{
if (m_argument_index.has_value())
return Reference(Reference::CallFrameArgument, m_argument_index.value(), string());
return interpreter.vm().get_reference(string());
}

View file

@ -19,6 +19,11 @@ void Reference::put(GlobalObject& global_object, Value value)
return;
}
if (m_call_frame_argument_index.has_value()) {
global_object.vm().call_frame().arguments[m_call_frame_argument_index.value()] = value;
return;
}
if (is_local_variable() || is_global_variable()) {
if (is_local_variable())
vm.set_variable(m_name.to_string(), value, global_object);
@ -68,6 +73,9 @@ Value Reference::get(GlobalObject& global_object)
return {};
}
if (m_call_frame_argument_index.has_value())
return global_object.vm().argument(m_call_frame_argument_index.value());
if (is_local_variable() || is_global_variable()) {
Value value;
if (is_local_variable())

View file

@ -40,6 +40,15 @@ public:
{
}
enum CallFrameArgumentTag { CallFrameArgument };
Reference(CallFrameArgumentTag, size_t index, FlyString const& name)
: m_base(js_null())
, m_name(name)
, m_call_frame_argument_index(index)
, m_local_variable(true)
{
}
Value base() const { return m_base; }
const PropertyName& name() const { return m_name; }
bool is_strict() const { return m_strict; }
@ -74,6 +83,7 @@ private:
Value m_base;
PropertyName m_name;
Optional<size_t> m_call_frame_argument_index;
bool m_strict { false };
bool m_local_variable { false };
bool m_global_variable { false };