Skip to content

Commit

Permalink
LibJS: Resolve the correct this value for calls in with statements
Browse files Browse the repository at this point in the history
  • Loading branch information
davidot authored and linusg committed Aug 17, 2022
1 parent 3a8dd3e commit 28e552f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Userland/Libraries/LibJS/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,15 @@ ThrowCompletionOr<CallExpression::ThisAndCallee> 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))
Expand Down

0 comments on commit 28e552f

Please sign in to comment.