From e340087b0c7f8eea2c359b6b213f3824219723bc Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Fri, 1 Aug 2025 11:07:51 +0200 Subject: [PATCH] More work --- components/script/dom/document.rs | 9 ++-- components/script/microtask.rs | 2 - components/script/script_thread.rs | 49 +++++++++++-------- .../wptrunner/executors/executorservo.py | 5 +- 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 613abfe27c2..68d0b4a2f16 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -3673,7 +3673,6 @@ impl Document { if self.has_resize_observers() { return true; } - if self.window().has_unhandled_resize_event() { return true; } @@ -3723,7 +3722,9 @@ impl Document { receiver.recv().unwrap(); } - self.window().reflow(ReflowGoal::UpdateTheRendering) + let result = self.window().reflow(ReflowGoal::UpdateTheRendering); + self.maybe_send_document_fonts_ready_message(CanGc::note()); + result } /// From https://drafts.csswg.org/css-font-loading/#font-face-set-ready: @@ -3754,9 +3755,11 @@ impl Document { if self.ReadyState() != DocumentReadyState::Complete { return; } - if self.needs_rendering_update() { + if !self.restyle_reason().is_empty() { return; } + + //eprintln!("fullfilling promise"); fonts.fulfill_ready_promise_if_needed(can_gc); } diff --git a/components/script/microtask.rs b/components/script/microtask.rs index 3f5969e7b7f..b034e8154a3 100644 --- a/components/script/microtask.rs +++ b/components/script/microtask.rs @@ -100,8 +100,6 @@ impl MicrotaskQueue { // Step 1 self.performing_a_microtask_checkpoint.set(true); - debug!("Now performing a microtask checkpoint"); - // Steps 2 while !self.microtask_queue.borrow().is_empty() { rooted_vec!(let mut pending_queue); diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 16eada5aeeb..ce4c74d28ae 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1247,6 +1247,8 @@ impl ScriptThread { pub(crate) fn update_the_rendering(&self, can_gc: CanGc) { self.last_render_opportunity_time.set(Some(Instant::now())); self.cancel_scheduled_update_the_rendering(); + self.has_pending_animation_tick + .store(false, Ordering::Relaxed); if !self.can_continue_running_inner() { return; @@ -1401,11 +1403,6 @@ impl ScriptThread { } fn maybe_schedule_rendering_opportunity_after_ipc_message(&self, can_gc: CanGc) { - if self.has_pending_animation_tick.load(Ordering::Relaxed) { - self.update_the_rendering(can_gc); - return; - } - // If no document needs a rendering update, exit early to avoid doing more work. if !self .documents @@ -1423,14 +1420,17 @@ impl ScriptThread { .last_render_opportunity_time .get() .map(|last_render_opportunity_time| Instant::now() - last_render_opportunity_time) - .unwrap_or(Duration::MAX); + .unwrap_or(Duration::MAX) + .min(SCRIPT_THREAD_ANIMATION_TICK_DELAY); - // If it's been more than the time of a single frame the last rendering opportunity, - // just run it now. - if time_since_last_rendering_opportunity > SCRIPT_THREAD_ANIMATION_TICK_DELAY { - self.update_the_rendering(can_gc); - return; - } + //eprintln!(" - scheduling update\n"); + //// If it's been more than the time of a single frame the last rendering opportunity, + //// just run it now. + //if time_since_last_rendering_opportunity > SCRIPT_THREAD_ANIMATION_TICK_DELAY { + // println!(" - running immediately"); + // self.update_the_rendering(can_gc); + // return; + //} self.schedule_update_the_rendering_timer_if_necessary( SCRIPT_THREAD_ANIMATION_TICK_DELAY - time_since_last_rendering_opportunity, @@ -1438,14 +1438,13 @@ impl ScriptThread { } fn maybe_send_document_state_messages(&self, can_gc: CanGc) { - let waiting_for_stable_image = opts::get().wait_for_stable_image; + if !opts::get().wait_for_stable_image { + return; + } for (_, document) in self.documents.borrow().iter() { - if waiting_for_stable_image { - document - .window() - .maybe_send_idle_document_state_to_constellation(); - } - document.maybe_send_document_fonts_ready_message(can_gc); + document + .window() + .maybe_send_idle_document_state_to_constellation(); } } @@ -1658,9 +1657,17 @@ impl ScriptThread { docs.clear(); } - self.maybe_schedule_rendering_opportunity_after_ipc_message(can_gc); - self.maybe_send_document_state_messages(can_gc); + if self.has_pending_animation_tick.load(Ordering::Relaxed) { + self.update_the_rendering(can_gc); + } + self.maybe_send_document_state_messages(can_gc); + for (_, document) in self.documents.borrow().iter() { + document.maybe_send_document_fonts_ready_message(can_gc); + } + self.perform_a_microtask_checkpoint(can_gc); + + self.maybe_schedule_rendering_opportunity_after_ipc_message(can_gc); true } diff --git a/tests/wpt/tests/tools/wptrunner/wptrunner/executors/executorservo.py b/tests/wpt/tests/tools/wptrunner/wptrunner/executors/executorservo.py index 7b0a64a6048..d983cf048ed 100644 --- a/tests/wpt/tests/tools/wptrunner/wptrunner/executors/executorservo.py +++ b/tests/wpt/tests/tools/wptrunner/wptrunner/executors/executorservo.py @@ -173,7 +173,10 @@ class ServoTestharnessExecutor(ServoExecutor): prefix = "ALERT: RESULT: " decoded_line = line.decode("utf8", "replace") if decoded_line.startswith(prefix): - self.result_data = json.loads(decoded_line[len(prefix):]) + try: + self.result_data = json.loads(decoded_line[len(prefix):]) + except json.JSONDecodeError as error: + self.logger.error(f"Could not process test output JSON: {error}") self.result_flag.set() else: ServoExecutor.on_output(self, line)