fire_timer moved due timers into an unrooted Vec; a GC inside one callback swept the functions of the timers still waiting. Heavy-web reruns and cargo test still pending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
3.5 KiB
Rust
104 lines
3.5 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
// check-tidy: no specs after this line
|
|
|
|
use backtrace::Backtrace;
|
|
use dom_struct::dom_struct;
|
|
use js::context::{JSContext, NoGC};
|
|
use layout_api::ReflowPhasesRun;
|
|
use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods;
|
|
use script_bindings::domstring::DOMString;
|
|
use script_bindings::reflector::Reflector;
|
|
use script_bindings::root::DomRoot;
|
|
use servo_base::Epoch;
|
|
use time::Duration;
|
|
|
|
use crate::dom::bindings::codegen::Bindings::ServoTestUtilsBinding::ServoTestUtilsMethods;
|
|
use crate::dom::globalscope::GlobalScope;
|
|
use crate::dom::layoutresult::LayoutResult;
|
|
use crate::dom::types::AccessibilityUpdateResult;
|
|
|
|
#[dom_struct]
|
|
pub(crate) struct ServoTestUtils {
|
|
reflector_: Reflector,
|
|
}
|
|
|
|
impl ServoTestUtilsMethods<crate::DomTypeHolder> for ServoTestUtils {
|
|
fn AdvanceClock(no_gc: &NoGC, global: &GlobalScope, ms: i32) {
|
|
global
|
|
.as_window()
|
|
.advance_animation_clock(no_gc, Duration::milliseconds(ms as i64));
|
|
}
|
|
|
|
#[expect(unsafe_code)]
|
|
fn CrashHard(_: &GlobalScope) {
|
|
unsafe { std::ptr::null_mut::<i32>().write(42) }
|
|
}
|
|
|
|
fn ForceLayout(cx: &mut JSContext, global: &GlobalScope) -> DomRoot<LayoutResult> {
|
|
let (phases_run, statistics) = global.as_window().Document().update_the_rendering(cx);
|
|
|
|
let mut phases = Vec::new();
|
|
if phases_run.contains(ReflowPhasesRun::RanLayout) {
|
|
phases.push(DOMString::from_static("RanLayout"))
|
|
}
|
|
if phases_run.contains(ReflowPhasesRun::BuiltStackingContextTree) {
|
|
phases.push(DOMString::from_static("BuiltStackingContextTree"))
|
|
}
|
|
if phases_run.contains(ReflowPhasesRun::BuiltDisplayList) {
|
|
phases.push(DOMString::from_static("BuiltDisplayList"))
|
|
}
|
|
if phases_run.contains(ReflowPhasesRun::UpdatedScrollNodeOffset) {
|
|
phases.push(DOMString::from_static("UpdatedScrollNodeOffset"))
|
|
}
|
|
if phases_run.contains(ReflowPhasesRun::UpdatedImageData) {
|
|
phases.push(DOMString::from_static("UpdatedImageData"))
|
|
}
|
|
|
|
LayoutResult::new(
|
|
cx,
|
|
global,
|
|
phases,
|
|
statistics.rebuilt_fragment_count,
|
|
statistics.restyle_fragment_count,
|
|
statistics.only_descendants_changed_count,
|
|
)
|
|
}
|
|
|
|
fn Js_backtrace(_: &GlobalScope) {
|
|
println!("Current JS stack:");
|
|
let rust_stack = Backtrace::new();
|
|
println!("Current Rust stack:\n{:?}", rust_stack);
|
|
}
|
|
|
|
fn Panic(_: &GlobalScope) {
|
|
panic!("explicit panic from script")
|
|
}
|
|
|
|
fn EnsureAccessibilityActive(global: &GlobalScope) {
|
|
let window = global.as_window();
|
|
window
|
|
.layout()
|
|
.set_accessibility_active(true, Epoch::default());
|
|
}
|
|
|
|
fn ForceAccessibilityUpdate(
|
|
cx: &mut JSContext,
|
|
global: &GlobalScope,
|
|
) -> DomRoot<AccessibilityUpdateResult> {
|
|
let window = global.as_window();
|
|
window.layout().set_force_accessibility_update();
|
|
let (_, statistics) = window.Document().update_the_rendering(cx);
|
|
|
|
AccessibilityUpdateResult::new(
|
|
cx,
|
|
global,
|
|
statistics.nodes_updated_from_dom,
|
|
statistics.nodes_updated_from_tree,
|
|
statistics.nodes_updated_bounds,
|
|
statistics.nodes_in_tree_update,
|
|
)
|
|
}
|
|
}
|