diff options
author | Ms2ger <ms2ger@gmail.com> | 2014-07-10 16:40:41 +0200 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2014-07-10 16:45:41 +0200 |
commit | 439bc78cabe2ef23748000b1eb9f345c9206524e (patch) | |
tree | 35f69907dffd2e4bae1aa9a8566bb07de0c4391c /src/components/script/dom/document.rs | |
parent | 360d5d01d86ec15fdfd8e3da62b2c39e731fa0d3 (diff) | |
download | servo-439bc78cabe2ef23748000b1eb9f345c9206524e.tar.gz servo-439bc78cabe2ef23748000b1eb9f345c9206524e.zip |
Return a Temporary from *Binding::Wrap.
Returning a JS<T> is GC-unsafe.
This commit also includes some cleanup around Node and Document reflection.
Diffstat (limited to 'src/components/script/dom/document.rs')
-rw-r--r-- | src/components/script/dom/document.rs | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 0bace6cf66a..a79beaedadb 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -47,7 +47,6 @@ use servo_util::namespace::{Namespace, Null}; use servo_util::str::{DOMString, null_str_as_empty_ref}; use std::collections::hashmap::HashMap; -use js::jsapi::JSContext; use std::ascii::StrAsciiExt; use std::cell::{Cell, RefCell}; use url::{Url, from_str}; @@ -192,20 +191,6 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> { } impl Document { - pub fn reflect_document(document: Box<Document>, - window: &JSRef<Window>, - wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<Window>, Box<Document>) -> JS<Document>) - -> Temporary<Document> { - assert!(document.reflector().get_jsobject().is_null()); - let raw_doc = reflect_dom_object(document, window, wrap_fn).root(); - assert!(raw_doc.reflector().get_jsobject().is_not_null()); - - let doc_alias = raw_doc.clone(); - let node: &JSRef<Node> = NodeCast::from_ref(&doc_alias); - node.set_owner_doc(&*raw_doc); - Temporary::from_rooted(&*raw_doc) - } - pub fn new_inherited(window: &JSRef<Window>, url: Option<Url>, is_html_document: IsHTMLDocument, @@ -243,7 +228,12 @@ impl Document { pub fn new(window: &JSRef<Window>, url: Option<Url>, doctype: IsHTMLDocument, content_type: Option<DOMString>) -> Temporary<Document> { let document = Document::new_inherited(window, url, doctype, content_type); - Document::reflect_document(box document, window, DocumentBinding::Wrap) + let document = reflect_dom_object(box document, window, + DocumentBinding::Wrap).root(); + + let node: &JSRef<Node> = NodeCast::from_ref(&*document); + node.set_owner_doc(&*document); + Temporary::from_rooted(&*document) } } |