From def62ebfa0fd78e1685f182bdd58a96deb073564 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Thu, 11 Jun 2026 07:18:14 +0800 Subject: [PATCH] Apply endEvaluationWindow in more places --- src/browser/Frame.zig | 2 +- src/browser/ScriptManagerBase.zig | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/browser/Frame.zig b/src/browser/Frame.zig index 70910efa..bbe669fc 100644 --- a/src/browser/Frame.zig +++ b/src/browser/Frame.zig @@ -1762,7 +1762,7 @@ pub fn loadExternalStylesheet(self: *Frame, link: *Element.Html.Link, href: []co const sm = &self._script_manager.base; const was_evaluating = sm.is_evaluating; sm.is_evaluating = true; - defer sm.is_evaluating = was_evaluating; + defer sm.endEvaluationWindow(was_evaluating); var response = http_client.syncRequest(arena, .{ .url = resolved, diff --git a/src/browser/ScriptManagerBase.zig b/src/browser/ScriptManagerBase.zig index 80d5f22d..f917ced6 100644 --- a/src/browser/ScriptManagerBase.zig +++ b/src/browser/ScriptManagerBase.zig @@ -96,7 +96,7 @@ owner: Owner, is_evaluating: bool, // an evaluate() arrived while is_evaluating was set, signal to call evaluate() -// when is_evaluating becomes false (to prevent reentrency) +// when is_evaluating becomes false (to prevent re-entrancy) evaluate_pending: bool = false, // Only once this is true can deferred scripts be run @@ -171,6 +171,7 @@ pub fn reset(self: *ScriptManagerBase) void { clearList(&self.async_scripts); clearList(&self.ready_scripts); self.static_scripts_done = false; + self.evaluate_pending = false; } fn clearList(list: *std.DoublyLinkedList) void { @@ -355,10 +356,9 @@ pub fn getAsyncImport(self: *ScriptManagerBase, url: [:0]const u8, cb: ImportAsy } // It's possible, but unlikely, for client.request to immediately finish - // a request, thus calling our callback. We generally don't want a call - // from v8 (which is why we're here), to result in a new script evaluation. - // So we block even the slightest change that `client.request` immediately - // executes a callback. + // a request, thus calling our callback. We don't want that to trigger a + // script evaluation while we're still setting the request up (the script + // isn't fully linked into our lists yet). const was_evaluating = self.is_evaluating; self.is_evaluating = true; defer self.endEvaluationWindow(was_evaluating); @@ -410,14 +410,14 @@ pub fn scriptCreatedParseDone(self: *ScriptManagerBase) void { pub fn evaluate(self: *ScriptManagerBase) void { if (self.is_evaluating) { // It's possible for a script.eval to cause evaluate to be called again. - // signal that this happened so that when we're done the outer-evaluate - // we can evaluate() again to catch these that we're gonna skip now. + // Signal that this happened so that, once the outer evaluate finishes, + // we evaluate() again to catch what we're skipping now. self.evaluate_pending = true; return; } self.is_evaluating = true; - defer self.is_evaluating = false; + defer self.endEvaluationWindow(false); while (true) { self.evaluate_pending = false;