From b53d4a149c21b5f336da3cde05fb849c9ffea326 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 15 Dec 2023 17:25:23 +0100 Subject: [PATCH] add nav web api --- src/{dom.zig => apiweb.zig} | 2 ++ src/main.zig | 4 ++-- src/main_shell.zig | 4 ++-- src/main_wpt.zig | 5 +++-- src/nav/nav.zig | 7 +++++++ src/nav/window.zig | 41 +++++++++++++++++++++++++++++++++++++ src/run_tests.zig | 4 ++-- 7 files changed, 59 insertions(+), 8 deletions(-) rename src/{dom.zig => apiweb.zig} (86%) create mode 100644 src/nav/nav.zig create mode 100644 src/nav/window.zig diff --git a/src/dom.zig b/src/apiweb.zig similarity index 86% rename from src/dom.zig rename to src/apiweb.zig index 08f4c3f5..32831909 100644 --- a/src/dom.zig +++ b/src/apiweb.zig @@ -4,6 +4,7 @@ const Console = @import("jsruntime").Console; const DOM = @import("dom/dom.zig"); const HTML = @import("html/html.zig"); +const nav = @import("nav/nav.zig"); pub const HTMLDocument = @import("html/document.zig").HTMLDocument; @@ -12,4 +13,5 @@ pub const Interfaces = generate.Tuple(.{ Console, DOM.Interfaces, HTML.Interfaces, + nav.Interfaces, }); diff --git a/src/main.zig b/src/main.zig index 9341072e..4469cddb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3,9 +3,9 @@ const std = @import("std"); const jsruntime = @import("jsruntime"); const parser = @import("netsurf.zig"); -const DOM = @import("dom.zig"); +const apiweb = @import("apiweb.zig"); -pub const Types = jsruntime.reflect(DOM.Interfaces); +pub const Types = jsruntime.reflect(apiweb.Interfaces); const socket_path = "/tmp/browsercore-server.sock"; diff --git a/src/main_shell.zig b/src/main_shell.zig index 35d1fb39..920c77bf 100644 --- a/src/main_shell.zig +++ b/src/main_shell.zig @@ -3,11 +3,11 @@ const std = @import("std"); const jsruntime = @import("jsruntime"); const parser = @import("netsurf.zig"); -const DOM = @import("dom.zig"); +const apiweb = @import("apiweb.zig"); const html_test = @import("html_test.zig").html; -pub const Types = jsruntime.reflect(DOM.Interfaces); +pub const Types = jsruntime.reflect(apiweb.Interfaces); var doc: *parser.DocumentHTML = undefined; diff --git a/src/main_wpt.zig b/src/main_wpt.zig index e91f42c6..e252ad52 100644 --- a/src/main_wpt.zig +++ b/src/main_wpt.zig @@ -6,7 +6,8 @@ const Suite = @import("wpt/testcase.zig").Suite; const FileLoader = @import("wpt/fileloader.zig").FileLoader; const wpt = @import("wpt/run.zig"); -const DOM = @import("dom.zig"); +const apiweb = @import("apiweb.zig"); +const nav = @import("nav/nav.zig"); const HTMLElem = @import("html/elements.zig"); const wpt_dir = "tests/wpt"; @@ -29,7 +30,7 @@ const Out = enum { text, }; -pub const Types = jsruntime.reflect(DOM.Interfaces); +pub const Types = jsruntime.reflect(apiweb.Interfaces); // TODO For now the WPT tests run is specific to WPT. // It manually load js framwork libs, and run the first script w/ js content in diff --git a/src/nav/nav.zig b/src/nav/nav.zig new file mode 100644 index 00000000..42590cd5 --- /dev/null +++ b/src/nav/nav.zig @@ -0,0 +1,7 @@ +const generate = @import("../generate.zig"); + +const Window = @import("window.zig"); + +pub const Interfaces = generate.Tuple(.{ + Window, +}); diff --git a/src/nav/window.zig b/src/nav/window.zig new file mode 100644 index 00000000..49ca899d --- /dev/null +++ b/src/nav/window.zig @@ -0,0 +1,41 @@ +const std = @import("std"); + +const parser = @import("../netsurf.zig"); + +// https://dom.spec.whatwg.org/#interface-window-extensions +// https://html.spec.whatwg.org/multipage/nav-history-apis.html#window +pub const Window = struct { + pub const mem_guarantied = true; + + document: *parser.Document, + target: []const u8, + + pub fn create(doc: *parser.Document, target: ?[]const u8) Window { + return Window{ + .document = doc, + .target = target orelse "", + }; + } + + pub fn get_window(self: *Window) *parser.Document { + return self; + } + + pub fn get_self(self: *Window) *parser.Document { + return self; + } + + pub fn get_parent(self: *Window) *parser.Document { + return self; + } + + pub fn get_document(self: *Window) *parser.Document { + return self.document; + } + + pub fn get_name(self: *Window) []const u8 { + return self.target; + } + + // TODO we need to re-implement EventTarget interface. +}; diff --git a/src/run_tests.zig b/src/run_tests.zig index 1ba0f8b3..08eaea3b 100644 --- a/src/run_tests.zig +++ b/src/run_tests.zig @@ -5,7 +5,7 @@ const jsruntime = @import("jsruntime"); const generate = @import("generate.zig"); const parser = @import("netsurf.zig"); -const DOM = @import("dom.zig"); +const apiweb = @import("apiweb.zig"); const documentTestExecFn = @import("dom/document.zig").testExecFn; const HTMLDocumentTestExecFn = @import("html/document.zig").testExecFn; @@ -21,7 +21,7 @@ const DOMTokenListExecFn = @import("dom/token_list.zig").testExecFn; const NodeListTestExecFn = @import("dom/nodelist.zig").testExecFn; const AttrTestExecFn = @import("dom/attribute.zig").testExecFn; -pub const Types = jsruntime.reflect(DOM.Interfaces); +pub const Types = jsruntime.reflect(apiweb.Interfaces); var doc: *parser.DocumentHTML = undefined;