mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
dom: implement currentScript
This commit is contained in:
@@ -411,7 +411,9 @@ pub const Page = struct {
|
|||||||
// > immediately before the browser continues to parse the
|
// > immediately before the browser continues to parse the
|
||||||
// > page.
|
// > page.
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#notes
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#notes
|
||||||
|
try parser.documentHTMLSetCurrentScript(html_doc, @ptrCast(e));
|
||||||
self.evalScript(e) catch |err| log.warn("evaljs: {any}", .{err});
|
self.evalScript(e) catch |err| log.warn("evaljs: {any}", .{err});
|
||||||
|
try parser.documentHTMLSetCurrentScript(html_doc, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO wait for deferred scripts
|
// TODO wait for deferred scripts
|
||||||
@@ -428,7 +430,9 @@ pub const Page = struct {
|
|||||||
|
|
||||||
// eval async scripts.
|
// eval async scripts.
|
||||||
for (sasync.items) |e| {
|
for (sasync.items) |e| {
|
||||||
|
try parser.documentHTMLSetCurrentScript(html_doc, @ptrCast(e));
|
||||||
self.evalScript(e) catch |err| log.warn("evaljs: {any}", .{err});
|
self.evalScript(e) catch |err| log.warn("evaljs: {any}", .{err});
|
||||||
|
try parser.documentHTMLSetCurrentScript(html_doc, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO wait for async scripts
|
// TODO wait for async scripts
|
||||||
|
|||||||
@@ -153,8 +153,8 @@ pub const HTMLDocument = struct {
|
|||||||
return try collection.HTMLCollectionAll(parser.documentHTMLToNode(self), true);
|
return try collection.HTMLCollectionAll(parser.documentHTMLToNode(self), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_currentScript(_: *parser.DocumentHTML) !?*parser.Element {
|
pub fn get_currentScript(self: *parser.DocumentHTML) !?*parser.Script {
|
||||||
return null;
|
return try parser.documentHTMLGetCurrentScript(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_designMode(_: *parser.DocumentHTML) []const u8 {
|
pub fn get_designMode(_: *parser.DocumentHTML) []const u8 {
|
||||||
|
|||||||
@@ -2249,3 +2249,18 @@ pub inline fn documentHTMLSetTitle(doc: *DocumentHTML, v: []const u8) !void {
|
|||||||
const err = documentHTMLVtable(doc).set_title.?(doc, try strFromData(v));
|
const err = documentHTMLVtable(doc).set_title.?(doc, try strFromData(v));
|
||||||
try DOMErr(err);
|
try DOMErr(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn documentHTMLSetCurrentScript(doc: *DocumentHTML, script: ?*Script) !void {
|
||||||
|
var s: ?*ElementHTML = null;
|
||||||
|
if (script != null) s = @ptrCast(script.?);
|
||||||
|
const err = documentHTMLVtable(doc).set_current_script.?(doc, s);
|
||||||
|
try DOMErr(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn documentHTMLGetCurrentScript(doc: *DocumentHTML) !?*Script {
|
||||||
|
var elem: ?*ElementHTML = undefined;
|
||||||
|
const err = documentHTMLVtable(doc).get_current_script.?(doc, &elem);
|
||||||
|
try DOMErr(err);
|
||||||
|
if (elem == null) return null;
|
||||||
|
return @ptrCast(elem.?);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user