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;
17
18/// An HTML comment.
19#[dom_struct]
20pub(crate) struct Comment {
21    characterdata: CharacterData,
22}
23
24impl Comment {
25    fn new_inherited(text: DOMString, document: &Document) -> Comment {
26        Comment {
27            characterdata: CharacterData::new_inherited(text, document),
28        }
29    }
30
31    pub(crate) fn new(
32        cx: &mut js::context::JSContext,
33        text: DOMString,
34        document: &Document,
35        proto: Option<HandleObject>,
36    ) -> DomRoot<Comment> {
37        Node::reflect_node_with_proto(
38            cx,
39            Box::new(Comment::new_inherited(text, document)),
40            document,
41            proto,
42        )
43    }
44}
45
46impl CommentMethods<crate::DomTypeHolder> for Comment {
47    /// <https://dom.spec.whatwg.org/#dom-comment-comment>
48    fn Constructor(
49        cx: &mut js::context::JSContext,
50        window: &Window,
51        proto: Option<HandleObject>,
52        data: DOMString,
53    ) -> Fallible<DomRoot<Comment>> {
54        let document = window.Document();
55        Ok(Comment::new(cx, data, &document, proto))
56    }
57}