diff --git a/Userland/Libraries/LibJS/Heap/GCPtr.h b/Userland/Libraries/LibJS/Heap/GCPtr.h index ed7790ab02..8a821167f6 100644 --- a/Userland/Libraries/LibJS/Heap/GCPtr.h +++ b/Userland/Libraries/LibJS/Heap/GCPtr.h @@ -23,12 +23,6 @@ public: { } - NonnullGCPtr(T const& ptr) - requires(!IsConst) - : m_ptr(&const_cast(ptr)) - { - } - template NonnullGCPtr(U& ptr) requires(IsConvertible) @@ -36,31 +30,21 @@ public: { } - template - NonnullGCPtr(U const& ptr) - requires(IsConvertible && !IsConst) - : m_ptr(&const_cast(static_cast(ptr))) + NonnullGCPtr(NonnullGCPtr const& other) + : m_ptr(other.ptr()) { } template - NonnullGCPtr(NonnullGCPtr ptr) + NonnullGCPtr(NonnullGCPtr const& other) requires(IsConvertible) - : m_ptr(ptr) + : m_ptr(other.ptr()) { } - NonnullGCPtr& operator=(T const& other) + NonnullGCPtr& operator=(NonnullGCPtr const& other) { - m_ptr = &const_cast(other); - return *this; - } - - template - NonnullGCPtr& operator=(U const& other) - requires(IsConvertible) - { - m_ptr = &const_cast(static_cast(other)); + m_ptr = other.ptr(); return *this; } @@ -68,7 +52,21 @@ public: NonnullGCPtr& operator=(NonnullGCPtr const& other) requires(IsConvertible) { - m_ptr = const_cast(static_cast(other.ptr())); + m_ptr = static_cast(other.ptr()); + return *this; + } + + NonnullGCPtr& operator=(T& other) + { + m_ptr = &other; + return *this; + } + + template + NonnullGCPtr& operator=(U& other) + requires(IsConvertible) + { + m_ptr = &static_cast(other); return *this; } @@ -96,32 +94,20 @@ public: { } - GCPtr(T const& ptr) - requires(!IsConst) - : m_ptr(&const_cast(ptr)) - { - } - GCPtr(T* ptr) : m_ptr(ptr) { } - GCPtr(T const* ptr) - requires(!IsConst) - : m_ptr(const_cast(ptr)) - { - } - - GCPtr(NonnullGCPtr ptr) - : m_ptr(ptr) + GCPtr(NonnullGCPtr const& other) + : m_ptr(other.ptr()) { } template - GCPtr(NonnullGCPtr ptr) + GCPtr(NonnullGCPtr const& other) requires(IsConvertible) - : m_ptr(ptr) + : m_ptr(other.ptr()) { } @@ -137,13 +123,13 @@ public: GCPtr& operator=(GCPtr const& other) requires(IsConvertible) { - m_ptr = const_cast(static_cast(other.ptr())); + m_ptr = static_cast(other.ptr()); return *this; } GCPtr& operator=(NonnullGCPtr const& other) { - m_ptr = const_cast(other.ptr()); + m_ptr = other.ptr(); return *this; } @@ -151,35 +137,35 @@ public: GCPtr& operator=(NonnullGCPtr const& other) requires(IsConvertible) { - m_ptr = const_cast(static_cast(other.ptr())); + m_ptr = static_cast(other.ptr()); return *this; } - GCPtr& operator=(T const& other) + GCPtr& operator=(T& other) { - m_ptr = &const_cast(other); + m_ptr = &other; return *this; } template - GCPtr& operator=(U const& other) + GCPtr& operator=(U& other) requires(IsConvertible) { - m_ptr = &const_cast(static_cast(other)); + m_ptr = &static_cast(other); return *this; } - GCPtr& operator=(T const* other) + GCPtr& operator=(T* other) { - m_ptr = const_cast(other); + m_ptr = other; return *this; } template - GCPtr& operator=(U const* other) + GCPtr& operator=(U* other) requires(IsConvertible) { - m_ptr = const_cast(static_cast(other)); + m_ptr = static_cast(other); return *this; }