Nacre/vendor/servo-script/dom/range/staticrange.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 <noreply@anthropic.com>
2026-11-12 20:38:47 -06:00

123 lines
3.6 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 std::rc::Rc;
use dom_struct::dom_struct;
use js::context::JSContext;
use js::rust::HandleObject;
use script_bindings::reflector::reflect_weak_referenceable_dom_object_with_proto;
use crate::dom::abstractrange::AbstractRange;
use crate::dom::bindings::codegen::Bindings::StaticRangeBinding::{
StaticRangeInit, StaticRangeMethods,
};
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::inheritance::NodeTypeId;
use crate::dom::bindings::root::DomRoot;
use crate::dom::document::Document;
use crate::dom::node::Node;
use crate::dom::window::Window;
#[dom_struct]
pub(crate) struct StaticRange {
abstract_range: AbstractRange,
}
impl StaticRange {
pub(crate) fn new(
cx: &mut JSContext,
document: &Document,
start_container: &Node,
start_offset: u32,
end_container: &Node,
end_offset: u32,
) -> DomRoot<StaticRange> {
Self::new_with_proto(
cx,
document,
start_container,
start_offset,
end_container,
end_offset,
None, /* proto */
)
}
fn new_inherited(
start_container: &Node,
start_offset: u32,
end_container: &Node,
end_offset: u32,
) -> StaticRange {
StaticRange {
abstract_range: AbstractRange::new_inherited(
start_container,
start_offset,
end_container,
end_offset,
),
}
}
pub(crate) fn new_with_proto(
cx: &mut JSContext,
document: &Document,
start_container: &Node,
start_offset: u32,
end_container: &Node,
end_offset: u32,
proto: Option<HandleObject>,
) -> DomRoot<StaticRange> {
reflect_weak_referenceable_dom_object_with_proto(
cx,
Rc::new(StaticRange::new_inherited(
start_container,
start_offset,
end_container,
end_offset,
)),
document.window(),
proto,
)
}
}
impl StaticRangeMethods<crate::DomTypeHolder> for StaticRange {
/// <https://dom.spec.whatwg.org/#dom-staticrange-staticrange>
fn Constructor(
cx: &mut JSContext,
window: &Window,
proto: Option<HandleObject>,
init: &StaticRangeInit,
) -> Fallible<DomRoot<StaticRange>> {
match init.startContainer.type_id() {
NodeTypeId::DocumentType | NodeTypeId::Attr => {
return Err(Error::InvalidNodeType(Some(
"Invalid node type: startContainer cannot be DocumentType or Attr node".into(),
)));
},
_ => (),
}
match init.endContainer.type_id() {
NodeTypeId::DocumentType | NodeTypeId::Attr => {
return Err(Error::InvalidNodeType(Some(
"Invalid node type: endContainer cannot be DocumentType or Attr node".into(),
)));
},
_ => (),
}
let document = window.Document();
Ok(StaticRange::new_with_proto(
cx,
&document,
&init.startContainer,
init.startOffset,
&init.endContainer,
init.endOffset,
proto,
))
}
}