mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
Add DOMError check in DOMImplementation
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -22,8 +22,8 @@ pub const Document = struct {
|
|||||||
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() !*parser.Document {
|
||||||
return parser.domImplementationCreateHTMLDocument(null);
|
return try parser.domImplementationCreateHTMLDocument(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// JS funcs
|
// JS funcs
|
||||||
|
|||||||
@@ -54,7 +54,11 @@ pub const DOMException = struct {
|
|||||||
.{ errName, callerName },
|
.{ errName, callerName },
|
||||||
),
|
),
|
||||||
error.NoError => unreachable,
|
error.NoError => unreachable,
|
||||||
else => "", // TODO: implement other messages
|
else => try allocPrint(
|
||||||
|
alloc,
|
||||||
|
"{s}: TODO message", // TODO: implement other messages
|
||||||
|
.{DOMException.name(errCast)},
|
||||||
|
),
|
||||||
};
|
};
|
||||||
return .{ .err = errCast, .str = str };
|
return .{ .err = errCast, .str = str };
|
||||||
}
|
}
|
||||||
@@ -154,6 +158,8 @@ pub fn testExecFn(
|
|||||||
.{ .src = "HierarchyRequestError.code", .ex = "3" },
|
.{ .src = "HierarchyRequestError.code", .ex = "3" },
|
||||||
.{ .src = "HierarchyRequestError.message", .ex = err },
|
.{ .src = "HierarchyRequestError.message", .ex = err },
|
||||||
.{ .src = "HierarchyRequestError.toString()", .ex = "HierarchyRequestError: " ++ err },
|
.{ .src = "HierarchyRequestError.toString()", .ex = "HierarchyRequestError: " ++ err },
|
||||||
|
.{ .src = "HierarchyRequestError instanceof DOMException", .ex = "true" },
|
||||||
|
.{ .src = "HierarchyRequestError instanceof Error", .ex = "true" },
|
||||||
};
|
};
|
||||||
try checkCases(js_env, &cases);
|
try checkCases(js_env, &cases);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,14 @@ const checkCases = jsruntime.test_utils.checkCases;
|
|||||||
|
|
||||||
const Document = @import("document.zig").Document;
|
const Document = @import("document.zig").Document;
|
||||||
const DocumentType = @import("document_type.zig").DocumentType;
|
const DocumentType = @import("document_type.zig").DocumentType;
|
||||||
|
const DOMException = @import("exceptions.zig").DOMException;
|
||||||
|
|
||||||
// WEB IDL https://dom.spec.whatwg.org/#domimplementation
|
// WEB IDL https://dom.spec.whatwg.org/#domimplementation
|
||||||
pub const DOMImplementation = struct {
|
pub const DOMImplementation = struct {
|
||||||
pub const mem_guarantied = true;
|
pub const mem_guarantied = true;
|
||||||
|
|
||||||
|
pub const Exception = DOMException;
|
||||||
|
|
||||||
pub fn _createDocumentType(
|
pub fn _createDocumentType(
|
||||||
_: *DOMImplementation,
|
_: *DOMImplementation,
|
||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
@@ -29,7 +32,7 @@ pub const DOMImplementation = struct {
|
|||||||
const csystemId = try alloc.dupeZ(u8, systemId);
|
const csystemId = try alloc.dupeZ(u8, systemId);
|
||||||
defer alloc.free(csystemId);
|
defer alloc.free(csystemId);
|
||||||
|
|
||||||
return parser.domImplementationCreateDocumentType(cqname, cpublicId, csystemId);
|
return try parser.domImplementationCreateDocumentType(cqname, cpublicId, csystemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _createDocument(
|
pub fn _createDocument(
|
||||||
@@ -51,11 +54,11 @@ pub const DOMImplementation = struct {
|
|||||||
defer alloc.free(cqname.?);
|
defer alloc.free(cqname.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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.Document {
|
||||||
return parser.domImplementationCreateHTMLDocument(title);
|
return try parser.domImplementationCreateHTMLDocument(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _hasFeature(_: *DOMImplementation) bool {
|
pub fn _hasFeature(_: *DOMImplementation) bool {
|
||||||
|
|||||||
@@ -889,7 +889,11 @@ pub inline fn documentTypeGetSystemId(dt: *DocumentType) ![]const u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DOMImplementation
|
// DOMImplementation
|
||||||
pub inline fn domImplementationCreateDocument(namespace: ?[:0]const u8, qname: ?[:0]const u8, doctype: ?*DocumentType) *Document {
|
pub inline fn domImplementationCreateDocument(
|
||||||
|
namespace: ?[:0]const u8,
|
||||||
|
qname: ?[:0]const u8,
|
||||||
|
doctype: ?*DocumentType,
|
||||||
|
) !*Document {
|
||||||
var doc: ?*Document = undefined;
|
var doc: ?*Document = undefined;
|
||||||
|
|
||||||
var ptrnamespace: [*c]const u8 = null;
|
var ptrnamespace: [*c]const u8 = null;
|
||||||
@@ -902,7 +906,7 @@ pub inline fn domImplementationCreateDocument(namespace: ?[:0]const u8, qname: ?
|
|||||||
ptrqname = qn.ptr;
|
ptrqname = qn.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = c.dom_implementation_create_document(
|
const err = c.dom_implementation_create_document(
|
||||||
c.DOM_IMPLEMENTATION_XML,
|
c.DOM_IMPLEMENTATION_XML,
|
||||||
ptrnamespace,
|
ptrnamespace,
|
||||||
ptrqname,
|
ptrqname,
|
||||||
@@ -911,18 +915,24 @@ pub inline fn domImplementationCreateDocument(namespace: ?[:0]const u8, qname: ?
|
|||||||
null,
|
null,
|
||||||
&doc,
|
&doc,
|
||||||
);
|
);
|
||||||
|
try DOMErr(err);
|
||||||
return doc.?;
|
return doc.?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn domImplementationCreateDocumentType(qname: [:0]const u8, publicId: [:0]const u8, systemId: [:0]const u8) *DocumentType {
|
pub inline fn domImplementationCreateDocumentType(
|
||||||
|
qname: [:0]const u8,
|
||||||
|
publicId: [:0]const u8,
|
||||||
|
systemId: [:0]const u8,
|
||||||
|
) !*DocumentType {
|
||||||
var dt: ?*DocumentType = undefined;
|
var dt: ?*DocumentType = undefined;
|
||||||
_ = c.dom_implementation_create_document_type(qname.ptr, publicId.ptr, systemId.ptr, &dt);
|
const err = c.dom_implementation_create_document_type(qname.ptr, publicId.ptr, systemId.ptr, &dt);
|
||||||
|
try DOMErr(err);
|
||||||
return dt.?;
|
return dt.?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) *Document {
|
pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) !*Document {
|
||||||
var doc: ?*Document = undefined;
|
var doc: ?*Document = undefined;
|
||||||
_ = c.dom_implementation_create_document(
|
const err = c.dom_implementation_create_document(
|
||||||
c.DOM_IMPLEMENTATION_HTML,
|
c.DOM_IMPLEMENTATION_HTML,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@@ -931,6 +941,7 @@ pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) *Document
|
|||||||
null,
|
null,
|
||||||
&doc,
|
&doc,
|
||||||
);
|
);
|
||||||
|
try DOMErr(err);
|
||||||
// TODO set title
|
// TODO set title
|
||||||
_ = title;
|
_ = title;
|
||||||
return doc.?;
|
return doc.?;
|
||||||
|
|||||||
2
vendor/jsruntime-lib
vendored
2
vendor/jsruntime-lib
vendored
Submodule vendor/jsruntime-lib updated: bca65e0985...d63b0a592f
Reference in New Issue
Block a user