Skip to content

Commit 2910f4f

Browse files
Merge pull request #581 from lightpanda-io/svgelement_dummy2
Svgelement dummy2
2 parents 93c0df3 + 7d9f6ee commit 2910f4f

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/browser/dom/element.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub const Element = struct {
4848

4949
pub fn toInterface(e: *parser.Element) !Union {
5050
return try HTMLElem.toInterface(Union, e);
51+
// SVGElement and MathML are not supported yet.
5152
}
5253

5354
// JS funcs

src/browser/html/html.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
const HTMLDocument = @import("document.zig").HTMLDocument;
2020
const HTMLElem = @import("elements.zig");
21+
const SVGElem = @import("svg_elements.zig");
2122
const Window = @import("window.zig").Window;
2223
const Navigator = @import("navigator.zig").Navigator;
2324
const History = @import("history.zig").History;
@@ -28,6 +29,7 @@ pub const Interfaces = .{
2829
HTMLElem.HTMLElement,
2930
HTMLElem.HTMLMediaElement,
3031
HTMLElem.Interfaces,
32+
SVGElem.SVGElement,
3133
Window,
3234
Navigator,
3335
History,

src/browser/html/svg_elements.zig

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 Element = @import("../dom/element.zig").Element;
20+
21+
// Support for SVGElements is very limited, this is a dummy implementation.
22+
// This is here no to be able to support `element instanceof SVGElement;` in JavaScript.
23+
// https://developer.mozilla.org/en-US/docs/Web/API/SVGElement
24+
pub const SVGElement = struct {
25+
// Currently the prototype chain is not implemented (will not be returned by toInterface())
26+
// For that we need parser.SvgElement and the derived types with tags in the v-table.
27+
pub const prototype = *Element;
28+
// While this is a Node, could consider not exposing the subtype untill we have
29+
// a Self type to cast to.
30+
pub const subtype = .node;
31+
};
32+
33+
const testing = @import("../../testing.zig");
34+
test "Browser.HTML.SVGElement" {
35+
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
36+
defer runner.deinit();
37+
38+
try runner.testCases(&.{
39+
.{ "'AString' instanceof SVGElement", "false" },
40+
}, .{});
41+
}

0 commit comments

Comments
 (0)