use std::rc::Rc;
use dom_struct::dom_struct;
use js::context::JSContext;
use js::jsapi::{GCReason, JS_GC};
use script_bindings::reflector::Reflector;
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 {
#[expect(unsafe_code)]
fn Gc(cx: &mut JSContext, global: &GlobalScope) -> Rc<Promise> {
let promise = Promise::new(cx, global);
let trusted = TrustedPromise::new(promise.clone());
let task = task!(testutils_gc: move |cx| {
unsafe {
JS_GC(cx.raw_cx(), GCReason::DOM_TESTUTILS);
}
let promise = trusted.root();
promise.resolve_native(cx, &());
});
global
.task_manager()
.dom_manipulation_task_source()
.queue(task);
promise
}
}