Add LayoutJS<Node>::from_trusted_node_address()

This commit is contained in:
Tetsuharu OHZEKI 2015-01-25 02:57:38 +09:00
parent 8889041c19
commit 9f57fa17d0
3 changed files with 14 additions and 4 deletions

View file

@ -32,7 +32,7 @@ use gfx::paint_task::{PaintChan, PaintLayer};
use gfx::paint_task::Msg as PaintMsg;
use layout_traits::{LayoutControlMsg, LayoutTaskFactory};
use log;
use script::dom::bindings::js::{JS, LayoutJS};
use script::dom::bindings::js::LayoutJS;
use script::dom::node::{LayoutDataRef, Node, NodeTypeId};
use script::dom::element::ElementTypeId;
use script::dom::htmlelement::HTMLElementTypeId;
@ -720,7 +720,7 @@ impl LayoutTask {
// FIXME(rust#16366): The following line had to be moved because of a
// rustc bug. It should be in the next unsafe block.
let mut node: LayoutJS<Node> = unsafe {
JS::from_trusted_node_address(data.document_root).to_layout()
LayoutJS::from_trusted_node_address(data.document_root)
};
let node: &mut LayoutNode = unsafe {
mem::transmute(&mut node)

View file

@ -10,7 +10,7 @@ use wrapper::{LayoutNode, TLayoutNode, ThreadSafeLayoutNode};
use gfx::display_list::OpaqueNode;
use gfx;
use libc::uintptr_t;
use script::dom::bindings::js::{JS, LayoutJS};
use script::dom::bindings::js::LayoutJS;
use script::dom::bindings::utils::Reflectable;
use script::dom::node::{Node, SharedLayoutData};
use script::layout_interface::{LayoutChan, TrustedNodeAddress};
@ -150,7 +150,7 @@ impl OpaqueNodeMethods for OpaqueNode {
fn from_script_node(node: TrustedNodeAddress) -> OpaqueNode {
unsafe {
OpaqueNodeMethods::from_jsmanaged(&JS::from_trusted_node_address(node).to_layout())
OpaqueNodeMethods::from_jsmanaged(&LayoutJS::from_trusted_node_address(node))
}
}

View file

@ -191,6 +191,16 @@ impl JS<Node> {
}
}
impl LayoutJS<Node> {
/// Create a new JS-owned value wrapped from an address known to be a `Node` pointer.
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> LayoutJS<Node> {
let TrustedNodeAddress(addr) = inner;
LayoutJS {
ptr: NonZero::new(addr as *const Node)
}
}
}
impl<T: Reflectable> JS<T> {
/// Create a new JS-owned value wrapped from a raw Rust pointer.
pub unsafe fn from_raw(raw: *const T) -> JS<T> {