Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/apiweb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ pub const Interfaces = generate.Tuple(.{
URL.Interfaces,
Iterators.Interfaces,
XMLSerializer.Interfaces,
});
}){};

pub const UserContext = @import("user_context.zig").UserContext;
38 changes: 12 additions & 26 deletions src/browser/dump.zig
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn isVoid(elem: *parser.Element) !bool {
fn writeEscapedTextNode(writer: anytype, value: []const u8) !void {
var v = value;
while (v.len > 0) {
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{'&', '<', '>'}) orelse {
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{ '&', '<', '>' }) orelse {
return writer.writeAll(v);
};
try writer.writeAll(v[0..index]);
Expand All @@ -133,14 +133,14 @@ fn writeEscapedTextNode(writer: anytype, value: []const u8) !void {
'>' => try writer.writeAll("&gt;"),
else => unreachable,
}
v = v[index+1..];
v = v[index + 1 ..];
}
}

fn writeEscapedAttributeValue(writer: anytype, value: []const u8) !void {
var v = value;
while (v.len > 0) {
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{'&', '<', '>', '"'}) orelse {
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{ '&', '<', '>', '"' }) orelse {
return writer.writeAll(v);
};
try writer.writeAll(v[0..index]);
Expand All @@ -151,40 +151,26 @@ fn writeEscapedAttributeValue(writer: anytype, value: []const u8) !void {
'"' => try writer.writeAll("&quot;"),
else => unreachable,
}
v = v[index+1..];
v = v[index + 1 ..];
}
}

const testing = std.testing;
test "dump.writeHTML" {
try testWriteHTML(
"<div id=\"content\">Over 9000!</div>",
"<div id=\"content\">Over 9000!</div>"
);

try testWriteHTML(
"<root><!-- a comment --></root>",
"<root><!-- a comment --></root>"
);

try testWriteHTML(
"<p>&lt; &gt; &amp;</p>",
"<p>&lt; &gt; &amp;</p>"
);

try testWriteHTML(
"<p id=\"&quot;&gt;&lt;&amp;&quot;''\">wat?</p>",
"<p id='\">&lt;&amp;&quot;&#39;&apos;'>wat?</p>"
);
try testWriteHTML("<div id=\"content\">Over 9000!</div>", "<div id=\"content\">Over 9000!</div>");

try testWriteHTML("<root><!-- a comment --></root>", "<root><!-- a comment --></root>");

try testWriteHTML("<p>&lt; &gt; &amp;</p>", "<p>&lt; &gt; &amp;</p>");

try testWriteHTML("<p id=\"&quot;&gt;&lt;&amp;&quot;''\">wat?</p>", "<p id='\">&lt;&amp;&quot;&#39;&apos;'>wat?</p>");

try testWriteFullHTML(
\\<!DOCTYPE html>
\\<html><head><title>It's over what?</title><meta name="a" value="b">
\\</head><body>9000</body></html>
\\
,
"<html><title>It's over what?</title><meta name=a value=\"b\">\n<body>9000"
);
, "<html><title>It's over what?</title><meta name=a value=\"b\">\n<body>9000");
}

fn testWriteHTML(comptime expected: []const u8, src: []const u8) !void {
Expand Down
5 changes: 2 additions & 3 deletions src/dom/character_data.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const std = @import("std");
const jsruntime = @import("jsruntime");
const Case = jsruntime.test_utils.Case;
const checkCases = jsruntime.test_utils.checkCases;
const generate = @import("../generate.zig");

const parser = @import("netsurf");

Expand All @@ -32,12 +31,12 @@ const ProcessingInstruction = @import("processing_instruction.zig").ProcessingIn
const HTMLElem = @import("../html/elements.zig");

// CharacterData interfaces
pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
Comment,
Text.Text,
Text.Interfaces,
ProcessingInstruction,
});
};

// CharacterData implementation
pub const CharacterData = struct {
Expand Down
6 changes: 2 additions & 4 deletions src/dom/dom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

const generate = @import("../generate.zig");

const DOMException = @import("exceptions.zig").DOMException;
const EventTarget = @import("event_target.zig").EventTarget;
const DOMImplementation = @import("implementation.zig").DOMImplementation;
Expand All @@ -27,7 +25,7 @@ const NodeList = @import("nodelist.zig");
const Nod = @import("node.zig");
const MutationObserver = @import("mutation_observer.zig");

pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
DOMException,
EventTarget,
DOMImplementation,
Expand All @@ -37,4 +35,4 @@ pub const Interfaces = generate.Tuple(.{
Nod.Node,
Nod.Interfaces,
MutationObserver.Interfaces,
});
};
6 changes: 2 additions & 4 deletions src/dom/mutation_observer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ const CallbackResult = jsruntime.CallbackResult;
const Case = jsruntime.test_utils.Case;
const checkCases = jsruntime.test_utils.checkCases;

const generate = @import("../generate.zig");

const NodeList = @import("nodelist.zig").NodeList;

pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
MutationObserver,
MutationRecord,
MutationRecords,
});
};

const Walker = @import("../dom/walker.zig").WalkerChildren;

Expand Down
10 changes: 4 additions & 6 deletions src/dom/node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const HTML = @import("../html/html.zig");
const HTMLElem = @import("../html/elements.zig");

// Node interfaces
pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
Attr,
CData.CharacterData,
CData.Interfaces,
Expand All @@ -57,12 +57,10 @@ pub const Interfaces = generate.Tuple(.{
DocumentFragment,
HTMLCollection,
HTMLCollectionIterator,

HTML.Interfaces,
});
const Generated = generate.Union.compile(Interfaces);
pub const Union = Generated._union;
pub const Tags = Generated._enum;
};

pub const Union = generate.Union(Interfaces);

// Node implementation
pub const Node = struct {
Expand Down
5 changes: 2 additions & 3 deletions src/dom/nodelist.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const Callback = jsruntime.Callback;
const CallbackResult = jsruntime.CallbackResult;
const Case = jsruntime.test_utils.Case;
const checkCases = jsruntime.test_utils.checkCases;
const generate = @import("../generate.zig");

const NodeUnion = @import("node.zig").Union;
const Node = @import("node.zig").Node;
Expand All @@ -36,10 +35,10 @@ const log = std.log.scoped(.nodelist);

const DOMException = @import("exceptions.zig").DOMException;

pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
NodeListIterator,
NodeList,
});
};

pub const NodeListIterator = struct {
pub const mem_guarantied = true;
Expand Down
5 changes: 2 additions & 3 deletions src/dom/text.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const std = @import("std");
const jsruntime = @import("jsruntime");
const Case = jsruntime.test_utils.Case;
const checkCases = jsruntime.test_utils.checkCases;
const generate = @import("../generate.zig");

const parser = @import("netsurf");

Expand All @@ -31,9 +30,9 @@ const CDATASection = @import("cdata_section.zig").CDATASection;
const UserContext = @import("../user_context.zig").UserContext;

// Text interfaces
pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
CDATASection,
});
};

pub const Text = struct {
pub const Self = parser.Text;
Expand Down
8 changes: 4 additions & 4 deletions src/events/event.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ const ProgressEvent = @import("../xhr/progress_event.zig").ProgressEvent;
const log = std.log.scoped(.events);

// Event interfaces
pub const Interfaces = generate.Tuple(.{
pub const Interfaces = .{
Event,
ProgressEvent,
});
const Generated = generate.Union.compile(Interfaces);
pub const Union = Generated._union;
};

pub const Union = generate.Union(Interfaces);

// https://dom.spec.whatwg.org/#event
pub const Event = struct {
Expand Down
Loading