mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:22:43 +00:00 
			
		
		
		
	LibWeb: Don't allocate XMLHttpRequestConstructor twice
add_constructor() will already allocate an XMLHttpRequestConstructor and update m_xhr_constructor accordingly, we don't have to do it ourselves. This is now in line with how all the LibJS constructors work. Also make the XHR constructor responsible for setting its "prototype" property itself, for consistency and fail-proofing. Previously we would only set it on the constructor we allocated manually but which was then thrown away, leading to the property never being set properly.
This commit is contained in:
		
							parent
							
								
									5e9f6f2e2c
								
							
						
					
					
						commit
						50b76e4cc7
					
				
					 2 changed files with 5 additions and 4 deletions
				
			
		|  | @ -85,8 +85,6 @@ void WindowObject::initialize() | ||||||
|     define_property("location", heap().allocate<LocationObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); |     define_property("location", heap().allocate<LocationObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); | ||||||
| 
 | 
 | ||||||
|     m_xhr_prototype = heap().allocate<XMLHttpRequestPrototype>(*this, *this); |     m_xhr_prototype = heap().allocate<XMLHttpRequestPrototype>(*this, *this); | ||||||
|     m_xhr_constructor = heap().allocate<XMLHttpRequestConstructor>(*this, *this); |  | ||||||
|     m_xhr_constructor->define_property("prototype", m_xhr_prototype, 0); |  | ||||||
|     add_constructor("XMLHttpRequest", m_xhr_constructor, m_xhr_prototype); |     add_constructor("XMLHttpRequest", m_xhr_constructor, m_xhr_prototype); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -26,9 +26,9 @@ | ||||||
| 
 | 
 | ||||||
| #include <LibJS/Heap/Heap.h> | #include <LibJS/Heap/Heap.h> | ||||||
| #include <LibJS/Runtime/GlobalObject.h> | #include <LibJS/Runtime/GlobalObject.h> | ||||||
| #include <LibJS/Runtime/Shape.h> |  | ||||||
| #include <LibWeb/Bindings/WindowObject.h> | #include <LibWeb/Bindings/WindowObject.h> | ||||||
| #include <LibWeb/Bindings/XMLHttpRequestConstructor.h> | #include <LibWeb/Bindings/XMLHttpRequestConstructor.h> | ||||||
|  | #include <LibWeb/Bindings/XMLHttpRequestPrototype.h> | ||||||
| #include <LibWeb/Bindings/XMLHttpRequestWrapper.h> | #include <LibWeb/Bindings/XMLHttpRequestWrapper.h> | ||||||
| #include <LibWeb/DOM/XMLHttpRequest.h> | #include <LibWeb/DOM/XMLHttpRequest.h> | ||||||
| 
 | 
 | ||||||
|  | @ -41,8 +41,11 @@ XMLHttpRequestConstructor::XMLHttpRequestConstructor(JS::GlobalObject& global_ob | ||||||
| 
 | 
 | ||||||
| void XMLHttpRequestConstructor::initialize(JS::GlobalObject& global_object) | void XMLHttpRequestConstructor::initialize(JS::GlobalObject& global_object) | ||||||
| { | { | ||||||
|  |     auto& vm = this->vm(); | ||||||
|     NativeFunction::initialize(global_object); |     NativeFunction::initialize(global_object); | ||||||
|     define_property("length", JS::Value(1), JS::Attribute::Configurable); |     auto& window = static_cast<WindowObject&>(global_object); | ||||||
|  |     define_property(vm.names.prototype, window.xhr_prototype(), 0); | ||||||
|  |     define_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable); | ||||||
| 
 | 
 | ||||||
|     define_property("UNSENT", JS::Value((i32)XMLHttpRequest::ReadyState::Unsent), JS::Attribute::Enumerable); |     define_property("UNSENT", JS::Value((i32)XMLHttpRequest::ReadyState::Unsent), JS::Attribute::Enumerable); | ||||||
|     define_property("OPENED", JS::Value((i32)XMLHttpRequest::ReadyState::Opened), JS::Attribute::Enumerable); |     define_property("OPENED", JS::Value((i32)XMLHttpRequest::ReadyState::Opened), JS::Attribute::Enumerable); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Linus Groh
						Linus Groh