mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
dom: implement text constructor
This commit is contained in:
@@ -28,6 +28,8 @@ const parser = @import("../netsurf.zig");
|
|||||||
const CharacterData = @import("character_data.zig").CharacterData;
|
const CharacterData = @import("character_data.zig").CharacterData;
|
||||||
const CDATASection = @import("cdata_section.zig").CDATASection;
|
const CDATASection = @import("cdata_section.zig").CDATASection;
|
||||||
|
|
||||||
|
const UserContext = @import("../user_context.zig").UserContext;
|
||||||
|
|
||||||
// Text interfaces
|
// Text interfaces
|
||||||
pub const Interfaces = generate.Tuple(.{
|
pub const Interfaces = generate.Tuple(.{
|
||||||
CDATASection,
|
CDATASection,
|
||||||
@@ -44,8 +46,13 @@ pub const Text = struct {
|
|||||||
// > and this’s node document to current global object’s associated
|
// > and this’s node document to current global object’s associated
|
||||||
// > Document.
|
// > Document.
|
||||||
// https://dom.spec.whatwg.org/#dom-text-text
|
// https://dom.spec.whatwg.org/#dom-text-text
|
||||||
pub fn constructor() !*parser.Comment {
|
pub fn constructor(userctx: UserContext, data: ?[]const u8) !*parser.Text {
|
||||||
return error.NotImplemented;
|
if (userctx.document == null) return parser.DOMError.NotSupported;
|
||||||
|
|
||||||
|
return parser.documentCreateTextNode(
|
||||||
|
parser.documentHTMLToDocument(userctx.document.?),
|
||||||
|
data orelse "",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// JS funcs
|
// JS funcs
|
||||||
@@ -72,6 +79,15 @@ pub fn testExecFn(
|
|||||||
_: std.mem.Allocator,
|
_: std.mem.Allocator,
|
||||||
js_env: *jsruntime.Env,
|
js_env: *jsruntime.Env,
|
||||||
) anyerror!void {
|
) anyerror!void {
|
||||||
|
var constructor = [_]Case{
|
||||||
|
.{ .src = "let t = new Text('foo')", .ex = "undefined" },
|
||||||
|
.{ .src = "t.data", .ex = "foo" },
|
||||||
|
|
||||||
|
.{ .src = "let emptyt = new Text()", .ex = "undefined" },
|
||||||
|
.{ .src = "emptyt.data", .ex = "" },
|
||||||
|
};
|
||||||
|
try checkCases(js_env, &constructor);
|
||||||
|
|
||||||
var get_whole_text = [_]Case{
|
var get_whole_text = [_]Case{
|
||||||
.{ .src = "let text = document.getElementById('link').firstChild", .ex = "undefined" },
|
.{ .src = "let text = document.getElementById('link').firstChild", .ex = "undefined" },
|
||||||
.{ .src = "text.wholeText === 'OK'", .ex = "true" },
|
.{ .src = "text.wholeText === 'OK'", .ex = "true" },
|
||||||
|
|||||||
Reference in New Issue
Block a user