Repository: jaytaph/gosub-browser
File: src/html5/node.rs (Rust)

Code before:
    /// ID of the node, 0 is always the root / document node
    pub id: NodeId,
    /// parent of the node, if any
    pub parent: Option<NodeId>,
    /// children of the node
    pub children: Vec<NodeId>,
    /// name of the node, or empty when it's not a tag
    pub name: String,
    /// namespace of the node
    pub namespace: Option<String>,
    /// actual data of the node
    pub data: NodeData,
    /// weak pointer to document this node is attached to
    pub document: Weak<RefCell<Document>>,
    // Returns true when the given node is registered into an arena
    pub is_registered: bool,
}

impl PartialEq for Node {
    fn eq(&self, other: &Node) -> bool {
        self.id == other.id
    }
}

impl Node {
    /// Returns true when the given node is of the given namespace
    pub(crate) fn is_namespace(&self, namespace: &str) -> bool {
        self.namespace == Some(namespace.into())
    }

    /// Returns true if the given node is a html integration point
    /// See: https://html.spec.whatwg.org/multipage/parsing.html#html-integration-point
    pub(crate) fn is_html_integration_point(&self) -> bool {
        let namespace = self.namespace.clone().unwrap_or_default();

        if namespace == MATHML_NAMESPACE && self.name == "annotation-xml" {
            if let NodeData::Element(element) = &self.data {
                if let Some(value) = element.attributes.get("encoding") {
                    if value.eq_ignore_ascii_case("text/html") {
                        return true;
                    }
                    if value.eq_ignore_ascii_case("application/xhtml+xml") {
                        return true;
                    }
                }
            }
        }

        namespace == SVG_NAMESPACE
            && ["foreignObject", "desc", "title"].contains(&self.name.as_str())
    }

Review comment (suggestion):
This was added since `Weak<RefCell>` doesn't have a `PartialEq` implementation and `#[derive(PartialEq)]` no longer worked. I think two Nodes should be equal if their `id`s are equal

Code after:
/// Node structure that resembles a DOM node
pub struct Node {
    /// ID of the node, 0 is always the root / document node
    pub id: NodeId,
    /// parent of the node, if any
    pub parent: Option<NodeId>,
    /// children of the node
    pub children: Vec<NodeId>,
    /// name of the node, or empty when it's not a tag
    pub name: String,
    /// namespace of the node
    pub namespace: Option<String>,
    /// actual data of the node
    pub data: NodeData,
    /// weak pointer to document this node is attached to
    pub document: Weak<RefCell<Document>>,
    // Returns true when the given node is registered into an arena
    pub is_registered: bool,
}

impl PartialEq for Node {
    fn eq(&self, other: &Node) -> bool {
        self.id == other.id
    }
}

impl Node {
    /// Returns true when the given node is of the given namespace
    pub(crate) fn is_namespace(&self, namespace: &str) -> bool {
        self.namespace == Some(namespace.into())
    }

    /// Returns true if the given node is a html integration point
    /// See: https://html.spec.whatwg.org/multipage/parsing.html#html-integration-point
    pub(crate) fn is_html_integration_point(&self) -> bool {
        let namespace = self.namespace.clone().unwrap_or_default();

        if namespace == MATHML_NAMESPACE && self.name == "annotation-xml" {
            if let NodeData::Element(element) = &self.data {
                if let Some(value) = element.attributes.get("encoding") {
                    if value.eq_ignore_ascii_case("text/html") {
                        return true;
                    }
                    if value.eq_ignore_ascii_case("application/xhtml+xml") {
                        return true;
                    }
                }
            }
        }

        namespace == SVG_NAMESPACE