|
15 | 15 | // |
16 | 16 | // You should have received a copy of the GNU Affero General Public License |
17 | 17 | // along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | +const std = @import("std"); |
18 | 19 |
|
19 | 20 | const parser = @import("../netsurf.zig"); |
20 | 21 | const generate = @import("../generate.zig"); |
21 | 22 |
|
| 23 | +const jsruntime = @import("jsruntime"); |
| 24 | +const Case = jsruntime.test_utils.Case; |
| 25 | +const checkCases = jsruntime.test_utils.checkCases; |
| 26 | + |
22 | 27 | const Element = @import("../dom/element.zig").Element; |
23 | 28 |
|
24 | 29 | // HTMLElement interfaces |
@@ -126,10 +131,31 @@ pub const HTMLUnknownElement = struct { |
126 | 131 | pub const mem_guarantied = true; |
127 | 132 | }; |
128 | 133 |
|
| 134 | +// https://html.spec.whatwg.org/#the-a-element |
129 | 135 | pub const HTMLAnchorElement = struct { |
130 | 136 | pub const Self = parser.Anchor; |
131 | 137 | pub const prototype = *HTMLElement; |
132 | 138 | pub const mem_guarantied = true; |
| 139 | + |
| 140 | + pub fn get_target(self: *parser.Anchor) ![]const u8 { |
| 141 | + return try parser.anchorGetTarget(self); |
| 142 | + } |
| 143 | + |
| 144 | + pub fn set_target(self: *parser.Anchor, href: []const u8) !void { |
| 145 | + return try parser.anchorSetTarget(self, href); |
| 146 | + } |
| 147 | + |
| 148 | + pub fn get_download(_: *parser.Anchor) ![]const u8 { |
| 149 | + return ""; // TODO |
| 150 | + } |
| 151 | + |
| 152 | + pub fn get_href(self: *parser.Anchor) ![]const u8 { |
| 153 | + return try parser.anchorGetHref(self); |
| 154 | + } |
| 155 | + |
| 156 | + pub fn set_href(self: *parser.Anchor, href: []const u8) !void { |
| 157 | + return try parser.anchorSetTarget(self, href); |
| 158 | + } |
133 | 159 | }; |
134 | 160 |
|
135 | 161 | pub const HTMLAppletElement = struct { |
@@ -589,3 +615,20 @@ pub fn toInterface(comptime T: type, e: *parser.Element) !T { |
589 | 615 | .undef => .{ .HTMLUnknownElement = @as(*parser.Unknown, @ptrCast(elem)) }, |
590 | 616 | }; |
591 | 617 | } |
| 618 | + |
| 619 | +// Tests |
| 620 | +// ----- |
| 621 | + |
| 622 | +pub fn testExecFn( |
| 623 | + _: std.mem.Allocator, |
| 624 | + js_env: *jsruntime.Env, |
| 625 | +) anyerror!void { |
| 626 | + var anchor = [_]Case{ |
| 627 | + .{ .src = "let a = document.getElementById('link')", .ex = "undefined" }, |
| 628 | + .{ .src = "a.target", .ex = "" }, |
| 629 | + .{ .src = "a.target = '_blank'", .ex = "_blank" }, |
| 630 | + .{ .src = "a.href", .ex = "foo" }, |
| 631 | + .{ .src = "a.href = 'https://lightpanda.io/'", .ex = "https://lightpanda.io/" }, |
| 632 | + }; |
| 633 | + try checkCases(js_env, &anchor); |
| 634 | +} |
0 commit comments