dom: document.documentURI and document.URL

This commit is contained in:
Pierre Tachoire
2023-11-21 09:52:35 +01:00
parent 0fadb4ff98
commit bf297ac97d
2 changed files with 22 additions and 0 deletions

View File

@@ -34,6 +34,15 @@ pub const Document = struct {
return Element.toInterface(e); 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 // TODO implement contentType
pub fn get_contentType(self: *parser.Document) []const u8 { pub fn get_contentType(self: *parser.Document) []const u8 {
_ = self; _ = self;
@@ -168,6 +177,13 @@ pub fn testExecFn(
}; };
try checkCases(js_env, &getContentType); 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(); const tags = comptime parser.Tag.all();
comptime var createElements: [(tags.len) * 2]Case = undefined; comptime var createElements: [(tags.len) * 2]Case = undefined;
inline for (tags, 0..) |tag, i| { inline for (tags, 0..) |tag, i| {

View File

@@ -794,6 +794,12 @@ pub inline fn documentGetDocumentElement(doc: *Document) *Element {
return elem.?; 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 { pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) *Element {
var elem: ?*Element = undefined; var elem: ?*Element = undefined;
_ = documentVtable(doc).dom_document_create_element.?(doc, stringFromData(tag_name), &elem); _ = documentVtable(doc).dom_document_create_element.?(doc, stringFromData(tag_name), &elem);