mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Use a Temporary iterator in Node::collect_text_contents()
This commit is contained in:
parent
e57630711f
commit
cdb3efec87
2 changed files with 6 additions and 5 deletions
|
@ -524,8 +524,7 @@ impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> {
|
||||||
|
|
||||||
// http://www.whatwg.org/html/#dom-script-text
|
// http://www.whatwg.org/html/#dom-script-text
|
||||||
fn Text(self) -> DOMString {
|
fn Text(self) -> DOMString {
|
||||||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
Node::collect_text_contents(NodeCast::from_ref(self).children())
|
||||||
Node::collect_text_contents(node.children().map(|c| c.root()).map(|c| c.get_unsound_ref_forever()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.whatwg.org/html/#dom-script-text
|
// http://www.whatwg.org/html/#dom-script-text
|
||||||
|
|
|
@ -1681,10 +1681,11 @@ impl Node {
|
||||||
Temporary::from_rooted(copy.r())
|
Temporary::from_rooted(copy.r())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_text_contents<'a, T: Iterator<Item=JSRef<'a, Node>>>(iterator: T) -> String {
|
pub fn collect_text_contents<T: Iterator<Item=Temporary<Node>>>(iterator: T) -> String {
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
for node in iterator {
|
for node in iterator {
|
||||||
let text: Option<JSRef<Text>> = TextCast::to_ref(node);
|
let node = node.root();
|
||||||
|
let text = TextCast::to_ref(node.r());
|
||||||
match text {
|
match text {
|
||||||
Some(text) => content.push_str(text.characterdata().data().as_slice()),
|
Some(text) => content.push_str(text.characterdata().data().as_slice()),
|
||||||
None => (),
|
None => (),
|
||||||
|
@ -1832,7 +1833,8 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
||||||
match self.type_id {
|
match self.type_id {
|
||||||
NodeTypeId::DocumentFragment |
|
NodeTypeId::DocumentFragment |
|
||||||
NodeTypeId::Element(..) => {
|
NodeTypeId::Element(..) => {
|
||||||
let content = Node::collect_text_contents(self.traverse_preorder());
|
let content = Node::collect_text_contents(
|
||||||
|
self.traverse_preorder().map(Temporary::from_rooted));
|
||||||
Some(content)
|
Some(content)
|
||||||
}
|
}
|
||||||
NodeTypeId::Comment |
|
NodeTypeId::Comment |
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue