Upgrade rust.

This commit is contained in:
Ms2ger 2014-03-21 11:51:25 +01:00
parent 7ece5f92db
commit 31eee791dd
102 changed files with 724 additions and 839 deletions

View file

@ -2023,7 +2023,7 @@ def CreateBindingJSObject(descriptor, parent=None):
assert not descriptor.createGlobal
handler = """
let js_info = aScope.get().page().js_info();
let handler = js_info.get().get_ref().dom_static.proxy_handlers.get(&(PrototypeList::id::%s as uint));
let handler = js_info.get_ref().dom_static.proxy_handlers.get(&(PrototypeList::id::%s as uint));
""" % descriptor.name
create += handler + """ let obj = NewProxyObject(aCx, *handler,
&PrivateValue(squirrel_away_unique(aObject) as *libc::c_void),
@ -2338,12 +2338,12 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
self.descriptor.name)
else:
body += """ js_info.dom_static.attribute_ids.insert(PrototypeList::id::%s as uint,
vec::cast_to_mut(vec::from_slice(sAttributes_ids)));
slice::cast_to_mut(slice::from_slice(sAttributes_ids)));
""" % self.descriptor.name
body = "" #XXXjdm xray stuff isn't necessary yet
return (body + """ let cx = js_info.js_context.borrow().ptr;
let receiver = js_info.js_compartment.borrow().global_obj;
return (body + """ let cx = js_info.js_context.deref().ptr;
let receiver = js_info.js_compartment.global_obj;
let global: *JSObject = JS_GetGlobalForObject(cx, receiver);
return %s(cx, global, receiver).is_not_null();""" % (getter))
@ -3700,7 +3700,7 @@ class CGXrayHelper(CGAbstractExternMethod):
methods = self.properties.methods
if methods.hasNonChromeOnly() or methods.hasChromeOnly():
methodArgs = "Some(zip_copies(%(methods)s, *method_ids))" % varNames
setup += "let method_ids = js_info.get().get_ref().dom_static.method_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
setup += "let method_ids = js_info.get_ref().dom_static.method_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
else:
methodArgs = "None"
methodArgs = CGGeneric(methodArgs)
@ -3708,7 +3708,7 @@ class CGXrayHelper(CGAbstractExternMethod):
attrs = self.properties.attrs
if attrs.hasNonChromeOnly() or attrs.hasChromeOnly():
attrArgs = "Some(zip_copies(%(attrs)s, *attr_ids))" % varNames
setup += "let attr_ids = js_info.get().get_ref().dom_static.attribute_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
setup += "let attr_ids = js_info.get_ref().dom_static.attribute_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
else:
attrArgs = "None"
attrArgs = CGGeneric(attrArgs)
@ -3716,7 +3716,7 @@ class CGXrayHelper(CGAbstractExternMethod):
consts = self.properties.consts
if consts.hasNonChromeOnly() or consts.hasChromeOnly():
constArgs = "Some(zip_copies(%(consts)s, *const_ids))" % varNames
setup += "let const_ids = js_info.get().get_ref().dom_static.constant_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
setup += "let const_ids = js_info.get_ref().dom_static.constant_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
else:
constArgs = "None"
constArgs = CGGeneric(constArgs)
@ -4774,7 +4774,7 @@ class CGBindingRoot(CGThing):
'std::cmp',
'std::libc',
'std::ptr',
'std::vec',
'std::slice',
'std::str',
'std::num',
])
@ -5336,7 +5336,7 @@ class CallbackMember(CGNativeMember):
if self.argCount > 0:
replacements["argCount"] = self.argCountStr
replacements["argvDecl"] = string.Template(
"let mut argv = vec::from_elem(${argCount}, UndefinedValue());\n"
"let mut argv = slice::from_elem(${argCount}, UndefinedValue());\n"
).substitute(replacements)
else:
# Avoid weird 0-sized arrays

View file

@ -17,6 +17,7 @@ use js::jsval::JSVal;
use js::jsval::{NullValue, BooleanValue, Int32Value, UInt32Value, StringValue};
use js::jsval::ObjectValue;
use js::glue::RUST_JS_NumberValue;
use std::default::Default;
use std::libc;
pub trait ToJSValConvertible {

View file

@ -64,14 +64,14 @@ impl<T> JS<T> {
pub fn get<'a>(&'a self) -> &'a T {
let borrowed = self.ptr.borrow();
unsafe {
&(**borrowed.get())
&**borrowed
}
}
pub fn get_mut<'a>(&'a mut self) -> &'a mut T {
let mut borrowed = self.ptr.borrow_mut();
unsafe {
&mut (**borrowed.get())
&mut **borrowed
}
}

View file

