mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
add dummy Performance.Navigation
This commit is contained in:
@@ -346,3 +346,50 @@
|
|||||||
testing.expectEqual(0, remainingMarks.length);
|
testing.expectEqual(0, remainingMarks.length);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script id=performance_timing_exists>
|
||||||
|
{
|
||||||
|
// Navigation Timing Level 1: performance.timing must be an object, not undefined
|
||||||
|
testing.expectEqual('object', typeof performance.timing);
|
||||||
|
testing.expectEqual(false, performance.timing === null);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=performance_timing_navigationStart>
|
||||||
|
{
|
||||||
|
// The most commonly used property — must be a number (not undefined)
|
||||||
|
testing.expectEqual('number', typeof performance.timing.navigationStart);
|
||||||
|
testing.expectEqual(0, performance.timing.navigationStart);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=performance_navigation_exists>
|
||||||
|
{
|
||||||
|
// Navigation Timing Level 1: performance.navigation must be an object, not undefined
|
||||||
|
testing.expectEqual('object', typeof performance.navigation);
|
||||||
|
testing.expectEqual(false, performance.navigation === null);
|
||||||
|
testing.expectEqual('number', typeof performance.navigation.type);
|
||||||
|
testing.expectEqual('number', typeof performance.navigation.redirectCount);
|
||||||
|
testing.expectEqual(0, performance.navigation.type);
|
||||||
|
testing.expectEqual(0, performance.navigation.redirectCount);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id=performance_timing_all_properties>
|
||||||
|
{
|
||||||
|
const t = performance.timing;
|
||||||
|
const props = [
|
||||||
|
'navigationStart', 'unloadEventStart', 'unloadEventEnd',
|
||||||
|
'redirectStart', 'redirectEnd', 'fetchStart',
|
||||||
|
'domainLookupStart', 'domainLookupEnd',
|
||||||
|
'connectStart', 'connectEnd', 'secureConnectionStart',
|
||||||
|
'requestStart', 'responseStart', 'responseEnd',
|
||||||
|
'domLoading', 'domInteractive',
|
||||||
|
'domContentLoadedEventStart', 'domContentLoadedEventEnd',
|
||||||
|
'domComplete', 'loadEventStart', 'loadEventEnd',
|
||||||
|
];
|
||||||
|
for (const prop of props) {
|
||||||
|
testing.expectEqual('number', typeof t[prop]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const Page = @import("../Page.zig");
|
|||||||
const datetime = @import("../../datetime.zig");
|
const datetime = @import("../../datetime.zig");
|
||||||
|
|
||||||
pub fn registerTypes() []const type {
|
pub fn registerTypes() []const type {
|
||||||
return &.{ Performance, Entry, Mark, Measure, PerformanceTiming };
|
return &.{ Performance, Entry, Mark, Measure, PerformanceTiming, PerformanceNavigation };
|
||||||
}
|
}
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
@@ -13,6 +13,7 @@ const Performance = @This();
|
|||||||
_time_origin: u64,
|
_time_origin: u64,
|
||||||
_entries: std.ArrayList(*Entry) = .{},
|
_entries: std.ArrayList(*Entry) = .{},
|
||||||
_timing: PerformanceTiming = .{},
|
_timing: PerformanceTiming = .{},
|
||||||
|
_navigation: PerformanceNavigation = .{},
|
||||||
|
|
||||||
/// Get high-resolution timestamp in microseconds, rounded to 5μs increments
|
/// Get high-resolution timestamp in microseconds, rounded to 5μs increments
|
||||||
/// to match browser behavior (prevents fingerprinting)
|
/// to match browser behavior (prevents fingerprinting)
|
||||||
@@ -29,6 +30,7 @@ pub fn init() Performance {
|
|||||||
._time_origin = highResTimestamp(),
|
._time_origin = highResTimestamp(),
|
||||||
._entries = .{},
|
._entries = .{},
|
||||||
._timing = .{},
|
._timing = .{},
|
||||||
|
._navigation = .{},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +50,10 @@ pub fn getTimeOrigin(self: *const Performance) f64 {
|
|||||||
return @as(f64, @floatFromInt(self._time_origin)) / 1000.0;
|
return @as(f64, @floatFromInt(self._time_origin)) / 1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getNavigation(self: *Performance) *PerformanceNavigation {
|
||||||
|
return &self._navigation;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mark(
|
pub fn mark(
|
||||||
self: *Performance,
|
self: *Performance,
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
@@ -270,6 +276,7 @@ pub const JsApi = struct {
|
|||||||
pub const getEntriesByName = bridge.function(Performance.getEntriesByName, .{});
|
pub const getEntriesByName = bridge.function(Performance.getEntriesByName, .{});
|
||||||
pub const timeOrigin = bridge.accessor(Performance.getTimeOrigin, null, .{});
|
pub const timeOrigin = bridge.accessor(Performance.getTimeOrigin, null, .{});
|
||||||
pub const timing = bridge.accessor(Performance.getTiming, null, .{});
|
pub const timing = bridge.accessor(Performance.getTiming, null, .{});
|
||||||
|
pub const navigation = bridge.accessor(Performance.getNavigation, null, .{});
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Entry = struct {
|
pub const Entry = struct {
|
||||||
@@ -519,6 +526,30 @@ pub const PerformanceTiming = struct {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// PerformanceNavigation implements the Navigation Timing Level 1 API.
|
||||||
|
// https://www.w3.org/TR/navigation-timing/#sec-navigation-navigation-timing-interface
|
||||||
|
// Stub implementation — returns 0 for type (TYPE_NAVIGATE) and 0 for redirectCount.
|
||||||
|
pub const PerformanceNavigation = struct {
|
||||||
|
// Padding to avoid zero-size struct, which causes identity_map pointer collisions.
|
||||||
|
_pad: bool = false,
|
||||||
|
|
||||||
|
pub fn getType(_: *const PerformanceNavigation) f64 { return 0; }
|
||||||
|
pub fn getRedirectCount(_: *const PerformanceNavigation) f64 { return 0; }
|
||||||
|
|
||||||
|
pub const JsApi = struct {
|
||||||
|
pub const bridge = js.Bridge(PerformanceNavigation);
|
||||||
|
|
||||||
|
pub const Meta = struct {
|
||||||
|
pub const name = "PerformanceNavigation";
|
||||||
|
pub const prototype_chain = bridge.prototypeChain();
|
||||||
|
pub var class_id: bridge.ClassId = undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const @"type" = bridge.accessor(PerformanceNavigation.getType, null, .{});
|
||||||
|
pub const redirectCount = bridge.accessor(PerformanceNavigation.getRedirectCount, null, .{});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const testing = @import("../../testing.zig");
|
const testing = @import("../../testing.zig");
|
||||||
test "WebApi: Performance" {
|
test "WebApi: Performance" {
|
||||||
try testing.htmlRunner("performance.html", .{});
|
try testing.htmlRunner("performance.html", .{});
|
||||||
|
|||||||
Reference in New Issue
Block a user