script/dom/
comment.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6use js::rust::HandleObject;
7
8use crate::dom::bindings::codegen::Bindings::CommentBinding::CommentMethods;
9use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
10use crate::dom::bindings::error::Fallible;
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::bindings::str::DOMString;
13use crate::dom::characterdata::CharacterData;
14use crate::dom::document::Document;
15use crate::dom::node::Node;
16use crate::dom::window::Window;
17use crate::script_runtime::CanGc;
18
19/// An HTML comment.
20#[dom_struct]
21pub(crate) struct Comment {
22    characterdata: CharacterData,
23}
24
25impl Comment {
26    fn new_inherited(text: DOMString, document: &Document) -> Comment {
27        Comment {
28            characterdata: CharacterData::new_inherited(text, document),
29        }
30    }
31
32    pub(crate) fn new(
33        text: DOMString,
34        document: &Document,
35        proto: Option<HandleObject>,
36        can_gc: CanGc,
37    ) -> DomRoot<Comment> {
38        Node::reflect_node_with_proto(
39            Box::new(Comment::new_inherited(text, document)),
40            document,
41            proto,
42            can_gc,
43        )
44    }
45}
46
47impl CommentMethods<crate::DomTypeHolder> for Comment {
48    /// <https://dom.spec.whatwg.org/#dom-comment-comment>
49    fn Constructor(
50        window: &Window,
51        proto: Option<HandleObject>,
52        can_gc: CanGc,
53        data: DOMString,
54    ) -> Fallible<DomRoot<Comment>> {
55        let document = window.Document();
56        Ok(Comment::new(data, &document, proto, can_gc))
57    }
58}