From 6898eae61ee8070bbc19815bc35428200e7074bf Mon Sep 17 00:00:00 2001 From: Yerkebulan Tulibergenov Date: Sat, 5 Apr 2025 23:27:59 -0700 Subject: [PATCH] Add CanGc as arguments in methods in Attr and Node (#36371) Add CanGc as argument to methods in `Attr` and `Node`. Addressed part of https://github.com/servo/servo/issues/34573. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes do not require tests because they are a refactor. Signed-off-by: Yerkebulan Tulibergenov --- components/script/devtools.rs | 8 +-- components/script/dom/attr.rs | 4 +- components/script/dom/document.rs | 14 ++-- components/script/dom/domimplementation.rs | 18 ++--- components/script/dom/element.rs | 9 ++- components/script/dom/htmldetailselement.rs | 6 +- components/script/dom/htmlelement.rs | 13 ++-- components/script/dom/htmlmediaelement.rs | 4 +- components/script/dom/htmlmeterelement.rs | 2 +- .../script/dom/htmloptionscollection.rs | 4 +- components/script/dom/htmlprogresselement.rs | 2 +- components/script/dom/htmlselectelement.rs | 8 +-- components/script/dom/htmltableelement.rs | 24 ++++--- components/script/dom/htmltemplateelement.rs | 2 +- components/script/dom/node.rs | 66 +++++++++---------- components/script/dom/range.rs | 36 +++++----- .../script/dom/servoparser/async_html.rs | 6 +- components/script/dom/servoparser/mod.rs | 14 ++-- components/script/dom/text.rs | 2 +- .../script_bindings/codegen/Bindings.conf | 6 +- 20 files changed, 137 insertions(+), 111 deletions(-) diff --git a/components/script/devtools.rs b/components/script/devtools.rs index d0d2a183f03..002ca5c1561 100644 --- a/components/script/devtools.rs +++ b/components/script/devtools.rs @@ -105,7 +105,7 @@ pub(crate) fn handle_get_root_node( ) { let info = documents .find_document(pipeline) - .map(|document| document.upcast::().summarize()); + .map(|document| document.upcast::().summarize(CanGc::note())); reply.send(info).unwrap(); } @@ -117,7 +117,7 @@ pub(crate) fn handle_get_document_element( let info = documents .find_document(pipeline) .and_then(|document| document.GetDocumentElement()) - .map(|element| element.upcast::().summarize()); + .map(|element| element.upcast::().summarize(CanGc::note())); reply.send(info).unwrap(); } @@ -166,7 +166,7 @@ pub(crate) fn handle_get_children( if !shadow_root.is_user_agent_widget() || pref!(inspector_show_servo_internal_shadow_roots) { - children.push(shadow_root.upcast::().summarize()); + children.push(shadow_root.upcast::().summarize(CanGc::note())); } } let children_iter = parent.children().enumerate().filter_map(|(i, child)| { @@ -175,7 +175,7 @@ pub(crate) fn handle_get_children( let prev_inline = i > 0 && inline[i - 1]; let next_inline = i < inline.len() - 1 && inline[i + 1]; - let info = child.summarize(); + let info = child.summarize(CanGc::note()); if !is_whitespace(&info) { return Some(info); } diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index a488b11c3c7..9b33213335e 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -112,10 +112,10 @@ impl AttrMethods for Attr { } // https://dom.spec.whatwg.org/#dom-attr-value - fn SetValue(&self, value: DOMString) { + fn SetValue(&self, value: DOMString, can_gc: CanGc) { if let Some(owner) = self.owner() { let value = owner.parse_attribute(self.namespace(), self.local_name(), value); - self.set_value(value, &owner, CanGc::note()); + self.set_value(value, &owner, can_gc); } else { *self.value.borrow_mut() = AttrValue::String(value.into()); } diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index d76367ca982..830f624b491 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -2249,13 +2249,13 @@ impl Document { for node in nodes { match node { NodeOrString::Node(node) => { - fragment.AppendChild(&node)?; + fragment.AppendChild(&node, can_gc)?; }, NodeOrString::String(string) => { let node = DomRoot::upcast::(self.CreateTextNode(string, can_gc)); // No try!() here because appending a text node // should not fail. - fragment.AppendChild(&node).unwrap(); + fragment.AppendChild(&node, can_gc).unwrap(); }, } } @@ -5404,7 +5404,7 @@ impl DocumentMethods for Document { let parent = root.upcast::(); let child = elem.upcast::(); parent - .InsertBefore(child, parent.GetFirstChild().as_deref()) + .InsertBefore(child, parent.GetFirstChild().as_deref(), can_gc) .unwrap() }, } @@ -5427,7 +5427,9 @@ impl DocumentMethods for Document { None, can_gc, ); - head.upcast::().AppendChild(elem.upcast()).unwrap() + head.upcast::() + .AppendChild(elem.upcast(), can_gc) + .unwrap() }, None => return, }, @@ -5500,7 +5502,7 @@ impl DocumentMethods for Document { // Step 3. (Some(ref root), Some(child)) => { let root = root.upcast::(); - root.ReplaceChild(new_body.upcast(), child.upcast()) + root.ReplaceChild(new_body.upcast(), child.upcast(), CanGc::note()) .unwrap(); }, @@ -5510,7 +5512,7 @@ impl DocumentMethods for Document { // Step 5. (Some(ref root), &None) => { let root = root.upcast::(); - root.AppendChild(new_body.upcast()).unwrap(); + root.AppendChild(new_body.upcast(), CanGc::note()).unwrap(); }, } Ok(()) diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index 4adae2f4229..2d0e8534e79 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -138,12 +138,12 @@ impl DOMImplementationMethods for DOMImplementation { // Step 4. if let Some(doc_type) = maybe_doctype { - doc_node.AppendChild(doc_type.upcast()).unwrap(); + doc_node.AppendChild(doc_type.upcast(), can_gc).unwrap(); } // Step 5. if let Some(ref elem) = maybe_elem { - doc_node.AppendChild(elem.upcast()).unwrap(); + doc_node.AppendChild(elem.upcast(), can_gc).unwrap(); } } @@ -185,7 +185,7 @@ impl DOMImplementationMethods for DOMImplementation { // Step 3. let doc_node = doc.upcast::(); let doc_type = DocumentType::new(DOMString::from("html"), None, None, &doc, can_gc); - doc_node.AppendChild(doc_type.upcast()).unwrap(); + doc_node.AppendChild(doc_type.upcast(), can_gc).unwrap(); } { @@ -198,7 +198,9 @@ impl DOMImplementationMethods for DOMImplementation { None, can_gc, )); - doc_node.AppendChild(&doc_html).expect("Appending failed"); + doc_node + .AppendChild(&doc_html, can_gc) + .expect("Appending failed"); { // Step 5. @@ -209,7 +211,7 @@ impl DOMImplementationMethods for DOMImplementation { None, can_gc, )); - doc_html.AppendChild(&doc_head).unwrap(); + doc_html.AppendChild(&doc_head, can_gc).unwrap(); // Step 6. if let Some(title_str) = title { @@ -221,17 +223,17 @@ impl DOMImplementationMethods for DOMImplementation { None, can_gc, )); - doc_head.AppendChild(&doc_title).unwrap(); + doc_head.AppendChild(&doc_title, can_gc).unwrap(); // Step 6.2. let title_text = Text::new(title_str, &doc, can_gc); - doc_title.AppendChild(title_text.upcast()).unwrap(); + doc_title.AppendChild(title_text.upcast(), can_gc).unwrap(); } } // Step 7. let doc_body = HTMLBodyElement::new(local_name!("body"), None, &doc, None, can_gc); - doc_html.AppendChild(doc_body.upcast()).unwrap(); + doc_html.AppendChild(doc_body.upcast(), can_gc).unwrap(); } // Step 8. diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 8193c99c896..5216768c3ac 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -2170,7 +2170,10 @@ impl Element { let fragment = DocumentFragment::new(&context_document, can_gc); // Step 4. for child in new_children { - fragment.upcast::().AppendChild(&child).unwrap(); + fragment + .upcast::() + .AppendChild(&child, can_gc) + .unwrap(); } // Step 5. Ok(fragment) @@ -2973,7 +2976,7 @@ impl ElementMethods for Element { // For each node in newChildren, append node to fragment. for child in new_children { - frag.upcast::().AppendChild(&child).unwrap(); + frag.upcast::().AppendChild(&child, can_gc).unwrap(); } // Replace all with fragment within target. @@ -3093,7 +3096,7 @@ impl ElementMethods for Element { // Step 5. let frag = parent.parse_fragment(value, can_gc)?; // Step 6. - context_parent.ReplaceChild(frag.upcast(), context_node)?; + context_parent.ReplaceChild(frag.upcast(), context_node, can_gc)?; Ok(()) } diff --git a/components/script/dom/htmldetailselement.rs b/components/script/dom/htmldetailselement.rs index 0752da270b8..ace941a1bc3 100644 --- a/components/script/dom/htmldetailselement.rs +++ b/components/script/dom/htmldetailselement.rs @@ -118,7 +118,7 @@ impl HTMLDetailsElement { let summary = HTMLSlotElement::new(local_name!("slot"), None, &document, None, can_gc); root.upcast::() - .AppendChild(summary.upcast::()) + .AppendChild(summary.upcast::(), can_gc) .unwrap(); let fallback_summary = @@ -128,12 +128,12 @@ impl HTMLDetailsElement { .SetTextContent(Some(DEFAULT_SUMMARY.into()), can_gc); summary .upcast::() - .AppendChild(fallback_summary.upcast::()) + .AppendChild(fallback_summary.upcast::(), can_gc) .unwrap(); let descendants = HTMLSlotElement::new(local_name!("slot"), None, &document, None, can_gc); root.upcast::() - .AppendChild(descendants.upcast::()) + .AppendChild(descendants.upcast::(), can_gc) .unwrap(); let _ = self.shadow_tree.borrow_mut().insert(ShadowTree { diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index bf95f8528e9..a74d4470788 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -532,11 +532,13 @@ impl HTMLElementMethods for HTMLElement { if fragment.upcast::().children_count() == 0 { let text_node = Text::new(DOMString::from("".to_owned()), &document, can_gc); - fragment.upcast::().AppendChild(text_node.upcast())?; + fragment + .upcast::() + .AppendChild(text_node.upcast(), can_gc)?; } // Step 6: Replace this with fragment within this's parent. - parent.ReplaceChild(fragment.upcast(), node)?; + parent.ReplaceChild(fragment.upcast(), node, can_gc)?; // Step 7: If next is non-null and next's previous sibling is a Text node, then merge with // the next text node given next's previous sibling. @@ -670,7 +672,7 @@ fn append_text_node_to_fragment( let text = Text::new(DOMString::from(text), document, can_gc); fragment .upcast::() - .AppendChild(text.upcast()) + .AppendChild(text.upcast(), can_gc) .unwrap(); } @@ -1016,7 +1018,10 @@ impl HTMLElement { } let br = HTMLBRElement::new(local_name!("br"), None, &document, None, can_gc); - fragment.upcast::().AppendChild(br.upcast()).unwrap(); + fragment + .upcast::() + .AppendChild(br.upcast(), can_gc) + .unwrap(); }, _ => { // Collect a sequence of code points that are not U+000A LF or U+000D CR from diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index a608ba40c92..64bd48b0c2f 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -1928,7 +1928,7 @@ impl HTMLMediaElement { .SetTextContent(Some(DOMString::from(media_controls_script)), can_gc); if let Err(e) = shadow_root .upcast::() - .AppendChild(script.upcast::()) + .AppendChild(script.upcast::(), can_gc) { warn!("Could not render media controls {:?}", e); return; @@ -1949,7 +1949,7 @@ impl HTMLMediaElement { if let Err(e) = shadow_root .upcast::() - .AppendChild(style.upcast::()) + .AppendChild(style.upcast::(), can_gc) { warn!("Could not render media controls {:?}", e); } diff --git a/components/script/dom/htmlmeterelement.rs b/components/script/dom/htmlmeterelement.rs index 103ab9c0131..24470d82de9 100644 --- a/components/script/dom/htmlmeterelement.rs +++ b/components/script/dom/htmlmeterelement.rs @@ -94,7 +94,7 @@ impl HTMLMeterElement { let meter_value = HTMLDivElement::new(local_name!("div"), None, &document, None, can_gc); root.upcast::() - .AppendChild(meter_value.upcast::()) + .AppendChild(meter_value.upcast::(), can_gc) .unwrap(); let _ = self.shadow_tree.borrow_mut().insert(ShadowTree { diff --git a/components/script/dom/htmloptionscollection.rs b/components/script/dom/htmloptionscollection.rs index e38749b3aa5..bf3b40909f2 100644 --- a/components/script/dom/htmloptionscollection.rs +++ b/components/script/dom/htmloptionscollection.rs @@ -64,7 +64,7 @@ impl HTMLOptionsCollection { let element = HTMLOptionElement::new(local_name!("option"), None, &document, None, can_gc); let node = element.upcast::(); - root.AppendChild(node)?; + root.AppendChild(node, can_gc)?; } Ok(()) } @@ -122,7 +122,7 @@ impl HTMLOptionsCollectionMethods for HTMLOptionsCollectio let child = self.upcast().IndexedGetter(index).unwrap(); let child_node = child.upcast::(); - root.ReplaceChild(node, child_node).map(|_| ()) + root.ReplaceChild(node, child_node, can_gc).map(|_| ()) } } else { // Step 1 diff --git a/components/script/dom/htmlprogresselement.rs b/components/script/dom/htmlprogresselement.rs index 30106c479d0..25e4ff15c2b 100644 --- a/components/script/dom/htmlprogresselement.rs +++ b/components/script/dom/htmlprogresselement.rs @@ -96,7 +96,7 @@ impl HTMLProgressElement { .upcast::() .SetId("-servo-progress-bar".into(), can_gc); root.upcast::() - .AppendChild(progress_bar.upcast::()) + .AppendChild(progress_bar.upcast::(), can_gc) .unwrap(); let _ = self.shadow_tree.borrow_mut().insert(ShadowTree { diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs index e349b58f9bb..0a416bd85a0 100644 --- a/components/script/dom/htmlselectelement.rs +++ b/components/script/dom/htmlselectelement.rs @@ -286,7 +286,7 @@ impl HTMLSelectElement { ); select_box .upcast::() - .AppendChild(text_container.upcast::()) + .AppendChild(text_container.upcast::(), can_gc) .unwrap(); let text = Text::new(DOMString::new(), &document, can_gc); @@ -295,7 +295,7 @@ impl HTMLSelectElement { }); text_container .upcast::() - .AppendChild(text.upcast::()) + .AppendChild(text.upcast::(), can_gc) .unwrap(); let chevron_container = @@ -310,11 +310,11 @@ impl HTMLSelectElement { .SetTextContent(Some("▾".into()), can_gc); select_box .upcast::() - .AppendChild(chevron_container.upcast::()) + .AppendChild(chevron_container.upcast::(), can_gc) .unwrap(); root.upcast::() - .AppendChild(select_box.upcast::()) + .AppendChild(select_box.upcast::(), can_gc) .unwrap(); } diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index 000816194ee..6783da6e97d 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -133,7 +133,7 @@ impl HTMLTableElement { let reference_element = node.child_elements().find(reference_predicate); let reference_node = reference_element.as_ref().map(|e| e.upcast()); - node.InsertBefore(section.upcast(), reference_node)?; + node.InsertBefore(section.upcast(), reference_node, can_gc)?; } Ok(()) @@ -212,7 +212,11 @@ impl HTMLTableElementMethods for HTMLTableElement { if let Some(caption) = new_caption { let node = self.upcast::(); - node.InsertBefore(caption.upcast(), node.GetFirstChild().as_deref())?; + node.InsertBefore( + caption.upcast(), + node.GetFirstChild().as_deref(), + CanGc::note(), + )?; } Ok(()) @@ -339,7 +343,7 @@ impl HTMLTableElementMethods for HTMLTableElement { .find(|n| n.is::() && n.local_name() == &local_name!("tbody")); let reference_element = last_tbody.and_then(|t| t.upcast::().GetNextSibling()); - node.InsertBefore(tbody.upcast(), reference_element.as_deref()) + node.InsertBefore(tbody.upcast(), reference_element.as_deref(), can_gc) .expect("Insertion failed"); tbody } @@ -373,16 +377,16 @@ impl HTMLTableElementMethods for HTMLTableElement { { last_tbody .upcast::() - .AppendChild(new_row.upcast::()) + .AppendChild(new_row.upcast::(), can_gc) .expect("InsertRow failed to append first row."); } else { let tbody = self.CreateTBody(can_gc); - node.AppendChild(tbody.upcast()) + node.AppendChild(tbody.upcast(), can_gc) .expect("InsertRow failed to append new tbody."); tbody .upcast::() - .AppendChild(new_row.upcast::()) + .AppendChild(new_row.upcast::(), can_gc) .expect("InsertRow failed to append first row."); } } else if index == number_of_row_elements as i32 || index == -1 { @@ -398,7 +402,7 @@ impl HTMLTableElementMethods for HTMLTableElement { last_row_parent .upcast::() - .AppendChild(new_row.upcast::()) + .AppendChild(new_row.upcast::(), can_gc) .expect("InsertRow failed to append last row."); } else { // insert new row before the index-th row in rows using the same parent @@ -413,7 +417,11 @@ impl HTMLTableElementMethods for HTMLTableElement { ith_row_parent .upcast::() - .InsertBefore(new_row.upcast::(), Some(ith_row.upcast::())) + .InsertBefore( + new_row.upcast::(), + Some(ith_row.upcast::()), + can_gc, + ) .expect("InsertRow failed to append row"); } diff --git a/components/script/dom/htmltemplateelement.rs b/components/script/dom/htmltemplateelement.rs index 93897f4710f..2c98035736e 100644 --- a/components/script/dom/htmltemplateelement.rs +++ b/components/script/dom/htmltemplateelement.rs @@ -149,7 +149,7 @@ impl VirtualMethods for HTMLTemplateElement { CloneChildrenFlag::CloneChildren, CanGc::note(), ); - copy_contents.AppendChild(©_child).unwrap(); + copy_contents.AppendChild(©_child, can_gc).unwrap(); } } } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 9c069a28c50..016787799c6 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1023,7 +1023,7 @@ impl Node { .node_from_nodes_and_strings(nodes, can_gc)?; if self.parent_node == Some(&*parent) { // Step 5. - parent.ReplaceChild(&node, self)?; + parent.ReplaceChild(&node, self, can_gc)?; } else { // Step 6. Node::pre_insert(&node, &parent, viable_next_sibling.as_deref(), can_gc)?; @@ -1047,7 +1047,7 @@ impl Node { let doc = self.owner_doc(); let node = doc.node_from_nodes_and_strings(nodes, can_gc)?; // Step 2. - self.AppendChild(&node).map(|_| ()) + self.AppendChild(&node, can_gc).map(|_| ()) } /// @@ -1226,7 +1226,7 @@ impl Node { .to_string() } - pub(crate) fn summarize(&self) -> NodeInfo { + pub(crate) fn summarize(&self, can_gc: CanGc) -> NodeInfo { let USVString(base_uri) = self.BaseURI(); let node_type = self.NodeType(); @@ -1246,9 +1246,9 @@ impl Node { let num_children = if is_shadow_host { // Shadow roots count as children - self.ChildNodes().Length() as usize + 1 + self.ChildNodes(can_gc).Length() as usize + 1 } else { - self.ChildNodes().Length() as usize + self.ChildNodes(can_gc).Length() as usize }; let window = self.owner_window(); @@ -1282,7 +1282,7 @@ impl Node { index: i32, get_items: F, new_child: G, - _can_gc: CanGc, + can_gc: CanGc, ) -> Fallible> where F: Fn() -> DomRoot, @@ -1298,7 +1298,7 @@ impl Node { { let tr_node = tr.upcast::(); if index == -1 { - self.InsertBefore(tr_node, None)?; + self.InsertBefore(tr_node, None, can_gc)?; } else { let items = get_items(); let node = match items @@ -1311,7 +1311,7 @@ impl Node { None => return Err(Error::IndexSize), Some(node) => node, }; - self.InsertBefore(tr_node, node.as_deref())?; + self.InsertBefore(tr_node, node.as_deref(), can_gc)?; } } @@ -2255,7 +2255,7 @@ impl Node { parent, reference_child, SuppressObserver::Unsuppressed, - CanGc::note(), + can_gc, ); // Step 6. @@ -3028,11 +3028,11 @@ impl NodeMethods for Node { } /// - fn ChildNodes(&self) -> DomRoot { + fn ChildNodes(&self, can_gc: CanGc) -> DomRoot { self.ensure_rare_data().child_list.or_init(|| { let doc = self.owner_doc(); let window = doc.window(); - NodeList::new_child_list(window, self, CanGc::note()) + NodeList::new_child_list(window, self, can_gc) }) } @@ -3068,11 +3068,11 @@ impl NodeMethods for Node { } /// - fn SetNodeValue(&self, val: Option) { + fn SetNodeValue(&self, val: Option, can_gc: CanGc) { match self.type_id() { NodeTypeId::Attr => { let attr = self.downcast::().unwrap(); - attr.SetValue(val.unwrap_or_default()); + attr.SetValue(val.unwrap_or_default(), can_gc); }, NodeTypeId::CharacterData(_) => { let character_data = self.downcast::().unwrap(); @@ -3118,7 +3118,7 @@ impl NodeMethods for Node { }, NodeTypeId::Attr => { let attr = self.downcast::().unwrap(); - attr.SetValue(value); + attr.SetValue(value, can_gc); }, NodeTypeId::CharacterData(..) => { let characterdata = self.downcast::().unwrap(); @@ -3129,17 +3129,22 @@ impl NodeMethods for Node { } /// - fn InsertBefore(&self, node: &Node, child: Option<&Node>) -> Fallible> { - Node::pre_insert(node, self, child, CanGc::note()) + fn InsertBefore( + &self, + node: &Node, + child: Option<&Node>, + can_gc: CanGc, + ) -> Fallible> { + Node::pre_insert(node, self, child, can_gc) } /// - fn AppendChild(&self, node: &Node) -> Fallible> { - Node::pre_insert(node, self, None, CanGc::note()) + fn AppendChild(&self, node: &Node, can_gc: CanGc) -> Fallible> { + Node::pre_insert(node, self, None, can_gc) } /// - fn ReplaceChild(&self, node: &Node, child: &Node) -> Fallible> { + fn ReplaceChild(&self, node: &Node, child: &Node, can_gc: CanGc) -> Fallible> { // Step 1. match self.type_id() { NodeTypeId::Document(_) | NodeTypeId::DocumentFragment(_) | NodeTypeId::Element(..) => { @@ -3237,11 +3242,11 @@ impl NodeMethods for Node { // Step 10. let document = self.owner_document(); - Node::adopt(node, &document, CanGc::note()); + Node::adopt(node, &document, can_gc); let removed_child = if node != child { // Step 11. - Node::remove(child, self, SuppressObserver::Suppressed, CanGc::note()); + Node::remove(child, self, SuppressObserver::Suppressed, can_gc); Some(child) } else { None @@ -3265,7 +3270,7 @@ impl NodeMethods for Node { self, reference_child, SuppressObserver::Suppressed, - CanGc::note(), + can_gc, ); // Step 14. @@ -3290,19 +3295,19 @@ impl NodeMethods for Node { } /// - fn RemoveChild(&self, node: &Node) -> Fallible> { - Node::pre_remove(node, self, CanGc::note()) + fn RemoveChild(&self, node: &Node, can_gc: CanGc) -> Fallible> { + Node::pre_remove(node, self, can_gc) } /// - fn Normalize(&self) { + fn Normalize(&self, can_gc: CanGc) { let mut children = self.children().enumerate().peekable(); while let Some((_, node)) = children.next() { if let Some(text) = node.downcast::() { let cdata = text.upcast::(); let mut length = cdata.Length(); if length == 0 { - Node::remove(&node, self, SuppressObserver::Unsuppressed, CanGc::note()); + Node::remove(&node, self, SuppressObserver::Unsuppressed, can_gc); continue; } while children @@ -3318,15 +3323,10 @@ impl NodeMethods for Node { let sibling_cdata = sibling.downcast::().unwrap(); length += sibling_cdata.Length(); cdata.append_data(&sibling_cdata.data()); - Node::remove( - &sibling, - self, - SuppressObserver::Unsuppressed, - CanGc::note(), - ); + Node::remove(&sibling, self, SuppressObserver::Unsuppressed, can_gc); } } else { - node.Normalize(); + node.Normalize(can_gc); } } } diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs index f76703098f4..4bf3b7fb72a 100644 --- a/components/script/dom/range.rs +++ b/components/script/dom/range.rs @@ -596,7 +596,7 @@ impl RangeMethods for Range { .unwrap(); let clone = cdata.clone_with_data(data, &start_node.owner_doc(), can_gc); // Step 4.3. - fragment.upcast::().AppendChild(&clone)?; + fragment.upcast::().AppendChild(&clone, can_gc)?; // Step 4.4 return Ok(fragment); } @@ -619,12 +619,12 @@ impl RangeMethods for Range { .unwrap(); let clone = cdata.clone_with_data(data, &start_node.owner_doc(), can_gc); // Step 13.3. - fragment.upcast::().AppendChild(&clone)?; + fragment.upcast::().AppendChild(&clone, can_gc)?; } else { // Step 14.1. let clone = child.CloneNode(/* deep */ false, can_gc)?; // Step 14.2. - fragment.upcast::().AppendChild(&clone)?; + fragment.upcast::().AppendChild(&clone, can_gc)?; // Step 14.3. let subrange = Range::new( &clone.owner_doc(), @@ -637,7 +637,7 @@ impl RangeMethods for Range { // Step 14.4. let subfragment = subrange.CloneContents(can_gc)?; // Step 14.5. - clone.AppendChild(subfragment.upcast())?; + clone.AppendChild(subfragment.upcast(), can_gc)?; } } @@ -646,7 +646,7 @@ impl RangeMethods for Range { // Step 15.1. let clone = child.CloneNode(/* deep */ true, can_gc)?; // Step 15.2. - fragment.upcast::().AppendChild(&clone)?; + fragment.upcast::().AppendChild(&clone, can_gc)?; } if let Some(child) = last_partially_contained_child { @@ -657,19 +657,19 @@ impl RangeMethods for Range { let data = cdata.SubstringData(0, end_offset).unwrap(); let clone = cdata.clone_with_data(data, &start_node.owner_doc(), can_gc); // Step 16.3. - fragment.upcast::().AppendChild(&clone)?; + fragment.upcast::().AppendChild(&clone, can_gc)?; } else { // Step 17.1. let clone = child.CloneNode(/* deep */ false, can_gc)?; // Step 17.2. - fragment.upcast::().AppendChild(&clone)?; + fragment.upcast::().AppendChild(&clone, can_gc)?; // Step 17.3. let subrange = Range::new(&clone.owner_doc(), &child, 0, &end_node, end_offset, can_gc); // Step 17.4. let subfragment = subrange.CloneContents(can_gc)?; // Step 17.5. - clone.AppendChild(subfragment.upcast())?; + clone.AppendChild(subfragment.upcast(), can_gc)?; } } @@ -705,7 +705,7 @@ impl RangeMethods for Range { .unwrap() .SetData(text.unwrap()); // Step 4.3. - fragment.upcast::().AppendChild(&clone)?; + fragment.upcast::().AppendChild(&clone, can_gc)?; // Step 4.4. end_data.ReplaceData(start_offset, end_offset - start_offset, DOMString::new())?; // Step 4.5. @@ -749,7 +749,7 @@ impl RangeMethods for Range { .unwrap() .SetData(text.unwrap()); // Step 15.3. - fragment.upcast::().AppendChild(&clone)?; + fragment.upcast::().AppendChild(&clone, can_gc)?; // Step 15.4. start_data.ReplaceData( start_offset, @@ -760,7 +760,7 @@ impl RangeMethods for Range { // Step 16.1. let clone = child.CloneNode(/* deep */ false, can_gc)?; // Step 16.2. - fragment.upcast::().AppendChild(&clone)?; + fragment.upcast::().AppendChild(&clone, can_gc)?; // Step 16.3. let subrange = Range::new( &clone.owner_doc(), @@ -773,13 +773,13 @@ impl RangeMethods for Range { // Step 16.4. let subfragment = subrange.ExtractContents(can_gc)?; // Step 16.5. - clone.AppendChild(subfragment.upcast())?; + clone.AppendChild(subfragment.upcast(), can_gc)?; } } // Step 17. for child in contained_children { - fragment.upcast::().AppendChild(&child)?; + fragment.upcast::().AppendChild(&child, can_gc)?; } if let Some(child) = last_partially_contained_child { @@ -794,21 +794,21 @@ impl RangeMethods for Range { .unwrap() .SetData(text.unwrap()); // Step 18.3. - fragment.upcast::().AppendChild(&clone)?; + fragment.upcast::().AppendChild(&clone, can_gc)?; // Step 18.4. end_data.ReplaceData(0, end_offset, DOMString::new())?; } else { // Step 19.1. let clone = child.CloneNode(/* deep */ false, can_gc)?; // Step 19.2. - fragment.upcast::().AppendChild(&clone)?; + fragment.upcast::().AppendChild(&clone, can_gc)?; // Step 19.3. let subrange = Range::new(&clone.owner_doc(), &child, 0, &end_node, end_offset, can_gc); // Step 19.4. let subfragment = subrange.ExtractContents(can_gc)?; // Step 19.5. - clone.AppendChild(subfragment.upcast())?; + clone.AppendChild(subfragment.upcast(), can_gc)?; } } @@ -856,7 +856,7 @@ impl RangeMethods for Range { }, _ => { // Steps 4-5. - let child = start_node.ChildNodes().Item(start_offset); + let child = start_node.ChildNodes(can_gc).Item(start_offset); (child, DomRoot::from_ref(&*start_node)) }, }; @@ -1029,7 +1029,7 @@ impl RangeMethods for Range { self.InsertNode(new_parent, can_gc)?; // Step 6. - new_parent.AppendChild(fragment.upcast())?; + new_parent.AppendChild(fragment.upcast(), can_gc)?; // Step 7. self.SelectNode(new_parent) diff --git a/components/script/dom/servoparser/async_html.rs b/components/script/dom/servoparser/async_html.rs index 269756505d2..3b3df28d4a9 100644 --- a/components/script/dom/servoparser/async_html.rs +++ b/components/script/dom/servoparser/async_html.rs @@ -484,7 +484,7 @@ impl Tokenizer { document .upcast::() - .AppendChild(doctype.upcast()) + .AppendChild(doctype.upcast(), can_gc) .expect("Appending failed"); }, ParseOperation::AddAttrsIfMissing { target, attrs } => { @@ -503,7 +503,7 @@ impl Tokenizer { }, ParseOperation::RemoveFromParent { target } => { if let Some(ref parent) = self.get_node(&target).GetParentNode() { - parent.RemoveChild(&self.get_node(&target)).unwrap(); + parent.RemoveChild(&self.get_node(&target), can_gc).unwrap(); } }, ParseOperation::MarkScriptAlreadyStarted { node } => { @@ -517,7 +517,7 @@ impl Tokenizer { let parent = self.get_node(&parent); let new_parent = self.get_node(&new_parent); while let Some(child) = parent.GetFirstChild() { - new_parent.AppendChild(&child).unwrap(); + new_parent.AppendChild(&child, can_gc).unwrap(); } }, ParseOperation::AssociateWithForm { diff --git a/components/script/dom/servoparser/mod.rs b/components/script/dom/servoparser/mod.rs index 0cc0854e34a..eb1e8d687bd 100644 --- a/components/script/dom/servoparser/mod.rs +++ b/components/script/dom/servoparser/mod.rs @@ -913,7 +913,7 @@ impl FetchResponseListener for ParserContext { let img = HTMLImageElement::new(local_name!("img"), None, doc, None, CanGc::note()); img.SetSrc(USVString(self.url.to_string())); doc_body - .AppendChild(&DomRoot::upcast::(img)) + .AppendChild(&DomRoot::upcast::(img), CanGc::note()) .expect("Appending failed"); }, (mime::TEXT, mime::PLAIN, _) => { @@ -1095,7 +1095,7 @@ fn insert( if element_in_non_fragment { ScriptThread::push_new_element_queue(); } - parent.InsertBefore(&n, reference_child).unwrap(); + parent.InsertBefore(&n, reference_child, can_gc).unwrap(); if element_in_non_fragment { ScriptThread::pop_current_element_queue(can_gc); } @@ -1111,7 +1111,9 @@ fn insert( text.upcast::().append_data(&t); } else { let text = Text::new(String::from(t).into(), &parent.owner_doc(), can_gc); - parent.InsertBefore(text.upcast(), reference_child).unwrap(); + parent + .InsertBefore(text.upcast(), reference_child, can_gc) + .unwrap(); } }, } @@ -1323,7 +1325,7 @@ impl TreeSink for Sink { CanGc::note(), ); doc.upcast::() - .AppendChild(doctype.upcast()) + .AppendChild(doctype.upcast(), CanGc::note()) .expect("Appending failed"); } @@ -1343,7 +1345,7 @@ impl TreeSink for Sink { fn remove_from_parent(&self, target: &Dom) { if let Some(ref parent) = target.GetParentNode() { - parent.RemoveChild(target).unwrap(); + parent.RemoveChild(target, CanGc::note()).unwrap(); } } @@ -1365,7 +1367,7 @@ impl TreeSink for Sink { fn reparent_children(&self, node: &Dom, new_parent: &Dom) { while let Some(ref child) = node.GetFirstChild() { - new_parent.AppendChild(child).unwrap(); + new_parent.AppendChild(child, CanGc::note()).unwrap(); } } diff --git a/components/script/dom/text.rs b/components/script/dom/text.rs index d4b31ab3dcf..c5c8b2ce06b 100644 --- a/components/script/dom/text.rs +++ b/components/script/dom/text.rs @@ -89,7 +89,7 @@ impl TextMethods for Text { if let Some(ref parent) = parent { // Step 7.1. parent - .InsertBefore(new_node.upcast(), node.GetNextSibling().as_deref()) + .InsertBefore(new_node.upcast(), node.GetNextSibling().as_deref(), can_gc) .unwrap(); // Steps 7.2-3. node.ranges() diff --git a/components/script_bindings/codegen/Bindings.conf b/components/script_bindings/codegen/Bindings.conf index 2c94c445778..ecbda986bf0 100644 --- a/components/script_bindings/codegen/Bindings.conf +++ b/components/script_bindings/codegen/Bindings.conf @@ -18,6 +18,10 @@ DOMInterfaces = { 'weakReferenceable': True, }, +'Attr': { + 'canGc':['SetValue'], +}, + 'AudioBuffer': { 'canGc':['CopyToChannel', 'GetChannelData'], }, @@ -452,7 +456,7 @@ DOMInterfaces = { }, 'Node': { - 'canGc': ['CloneNode', 'SetTextContent'], + 'canGc': ['AppendChild', 'ChildNodes', 'CloneNode', 'InsertBefore', 'Normalize', 'SetNodeValue', 'SetTextContent', 'RemoveChild', 'ReplaceChild'], }, 'NodeIterator': {