| 
									
										
										
										
											2020-05-21 11:14:23 -07:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-04-22 16:53:07 -07:00
										 |  |  |  * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-04-22 22:51:19 +02:00
										 |  |  |  * Copyright (c) 2020, Linus Groh <linusg@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-05-21 11:14:23 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-05-21 11:14:23 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-16 18:26:49 -06:00
										 |  |  | #include <AK/StringView.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-27 21:48:34 +02:00
										 |  |  | #include <LibJS/Runtime/FunctionObject.h>
 | 
					
						
							| 
									
										
										
										
											2020-09-27 19:59:33 +02:00
										 |  |  | #include <LibJS/Runtime/VM.h>
 | 
					
						
							| 
									
										
										
										
											2020-05-21 11:14:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Accessor final : public Cell { | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC_CELL(Accessor, Cell); | 
					
						
							|  |  |  |     GC_DECLARE_ALLOCATOR(Accessor); | 
					
						
							| 
									
										
										
										
											2022-08-28 22:11:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-21 11:14:23 -07:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     static GC::Ref<Accessor> create(VM& vm, FunctionObject* getter, FunctionObject* setter) | 
					
						
							| 
									
										
										
										
											2020-05-21 11:14:23 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-11-14 06:13:46 +13:00
										 |  |  |         return vm.heap().allocate<Accessor>(getter, setter); | 
					
						
							| 
									
										
										
										
											2020-05-21 11:14:23 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-27 21:48:34 +02:00
										 |  |  |     FunctionObject* getter() const { return m_getter; } | 
					
						
							|  |  |  |     void set_getter(FunctionObject* getter) { m_getter = getter; } | 
					
						
							| 
									
										
										
										
											2020-05-21 11:14:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-27 21:48:34 +02:00
										 |  |  |     FunctionObject* setter() const { return m_setter; } | 
					
						
							|  |  |  |     void set_setter(FunctionObject* setter) { m_setter = setter; } | 
					
						
							| 
									
										
										
										
											2020-05-23 23:27:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-28 14:33:36 +01:00
										 |  |  |     void visit_edges(Cell::Visitor& visitor) override | 
					
						
							| 
									
										
										
										
											2020-05-21 11:14:23 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-03-20 13:37:11 -07:00
										 |  |  |         Base::visit_edges(visitor); | 
					
						
							| 
									
										
										
										
											2020-05-21 11:14:23 -07:00
										 |  |  |         visitor.visit(m_getter); | 
					
						
							|  |  |  |         visitor.visit(m_setter); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-08-28 23:51:28 +02:00
										 |  |  |     Accessor(FunctionObject* getter, FunctionObject* setter) | 
					
						
							|  |  |  |         : m_getter(getter) | 
					
						
							|  |  |  |         , m_setter(setter) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ptr<FunctionObject> m_getter; | 
					
						
							|  |  |  |     GC::Ptr<FunctionObject> m_setter; | 
					
						
							| 
									
										
										
										
											2020-05-21 11:14:23 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |