1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 04:55:09 +00:00

LibJS/Bytecode: Check if eval function is a function

When overriding 'eval' to a non-function value, the interpreter would
crash. Now it handles this case swiftly, throwing a TypeError.
This commit is contained in:
Jesús (gsus) Lapastora 2023-11-09 21:53:22 +01:00 committed by Andreas Kling
parent a9ef65e64a
commit 1850652881
2 changed files with 7 additions and 1 deletions

View file

@ -233,7 +233,8 @@ static Completion throw_type_error_for_callee(Bytecode::Interpreter& interpreter
ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter& interpreter, Value callee, Op::CallType call_type, Optional<StringTableIndex> 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);