| 
									
										
										
										
											2021-09-28 02:11:55 +03:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibJS/Runtime/Array.h>
 | 
					
						
							| 
									
										
										
										
											2023-07-19 06:54:48 -04:00
										 |  |  | #include <LibJS/Runtime/Iterator.h>
 | 
					
						
							| 
									
										
										
											
												LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
											
										 
											2022-09-25 18:11:21 -06:00
										 |  |  | #include <LibWeb/Bindings/Intrinsics.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-04 14:04:42 +02:00
										 |  |  | #include <LibWeb/Bindings/URLSearchParamsIteratorPrototype.h>
 | 
					
						
							| 
									
										
										
										
											2024-02-11 19:48:56 +13:00
										 |  |  | #include <LibWeb/DOMURL/URLSearchParamsIterator.h>
 | 
					
						
							| 
									
										
										
										
											2021-09-28 02:11:55 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-09 17:49:06 -05:00
										 |  |  | namespace Web::Bindings { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | void Intrinsics::create_web_prototype_and_constructor<URLSearchParamsIteratorPrototype>(JS::Realm& realm) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-11-14 05:50:17 +13:00
										 |  |  |     auto prototype = realm.create<URLSearchParamsIteratorPrototype>(realm); | 
					
						
							| 
									
										
										
										
											2023-11-22 12:55:21 +13:00
										 |  |  |     m_prototypes.set("URLSearchParamsIterator"_fly_string, prototype); | 
					
						
							| 
									
										
										
										
											2023-01-09 17:49:06 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-11 19:48:56 +13:00
										 |  |  | namespace Web::DOMURL { | 
					
						
							| 
									
										
										
										
											2021-09-28 02:11:55 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | GC_DEFINE_ALLOCATOR(URLSearchParamsIterator); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | WebIDL::ExceptionOr<GC::Ref<URLSearchParamsIterator>> URLSearchParamsIterator::create(URLSearchParams const& url_search_params, JS::Object::PropertyKind iteration_kind) | 
					
						
							| 
									
										
										
										
											2022-09-04 14:04:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-11-14 05:50:17 +13:00
										 |  |  |     return url_search_params.realm().create<URLSearchParamsIterator>(url_search_params, iteration_kind); | 
					
						
							| 
									
										
										
										
											2022-09-04 14:04:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | URLSearchParamsIterator::URLSearchParamsIterator(URLSearchParams const& url_search_params, JS::Object::PropertyKind iteration_kind) | 
					
						
							|  |  |  |     : PlatformObject(url_search_params.realm()) | 
					
						
							|  |  |  |     , m_url_search_params(url_search_params) | 
					
						
							|  |  |  |     , m_iteration_kind(iteration_kind) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | URLSearchParamsIterator::~URLSearchParamsIterator() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  | void URLSearchParamsIterator::initialize(JS::Realm& realm) | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     Base::initialize(realm); | 
					
						
							| 
									
										
										
										
											2024-03-16 13:13:08 +01:00
										 |  |  |     WEB_SET_PROTOTYPE_FOR_INTERFACE(URLSearchParamsIterator); | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-04 14:04:42 +02:00
										 |  |  | void URLSearchParamsIterator::visit_edges(JS::Cell::Visitor& visitor) | 
					
						
							| 
									
										
										
										
											2021-09-28 02:11:55 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-09-04 14:04:42 +02:00
										 |  |  |     Base::visit_edges(visitor); | 
					
						
							| 
									
										
										
										
											2023-02-26 16:09:02 -07:00
										 |  |  |     visitor.visit(m_url_search_params); | 
					
						
							| 
									
										
										
										
											2022-09-04 14:04:42 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-09-28 02:11:55 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-04 14:04:42 +02:00
										 |  |  | JS::Object* URLSearchParamsIterator::next() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-02-26 16:09:02 -07:00
										 |  |  |     if (m_index >= m_url_search_params->m_list.size()) | 
					
						
							| 
									
										
										
										
											2022-09-04 14:04:42 +02:00
										 |  |  |         return create_iterator_result_object(vm(), JS::js_undefined(), true); | 
					
						
							| 
									
										
										
										
											2021-09-28 02:11:55 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-26 16:09:02 -07:00
										 |  |  |     auto& entry = m_url_search_params->m_list[m_index++]; | 
					
						
							| 
									
										
										
										
											2021-09-28 02:11:55 +03:00
										 |  |  |     if (m_iteration_kind == JS::Object::PropertyKind::Key) | 
					
						
							| 
									
										
										
										
											2022-12-06 22:17:27 +00:00
										 |  |  |         return create_iterator_result_object(vm(), JS::PrimitiveString::create(vm(), entry.name), false); | 
					
						
							| 
									
										
										
										
											2021-09-28 02:11:55 +03:00
										 |  |  |     else if (m_iteration_kind == JS::Object::PropertyKind::Value) | 
					
						
							| 
									
										
										
										
											2022-12-06 22:17:27 +00:00
										 |  |  |         return create_iterator_result_object(vm(), JS::PrimitiveString::create(vm(), entry.value), false); | 
					
						
							| 
									
										
										
										
											2021-09-28 02:11:55 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-06 22:17:27 +00:00
										 |  |  |     return create_iterator_result_object(vm(), JS::Array::create_from(realm(), { JS::PrimitiveString::create(vm(), entry.name), JS::PrimitiveString::create(vm(), entry.value) }), false); | 
					
						
							| 
									
										
										
										
											2021-09-28 02:11:55 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |