@@ -21,6 +21,9 @@ const std = @import("std");
2121const parser = @import ("../netsurf.zig" );
2222const Page = @import ("../page.zig" ).Page ;
2323
24+ const NodeUnion = @import ("node.zig" ).Union ;
25+ const Node = @import ("node.zig" ).Node ;
26+
2427pub const Interfaces = .{
2528 AbstractRange ,
2629 Range ,
@@ -42,16 +45,16 @@ pub const AbstractRange = struct {
4245 return self .collapsed ;
4346 }
4447
45- pub fn get_endContainer (self : * const AbstractRange ) * parser.Node {
46- return self .end_container ;
48+ pub fn get_endContainer (self : * const AbstractRange ) ! NodeUnion {
49+ return Node . toInterface ( self .end_container ) ;
4750 }
4851
4952 pub fn get_endOffset (self : * const AbstractRange ) i32 {
5053 return self .end_offset ;
5154 }
5255
53- pub fn get_startContainer (self : * const AbstractRange ) * parser.Node {
54- return self .start_container ;
56+ pub fn get_startContainer (self : * const AbstractRange ) ! NodeUnion {
57+ return Node . toInterface ( self .start_container ) ;
5558 }
5659
5760 pub fn get_startOffset (self : * const AbstractRange ) i32 {
@@ -64,12 +67,15 @@ pub const Range = struct {
6467
6568 proto : AbstractRange ,
6669
67- pub fn constructor () Range {
70+ // The Range() constructor returns a newly created Range object whose start
71+ // and end is the global Document object.
72+ // https://developer.mozilla.org/en-US/docs/Web/API/Range/Range
73+ pub fn constructor (page : * Page ) Range {
6874 const proto : AbstractRange = .{
6975 .collapsed = true ,
70- .end_container = undefined ,
76+ .end_container = parser . documentHTMLToNode ( page . window . document ) ,
7177 .end_offset = 0 ,
72- .start_container = undefined ,
78+ .start_container = parser . documentHTMLToNode ( page . window . document ) ,
7379 .start_offset = 0 ,
7480 };
7581
@@ -137,6 +143,8 @@ test "Browser.Range" {
137143 .{ "range.collapsed" , "true" },
138144 .{ "range.startOffset" , "0" },
139145 .{ "range.endOffset" , "0" },
146+ .{ "range.startContainer instanceof HTMLDocument" , "true" },
147+ .{ "range.endContainer instanceof HTMLDocument" , "true" },
140148
141149 // Test document.createRange()
142150 .{ "let docRange = document.createRange()" , "undefined" },
0 commit comments