mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #11872 - eddyb:back-to-roots, r=Ms2ger
Replace return_address usage for rooting with stack guards and convenience macros. The existing `Rooted` and `RootedVec` users were migrated the the following two macros: ```rust let x = Rooted::new(cx, value); // Was changed to: rooted!(in(cx) let x = value); // Which expands to: let mut __root = Rooted::new_unrooted(value); let x = RootedGuard::new(cx, &mut __root); ``` ```rust let mut v = RootedVec::new(); v.extend(iterator); // Was changed to: rooted_vec!(let v <- iterator); // Which expands to: let mut __root = RootableVec::new(); let v = RootedVec::new(&mut __root, iterator); ``` The `rooted!` macro depends on servo/rust-mozjs#272. These APIs based on two types, a container to be rooted and a rooting guard, allow implementing both `Rooted`-style rooting and `Traceable`-based rooting in stable Rust, without abusing `return_address`. Such macros may have been tried before, but in 1.9 their hygiene is broken, they work only since 1.10. Sadly, `Rooted` is a FFI type and completely exposed, so I cannot prevent anyone from creating their own, although all fields but the value get overwritten by `RootedGuard::new` anyway. `RootableVec` OTOH is *guaranteed* to be empty when not rooted, which makes it harmless AFAICT. By fixing rust-lang/rust#34227, this PR enables Servo to build with `-Zorbit`. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix rust-lang/rust#34227 - [x] These changes do not require tests because they are not functional changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11872) <!-- Reviewable:end -->
This commit is contained in:
commit
80cb0cf821
33 changed files with 315 additions and 308 deletions
|
@ -28,7 +28,6 @@ use dom::bindings::js::RootedReference;
|
|||
use dom::bindings::js::{JS, LayoutJS, MutNullableHeap};
|
||||
use dom::bindings::reflector::{Reflectable, reflect_dom_object};
|
||||
use dom::bindings::str::{DOMString, USVString};
|
||||
use dom::bindings::trace::RootedVec;
|
||||
use dom::bindings::xmlname::namespace_from_domstring;
|
||||
use dom::characterdata::{CharacterData, LayoutCharacterDataHelpers};
|
||||
use dom::document::{Document, DocumentSource, IsHTMLDocument};
|
||||
|
@ -1562,7 +1561,7 @@ impl Node {
|
|||
parent.ranges.increase_above(parent, index, count);
|
||||
}
|
||||
}
|
||||
let mut new_nodes = RootedVec::new();
|
||||
rooted_vec!(let mut new_nodes);
|
||||
let new_nodes = if let NodeTypeId::DocumentFragment = node.type_id() {
|
||||
// Step 3.
|
||||
new_nodes.extend(node.children().map(|kid| JS::from_ref(&*kid)));
|
||||
|
@ -1606,9 +1605,9 @@ impl Node {
|
|||
Node::adopt(node, &*parent.owner_doc());
|
||||
}
|
||||
// Step 2.
|
||||
let removed_nodes = parent.children().collect::<RootedVec<_>>();
|
||||
rooted_vec!(let removed_nodes <- parent.children());
|
||||
// Step 3.
|
||||
let mut added_nodes = RootedVec::new();
|
||||
rooted_vec!(let mut added_nodes);
|
||||
let added_nodes = if let Some(node) = node.as_ref() {
|
||||
if let NodeTypeId::DocumentFragment = node.type_id() {
|
||||
added_nodes.extend(node.children().map(|child| JS::from_ref(&*child)));
|
||||
|
@ -2152,7 +2151,7 @@ impl NodeMethods for Node {
|
|||
};
|
||||
|
||||
// Step 12.
|
||||
let mut nodes = RootedVec::new();
|
||||
rooted_vec!(let mut nodes);
|
||||
let nodes = if node.type_id() == NodeTypeId::DocumentFragment {
|
||||
nodes.extend(node.children().map(|node| JS::from_ref(&*node)));
|
||||
nodes.r()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue