diff options
author | bors-servo <release+servo@mozilla.com> | 2014-01-14 22:06:56 -0800 |
---|---|---|
committer | bors-servo <release+servo@mozilla.com> | 2014-01-14 22:06:56 -0800 |
commit | c876335d227d4f826b5ece66fb388134cf29fce4 (patch) | |
tree | 9af551f0fd807bb33b71205021d6b3845a5d71de /src/components/script/dom/node.rs | |
parent | 32bf796efca9b2de42a86815b78926ca0785c19f (diff) | |
parent | 7d447dbc062429b97d75bebd6fdea7878fbd049d (diff) | |
download | servo-c876335d227d4f826b5ece66fb388134cf29fce4.tar.gz servo-c876335d227d4f826b5ece66fb388134cf29fce4.zip |
auto merge of #1490 : pcwalton/servo/distrust-layout-new, r=jdm
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.
Depends on the `get-addressable-gc-thing` branches of `mozjs` and `rust-mozjs`.
r? @jdm
Diffstat (limited to 'src/components/script/dom/node.rs')
-rw-r--r-- | src/components/script/dom/node.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 7c58f4d2751..14f02eb4bc8 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -7,6 +7,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{DOMString, null_str_as_empty}; use dom::bindings::utils::{ErrorResult, Fallible, NotFound, HierarchyRequest}; +use dom::bindings::utils; use dom::characterdata::CharacterData; use dom::document::{AbstractDocument, DocumentTypeId}; use dom::documenttype::DocumentType; @@ -17,15 +18,15 @@ use dom::htmliframeelement::HTMLIFrameElement; use dom::htmlimageelement::HTMLImageElement; use dom::nodelist::{NodeList}; use dom::text::Text; +use layout_interface::{LayoutChan, ReapLayoutDataMsg, UntrustedNodeAddress}; -use js::jsapi::{JSObject, JSContext}; - -use layout_interface::{LayoutChan, ReapLayoutDataMsg}; - -use std::cast; +use js::jsapi::{JSContext, JSObject, JSRuntime}; +use js::jsfriendapi; use std::cast::transmute; +use std::cast; use std::cell::{RefCell, Ref, RefMut}; use std::iter::Filter; +use std::libc::uintptr_t; use std::util; use std::unstable::raw::Box; @@ -241,6 +242,22 @@ impl AbstractNode { _ => false } } + + /// If the given untrusted node address represents a valid DOM node in the given runtime, + /// returns it. + pub fn from_untrusted_node_address(runtime: *JSRuntime, candidate: UntrustedNodeAddress) + -> AbstractNode { + unsafe { + let candidate: uintptr_t = cast::transmute(candidate); + let object: *JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime, + candidate); + if object.is_null() { + fail!("Attempted to create an `AbstractNode` from an invalid pointer!") + } + let boxed_node: *mut Box<Node> = utils::unwrap(object); + AbstractNode::from_box(boxed_node) + } + } } impl<'a> AbstractNode { |