mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-16 00:08:59 +00:00
dom: fix document constructor
This commit is contained in:
@@ -40,14 +40,30 @@ const DocumentType = @import("document_type.zig").DocumentType;
|
|||||||
const DocumentFragment = @import("document_fragment.zig").DocumentFragment;
|
const DocumentFragment = @import("document_fragment.zig").DocumentFragment;
|
||||||
const DOMImplementation = @import("implementation.zig").DOMImplementation;
|
const DOMImplementation = @import("implementation.zig").DOMImplementation;
|
||||||
|
|
||||||
|
const UserContext = @import("../user_context.zig").UserContext;
|
||||||
|
|
||||||
// WEB IDL https://dom.spec.whatwg.org/#document
|
// WEB IDL https://dom.spec.whatwg.org/#document
|
||||||
pub const Document = struct {
|
pub const Document = struct {
|
||||||
pub const Self = parser.Document;
|
pub const Self = parser.Document;
|
||||||
pub const prototype = *Node;
|
pub const prototype = *Node;
|
||||||
pub const mem_guarantied = true;
|
pub const mem_guarantied = true;
|
||||||
|
|
||||||
pub fn constructor() !*parser.Document {
|
pub fn constructor(userctx: UserContext) !*parser.DocumentHTML {
|
||||||
return try parser.domImplementationCreateHTMLDocument(null);
|
var title: ?[]const u8 = null;
|
||||||
|
if (userctx.document) |cur| {
|
||||||
|
title = try parser.documentHTMLGetTitle(cur);
|
||||||
|
}
|
||||||
|
const doc = try parser.domImplementationCreateHTMLDocument(title);
|
||||||
|
|
||||||
|
if (userctx.document) |cur| {
|
||||||
|
// we have to work w/ document instead of html document.
|
||||||
|
const ddoc = parser.documentHTMLToDocument(doc);
|
||||||
|
const ccur = parser.documentHTMLToDocument(cur);
|
||||||
|
try parser.documentSetDocumentURI(ddoc, try parser.documentGetDocumentURI(ccur));
|
||||||
|
try parser.documentSetInputEncoding(ddoc, try parser.documentGetInputEncoding(ccur));
|
||||||
|
}
|
||||||
|
|
||||||
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// JS funcs
|
// JS funcs
|
||||||
@@ -262,6 +278,13 @@ pub fn testExecFn(
|
|||||||
.{ .src = "newdoc.children.length", .ex = "0" },
|
.{ .src = "newdoc.children.length", .ex = "0" },
|
||||||
.{ .src = "newdoc.getElementsByTagName('*').length", .ex = "0" },
|
.{ .src = "newdoc.getElementsByTagName('*').length", .ex = "0" },
|
||||||
.{ .src = "newdoc.getElementsByTagName('*').item(0)", .ex = "null" },
|
.{ .src = "newdoc.getElementsByTagName('*').item(0)", .ex = "null" },
|
||||||
|
.{ .src = "newdoc.inputEncoding === document.inputEncoding", .ex = "true" },
|
||||||
|
.{ .src = "newdoc.documentURI === document.documentURI", .ex = "true" },
|
||||||
|
.{ .src = "newdoc.URL === document.URL", .ex = "true" },
|
||||||
|
.{ .src = "newdoc.compatMode === document.compatMode", .ex = "true" },
|
||||||
|
.{ .src = "newdoc.characterSet === document.characterSet", .ex = "true" },
|
||||||
|
.{ .src = "newdoc.charset === document.charset", .ex = "true" },
|
||||||
|
.{ .src = "newdoc.contentType === document.contentType", .ex = "true" },
|
||||||
};
|
};
|
||||||
try checkCases(js_env, &constructor);
|
try checkCases(js_env, &constructor);
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ pub const DOMImplementation = struct {
|
|||||||
return try parser.domImplementationCreateDocument(cnamespace, cqname, doctype);
|
return try parser.domImplementationCreateDocument(cnamespace, cqname, doctype);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _createHTMLDocument(_: *DOMImplementation, title: ?[]const u8) !*parser.Document {
|
pub fn _createHTMLDocument(_: *DOMImplementation, title: ?[]const u8) !*parser.DocumentHTML {
|
||||||
return try parser.domImplementationCreateHTMLDocument(title);
|
return try parser.domImplementationCreateHTMLDocument(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ pub fn testExecFn(
|
|||||||
) anyerror!void {
|
) anyerror!void {
|
||||||
var getImplementation = [_]Case{
|
var getImplementation = [_]Case{
|
||||||
.{ .src = "let impl = document.implementation", .ex = "undefined" },
|
.{ .src = "let impl = document.implementation", .ex = "undefined" },
|
||||||
.{ .src = "impl.createHTMLDocument();", .ex = "[object Document]" },
|
.{ .src = "impl.createHTMLDocument();", .ex = "[object HTMLDocument]" },
|
||||||
.{ .src = "impl.createDocument(null, 'foo');", .ex = "[object Document]" },
|
.{ .src = "impl.createDocument(null, 'foo');", .ex = "[object Document]" },
|
||||||
.{ .src = "impl.createDocumentType('foo', 'bar', 'baz')", .ex = "[object DocumentType]" },
|
.{ .src = "impl.createDocumentType('foo', 'bar', 'baz')", .ex = "[object DocumentType]" },
|
||||||
.{ .src = "impl.hasFeature()", .ex = "true" },
|
.{ .src = "impl.hasFeature()", .ex = "true" },
|
||||||
|
|||||||
@@ -1763,7 +1763,7 @@ pub inline fn domImplementationCreateDocumentType(
|
|||||||
return dt.?;
|
return dt.?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) !*Document {
|
pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) !*DocumentHTML {
|
||||||
var doc: ?*Document = undefined;
|
var doc: ?*Document = undefined;
|
||||||
const err = c.dom_implementation_create_document(
|
const err = c.dom_implementation_create_document(
|
||||||
c.DOM_IMPLEMENTATION_HTML,
|
c.DOM_IMPLEMENTATION_HTML,
|
||||||
@@ -1775,9 +1775,12 @@ pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) !*Document
|
|||||||
&doc,
|
&doc,
|
||||||
);
|
);
|
||||||
try DOMErr(err);
|
try DOMErr(err);
|
||||||
// TODO set title
|
|
||||||
_ = title;
|
const doc_html = @as(*DocumentHTML, @ptrCast(doc.?));
|
||||||
return doc.?;
|
|
||||||
|
if (title) |t| try documentHTMLSetTitle(doc_html, t);
|
||||||
|
|
||||||
|
return doc_html;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Document
|
// Document
|
||||||
@@ -1833,6 +1836,11 @@ pub inline fn documentGetInputEncoding(doc: *Document) ![]const u8 {
|
|||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub inline fn documentSetInputEncoding(doc: *Document, enc: []const u8) !void {
|
||||||
|
const err = documentVtable(doc).dom_document_set_input_encoding.?(doc, try strFromData(enc));
|
||||||
|
try DOMErr(err);
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
const err = documentVtable(doc).dom_document_create_element.?(doc, try strFromData(tag_name), &elem);
|
const err = documentVtable(doc).dom_document_create_element.?(doc, try strFromData(tag_name), &elem);
|
||||||
|
|||||||
Reference in New Issue
Block a user