mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 18:57:34 +00:00
LibJS: Teach Reference to access call frame arguments directly
This commit is contained in:
parent
91fbeeab72
commit
6e0e8a8242
3 changed files with 20 additions and 0 deletions
|
@ -668,6 +668,8 @@ Reference Expression::to_reference(Interpreter&, GlobalObject&) const
|
||||||
|
|
||||||
Reference Identifier::to_reference(Interpreter& 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());
|
return interpreter.vm().get_reference(string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,11 @@ void Reference::put(GlobalObject& global_object, Value value)
|
||||||
return;
|
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() || is_global_variable()) {
|
||||||
if (is_local_variable())
|
if (is_local_variable())
|
||||||
vm.set_variable(m_name.to_string(), value, global_object);
|
vm.set_variable(m_name.to_string(), value, global_object);
|
||||||
|
@ -68,6 +73,9 @@ Value Reference::get(GlobalObject& global_object)
|
||||||
return {};
|
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()) {
|
if (is_local_variable() || is_global_variable()) {
|
||||||
Value value;
|
Value value;
|
||||||
if (is_local_variable())
|
if (is_local_variable())
|
||||||
|
|
|
@ -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; }
|
Value base() const { return m_base; }
|
||||||
const PropertyName& name() const { return m_name; }
|
const PropertyName& name() const { return m_name; }
|
||||||
bool is_strict() const { return m_strict; }
|
bool is_strict() const { return m_strict; }
|
||||||
|
@ -74,6 +83,7 @@ private:
|
||||||
|
|
||||||
Value m_base;
|
Value m_base;
|
||||||
PropertyName m_name;
|
PropertyName m_name;
|
||||||
|
Optional<size_t> m_call_frame_argument_index;
|
||||||
bool m_strict { false };
|
bool m_strict { false };
|
||||||
bool m_local_variable { false };
|
bool m_local_variable { false };
|
||||||
bool m_global_variable { false };
|
bool m_global_variable { false };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue