diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2014-01-13 21:00:18 -0800 |
---|---|---|
committer | Patrick Walton <pcwalton@mimiga.net> | 2014-01-14 21:51:24 -0800 |
commit | 7d447dbc062429b97d75bebd6fdea7878fbd049d (patch) | |
tree | 5903ac1ee64a8a9edf6cf4308daad8a96b5186cf /src/components/main/layout/util.rs | |
parent | 563d6ef91a43a4ebefb87281db7e4813d2afcee6 (diff) | |
download | servo-7d447dbc062429b97d75bebd6fdea7878fbd049d.tar.gz servo-7d447dbc062429b97d75bebd6fdea7878fbd049d.zip |
script: Stop trusting pointers to DOM nodes that layout provides.
Pointers to DOM nodes from layout could go stale if incremental reflow
does not correctly destroy dead nodes. Therefore, we ask the JavaScript
garbage collector to verify that each DOM node is indeed a valid pointer
before calling event handlers on it, and fail otherwise.
Diffstat (limited to 'src/components/main/layout/util.rs')
-rw-r--r-- | src/components/main/layout/util.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/components/main/layout/util.rs b/src/components/main/layout/util.rs index 65cf0b6b676..8ef031bfb3f 100644 --- a/src/components/main/layout/util.rs +++ b/src/components/main/layout/util.rs @@ -7,8 +7,9 @@ use layout::construct::{ConstructionResult, NoConstructionResult}; use layout::wrapper::LayoutNode; use extra::arc::Arc; +use script::dom::bindings::utils::Reflectable; use script::dom::node::AbstractNode; -use script::layout_interface::LayoutChan; +use script::layout_interface::{LayoutChan, UntrustedNodeAddress}; use servo_util::range::Range; use std::cast; use std::cell::{Ref, RefMut}; @@ -211,21 +212,28 @@ impl OpaqueNode { /// Converts a DOM node (layout view) to an `OpaqueNode`. pub fn from_layout_node(node: &LayoutNode) -> OpaqueNode { unsafe { - OpaqueNode(cast::transmute_copy(node)) + let abstract_node = node.get_abstract(); + let ptr: uintptr_t = cast::transmute(abstract_node.reflector().get_jsobject()); + OpaqueNode(ptr) } } /// Converts a DOM node (script view) to an `OpaqueNode`. pub fn from_script_node(node: &AbstractNode) -> OpaqueNode { unsafe { - OpaqueNode(cast::transmute_copy(node)) + let ptr: uintptr_t = cast::transmute(node.reflector().get_jsobject()); + OpaqueNode(ptr) } } - /// Unsafely converts an `OpaqueNode` to a DOM node (script view). Use this only if you - /// absolutely know what you're doing. - pub unsafe fn to_script_node(&self) -> AbstractNode { - cast::transmute(**self) + /// Converts this node to an `UntrustedNodeAddress`. An `UntrustedNodeAddress` is just the type + /// of node that script expects to receive in a hit test. + pub fn to_untrusted_node_address(&self) -> UntrustedNodeAddress { + unsafe { + let OpaqueNode(addr) = *self; + let addr: UntrustedNodeAddress = cast::transmute(addr); + addr + } } /// Returns the address of this node, for debugging purposes. |