From cf57efd252d23b8bbded57b782ccb07b519b8915 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Fri, 10 Jan 2025 17:25:42 +0300 Subject: [PATCH] LibWeb: Unload fonts when adopted style sheet is removed Add missing unloading step that we do for regular style sheets but mistakenly missed for adopted style sheets. --- Libraries/LibWeb/DOM/AdoptedStyleSheets.cpp | 8 +++++++- Libraries/LibWeb/WebIDL/ObservableArray.cpp | 9 +++++++-- Libraries/LibWeb/WebIDL/ObservableArray.h | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/DOM/AdoptedStyleSheets.cpp b/Libraries/LibWeb/DOM/AdoptedStyleSheets.cpp index 7e1e611f1cef..db57fa2f49f5 100644 --- a/Libraries/LibWeb/DOM/AdoptedStyleSheets.cpp +++ b/Libraries/LibWeb/DOM/AdoptedStyleSheets.cpp @@ -35,7 +35,13 @@ GC::Ref create_adopted_style_sheets_list(Document& docu document.invalidate_style(DOM::StyleInvalidationReason::AdoptedStyleSheetsList); return {}; }); - adopted_style_sheets->set_on_delete_an_indexed_value_callback([&document]() -> WebIDL::ExceptionOr { + adopted_style_sheets->set_on_delete_an_indexed_value_callback([&document](JS::Value value) -> WebIDL::ExceptionOr { + VERIFY(value.is_object()); + auto& object = value.as_object(); + VERIFY(is(object)); + auto& style_sheet = static_cast(object); + + document.style_computer().unload_fonts_from_sheet(style_sheet); document.style_computer().invalidate_rule_cache(); document.invalidate_style(DOM::StyleInvalidationReason::AdoptedStyleSheetsList); return {}; diff --git a/Libraries/LibWeb/WebIDL/ObservableArray.cpp b/Libraries/LibWeb/WebIDL/ObservableArray.cpp index 0f999f01d683..13c76e61570e 100644 --- a/Libraries/LibWeb/WebIDL/ObservableArray.cpp +++ b/Libraries/LibWeb/WebIDL/ObservableArray.cpp @@ -48,8 +48,13 @@ JS::ThrowCompletionOr ObservableArray::internal_set(JS::PropertyKey const& JS::ThrowCompletionOr ObservableArray::internal_delete(JS::PropertyKey const& property_key) { - if (property_key.is_number() && m_on_delete_an_indexed_value) - TRY(Bindings::throw_dom_exception_if_needed(vm(), [&] { return m_on_delete_an_indexed_value->function()(); })); + if (property_key.is_number() && m_on_delete_an_indexed_value) { + auto maybe_value_and_attributes = indexed_properties().get(property_key.as_number()); + JS::Value deleted_value; + if (maybe_value_and_attributes.has_value()) + deleted_value = maybe_value_and_attributes->value; + TRY(Bindings::throw_dom_exception_if_needed(vm(), [&] { return m_on_delete_an_indexed_value->function()(deleted_value); })); + } return JS::Array::internal_delete(property_key); } diff --git a/Libraries/LibWeb/WebIDL/ObservableArray.h b/Libraries/LibWeb/WebIDL/ObservableArray.h index e3dd4e30a263..f07b9c41bcbd 100644 --- a/Libraries/LibWeb/WebIDL/ObservableArray.h +++ b/Libraries/LibWeb/WebIDL/ObservableArray.h @@ -23,7 +23,7 @@ class ObservableArray final : public JS::Array { virtual JS::ThrowCompletionOr internal_delete(JS::PropertyKey const& property_key) override; using SetAnIndexedValueCallbackFunction = Function(JS::Value&)>; - using DeleteAnIndexedValueCallbackFunction = Function()>; + using DeleteAnIndexedValueCallbackFunction = Function(JS::Value)>; void set_on_set_an_indexed_value_callback(SetAnIndexedValueCallbackFunction&& callback); void set_on_delete_an_indexed_value_callback(DeleteAnIndexedValueCallbackFunction&& callback);