servo: Merge #2801 - Return a Temporary from *Binding::Wrap (from Ms2ger:wrap-temp)

Source-Repo: https://github.com/servo/servo
Source-Revision: 3a22ee3237a92e6776b1e9d54ac3fc81ae7567df
This commit is contained in:
Ms2ger 2014-07-11 20:48:22 -04:00
Родитель bc2ebf9676
Коммит 4b3a4f0ded
5 изменённых файлов: 16 добавлений и 28 удалений

Просмотреть файл

@ -1792,7 +1792,7 @@ class CGWrapMethod(CGAbstractMethod):
else:
args = [Argument('*mut JSContext', 'aCx'),
Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)]
retval = 'JS<%s>' % descriptor.concreteType
retval = 'Temporary<%s>' % descriptor.concreteType
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True)
def definition_body(self):
@ -1809,7 +1809,7 @@ assert!(proto.is_not_null());
raw.reflector().set_jsobject(obj);
return raw;""" % CreateBindingJSObject(self.descriptor, "scope"))
Temporary::new(raw)""" % CreateBindingJSObject(self.descriptor, "scope"))
else:
return CGGeneric("""\
%s
@ -1818,7 +1818,8 @@ with_compartment(aCx, obj, || {
JS_SetPrototype(aCx, obj, proto);
});
raw.reflector().set_jsobject(obj);
return raw;""" % CreateBindingJSObject(self.descriptor))
Temporary::new(raw)""" % CreateBindingJSObject(self.descriptor))
class CGIDLInterface(CGThing):

Просмотреть файл

@ -377,9 +377,9 @@ pub trait Reflectable {
pub fn reflect_dom_object<T: Reflectable>
(obj: Box<T>,
window: &JSRef<window::Window>,
wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<window::Window>, Box<T>) -> JS<T>)
wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<window::Window>, Box<T>) -> Temporary<T>)
-> Temporary<T> {
Temporary::new(wrap_fn(window.deref().get_cx(), window, obj))
wrap_fn(window.get_cx(), window, obj)
}
#[allow(raw_pointer_deriving)]

Просмотреть файл

@ -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)
}
}

Просмотреть файл

@ -907,13 +907,10 @@ impl Node {
pub fn reflect_node<N: Reflectable+NodeBase>
(node: Box<N>,
document: &JSRef<Document>,
wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<Window>, Box<N>) -> JS<N>)
wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<Window>, Box<N>) -> Temporary<N>)
-> Temporary<N> {
assert!(node.reflector().get_jsobject().is_null());
let window = document.deref().window.root();
let node = reflect_dom_object(node, &window.root_ref(), wrap_fn).root();
assert!(node.deref().reflector().get_jsobject().is_not_null());
Temporary::from_rooted(&*node)
let window = document.window.root();
reflect_dom_object(node, &*window, wrap_fn)
}
pub fn new_inherited(type_id: NodeTypeId, doc: &JSRef<Document>) -> Node {

Просмотреть файл

@ -388,7 +388,7 @@ impl Window {
script_chan: ScriptChan,
compositor: Box<ScriptListener>,
image_cache_task: ImageCacheTask)
-> JS<Window> {
-> Temporary<Window> {
let win = box Window {
eventtarget: EventTarget::new_inherited(WindowTypeId),
script_chan: script_chan,