From 8062fc711c83d1d031585ec20a526b796b321c06 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 14 Mar 2021 16:41:00 +0100 Subject: [PATCH] LibJS: Add arguments.callee to our hack arguments object arguments.callee refers to the currently executing function. --- Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h | 1 + Userland/Libraries/LibJS/Runtime/VM.cpp | 3 +++ Userland/Libraries/LibJS/Runtime/VM.h | 1 + 3 files changed, 5 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h index f77911048e..dbc332144a 100644 --- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h +++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h @@ -75,6 +75,7 @@ namespace JS { P(bind) \ P(byteLength) \ P(call) \ + P(callee) \ P(cbrt) \ P(ceil) \ P(charAt) \ diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index fe83987150..afaeaefed2 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -175,6 +175,7 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object) return possible_match.value().value; if (!call_frame().arguments_object) { call_frame().arguments_object = Array::create(global_object); + call_frame().arguments_object->put(names.callee, call_frame().callee); for (auto argument : call_frame().arguments) { call_frame().arguments_object->indexed_properties().append(argument); } @@ -211,6 +212,7 @@ Reference VM::get_reference(const FlyString& name) Value VM::construct(Function& function, Function& new_target, Optional arguments, GlobalObject& global_object) { CallFrame call_frame; + call_frame.callee = &function; call_frame.current_node = current_node(); call_frame.is_strict_mode = function.is_strict_mode(); @@ -335,6 +337,7 @@ Value VM::call_internal(Function& function, Value this_value, Optional arguments; Array* arguments_object { nullptr };