New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Root nodes for the duration of their CSS transitions #16295
Merged
+244
−90
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dabebdf
Root nodes for the duration of their CSS transitions.
jdm c3b9714
Accumulate transitioning nodes inside the layout context.
jdm 9134918
Send information to script as part of finishing layout.
jdm 2ca80a8
Warn about ignored transitions which can't be rooted.
jdm b0bf2b4
Make methods storing layout-originating nodes unsafe.
jdm File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Root nodes for the duration of their CSS transitions.
This ensures that we can pass a node address as part of the asynchronous transition end notification, making it safe to fire the corresponding DOM event on the node from the script thread. Without explicitly rooting this node when the transition starts, we risk the node being GCed before the transition is complete.
- Loading branch information
commit dabebdfbf5e502e3eef7cb0159b20f0fa5e74f65
| @@ -47,7 +47,7 @@ use dom::globalscope::GlobalScope; | ||
| use dom::htmlanchorelement::HTMLAnchorElement; | ||
| use dom::htmliframeelement::{HTMLIFrameElement, NavigationType}; | ||
| use dom::mutationobserver::MutationObserver; | ||
| use dom::node::{Node, NodeDamage, window_from_node}; | ||
| use dom::node::{Node, NodeDamage, window_from_node, from_untrusted_node_address}; | ||
| use dom::serviceworker::TrustedServiceWorkerAddress; | ||
| use dom::serviceworkerregistration::ServiceWorkerRegistration; | ||
| use dom::servoparser::{ParserContext, ServoParser}; | ||
| @@ -69,7 +69,6 @@ use js::jsapi::{JSAutoCompartment, JSContext, JS_SetWrapObjectCallbacks}; | ||
| use js::jsapi::{JSTracer, SetWindowProxyClass}; | ||
| use js::jsval::UndefinedValue; | ||
| use js::rust::Runtime; | ||
| use layout_wrapper::ServoLayoutNode; | ||
| use mem::heap_size_of_self_and_children; | ||
| use microtask::{MicrotaskQueue, Microtask}; | ||
| use msg::constellation_msg::{FrameId, FrameType, PipelineId, PipelineNamespace}; | ||
| @@ -109,7 +108,6 @@ use std::sync::atomic::{AtomicBool, Ordering}; | ||
| use std::sync::mpsc::{Receiver, Select, Sender, channel}; | ||
| use std::thread; | ||
| use style::context::ReflowGoal; | ||
| use style::dom::{TNode, UnsafeNode}; | ||
| use style::thread_state; | ||
| use task_source::dom_manipulation::{DOMManipulationTask, DOMManipulationTaskSource}; | ||
| use task_source::file_reading::FileReadingTaskSource; | ||
| @@ -490,6 +488,10 @@ pub struct ScriptThread { | ||
| /// A list of pipelines containing documents that finished loading all their blocking | ||
| /// resources during a turn of the event loop. | ||
| docs_with_no_blocking_loads: DOMRefCell<HashSet<JS<Document>>>, | ||
|
|
||
| /// A list of nodes with in-progress CSS transitions, which roots them for the duration | ||
| /// of the transition. | ||
| transitioning_nodes: DOMRefCell<Vec<JS<Node>>>, | ||
| } | ||
|
|
||
| /// In the event of thread panic, all data on the stack runs its destructor. However, there | ||
| @@ -574,6 +576,17 @@ impl ScriptThreadFactory for ScriptThread { | ||
| } | ||
|
|
||
| impl ScriptThread { | ||
| pub fn note_newly_transitioning_nodes(nodes: Vec<UntrustedNodeAddress>) { | ||
nox
Member
|
||
| SCRIPT_THREAD_ROOT.with(|root| { | ||
| let script_thread = unsafe { &*root.get().unwrap() }; | ||
| let js_runtime = script_thread.js_runtime.rt(); | ||
| let new_nodes = nodes | ||
| .into_iter() | ||
| .map(|n| JS::from_ref(&*from_untrusted_node_address(js_runtime, n))); | ||
| script_thread.transitioning_nodes.borrow_mut().extend(new_nodes); | ||
| }) | ||
| } | ||
|
|
||
| pub fn add_mutation_observer(observer: &MutationObserver) { | ||
| SCRIPT_THREAD_ROOT.with(|root| { | ||
| let script_thread = unsafe { &*root.get().unwrap() }; | ||
| @@ -742,6 +755,8 @@ impl ScriptThread { | ||
| webvr_thread: state.webvr_thread, | ||
|
|
||
| docs_with_no_blocking_loads: Default::default(), | ||
|
|
||
| transitioning_nodes: Default::default(), | ||
| } | ||
| } | ||
|
|
||
| @@ -1602,11 +1617,27 @@ impl ScriptThread { | ||
| } | ||
|
|
||
| /// Handles firing of transition events. | ||
| #[allow(unsafe_code)] | ||
| fn handle_transition_event(&self, unsafe_node: UnsafeNode, name: String, duration: f64) { | ||
| let node = unsafe { ServoLayoutNode::from_unsafe(&unsafe_node) }; | ||
| let node = unsafe { node.get_jsmanaged().get_for_script() }; | ||
| let window = window_from_node(node); | ||
| fn handle_transition_event(&self, unsafe_node: UntrustedNodeAddress, name: String, duration: f64) { | ||
|
||
| let js_runtime = self.js_runtime.rt(); | ||
| let node = from_untrusted_node_address(js_runtime, unsafe_node); | ||
|
|
||
| let idx = self.transitioning_nodes | ||
| .borrow() | ||
| .iter() | ||
| .position(|n| &**n as *const _ == &*node as *const _); | ||
| match idx { | ||
| Some(idx) => { | ||
| self.transitioning_nodes.borrow_mut().remove(idx); | ||
| } | ||
| None => { | ||
| // If no index is found, we can't know whether this node is safe to use. | ||
| // It's better not to fire a DOM event than crash. | ||
| warn!("Ignoring transition end notification for unknown node."); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| let window = window_from_node(&*node); | ||
|
|
||
| // Not quite the right thing - see #13865. | ||
| node.dirty(NodeDamage::NodeStyleDamaged); | ||
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Why can't we send back the
nodeitself?