Skip to content

Commit

Permalink
dom: document.documentURI and document.URL
Browse files Browse the repository at this point in the history
  • Loading branch information
krichprollsch committed Nov 21, 2023
1 parent 100aa45 commit 8c8e679
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/dom/document.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ pub const Document = struct {
return Element.toInterface(e);
}

pub fn get_documentURI(self: *parser.Document) []const u8 {
return parser.documentGetDocumentURI(self);
}

// TODO should be get_URL but in this case, document.URL is indefined.
pub fn get_url(self: *parser.Document) []const u8 {
return get_documentURI(self);
}

// TODO implement contentType
pub fn get_contentType(self: *parser.Document) []const u8 {
_ = self;
Expand Down Expand Up @@ -162,6 +171,13 @@ pub fn testExecFn(
};
try checkCases(js_env, &getContentType);

var getDocumentURI = [_]Case{
.{ .src = "document.documentURI", .ex = "about:blank" },
// TODO should be document.URL
.{ .src = "document.url", .ex = "about:blank" },
};
try checkCases(js_env, &getDocumentURI);

const tags = comptime parser.Tag.all();
comptime var createElements: [(tags.len) * 2]Case = undefined;
inline for (tags, 0..) |tag, i| {
Expand Down
6 changes: 6 additions & 0 deletions src/netsurf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,12 @@ pub inline fn documentGetDocumentElement(doc: *Document) *Element {
return elem.?;
}

pub inline fn documentGetDocumentURI(doc: *Document) []const u8 {
var s: ?*String = undefined;
_ = documentVtable(doc).dom_document_get_uri.?(doc, &s);
return stringToData(s.?);
}

pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) *Element {
var elem: ?*Element = undefined;
_ = documentVtable(doc).dom_document_create_element.?(doc, stringFromData(tag_name), &elem);
Expand Down

0 comments on commit 8c8e679

Please sign in to comment.