mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
PerformanceObserver changes
This commit is contained in:
@@ -49,7 +49,6 @@ const Document = @import("webapi/Document.zig");
|
|||||||
const ShadowRoot = @import("webapi/ShadowRoot.zig");
|
const ShadowRoot = @import("webapi/ShadowRoot.zig");
|
||||||
const Performance = @import("webapi/Performance.zig");
|
const Performance = @import("webapi/Performance.zig");
|
||||||
const Screen = @import("webapi/Screen.zig");
|
const Screen = @import("webapi/Screen.zig");
|
||||||
const HtmlScript = @import("webapi/Element.zig").Html.Script;
|
|
||||||
const PerformanceObserver = @import("webapi/PerformanceObserver.zig");
|
const PerformanceObserver = @import("webapi/PerformanceObserver.zig");
|
||||||
const MutationObserver = @import("webapi/MutationObserver.zig");
|
const MutationObserver = @import("webapi/MutationObserver.zig");
|
||||||
const IntersectionObserver = @import("webapi/IntersectionObserver.zig");
|
const IntersectionObserver = @import("webapi/IntersectionObserver.zig");
|
||||||
@@ -1067,14 +1066,19 @@ pub fn notifyPerformanceObservers(self: *Page, entry: *Performance.Entry) !void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self._performance_delivery_scheduled == false) {
|
// Already scheduled.
|
||||||
|
if (self._performance_delivery_scheduled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
self._performance_delivery_scheduled = true;
|
self._performance_delivery_scheduled = true;
|
||||||
try self.scheduler.add(
|
|
||||||
|
return self.scheduler.add(
|
||||||
self,
|
self,
|
||||||
struct {
|
struct {
|
||||||
fn run(_page: *anyopaque) anyerror!?u32 {
|
fn run(_page: *anyopaque) anyerror!?u32 {
|
||||||
const page: *Page = @ptrCast(@alignCast(_page));
|
const page: *Page = @ptrCast(@alignCast(_page));
|
||||||
page._performance_delivery_scheduled = true;
|
page._performance_delivery_scheduled = false;
|
||||||
|
|
||||||
// Dispatch performance observer events.
|
// Dispatch performance observer events.
|
||||||
for (page._performance_observers.items) |observer| {
|
for (page._performance_observers.items) |observer| {
|
||||||
if (observer.hasRecords()) {
|
if (observer.hasRecords()) {
|
||||||
@@ -1088,7 +1092,6 @@ pub fn notifyPerformanceObservers(self: *Page, entry: *Performance.Entry) !void
|
|||||||
0,
|
0,
|
||||||
.{ .low_priority = true },
|
.{ .low_priority = true },
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn registerMutationObserver(self: *Page, observer: *MutationObserver) !void {
|
pub fn registerMutationObserver(self: *Page, observer: *MutationObserver) !void {
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ const js = @import("../js/js.zig");
|
|||||||
const Page = @import("../Page.zig");
|
const Page = @import("../Page.zig");
|
||||||
const Performance = @import("Performance.zig");
|
const Performance = @import("Performance.zig");
|
||||||
|
|
||||||
|
pub fn registerTypes() []const type {
|
||||||
|
return &.{ PerformanceObserver, EntryList };
|
||||||
|
}
|
||||||
|
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver
|
/// https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver
|
||||||
const PerformanceObserver = @This();
|
const PerformanceObserver = @This();
|
||||||
|
|
||||||
@@ -109,8 +113,12 @@ pub fn observe(
|
|||||||
self._interests = interests;
|
self._interests = interests;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disconnect(self: *PerformanceObserver) void {
|
pub fn disconnect(self: *PerformanceObserver, page: *Page) void {
|
||||||
_ = self;
|
page.unregisterPerformanceObserver(self);
|
||||||
|
// Reset observer.
|
||||||
|
self._duration_threshold = DefaultDurationThreshold;
|
||||||
|
self._interests = 0;
|
||||||
|
self._entries.clearRetainingCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current list of PerformanceEntry objects
|
/// Returns the current list of PerformanceEntry objects
|
||||||
@@ -141,7 +149,7 @@ pub inline fn hasRecords(self: *const PerformanceObserver) bool {
|
|||||||
/// Runs the PerformanceObserver's callback with records; emptying it out.
|
/// Runs the PerformanceObserver's callback with records; emptying it out.
|
||||||
pub fn dispatch(self: *PerformanceObserver, page: *Page) !void {
|
pub fn dispatch(self: *PerformanceObserver, page: *Page) !void {
|
||||||
const records = try self.takeRecords(page);
|
const records = try self.takeRecords(page);
|
||||||
_ = try self._callback.call(void, .{records});
|
_ = try self._callback.call(void, .{ EntryList{ ._entries = records }, self });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const JsApi = struct {
|
pub const JsApi = struct {
|
||||||
@@ -175,11 +183,16 @@ pub const EntryList = struct {
|
|||||||
pub const bridge = js.Bridge(EntryList);
|
pub const bridge = js.Bridge(EntryList);
|
||||||
|
|
||||||
pub const Meta = struct {
|
pub const Meta = struct {
|
||||||
pub const name = "PerformanceEntryList";
|
pub const name = "PerformanceObserverEntryList";
|
||||||
pub const prototype_chain = bridge.prototypeChain();
|
pub const prototype_chain = bridge.prototypeChain();
|
||||||
pub var class_id: bridge.ClassId = undefined;
|
pub var class_id: bridge.ClassId = undefined;
|
||||||
|
};
|
||||||
|
|
||||||
pub const getEntries = bridge.function(EntryList.getEntries, .{});
|
pub const getEntries = bridge.function(EntryList.getEntries, .{});
|
||||||
};
|
};
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const testing = @import("../../testing.zig");
|
||||||
|
test "WebApi: PerformanceObserver" {
|
||||||
|
try testing.htmlRunner("performance_observer", .{});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user