Skip to content

Lightpanda: the headless browser designed for AI and automation

`Frame`: change `Location` reference release order

Halil Durak0bb2d1cf53bc
diff --git a/src/browser/Frame.zig b/src/browser/Frame.zig
index 70960445c..07c9a1597 100644
--- a/src/browser/Frame.zig
+++ b/src/browser/Frame.zig
@@ -566,13 +566,11 @@ pub fn navigate(self: *Frame, request_url: [:0]const u8, opts: NavigateOpts) !vo
// have to do this to make sure window.location is at a unique _address_.
// If we don't do this, multiple window._location will have the same
// address and thus be mapped to the same v8::Object in the identity map.
- //
- // We don't hold a reference to old location anymore.
- self.window._location.releaseRef(self._page);
- // Create new location.
const location = try Location.init(self.url, self);
location.acquireRef();
errdefer location.releaseRef(self._page);
+ // We're not holding a ref to old location anymore.
+ self.window._location.releaseRef(self._page);
self.window._location = location;
if (is_blob) {
@@ -810,11 +808,10 @@ fn scheduleNavigationWithArena(originator: *Frame, arena: Allocator, request_url
if (!opts.force and is_fragment_navigation) {
target.url = try target.arena.dupeZ(u8, resolved_url);
- // Release our reference to the previous location before replacing it.
- target.window._location.releaseRef(target._page);
const location = try Location.init(target.url, target);
location.acquireRef();
errdefer location.releaseRef(target._page);
+ target.window._location.releaseRef(target._page);
target.window._location = location;
if (target.parent == null) {
@@ -1094,12 +1091,11 @@ fn frameHeaderDoneCallback(response: HttpClient.Response) !bool {
}
}
- // Release our reference to location before.
- self.window._location.releaseRef(self._page);
// Init new location.
const location = try Location.init(self.url, self);
location.acquireRef();
errdefer location.releaseRef(self._page);
+ self.window._location.releaseRef(self._page);
self.window._location = location;
if (comptime IS_DEBUG) {