diff --git a/src/browser/dom/element.zig b/src/browser/dom/element.zig index 58016167..3aeac4bd 100644 --- a/src/browser/dom/element.zig +++ b/src/browser/dom/element.zig @@ -48,6 +48,7 @@ pub const Element = struct { pub fn toInterface(e: *parser.Element) !Union { return try HTMLElem.toInterface(Union, e); + // SVGElement and MathML are not supported yet. } // JS funcs diff --git a/src/browser/html/html.zig b/src/browser/html/html.zig index 513e3fe5..6e576228 100644 --- a/src/browser/html/html.zig +++ b/src/browser/html/html.zig @@ -18,6 +18,7 @@ const HTMLDocument = @import("document.zig").HTMLDocument; const HTMLElem = @import("elements.zig"); +const SVGElem = @import("svg_elements.zig"); const Window = @import("window.zig").Window; const Navigator = @import("navigator.zig").Navigator; const History = @import("history.zig").History; @@ -28,6 +29,7 @@ pub const Interfaces = .{ HTMLElem.HTMLElement, HTMLElem.HTMLMediaElement, HTMLElem.Interfaces, + SVGElem.SVGElement, Window, Navigator, History, diff --git a/src/browser/html/svg_elements.zig b/src/browser/html/svg_elements.zig new file mode 100644 index 00000000..867256d0 --- /dev/null +++ b/src/browser/html/svg_elements.zig @@ -0,0 +1,41 @@ +// Copyright (C) 2023-2024 Lightpanda (Selecy SAS) +// +// Francis Bouvier +// Pierre Tachoire +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +const Element = @import("../dom/element.zig").Element; + +// Support for SVGElements is very limited, this is a dummy implementation. +// This is here no to be able to support `element instanceof SVGElement;` in JavaScript. +// https://developer.mozilla.org/en-US/docs/Web/API/SVGElement +pub const SVGElement = struct { + // Currently the prototype chain is not implemented (will not be returned by toInterface()) + // For that we need parser.SvgElement and the derived types with tags in the v-table. + pub const prototype = *Element; + // While this is a Node, could consider not exposing the subtype untill we have + // a Self type to cast to. + pub const subtype = .node; +}; + +const testing = @import("../../testing.zig"); +test "Browser.HTML.SVGElement" { + var runner = try testing.jsRunner(testing.tracking_allocator, .{}); + defer runner.deinit(); + + try runner.testCases(&.{ + .{ "'AString' instanceof SVGElement", "false" }, + }, .{}); +}