mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-28 11:02:36 +00:00 
			
		
		
		
	 83bd675477
			
		
	
	
		83bd675477
		
	
	
	
	
		
			
			Instead of iterating *all* swept cells when pruning weak containers, only iterate the cells actually *in* the container. Also, instead of compiling a list of all swept cells, we can simply check the Cell::state() flag to know if something should be pruned.
		
			
				
	
	
		
			55 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/SinglyLinkedList.h>
 | |
| #include <LibJS/Runtime/FunctionObject.h>
 | |
| #include <LibJS/Runtime/GlobalObject.h>
 | |
| #include <LibJS/Runtime/Object.h>
 | |
| #include <LibJS/Runtime/Value.h>
 | |
| #include <LibJS/Runtime/WeakContainer.h>
 | |
| 
 | |
| namespace JS {
 | |
| 
 | |
| class FinalizationRegistry final
 | |
|     : public Object
 | |
|     , public WeakContainer {
 | |
|     JS_OBJECT(FinalizationRegistry, Object);
 | |
| 
 | |
| public:
 | |
|     static FinalizationRegistry* create(GlobalObject&, FunctionObject&);
 | |
| 
 | |
|     explicit FinalizationRegistry(FunctionObject&, Object& prototype);
 | |
|     virtual ~FinalizationRegistry() override;
 | |
| 
 | |
|     void add_finalization_record(Cell& target, Value held_value, Object* unregister_token);
 | |
|     bool remove_by_token(Object& unregister_token);
 | |
|     void cleanup(FunctionObject* callback = nullptr);
 | |
| 
 | |
|     virtual void remove_dead_cells(Badge<Heap>) override;
 | |
| 
 | |
| private:
 | |
|     virtual void visit_edges(Visitor& visitor) override;
 | |
| 
 | |
| #ifdef JS_TRACK_ZOMBIE_CELLS
 | |
|     virtual void did_become_zombie() override
 | |
|     {
 | |
|         deregister();
 | |
|     }
 | |
| #endif
 | |
| 
 | |
|     FunctionObject* m_cleanup_callback { nullptr };
 | |
| 
 | |
|     struct FinalizationRecord {
 | |
|         Cell* target { nullptr };
 | |
|         Value held_value;
 | |
|         Object* unregister_token { nullptr };
 | |
|     };
 | |
|     SinglyLinkedList<FinalizationRecord> m_records;
 | |
| };
 | |
| 
 | |
| }
 |