mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
LibJS: Teach Reference to access call frame arguments directly
This commit is contained in:
parent
91fbeeab72
commit
6e0e8a8242
Notes:
sideshowbarker
2024-07-18 12:15:51 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6e0e8a82429
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Reference in a new issue