diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp index 9051e86130..571e00ac3d 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp @@ -202,30 +202,25 @@ ThrowCompletionOr perform_call(Interpreter& interpreter, Value this_value return return_value; } -static Completion throw_type_error_for_callee(Bytecode::Interpreter& interpreter, auto& call, StringView callee_type) +static Completion throw_type_error_for_callee(Bytecode::Interpreter& interpreter, Value callee, StringView callee_type, Optional const& expression_string) { 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())); + if (expression_string.has_value()) + return vm.throw_completion(ErrorType::IsNotAEvaluatedFrom, callee.to_string_without_side_effects(), callee_type, interpreter.current_executable().get_string(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) +ThrowCompletionOr throw_if_needed_for_call(Interpreter& interpreter, Value callee, Op::CallType call_type, Optional const& expression_string) { - 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); + if (call_type == Op::CallType::Call && !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); 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); - ThrowCompletionOr typeof_variable(VM& vm, DeprecatedFlyString const& string) { // 1. Let val be the result of evaluating UnaryExpression. diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h index a78381611b..fdb7427fb8 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h @@ -18,8 +18,7 @@ ThrowCompletionOr get_by_value(Bytecode::Interpreter&, Value base_value, ThrowCompletionOr get_global(Bytecode::Interpreter&, IdentifierTableIndex, u32 cache_index); ThrowCompletionOr put_by_property_key(VM&, Value base, Value this_value, Value value, PropertyKey name, Op::PropertyKind kind); ThrowCompletionOr perform_call(Interpreter&, Value this_value, Op::CallType, Value callee, MarkedVector argument_values); -template -ThrowCompletionOr throw_if_needed_for_call(Interpreter&, InstructionType const&, Value callee); +ThrowCompletionOr throw_if_needed_for_call(Interpreter&, Value callee, Op::CallType, Optional const& expression_string); ThrowCompletionOr typeof_variable(VM&, DeprecatedFlyString const&); ThrowCompletionOr set_variable(VM&, DeprecatedFlyString const&, Value, Op::EnvironmentMode, Op::SetVariable::InitializationMode); Value new_function(VM&, FunctionExpression const&, Optional const& lhs_name, Optional const& home_object); diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 61f385b9dc..46b19adf38 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -1131,7 +1131,7 @@ ThrowCompletionOr Call::execute_impl(Bytecode::Interpreter& interpreter) c auto& vm = interpreter.vm(); auto callee = interpreter.reg(m_callee); - TRY(throw_if_needed_for_call(interpreter, *this, callee)); + TRY(throw_if_needed_for_call(interpreter, callee, call_type(), expression_string())); MarkedVector argument_values(vm.heap()); argument_values.ensure_capacity(m_argument_count); @@ -1145,7 +1145,7 @@ ThrowCompletionOr Call::execute_impl(Bytecode::Interpreter& interpreter) c ThrowCompletionOr CallWithArgumentArray::execute_impl(Bytecode::Interpreter& interpreter) const { auto callee = interpreter.reg(m_callee); - TRY(throw_if_needed_for_call(interpreter, *this, callee)); + TRY(throw_if_needed_for_call(interpreter, callee, call_type(), expression_string())); auto argument_values = argument_list_evaluation(interpreter); interpreter.accumulator() = TRY(perform_call(interpreter, interpreter.reg(m_this_value), call_type(), callee, move(argument_values))); return {};