Nacre/vendor/servo-script/dom/testing/testutils.rs
astar76 0ecfd0f573 S031: root due timers in vendored servo-script (R5-01 SIGSEGV), crash-adblock regression smoke
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 <[email protected]>
2026-11-12 20:38:47 -06:00

48 lines
1.7 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/. */
use dom_struct::dom_struct;
use js::context::JSContext;
use js::jsapi::{GCReason, JS_GC};
use script_bindings::reflector::Reflector;
use crate::dom::RootedPromise;
use crate::dom::bindings::codegen::Bindings::TestUtilsBinding::TestUtilsMethods;
use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
use crate::test::TrustedPromise;
#[dom_struct]
pub(crate) struct TestUtils {
reflector_: Reflector,
}
impl TestUtilsMethods<crate::DomTypeHolder> for TestUtils {
/// <https://testutils.spec.whatwg.org/#dom-testutils-gc>
#[expect(unsafe_code)]
fn Gc(cx: &mut JSContext, global: &GlobalScope) -> RootedPromise {
// 1. Let p be a new promise.
let promise = Promise::new(cx, global);
let trusted = TrustedPromise::from(&promise);
// 2. Run the following in parallel:
// 2.1 Run implementation-defined steps to perform a garbage collection covering at least the entry Realm.
// 2.2 Resolve p.
// We need to spin the event-loop in order get the GC to actually run.
// We do this by queuing a task that calls the GC and then resolves the promise.
let task = task!(testutils_gc: move |cx| {
unsafe {
JS_GC(cx.raw_cx(), GCReason::DOM_TESTUTILS);
}
let promise = trusted.root(cx);
promise.resolve_native(cx, &());
});
global
.task_manager()
.dom_manipulation_task_source()
.queue(task);
promise
}
}