@ -15,8 +15,8 @@ use std::cmp::Eq;
use std::libc;
use std::ptr;
use std::ptr::null;
use std::slice;
use std::str;
use std::vec;
use js::glue::*;
use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily};
use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewFunction};
@ -136,7 +136,7 @@ pub fn jsstring_to_str(cx: *JSContext, s: *JSString) -> DOMString {
unsafe {
let length = 0;
let chars = JS_GetStringCharsAndLength(cx, s, &length);
vec::raw::buf_as_slice(chars, length as uint, |char_vec| {
slice::raw::buf_as_slice(chars, length as uint, |char_vec| {
str::from_utf16(char_vec).unwrap()
})
}
@ -646,8 +646,8 @@ pub fn global_object_for_js_object(obj: *JSObject) -> JS<window::Window> {
fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
let win = global_object_for_js_object(obj);
let js_info = win.get().page().js_info();
match *js_info.get() {
Some(ref info) => info.js_context.borrow().ptr,
match *js_info {
Some(ref info) => info.js_context.deref().ptr,
None => fail!("no JS context for DOM global")
}
}

View file

@ -40,9 +40,9 @@ use servo_util::namespace::{Namespace, Null};
use servo_util::str::DOMString;
use collections::hashmap::HashMap;
use extra::url::{Url, from_str};
use js::jsapi::JSContext;
use std::ascii::StrAsciiExt;
use url::{Url, from_str};
use serialize::{Encoder, Encodable};
@ -610,12 +610,14 @@ impl Document {
// TODO: support the case if multiple elements
// which haves same id are in the same document.
self.idmap.mangle(id, element,
|_, new_element: &JS<Element>| -> JS<Element> {
new_element.clone()
},
|_, old_element: &mut JS<Element>, new_element: &JS<Element>| {
*old_element = new_element.clone();
});
// This would use mangle(), but some dumbass removed it.
match self.idmap.find_mut(&id) {
Some(v) => {
*v = element.clone();
return;
},
None => (),
}
self.idmap.insert(id, element.clone());
}
}

View file

@ -569,7 +569,7 @@ impl Element {
let doc = self.node.owner_doc();
let win = &doc.get().window;
let node: JS<Node> = NodeCast::from(abstract_self);
let (port, chan) = Chan::new();
let (chan, port) = channel();
let addr = node.to_trusted_node_address();
let ContentBoxesResponse(rects) = win.get().page().query_layout(ContentBoxesQuery(addr, chan), port);
let rects = rects.map(|r| {
@ -589,7 +589,7 @@ impl Element {
let doc = self.node.owner_doc();
let win = &doc.get().window;
let node: JS<Node> = NodeCast::from(abstract_self);
let (port, chan) = Chan::new();
let (chan, port) = channel();
let addr = node.to_trusted_node_address();
let ContentBoxResponse(rect) = win.get().page().query_layout(ContentBoxQuery(addr, chan), port);
ClientRect::new(

View file

@ -15,10 +15,10 @@ use dom::node::{Node, ElementNodeTypeId};
use dom::windowproxy::WindowProxy;
use servo_util::str::DOMString;
use extra::url::Url;
use serialize::{Encoder, Encodable};
use servo_msg::constellation_msg::{PipelineId, SubpageId};
use std::ascii::StrAsciiExt;
use url::Url;
enum SandboxAllowance {
AllowNothing = 0x00,

View file

@ -13,12 +13,12 @@ use dom::element::{AttributeHandlers, AfterSetAttrListener, BeforeRemoveAttrList
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{Node, ElementNodeTypeId, NodeHelpers, window_from_node};
use extra::url::Url;
use servo_util::geometry::to_px;
use layout_interface::{ContentBoxQuery, ContentBoxResponse};
use servo_net::image_cache_task;
use servo_util::url::parse_url;
use servo_util::str::DOMString;
use url::Url;
use serialize::{Encoder, Encodable};
@ -138,7 +138,7 @@ impl HTMLImageElement {
let node: JS<Node> = NodeCast::from(abstract_self);
let window = window_from_node(&node);
let page = window.get().page();
let (port, chan) = Chan::new();
let (chan, port) = channel();
let addr = node.to_trusted_node_address();
let ContentBoxResponse(rect) = page.query_layout(ContentBoxQuery(addr, chan), port);
to_px(rect.size.width) as u32
@ -153,7 +153,7 @@ impl HTMLImageElement {
let node = &self.htmlelement.element.node;
let doc = node.owner_doc();
let page = doc.get().window.get().page();
let (port, chan) = Chan::new();
let (chan, port) = channel();
let this_node: JS<Node> = NodeCast::from(abstract_self);
let addr = this_node.to_trusted_node_address();
let ContentBoxResponse(rect) = page.query_layout(ContentBoxQuery(addr, chan), port);

View file

@ -18,12 +18,12 @@ use dom::validitystate::ValidityState;
use dom::windowproxy::WindowProxy;
use servo_util::str::DOMString;
use extra::url::Url;
use servo_net::image_cache_task;
use servo_net::image_cache_task::ImageCacheTask;
use servo_util::url::parse_url;
use servo_util::namespace::Null;
use servo_util::url::is_image_data;
use url::Url;
#[deriving(Encodable)]
pub struct HTMLObjectElement {

View file

@ -27,7 +27,7 @@ struct Untraceable {
impl<S: Encoder> Encodable<S> for Untraceable {
fn encode(&self, s: &mut S) {
self.page.borrow().encode(s);
self.page.encode(s);
}
}
@ -60,7 +60,7 @@ impl Location {
}
pub fn Href(&self) -> DOMString {
self.extra.page.borrow().get_url().to_str()
self.extra.page.get_url().to_str()
}
pub fn SetHref(&self, _href: DOMString) -> Fallible<()> {

View file

@ -162,14 +162,12 @@ impl LayoutDataRef {
/// Returns true if there is layout data present.
#[inline]
pub fn is_present(&self) -> bool {
let data_ref = self.data_cell.borrow();
data_ref.get().is_some()
self.data_cell.borrow().is_some()
}
/// Take the chan out of the layout data if it is present.
pub fn take_chan(&self) -> Option<LayoutChan> {
let mut data_ref = self.data_cell.borrow_mut();
let layout_data = data_ref.get();
let mut layout_data = self.data_cell.borrow_mut();
match *layout_data {
None => None,
Some(..) => Some(layout_data.get_mut_ref().chan.take_unwrap()),
@ -1353,7 +1351,7 @@ impl Node {
if copy.is_document() {
document = DocumentCast::to(&copy).unwrap();
}
assert_eq!(copy.get().owner_doc(), &document);
assert!(copy.get().owner_doc() == &document);
// Step 4 (some data already copied in step 2).
match node.type_id() {

View file

@ -28,14 +28,14 @@ use js::JSPROP_ENUMERATE;
use collections::hashmap::HashMap;
use std::cast;
use std::cmp;
use std::comm::Chan;
use std::comm::{channel, Sender, Receiver};
use std::comm::Select;
use std::hash::{Hash, sip};
use std::io::timer::Timer;
use std::rc::Rc;
use serialize::{Encoder, Encodable};
use extra::url::{Url};
use url::Url;
pub enum TimerControlMsg {
TimerMessageFire(~TimerData),
@ -45,7 +45,7 @@ pub enum TimerControlMsg {
pub struct TimerHandle {
handle: i32,
cancel_chan: Option<Chan<()>>,
cancel_chan: Option<Sender<()>>,
}
impl<S: Encoder> Encodable<S> for TimerHandle {
@ -65,6 +65,12 @@ impl Eq for TimerHandle {
}
}
impl TotalEq for TimerHandle {
fn equals(&self, other: &TimerHandle) -> bool {
self.eq(other)
}
}
impl TimerHandle {
fn cancel(&self) {
self.cancel_chan.as_ref().map(|chan| chan.send(()));
@ -87,25 +93,23 @@ pub struct Window {
struct Untraceable {
page: Rc<Page>,
compositor: ~ScriptListener,
timer_chan: Chan<TimerControlMsg>,
timer_chan: Sender<TimerControlMsg>,
}
impl<S: Encoder> Encodable<S> for Untraceable {
fn encode(&self, s: &mut S) {
let page = self.page.borrow();
page.encode(s);
self.page.encode(s);
}
}
impl Window {
pub fn get_cx(&self) -> *JSObject {
let js_info = self.page().js_info();
(*js_info.get()).get_ref().js_compartment.borrow().cx.borrow().ptr
js_info.get_ref().js_compartment.cx.deref().ptr
}
pub fn page<'a>(&'a self) -> &'a Page {
let page = &self.extra.page;
page.borrow()
&*self.extra.page
}
pub fn get_url(&self) -> Url {
self.page().get_url()
@ -143,7 +147,7 @@ impl Window {
pub fn Document(&self) -> JS<Document> {
let frame = self.page().frame();
(*frame.get()).get_ref().document.clone()
frame.get_ref().document.clone()
}
pub fn Name(&self) -> DOMString {
@ -233,7 +237,7 @@ impl Window {
// Post a delayed message to the per-window timer task; it will dispatch it
// to the relevant script handler that will deal with it.
let tm = Timer::new().unwrap();
let (cancel_port, cancel_chan) = Chan::new();
let (cancel_chan, cancel_port) = channel();
let chan = self.extra.timer_chan.clone();
spawn_named("Window:SetTimeout", proc() {
let mut tm = tm;
@ -294,8 +298,8 @@ impl Window {
compositor: compositor,
page: page.clone(),
timer_chan: {
let (timer_port, timer_chan): (Port<TimerControlMsg>, Chan<TimerControlMsg>) = Chan::new();
let id = page.borrow().id.clone();
let (timer_chan, timer_port): (Sender<TimerControlMsg>, Receiver<TimerControlMsg>) = channel();
let id = page.id.clone();
spawn_named("timer controller", proc() {
let ScriptChan(script_chan) = script_chan;
loop {