mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 18:42:43 +00:00 
			
		
		
		
	LibWeb: Add a flag to pause an HTML event loop's execution
This will be used to unblock the WebContent IPC event loop while waiting for a dialog response.
This commit is contained in:
		
							parent
							
								
									894bddf62c
								
							
						
					
					
						commit
						4b8729aea6
					
				
					 2 changed files with 12 additions and 0 deletions
				
			
		|  | @ -73,6 +73,10 @@ public: | ||||||
| 
 | 
 | ||||||
|     double compute_deadline() const; |     double compute_deadline() const; | ||||||
| 
 | 
 | ||||||
|  |     // https://html.spec.whatwg.org/multipage/webappapis.html#pause
 | ||||||
|  |     void set_execution_paused(bool execution_paused) { m_execution_paused = execution_paused; } | ||||||
|  |     bool execution_paused() const { return m_execution_paused; } | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|     Type m_type { Type::Window }; |     Type m_type { Type::Window }; | ||||||
| 
 | 
 | ||||||
|  | @ -104,6 +108,8 @@ private: | ||||||
| 
 | 
 | ||||||
|     // https://html.spec.whatwg.org/multipage/browsing-the-web.html#termination-nesting-level
 |     // https://html.spec.whatwg.org/multipage/browsing-the-web.html#termination-nesting-level
 | ||||||
|     size_t m_termination_nesting_level { 0 }; |     size_t m_termination_nesting_level { 0 }; | ||||||
|  | 
 | ||||||
|  |     bool m_execution_paused { false }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| EventLoop& main_thread_event_loop(); | EventLoop& main_thread_event_loop(); | ||||||
|  |  | ||||||
|  | @ -24,6 +24,9 @@ void TaskQueue::add(NonnullOwnPtr<Task> task) | ||||||
| 
 | 
 | ||||||
| OwnPtr<Task> TaskQueue::take_first_runnable() | OwnPtr<Task> TaskQueue::take_first_runnable() | ||||||
| { | { | ||||||
|  |     if (m_event_loop.execution_paused()) | ||||||
|  |         return nullptr; | ||||||
|  | 
 | ||||||
|     for (size_t i = 0; i < m_tasks.size(); ++i) { |     for (size_t i = 0; i < m_tasks.size(); ++i) { | ||||||
|         if (m_tasks[i]->is_runnable()) |         if (m_tasks[i]->is_runnable()) | ||||||
|             return m_tasks.take(i); |             return m_tasks.take(i); | ||||||
|  | @ -33,6 +36,9 @@ OwnPtr<Task> TaskQueue::take_first_runnable() | ||||||
| 
 | 
 | ||||||
| bool TaskQueue::has_runnable_tasks() const | bool TaskQueue::has_runnable_tasks() const | ||||||
| { | { | ||||||
|  |     if (m_event_loop.execution_paused()) | ||||||
|  |         return false; | ||||||
|  | 
 | ||||||
|     for (auto& task : m_tasks) { |     for (auto& task : m_tasks) { | ||||||
|         if (task->is_runnable()) |         if (task->is_runnable()) | ||||||
|             return true; |             return true; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Flynn
						Timothy Flynn