diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp index 446c179cf8..64d34767fa 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp @@ -207,4 +207,28 @@ ThrowCompletionOr perform_call(Interpreter& interpreter, InstructionType template ThrowCompletionOr perform_call(Interpreter&, Op::Call const&, Value, MarkedVector); template ThrowCompletionOr perform_call(Interpreter&, Op::CallWithArgumentArray const&, Value, MarkedVector); +static Completion throw_type_error_for_callee(Bytecode::Interpreter& interpreter, auto& call, StringView callee_type) +{ + auto& vm = interpreter.vm(); + auto callee = interpreter.reg(call.callee()); + + if (call.expression_string().has_value()) + return vm.throw_completion(ErrorType::IsNotAEvaluatedFrom, callee.to_string_without_side_effects(), callee_type, interpreter.current_executable().get_string(call.expression_string()->value())); + + return vm.throw_completion(ErrorType::IsNotA, callee.to_string_without_side_effects(), callee_type); +} + +template +ThrowCompletionOr throw_if_needed_for_call(Interpreter& interpreter, InstructionType const& call, Value callee) +{ + if (call.call_type() == Op::CallType::Call && !callee.is_function()) + return throw_type_error_for_callee(interpreter, call, "function"sv); + if (call.call_type() == Op::CallType::Construct && !callee.is_constructor()) + return throw_type_error_for_callee(interpreter, call, "constructor"sv); + return {}; +} + +template ThrowCompletionOr throw_if_needed_for_call(Interpreter&, Op::Call const&, Value); +template ThrowCompletionOr throw_if_needed_for_call(Interpreter&, Op::CallWithArgumentArray const&, Value); + } diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h index cf3a2debbe..219eb664b8 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h @@ -19,5 +19,7 @@ ThrowCompletionOr get_global(Bytecode::Interpreter&, IdentifierTableIndex ThrowCompletionOr put_by_property_key(VM&, Value base, Value this_value, Value value, PropertyKey name, Op::PropertyKind kind); template ThrowCompletionOr perform_call(Interpreter&, InstructionType const&, Value callee, MarkedVector argument_values); +template +ThrowCompletionOr throw_if_needed_for_call(Interpreter&, InstructionType const&, Value callee); } diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index f0e1e7a815..d1c878c647 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -1135,26 +1135,6 @@ static MarkedVector argument_list_evaluation(Bytecode::Interpreter& inter return argument_values; } -static Completion throw_type_error_for_callee(Bytecode::Interpreter& interpreter, auto& call, StringView callee_type) -{ - auto& vm = interpreter.vm(); - auto callee = interpreter.reg(call.callee()); - - if (call.expression_string().has_value()) - return vm.throw_completion(ErrorType::IsNotAEvaluatedFrom, callee.to_string_without_side_effects(), callee_type, interpreter.current_executable().get_string(call.expression_string()->value())); - - return vm.throw_completion(ErrorType::IsNotA, callee.to_string_without_side_effects(), callee_type); -} - -static ThrowCompletionOr throw_if_needed_for_call(Interpreter& interpreter, auto& call, Value callee) -{ - if (call.call_type() == CallType::Call && !callee.is_function()) - return throw_type_error_for_callee(interpreter, call, "function"sv); - if (call.call_type() == CallType::Construct && !callee.is_constructor()) - return throw_type_error_for_callee(interpreter, call, "constructor"sv); - return {}; -} - ThrowCompletionOr Call::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm();