mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:32:46 +00:00 
			
		
		
		
	LibWeb: Make DOMStringMap GC-allocated
This commit is contained in:
		
							parent
							
								
									72bacba97b
								
							
						
					
					
						commit
						ae11d70b0c
					
				
					 8 changed files with 35 additions and 25 deletions
				
			
		|  | @ -5,13 +5,23 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <AK/CharacterTypes.h> | ||||
| #include <LibWeb/Bindings/DOMStringMapPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/Element.h> | ||||
| #include <LibWeb/HTML/DOMStringMap.h> | ||||
| 
 | ||||
| namespace Web::HTML { | ||||
| 
 | ||||
| DOMStringMap::DOMStringMap(DOM::Element& associated_element) | ||||
|     : m_associated_element(associated_element) | ||||
| DOMStringMap* DOMStringMap::create(DOM::Element& element) | ||||
| { | ||||
|     auto& realm = element.document().preferred_window_object().realm(); | ||||
|     return realm.heap().allocate<DOMStringMap>(realm, element); | ||||
| } | ||||
| 
 | ||||
| DOMStringMap::DOMStringMap(DOM::Element& element) | ||||
|     : PlatformObject(element.document().preferred_window_object().ensure_web_prototype<Bindings::DOMStringMapPrototype>("DOMStringMap")) | ||||
|     , m_associated_element(element) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,33 +1,29 @@ | |||
| /*
 | ||||
|  * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org> | ||||
|  * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> | ||||
|  * | ||||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <AK/RefCounted.h> | ||||
| #include <AK/Weakable.h> | ||||
| #include <LibWeb/Bindings/Wrappable.h> | ||||
| #include <LibWeb/Bindings/PlatformObject.h> | ||||
| #include <LibWeb/Forward.h> | ||||
| 
 | ||||
| namespace Web::HTML { | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/dom.html#domstringmap
 | ||||
| class DOMStringMap final | ||||
|     : public RefCounted<DOMStringMap> | ||||
|     , public Weakable<DOMStringMap> | ||||
|     , public Bindings::Wrappable { | ||||
| public: | ||||
|     using WrapperType = Bindings::DOMStringMapWrapper; | ||||
| class DOMStringMap final : public Bindings::PlatformObject { | ||||
|     JS_OBJECT(DOMStringMap, Bindings::PlatformObject); | ||||
| 
 | ||||
|     static NonnullRefPtr<DOMStringMap> create(DOM::Element& associated_element) | ||||
|     { | ||||
|         return adopt_ref(*new DOMStringMap(associated_element)); | ||||
|     } | ||||
| public: | ||||
|     static DOMStringMap* create(DOM::Element&); | ||||
|     explicit DOMStringMap(DOM::Element&); | ||||
| 
 | ||||
|     virtual ~DOMStringMap() override; | ||||
| 
 | ||||
|     DOMStringMap& impl() { return *this; } | ||||
| 
 | ||||
|     Vector<String> supported_property_names() const; | ||||
| 
 | ||||
|     String determine_value_of_named_property(String const&) const; | ||||
|  | @ -38,8 +34,6 @@ public: | |||
|     bool delete_existing_named_property(String const&); | ||||
| 
 | ||||
| private: | ||||
|     DOMStringMap(DOM::Element&); | ||||
| 
 | ||||
|     struct NameValuePair { | ||||
|         String name; | ||||
|         String value; | ||||
|  | @ -52,3 +46,8 @@ private: | |||
| }; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::HTML::DOMStringMap& object) { return &object; } | ||||
| using DOMStringMapWrapper = Web::HTML::DOMStringMap; | ||||
| } | ||||
|  |  | |||
|  | @ -30,7 +30,7 @@ namespace Web::HTML { | |||
| 
 | ||||
| HTMLElement::HTMLElement(DOM::Document& document, DOM::QualifiedName qualified_name) | ||||
|     : Element(document, move(qualified_name)) | ||||
|     , m_dataset(DOMStringMap::create(*this)) | ||||
|     , m_dataset(JS::make_handle(DOMStringMap::create(*this))) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -38,7 +38,8 @@ public: | |||
| 
 | ||||
|     bool cannot_navigate() const; | ||||
| 
 | ||||
|     NonnullRefPtr<DOMStringMap> dataset() const { return m_dataset; } | ||||
|     DOMStringMap* dataset() { return m_dataset.cell(); } | ||||
|     DOMStringMap const* dataset() const { return m_dataset.cell(); } | ||||
| 
 | ||||
|     void focus(); | ||||
| 
 | ||||
|  | @ -65,7 +66,7 @@ private: | |||
|     }; | ||||
|     ContentEditableState content_editable_state() const; | ||||
| 
 | ||||
|     NonnullRefPtr<DOMStringMap> m_dataset; | ||||
|     JS::Handle<DOMStringMap> m_dataset; | ||||
| 
 | ||||
|     // https://html.spec.whatwg.org/multipage/interaction.html#locked-for-focus
 | ||||
|     bool m_locked_for_focus { false }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling