From 66645cdc94ed6d69afef92692053ebb8efb3bbab Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Wed, 26 Jul 2023 19:56:09 +0200 Subject: [PATCH] LibJS+LibWeb: Mark `NonnullGCPtr::ptr()` as `returns_nonnull` This invariant is enforced by the fact that `NonnullGCPtr` can only be constructed from references. This commit fixes an instance where we compared a pointer to null after we have already dereferenced it. --- Userland/Libraries/LibJS/Heap/GCPtr.h | 6 +++--- Userland/Libraries/LibWeb/Page/EventHandler.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Heap/GCPtr.h b/Userland/Libraries/LibJS/Heap/GCPtr.h index 83f67caefd3..29e05ec2be0 100644 --- a/Userland/Libraries/LibJS/Heap/GCPtr.h +++ b/Userland/Libraries/LibJS/Heap/GCPtr.h @@ -60,13 +60,13 @@ public: return *this; } - T* operator->() const { return m_ptr; } + RETURNS_NONNULL T* operator->() const { return m_ptr; } T& operator*() const { return *m_ptr; } - T* ptr() const { return m_ptr; } + RETURNS_NONNULL T* ptr() const { return m_ptr; } - operator T*() const { return m_ptr; } + RETURNS_NONNULL operator T*() const { return m_ptr; } operator T&() const { return *m_ptr; } diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index b97cab5e07b..0e9b279dd0c 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -682,7 +682,7 @@ constexpr bool should_ignore_keydown_event(u32 code_point) bool EventHandler::fire_keyboard_event(FlyString const& event_name, HTML::BrowsingContext& browsing_context, KeyCode key, unsigned int modifiers, u32 code_point) { - JS::NonnullGCPtr document = *browsing_context.active_document(); + JS::GCPtr document = browsing_context.active_document(); if (!document) return false;