diff --git a/Libraries/LibGC/ConservativeVector.cpp b/Libraries/LibGC/ConservativeVector.cpp index 33e6f1a3aa..6fd8b8a9b9 100644 --- a/Libraries/LibGC/ConservativeVector.cpp +++ b/Libraries/LibGC/ConservativeVector.cpp @@ -9,6 +9,11 @@ namespace GC { +ConservativeVectorBase::ConservativeVectorBase() + : ConservativeVectorBase(Heap::the()) +{ +} + ConservativeVectorBase::ConservativeVectorBase(Heap& heap) : m_heap(&heap) { diff --git a/Libraries/LibGC/ConservativeVector.h b/Libraries/LibGC/ConservativeVector.h index 4b94ef4fb3..90deb9e0e3 100644 --- a/Libraries/LibGC/ConservativeVector.h +++ b/Libraries/LibGC/ConservativeVector.h @@ -19,6 +19,7 @@ public: virtual ReadonlySpan possible_values() const = 0; protected: + ConservativeVectorBase(); explicit ConservativeVectorBase(Heap&); ~ConservativeVectorBase(); @@ -35,13 +36,13 @@ class GC_API ConservativeVector final , public Vector { public: - explicit ConservativeVector(Heap& heap) - : ConservativeVectorBase(heap) + ConservativeVector() + : ConservativeVectorBase() { } - ConservativeVector(Heap& heap, Vector const& other) - : ConservativeVectorBase(heap) + ConservativeVector(Vector const& other) + : ConservativeVectorBase() , Vector(other) { } diff --git a/Libraries/LibJS/CyclicModule.cpp b/Libraries/LibJS/CyclicModule.cpp index 179e2a1202..860881a4e1 100644 --- a/Libraries/LibJS/CyclicModule.cpp +++ b/Libraries/LibJS/CyclicModule.cpp @@ -868,7 +868,7 @@ GC::Ref CyclicModule::get_imported_module(ModuleRequest const& request) { // 1. Let records be a List consisting of each LoadedModuleRequest Record r of referrer.[[LoadedModules]] // such that ModuleRequestsEqual(r, request) is true. - GC::ConservativeVector records(vm().heap()); + GC::ConservativeVector records; for (auto const& r : m_loaded_modules) { if (module_requests_equal(r, request)) records.append(r); diff --git a/Libraries/LibJS/Runtime/ClassConstruction.cpp b/Libraries/LibJS/Runtime/ClassConstruction.cpp index 93b809d978..79a21e5705 100644 --- a/Libraries/LibJS/Runtime/ClassConstruction.cpp +++ b/Libraries/LibJS/Runtime/ClassConstruction.cpp @@ -126,10 +126,10 @@ ThrowCompletionOr construct_class( using StaticElement = Variant>; - GC::ConservativeVector static_private_methods(vm.heap()); - GC::ConservativeVector instance_private_methods(vm.heap()); - GC::ConservativeVector instance_fields(vm.heap()); - GC::ConservativeVector static_elements(vm.heap()); + GC::ConservativeVector static_private_methods; + GC::ConservativeVector instance_private_methods; + GC::ConservativeVector instance_fields; + GC::ConservativeVector static_elements; for (size_t element_index = 0; element_index < blueprint.elements.size(); ++element_index) { auto const& descriptor = blueprint.elements[element_index]; diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp index 31fe21ae5a..f6dbcf079e 100644 --- a/Libraries/LibJS/Runtime/Object.cpp +++ b/Libraries/LibJS/Runtime/Object.cpp @@ -1467,7 +1467,7 @@ ThrowCompletionOr Object::for_each_own_property_with_enumerability(Functio PropertyKey property_key; bool enumerable; }; - GC::ConservativeVector keys { heap() }; + GC::ConservativeVector keys; keys.ensure_capacity(indexed_real_size() + shape().property_count() + (has_magical_length_property() ? 1 : 0)); { diff --git a/Libraries/LibJS/SourceTextModule.cpp b/Libraries/LibJS/SourceTextModule.cpp index d0cad422e7..c0202bcb9d 100644 --- a/Libraries/LibJS/SourceTextModule.cpp +++ b/Libraries/LibJS/SourceTextModule.cpp @@ -117,7 +117,7 @@ Result, Vector> SourceTextModule::parse_f if (rust_result->is_error()) return rust_result->release_error(); auto& module_result = rust_result->value(); - GC::ConservativeVector functions_to_initialize(realm.heap()); + GC::ConservativeVector functions_to_initialize; functions_to_initialize.ensure_capacity(module_result.functions_to_initialize.size()); for (auto& f : module_result.functions_to_initialize) functions_to_initialize.append({ *f.shared_data, move(f.name) }); @@ -187,7 +187,7 @@ Result, Vector> SourceTextModule::parse(S return rust_result->release_error(); auto& module_result = rust_result->value(); - GC::ConservativeVector functions_to_initialize(realm.heap()); + GC::ConservativeVector functions_to_initialize; functions_to_initialize.ensure_capacity(module_result.functions_to_initialize.size()); for (auto& f : module_result.functions_to_initialize) functions_to_initialize.append({ *f.shared_data, move(f.name) }); diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index f8af07f66b..6145d3354c 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1977,7 +1977,7 @@ RefPtr StyleComputer::recascade_font_size_if_needed(DOM::Abstr // Reconstruct the line of ancestor elements we need to inherit style from, and then do the cascade again // but only for the font-size property. - GC::ConservativeVector ancestors { heap() }; + GC::ConservativeVector ancestors; for (auto ancestor = abstract_element.element_to_inherit_style_from(); ancestor.has_value(); ancestor = ancestor->element_to_inherit_style_from()) ancestors.append(*ancestor); diff --git a/Libraries/LibWeb/CSS/StyleScope.cpp b/Libraries/LibWeb/CSS/StyleScope.cpp index dcd97e7398..6784386928 100644 --- a/Libraries/LibWeb/CSS/StyleScope.cpp +++ b/Libraries/LibWeb/CSS/StyleScope.cpp @@ -323,7 +323,7 @@ void StyleScope::for_each_stylesheet(CascadeOrigin cascade_origin, Function matching_rules { m_node->heap() }; + GC::ConservativeVector matching_rules; size_t style_sheet_index = 0; for_each_stylesheet(cascade_origin, [&](auto& sheet) { auto& rule_caches = [&] -> RuleCaches& { diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index b3f2decf36..d337b7b8fd 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -6484,7 +6484,7 @@ void Document::update_animations_and_send_events(double timestamp) } // 4. Let events to dispatch be a copy of doc’s pending animation event queue. - auto events_to_dispatch = GC::ConservativeVector { vm().heap() }; + GC::ConservativeVector events_to_dispatch; events_to_dispatch.extend(m_pending_animation_event_queue); // 5. Clear doc’s pending animation event queue. @@ -7543,7 +7543,7 @@ void Document::remove_render_blocking_element(GC::Ref element) void Document::run_fullscreen_steps() { // 1. Let pendingEvents be document’s list of pending fullscreen events. - auto pending_events = GC::ConservativeVector { vm().heap() }; + GC::ConservativeVector pending_events; pending_events.extend(m_pending_fullscreen_events); // 2. Empty document’s list of pending fullscreen events. diff --git a/Libraries/LibWeb/Editing/Commands.cpp b/Libraries/LibWeb/Editing/Commands.cpp index 717d7fe4a9..7a6ce31628 100644 --- a/Libraries/LibWeb/Editing/Commands.cpp +++ b/Libraries/LibWeb/Editing/Commands.cpp @@ -249,7 +249,7 @@ bool command_delete_action(DOM::Document& document, Utf16String const&) // 3. Record the values of the one-node list consisting of node, and let values be the // result. - auto values = record_the_values_of_nodes(document.heap(), { *node }); + auto values = record_the_values_of_nodes({ *node }); // 4. Split the parent of the one-node list consisting of node. split_the_parent_of_nodes({ *node }); @@ -674,7 +674,7 @@ bool command_format_block_action(DOM::Document& document, Utf16String const& val }); // 7. Record the values of node list, and let values be the result. - auto values = record_the_values_of_nodes(document.heap(), node_list); + auto values = record_the_values_of_nodes(node_list); // 8. For each node in node list, while node is the descendant of an editable HTML element in the same editing host, // whose local name is a formattable block name, and which is not the ancestor of a prohibited paragraph child, @@ -722,7 +722,7 @@ bool command_format_block_action(DOM::Document& document, Utf16String const& val }); // 2. Record the values of sublist, and let values be the result. - auto values = record_the_values_of_nodes(document.heap(), sublist); + auto values = record_the_values_of_nodes(sublist); // 3. Remove the first member of node list from its parent, preserving its descendants. remove_node_preserving_its_descendants(node_list.first()); @@ -2185,7 +2185,7 @@ bool command_outdent_action(DOM::Document& document, Utf16String const&) sublist.append(node_list.take_first()); // 6. Record the values of sublist, and let values be the result. - auto values = record_the_values_of_nodes(document.heap(), sublist); + auto values = record_the_values_of_nodes(sublist); // 7. Split the parent of sublist. split_the_parent_of_nodes(sublist); diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp index df874e7a92..0e093efb86 100644 --- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp @@ -960,7 +960,7 @@ void delete_the_selection(Selection& selection, bool block_merging, bool strip_w } // 9. Record the values of children, and let values be the result. - values = record_the_values_of_nodes(document.heap(), children); + values = record_the_values_of_nodes(children); // 10. While children's first member's parent is not start block, split the parent of children. while (children.first()->parent() != start_block) @@ -1004,7 +1004,7 @@ void delete_the_selection(Selection& selection, bool block_merging, bool strip_w nodes_to_move.append(*nodes_to_move.last()->next_sibling()); // 8. Record the values of nodes to move, and let values be the result. - values = record_the_values_of_nodes(document.heap(), nodes_to_move); + values = record_the_values_of_nodes(nodes_to_move); // 9. For each node in nodes to move, append node as the last child of start block, preserving ranges. auto new_position = start_block->length(); @@ -1031,7 +1031,7 @@ void delete_the_selection(Selection& selection, bool block_merging, bool strip_w end_block_children.append(child); return IterationDecision::Continue; }); - values = record_the_values_of_nodes(document.heap(), end_block_children); + values = record_the_values_of_nodes(end_block_children); // 4. While end block has children, append the first child of end block to start block, preserving ranges. auto new_position = start_block->length(); @@ -1301,7 +1301,7 @@ void fix_disallowed_ancestors_of_node(GC::Ref node) return IterationDecision::Continue; // 1. Record the values of the one-node list consisting of child, and let values be the result. - auto values = record_the_values_of_nodes(child.heap(), { child }); + auto values = record_the_values_of_nodes({ child }); // 2. Split the parent of the one-node list consisting of child. split_the_parent_of_nodes({ child }); @@ -1317,7 +1317,7 @@ void fix_disallowed_ancestors_of_node(GC::Ref node) } // 3. Record the values of the one-node list consisting of node, and let values be the result. - auto values = record_the_values_of_nodes(node->heap(), { node }); + auto values = record_the_values_of_nodes({ node }); // 4. While node is not an allowed child of its parent, split the parent of the one-node list consisting of node. while (!is_allowed_child_of_node(node, GC::Ref { *node->parent() })) @@ -3005,7 +3005,7 @@ void outdent(GC::Ref node) // 4. Otherwise: else { // 1. Record the values of node's children, and let values be the result. - auto values = record_the_values_of_nodes(node->heap(), children); + auto values = record_the_values_of_nodes(children); // 2. Remove node, preserving its descendants. remove_node_preserving_its_descendants(node); @@ -3293,10 +3293,10 @@ Vector record_current_states_and_values(DOM::Document const& d } // https://w3c.github.io/editing/docs/execCommand/#record-the-values -GC::ConservativeVector record_the_values_of_nodes(GC::Heap& heap, Vector> const& node_list) +GC::ConservativeVector record_the_values_of_nodes(Vector> const& node_list) { // 1. Let values be a list of (node, command, specified command value) triples, initially empty. - GC::ConservativeVector values { heap }; + GC::ConservativeVector values; // 2. For each node in node list, for each command in the list "subscript", "bold", "fontName", // "fontSize", "foreColor", "hiliteColor", "italic", "strikethrough", and "underline" in that @@ -4103,7 +4103,7 @@ void toggle_lists(DOM::Document& document, FlyString const& tag_name) }); // 2. Record the values of children, and let values be the result. - auto values = record_the_values_of_nodes(document.heap(), children); + auto values = record_the_values_of_nodes(children); // 3. Split the parent of children. split_the_parent_of_nodes(children); @@ -4178,7 +4178,7 @@ void toggle_lists(DOM::Document& document, FlyString const& tag_name) sublist.append(node_list.take_first()); // 5. Record the values of sublist, and let values be the result. - auto values = record_the_values_of_nodes(document.heap(), sublist); + auto values = record_the_values_of_nodes(sublist); // 6. Split the parent of sublist. split_the_parent_of_nodes(sublist); @@ -4261,7 +4261,7 @@ void toggle_lists(DOM::Document& document, FlyString const& tag_name) if (!sublist.is_empty() && is(sublist.first()->parent()) && static_cast(*sublist.first()->parent()).local_name() == other_tag_name) { // 1. Record the values of sublist, and let values be the result. - auto values = record_the_values_of_nodes(document.heap(), sublist); + auto values = record_the_values_of_nodes(sublist); // 2. Split the parent of sublist. split_the_parent_of_nodes(sublist); diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.h b/Libraries/LibWeb/Editing/Internal/Algorithms.h index b8bcf9aed8..7e31667196 100644 --- a/Libraries/LibWeb/Editing/Internal/Algorithms.h +++ b/Libraries/LibWeb/Editing/Internal/Algorithms.h @@ -104,7 +104,7 @@ Optional previous_equivalent_point(DOM::BoundaryPoint); void push_down_values(FlyString const&, GC::Ref, Optional); Vector record_current_overrides(DOM::Document const&); Vector record_current_states_and_values(DOM::Document const&); -GC::ConservativeVector record_the_values_of_nodes(GC::Heap&, Vector> const&); +GC::ConservativeVector record_the_values_of_nodes(Vector> const&); void remove_extraneous_line_breaks_at_the_end_of_node(GC::Ref); void remove_extraneous_line_breaks_before_node(GC::Ref); void remove_extraneous_line_breaks_from_a_node(GC::Ref); diff --git a/Libraries/LibWeb/Fetch/Body.cpp b/Libraries/LibWeb/Fetch/Body.cpp index e62074319b..7e91400677 100644 --- a/Libraries/LibWeb/Fetch/Body.cpp +++ b/Libraries/LibWeb/Fetch/Body.cpp @@ -381,7 +381,7 @@ MultipartParsingErrorOr> parse_multip auto boundary = maybe_boundary.release_value(); // 3. Let entry list be an empty entry list. - GC::ConservativeVector entry_list { realm.heap() }; + GC::ConservativeVector entry_list; // 4. Let position be a pointer to a byte in input, initially pointing at the first byte. GenericLexer lexer(input); diff --git a/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp b/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp index 64f8658ca0..00835b4bf1 100644 --- a/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp +++ b/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp @@ -117,7 +117,7 @@ WebIDL::ExceptionOr>> constr auto controls = form.get_submittable_elements(); // 4. Let entry list be a new empty entry list. - GC::ConservativeVector entry_list { realm.heap() }; + GC::ConservativeVector entry_list; // 5. For each element field in controls, in tree order: for (auto const& control : controls) { diff --git a/Libraries/LibWeb/HTML/Navigable.cpp b/Libraries/LibWeb/HTML/Navigable.cpp index 6b7defa8fc..5a97c1118a 100644 --- a/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Libraries/LibWeb/HTML/Navigable.cpp @@ -2063,7 +2063,7 @@ void Navigable::begin_navigation(NavigateParams params) // 2. Let entryListForFiring be formDataEntryList if documentResource is a POST resource; otherwise, null. auto entry_list_for_firing = [&]() -> Optional> { if (document_resource.has()) - return GC::ConservativeVector { vm.heap(), params.form_data_entry_list.value() }; + return GC::ConservativeVector { params.form_data_entry_list.value() }; return {}; }(); diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp index 362e9678bb..2bf8043e89 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp @@ -2027,7 +2027,7 @@ GC::Ref retrieve_multiple_items_from_an_object_store(JS::Realm& realm count = OptionalNone(); // 2. Let records an empty list. - GC::ConservativeVector records(realm.heap()); + GC::ConservativeVector records; // 3. If direction is "next" or "nextunique", set records to the first count of store’s list of records whose key is in range. if (direction == Bindings::IDBCursorDirection::Next || direction == Bindings::IDBCursorDirection::Nextunique) { @@ -2293,7 +2293,7 @@ GC::Ref retrieve_multiple_items_from_an_index(JS::Realm& target_realm count = OptionalNone(); // 2. Let records be a an empty list. - GC::ConservativeVector records(target_realm.heap()); + GC::ConservativeVector records; // 3. Switching on direction: switch (direction) { diff --git a/Libraries/LibWeb/IndexedDB/Internal/Index.cpp b/Libraries/LibWeb/IndexedDB/Internal/Index.cpp index c0080b75d3..5c3b7a1de7 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Index.cpp +++ b/Libraries/LibWeb/IndexedDB/Internal/Index.cpp @@ -96,7 +96,7 @@ Optional Index::first_in_range(GC::Ref range) GC::ConservativeVector Index::first_n_in_range(GC::Ref range, Optional count) { - GC::ConservativeVector records(range->heap()); + GC::ConservativeVector records; auto record_range = record_range_for_key_range(m_records, range); for (size_t i = record_range.start; i < record_range.end; ++i) { records.append(m_records[i]); @@ -110,7 +110,7 @@ GC::ConservativeVector Index::first_n_in_range(GC::Ref GC::ConservativeVector Index::last_n_in_range(GC::Ref range, Optional count) { - GC::ConservativeVector records(range->heap()); + GC::ConservativeVector records; auto record_range = record_range_for_key_range(m_records, range); for (size_t i = record_range.end; i > record_range.start;) { --i; diff --git a/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.cpp b/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.cpp index 33991f5bfe..398b9aefd5 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.cpp +++ b/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.cpp @@ -181,7 +181,7 @@ void ObjectStore::possibly_update_the_key_generator(GC::Ref key) GC::ConservativeVector ObjectStore::first_n_in_range(GC::Ref range, Optional count) { - GC::ConservativeVector records(range->heap()); + GC::ConservativeVector records; auto record_range = record_range_for_key_range(m_records, range); for (size_t i = record_range.start; i < record_range.end; ++i) { records.append(m_records[i]); @@ -195,7 +195,7 @@ GC::ConservativeVector ObjectStore::first_n_in_range(GC::Ref< GC::ConservativeVector ObjectStore::last_n_in_range(GC::Ref range, Optional count) { - GC::ConservativeVector records(range->heap()); + GC::ConservativeVector records; auto record_range = record_range_for_key_range(m_records, range); for (size_t i = record_range.end; i > record_range.start;) { --i; diff --git a/Libraries/LibWeb/XHR/FormData.cpp b/Libraries/LibWeb/XHR/FormData.cpp index 8aeaaefd5e..036a73d27a 100644 --- a/Libraries/LibWeb/XHR/FormData.cpp +++ b/Libraries/LibWeb/XHR/FormData.cpp @@ -22,7 +22,7 @@ GC_DEFINE_ALLOCATOR(FormData); // https://xhr.spec.whatwg.org/#dom-formdata WebIDL::ExceptionOr> FormData::construct_impl(JS::Realm& realm, GC::Ptr form, GC::Ptr submitter) { - GC::ConservativeVector list { realm.heap() }; + GC::ConservativeVector list; // 1. If form is given, then: if (form) { // 1. If submitter is non-null, then: @@ -62,7 +62,7 @@ WebIDL::ExceptionOr> FormData::construct_impl(JS::Realm& realm WebIDL::ExceptionOr> FormData::create(JS::Realm& realm, Vector entry_list) { - GC::ConservativeVector list { realm.heap() }; + GC::ConservativeVector list; list.ensure_capacity(entry_list.size()); for (auto& entry : entry_list) list.unchecked_append({ .name = move(entry.name), .value = move(entry.value) }); @@ -185,7 +185,7 @@ WebIDL::ExceptionOr FormData::set(String const& name, GC::Ref FormData::entry_list() const { - return { realm().heap(), m_entry_list }; + return GC::ConservativeVector { m_entry_list }; } // https://xhr.spec.whatwg.org/#dom-formdata-set diff --git a/Tests/LibGC/TestGCContainers.cpp b/Tests/LibGC/TestGCContainers.cpp index 47ff3b4574..5535dcf136 100644 --- a/Tests/LibGC/TestGCContainers.cpp +++ b/Tests/LibGC/TestGCContainers.cpp @@ -168,7 +168,7 @@ TEST_CASE(cleared_container_reports_no_roots) TEST_CASE(conservative_vector_reports_possible_values) { auto& heap = test_heap(); - GC::ConservativeVector> vector(heap); + GC::ConservativeVector> vector; auto cell = heap.allocate(); vector.append(cell);