diff options
author | Andreas Kling <kling@serenityos.org> | 2021-03-14 16:41:00 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-15 21:20:33 +0100 |
commit | 8062fc711c83d1d031585ec20a526b796b321c06 (patch) | |
tree | 32ddc3592f53c8eae908a896d26edb44f498aa5c /Userland | |
parent | 093331df06b15a5635ec9e0a76840a8e99787449 (diff) | |
download | serenity-8062fc711c83d1d031585ec20a526b796b321c06.zip |
LibJS: Add arguments.callee to our hack arguments object
arguments.callee refers to the currently executing function.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/VM.cpp | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/VM.h | 1 |
3 files changed, 5 insertions, 0 deletions
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<MarkedValueList> 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<MarkedVal VERIFY(!exception()); CallFrame call_frame; + call_frame.callee = &function; call_frame.current_node = current_node(); call_frame.is_strict_mode = function.is_strict_mode(); call_frame.function_name = function.name(); diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 7313e9301a..1dca17e66f 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/Userland/Libraries/LibJS/Runtime/VM.h @@ -58,6 +58,7 @@ struct ScopeFrame { struct CallFrame { const ASTNode* current_node; FlyString function_name; + Value callee; Value this_value; Vector<Value> arguments; Array* arguments_object { nullptr }; |