From 7d742d62b893090125d5a677cda670a41be38186 Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Thu, 24 Apr 2025 14:35:05 +0200 Subject: [PATCH 1/2] SVGElement dummy --- src/browser/dom/element.zig | 1 + src/browser/html/html.zig | 2 ++ src/browser/html/svg_elements.zig | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 src/browser/html/svg_elements.zig 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..c3342164 --- /dev/null +++ b/src/browser/html/svg_elements.zig @@ -0,0 +1,31 @@ +// 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; +}; From 7d9f6eef27c074ec96c402cb53a3292e58e8a2dd Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Thu, 24 Apr 2025 14:56:16 +0200 Subject: [PATCH 2/2] instanceof svgelement test --- src/browser/html/svg_elements.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/browser/html/svg_elements.zig b/src/browser/html/svg_elements.zig index c3342164..867256d0 100644 --- a/src/browser/html/svg_elements.zig +++ b/src/browser/html/svg_elements.zig @@ -29,3 +29,13 @@ pub const SVGElement = struct { // 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" }, + }, .{}); +}