| 
									
										
										
										
											2021-09-02 02:12:49 +01:00
										 |  |  |  | /*
 | 
					
						
							|  |  |  |  |  * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org> | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 16:15:49 -06:00
										 |  |  |  | #include <LibWeb/Bindings/Intrinsics.h>
 | 
					
						
							| 
									
										
										
										
											2021-09-02 02:12:49 +01:00
										 |  |  |  | #include <LibWeb/DOM/AbortController.h>
 | 
					
						
							|  |  |  |  | #include <LibWeb/DOM/AbortSignal.h>
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace Web::DOM { | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-14 20:45:54 +01:00
										 |  |  |  | WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortController>> AbortController::construct_impl(JS::Realm& realm) | 
					
						
							| 
									
										
										
										
											2022-09-02 14:59:27 +02:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-02-14 21:02:46 +01:00
										 |  |  |  |     auto signal = TRY(AbortSignal::construct_impl(realm)); | 
					
						
							| 
									
										
										
										
											2023-02-14 20:45:54 +01:00
										 |  |  |  |     return MUST_OR_THROW_OOM(realm.heap().allocate<AbortController>(realm, realm, move(signal))); | 
					
						
							| 
									
										
										
										
											2022-09-02 14:59:27 +02:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-02 02:12:49 +01:00
										 |  |  |  | // https://dom.spec.whatwg.org/#dom-abortcontroller-abortcontroller
 | 
					
						
							| 
									
										
										
										
											2022-09-25 16:15:49 -06:00
										 |  |  |  | AbortController::AbortController(JS::Realm& realm, JS::NonnullGCPtr<AbortSignal> signal) | 
					
						
							|  |  |  |  |     : PlatformObject(realm) | 
					
						
							| 
									
										
										
										
											2022-09-02 14:59:27 +02:00
										 |  |  |  |     , m_signal(move(signal)) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | AbortController::~AbortController() = default; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |  | void AbortController::initialize(JS::Realm& realm) | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |  |     Base::initialize(realm); | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  |  |     set_prototype(&Bindings::ensure_web_prototype<Bindings::AbortControllerPrototype>(realm, "AbortController")); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-02 14:59:27 +02:00
										 |  |  |  | void AbortController::visit_edges(Cell::Visitor& visitor) | 
					
						
							| 
									
										
										
										
											2021-09-02 02:12:49 +01:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-09-02 14:59:27 +02:00
										 |  |  |  |     Base::visit_edges(visitor); | 
					
						
							|  |  |  |  |     visitor.visit(m_signal.ptr()); | 
					
						
							| 
									
										
										
										
											2021-09-02 02:12:49 +01:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // https://dom.spec.whatwg.org/#dom-abortcontroller-abort
 | 
					
						
							| 
									
										
										
										
											2021-12-10 20:05:12 +00:00
										 |  |  |  | void AbortController::abort(JS::Value reason) | 
					
						
							| 
									
										
										
										
											2021-09-02 02:12:49 +01:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-12-10 20:05:12 +00:00
										 |  |  |  |     // The abort(reason) method steps are to signal abort on this’s signal with reason if it is given.
 | 
					
						
							|  |  |  |  |     m_signal->signal_abort(reason); | 
					
						
							| 
									
										
										
										
											2021-09-02 02:12:49 +01:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | } |