@@ -25,6 +25,7 @@ pub const NamedNodeMap = struct {
2525 pub const Self = parser .NamedNodeMap ;
2626
2727 pub const Exception = DOMException ;
28+ pub const Iterator = NamedNodeMapIterator ;
2829
2930 // TODO implement LegacyUnenumerableNamedProperties.
3031 // https://webidl.spec.whatwg.org/#LegacyUnenumerableNamedProperties
@@ -70,11 +71,48 @@ pub const NamedNodeMap = struct {
7071 }
7172
7273 pub fn indexed_get (self : * parser.NamedNodeMap , index : u32 , has_value : * bool ) ! * parser.Attribute {
73- return (try NamedNodeMap . _item (self , index )) orelse {
74+ return (try _item (self , index )) orelse {
7475 has_value .* = false ;
7576 return undefined ;
7677 };
7778 }
79+
80+ pub fn named_get (self : * parser.NamedNodeMap , name : []const u8 , has_value : * bool ) ! * parser.Attribute {
81+ return (try _getNamedItem (self , name )) orelse {
82+ has_value .* = false ;
83+ return undefined ;
84+ };
85+ }
86+
87+ pub fn _symbol_iterator (self : * parser.NamedNodeMap ) NamedNodeMapIterator {
88+ return .{ .map = self };
89+ }
90+ };
91+
92+ pub const NamedNodeMapIterator = struct {
93+ index : u32 = 0 ,
94+ map : * parser.NamedNodeMap ,
95+
96+ pub const Return = struct {
97+ done : bool ,
98+ value : ? * parser.Attribute ,
99+ };
100+
101+ pub fn _next (self : * NamedNodeMapIterator ) ! Return {
102+ const e = try NamedNodeMap ._item (self .map , self .index );
103+ if (e == null ) {
104+ return .{
105+ .value = null ,
106+ .done = true ,
107+ };
108+ }
109+
110+ self .index += 1 ;
111+ return .{
112+ .value = e ,
113+ .done = false ,
114+ };
115+ }
78116};
79117
80118// Tests
@@ -93,5 +131,8 @@ test "Browser.DOM.NamedNodeMap" {
93131 .{ "a.getNamedItem('id')" , "[object Attr]" },
94132 .{ "a.getNamedItem('foo')" , "null" },
95133 .{ "a.setNamedItem(a.getNamedItem('id'))" , "[object Attr]" },
134+ .{ "a['id'].name" , "id" },
135+ .{ "a['id'].value" , "content" },
136+ .{ "a['other']" , "undefined" },
96137 }, .{});
97138}
0 commit comments