Skip to content

Commit 1ff422a

Browse files
authored
Merge pull request #659 from lightpanda-io/dedup-document
Deduplicate document
2 parents a99d193 + 76f1fcb commit 1ff422a

File tree

10 files changed

+9
-15
lines changed

10 files changed

+9
-15
lines changed

src/browser/dom/comment.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub const Comment = struct {
3030

3131
pub fn constructor(data: ?[]const u8, state: *const SessionState) !*parser.Comment {
3232
return parser.documentCreateComment(
33-
parser.documentHTMLToDocument(state.document.?),
33+
parser.documentHTMLToDocument(state.window.document.?),
3434
data orelse "",
3535
);
3636
}

src/browser/dom/document.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ pub const Document = struct {
4141

4242
pub fn constructor(state: *const SessionState) !*parser.DocumentHTML {
4343
const doc = try parser.documentCreateDocument(
44-
try parser.documentHTMLGetTitle(state.document.?),
44+
try parser.documentHTMLGetTitle(state.window.document.?),
4545
);
4646

4747
// we have to work w/ document instead of html document.
4848
const ddoc = parser.documentHTMLToDocument(doc);
49-
const ccur = parser.documentHTMLToDocument(state.document.?);
49+
const ccur = parser.documentHTMLToDocument(state.window.document.?);
5050
try parser.documentSetDocumentURI(ddoc, try parser.documentGetDocumentURI(ccur));
5151
try parser.documentSetInputEncoding(ddoc, try parser.documentGetInputEncoding(ccur));
5252

src/browser/dom/document_fragment.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub const DocumentFragment = struct {
2929

3030
pub fn constructor(state: *const SessionState) !*parser.DocumentFragment {
3131
return parser.documentCreateDocumentFragment(
32-
parser.documentHTMLToDocument(state.document.?),
32+
parser.documentHTMLToDocument(state.window.document.?),
3333
);
3434
}
3535

src/browser/dom/intersection_observer.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub const IntersectionObserver = struct {
5050
// new IntersectionObserver(callback, options) [not supported yet]
5151
pub fn constructor(callback: Env.Callback, options_: ?IntersectionObserverOptions, state: *SessionState) !IntersectionObserver {
5252
var options = IntersectionObserverOptions{
53-
.root = parser.documentToNode(parser.documentHTMLToDocument(state.document.?)),
53+
.root = parser.documentToNode(parser.documentHTMLToDocument(state.window.document.?)),
5454
.rootMargin = "0px 0px 0px 0px",
5555
.threshold = &.{0.0},
5656
};
@@ -142,7 +142,7 @@ pub const IntersectionObserverEntry = struct {
142142
// Returns a DOMRectReadOnly for the intersection observer's root.
143143
pub fn get_rootBounds(self: *const IntersectionObserverEntry) !Element.DOMRect {
144144
const root = self.options.root.?;
145-
if (@intFromPtr(root) == @intFromPtr(self.state.document.?)) {
145+
if (@intFromPtr(root) == @intFromPtr(self.state.window.document.?)) {
146146
return self.state.renderer.boundingRect();
147147
}
148148

src/browser/dom/processing_instruction.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub const ProcessingInstruction = struct {
4141
// a simple workaround.
4242
pub fn _cloneNode(self: *parser.ProcessingInstruction, _: ?bool, state: *SessionState) !*parser.ProcessingInstruction {
4343
return try parser.documentCreateProcessingInstruction(
44-
@ptrCast(state.document),
44+
@ptrCast(state.window.document.?),
4545
try get_target(self),
4646
(try get_data(self)) orelse "",
4747
);

src/browser/dom/text.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub const Text = struct {
3434

3535
pub fn constructor(data: ?[]const u8, state: *const SessionState) !*parser.Text {
3636
return parser.documentCreateTextNode(
37-
parser.documentHTMLToDocument(state.document.?),
37+
parser.documentHTMLToDocument(state.window.document.?),
3838
data orelse "",
3939
);
4040
}

src/browser/env.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub const SessionState = struct {
5656
arena: std.mem.Allocator,
5757
http_client: *HttpClient,
5858
cookie_jar: *storage.CookieJar,
59-
document: ?*parser.DocumentHTML,
6059

6160
// dangerous, but set by the JS framework
6261
// shorter-lived than the arena above, which

src/browser/page.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ pub const Page = struct {
9595
.window_clicked_event_node = .{ .func = windowClicked },
9696
.state = .{
9797
.arena = arena,
98-
.document = null,
9998
.url = &self.url,
10099
.window = &self.window,
101100
.renderer = &self.renderer,
@@ -277,9 +276,6 @@ pub const Page = struct {
277276

278277
// https://html.spec.whatwg.org/#read-html
279278

280-
// update the sessions state
281-
self.state.document = html_doc;
282-
283279
// browse the DOM tree to retrieve scripts
284280
// TODO execute the synchronous scripts during the HTL parsing.
285281
// TODO fetch the script resources concurrently but execute them in the

src/main_wpt.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn run(arena: Allocator, test_file: []const u8, loader: *FileLoader, err_out: *?
116116
try polyfill.load(arena, runner.scope);
117117

118118
// loop over the scripts.
119-
const doc = parser.documentHTMLToDocument(runner.state.document.?);
119+
const doc = parser.documentHTMLToDocument(runner.state.window.document.?);
120120
const scripts = try parser.documentGetElementsByTagName(doc, "script");
121121
const script_count = try parser.nodeListLength(scripts);
122122
for (0..script_count) |i| {

src/testing.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ pub const JsRunner = struct {
421421
self.state = .{
422422
.arena = arena,
423423
.loop = &self.loop,
424-
.document = document,
425424
.url = &self.url,
426425
.window = &self.window,
427426
.renderer = &self.renderer,

0 commit comments

Comments
 (0)