diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp index 0fc6722b5d..8e5d9a15b2 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp @@ -233,7 +233,8 @@ static Completion throw_type_error_for_callee(Bytecode::Interpreter& interpreter ThrowCompletionOr throw_if_needed_for_call(Interpreter& interpreter, Value callee, Op::CallType call_type, Optional const& expression_string) { - if (call_type == Op::CallType::Call && !callee.is_function()) + if ((call_type == Op::CallType::Call || call_type == Op::CallType::DirectEval) + && !callee.is_function()) return throw_type_error_for_callee(interpreter, callee, "function"sv, expression_string); if (call_type == Op::CallType::Construct && !callee.is_constructor()) return throw_type_error_for_callee(interpreter, callee, "constructor"sv, expression_string); diff --git a/Userland/Libraries/LibJS/Tests/eval-aliasing.js b/Userland/Libraries/LibJS/Tests/eval-aliasing.js index 2779783535..aaa93b7037 100644 --- a/Userland/Libraries/LibJS/Tests/eval-aliasing.js +++ b/Userland/Libraries/LibJS/Tests/eval-aliasing.js @@ -13,3 +13,8 @@ test("variable named 'eval' pointing to real eval works as a direct eval", funct var eval = globalThis.eval; expect(eval("testValue")).toEqual("inner"); }); + +test("variable named 'eval' pointing to a non-function raises a TypeError", function () { + var eval = "borked"; + expect(() => eval("something").toThrowWithMessage(TypeError, "borked is not a function")); +});