mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 14:32:46 +00:00 
			
		
		
		
	LibWeb: Make DOM Nodes keep their Document alive
In addition to being reference-counted, all nodes that are part of a document must also keep the document alive. This is achieved by adding a second ref-count to the Document object and incrementing/decrementing it whenever a node is created/destroyed in that document. This brings us much closer to a proper DOM lifetime model, although the JS bindings still need more work.
This commit is contained in:
		
							parent
							
								
									99acbbe86b
								
							
						
					
					
						commit
						f68ed6d25b
					
				
					 5 changed files with 45 additions and 11 deletions
				
			
		|  | @ -30,6 +30,7 @@ | |||
| #include <AK/NonnullRefPtr.h> | ||||
| #include <AK/TypeCasts.h> | ||||
| #include <AK/Weakable.h> | ||||
| #include <LibWeb/Forward.h> | ||||
| 
 | ||||
| namespace Web { | ||||
| 
 | ||||
|  | @ -46,17 +47,11 @@ public: | |||
|     { | ||||
|         ASSERT(m_ref_count); | ||||
|         if (!--m_ref_count) { | ||||
|             if (m_next_sibling) | ||||
|                 m_next_sibling->m_previous_sibling = m_previous_sibling; | ||||
|             if (m_previous_sibling) | ||||
|                 m_previous_sibling->m_next_sibling = m_next_sibling; | ||||
|             T* next_child; | ||||
|             for (auto* child = m_first_child; child; child = next_child) { | ||||
|                 next_child = child->m_next_sibling; | ||||
|                 child->m_parent = nullptr; | ||||
|                 child->unref(); | ||||
|             } | ||||
|             delete static_cast<T*>(this); | ||||
|             if constexpr (IsBaseOf<DOM::Node, T>::value) | ||||
|                 static_cast<T*>(this)->removed_last_ref(); | ||||
|             else | ||||
|                 delete static_cast<T*>(this); | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
|     int ref_count() const { return m_ref_count; } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling