window: inject DocumentHTML instead of Document

This commit is contained in:
Pierre Tachoire
2024-03-07 14:39:51 +01:00
parent 500da5bfd8
commit 886c9daa47
6 changed files with 9 additions and 9 deletions

View File

@@ -229,7 +229,7 @@ pub const Page = struct {
// TODO set the referrer to the document. // TODO set the referrer to the document.
self.session.window.replaceDocument(doc); self.session.window.replaceDocument(html_doc);
// https://html.spec.whatwg.org/#read-html // https://html.spec.whatwg.org/#read-html

View File

@@ -14,7 +14,7 @@ pub const Window = struct {
// Extend libdom event target for pure zig struct. // Extend libdom event target for pure zig struct.
base: parser.EventTargetTBase = parser.EventTargetTBase{}, base: parser.EventTargetTBase = parser.EventTargetTBase{},
document: ?*parser.Document = null, document: ?*parser.DocumentHTML = null,
target: []const u8, target: []const u8,
pub fn create(target: ?[]const u8) Window { pub fn create(target: ?[]const u8) Window {
@@ -23,7 +23,7 @@ pub const Window = struct {
}; };
} }
pub fn replaceDocument(self: *Window, doc: *parser.Document) void { pub fn replaceDocument(self: *Window, doc: *parser.DocumentHTML) void {
self.document = doc; self.document = doc;
} }
@@ -39,7 +39,7 @@ pub const Window = struct {
return self; return self;
} }
pub fn get_document(self: *Window) ?*parser.Document { pub fn get_document(self: *Window) ?*parser.DocumentHTML {
return self.document; return self.document;
} }

View File

@@ -23,7 +23,7 @@ fn execJS(
// alias global as self and window // alias global as self and window
var window = Window.create(null); var window = Window.create(null);
window.replaceDocument(parser.documentHTMLToDocument(doc)); window.replaceDocument(doc);
try js_env.bindGlobal(window); try js_env.bindGlobal(window);
while (true) { while (true) {

View File

@@ -22,7 +22,7 @@ fn execJS(
// alias global as self and window // alias global as self and window
var window = Window.create(null); var window = Window.create(null);
window.replaceDocument(parser.documentHTMLToDocument(doc)); window.replaceDocument(doc);
try js_env.bindGlobal(window); try js_env.bindGlobal(window);
// launch shellExec // launch shellExec

View File

@@ -51,7 +51,7 @@ fn testExecFn(
// alias global as self and window // alias global as self and window
var window = Window.create(null); var window = Window.create(null);
window.replaceDocument(parser.documentHTMLToDocument(doc)); window.replaceDocument(doc);
try js_env.bindGlobal(window); try js_env.bindGlobal(window);
// run test // run test

View File

@@ -23,7 +23,6 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
defer file.close(); defer file.close();
const html_doc = try parser.documentHTMLParse(file.reader(), "UTF-8"); const html_doc = try parser.documentHTMLParse(file.reader(), "UTF-8");
const doc = parser.documentHTMLToDocument(html_doc);
const dirname = fspath.dirname(f[dir.len..]) orelse unreachable; const dirname = fspath.dirname(f[dir.len..]) orelse unreachable;
@@ -52,7 +51,7 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
// setup global env vars. // setup global env vars.
var window = Window.create(null); var window = Window.create(null);
window.replaceDocument(doc); window.replaceDocument(html_doc);
try js_env.bindGlobal(window); try js_env.bindGlobal(window);
// thanks to the arena, we don't need to deinit res. // thanks to the arena, we don't need to deinit res.
@@ -70,6 +69,7 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
} }
// loop hover the scripts. // loop hover the scripts.
const doc = parser.documentHTMLToDocument(html_doc);
const scripts = try parser.documentGetElementsByTagName(doc, "script"); const scripts = try parser.documentGetElementsByTagName(doc, "script");
const slen = try parser.nodeListLength(scripts); const slen = try parser.nodeListLength(scripts);
for (0..slen) |i| { for (0..slen) |i| {