mirror of
https://github.com/servo/servo.git
synced 2025-06-20 15:18:58 +01:00
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
This commit is contained in:
commit
c876335d22
8 changed files with 78 additions and 48 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue