Skip to content

Commit

Permalink
LibWeb: Unload fonts when adopted style sheet is removed
Browse files Browse the repository at this point in the history
Add missing unloading step that we do for regular style sheets but
mistakenly missed for adopted style sheets.
  • Loading branch information
kalenikaliaksandr committed Jan 10, 2025
1 parent 0d92cd1 commit cf57efd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 7 additions & 1 deletion Libraries/LibWeb/DOM/AdoptedStyleSheets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ GC::Ref<WebIDL::ObservableArray> 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<void> {
adopted_style_sheets->set_on_delete_an_indexed_value_callback([&document](JS::Value value) -> WebIDL::ExceptionOr<void> {
VERIFY(value.is_object());
auto& object = value.as_object();
VERIFY(is<CSS::CSSStyleSheet>(object));
auto& style_sheet = static_cast<CSS::CSSStyleSheet&>(object);

document.style_computer().unload_fonts_from_sheet(style_sheet);
document.style_computer().invalidate_rule_cache();
document.invalidate_style(DOM::StyleInvalidationReason::AdoptedStyleSheetsList);
return {};
Expand Down
9 changes: 7 additions & 2 deletions Libraries/LibWeb/WebIDL/ObservableArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ JS::ThrowCompletionOr<bool> ObservableArray::internal_set(JS::PropertyKey const&

JS::ThrowCompletionOr<bool> 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);
}

Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/WebIDL/ObservableArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ObservableArray final : public JS::Array {
virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const& property_key) override;

using SetAnIndexedValueCallbackFunction = Function<ExceptionOr<void>(JS::Value&)>;
using DeleteAnIndexedValueCallbackFunction = Function<ExceptionOr<void>()>;
using DeleteAnIndexedValueCallbackFunction = Function<ExceptionOr<void>(JS::Value)>;

void set_on_set_an_indexed_value_callback(SetAnIndexedValueCallbackFunction&& callback);
void set_on_delete_an_indexed_value_callback(DeleteAnIndexedValueCallbackFunction&& callback);
Expand Down

0 comments on commit cf57efd

Please sign in to comment.