mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 05:12:44 +00:00 
			
		
		
		
	LibJS/Bytecode: Un-templatize throw_if_needed_for_call()
This commit is contained in:
		
							parent
							
								
									72c31fdd01
								
							
						
					
					
						commit
						bcf7cdb679
					
				
					 3 changed files with 11 additions and 17 deletions
				
			
		|  | @ -202,30 +202,25 @@ ThrowCompletionOr<Value> perform_call(Interpreter& interpreter, Value this_value | ||||||
|     return return_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<StringTableIndex> const& expression_string) | ||||||
| { | { | ||||||
|     auto& vm = interpreter.vm(); |     auto& vm = interpreter.vm(); | ||||||
|     auto callee = interpreter.reg(call.callee()); |  | ||||||
| 
 | 
 | ||||||
|     if (call.expression_string().has_value()) |     if (expression_string.has_value()) | ||||||
|         return vm.throw_completion<TypeError>(ErrorType::IsNotAEvaluatedFrom, callee.to_string_without_side_effects(), callee_type, interpreter.current_executable().get_string(call.expression_string()->value())); |         return vm.throw_completion<TypeError>(ErrorType::IsNotAEvaluatedFrom, callee.to_string_without_side_effects(), callee_type, interpreter.current_executable().get_string(expression_string->value())); | ||||||
| 
 | 
 | ||||||
|     return vm.throw_completion<TypeError>(ErrorType::IsNotA, callee.to_string_without_side_effects(), callee_type); |     return vm.throw_completion<TypeError>(ErrorType::IsNotA, callee.to_string_without_side_effects(), callee_type); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| template<typename InstructionType> | ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter& interpreter, Value callee, Op::CallType call_type, Optional<StringTableIndex> const& expression_string) | ||||||
| ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter& interpreter, InstructionType const& call, Value callee) |  | ||||||
| { | { | ||||||
|     if (call.call_type() == Op::CallType::Call && !callee.is_function()) |     if (call_type == Op::CallType::Call && !callee.is_function()) | ||||||
|         return throw_type_error_for_callee(interpreter, call, "function"sv); |         return throw_type_error_for_callee(interpreter, callee, "function"sv, expression_string); | ||||||
|     if (call.call_type() == Op::CallType::Construct && !callee.is_constructor()) |     if (call_type == Op::CallType::Construct && !callee.is_constructor()) | ||||||
|         return throw_type_error_for_callee(interpreter, call, "constructor"sv); |         return throw_type_error_for_callee(interpreter, callee, "constructor"sv, expression_string); | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| template ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter&, Op::Call const&, Value); |  | ||||||
| template ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter&, Op::CallWithArgumentArray const&, Value); |  | ||||||
| 
 |  | ||||||
| ThrowCompletionOr<Value> typeof_variable(VM& vm, DeprecatedFlyString const& string) | ThrowCompletionOr<Value> typeof_variable(VM& vm, DeprecatedFlyString const& string) | ||||||
| { | { | ||||||
|     // 1. Let val be the result of evaluating UnaryExpression.
 |     // 1. Let val be the result of evaluating UnaryExpression.
 | ||||||
|  |  | ||||||
|  | @ -18,8 +18,7 @@ ThrowCompletionOr<Value> get_by_value(Bytecode::Interpreter&, Value base_value, | ||||||
| ThrowCompletionOr<Value> get_global(Bytecode::Interpreter&, IdentifierTableIndex, u32 cache_index); | ThrowCompletionOr<Value> get_global(Bytecode::Interpreter&, IdentifierTableIndex, u32 cache_index); | ||||||
| ThrowCompletionOr<void> put_by_property_key(VM&, Value base, Value this_value, Value value, PropertyKey name, Op::PropertyKind kind); | ThrowCompletionOr<void> put_by_property_key(VM&, Value base, Value this_value, Value value, PropertyKey name, Op::PropertyKind kind); | ||||||
| ThrowCompletionOr<Value> perform_call(Interpreter&, Value this_value, Op::CallType, Value callee, MarkedVector<Value> argument_values); | ThrowCompletionOr<Value> perform_call(Interpreter&, Value this_value, Op::CallType, Value callee, MarkedVector<Value> argument_values); | ||||||
| template<typename InstructionType> | ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter&, Value callee, Op::CallType, Optional<StringTableIndex> const& expression_string); | ||||||
| ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter&, InstructionType const&, Value callee); |  | ||||||
| ThrowCompletionOr<Value> typeof_variable(VM&, DeprecatedFlyString const&); | ThrowCompletionOr<Value> typeof_variable(VM&, DeprecatedFlyString const&); | ||||||
| ThrowCompletionOr<void> set_variable(VM&, DeprecatedFlyString const&, Value, Op::EnvironmentMode, Op::SetVariable::InitializationMode); | ThrowCompletionOr<void> set_variable(VM&, DeprecatedFlyString const&, Value, Op::EnvironmentMode, Op::SetVariable::InitializationMode); | ||||||
| Value new_function(VM&, FunctionExpression const&, Optional<IdentifierTableIndex> const& lhs_name, Optional<Register> const& home_object); | Value new_function(VM&, FunctionExpression const&, Optional<IdentifierTableIndex> const& lhs_name, Optional<Register> const& home_object); | ||||||
|  |  | ||||||
|  | @ -1131,7 +1131,7 @@ ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) c | ||||||
|     auto& vm = interpreter.vm(); |     auto& vm = interpreter.vm(); | ||||||
|     auto callee = interpreter.reg(m_callee); |     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<Value> argument_values(vm.heap()); |     MarkedVector<Value> argument_values(vm.heap()); | ||||||
|     argument_values.ensure_capacity(m_argument_count); |     argument_values.ensure_capacity(m_argument_count); | ||||||
|  | @ -1145,7 +1145,7 @@ ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) c | ||||||
| ThrowCompletionOr<void> CallWithArgumentArray::execute_impl(Bytecode::Interpreter& interpreter) const | ThrowCompletionOr<void> CallWithArgumentArray::execute_impl(Bytecode::Interpreter& interpreter) const | ||||||
| { | { | ||||||
|     auto callee = interpreter.reg(m_callee); |     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); |     auto argument_values = argument_list_evaluation(interpreter); | ||||||
|     interpreter.accumulator() = TRY(perform_call(interpreter, interpreter.reg(m_this_value), call_type(), callee, move(argument_values))); |     interpreter.accumulator() = TRY(perform_call(interpreter, interpreter.reg(m_this_value), call_type(), callee, move(argument_values))); | ||||||
|     return {}; |     return {}; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling