cangc fixes in node.rs (#33984)

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
chickenleaf 2024-10-24 04:14:50 +05:30 committed by GitHub
parent 3ed778150f
commit bb4932026c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
97 changed files with 1038 additions and 534 deletions

View file

@ -28,6 +28,7 @@ use crate::dom::htmltablerowelement::HTMLTableRowElement;
use crate::dom::htmltablesectionelement::HTMLTableSectionElement;
use crate::dom::node::{document_from_node, window_from_node, Node};
use crate::dom::virtualmethods::VirtualMethods;
use crate::script_runtime::CanGc;
#[dom_struct]
pub struct HTMLTableElement {
@ -75,6 +76,7 @@ impl HTMLTableElement {
prefix: Option<Prefix>,
document: &Document,
proto: Option<HandleObject>,
can_gc: CanGc,
) -> DomRoot<HTMLTableElement> {
let n = Node::reflect_node_with_proto(
Box::new(HTMLTableElement::new_inherited(
@ -82,6 +84,7 @@ impl HTMLTableElement {
)),
document,
proto,
can_gc,
);
n.upcast::<Node>().set_weird_parser_insertion_mode();
@ -137,13 +140,22 @@ impl HTMLTableElement {
// https://html.spec.whatwg.org/multipage/#dom-table-createthead
// https://html.spec.whatwg.org/multipage/#dom-table-createtfoot
fn create_section_of_type(&self, atom: &LocalName) -> DomRoot<HTMLTableSectionElement> {
fn create_section_of_type(
&self,
atom: &LocalName,
can_gc: CanGc,
) -> DomRoot<HTMLTableSectionElement> {
if let Some(section) = self.get_first_section_of_type(atom) {
return section;
}
let section =
HTMLTableSectionElement::new(atom.clone(), None, &document_from_node(self), None);
let section = HTMLTableSectionElement::new(
atom.clone(),
None,
&document_from_node(self),
None,
can_gc,
);
match *atom {
local_name!("thead") => self.SetTHead(Some(&section)),
local_name!("tfoot") => self.SetTFoot(Some(&section)),
@ -206,7 +218,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
}
// https://html.spec.whatwg.org/multipage/#dom-table-createcaption
fn CreateCaption(&self) -> DomRoot<HTMLTableCaptionElement> {
fn CreateCaption(&self, can_gc: CanGc) -> DomRoot<HTMLTableCaptionElement> {
match self.GetCaption() {
Some(caption) => caption,
None => {
@ -215,6 +227,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
None,
&document_from_node(self),
None,
can_gc,
);
self.SetCaption(Some(&caption))
.expect("Generated caption is invalid");
@ -243,8 +256,8 @@ impl HTMLTableElementMethods for HTMLTableElement {
}
// https://html.spec.whatwg.org/multipage/#dom-table-createthead
fn CreateTHead(&self) -> DomRoot<HTMLTableSectionElement> {
self.create_section_of_type(&local_name!("thead"))
fn CreateTHead(&self, can_gc: CanGc) -> DomRoot<HTMLTableSectionElement> {
self.create_section_of_type(&local_name!("thead"), can_gc)
}
// https://html.spec.whatwg.org/multipage/#dom-table-deletethead
@ -276,8 +289,8 @@ impl HTMLTableElementMethods for HTMLTableElement {
}
// https://html.spec.whatwg.org/multipage/#dom-table-createtfoot
fn CreateTFoot(&self) -> DomRoot<HTMLTableSectionElement> {
self.create_section_of_type(&local_name!("tfoot"))
fn CreateTFoot(&self, can_gc: CanGc) -> DomRoot<HTMLTableSectionElement> {
self.create_section_of_type(&local_name!("tfoot"), can_gc)
}
// https://html.spec.whatwg.org/multipage/#dom-table-deletetfoot
@ -305,12 +318,13 @@ impl HTMLTableElementMethods for HTMLTableElement {
}
// https://html.spec.whatwg.org/multipage/#dom-table-createtbody
fn CreateTBody(&self) -> DomRoot<HTMLTableSectionElement> {
fn CreateTBody(&self, can_gc: CanGc) -> DomRoot<HTMLTableSectionElement> {
let tbody = HTMLTableSectionElement::new(
local_name!("tbody"),
None,
&document_from_node(self),
None,
can_gc,
);
let node = self.upcast::<Node>();
let last_tbody = node
@ -325,7 +339,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
}
// https://html.spec.whatwg.org/multipage/#dom-table-insertrow
fn InsertRow(&self, index: i32) -> Fallible<DomRoot<HTMLTableRowElement>> {
fn InsertRow(&self, index: i32, can_gc: CanGc) -> Fallible<DomRoot<HTMLTableRowElement>> {
let rows = self.Rows();
let number_of_row_elements = rows.Length();
@ -333,8 +347,13 @@ impl HTMLTableElementMethods for HTMLTableElement {
return Err(Error::IndexSize);
}
let new_row =
HTMLTableRowElement::new(local_name!("tr"), None, &document_from_node(self), None);
let new_row = HTMLTableRowElement::new(
local_name!("tr"),
None,
&document_from_node(self),
None,
can_gc,
);
let node = self.upcast::<Node>();
if number_of_row_elements == 0 {
@ -351,7 +370,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
.AppendChild(new_row.upcast::<Node>())
.expect("InsertRow failed to append first row.");
} else {
let tbody = self.CreateTBody();
let tbody = self.CreateTBody(can_gc);
node.AppendChild(tbody.upcast())
.expect("InsertRow failed to append new tbody.");