mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 15:41:48 +00:00
dom: fix document creation process
This commit is contained in:
@@ -53,7 +53,7 @@ pub const Document = struct {
|
||||
if (userctx.document) |cur| {
|
||||
title = try parser.documentHTMLGetTitle(cur);
|
||||
}
|
||||
const doc = try parser.domImplementationCreateHTMLDocument(title);
|
||||
const doc = try parser.documentCreateDocument(title);
|
||||
|
||||
if (userctx.document) |cur| {
|
||||
// we have to work w/ document instead of html document.
|
||||
|
||||
@@ -96,6 +96,7 @@ pub fn testExecFn(
|
||||
var getImplementation = [_]Case{
|
||||
.{ .src = "let impl = document.implementation", .ex = "undefined" },
|
||||
.{ .src = "impl.createHTMLDocument();", .ex = "[object HTMLDocument]" },
|
||||
.{ .src = "impl.createHTMLDocument('foo');", .ex = "[object HTMLDocument]" },
|
||||
.{ .src = "impl.createDocument(null, 'foo');", .ex = "[object Document]" },
|
||||
.{ .src = "impl.createDocumentType('foo', 'bar', 'baz')", .ex = "[object DocumentType]" },
|
||||
.{ .src = "impl.hasFeature()", .ex = "true" },
|
||||
|
||||
@@ -277,26 +277,6 @@ pub const Node = struct {
|
||||
return try Node.toInterface(res);
|
||||
}
|
||||
|
||||
// TODO according with https://dom.spec.whatwg.org/#parentnode, the
|
||||
// function must accept either node or string.
|
||||
// blocked by https://github.com/lightpanda-io/jsruntime-lib/issues/114
|
||||
pub fn prepend(self: *parser.Node, nodes: ?Variadic(*parser.Node)) !void {
|
||||
if (nodes == null) return;
|
||||
if (nodes.?.slice.len == 0) return;
|
||||
const first = try parser.nodeFirstChild(self);
|
||||
|
||||
if (first == null) {
|
||||
for (nodes.?.slice) |node| {
|
||||
_ = try parser.nodeAppendChild(self, node);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (nodes.?.slice) |node| {
|
||||
_ = try parser.nodeInsertBefore(self, node, first.?);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the hierarchy node tree constraints are respected.
|
||||
// For now, it checks only if new nodes are not self.
|
||||
// TODO implements the others contraints.
|
||||
@@ -310,6 +290,29 @@ pub const Node = struct {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO according with https://dom.spec.whatwg.org/#parentnode, the
|
||||
// function must accept either node or string.
|
||||
// blocked by https://github.com/lightpanda-io/jsruntime-lib/issues/114
|
||||
pub fn prepend(self: *parser.Node, nodes: ?Variadic(*parser.Node)) !void {
|
||||
if (nodes == null) return;
|
||||
if (nodes.?.slice.len == 0) return;
|
||||
|
||||
// check hierarchy
|
||||
if (!try hierarchy(self, nodes)) return parser.DOMError.HierarchyRequest;
|
||||
|
||||
const first = try parser.nodeFirstChild(self);
|
||||
if (first == null) {
|
||||
for (nodes.?.slice) |node| {
|
||||
_ = try parser.nodeAppendChild(self, node);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (nodes.?.slice) |node| {
|
||||
_ = try parser.nodeInsertBefore(self, node, first.?);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO according with https://dom.spec.whatwg.org/#parentnode, the
|
||||
// function must accept either node or string.
|
||||
// blocked by https://github.com/lightpanda-io/jsruntime-lib/issues/114
|
||||
|
||||
Reference in New Issue
Block a user