1515//
1616// You should have received a copy of the GNU Affero General Public License
1717// along with this program. If not, see <https://www.gnu.org/licenses/>.
18+ const std = @import ("std" );
1819
1920const parser = @import ("../netsurf.zig" );
2021
22+ const jsruntime = @import ("jsruntime" );
23+ const Case = jsruntime .test_utils .Case ;
24+ const checkCases = jsruntime .test_utils .checkCases ;
25+
2126const CharacterData = @import ("character_data.zig" ).CharacterData ;
2227
28+ const UserContext = @import ("../user_context.zig" ).UserContext ;
29+
2330// https://dom.spec.whatwg.org/#interface-comment
2431pub const Comment = struct {
2532 pub const Self = parser .Comment ;
@@ -32,7 +39,29 @@ pub const Comment = struct {
3239 // > and this’s node document to current global object’s associated
3340 // > Document.
3441 // https://dom.spec.whatwg.org/#dom-comment-comment
35- pub fn constructor () ! * parser.Comment {
36- return error .NotImplemented ;
42+ pub fn constructor (userctx : UserContext , data : ? []const u8 ) ! * parser.Comment {
43+ if (userctx .document == null ) return parser .DOMError .NotSupported ;
44+
45+ return parser .documentCreateComment (
46+ parser .documentHTMLToDocument (userctx .document .? ),
47+ data orelse "" ,
48+ );
3749 }
3850};
51+
52+ // Tests
53+ // -----
54+
55+ pub fn testExecFn (
56+ _ : std.mem.Allocator ,
57+ js_env : * jsruntime.Env ,
58+ ) anyerror ! void {
59+ var constructor = [_ ]Case {
60+ .{ .src = "let comment = new Comment('foo')" , .ex = "undefined" },
61+ .{ .src = "comment.data" , .ex = "foo" },
62+
63+ .{ .src = "let emptycomment = new Comment()" , .ex = "undefined" },
64+ .{ .src = "emptycomment.data" , .ex = "" },
65+ };
66+ try checkCases (js_env , & constructor );
67+ }
0 commit comments