mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 08:52:44 +00:00 
			
		
		
		
	 521ed0e911
			
		
	
	
		521ed0e911
		
	
	
	
	
		
			
			We have two known PlatformObjects that need to implement some of the behavior of LegacyPlatformObjects to date: Window, and HTMLFormElement. To make this not require double (or virtual) inheritance of PlatformObject, move the behavior of LegacyPlatformObject into PlatformObject. The selection of LegacyPlatformObject behavior is done with a new bitfield of feature flags instead of a dozen virtual functions that return bool. This change simplifies every class involved in the diff with the notable exception of Window, which now needs some ugly const casts to implement named property access.
		
			
				
	
	
		
			40 lines
		
	
	
	
		
			923 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
	
		
			923 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibWeb/Bindings/Intrinsics.h>
 | |
| #include <LibWeb/DOM/Node.h>
 | |
| #include <LibWeb/DOM/NodeList.h>
 | |
| 
 | |
| namespace Web::DOM {
 | |
| 
 | |
| NodeList::NodeList(JS::Realm& realm)
 | |
|     : PlatformObject(realm)
 | |
| {
 | |
|     m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = true };
 | |
| }
 | |
| 
 | |
| NodeList::~NodeList() = default;
 | |
| 
 | |
| void NodeList::initialize(JS::Realm& realm)
 | |
| {
 | |
|     Base::initialize(realm);
 | |
|     set_prototype(&Bindings::ensure_web_prototype<Bindings::NodeListPrototype>(realm, "NodeList"_fly_string));
 | |
| }
 | |
| 
 | |
| WebIDL::ExceptionOr<JS::Value> NodeList::item_value(size_t index) const
 | |
| {
 | |
|     auto* node = item(index);
 | |
|     if (!node)
 | |
|         return JS::js_undefined();
 | |
|     return const_cast<Node*>(node);
 | |
| }
 | |
| 
 | |
| bool NodeList::is_supported_property_index(u32 index) const
 | |
| {
 | |
|     return index < length();
 | |
| }
 | |
| 
 | |
| }
 |