mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
dom: use allocator with HTMLCollection getters
This commit is contained in:
committed by
Pierre Tachoire
parent
9bb200a46f
commit
f02769b2dd
@@ -63,18 +63,13 @@ pub const HTMLCollection = struct {
|
|||||||
/// _get_length computes the collection's length dynamically according to
|
/// _get_length computes the collection's length dynamically according to
|
||||||
/// the current root structure.
|
/// the current root structure.
|
||||||
// TODO: nodes retrieved must be de-referenced.
|
// TODO: nodes retrieved must be de-referenced.
|
||||||
pub fn get_length(self: *HTMLCollection) u32 {
|
pub fn get_length(self: *HTMLCollection, allocator: std.mem.Allocator) !u32 {
|
||||||
var len: u32 = 0;
|
var len: u32 = 0;
|
||||||
var node: *parser.Node = self.root;
|
var node: *parser.Node = self.root;
|
||||||
var ntype: parser.NodeType = undefined;
|
var ntype: parser.NodeType = undefined;
|
||||||
|
|
||||||
// FIXME using a fixed length buffer here avoid the need of an allocator
|
const imatch = try std.ascii.allocUpperString(allocator, self.match);
|
||||||
// to get an upper case match value. But if the match value (a tag
|
defer allocator.free(imatch);
|
||||||
// name) is greater than 128 chars, the code will panic.
|
|
||||||
// ascii.upperString asserts the buffer size is greater or equals than
|
|
||||||
// the given string.
|
|
||||||
var buffer: [128]u8 = undefined;
|
|
||||||
const imatch = std.ascii.upperString(&buffer, self.match);
|
|
||||||
|
|
||||||
var is_wildcard = std.mem.eql(u8, self.match, "*");
|
var is_wildcard = std.mem.eql(u8, self.match, "*");
|
||||||
|
|
||||||
@@ -92,7 +87,7 @@ pub const HTMLCollection = struct {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _item(self: *HTMLCollection, index: u32) ?*parser.Element {
|
pub fn _item(self: *HTMLCollection, allocator: std.mem.Allocator, index: u32) !?*parser.Element {
|
||||||
var i: u32 = 0;
|
var i: u32 = 0;
|
||||||
var node: *parser.Node = self.root;
|
var node: *parser.Node = self.root;
|
||||||
var ntype: parser.NodeType = undefined;
|
var ntype: parser.NodeType = undefined;
|
||||||
@@ -105,13 +100,8 @@ pub const HTMLCollection = struct {
|
|||||||
node = self.cur_node;
|
node = self.cur_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME using a fixed length buffer here avoid the need of an allocator
|
const imatch = try std.ascii.allocUpperString(allocator, self.match);
|
||||||
// to get an upper case match value. But if the match value (a tag
|
defer allocator.free(imatch);
|
||||||
// name) is greater than 128 chars, the code will panic.
|
|
||||||
// ascii.upperString asserts the buffer size is greater or equals than
|
|
||||||
// the given string.
|
|
||||||
var buffer: [128]u8 = undefined;
|
|
||||||
const imatch = std.ascii.upperString(&buffer, self.match);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
ntype = parser.nodeType(node);
|
ntype = parser.nodeType(node);
|
||||||
@@ -136,7 +126,7 @@ pub const HTMLCollection = struct {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _namedItem(self: *HTMLCollection, name: []const u8) ?*parser.Element {
|
pub fn _namedItem(self: *HTMLCollection, allocator: std.mem.Allocator, name: []const u8) !?*parser.Element {
|
||||||
if (name.len == 0) {
|
if (name.len == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -146,13 +136,8 @@ pub const HTMLCollection = struct {
|
|||||||
|
|
||||||
var is_wildcard = std.mem.eql(u8, self.match, "*");
|
var is_wildcard = std.mem.eql(u8, self.match, "*");
|
||||||
|
|
||||||
// FIXME using a fixed length buffer here avoid the need of an allocator
|
const imatch = try std.ascii.allocUpperString(allocator, self.match);
|
||||||
// to get an upper case match value. But if the match value (a tag
|
defer allocator.free(imatch);
|
||||||
// name) is greater than 128 chars, the code will panic.
|
|
||||||
// ascii.upperString asserts the buffer size is greater or equals than
|
|
||||||
// the given string.
|
|
||||||
var buffer: [128]u8 = undefined;
|
|
||||||
const imatch = std.ascii.upperString(&buffer, self.match);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
ntype = parser.nodeType(node);
|
ntype = parser.nodeType(node);
|
||||||
@@ -192,6 +177,8 @@ pub fn testExecFn(
|
|||||||
var getElementsByTagName = [_]Case{
|
var getElementsByTagName = [_]Case{
|
||||||
.{ .src = "let getElementsByTagName = document.getElementsByTagName('p')", .ex = "undefined" },
|
.{ .src = "let getElementsByTagName = document.getElementsByTagName('p')", .ex = "undefined" },
|
||||||
.{ .src = "getElementsByTagName.length", .ex = "2" },
|
.{ .src = "getElementsByTagName.length", .ex = "2" },
|
||||||
|
.{ .src = "let getElementsByTagNameCI = document.getElementsByTagName('P')", .ex = "undefined" },
|
||||||
|
.{ .src = "getElementsByTagNameCI.length", .ex = "2" },
|
||||||
.{ .src = "getElementsByTagName.item(0).localName", .ex = "p" },
|
.{ .src = "getElementsByTagName.item(0).localName", .ex = "p" },
|
||||||
.{ .src = "getElementsByTagName.item(1).localName", .ex = "p" },
|
.{ .src = "getElementsByTagName.item(1).localName", .ex = "p" },
|
||||||
.{ .src = "let getElementsByTagNameAll = document.getElementsByTagName('*')", .ex = "undefined" },
|
.{ .src = "let getElementsByTagNameAll = document.getElementsByTagName('*')", .ex = "undefined" },
|
||||||
|
|||||||
Reference in New Issue
Block a user