mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #7466 - nox:rootedvec-from-iter, r=Ms2ger
Implement FromIterator<Root<A>> for RootedVec<JS<A>> (fixes #5117) <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7466) <!-- Reviewable:end -->
This commit is contained in:
commit
fea36ceb9a
2 changed files with 14 additions and 3 deletions
|
@ -29,7 +29,7 @@
|
||||||
//! The `no_jsmanaged_fields!()` macro adds an empty implementation of `JSTraceable` to
|
//! The `no_jsmanaged_fields!()` macro adds an empty implementation of `JSTraceable` to
|
||||||
//! a datatype.
|
//! a datatype.
|
||||||
|
|
||||||
use dom::bindings::js::JS;
|
use dom::bindings::js::{JS, Root};
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
use dom::bindings::utils::{Reflectable, Reflector, WindowProxyHandler};
|
use dom::bindings::utils::{Reflectable, Reflector, WindowProxyHandler};
|
||||||
use script_task::ScriptChan;
|
use script_task::ScriptChan;
|
||||||
|
@ -69,6 +69,7 @@ use std::collections::{HashMap, HashSet};
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::intrinsics::return_address;
|
use std::intrinsics::return_address;
|
||||||
|
use std::iter::{FromIterator, IntoIterator};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -511,6 +512,17 @@ impl<T: JSTraceable + Reflectable> DerefMut for RootedVec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A: JSTraceable + Reflectable> FromIterator<Root<A>> for RootedVec<JS<A>> {
|
||||||
|
#[allow(moved_no_move)]
|
||||||
|
fn from_iter<T>(iterable: T) -> RootedVec<JS<A>> where T: IntoIterator<Item=Root<A>> {
|
||||||
|
let mut vec = RootedVec::new_with_destination_address(unsafe {
|
||||||
|
return_address() as *const libc::c_void
|
||||||
|
});
|
||||||
|
vec.extend(iterable.into_iter().map(|item| JS::from_rooted(&item)));
|
||||||
|
vec
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// SM Callback that traces the rooted traceables
|
/// SM Callback that traces the rooted traceables
|
||||||
pub unsafe fn trace_traceables(tracer: *mut JSTracer) {
|
pub unsafe fn trace_traceables(tracer: *mut JSTracer) {
|
||||||
ROOTED_TRACEABLES.with(|ref traceables| {
|
ROOTED_TRACEABLES.with(|ref traceables| {
|
||||||
|
|
|
@ -1629,8 +1629,7 @@ impl Node {
|
||||||
Node::adopt(node, &*parent.owner_doc());
|
Node::adopt(node, &*parent.owner_doc());
|
||||||
}
|
}
|
||||||
// Step 2.
|
// Step 2.
|
||||||
let mut removed_nodes = RootedVec::new();
|
let removed_nodes = parent.children().collect::<RootedVec<_>>();
|
||||||
removed_nodes.extend(parent.children().map(|child| JS::from_rooted(&child)));
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
let mut added_nodes = RootedVec::new();
|
let mut added_nodes = RootedVec::new();
|
||||||
let added_nodes = if let Some(node) = node.as_ref() {
|
let added_nodes = if let Some(node) = node.as_ref() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue