From 28e552f8537059068f4fdd66263fca51902d9737 Mon Sep 17 00:00:00 2001 From: davidot Date: Wed, 17 Aug 2022 22:51:42 +0200 Subject: [PATCH] LibJS: Resolve the correct this value for calls in with statements --- Userland/Libraries/LibJS/AST.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index eafb76939d..3b779b3c5a 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -339,9 +339,15 @@ ThrowCompletionOr CallExpression::compute_this_an return ThisAndCallee { this_value, callee }; } + Value this_value = js_undefined(); + if (callee_reference.is_environment_reference()) { + if (Object* base_object = callee_reference.base_environment().with_base_object(); base_object != nullptr) + this_value = base_object; + } + // [[Call]] will handle that in non-strict mode the this value becomes the global object return ThisAndCallee { - js_undefined(), + this_value, callee_reference.is_unresolvable() ? TRY(m_callee->execute(interpreter, global_object)).release_value() : TRY(callee_reference.get_value(global_object))