mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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:
commit
2f0b805fad
13 changed files with 66 additions and 57 deletions
|
@ -400,9 +400,8 @@ impl FromJSValConvertible for USVString {
|
|||
impl ToJSValConvertible for ByteString {
|
||||
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||
unsafe {
|
||||
let slice = self.as_slice();
|
||||
let jsstr = JS_NewStringCopyN(cx, slice.as_ptr() as *const libc::c_char,
|
||||
slice.len() as libc::size_t);
|
||||
let jsstr = JS_NewStringCopyN(cx, self.as_ptr() as *const libc::c_char,
|
||||
self.len() as libc::size_t);
|
||||
if jsstr.is_null() {
|
||||
panic!("JS_NewStringCopyN failed");
|
||||
}
|
||||
|
|
|
@ -593,7 +593,7 @@ impl RootCollection {
|
|||
/// `RootCollection` object. Attempts to transfer ownership of a `Root` via
|
||||
/// moving will trigger dynamic unrooting failures due to incorrect ordering.
|
||||
#[no_move]
|
||||
pub struct Root<T> {
|
||||
pub struct Root<T: Reflectable> {
|
||||
/// List that ensures correct dynamic root ordering
|
||||
root_list: &'static RootCollection,
|
||||
/// Reference to rooted value that must not outlive this container
|
||||
|
|
|
@ -47,7 +47,7 @@ unsafe impl Send for TrustedReference {}
|
|||
/// shared among tasks for use in asynchronous operations. The underlying
|
||||
/// DOM object is guaranteed to live at least as long as the last outstanding
|
||||
/// `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
|
||||
/// sending `Trusted<T>` between tasks, regardless of T's sendability.
|
||||
ptr: *const libc::c_void,
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
|
||||
//! The `ByteString` struct.
|
||||
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::ToOwned;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops;
|
||||
use std::str;
|
||||
use std::str::FromStr;
|
||||
|
||||
|
@ -27,12 +29,6 @@ impl ByteString {
|
|||
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.
|
||||
pub fn len(&self) -> usize {
|
||||
let ByteString(ref vector) = *self;
|
||||
|
@ -41,20 +37,12 @@ impl ByteString {
|
|||
|
||||
/// Compare `self` to `other`, matching A–Z and a–z as equal.
|
||||
pub fn eq_ignore_case(&self, other: &ByteString) -> bool {
|
||||
// XXXManishearth make this more efficient
|
||||
self.to_lower() == other.to_lower()
|
||||
self.0.eq_ignore_ascii_case(&other.0)
|
||||
}
|
||||
|
||||
/// Returns `self` with A–Z replaced by a–z.
|
||||
pub fn to_lower(&self) -> ByteString {
|
||||
let ByteString(ref vec) = *self;
|
||||
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())
|
||||
ByteString::new(self.0.to_ascii_lowercase())
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// points with the replacement character.
|
||||
pub struct USVString(pub String);
|
||||
|
|
|
@ -99,7 +99,7 @@ pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) {
|
|||
unsafe {
|
||||
let name = CString::new(description).unwrap();
|
||||
(*tracer).debugPrinter = None;
|
||||
(*tracer).debugPrintIndex = -1;
|
||||
(*tracer).debugPrintIndex = !0;
|
||||
(*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void;
|
||||
debug!("tracing value {}", description);
|
||||
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 {
|
||||
let name = CString::new(description).unwrap();
|
||||
(*tracer).debugPrinter = None;
|
||||
(*tracer).debugPrintIndex = -1;
|
||||
(*tracer).debugPrintIndex = !0;
|
||||
(*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void;
|
||||
debug!("tracing {}", description);
|
||||
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
|
||||
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
|
||||
thread_local!(pub static ROOTED_COLLECTIONS: Rc<RefCell<RootedCollectionSet>> =
|
||||
Rc::new(RefCell::new(RootedCollectionSet::new())));
|
||||
|
||||
enum CollectionType {
|
||||
/// Type of `RootedVec`
|
||||
pub enum CollectionType {
|
||||
/// DOM objects
|
||||
DOMObjects,
|
||||
/// `JSVal`s
|
||||
JSVals,
|
||||
/// `*mut JSObject`s
|
||||
JSObjects,
|
||||
}
|
||||
|
||||
|
@ -356,10 +360,12 @@ impl RootedCollectionSet {
|
|||
}
|
||||
|
||||
unsafe fn trace(&self, tracer: *mut JSTracer) {
|
||||
fn trace_collection_type<T: JSTraceable>(tracer: *mut JSTracer,
|
||||
collections: &HashSet<*const RootedVec<()>>) {
|
||||
fn trace_collection_type<T>(tracer: *mut JSTracer,
|
||||
collections: &HashSet<*const RootedVec<Void>>)
|
||||
where T: JSTraceable + VecRootableType
|
||||
{
|
||||
for collection in collections {
|
||||
let collection: *const RootedVec<()> = *collection;
|
||||
let collection: *const RootedVec<Void> = *collection;
|
||||
let collection = collection as *const RootedVec<T>;
|
||||
unsafe {
|
||||
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 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 VecRootableType {
|
||||
pub trait VecRootableType {
|
||||
/// Return the type tag used to determine how to trace RootedVec
|
||||
fn tag(_a: Option<Self>) -> CollectionType;
|
||||
}
|
||||
|
@ -398,11 +404,21 @@ impl VecRootableType for *mut JSObject {
|
|||
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
|
||||
/// of this struct
|
||||
#[allow(unrooted_must_root)]
|
||||
#[no_move]
|
||||
pub struct RootedVec<T> {
|
||||
pub struct RootedVec<T: VecRootableType> {
|
||||
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>;
|
||||
fn deref(&self) -> &Vec<T> {
|
||||
&self.v
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DerefMut for RootedVec<T> {
|
||||
impl<T: VecRootableType> DerefMut for RootedVec<T> {
|
||||
fn deref_mut(&mut self) -> &mut Vec<T> {
|
||||
&mut self.v
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ use std::borrow::{IntoCow, ToOwned};
|
|||
use std::cell::{Ref, RefMut};
|
||||
use std::default::Default;
|
||||
use std::mem;
|
||||
use std::old_io::{MemWriter, Writer};
|
||||
use std::old_io::Writer;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -571,13 +571,13 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
|||
|
||||
fn serialize(self, traversal_scope: TraversalScope) -> Fallible<DOMString> {
|
||||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||
let mut writer = MemWriter::new();
|
||||
let mut writer = vec![];
|
||||
match serialize(&mut writer, &node,
|
||||
SerializeOpts {
|
||||
traversal_scope: traversal_scope,
|
||||
.. Default::default()
|
||||
}) {
|
||||
Ok(()) => Ok(String::from_utf8(writer.into_inner()).unwrap()),
|
||||
Ok(()) => Ok(String::from_utf8(writer).unwrap()),
|
||||
Err(_) => panic!("Cannot serialize element"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,12 +85,11 @@ macro_rules! make_url_or_base_getter(
|
|||
use std::ascii::AsciiExt;
|
||||
let element: JSRef<Element> = ElementCast::from_ref(self);
|
||||
let url = element.get_url_attribute(&Atom::from_slice($htmlname));
|
||||
match &*url {
|
||||
"" => {
|
||||
let window = window_from_node(self).root();
|
||||
window.r().get_url().serialize()
|
||||
},
|
||||
_ => url
|
||||
if url.is_empty() {
|
||||
let window = window_from_node(self).root();
|
||||
window.r().get_url().serialize()
|
||||
} else {
|
||||
url
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -80,12 +80,12 @@ impl<'a> TextEncoderMethods for JSRef<'a, TextEncoder> {
|
|||
#[allow(unsafe_code)]
|
||||
fn Encode(self, cx: *mut JSContext, input: USVString) -> *mut JSObject {
|
||||
unsafe {
|
||||
let output = self.encoder.encode(&input.0, EncoderTrap::Strict).unwrap();
|
||||
let length = output.len() as u32;
|
||||
let encoded = self.encoder.encode(&input.0, EncoderTrap::Strict).unwrap();
|
||||
let length = encoded.len() as u32;
|
||||
let js_object: *mut JSObject = JS_NewUint8Array(cx, length);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -399,14 +399,14 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> {
|
|||
debug!("SetRequestHeader: old value = {:?}", raw[0]);
|
||||
let mut buf = raw[0].clone();
|
||||
buf.push_all(b", ");
|
||||
buf.push_all(value.as_slice());
|
||||
buf.push_all(&value);
|
||||
debug!("SetRequestHeader: new value = {:?}", buf);
|
||||
value = ByteString::new(buf);
|
||||
},
|
||||
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(())
|
||||
}
|
||||
|
||||
|
@ -678,7 +678,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> {
|
|||
},
|
||||
_ if self.ready_state.get() != XMLHttpRequestState::Done => NullValue(),
|
||||
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 mut vp = UndefinedValue();
|
||||
unsafe {
|
||||
|
@ -1028,7 +1028,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
|
|||
let response = self.response.borrow();
|
||||
// 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
|
||||
encoding.decode(response.as_slice(), DecoderTrap::Replace).unwrap().to_owned()
|
||||
encoding.decode(&response, DecoderTrap::Replace).unwrap().to_owned()
|
||||
}
|
||||
fn filter_response_headers(self) -> Headers {
|
||||
// https://fetch.spec.whatwg.org/#concept-response-header-list
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue