mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 00:42:44 +00:00 
			
		
		
		
	LibJS/Bytecode: Move throw_if_needed_for_call to CommonImplementations
This commit is contained in:
		
							parent
							
								
									b56ecc7e34
								
							
						
					
					
						commit
						7fc35fde09
					
				
					 3 changed files with 26 additions and 20 deletions
				
			
		|  | @ -207,4 +207,28 @@ ThrowCompletionOr<Value> perform_call(Interpreter& interpreter, InstructionType | ||||||
| template ThrowCompletionOr<Value> perform_call(Interpreter&, Op::Call const&, Value, MarkedVector<Value>); | template ThrowCompletionOr<Value> perform_call(Interpreter&, Op::Call const&, Value, MarkedVector<Value>); | ||||||
| template ThrowCompletionOr<Value> perform_call(Interpreter&, Op::CallWithArgumentArray const&, Value, MarkedVector<Value>); | template ThrowCompletionOr<Value> perform_call(Interpreter&, Op::CallWithArgumentArray const&, Value, MarkedVector<Value>); | ||||||
| 
 | 
 | ||||||
|  | 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<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::IsNotA, callee.to_string_without_side_effects(), callee_type); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | template<typename InstructionType> | ||||||
|  | ThrowCompletionOr<void> 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<void> throw_if_needed_for_call(Interpreter&, Op::Call const&, Value); | ||||||
|  | template ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter&, Op::CallWithArgumentArray const&, Value); | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -19,5 +19,7 @@ ThrowCompletionOr<Value> get_global(Bytecode::Interpreter&, IdentifierTableIndex | ||||||
| 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); | ||||||
| template<typename InstructionType> | template<typename InstructionType> | ||||||
| ThrowCompletionOr<Value> perform_call(Interpreter&, InstructionType const&, Value callee, MarkedVector<Value> argument_values); | ThrowCompletionOr<Value> perform_call(Interpreter&, InstructionType const&, Value callee, MarkedVector<Value> argument_values); | ||||||
|  | template<typename InstructionType> | ||||||
|  | ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter&, InstructionType const&, Value callee); | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1135,26 +1135,6 @@ static MarkedVector<Value> argument_list_evaluation(Bytecode::Interpreter& inter | ||||||
|     return argument_values; |     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<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::IsNotA, callee.to_string_without_side_effects(), callee_type); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static ThrowCompletionOr<void> 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<void> Call::execute_impl(Bytecode::Interpreter& interpreter) const | ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) const | ||||||
| { | { | ||||||
|     auto& vm = interpreter.vm(); |     auto& vm = interpreter.vm(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling