mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:02:45 +00:00 
			
		
		
		
	LibJS+LibWeb: Move native JS functions into dedicated member functions
Instead of implementing every native function as a lambda function, use static member functions instead. This makes it easier to navigate the code + backtraces look nicer. :^)
This commit is contained in:
		
							parent
							
								
									7c4e53f31e
								
							
						
					
					
						commit
						56936b97d0
					
				
					 20 changed files with 233 additions and 149 deletions
				
			
		|  | @ -39,28 +39,29 @@ namespace Bindings { | |||
| EventTargetWrapper::EventTargetWrapper(EventTarget& impl) | ||||
|     : m_impl(impl) | ||||
| { | ||||
|     put_native_function("addEventListener", [](JS::Interpreter& interpreter) -> JS::Value { | ||||
|         auto* this_object = interpreter.this_value().to_object(interpreter.heap()); | ||||
|         if (!this_object) | ||||
|             return {}; | ||||
| 
 | ||||
|         auto& arguments = interpreter.call_frame().arguments; | ||||
|         if (arguments.size() < 2) | ||||
|             return JS::js_undefined(); | ||||
| 
 | ||||
|         auto event_name = arguments[0].to_string(); | ||||
|         ASSERT(arguments[1].is_object()); | ||||
|         ASSERT(arguments[1].as_object()->is_function()); | ||||
|         auto* function = static_cast<JS::Function*>(const_cast<Object*>(arguments[1].as_object())); | ||||
|         auto listener = adopt(*new EventListener(JS::make_handle(function))); | ||||
|         static_cast<EventTargetWrapper*>(this_object)->impl().add_event_listener(event_name, move(listener)); | ||||
|         return JS::js_undefined(); | ||||
|     }); | ||||
|     put_native_function("addEventListener", add_event_listener); | ||||
| } | ||||
| 
 | ||||
| EventTargetWrapper::~EventTargetWrapper() | ||||
| { | ||||
| } | ||||
| 
 | ||||
| JS::Value EventTargetWrapper::add_event_listener(JS::Interpreter& interpreter) | ||||
| { | ||||
|     auto* this_object = interpreter.this_value().to_object(interpreter.heap()); | ||||
|     if (!this_object) | ||||
|         return {}; | ||||
|     auto& arguments = interpreter.call_frame().arguments; | ||||
|     if (arguments.size() < 2) | ||||
|         return JS::js_undefined(); | ||||
|     auto event_name = arguments[0].to_string(); | ||||
|     ASSERT(arguments[1].is_object()); | ||||
|     ASSERT(arguments[1].as_object()->is_function()); | ||||
|     auto* function = static_cast<JS::Function*>(const_cast<Object*>(arguments[1].as_object())); | ||||
|     auto listener = adopt(*new EventListener(JS::make_handle(function))); | ||||
|     static_cast<EventTargetWrapper*>(this_object)->impl().add_event_listener(event_name, move(listener)); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling