From 0388766531bad45c77aae13e3f8064c63aaca06b Mon Sep 17 00:00:00 2001 From: networkException Date: Wed, 25 Oct 2023 12:39:01 +0200 Subject: [PATCH] LibWeb: Set module map entry before invoking callbacks This patch fixes the value of a module map entry being wrong in the callbacks invoked in the set call. Previously we would set the value in only after invoking the callbacks, leading to crashes when a callback implementation would rightfully assume the value to be set already. Resolves #20994 --- Userland/Libraries/LibWeb/HTML/Scripting/ModuleMap.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ModuleMap.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ModuleMap.cpp index c387420738..e08e3bbbd2 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ModuleMap.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ModuleMap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, networkException + * Copyright (c) 2022-2023, networkException * * SPDX-License-Identifier: BSD-2-Clause */ @@ -42,12 +42,14 @@ Optional ModuleMap::get(AK::URL const& url, DeprecatedString c AK::HashSetResult ModuleMap::set(AK::URL const& url, DeprecatedString const& type, Entry entry) { + auto value = m_values.set({ url, type }, entry); + auto callbacks = m_callbacks.get({ url, type }); if (callbacks.has_value()) for (auto const& callback : *callbacks) callback(entry); - return m_values.set({ url, type }, entry); + return value; } void ModuleMap::wait_for_change(AK::URL const& url, DeprecatedString const& type, Function callback)