Auto merge of #5916 - servo:prepare-rustup, r=jdm

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5916)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-05-01 14:44:19 -05:00
commit 2f0b805fad
13 changed files with 66 additions and 57 deletions

View file

@ -109,7 +109,7 @@ impl BufferMap {
} }
}; };
if { if {
let list = &mut self.map[old_key].buffers; let list = &mut self.map.get_mut(&old_key).unwrap().buffers;
let condemned_buffer = list.pop().take().unwrap(); let condemned_buffer = list.pop().take().unwrap();
self.mem -= condemned_buffer.get_mem(); self.mem -= condemned_buffer.get_mem();
condemned_buffer.destroy(graphics_context); condemned_buffer.destroy(graphics_context);

View file

@ -139,7 +139,7 @@ impl FontCache {
let maybe_resource = load_whole_resource(&self.resource_task, url.clone()); let maybe_resource = load_whole_resource(&self.resource_task, url.clone());
match maybe_resource { match maybe_resource {
Ok((_, bytes)) => { Ok((_, bytes)) => {
let family = &mut self.web_families[family_name]; let family = &mut self.web_families.get_mut(&family_name).unwrap();
family.add_template(&url.to_string(), Some(bytes)); family.add_template(&url.to_string(), Some(bytes));
}, },
Err(_) => { Err(_) => {
@ -148,7 +148,7 @@ impl FontCache {
} }
} }
Source::Local(ref local_family_name) => { Source::Local(ref local_family_name) => {
let family = &mut self.web_families[family_name]; let family = &mut self.web_families.get_mut(&family_name).unwrap();
get_variations_for_family(&local_family_name, |path| { get_variations_for_family(&local_family_name, |path| {
family.add_template(&path, None); family.add_template(&path, None);
}); });
@ -188,7 +188,7 @@ impl FontCache {
// look up canonical name // look up canonical name
if self.local_families.contains_key(family_name) { if self.local_families.contains_key(family_name) {
debug!("FontList: Found font family with name={}", &**family_name); debug!("FontList: Found font family with name={}", &**family_name);
let s = &mut self.local_families[*family_name]; let s = self.local_families.get_mut(family_name).unwrap();
if s.templates.len() == 0 { if s.templates.len() == 0 {
get_variations_for_family(&family_name, |path| { get_variations_for_family(&family_name, |path| {
@ -213,7 +213,7 @@ impl FontCache {
fn find_font_in_web_family<'a>(&'a mut self, family_name: &LowercaseString, desc: &FontTemplateDescriptor) fn find_font_in_web_family<'a>(&'a mut self, family_name: &LowercaseString, desc: &FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> { -> Option<Arc<FontTemplateData>> {
if self.web_families.contains_key(family_name) { if self.web_families.contains_key(family_name) {
let family = &mut self.web_families[*family_name]; let family = self.web_families.get_mut(family_name).unwrap();
let maybe_font = family.find_font_for_style(desc, &self.font_context); let maybe_font = family.find_font_for_style(desc, &self.font_context);
maybe_font maybe_font
} else { } else {

View file

@ -88,7 +88,7 @@ impl TableRowGroupFlow {
self.collapsed_inline_direction_border_widths_for_table self.collapsed_inline_direction_border_widths_for_table
.extend(collapsed_inline_direction_border_widths_for_table.into_iter().map(|x| *x)); .extend(collapsed_inline_direction_border_widths_for_table.into_iter().map(|x| *x));
for _ in range(0, self.block_flow.base.children.len()) { for _ in 0..self.block_flow.base.children.len() {
if let Some(collapsed_block_direction_border_width_for_table) = if let Some(collapsed_block_direction_border_width_for_table) =
collapsed_block_direction_border_widths_for_table.next() { collapsed_block_direction_border_widths_for_table.next() {
self.collapsed_block_direction_border_widths_for_table self.collapsed_block_direction_border_widths_for_table

View file

@ -305,7 +305,7 @@ impl Flow for TableWrapperFlow {
self.compute_used_inline_size(layout_context, self.compute_used_inline_size(layout_context,
containing_block_inline_size, containing_block_inline_size,
intermediate_column_inline_sizes.as_slice()); &intermediate_column_inline_sizes);
if let TableLayout::Auto = self.table_layout { if let TableLayout::Auto = self.table_layout {
self.calculate_table_column_sizes_for_automatic_layout( self.calculate_table_column_sizes_for_automatic_layout(

View file

@ -400,9 +400,8 @@ impl FromJSValConvertible for USVString {
impl ToJSValConvertible for ByteString { impl ToJSValConvertible for ByteString {
fn to_jsval(&self, cx: *mut JSContext) -> JSVal { fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
unsafe { unsafe {
let slice = self.as_slice(); let jsstr = JS_NewStringCopyN(cx, self.as_ptr() as *const libc::c_char,
let jsstr = JS_NewStringCopyN(cx, slice.as_ptr() as *const libc::c_char, self.len() as libc::size_t);
slice.len() as libc::size_t);
if jsstr.is_null() { if jsstr.is_null() {
panic!("JS_NewStringCopyN failed"); panic!("JS_NewStringCopyN failed");
} }

View file

@ -593,7 +593,7 @@ impl RootCollection {
/// `RootCollection` object. Attempts to transfer ownership of a `Root` via /// `RootCollection` object. Attempts to transfer ownership of a `Root` via
/// moving will trigger dynamic unrooting failures due to incorrect ordering. /// moving will trigger dynamic unrooting failures due to incorrect ordering.
#[no_move] #[no_move]
pub struct Root<T> { pub struct Root<T: Reflectable> {
/// List that ensures correct dynamic root ordering /// List that ensures correct dynamic root ordering
root_list: &'static RootCollection, root_list: &'static RootCollection,
/// Reference to rooted value that must not outlive this container /// Reference to rooted value that must not outlive this container

View file

@ -47,7 +47,7 @@ unsafe impl Send for TrustedReference {}
/// shared among tasks for use in asynchronous operations. The underlying /// shared among tasks for use in asynchronous operations. The underlying
/// DOM object is guaranteed to live at least as long as the last outstanding /// DOM object is guaranteed to live at least as long as the last outstanding
/// `Trusted<T>` instance. /// `Trusted<T>` instance.
pub struct Trusted<T> { pub struct Trusted<T: Reflectable> {
/// A pointer to the Rust DOM object of type T, but void to allow /// A pointer to the Rust DOM object of type T, but void to allow
/// sending `Trusted<T>` between tasks, regardless of T's sendability. /// sending `Trusted<T>` between tasks, regardless of T's sendability.
ptr: *const libc::c_void, ptr: *const libc::c_void,

View file

@ -4,8 +4,10 @@
//! The `ByteString` struct. //! The `ByteString` struct.
use std::ascii::AsciiExt;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::ops;
use std::str; use std::str;
use std::str::FromStr; use std::str::FromStr;
@ -27,12 +29,6 @@ impl ByteString {
str::from_utf8(&vec).ok() str::from_utf8(&vec).ok()
} }
/// Returns the underlying vector as a slice.
pub fn as_slice<'a>(&'a self) -> &'a [u8] {
let ByteString(ref vector) = *self;
vector
}
/// Returns the length. /// Returns the length.
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
let ByteString(ref vector) = *self; let ByteString(ref vector) = *self;
@ -41,20 +37,12 @@ impl ByteString {
/// Compare `self` to `other`, matching AZ and az as equal. /// Compare `self` to `other`, matching AZ and az as equal.
pub fn eq_ignore_case(&self, other: &ByteString) -> bool { pub fn eq_ignore_case(&self, other: &ByteString) -> bool {
// XXXManishearth make this more efficient self.0.eq_ignore_ascii_case(&other.0)
self.to_lower() == other.to_lower()
} }
/// Returns `self` with AZ replaced by az. /// Returns `self` with AZ replaced by az.
pub fn to_lower(&self) -> ByteString { pub fn to_lower(&self) -> ByteString {
let ByteString(ref vec) = *self; ByteString::new(self.0.to_ascii_lowercase())
ByteString::new(vec.iter().map(|&x| {
if x > 'A' as u8 && x < 'Z' as u8 {
x + ('a' as u8) - ('A' as u8)
} else {
x
}
}).collect())
} }
/// Returns whether `self` is a `token`, as defined by /// Returns whether `self` is a `token`, as defined by
@ -158,6 +146,13 @@ impl FromStr for ByteString {
} }
} }
impl ops::Deref for ByteString {
type Target = [u8];
fn deref(&self) -> &[u8] {
&self.0
}
}
/// A string that is constructed from a UCS-2 buffer by replacing invalid code /// A string that is constructed from a UCS-2 buffer by replacing invalid code
/// points with the replacement character. /// points with the replacement character.
pub struct USVString(pub String); pub struct USVString(pub String);

View file

@ -99,7 +99,7 @@ pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) {
unsafe { unsafe {
let name = CString::new(description).unwrap(); let name = CString::new(description).unwrap();
(*tracer).debugPrinter = None; (*tracer).debugPrinter = None;
(*tracer).debugPrintIndex = -1; (*tracer).debugPrintIndex = !0;
(*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void; (*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void;
debug!("tracing value {}", description); debug!("tracing value {}", description);
JS_CallTracer(tracer, val.to_gcthing(), val.trace_kind()); JS_CallTracer(tracer, val.to_gcthing(), val.trace_kind());
@ -117,7 +117,7 @@ pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: *mut JSObject
unsafe { unsafe {
let name = CString::new(description).unwrap(); let name = CString::new(description).unwrap();
(*tracer).debugPrinter = None; (*tracer).debugPrinter = None;
(*tracer).debugPrintIndex = -1; (*tracer).debugPrintIndex = !0;
(*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void; (*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void;
debug!("tracing {}", description); debug!("tracing {}", description);
JS_CallTracer(tracer, obj as *mut libc::c_void, JSGCTraceKind::JSTRACE_OBJECT); JS_CallTracer(tracer, obj as *mut libc::c_void, JSGCTraceKind::JSTRACE_OBJECT);
@ -318,16 +318,20 @@ impl JSTraceable for () {
/// Holds a set of vectors that need to be rooted /// Holds a set of vectors that need to be rooted
pub struct RootedCollectionSet { pub struct RootedCollectionSet {
set: Vec<HashSet<*const RootedVec<()>>> set: Vec<HashSet<*const RootedVec<Void>>>
} }
/// TLV Holds a set of vectors that need to be rooted /// TLV Holds a set of vectors that need to be rooted
thread_local!(pub static ROOTED_COLLECTIONS: Rc<RefCell<RootedCollectionSet>> = thread_local!(pub static ROOTED_COLLECTIONS: Rc<RefCell<RootedCollectionSet>> =
Rc::new(RefCell::new(RootedCollectionSet::new()))); Rc::new(RefCell::new(RootedCollectionSet::new())));
enum CollectionType { /// Type of `RootedVec`
pub enum CollectionType {
/// DOM objects
DOMObjects, DOMObjects,
/// `JSVal`s
JSVals, JSVals,
/// `*mut JSObject`s
JSObjects, JSObjects,
} }
@ -356,10 +360,12 @@ impl RootedCollectionSet {
} }
unsafe fn trace(&self, tracer: *mut JSTracer) { unsafe fn trace(&self, tracer: *mut JSTracer) {
fn trace_collection_type<T: JSTraceable>(tracer: *mut JSTracer, fn trace_collection_type<T>(tracer: *mut JSTracer,
collections: &HashSet<*const RootedVec<()>>) { collections: &HashSet<*const RootedVec<Void>>)
where T: JSTraceable + VecRootableType
{
for collection in collections { for collection in collections {
let collection: *const RootedVec<()> = *collection; let collection: *const RootedVec<Void> = *collection;
let collection = collection as *const RootedVec<T>; let collection = collection as *const RootedVec<T>;
unsafe { unsafe {
let _ = (*collection).trace(tracer); let _ = (*collection).trace(tracer);
@ -367,10 +373,10 @@ impl RootedCollectionSet {
} }
} }
let dom_collections = &self.set[CollectionType::DOMObjects as usize] as *const _ as *const HashSet<*const RootedVec<*const Reflector>>; let dom_collections = &self.set[CollectionType::DOMObjects as usize] as *const _ as *const HashSet<*const RootedVec<JS<Void>>>;
for dom_collection in (*dom_collections).iter() { for dom_collection in (*dom_collections).iter() {
for reflector in (**dom_collection).iter() { for reflector in (**dom_collection).iter() {
trace_reflector(tracer, "", &**reflector); trace_reflector(tracer, "", reflector.reflector());
} }
} }
@ -381,7 +387,7 @@ impl RootedCollectionSet {
/// Trait implemented by all types that can be used with RootedVec /// Trait implemented by all types that can be used with RootedVec
trait VecRootableType { pub trait VecRootableType {
/// Return the type tag used to determine how to trace RootedVec /// Return the type tag used to determine how to trace RootedVec
fn tag(_a: Option<Self>) -> CollectionType; fn tag(_a: Option<Self>) -> CollectionType;
} }
@ -398,11 +404,21 @@ impl VecRootableType for *mut JSObject {
fn tag(_a: Option<*mut JSObject>) -> CollectionType { CollectionType::JSObjects } fn tag(_a: Option<*mut JSObject>) -> CollectionType { CollectionType::JSObjects }
} }
enum Void {}
impl VecRootableType for Void {
fn tag(_a: Option<Void>) -> CollectionType { unreachable!() }
}
impl Reflectable for Void {
fn reflector<'a>(&'a self) -> &'a Reflector { unreachable!() }
}
/// A vector of items that are rooted for the lifetime /// A vector of items that are rooted for the lifetime
/// of this struct /// of this struct
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
#[no_move] #[no_move]
pub struct RootedVec<T> { pub struct RootedVec<T: VecRootableType> {
v: Vec<T> v: Vec<T>
} }
@ -435,14 +451,14 @@ impl<T: VecRootableType> Drop for RootedVec<T> {
} }
} }
impl<T> Deref for RootedVec<T> { impl<T: VecRootableType> Deref for RootedVec<T> {
type Target = Vec<T>; type Target = Vec<T>;
fn deref(&self) -> &Vec<T> { fn deref(&self) -> &Vec<T> {
&self.v &self.v
} }
} }
impl<T> DerefMut for RootedVec<T> { impl<T: VecRootableType> DerefMut for RootedVec<T> {
fn deref_mut(&mut self) -> &mut Vec<T> { fn deref_mut(&mut self) -> &mut Vec<T> {
&mut self.v &mut self.v
} }

View file

@ -83,7 +83,7 @@ use std::borrow::{IntoCow, ToOwned};
use std::cell::{Ref, RefMut}; use std::cell::{Ref, RefMut};
use std::default::Default; use std::default::Default;
use std::mem; use std::mem;
use std::old_io::{MemWriter, Writer}; use std::old_io::Writer;
use std::sync::Arc; use std::sync::Arc;
#[dom_struct] #[dom_struct]
@ -571,13 +571,13 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
fn serialize(self, traversal_scope: TraversalScope) -> Fallible<DOMString> { fn serialize(self, traversal_scope: TraversalScope) -> Fallible<DOMString> {
let node: JSRef<Node> = NodeCast::from_ref(self); let node: JSRef<Node> = NodeCast::from_ref(self);
let mut writer = MemWriter::new(); let mut writer = vec![];
match serialize(&mut writer, &node, match serialize(&mut writer, &node,
SerializeOpts { SerializeOpts {
traversal_scope: traversal_scope, traversal_scope: traversal_scope,
.. Default::default() .. Default::default()
}) { }) {
Ok(()) => Ok(String::from_utf8(writer.into_inner()).unwrap()), Ok(()) => Ok(String::from_utf8(writer).unwrap()),
Err(_) => panic!("Cannot serialize element"), Err(_) => panic!("Cannot serialize element"),
} }
} }

View file

@ -85,12 +85,11 @@ macro_rules! make_url_or_base_getter(
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
let element: JSRef<Element> = ElementCast::from_ref(self); let element: JSRef<Element> = ElementCast::from_ref(self);
let url = element.get_url_attribute(&Atom::from_slice($htmlname)); let url = element.get_url_attribute(&Atom::from_slice($htmlname));
match &*url { if url.is_empty() {
"" => { let window = window_from_node(self).root();
let window = window_from_node(self).root(); window.r().get_url().serialize()
window.r().get_url().serialize() } else {
}, url
_ => url
} }
} }
); );

View file

@ -80,12 +80,12 @@ impl<'a> TextEncoderMethods for JSRef<'a, TextEncoder> {
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn Encode(self, cx: *mut JSContext, input: USVString) -> *mut JSObject { fn Encode(self, cx: *mut JSContext, input: USVString) -> *mut JSObject {
unsafe { unsafe {
let output = self.encoder.encode(&input.0, EncoderTrap::Strict).unwrap(); let encoded = self.encoder.encode(&input.0, EncoderTrap::Strict).unwrap();
let length = output.len() as u32; let length = encoded.len() as u32;
let js_object: *mut JSObject = JS_NewUint8Array(cx, length); let js_object: *mut JSObject = JS_NewUint8Array(cx, length);
let js_object_data: *mut uint8_t = JS_GetUint8ArrayData(js_object, cx); let js_object_data: *mut uint8_t = JS_GetUint8ArrayData(js_object, cx);
ptr::copy_nonoverlapping(js_object_data, output.as_ptr(), length as usize); ptr::copy_nonoverlapping(js_object_data, encoded.as_ptr(), length as usize);
return js_object; return js_object;
} }
} }

View file

@ -399,14 +399,14 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> {
debug!("SetRequestHeader: old value = {:?}", raw[0]); debug!("SetRequestHeader: old value = {:?}", raw[0]);
let mut buf = raw[0].clone(); let mut buf = raw[0].clone();
buf.push_all(b", "); buf.push_all(b", ");
buf.push_all(value.as_slice()); buf.push_all(&value);
debug!("SetRequestHeader: new value = {:?}", buf); debug!("SetRequestHeader: new value = {:?}", buf);
value = ByteString::new(buf); value = ByteString::new(buf);
}, },
None => {} None => {}
} }
headers.set_raw(name_str.to_owned(), vec![value.as_slice().to_vec()]); headers.set_raw(name_str.to_owned(), vec![value.to_vec()]);
Ok(()) Ok(())
} }
@ -678,7 +678,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> {
}, },
_ if self.ready_state.get() != XMLHttpRequestState::Done => NullValue(), _ if self.ready_state.get() != XMLHttpRequestState::Done => NullValue(),
Json => { Json => {
let decoded = UTF_8.decode(self.response.borrow().as_slice(), DecoderTrap::Replace).unwrap().to_owned(); let decoded = UTF_8.decode(&self.response.borrow(), DecoderTrap::Replace).unwrap().to_owned();
let decoded: Vec<u16> = decoded.utf16_units().collect(); let decoded: Vec<u16> = decoded.utf16_units().collect();
let mut vp = UndefinedValue(); let mut vp = UndefinedValue();
unsafe { unsafe {
@ -1028,7 +1028,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
let response = self.response.borrow(); let response = self.response.borrow();
// According to Simon, decode() should never return an error, so unwrap()ing // According to Simon, decode() should never return an error, so unwrap()ing
// the result should be fine. XXXManishearth have a closer look at this later // the result should be fine. XXXManishearth have a closer look at this later
encoding.decode(response.as_slice(), DecoderTrap::Replace).unwrap().to_owned() encoding.decode(&response, DecoderTrap::Replace).unwrap().to_owned()
} }
fn filter_response_headers(self) -> Headers { fn filter_response_headers(self) -> Headers {
// https://fetch.spec.whatwg.org/#concept-response-header-list // https://fetch.spec.whatwg.org/#concept-response-header-list