diff options
author | MacDue <macdue@dueutil.tech> | 2022-11-19 01:08:51 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-19 14:37:31 +0000 |
commit | 66a428ae03e12e5990feb209533f99516e41ed78 (patch) | |
tree | e3d30497effc43c2b593fc21edc5b066d5ba4acf /Userland/Libraries/LibJS/Heap | |
parent | 3483407ddc11ed064915ab12b7b7b6439d6b0e28 (diff) | |
download | serenity-66a428ae03e12e5990feb209533f99516e41ed78.zip |
LibJS+LibWeb: Return non-const types from Ptr class operators
Even if the pointer value is const, the value they point to is not
necessarily const, so these functions should not add the qualifier.
This also removes the redundant non-const implementations of these
operators.
Diffstat (limited to 'Userland/Libraries/LibJS/Heap')
-rw-r--r-- | Userland/Libraries/LibJS/Heap/GCPtr.h | 29 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Heap/Handle.h | 30 |
2 files changed, 14 insertions, 45 deletions
diff --git a/Userland/Libraries/LibJS/Heap/GCPtr.h b/Userland/Libraries/LibJS/Heap/GCPtr.h index 8ba3654af6..b2c57be3d3 100644 --- a/Userland/Libraries/LibJS/Heap/GCPtr.h +++ b/Userland/Libraries/LibJS/Heap/GCPtr.h @@ -72,20 +72,15 @@ public: return *this; } - T* operator->() { return m_ptr; } - T const* operator->() const { return m_ptr; } + T* operator->() const { return m_ptr; } - T& operator*() { return *m_ptr; } - T const& operator*() const { return *m_ptr; } + T& operator*() const { return *m_ptr; } - T* ptr() { return m_ptr; } - T const* ptr() const { return m_ptr; } + T* ptr() const { return m_ptr; } - operator T*() { return m_ptr; } - operator T const*() const { return m_ptr; } + operator T*() const { return m_ptr; } - operator T&() { return *m_ptr; } - operator T const&() const { return *m_ptr; } + operator T&() const { return *m_ptr; } private: T* m_ptr { nullptr }; @@ -181,20 +176,14 @@ public: return *this; } - T* operator->() { return m_ptr; } - T const* operator->() const { return m_ptr; } - - T& operator*() { return *m_ptr; } - T const& operator*() const { return *m_ptr; } - - T* ptr() { return m_ptr; } - T const* ptr() const { return m_ptr; } + T* operator->() const { return m_ptr; } + T& operator*() const { return *m_ptr; } + T* ptr() const { return m_ptr; } operator bool() const { return !!m_ptr; } bool operator!() const { return !m_ptr; } - operator T*() { return m_ptr; } - operator T const*() const { return m_ptr; } + operator T*() const { return m_ptr; } private: T* m_ptr { nullptr }; diff --git a/Userland/Libraries/LibJS/Heap/Handle.h b/Userland/Libraries/LibJS/Heap/Handle.h index 4b84a7ef37..3daf556829 100644 --- a/Userland/Libraries/LibJS/Heap/Handle.h +++ b/Userland/Libraries/LibJS/Heap/Handle.h @@ -60,25 +60,14 @@ public: { } - T* cell() + T* cell() const { if (!m_impl) return nullptr; return static_cast<T*>(m_impl->cell()); } - T const* cell() const - { - if (!m_impl) - return nullptr; - return static_cast<T const*>(m_impl->cell()); - } - - T* ptr() - { - return cell(); - } - T const* ptr() const + T* ptr() const { return cell(); } @@ -88,20 +77,12 @@ public: return m_impl.is_null(); } - T* operator->() - { - return cell(); - } - T const* operator->() const + T* operator->() const { return cell(); } - T& operator*() - { - return *cell(); - } - T const& operator*() const + T& operator*() const { return *cell(); } @@ -115,8 +96,7 @@ public: return cell(); } - operator T*() { return cell(); } - operator T const*() const { return cell(); } + operator T*() const { return cell(); } private: explicit Handle(NonnullRefPtr<HandleImpl> impl) |