1818
1919const std = @import ("std" );
2020const JS = @import ("js/js.zig" );
21+ const lp = @import ("lightpanda" );
2122const builtin = @import ("builtin" );
2223
2324const Allocator = std .mem .Allocator ;
@@ -786,7 +787,9 @@ fn _wait(self: *Page, wait_ms: u32) !Session.WaitResult {
786787 // an extra socket, so it should not be possibl to
787788 // get an cdp_socket message when exit_when_done
788789 // is true.
789- std .debug .assert (exit_when_done == false );
790+ if (IS_DEBUG ) {
791+ std .debug .assert (exit_when_done == false );
792+ }
790793
791794 // data on a socket we aren't handling, return to caller
792795 return .cdp_socket ;
@@ -822,7 +825,9 @@ fn _wait(self: *Page, wait_ms: u32) !Session.WaitResult {
822825 // we don't need to consider http_client.intercepted here
823826 // because exit_when_done is true, and that can only be
824827 // the case when interception isn't possible.
825- std .debug .assert (http_client .intercepted == 0 );
828+ if (comptime IS_DEBUG ) {
829+ std .debug .assert (http_client .intercepted == 0 );
830+ }
826831
827832 const ms = ms_to_next_task orelse blk : {
828833 if (wait_ms - ms_remaining < 100 ) {
@@ -1019,7 +1024,9 @@ fn getElementIdMap(page: *Page, node: *Node) ElementIdMaps {
10191024 };
10201025 }
10211026 // Detached nodes should not have IDs registered
1022- std .debug .assert (false );
1027+ if (IS_DEBUG ) {
1028+ std .debug .assert (false );
1029+ }
10231030 return .{
10241031 .lookup = & page .document ._elements_by_id ,
10251032 .removed_ids = & page .document ._removed_ids ,
@@ -1265,14 +1272,14 @@ pub fn deliverSlotchangeEvents(self: *Page) void {
12651272}
12661273
12671274fn notifyNetworkIdle (self : * Page ) void {
1268- std . debug . assert (self ._notified_network_idle == .done );
1275+ lp . assert (self ._notified_network_idle == .done , "Page.notifyNetworkIdle" , .{} );
12691276 self ._session .browser .notification .dispatch (.page_network_idle , &.{
12701277 .timestamp = timestamp (.monotonic ),
12711278 });
12721279}
12731280
12741281fn notifyNetworkAlmostIdle (self : * Page ) void {
1275- std . debug . assert (self ._notified_network_almost_idle == .done );
1282+ lp . assert (self ._notified_network_almost_idle == .done , "Page.notifyNetworkAlmostIdle" , .{} );
12761283 self ._session .browser .notification .dispatch (.page_network_almost_idle , &.{
12771284 .timestamp = timestamp (.monotonic ),
12781285 });
@@ -1298,7 +1305,7 @@ pub fn appendNew(self: *Page, parent: *Node, child: Node.NodeOrText) !void {
12981305 },
12991306 };
13001307
1301- std . debug . assert (node ._parent == null );
1308+ lp . assert (node ._parent == null , "Page.appendNew" , .{} );
13021309 try self ._insertNodeRelative (true , parent , node , .append , .{
13031310 // this opts has no meaning since we're passing `true` as the first
13041311 // parameter, which indicates this comes from the parser, and has its
@@ -2213,7 +2220,7 @@ pub fn removeNode(self: *Page, parent: *Node, child: *Node, opts: RemoveNodeOpts
22132220 const children = parent ._children .? ;
22142221 switch (children .* ) {
22152222 .one = > | n | {
2216- std . debug . assert (n == child );
2223+ lp . assert (n == child , "Page.removeNode.one" , .{} );
22172224 parent ._children = null ;
22182225 self ._factory .destroy (children );
22192226 },
@@ -2340,7 +2347,8 @@ pub fn insertNodeRelative(self: *Page, parent: *Node, child: *Node, relative: In
23402347}
23412348pub fn _insertNodeRelative (self : * Page , comptime from_parser : bool , parent : * Node , child : * Node , relative : InsertNodeRelative , opts : InsertNodeOpts ) ! void {
23422349 // caller should have made sure this was the case
2343- std .debug .assert (child ._parent == null );
2350+
2351+ lp .assert (child ._parent == null , "Page.insertNodeRelative parent" , .{ .url = self .url });
23442352
23452353 const children = blk : {
23462354 // expand parent._children so that it can take another child
@@ -2369,14 +2377,14 @@ pub fn _insertNodeRelative(self: *Page, comptime from_parser: bool, parent: *Nod
23692377 },
23702378 .after = > | ref_node | {
23712379 // caller should have made sure this was the case
2372- std . debug . assert (ref_node ._parent .? == parent );
2380+ lp . assert (ref_node ._parent .? == parent , "Page.insertNodeRelative after" , .{ . url = self . url } );
23732381 // if ref_node is in parent, and expanded _children above to
23742382 // accommodate another child, then `children` must be a list
23752383 children .list .insertAfter (& ref_node ._child_link , & child ._child_link );
23762384 },
23772385 .before = > | ref_node | {
23782386 // caller should have made sure this was the case
2379- std . debug . assert (ref_node ._parent .? == parent );
2387+ lp . assert (ref_node ._parent .? == parent , "Page.insertNodeRelative before" , .{ . url = self . url } );
23802388 // if ref_node is in parent, and expanded _children above to
23812389 // accommodate another child, then `children` must be a list
23822390 children .list .insertBefore (& ref_node ._child_link , & child ._child_link );
@@ -2654,7 +2662,7 @@ pub fn parseHtmlAsChildren(self: *Page, node: *Node, html: []const u8) !void {
26542662 // https://github.com/servo/html5ever/issues/583
26552663 const children = node ._children orelse return ;
26562664 const first = children .one ;
2657- std . debug . assert (first .is (Element .Html .Html ) != null );
2665+ lp . assert (first .is (Element .Html .Html ) != null , "Page.parseHtmlAsChildren root" , .{ . type = first . _type } );
26582666 node ._children = first ._children ;
26592667
26602668 if (self .hasMutationObservers ()) {
0 commit comments