Truly independent web browser
LibWeb: Make markAsGarbage() uproot the wrapped object too
sideshowbarkerd205df12b72b
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex 113be973623..82275c61720 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -443,6 +443,11 @@ WebIDL::ExceptionOr<void> Internals::mark_as_garbage(Utf16String const& variableTRY(environment->set_mutable_binding(vm, variable_name_fly, JS::js_undefined(), false));(void)TRY(environment->delete_binding(vm, variable_name_fly));vm.heap().uproot_cell(&value.as_cell());+ // A wrapper's wrappable is a cell of its own, so a stale stack word that points at it could still keep it alive.+ if (value.is_object()) {+ if (auto* platform_object = Bindings::as_platform_object(value.as_object()); platform_object && platform_object->wrappable())+ vm.heap().uproot_cell(platform_object->wrappable().ptr());+ }return {};}diff --git a/Tests/LibWeb/Text/input/ResizeObserver/dead-observer-does-not-skip-active-observer.html b/Tests/LibWeb/Text/input/ResizeObserver/dead-observer-does-not-skip-active-observer.htmlindex f8a7e66fff8..22517742e2f 100644--- a/Tests/LibWeb/Text/input/ResizeObserver/dead-observer-does-not-skip-active-observer.html+++ b/Tests/LibWeb/Text/input/ResizeObserver/dead-observer-does-not-skip-active-observer.html@@ -9,9 +9,10 @@<div id="active-box"></div><script>let deadBox = null;+ let deadObserver = null;function observeDeadBox() {- let deadObserver = new ResizeObserver(() => {+ deadObserver = new ResizeObserver(() => {println("dead observer callback");});@@ -25,6 +26,7 @@promiseTest(async () => {observeDeadBox();+ // Only the box is collected. The observer stays reachable, so the next gather prunes its dead observation.internals.markAsGarbage("deadBox");internals.gc();