Skip to content

Commit fada732

Browse files
committed
add NodeFilter
1 parent 152d0fd commit fada732

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/browser/dom/dom.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const MutationObserver = @import("mutation_observer.zig");
2727
const IntersectionObserver = @import("intersection_observer.zig");
2828
const DOMParser = @import("dom_parser.zig").DOMParser;
2929
const TreeWalker = @import("tree_walker.zig").TreeWalker;
30+
const NodeFilter = @import("node_filter.zig").NodeFilter;
3031

3132
pub const Interfaces = .{
3233
DOMException,
@@ -41,4 +42,5 @@ pub const Interfaces = .{
4142
IntersectionObserver.Interfaces,
4243
DOMParser,
4344
TreeWalker,
45+
NodeFilter,
4446
};

src/browser/dom/node_filter.zig

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (C) 2023-2024 Lightpanda (Selecy SAS)
2+
//
3+
// Francis Bouvier <[email protected]>
4+
// Pierre Tachoire <[email protected]>
5+
//
6+
// This program is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU Affero General Public License as
8+
// published by the Free Software Foundation, either version 3 of the
9+
// License, or (at your option) any later version.
10+
//
11+
// This program is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU Affero General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU Affero General Public License
17+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
19+
const std = @import("std");
20+
21+
pub const NodeFilter = struct {
22+
pub const _FILTER_ACCEPT: u16 = 1;
23+
pub const _FILTER_REJECT: u16 = 2;
24+
pub const _FILTER_SKIP: u16 = 3;
25+
pub const _SHOW_ALL: u32 = std.math.maxInt(u32);
26+
pub const _SHOW_ELEMENT: u32 = 0b1;
27+
pub const _SHOW_ATTRIBUTE: u32 = 0b10;
28+
pub const _SHOW_TEXT: u32 = 0b100;
29+
pub const _SHOW_CDATA_SECTION: u32 = 0b1000;
30+
pub const _SHOW_ENTITY_REFERENCE: u32 = 0b10000;
31+
pub const _SHOW_ENTITY: u32 = 0b100000;
32+
pub const _SHOW_PROCESSING_INSTRUCTION: u32 = 0b1000000;
33+
pub const _SHOW_COMMENT: u32 = 0b10000000;
34+
pub const _SHOW_DOCUMENT: u32 = 0b100000000;
35+
pub const _SHOW_DOCUMENT_TYPE: u32 = 0b1000000000;
36+
pub const _SHOW_DOCUMENT_FRAGMENT: u32 = 0b10000000000;
37+
pub const _SHOW_NOTATION: u32 = 0b100000000000;
38+
};
39+
40+
const testing = @import("../../testing.zig");
41+
test "Browser.DOM.NodeFilter" {
42+
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
43+
defer runner.deinit();
44+
45+
try runner.testCases(&.{
46+
.{ "NodeFilter.FILTER_ACCEPT", "1" },
47+
.{ "NodeFilter.FILTER_REJECT", "2" },
48+
.{ "NodeFilter.FILTER_SKIP", "3" },
49+
.{ "NodeFilter.SHOW_ALL", "4294967295" },
50+
.{ "NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT", "129" },
51+
}, .{});
52+
}

0 commit comments

Comments
 (0)