diff options
169 files changed, 940 insertions, 693 deletions
diff --git a/components/canvas/canvas_paint_task.rs b/components/canvas/canvas_paint_task.rs index 5fcd245a2f2..c8781419f10 100644 --- a/components/canvas/canvas_paint_task.rs +++ b/components/canvas/canvas_paint_task.rs @@ -5,6 +5,7 @@ use azure::azure::AzFloat; use azure::azure_hl::{DrawTarget, SurfaceFormat, BackendType, StrokeOptions, DrawOptions, Pattern}; use azure::azure_hl::{ColorPattern, PathBuilder, JoinStyle, CapStyle, DrawSurfaceOptions, Filter}; +use azure::azure_hl::{GradientStop, LinearGradientPattern, RadialGradientPattern, ExtendMode}; use geom::matrix2d::Matrix2D; use geom::point::Point2D; use geom::rect::Rect; @@ -28,6 +29,7 @@ pub enum CanvasMsg { Fill, MoveTo(Point2D<f32>), LineTo(Point2D<f32>), + QuadraticCurveTo(Point2D<f32>, Point2D<f32>), BezierCurveTo(Point2D<f32>, Point2D<f32>, Point2D<f32>), Arc(Point2D<f32>, f32, f32, f32, bool), SetFillStyle(FillOrStrokeStyle), @@ -80,6 +82,9 @@ impl<'a> CanvasPaintTask<'a> { CanvasMsg::Fill => painter.fill(), CanvasMsg::MoveTo(ref point) => painter.move_to(point), CanvasMsg::LineTo(ref point) => painter.line_to(point), + CanvasMsg::QuadraticCurveTo(ref cp, ref pt) => { + painter.quadratic_curve_to(cp, pt) + } CanvasMsg::BezierCurveTo(ref cp1, ref cp2, ref pt) => { painter.bezier_curve_to(cp1, cp2, pt) } @@ -150,6 +155,12 @@ impl<'a> CanvasPaintTask<'a> { self.path_builder.line_to(*point) } + fn quadratic_curve_to(&self, + cp: &Point2D<AzFloat>, + endpoint: &Point2D<AzFloat>) { + self.path_builder.quadratic_curve_to(cp, endpoint) + } + fn bezier_curve_to(&self, cp1: &Point2D<AzFloat>, cp2: &Point2D<AzFloat>, @@ -167,11 +178,11 @@ impl<'a> CanvasPaintTask<'a> { } fn set_fill_style(&mut self, style: FillOrStrokeStyle) { - self.fill_style = style.to_azure_pattern() + self.fill_style = style.to_azure_pattern(&self.drawtarget) } fn set_stroke_style(&mut self, style: FillOrStrokeStyle) { - self.stroke_style = style.to_azure_pattern() + self.stroke_style = style.to_azure_pattern(&self.drawtarget) } fn set_transform(&mut self, transform: &Matrix2D<f32>) { @@ -226,7 +237,7 @@ impl<'a> CanvasPaintTask<'a> { //start offset of the copyable rectangle let mut src = (src_read_rect.origin.y * stride + src_read_rect.origin.x * 4) as usize; //copy the data to the destination vector - for _ in range(0, src_read_rect.size.height) { + for _ in 0..src_read_rect.size.height { let row = &src_data[src .. src + (4 * src_read_rect.size.width) as usize]; dest_data.push_all(row); src += stride as usize; @@ -274,7 +285,7 @@ impl<'a> CanvasPaintTask<'a> { return } - let source_surface = self.drawtarget.create_source_surface_from_data(imagedata.as_slice(), + let source_surface = self.drawtarget.create_source_surface_from_data(&imagedata, image_data_rect.size, image_data_rect.size.width * 4, SurfaceFormat::B8G8R8A8); let draw_surface_options = DrawSurfaceOptions::new(Filter::Linear, true); @@ -292,20 +303,104 @@ impl<'a> CanvasPaintTask<'a> { } #[derive(Clone)] +pub struct CanvasGradientStop { + pub offset: f64, + pub color: RGBA, +} + +#[derive(Clone)] +pub struct LinearGradientStyle { + pub x0: f64, + pub y0: f64, + pub x1: f64, + pub y1: f64, + pub stops: Vec<CanvasGradientStop> +} + +impl LinearGradientStyle { + pub fn new(x0: f64, y0: f64, x1: f64, y1: f64, stops: Vec<CanvasGradientStop>) + -> LinearGradientStyle { + LinearGradientStyle { + x0: x0, + y0: y0, + x1: x1, + y1: y1, + stops: stops, + } + } +} + +#[derive(Clone)] +pub struct RadialGradientStyle { + pub x0: f64, + pub y0: f64, + pub r0: f64, + pub x1: f64, + pub y1: f64, + pub r1: f64, + pub stops: Vec<CanvasGradientStop> +} + +impl RadialGradientStyle { + pub fn new(x0: f64, y0: f64, r0: f64, x1: f64, y1: f64, r1: f64, stops: Vec<CanvasGradientStop>) + -> RadialGradientStyle { + RadialGradientStyle { + x0: x0, + y0: y0, + r0: r0, + x1: x1, + y1: y1, + r1: r1, + stops: stops, + } + } +} + +#[derive(Clone)] pub enum FillOrStrokeStyle { Color(RGBA), + LinearGradient(LinearGradientStyle), + RadialGradient(RadialGradientStyle), } impl FillOrStrokeStyle { - fn to_azure_pattern(&self) -> Pattern { + fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Pattern { match *self { FillOrStrokeStyle::Color(ref color) => { Pattern::Color(ColorPattern::new(color::new(color.red, color.green, color.blue, color.alpha))) + }, + FillOrStrokeStyle::LinearGradient(ref linear_gradient_style) => { + let gradient_stops: Vec<GradientStop> = linear_gradient_style.stops.iter().map(|s| { + GradientStop { + offset: s.offset as AzFloat, + color: color::new(s.color.red, s.color.green, s.color.blue, s.color.alpha) + } + }).collect(); + + Pattern::LinearGradient(LinearGradientPattern::new( + &Point2D(linear_gradient_style.x0 as AzFloat, linear_gradient_style.y0 as AzFloat), + &Point2D(linear_gradient_style.x1 as AzFloat, linear_gradient_style.y1 as AzFloat), + drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp), + &Matrix2D::identity())) + }, + FillOrStrokeStyle::RadialGradient(ref radial_gradient_style) => { + let gradient_stops: Vec<GradientStop> = radial_gradient_style.stops.iter().map(|s| { + GradientStop { + offset: s.offset as AzFloat, + color: color::new(s.color.red, s.color.green, s.color.blue, s.color.alpha) + } + }).collect(); + + Pattern::RadialGradient(RadialGradientPattern::new( + &Point2D(radial_gradient_style.x0 as AzFloat, radial_gradient_style.y0 as AzFloat), + &Point2D(radial_gradient_style.x1 as AzFloat, radial_gradient_style.y1 as AzFloat), + radial_gradient_style.r0 as AzFloat, radial_gradient_style.r1 as AzFloat, + drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp), + &Matrix2D::identity())) } } } } - diff --git a/components/canvas/lib.rs b/components/canvas/lib.rs index 42fa6733998..7118b76af00 100644 --- a/components/canvas/lib.rs +++ b/components/canvas/lib.rs @@ -2,7 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#![feature(core)] #![feature(collections)] extern crate azure; diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index ba8dfc3bb2c..e865c61be49 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -832,7 +832,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { }; let msg = ConstellationMsg::LoadUrl(root_pipeline_id, - LoadData::new(Url::parse(url_string.as_slice()).unwrap())); + LoadData::new(Url::parse(&url_string).unwrap())); let ConstellationChan(ref chan) = self.constellation_chan; chan.send(msg).unwrap() } @@ -1133,7 +1133,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { if output_image { let path: Path = - opts::get().output_file.as_ref().unwrap().as_slice().parse().unwrap(); + opts::get().output_file.as_ref().unwrap().parse().unwrap(); let mut pixels = gl::read_pixels(0, 0, width as gl::GLsizei, height as gl::GLsizei, @@ -1141,13 +1141,13 @@ impl<Window: WindowMethods> IOCompositor<Window> { gl::bind_framebuffer(gl::FRAMEBUFFER, 0); - gl::delete_buffers(texture_ids.as_slice()); - gl::delete_frame_buffers(framebuffer_ids.as_slice()); + gl::delete_buffers(&texture_ids); + gl::delete_frame_buffers(&framebuffer_ids); // flip image vertically (texture is upside down) let orig_pixels = pixels.clone(); let stride = width * 3; - for y in range(0, height) { + for y in 0..height { let dst_start = y * stride; let src_start = (height - y - 1) * stride; let src_slice = &orig_pixels[src_start .. src_start + stride]; diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 5c17b0e1b52..bf61a03e94b 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -22,8 +22,7 @@ use msg::constellation_msg::{FrameId, PipelineExitType, PipelineId}; use msg::constellation_msg::{SubpageId, WindowSizeData}; use msg::constellation_msg::Msg as ConstellationMsg; use net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient}; -use net::resource_task::ResourceTask; -use net::resource_task; +use net::resource_task::{self, ResourceTask}; use net::storage_task::{StorageTask, StorageTaskMsg}; use util::cursor::Cursor; use util::geometry::PagePx; @@ -32,7 +31,7 @@ use util::opts; use util::task::spawn_named; use util::time::TimeProfilerChan; use std::borrow::ToOwned; -use std::collections::{HashMap}; +use std::collections::HashMap; use std::old_io as io; use std::marker::PhantomData; use std::mem::replace; @@ -147,15 +146,12 @@ struct FrameTreeIterator<'a> { impl<'a> Iterator for FrameTreeIterator<'a> { type Item = &'a Frame; fn next(&mut self) -> Option<&'a Frame> { - match self.stack.pop() { - Some(next) => { - let frame = self.frames.get(&next).unwrap(); - let pipeline = self.pipelines.get(&frame.current).unwrap(); - self.stack.extend(pipeline.children.iter().map(|&c| c)); - Some(frame) - } - None => None, - } + self.stack.pop().map(|next| { + let frame = self.frames.get(&next).unwrap(); + let pipeline = self.pipelines.get(&frame.current).unwrap(); + self.stack.extend(pipeline.children.iter().map(|&c| c)); + frame + }) } } @@ -394,7 +390,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> { } fn handle_exit(&mut self) { - for (_id, ref pipeline) in self.pipelines.iter() { + for (_id, ref pipeline) in &self.pipelines { pipeline.exit(PipelineExitType::Complete); } self.image_cache_task.exit(); @@ -544,7 +540,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> { } None => { // Make sure no pending page would be overridden. - for frame_change in self.pending_frames.iter() { + for frame_change in &self.pending_frames { if frame_change.old_pipeline_id == Some(source_id) { // id that sent load msg is being changed already; abort return; @@ -582,36 +578,27 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> { let (prev_pipeline_id, next_pipeline_id) = { let frame = self.mut_frame(frame_id); - match direction { + let next = match direction { NavigationDirection::Forward => { if frame.next.is_empty() { debug!("no next page to navigate to"); return; - } else { - let prev = frame.current; - - frame.prev.push(frame.current); - let next = frame.next.pop().unwrap(); - frame.current = next; - - (prev, next) } + frame.prev.push(frame.current); + frame.next.pop().unwrap() } NavigationDirection::Back => { if frame.prev.is_empty() { debug!("no previous page to navigate to"); return; - } else { - let prev = frame.current; - - frame.next.push(frame.current); - let next = frame.prev.pop().unwrap(); - frame.current = next; - - (prev, next) } + frame.next.push(frame.current); + frame.prev.pop().unwrap() } - } + }; + let prev = frame.current; + frame.current = next; + (prev, next) }; // Suspend the old pipeline, and resume the new one. @@ -708,7 +695,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> { // Remove any evicted frames if let Some(evicted_frames) = evicted_frames { - for pipeline_id in evicted_frames.iter() { + for pipeline_id in &evicted_frames { self.close_pipeline(*pipeline_id, ExitPipelineMode::Normal); } } @@ -783,7 +770,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> { } // Send resize message to any pending pipelines that aren't loaded yet. - for pending_frame in self.pending_frames.iter() { + for pending_frame in &self.pending_frames { let pipeline = self.pipelines.get(&pending_frame.new_pipeline_id).unwrap(); if pipeline.parent_info.is_none() { let ScriptControlChan(ref chan) = pipeline.script_chan; @@ -810,7 +797,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> { let pipeline = self.pipelines.remove(&pipeline_id).unwrap(); // Remove any child frames - for child in pipeline.children.iter() { + for child in &pipeline.children { self.close_frame(*child, exit_mode); } @@ -840,7 +827,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> { children: vec!(), }; - for child_frame_id in pipeline.children.iter() { + for child_frame_id in &pipeline.children { frame_tree.children.push(self.frame_to_sendable(*child_frame_id)); } diff --git a/components/devtools/actor.rs b/components/devtools/actor.rs index 37c0a9c0482..5593a07e8a7 100644 --- a/components/devtools/actor.rs +++ b/components/devtools/actor.rs @@ -93,13 +93,13 @@ impl ActorRegistry { } pub fn register_script_actor(&self, script_id: String, actor: String) { - println!("registering {} ({})", actor.as_slice(), script_id.as_slice()); + println!("registering {} ({})", actor, script_id); let mut script_actors = self.script_actors.borrow_mut(); script_actors.insert(script_id, actor); } pub fn script_to_actor(&self, script_id: String) -> String { - if script_id.as_slice() == "" { + if script_id.is_empty() { return "".to_string(); } self.script_actors.borrow().get(&script_id).unwrap().to_string() @@ -111,8 +111,8 @@ impl ActorRegistry { pub fn actor_to_script(&self, actor: String) -> String { for (key, value) in self.script_actors.borrow().iter() { - println!("checking {}", value.as_slice()); - if value.as_slice() == actor.as_slice() { + println!("checking {}", value); + if *value == actor { return key.to_string(); } } diff --git a/components/devtools/actors/console.rs b/components/devtools/actors/console.rs index e7151b55068..1d753eb928e 100644 --- a/components/devtools/actors/console.rs +++ b/components/devtools/actors/console.rs @@ -121,13 +121,13 @@ impl Actor for ConsoleActor { msg_type: &String, msg: &json::Object, stream: &mut TcpStream) -> Result<bool, ()> { - Ok(match msg_type.as_slice() { + Ok(match &**msg_type { "getCachedMessages" => { let types = msg.get(&"messageTypes".to_string()).unwrap().as_array().unwrap(); let /*mut*/ messages = vec!(); for msg_type in types.iter() { let msg_type = msg_type.as_string().unwrap(); - match msg_type.as_slice() { + match &*msg_type { "ConsoleAPI" => { //TODO: figure out all consoleapi properties from FFOX source } diff --git a/components/devtools/actors/inspector.rs b/components/devtools/actors/inspector.rs index 8b8bfb41f97..23409910b62 100644 --- a/components/devtools/actors/inspector.rs +++ b/components/devtools/actors/inspector.rs @@ -69,7 +69,7 @@ impl Actor for HighlighterActor { msg_type: &String, _msg: &json::Object, stream: &mut TcpStream) -> Result<bool, ()> { - Ok(match msg_type.as_slice() { + Ok(match &**msg_type { "showBoxModel" => { let msg = ShowBoxModelReply { from: self.name(), @@ -106,12 +106,12 @@ impl Actor for NodeActor { msg_type: &String, msg: &json::Object, stream: &mut TcpStream) -> Result<bool, ()> { - Ok(match msg_type.as_slice() { + Ok(match &**msg_type { "modifyAttributes" => { let target = msg.get(&"to".to_string()).unwrap().as_string().unwrap(); let mods = msg.get(&"modifications".to_string()).unwrap().as_array().unwrap(); let modifications = mods.iter().map(|json_mod| { - json::decode(json_mod.to_string().as_slice()).unwrap() + json::decode(&json_mod.to_string()).unwrap() }).collect(); self.script_chan.send(ModifyAttribute(self.pipeline, @@ -280,7 +280,7 @@ impl Actor for WalkerActor { msg_type: &String, msg: &json::Object, stream: &mut TcpStream) -> Result<bool, ()> { - Ok(match msg_type.as_slice() { + Ok(match &**msg_type { "querySelector" => { let msg = QuerySelectorReply { from: self.name(), @@ -426,7 +426,7 @@ impl Actor for PageStyleActor { msg_type: &String, msg: &json::Object, stream: &mut TcpStream) -> Result<bool, ()> { - Ok(match msg_type.as_slice() { + Ok(match &**msg_type { "getApplied" => { //TODO: query script for relevant applied styles to node (msg.node) let msg = GetAppliedReply { @@ -498,7 +498,7 @@ impl Actor for InspectorActor { msg_type: &String, _msg: &json::Object, stream: &mut TcpStream) -> Result<bool, ()> { - Ok(match msg_type.as_slice() { + Ok(match &**msg_type { "getWalker" => { if self.walker.borrow().is_none() { let walker = WalkerActor { diff --git a/components/devtools/actors/root.rs b/components/devtools/actors/root.rs index 453b3dd8161..06343956c1f 100644 --- a/components/devtools/actors/root.rs +++ b/components/devtools/actors/root.rs @@ -55,7 +55,7 @@ impl Actor for RootActor { msg_type: &String, _msg: &json::Object, stream: &mut TcpStream) -> Result<bool, ()> { - Ok(match msg_type.as_slice() { + Ok(match &**msg_type { "listAddons" => { let actor = ErrorReply { from: "root".to_string(), @@ -72,7 +72,7 @@ impl Actor for RootActor { from: "root".to_string(), selected: 0, tabs: self.tabs.iter().map(|tab| { - registry.find::<TabActor>(tab.as_slice()).encodable() + registry.find::<TabActor>(tab).encodable() }).collect() }; stream.write_json_packet(&actor); diff --git a/components/devtools/actors/tab.rs b/components/devtools/actors/tab.rs index cee5b122905..b96d8cbfc57 100644 --- a/components/devtools/actors/tab.rs +++ b/components/devtools/actors/tab.rs @@ -80,7 +80,7 @@ impl Actor for TabActor { msg_type: &String, _msg: &json::Object, stream: &mut TcpStream) -> Result<bool, ()> { - Ok(match msg_type.as_slice() { + Ok(match &**msg_type { "reconfigure" => { stream.write_json_packet(&ReconfigureReply { from: self.name() }); true @@ -97,7 +97,7 @@ impl Actor for TabActor { javascriptEnabled: true, traits: TabTraits, }; - let console_actor = registry.find::<ConsoleActor>(self.console.as_slice()); + let console_actor = registry.find::<ConsoleActor>(&self.console); console_actor.streams.borrow_mut().push(stream.clone()); stream.write_json_packet(&msg); console_actor.script_chan.send( @@ -112,7 +112,7 @@ impl Actor for TabActor { from: self.name(), __type__: "detached".to_string(), }; - let console_actor = registry.find::<ConsoleActor>(self.console.as_slice()); + let console_actor = registry.find::<ConsoleActor>(&self.console); console_actor.streams.borrow_mut().pop(); stream.write_json_packet(&msg); console_actor.script_chan.send( diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs index 828f3b3bbab..4803d8ecad7 100644 --- a/components/devtools/lib.rs +++ b/components/devtools/lib.rs @@ -67,9 +67,12 @@ struct ConsoleAPICall { #[derive(RustcEncodable)] struct ConsoleMsg { - logLevel: u32, - timestamp: u64, - message: String, + level: String, + timeStamp: u64, + arguments: Vec<String>, + filename: String, + lineNumber: u32, + columnNumber: u32, } /// Spin up a devtools server that listens for connections on the specified port. @@ -84,7 +87,7 @@ pub fn start_server(port: u16) -> Sender<DevtoolsControlMsg> { static POLL_TIMEOUT: u64 = 300; fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) { - let listener = TcpListener::bind(format!("{}:{}", "127.0.0.1", port).as_slice()); + let listener = TcpListener::bind(&*format!("{}:{}", "127.0.0.1", port)); // bind the listener to the specified address let mut acceptor = listener.listen().unwrap(); @@ -190,16 +193,19 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) { actor_pipelines: &HashMap<PipelineId, String>) { let console_actor_name = find_console_actor(actors.clone(), id, actor_pipelines); let actors = actors.lock().unwrap(); - let console_actor = actors.find::<ConsoleActor>(console_actor_name.as_slice()); + let console_actor = actors.find::<ConsoleActor>(&console_actor_name); match console_message { - ConsoleMessage::LogMessage(message) => { + ConsoleMessage::LogMessage(message, filename, lineNumber, columnNumber) => { let msg = ConsoleAPICall { from: console_actor.name.clone(), __type__: "consoleAPICall".to_string(), message: ConsoleMsg { - logLevel: 0, - timestamp: precise_time_ns(), - message: message, + level: "log".to_string(), + timeStamp: precise_time_ns(), + arguments: vec!(message), + filename: filename, + lineNumber: lineNumber, + columnNumber: columnNumber, }, }; for stream in console_actor.streams.borrow_mut().iter_mut() { @@ -214,7 +220,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) { actor_pipelines: &HashMap<PipelineId, String>) -> String { let actors = actors.lock().unwrap(); let ref tab_actor_name = (*actor_pipelines)[id]; - let tab_actor = actors.find::<TabActor>(tab_actor_name.as_slice()); + let tab_actor = actors.find::<TabActor>(tab_actor_name); let console_actor_name = tab_actor.console.clone(); return console_actor_name; } diff --git a/components/devtools/protocol.rs b/components/devtools/protocol.rs index 07534df139b..6d978a054dd 100644 --- a/components/devtools/protocol.rs +++ b/components/devtools/protocol.rs @@ -20,9 +20,9 @@ impl JsonPacketStream for TcpStream { fn write_json_packet<'a, T: Encodable>(&mut self, obj: &T) { let s = json::encode(obj).unwrap().replace("__type__", "type"); println!("<- {}", s); - self.write_str(s.len().to_string().as_slice()).unwrap(); + self.write_str(&s.len().to_string()).unwrap(); self.write_u8(':' as u8).unwrap(); - self.write_str(s.as_slice()).unwrap(); + self.write_str(&s).unwrap(); } fn read_json_packet<'a>(&mut self) -> IoResult<Json> { @@ -35,11 +35,11 @@ impl JsonPacketStream for TcpStream { Ok(c) if c != colon => buffer.push(c as u8), Ok(_) => { let packet_len_str = String::from_utf8(buffer).unwrap(); - let packet_len = num::from_str_radix(packet_len_str.as_slice(), 10).unwrap(); + let packet_len = num::from_str_radix(&packet_len_str, 10).unwrap(); let packet_buf = self.read_exact(packet_len).unwrap(); let packet = String::from_utf8(packet_buf).unwrap(); println!("{}", packet); - return Ok(Json::from_str(packet.as_slice()).unwrap()) + return Ok(Json::from_str(&packet).unwrap()) }, Err(ref e) if e.kind == EndOfFile => return Err(IoError { kind: EndOfFile, desc: "EOF", detail: None }), diff --git a/components/devtools_traits/lib.rs b/components/devtools_traits/lib.rs index 9ea3772b665..63dbe74b6c1 100644 --- a/components/devtools_traits/lib.rs +++ b/components/devtools_traits/lib.rs @@ -122,6 +122,7 @@ impl Decodable for Modification { //TODO: Include options for Warn, Debug, Info, Error messages from Console #[derive(Clone)] pub enum ConsoleMessage { - LogMessage(String), + // Log: message, filename, line number, column number + LogMessage(String, String, u32, u32), //WarnMessage(String), } diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 37fb6b73340..398bd4d81b8 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -1079,7 +1079,7 @@ impl DisplayItem { paint_context.draw_linear_gradient(&gradient.base.bounds, &gradient.start_point, &gradient.end_point, - gradient.stops.as_slice()); + &gradient.stops); } DisplayItem::LineClass(ref line) => { diff --git a/components/gfx/font_template.rs b/components/gfx/font_template.rs index fee0bc69642..736c8dfad41 100644 --- a/components/gfx/font_template.rs +++ b/components/gfx/font_template.rs @@ -84,7 +84,7 @@ impl FontTemplate { } pub fn identifier<'a>(&'a self) -> &'a str { - self.identifier.as_slice() + &*self.identifier } /// Get the data for creating a font if it matches a given descriptor. diff --git a/components/gfx/lib.rs b/components/gfx/lib.rs index 2bd53bd699b..62f72722b9c 100644 --- a/components/gfx/lib.rs +++ b/components/gfx/lib.rs @@ -7,7 +7,7 @@ #![feature(collections)] #![feature(core)] #![feature(int_uint)] -#![cfg_attr(any(target_os="linux", target_os = "android"), feature(old_io))] +#![cfg_attr(any(target_os="linux", target_os = "android"), feature(io))] #![cfg_attr(any(target_os="linux", target_os = "android"), feature(old_path))] #![feature(plugin)] #![feature(rustc_private)] diff --git a/components/gfx/platform/freetype/font_list.rs b/components/gfx/platform/freetype/font_list.rs index 5b1d309b31e..3970efa92ec 100644 --- a/components/gfx/platform/freetype/font_list.rs +++ b/components/gfx/platform/freetype/font_list.rs @@ -36,7 +36,7 @@ pub fn get_available_families<F>(mut callback: F) where F: FnMut(String) { unsafe { let config = FcConfigGetCurrent(); let fontSet = FcConfigGetFonts(config, FcSetSystem); - for i in range(0, (*fontSet).nfont as int) { + for i in 0..((*fontSet).nfont as int) { let font = (*fontSet).fonts.offset(i); let mut family: *mut FcChar8 = ptr::null_mut(); let mut v: c_int = 0; @@ -74,7 +74,7 @@ pub fn get_variations_for_family<F>(family_name: &str, mut callback: F) debug!("found {} variations", (*matches).nfont); - for i in range(0, (*matches).nfont as int) { + for i in 0..((*matches).nfont as int) { let font = (*matches).fonts.offset(i); let mut file: *mut FcChar8 = ptr::null_mut(); let file = if FcPatternGetString(*font, FC_FILE.as_ptr() as *mut c_char, 0, &mut file) == FcResultMatch { diff --git a/components/gfx/platform/freetype/font_template.rs b/components/gfx/platform/freetype/font_template.rs index b41a5f0d7e6..176cd0f397b 100644 --- a/components/gfx/platform/freetype/font_template.rs +++ b/components/gfx/platform/freetype/font_template.rs @@ -3,8 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::borrow::ToOwned; -use std::old_io as io; -use std::old_io::File; +use std::fs::File; +use std::io::Read; /// Platform specific font representation for Linux. /// The identifier is an absolute path, and the bytes @@ -23,8 +23,10 @@ impl FontTemplateData { }, None => { // TODO: Handle file load failure! - let mut file = File::open_mode(&Path::new(identifier), io::Open, io::Read).unwrap(); - file.read_to_end().unwrap() + let mut file = File::open(identifier).unwrap(); + let mut buffer = vec![]; + file.read_to_end(&mut buffer).unwrap(); + buffer }, }; diff --git a/components/gfx/text/glyph.rs b/components/gfx/text/glyph.rs index 7341036e6d3..4ed96281a85 100644 --- a/components/gfx/text/glyph.rs +++ b/components/gfx/text/glyph.rs @@ -356,7 +356,7 @@ impl<'a> DetailedGlyphStore { detail_offset: 0, // unused }; - let i = self.detail_lookup.as_slice().binary_search_index(&key) + let i = (&*self.detail_lookup).binary_search_index(&key) .expect("Invalid index not found in detailed glyph lookup table!"); assert!(i + (count as uint) <= self.detail_buffer.len()); @@ -600,7 +600,7 @@ impl<'a> GlyphStore { data_for_glyphs[i].offset) }).collect(); - self.detail_store.add_detailed_glyphs_for_entry(i, glyphs_vec.as_slice()); + self.detail_store.add_detailed_glyphs_for_entry(i, &glyphs_vec); GlyphEntry::complex(first_glyph_data.cluster_start, first_glyph_data.ligature_start, glyph_count) diff --git a/components/gfx/text/shaping/harfbuzz.rs b/components/gfx/text/shaping/harfbuzz.rs index 5b12ba22b74..eb1a6cfb87c 100644 --- a/components/gfx/text/shaping/harfbuzz.rs +++ b/components/gfx/text/shaping/harfbuzz.rs @@ -306,7 +306,7 @@ impl Shaper { } debug!("(glyph idx) -> (text byte offset)"); - for i in range(0, glyph_data.len()) { + for i in 0..glyph_data.len() { // loc refers to a *byte* offset within the utf8 string. let loc = glyph_data.byte_offset_of_glyph(i); if loc < byte_max { @@ -481,7 +481,7 @@ impl Shaper { } // now add the detailed glyph entry. - glyphs.add_glyphs_for_char_index(char_idx, datas.as_slice()); + glyphs.add_glyphs_for_char_index(char_idx, &datas); // set the other chars, who have no glyphs let mut i = covered_byte_span.begin(); diff --git a/components/gfx/text/text_run.rs b/components/gfx/text/text_run.rs index 9c28462411e..eadcffcd733 100644 --- a/components/gfx/text/text_run.rs +++ b/components/gfx/text/text_run.rs @@ -186,7 +186,7 @@ impl<'a> Iterator for LineIterator<'a> { impl<'a> TextRun { pub fn new(font: &mut Font, text: String, options: &ShapingOptions) -> TextRun { - let glyphs = TextRun::break_and_shape(font, text.as_slice(), options); + let glyphs = TextRun::break_and_shape(font, &text, options); let run = TextRun { text: Arc::new(text), font_metrics: font.metrics.clone(), @@ -331,7 +331,7 @@ impl<'a> TextRun { /// Returns the index of the first glyph run containing the given character index. fn index_of_first_glyph_run_containing(&self, index: CharIndex) -> Option<uint> { - self.glyphs.as_slice().binary_search_index_by(&index, CharIndexComparator) + (&**self.glyphs).binary_search_index_by(&index, CharIndexComparator) } /// Returns an iterator that will iterate over all slices of glyphs that represent natural diff --git a/components/layout/block.rs b/components/layout/block.rs index 1f6b64a97d2..231f406d25a 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -25,7 +25,7 @@ //! //! http://dev.w3.org/csswg/css-sizing/ -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use context::LayoutContext; use css::node_style::StyledNode; diff --git a/components/layout/construct.rs b/components/layout/construct.rs index a30f3aee701..675f49a2be8 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -11,7 +11,7 @@ //! maybe it's an absolute or fixed position thing that hasn't found its containing block yet. //! Construction items bubble up the tree from children to parents until they find their homes. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use block::BlockFlow; use context::LayoutContext; diff --git a/components/layout/context.rs b/components/layout/context.rs index 7420a29fa9c..6c87ef63742 100644 --- a/components/layout/context.rs +++ b/components/layout/context.rs @@ -4,7 +4,7 @@ //! Data needed by the layout task. -#![allow(unsafe_blocks)] +#![allow(unsafe_code)] use css::matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache}; diff --git a/components/layout/css/matching.rs b/components/layout/css/matching.rs index 59e9a75b8d9..8d25f7007f5 100644 --- a/components/layout/css/matching.rs +++ b/components/layout/css/matching.rs @@ -4,7 +4,7 @@ //! High-level interface to CSS selector matching. -#![allow(unsafe_blocks)] +#![allow(unsafe_code)] use context::SharedLayoutContext; use css::node_style::StyledNode; diff --git a/components/layout/css/node_style.rs b/components/layout/css/node_style.rs index 946ac11a5e7..5b33d8d4c2d 100644 --- a/components/layout/css/node_style.rs +++ b/components/layout/css/node_style.rs @@ -23,7 +23,7 @@ pub trait StyledNode { impl<'ln> StyledNode for ThreadSafeLayoutNode<'ln> { #[inline] - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn style<'a>(&'a self) -> &'a Arc<ComputedValues> { unsafe { let layout_data_ref = self.borrow_layout_data(); diff --git a/components/layout/data.rs b/components/layout/data.rs index da24d662485..70ee8eb2c2e 100644 --- a/components/layout/data.rs +++ b/components/layout/data.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#![allow(unsafe_blocks)] +#![allow(unsafe_code)] use construct::{ConstructionItem, ConstructionResult}; use incremental::RestyleDamage; diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 30483b64f65..d4a2e7c7e38 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -8,7 +8,7 @@ //! list building, as the actual painting does not happen here—only deciding *what* we're going to //! paint. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use azure::azure_hl::Color; use block::BlockFlow; diff --git a/components/layout/flow.rs b/components/layout/flow.rs index a49b8a18db7..46b69e2deaa 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -58,7 +58,7 @@ use std::fmt; use std::iter::Zip; use std::num::FromPrimitive; use std::raw; -use std::sync::atomic::{AtomicUint, Ordering}; +use std::sync::atomic::{AtomicUsize, Ordering}; use std::slice::IterMut; use style::computed_values::{clear, empty_cells, float, position, text_align}; use style::properties::ComputedValues; @@ -310,7 +310,7 @@ pub trait Flow: fmt::Debug + Sync { } /// Returns a layer ID for the given fragment. - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn layer_id(&self, fragment_id: uint) -> LayerId { unsafe { let obj = mem::transmute::<&&Self, &raw::TraitObject>(&self); @@ -330,7 +330,7 @@ pub trait Flow: fmt::Debug + Sync { // Base access #[inline(always)] -#[allow(unsafe_blocks)] +#[allow(unsafe_code)] pub fn base<'a, T: ?Sized + Flow>(this: &'a T) -> &'a BaseFlow { unsafe { let obj = mem::transmute::<&&'a T, &'a raw::TraitObject>(&this); @@ -344,7 +344,7 @@ pub fn imm_child_iter<'a>(flow: &'a Flow) -> FlowListIterator<'a> { } #[inline(always)] -#[allow(unsafe_blocks)] +#[allow(unsafe_code)] pub fn mut_base<'a, T: ?Sized + Flow>(this: &'a mut T) -> &'a mut BaseFlow { unsafe { let obj = mem::transmute::<&&'a mut T, &'a raw::TraitObject>(&this); @@ -740,9 +740,9 @@ pub struct BaseFlow { /// NB: Must be the first element. /// /// The necessity of this will disappear once we have dynamically-sized types. - strong_ref_count: AtomicUint, + strong_ref_count: AtomicUsize, - weak_ref_count: AtomicUint, + weak_ref_count: AtomicUsize, pub restyle_damage: RestyleDamage, @@ -832,7 +832,9 @@ pub struct BaseFlow { pub flags: FlowFlags, } +#[allow(unsafe_code)] unsafe impl Send for BaseFlow {} +#[allow(unsafe_code)] unsafe impl Sync for BaseFlow {} impl fmt::Debug for BaseFlow { @@ -951,8 +953,8 @@ impl BaseFlow { damage.remove(RECONSTRUCT_FLOW); BaseFlow { - strong_ref_count: AtomicUint::new(1), - weak_ref_count: AtomicUint::new(1), + strong_ref_count: AtomicUsize::new(1), + weak_ref_count: AtomicUsize::new(1), restyle_damage: damage, children: FlowList::new(), intrinsic_inline_sizes: IntrinsicISizes::new(), @@ -982,11 +984,13 @@ impl BaseFlow { self.children.iter_mut() } - pub unsafe fn strong_ref_count<'a>(&'a self) -> &'a AtomicUint { + #[allow(unsafe_code)] + pub unsafe fn strong_ref_count<'a>(&'a self) -> &'a AtomicUsize { &self.strong_ref_count } - pub unsafe fn weak_ref_count<'a>(&'a self) -> &'a AtomicUint { + #[allow(unsafe_code)] + pub unsafe fn weak_ref_count<'a>(&'a self) -> &'a AtomicUsize { &self.weak_ref_count } @@ -1355,6 +1359,7 @@ impl ContainingBlockLink { self.link = Some(link.downgrade()) } + #[allow(unsafe_code)] pub unsafe fn get<'a>(&'a mut self) -> &'a mut Option<WeakFlowRef> { &mut self.link } diff --git a/components/layout/flow_list.rs b/components/layout/flow_list.rs index bd72d7a62ae..20c69b6081c 100644 --- a/components/layout/flow_list.rs +++ b/components/layout/flow_list.rs @@ -31,6 +31,7 @@ impl FlowList { /// Provide a mutable reference to the front element, or None if the list is empty #[inline] + #[allow(unsafe_code)] pub unsafe fn front_mut<'a>(&'a mut self) -> Option<&'a mut Flow> { self.flows.front_mut().map(|head| &mut **head) } @@ -43,6 +44,7 @@ impl FlowList { /// Provide a mutable reference to the back element, or None if the list is empty #[inline] + #[allow(unsafe_code)] pub unsafe fn back_mut<'a>(&'a mut self) -> Option<&'a mut Flow> { self.flows.back_mut().map(|tail| &mut **tail) } diff --git a/components/layout/flow_ref.rs b/components/layout/flow_ref.rs index e7b23aac698..9a8e2bb580e 100644 --- a/components/layout/flow_ref.rs +++ b/components/layout/flow_ref.rs @@ -8,7 +8,7 @@ //! be superfluous. This design is largely duplicating logic of Arc<T> and //! Weak<T>; please see comments there for details. -#![allow(unsafe_blocks)] +#![allow(unsafe_code)] use flow::Flow; use flow; @@ -102,9 +102,7 @@ impl Drop for FlowRef { let object_align = vtable[2]; let fake_data = heap::allocate(object_size, object_align); - ptr::copy_memory(fake_data, - flow_ref.object.data as *const u8, - object_size); + ptr::copy(fake_data, flow_ref.object.data as *const u8, object_size); let fake_box = raw::TraitObject { vtable: flow_ref.object.vtable, data: fake_data as *mut () }; let fake_flow = mem::transmute::<raw::TraitObject, Box<Flow>>(fake_box); diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index d39d0c4f74d..5b2c3d83a62 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -4,7 +4,7 @@ //! The `Fragment` type, which represents the leaves of the layout tree. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use canvas::canvas_paint_task::CanvasMsg; use css::node_style::StyledNode; @@ -118,7 +118,9 @@ pub struct Fragment { pub debug_id: u16, } +#[allow(unsafe_code)] unsafe impl Send for Fragment {} +#[allow(unsafe_code)] unsafe impl Sync for Fragment {} impl Encodable for Fragment { diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 3c0c0ccd0fe..0b645aa0971 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use css::node_style::StyledNode; use context::LayoutContext; diff --git a/components/layout/layout_debug.rs b/components/layout/layout_debug.rs index ed73a1c693e..79bd12ce8a5 100644 --- a/components/layout/layout_debug.rs +++ b/components/layout/layout_debug.rs @@ -6,6 +6,7 @@ //! that can be viewed by an external tool to make layout debugging easier. #![macro_use] +#![allow(unsafe_code)] // thread_local!() defines an unsafe function on Android use flow_ref::FlowRef; use flow; @@ -13,7 +14,8 @@ use rustc_serialize::json; use std::borrow::ToOwned; use std::cell::RefCell; -use std::old_io::File; +use std::io::Write; +use std::fs::File; use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT}; thread_local!(static STATE_KEY: RefCell<Option<State>> = RefCell::new(None)); @@ -95,7 +97,6 @@ impl Drop for Scope { /// Generate a unique ID. This is used for items such as Fragment /// which are often reallocated but represent essentially the /// same data. -#[allow(unsafe_blocks)] pub fn generate_unique_debug_id() -> u16 { unsafe { DEBUG_ID_COUNTER.fetch_add(1, Ordering::SeqCst) as u16 } } @@ -127,5 +128,5 @@ pub fn end_trace() { let result = json::encode(&root_scope).unwrap(); let path = Path::new("layout_trace.json"); let mut file = File::create(&path).unwrap(); - file.write_str(result.as_slice()).unwrap(); + file.write_all(result.as_bytes()).unwrap(); } diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index fa670ca1191..4df269e725a 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -5,7 +5,7 @@ //! The layout task. Performs layout on the DOM, builds display lists and sends them to be //! painted. -#![allow(unsafe_blocks)] +#![allow(unsafe_code)] use construct::ConstructionResult; use context::{SharedLayoutContext, SharedLayoutContextWrapper}; diff --git a/components/layout/lib.rs b/components/layout/lib.rs index 45322b6edf4..2ff8502f7f1 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -6,10 +6,9 @@ #![feature(box_syntax)] #![feature(collections)] #![feature(core)] -#![feature(hash)] #![feature(int_uint)] #![feature(io)] -#![feature(path)] +#![feature(old_path)] #![feature(plugin)] #![feature(rustc_private)] #![feature(std_misc)] @@ -18,7 +17,7 @@ #![feature(unsafe_destructor)] #![feature(unsafe_no_drop_flag)] -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] #![allow(unrooted_must_root)] #![plugin(string_cache_plugin)] diff --git a/components/layout/list_item.rs b/components/layout/list_item.rs index e7c90257ccd..cb78f44399e 100644 --- a/components/layout/list_item.rs +++ b/components/layout/list_item.rs @@ -5,7 +5,7 @@ //! Layout for elements with a CSS `display` property of `list-item`. These elements consist of a //! block and an extra inline fragment for the marker. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use block::BlockFlow; use context::LayoutContext; diff --git a/components/layout/model.rs b/components/layout/model.rs index 571a45a199e..64ba9a001d8 100644 --- a/components/layout/model.rs +++ b/components/layout/model.rs @@ -4,7 +4,7 @@ //! Borders, padding, and margins. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use fragment::Fragment; diff --git a/components/layout/opaque_node.rs b/components/layout/opaque_node.rs index e40538251de..666d3a9eb11 100644 --- a/components/layout/opaque_node.rs +++ b/components/layout/opaque_node.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#![allow(unsafe_blocks)] +#![allow(unsafe_code)] use gfx::display_list::OpaqueNode; use libc::{c_void, uintptr_t}; diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs index ee2ca416cd1..5562db5e10d 100644 --- a/components/layout/parallel.rs +++ b/components/layout/parallel.rs @@ -6,7 +6,7 @@ //! //! This code is highly unsafe. Keep this file small and easy to audit. -#![allow(unsafe_blocks)] +#![allow(unsafe_code)] use context::{LayoutContext, SharedLayoutContextWrapper, SharedLayoutContext}; use flow::{Flow, MutableFlowUtils, PreorderFlowTraversal, PostorderFlowTraversal}; @@ -25,7 +25,7 @@ use util::time::{TimeProfilerCategory, ProfilerMetadata, TimeProfilerChan, profi use util::workqueue::{WorkQueue, WorkUnit, WorkerProxy}; use std::mem; use std::ptr; -use std::sync::atomic::{AtomicInt, Ordering}; +use std::sync::atomic::{AtomicIsize, Ordering}; #[allow(dead_code)] fn static_assertion(node: UnsafeLayoutNode) { @@ -68,13 +68,13 @@ pub fn mut_borrowed_flow_to_unsafe_flow(flow: &mut Flow) -> UnsafeFlow { /// Information that we need stored in each DOM node. pub struct DomParallelInfo { /// The number of children that still need work done. - pub children_count: AtomicInt, + pub children_count: AtomicIsize, } impl DomParallelInfo { pub fn new() -> DomParallelInfo { DomParallelInfo { - children_count: AtomicInt::new(0), + children_count: AtomicIsize::new(0), } } } @@ -187,7 +187,7 @@ trait ParallelPostorderDomTraversal : PostorderDomTraversal { /// Information that we need stored in each flow. pub struct FlowParallelInfo { /// The number of children that still need work done. - pub children_count: AtomicInt, + pub children_count: AtomicIsize, /// The address of the parent flow. pub parent: UnsafeFlow, } @@ -195,7 +195,7 @@ pub struct FlowParallelInfo { impl FlowParallelInfo { pub fn new() -> FlowParallelInfo { FlowParallelInfo { - children_count: AtomicInt::new(0), + children_count: AtomicIsize::new(0), parent: null_unsafe_flow(), } } diff --git a/components/layout/table.rs b/components/layout/table.rs index 0c1e0c259ef..85bab65e036 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use block::{self, BlockFlow, CandidateBSizeIterator, ISizeAndMarginsComputer}; use block::{ISizeConstraintInput, ISizeConstraintSolution}; diff --git a/components/layout/table_caption.rs b/components/layout/table_caption.rs index b0b08e7cdec..06617e8c198 100644 --- a/components/layout/table_caption.rs +++ b/components/layout/table_caption.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use block::BlockFlow; use context::LayoutContext; diff --git a/components/layout/table_cell.rs b/components/layout/table_cell.rs index 5ab285aa00e..1de720b2516 100644 --- a/components/layout/table_cell.rs +++ b/components/layout/table_cell.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use block::{BlockFlow, ISizeAndMarginsComputer, MarginsMayCollapseFlag}; use context::LayoutContext; diff --git a/components/layout/table_colgroup.rs b/components/layout/table_colgroup.rs index 61008cd2506..edb6d64bd0f 100644 --- a/components/layout/table_colgroup.rs +++ b/components/layout/table_colgroup.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use context::LayoutContext; use css::node_style::StyledNode; diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 44ac99420dc..5d05a5fd5b5 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use block::BlockFlow; use block::ISizeAndMarginsComputer; diff --git a/components/layout/table_rowgroup.rs b/components/layout/table_rowgroup.rs index 173310de6e2..64f39412a33 100644 --- a/components/layout/table_rowgroup.rs +++ b/components/layout/table_rowgroup.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use block::{BlockFlow, ISizeAndMarginsComputer}; use context::LayoutContext; diff --git a/components/layout/table_wrapper.rs b/components/layout/table_wrapper.rs index 84524285d2b..a291224944e 100644 --- a/components/layout/table_wrapper.rs +++ b/components/layout/table_wrapper.rs @@ -11,7 +11,7 @@ //! //! Hereafter this document is referred to as INTRINSIC. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use block::{BlockFlow, BlockNonReplaced, FloatNonReplaced, ISizeAndMarginsComputer}; use block::{MarginsMayCollapseFlag}; diff --git a/components/layout/text.rs b/components/layout/text.rs index 9ac4d9b1174..66a7597c891 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -4,7 +4,7 @@ //! Text layout. -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] use fragment::{Fragment, SpecificFragmentInfo, ScannedTextFragmentInfo}; use inline::InlineFragments; diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index 228fdd6e7f0..a206bf75b4a 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -4,7 +4,7 @@ //! Traversals over the DOM and flow trees, running the layout computations. -#![allow(unsafe_blocks)] +#![allow(unsafe_code)] use css::node_style::StyledNode; use css::matching::{ApplicableDeclarations, MatchMethods, StyleSharingResult}; diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index ce42907f119..101249b4747 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -30,7 +30,7 @@ //! o Instead of `html_element_in_html_document()`, use //! `html_element_in_html_document_for_layout()`. -#![allow(unsafe_blocks)] +#![allow(unsafe_code)] use canvas::canvas_paint_task::CanvasMsg; use context::SharedLayoutContext; diff --git a/components/net/cookie.rs b/components/net/cookie.rs index dfca6912c94..a6390bf35c6 100644 --- a/components/net/cookie.rs +++ b/components/net/cookie.rs @@ -54,7 +54,7 @@ impl Cookie { // Step 6 let host_only = if !domain.is_empty() { - if !Cookie::domain_match(url_host.as_slice(), domain.as_slice()) { + if !Cookie::domain_match(&url_host, &domain) { return None; } else { cookie.domain = Some(domain); @@ -69,7 +69,7 @@ impl Cookie { let mut path = cookie.path.unwrap_or("".to_owned()); if path.is_empty() || path.char_at(0) != '/' { let url_path = request.serialize_path(); - let url_path = url_path.as_ref().map(|path| path.as_slice()); + let url_path = url_path.as_ref().map(|path| &**path); path = Cookie::default_path(url_path.unwrap_or("")); } cookie.path = Some(path); @@ -136,14 +136,14 @@ impl Cookie { } } else { if let (Some(ref domain), &Some(ref cookie_domain)) = (domain, &self.cookie.domain) { - if !Cookie::domain_match(domain.as_slice(), cookie_domain.as_slice()) { + if !Cookie::domain_match(domain, cookie_domain) { return false; } } } if let (Some(ref path), &Some(ref cookie_path)) = (url.serialize_path(), &self.cookie.path) { - if !Cookie::path_match(path.as_slice(), cookie_path.as_slice()) { + if !Cookie::path_match(path, cookie_path) { return false; } } @@ -177,12 +177,12 @@ fn test_domain_match() { #[test] fn test_default_path() { - assert!(Cookie::default_path("/foo/bar/baz/").as_slice() == "/foo/bar/baz"); - assert!(Cookie::default_path("/foo/").as_slice() == "/foo"); - assert!(Cookie::default_path("/foo").as_slice() == "/"); - assert!(Cookie::default_path("/").as_slice() == "/"); - assert!(Cookie::default_path("").as_slice() == "/"); - assert!(Cookie::default_path("foo").as_slice() == "/"); + assert!(&*Cookie::default_path("/foo/bar/baz/") == "/foo/bar/baz"); + assert!(&*Cookie::default_path("/foo/") == "/foo"); + assert!(&*Cookie::default_path("/foo") == "/"); + assert!(&*Cookie::default_path("/") == "/"); + assert!(&*Cookie::default_path("") == "/"); + assert!(&*Cookie::default_path("foo") == "/"); } #[test] @@ -201,7 +201,7 @@ fn fn_cookie_constructor() { let cookie = cookie_rs::Cookie::parse(" baz = bar; Domain = ").unwrap(); assert!(Cookie::new_wrapped(cookie.clone(), url, CookieSource::HTTP).is_some()); let cookie = Cookie::new_wrapped(cookie, url, CookieSource::HTTP).unwrap(); - assert!(cookie.cookie.domain.as_ref().unwrap().as_slice() == "example.com"); + assert!(&**cookie.cookie.domain.as_ref().unwrap() == "example.com"); // cookie public domains test let cookie = cookie_rs::Cookie::parse(" baz = bar; Domain = gov.ac").unwrap(); diff --git a/components/net/cookie_storage.rs b/components/net/cookie_storage.rs index 0f3cf180aac..88c88f1a773 100644 --- a/components/net/cookie_storage.rs +++ b/components/net/cookie_storage.rs @@ -112,7 +112,7 @@ impl CookieStorage { (match acc.len() { 0 => acc, _ => acc + ";" - }) + c.cookie.name.as_slice() + "=" + c.cookie.value.as_slice() + }) + &c.cookie.name + "=" + &c.cookie.value }; let result = url_cookies.iter_mut().fold("".to_string(), reducer); diff --git a/components/net/data_loader.rs b/components/net/data_loader.rs index d430e3e4eb4..2b75d238053 100644 --- a/components/net/data_loader.rs +++ b/components/net/data_loader.rs @@ -22,7 +22,7 @@ pub fn factory(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) { fn load(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) { let url = load_data.url; - assert!("data" == url.scheme.as_slice()); + assert!(&*url.scheme == "data"); let mut metadata = Metadata::default(url.clone()); @@ -39,11 +39,11 @@ fn load(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) { match url.query { Some(query) => { scheme_data.push_str("?"); - scheme_data.push_str(query.as_slice()); + scheme_data.push_str(&query); }, None => () } - let parts: Vec<&str> = scheme_data.as_slice().splitn(1, ',').collect(); + let parts: Vec<&str> = scheme_data.splitn(1, ',').collect(); if parts.len() != 2 { start_sending(senders, metadata).send(Done(Err("invalid data uri".to_string()))).unwrap(); return; @@ -70,7 +70,7 @@ fn load(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) { // FIXME(#2909): It’s unclear what to do with non-alphabet characters, // but Acid 3 apparently depends on spaces being ignored. let bytes = bytes.into_iter().filter(|&b| b != ' ' as u8).collect::<Vec<u8>>(); - match bytes.as_slice().from_base64() { + match bytes.from_base64() { Err(..) => { progress_chan.send(Done(Err("non-base64 data uri".to_string()))).unwrap(); } diff --git a/components/net/fetch/cors_cache.rs b/components/net/fetch/cors_cache.rs index e3b79b48c24..5a36026fdc3 100644 --- a/components/net/fetch/cors_cache.rs +++ b/components/net/fetch/cors_cache.rs @@ -28,7 +28,7 @@ pub enum HeaderOrMethod { impl HeaderOrMethod { fn match_header(&self, header_name: &str) -> bool { match *self { - HeaderOrMethod::HeaderData(ref s) => s.as_slice().eq_ignore_ascii_case(header_name), + HeaderOrMethod::HeaderData(ref s) => s.eq_ignore_ascii_case(header_name), _ => false } } @@ -294,10 +294,10 @@ impl CORSCacheTask { tx.send(()); }, CORSCacheTaskMsg::MatchHeader(request, header, tx) => { - tx.send(self.cache.match_header(request, header.as_slice())); + tx.send(self.cache.match_header(request, &header)); }, CORSCacheTaskMsg::MatchHeaderUpdate(request, header, new_max_age, tx) => { - tx.send(self.cache.match_header_and_update(request, header.as_slice(), new_max_age)); + tx.send(self.cache.match_header_and_update(request, &header, new_max_age)); }, CORSCacheTaskMsg::MatchMethod(request, method, tx) => { tx.send(self.cache.match_method(request, method)); diff --git a/components/net/fetch/request.rs b/components/net/fetch/request.rs index 7134b054e98..e7bb5914aaa 100644 --- a/components/net/fetch/request.rs +++ b/components/net/fetch/request.rs @@ -119,9 +119,9 @@ impl Request { /// [Basic fetch](http://fetch.spec.whatwg.org#basic-fetch) pub fn basic_fetch(&mut self) -> Response { - match self.url.scheme.as_slice() { + match &*self.url.scheme { "about" => match self.url.non_relative_scheme_data() { - Some(s) if s.as_slice() == "blank" => { + Some(s) if &*s == "blank" => { let mut response = Response::new(); response.headers.set(ContentType(Mime( TopLevel::Text, SubLevel::Html, diff --git a/components/net/fetch/response.rs b/components/net/fetch/response.rs index 7380f3e7ad6..1db7dce330c 100644 --- a/components/net/fetch/response.rs +++ b/components/net/fetch/response.rs @@ -110,7 +110,7 @@ impl Response { ResponseType::Default | ResponseType::Error => unreachable!(), ResponseType::Basic => { let headers = old_headers.iter().filter(|header| { - match header.name().to_ascii_lowercase().as_slice() { + match &*header.name().to_ascii_lowercase() { "set-cookie" | "set-cookie2" => false, _ => true } @@ -120,7 +120,7 @@ impl Response { }, ResponseType::CORS => { let headers = old_headers.iter().filter(|header| { - match header.name().to_ascii_lowercase().as_slice() { + match &*header.name().to_ascii_lowercase() { "cache-control" | "content-language" | "content-type" | "expires" | "last-modified" | "Pragma" => false, // XXXManishearth handle Access-Control-Expose-Headers diff --git a/components/net/file_loader.rs b/components/net/file_loader.rs index 72f222a2c4a..2ee1b3b076d 100644 --- a/components/net/file_loader.rs +++ b/components/net/file_loader.rs @@ -34,7 +34,7 @@ fn read_all(reader: &mut io::Stream, progress_chan: &Sender<ProgressMsg>) pub fn factory(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) { let url = load_data.url; - assert!("file" == url.scheme.as_slice()); + assert!(&*url.scheme == "file"); let senders = ResponseSenders { immediate_consumer: start_chan, eventual_consumer: load_data.consumer, diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index ccaf8d318e8..e1f0c1c69f3 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -64,20 +64,20 @@ fn load(mut load_data: LoadData, start_chan: Sender<TargetedLoadResponse>, cooki // real URL that should be used for which the source is to be viewed. // Change our existing URL to that and keep note that we are viewing // the source rather than rendering the contents of the URL. - let viewing_source = if url.scheme == "view-source" { - let inner_url = load_data.url.non_relative_scheme_data().unwrap(); - url = Url::parse(inner_url).unwrap(); - match url.scheme.as_slice() { - "http" | "https" => {} - _ => { - let s = format!("The {} scheme with view-source is not supported", url.scheme); - send_error(url, s, senders); - return; - } - }; - true + let viewing_source = if &*url.scheme == "view-source" { + let inner_url = load_data.url.non_relative_scheme_data().unwrap(); + url = Url::parse(inner_url).unwrap(); + match &*url.scheme { + "http" | "https" => {} + _ => { + let s = format!("The {} scheme with view-source is not supported", url.scheme); + send_error(url, s, senders); + return; + } + }; + true } else { - false + false }; // Loop to handle redirects. @@ -89,7 +89,7 @@ fn load(mut load_data: LoadData, start_chan: Sender<TargetedLoadResponse>, cooki return; } - match url.scheme.as_slice() { + match &*url.scheme { "http" | "https" => {} _ => { let s = format!("{} request, but we don't support that scheme", url.scheme); @@ -252,7 +252,7 @@ reason: \"certificate verify failed\" }]"; } _ => {} } - let new_url = match UrlParser::new().base_url(&url).parse(new_url.as_slice()) { + let new_url = match UrlParser::new().base_url(&url).parse(&new_url) { Ok(u) => u, Err(e) => { send_error(url, e.to_string(), senders); diff --git a/components/net/image_cache_task.rs b/components/net/image_cache_task.rs index 16d390bf6d1..ecb6b4ae396 100644 --- a/components/net/image_cache_task.rs +++ b/components/net/image_cache_task.rs @@ -316,7 +316,7 @@ impl ImageCache { debug!("image_cache_task: started image decode for {}", url.serialize()); let image = profile(time::TimeProfilerCategory::ImageDecoding, None, time_profiler_chan, || { - load_from_memory(data.as_slice()) + load_from_memory(&data) }); let image = image.map(|image| Arc::new(box image)); @@ -456,7 +456,7 @@ fn load_image_data(url: Url, resource_task: ResourceTask) -> Result<Vec<u8>, ()> loop { match progress_port.recv().unwrap() { Payload(data) => { - image_data.push_all(data.as_slice()); + image_data.push_all(&data); } Done(Ok(..)) => { return Ok(image_data); diff --git a/components/net/lib.rs b/components/net/lib.rs index 2387583b76e..7137b410af7 100644 --- a/components/net/lib.rs +++ b/components/net/lib.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#![feature(alloc)] #![feature(box_syntax)] #![feature(collections)] #![feature(core)] diff --git a/components/net/resource_task.rs b/components/net/resource_task.rs index 688c507c06f..27df208bd6d 100644 --- a/components/net/resource_task.rs +++ b/components/net/resource_task.rs @@ -23,10 +23,11 @@ use hyper::mime::{Mime, Attr}; use url::Url; use std::borrow::{ToOwned, IntoCow}; +use std::boxed; use std::collections::HashMap; use std::env; -use std::mem; -use std::old_io::{BufferedReader, File}; +use std::fs::File; +use std::io::{BufReader, Read}; use std::sync::mpsc::{channel, Receiver, Sender}; use std::thunk::Invoke; @@ -38,16 +39,26 @@ use std::old_io::net::tcp::TcpListener; static mut HOST_TABLE: Option<*mut HashMap<String, String>> = None; pub fn global_init() { - if let Ok(host_file_path) = env::var("HOST_FILE") { - //TODO: handle bad file path - let path = Path::new(host_file_path); - let mut file = BufferedReader::new(File::open(&path)); - if let Ok(lines) = file.read_to_string(){ - unsafe { - let host_table: *mut HashMap<String, String> = mem::transmute(parse_hostsfile(lines.as_slice())); - HOST_TABLE = Some(host_table); - } - } + //TODO: handle bad file path + let path = match env::var("HOST_FILE") { + Ok(host_file_path) => Path::new(host_file_path), + Err(_) => return, + }; + + let mut file = match File::open(&path) { + Ok(f) => BufReader::new(f), + Err(_) => return, + }; + + let mut lines = String::new(); + match file.read_to_string(&mut lines) { + Ok(()) => (), + Err(_) => return, + }; + + unsafe { + let host_table = boxed::into_raw(parse_hostsfile(&lines)); + HOST_TABLE = Some(host_table); } } @@ -207,7 +218,7 @@ pub fn load_whole_resource(resource_task: &ResourceTask, url: Url) let mut buf = vec!(); loop { match response.progress_port.recv().unwrap() { - ProgressMsg::Payload(data) => buf.push_all(data.as_slice()), + ProgressMsg::Payload(data) => buf.push_all(&data), ProgressMsg::Done(Ok(())) => return Ok((response.metadata, buf)), ProgressMsg::Done(Err(e)) => return Err(e) } @@ -292,7 +303,7 @@ impl ResourceManager { self.load(load_data) } ControlMsg::SetCookiesForUrl(request, cookie_list, source) => { - let header = Header::parse_header([cookie_list.into_bytes()].as_slice()); + let header = Header::parse_header(&[cookie_list.into_bytes()]); if let Some(SetCookie(cookies)) = header { for bare_cookie in cookies.into_iter() { if let Some(cookie) = cookie::Cookie::new_wrapped(bare_cookie, &request, source) { @@ -331,7 +342,7 @@ impl ResourceManager { } } - let loader = match load_data.url.scheme.as_slice() { + let loader = match &*load_data.url.scheme { "file" => from_factory(file_loader::factory), "http" | "https" | "view-source" => http_loader::factory(self.resource_task.clone()), "data" => from_factory(data_loader::factory), @@ -526,7 +537,9 @@ fn test_replace_hosts() { host_table_box.insert("foo.bar.com".to_owned(), "127.0.0.1".to_owned()); host_table_box.insert("servo.test.server".to_owned(), "127.0.0.2".to_owned()); - let host_table: *mut HashMap<String, String> = unsafe {mem::transmute(host_table_box)}; + let host_table: *mut HashMap<String, String> = unsafe { + boxed::into_raw(host_table_box) + }; //Start the TCP server let mut listener = TcpListener::bind("127.0.0.1:0").unwrap(); @@ -536,9 +549,7 @@ fn test_replace_hosts() { //Start the resource task and make a request to our TCP server let resource_task = new_resource_task(None); let (start_chan, _) = channel(); - let mut raw_url: String = "http://foo.bar.com:".to_string(); - raw_url = raw_url + port.to_string().as_slice(); - let url = Url::parse(raw_url.as_slice()).unwrap(); + let url = Url::parse(&format!("http://foo.bar.com:{}", port)).unwrap(); resource_task.send(ControlMsg::Load(replace_hosts(LoadData::new(url, start_chan), host_table))); match acceptor.accept() { diff --git a/components/net/storage_task.rs b/components/net/storage_task.rs index 5f15025b77b..658340b8bf3 100644 --- a/components/net/storage_task.rs +++ b/components/net/storage_task.rs @@ -141,7 +141,7 @@ impl StorageManager { } let updated = data.get_mut(&origin).map(|entry| { - if entry.get(&origin).map_or(true, |item| item.as_slice() != value.as_slice()) { + if entry.get(&origin).map_or(true, |item| *item != value) { entry.insert(name.clone(), value.clone()); true } else { @@ -182,12 +182,12 @@ impl StorageManager { fn get_origin_as_string(&self, url: Url) -> String { let mut origin = "".to_string(); - origin.push_str(url.scheme.as_slice()); + origin.push_str(&url.scheme); origin.push_str("://"); - url.domain().map(|domain| origin.push_str(domain.as_slice())); + url.domain().map(|domain| origin.push_str(&domain)); url.port().map(|port| { origin.push_str(":"); - origin.push_str(port.to_string().as_slice()); + origin.push_str(&port.to_string()); }); origin.push_str("/"); origin diff --git a/components/plugins/lints/privatize.rs b/components/plugins/lints/privatize.rs index 475338dee07..91ecf15d9da 100644 --- a/components/plugins/lints/privatize.rs +++ b/components/plugins/lints/privatize.rs @@ -27,7 +27,7 @@ impl LintPass for PrivatizePass { match field.node { ast::StructField_ { kind: ast::NamedField(ident, visibility), .. } if visibility == Public => { cx.span_lint(PRIVATIZE, field.span, - format!("Field {} is public where only private fields are allowed", ident.name).as_slice()); + &format!("Field {} is public where only private fields are allowed", ident.name)); } _ => {} } diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 53972dc6ab8..f201c768187 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -246,6 +246,7 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> { } } +#[allow(unsafe_code)] pub trait AttrHelpersForLayout { unsafe fn value_ref_forever(&self) -> &'static str; unsafe fn value_atom_forever(&self) -> Option<Atom>; @@ -253,6 +254,7 @@ pub trait AttrHelpersForLayout { unsafe fn local_name_atom_forever(&self) -> Atom; } +#[allow(unsafe_code)] impl AttrHelpersForLayout for Attr { #[inline] unsafe fn value_ref_forever(&self) -> &'static str { diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index 24bdc815509..1d3936f21bb 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -99,7 +99,7 @@ impl CallbackInterface { -> Result<JSVal, ()> { let mut callable = UndefinedValue(); unsafe { - let name = CString::from_slice(name.as_bytes()); + let name = CString::new(name).unwrap(); if JS_GetProperty(cx, self.callback(), name.as_ptr(), &mut callable) == 0 { return Err(()); } diff --git a/components/script/dom/bindings/cell.rs b/components/script/dom/bindings/cell.rs index 18ea62d7106..f2a1504f8b9 100644 --- a/components/script/dom/bindings/cell.rs +++ b/components/script/dom/bindings/cell.rs @@ -27,6 +27,7 @@ impl<T> DOMRefCell<T> { /// Return a reference to the contents. /// /// For use in the layout task only. + #[allow(unsafe_code)] pub unsafe fn borrow_for_layout<'a>(&'a self) -> &'a T { debug_assert!(task_state::get().is_layout()); &*self.value.as_unsafe_cell().get() @@ -36,6 +37,7 @@ impl<T> DOMRefCell<T> { /// /// This succeeds even if the object is mutably borrowed, /// so you have to be careful in trace code! + #[allow(unsafe_code)] pub unsafe fn borrow_for_gc_trace<'a>(&'a self) -> &'a T { debug_assert!(task_state::get().contains(SCRIPT | IN_GC)); &*self.value.as_unsafe_cell().get() @@ -43,6 +45,7 @@ impl<T> DOMRefCell<T> { /// Borrow the contents for the purpose of script deallocation. /// + #[allow(unsafe_code)] pub unsafe fn borrow_for_script_deallocation<'a>(&'a self) -> &'a mut T { debug_assert!(task_state::get().contains(SCRIPT)); &mut *self.value.as_unsafe_cell().get() diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 583a0233c7f..92b05cb5780 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -4061,7 +4061,12 @@ let this: *const %s = native_from_reflector::<%s>(obj); assert(False) def finalizeHook(descriptor, hookName, context): - release = """\ + release = "" + if descriptor.isGlobal(): + release += """\ +finalize_global(obj); +""" + release += """\ let _ = Box::from_raw(this as *mut %s); debug!("%s finalize: {:p}", this);\ """ % (descriptor.concreteType, descriptor.concreteType) @@ -4650,6 +4655,7 @@ class CGBindingRoot(CGThing): 'dom::bindings::utils::{DOMJSClass, JSCLASS_DOM_GLOBAL}', 'dom::bindings::utils::{find_enum_string_index, get_array_index_from_id}', 'dom::bindings::utils::{get_property_on_prototype, get_proto_or_iface_array}', + 'dom::bindings::utils::finalize_global', 'dom::bindings::utils::has_property_on_prototype', 'dom::bindings::utils::is_platform_object', 'dom::bindings::utils::{Reflectable}', diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs index 275c498c038..c62216d4683 100644 --- a/components/script/dom/bindings/error.rs +++ b/components/script/dom/bindings/error.rs @@ -122,7 +122,7 @@ pub fn report_pending_exception(cx: *mut JSContext, obj: *mut JSObject) { pub fn throw_not_in_union(cx: *mut JSContext, names: &'static str) -> JSBool { assert!(unsafe { JS_IsExceptionPending(cx) } == 0); let message = format!("argument could not be converted to any of: {}", names); - let string = CString::from_slice(message.as_bytes()); + let string = CString::new(message).unwrap(); unsafe { ReportError(cx, string.as_ptr()) }; return 0; } @@ -153,7 +153,7 @@ unsafe extern fn get_error_message(_user_ref: *mut libc::c_void, /// Throw a `TypeError` with the given message. pub fn throw_type_error(cx: *mut JSContext, error: &str) { - let error = CString::from_slice(error.as_bytes()); + let error = CString::new(error).unwrap(); unsafe { JS_ReportErrorNumber(cx, Some(get_error_message as diff --git a/components/script/dom/bindings/mod.rs b/components/script/dom/bindings/mod.rs index c5709f01e8f..2775f513525 100644 --- a/components/script/dom/bindings/mod.rs +++ b/components/script/dom/bindings/mod.rs @@ -25,7 +25,7 @@ //! some sanity checks and [argument conversions](conversions/index.html), and //! calls into API implementation for the DOM object. -#![allow(unsafe_blocks)] +#![allow(unsafe_code)] #![deny(missing_docs, non_snake_case)] pub mod cell; diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 505307dd7bf..4af66e2edba 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -34,6 +34,7 @@ use dom::bindings::refcounted::Trusted; use dom::bindings::utils::{Reflectable, Reflector, WindowProxyHandler}; use script_task::ScriptChan; +use canvas::canvas_paint_task::{CanvasGradientStop, LinearGradientStyle, RadialGradientStyle}; use cssparser::RGBA; use encoding::types::EncodingRef; use geom::matrix2d::Matrix2D; @@ -91,7 +92,7 @@ pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) { } unsafe { - let name = CString::from_slice(description.as_bytes()); + let name = CString::new(description).unwrap(); (*tracer).debugPrinter = None; (*tracer).debugPrintIndex = -1; (*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void; @@ -109,7 +110,7 @@ pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Ref /// Trace a `JSObject`. pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: *mut JSObject) { unsafe { - let name = CString::from_slice(description.as_bytes()); + let name = CString::new(description).unwrap(); (*tracer).debugPrinter = None; (*tracer).debugPrintIndex = -1; (*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void; @@ -233,6 +234,7 @@ no_jsmanaged_fields!(LengthOrPercentageOrAuto); no_jsmanaged_fields!(RGBA); no_jsmanaged_fields!(Matrix2D<T>); no_jsmanaged_fields!(StorageType); +no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyle); impl JSTraceable for Box<ScriptChan+Send> { #[inline] diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index c24c6110821..64080fbdfce 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -197,7 +197,7 @@ pub fn do_create_interface_objects(cx: *mut JSContext, global: *mut JSObject, match constructor { Some((native, name, nargs)) => { - let s = CString::from_slice(name.as_bytes()); + let s = CString::new(name).unwrap(); create_interface_object(cx, global, receiver, native, nargs, proto, members, s.as_ptr()) @@ -321,10 +321,12 @@ pub unsafe extern fn throwing_constructor(cx: *mut JSContext, _argc: c_uint, return 0; } +type ProtoOrIfaceArray = [*mut JSObject; PrototypeList::ID::Count as usize]; + /// Construct and cache the ProtoOrIfaceArray for the given global. /// Fails if the argument is not a DOM global. pub fn initialize_global(global: *mut JSObject) { - let proto_array = box () + let proto_array: Box<ProtoOrIfaceArray> = box () ([0 as *mut JSObject; PrototypeList::ID::Count as usize]); unsafe { assert!(((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0); @@ -514,7 +516,7 @@ pub fn get_dictionary_property(cx: *mut JSContext, } } - let property = CString::from_slice(property.as_bytes()); + let property = CString::new(property).unwrap(); if object.is_null() { return Ok(None); } @@ -560,6 +562,12 @@ pub fn create_dom_global(cx: *mut JSContext, class: *const JSClass) } } +/// Drop the resources held by reserved slots of a global object +pub unsafe fn finalize_global(obj: *mut JSObject) { + let _: Box<ProtoOrIfaceArray> = + Box::from_raw(get_proto_or_iface_array(obj) as *mut ProtoOrIfaceArray); +} + /// Callback to outerize windows when wrapping. pub unsafe extern fn wrap_for_same_compartment(cx: *mut JSContext, obj: *mut JSObject) -> *mut JSObject { JS_ObjectToOuterObject(cx, obj) diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs index 103fc2a1f78..60763f7aa7e 100644 --- a/components/script/dom/blob.rs +++ b/components/script/dom/blob.rs @@ -126,8 +126,8 @@ impl<'a> BlobMethods for JSRef<'a, Blob> { match self.bytes { None => Blob::new(global.r(), None, relativeContentType.as_slice()), Some(ref vec) => { - let start = relativeStart.to_uint().unwrap(); - let end = (relativeStart + span).to_uint().unwrap(); + let start = relativeStart.to_usize().unwrap(); + let end = (relativeStart + span).to_usize().unwrap(); let mut bytes: Vec<u8> = Vec::new(); bytes.push_all(&vec[start..end]); Blob::new(global.r(), Some(bytes), relativeContentType.as_slice()) diff --git a/components/script/dom/browsercontext.rs b/components/script/dom/browsercontext.rs index d4b2591f247..d7e3eb90500 100644 --- a/components/script/dom/browsercontext.rs +++ b/components/script/dom/browsercontext.rs @@ -67,7 +67,7 @@ impl BrowserContext { self.window_proxy } - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn create_window_proxy(&mut self) { let win = self.active_window().root(); let win = win.r(); @@ -104,6 +104,7 @@ impl SessionHistoryEntry { } } +#[allow(unsafe_code)] unsafe fn GetSubframeWindow(cx: *mut JSContext, proxy: *mut JSObject, id: jsid) -> Option<Temporary<Window>> { let index = get_array_index_from_id(cx, id); if let Some(index) = index { @@ -116,6 +117,7 @@ unsafe fn GetSubframeWindow(cx: *mut JSContext, proxy: *mut JSObject, id: jsid) None } +#[allow(unsafe_code)] unsafe extern fn getOwnPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, set: bool, desc: *mut JSPropertyDescriptor) -> bool { let window = GetSubframeWindow(cx, proxy, id); if let Some(window) = window { @@ -142,7 +144,7 @@ unsafe extern fn getOwnPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObje true } - +#[allow(unsafe_code)] unsafe extern fn defineProperty(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, desc: *mut JSPropertyDescriptor) -> bool { if get_array_index_from_id(cx, id).is_some() { // Spec says to Reject whether this is a supported index or not, @@ -157,6 +159,7 @@ unsafe extern fn defineProperty(cx: *mut JSContext, proxy: *mut JSObject, id: js (*desc).setter, (*desc).attrs) != 0 } +#[allow(unsafe_code)] unsafe extern fn hasOwn(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, bp: *mut bool) -> bool { let window = GetSubframeWindow(cx, proxy, id); if window.is_some() { @@ -174,6 +177,7 @@ unsafe extern fn hasOwn(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, bp: return true; } +#[allow(unsafe_code)] unsafe extern fn get(cx: *mut JSContext, proxy: *mut JSObject, receiver: *mut JSObject, id: jsid, vp: *mut JSVal) -> bool { let window = GetSubframeWindow(cx, proxy, id); if let Some(window) = window { @@ -186,6 +190,7 @@ unsafe extern fn get(cx: *mut JSContext, proxy: *mut JSObject, receiver: *mut JS JS_ForwardGetPropertyTo(cx, target, id, receiver, vp) != 0 } +#[allow(unsafe_code)] unsafe extern fn set(cx: *mut JSContext, proxy: *mut JSObject, _receiver: *mut JSObject, id: jsid, _strict: bool, vp: *mut JSVal) -> bool { if get_array_index_from_id(cx, id).is_some() { // Reject (which means throw if and only if strict) the set. @@ -234,7 +239,7 @@ static PROXY_HANDLER: ProxyTraps = ProxyTraps { trace: None }; -#[allow(unsafe_blocks)] +#[allow(unsafe_code)] pub fn new_window_proxy_handler() -> WindowProxyHandler { unsafe { WindowProxyHandler(CreateWrapperProxyHandler(&PROXY_HANDLER)) diff --git a/components/script/dom/canvasgradient.rs b/components/script/dom/canvasgradient.rs index def78ca7f33..c1e61a12c26 100644 --- a/components/script/dom/canvasgradient.rs +++ b/components/script/dom/canvasgradient.rs @@ -2,10 +2,80 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::bindings::utils::Reflector; +use cssparser::RGBA; +use canvas::canvas_paint_task::{CanvasGradientStop, FillOrStrokeStyle, LinearGradientStyle, RadialGradientStyle}; +use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::CanvasGradientBinding; +use dom::bindings::codegen::Bindings::CanvasGradientBinding::CanvasGradientMethods; +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{JSRef, Temporary}; +use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::canvasrenderingcontext2d::parse_color; #[dom_struct] pub struct CanvasGradient { reflector_: Reflector, + style: CanvasGradientStyle, + stops: DOMRefCell<Vec<CanvasGradientStop>>, } +#[jstraceable] +pub enum CanvasGradientStyle { + Linear(LinearGradientStyle), + Radial(RadialGradientStyle), +} + +impl CanvasGradient { + fn new_inherited(style: CanvasGradientStyle) -> CanvasGradient { + CanvasGradient { + reflector_: Reflector::new(), + style: style, + stops: DOMRefCell::new(Vec::new()), + } + } + + pub fn new(global: GlobalRef, style: CanvasGradientStyle) -> Temporary<CanvasGradient> { + reflect_dom_object(box CanvasGradient::new_inherited(style), + global, CanvasGradientBinding::Wrap) + } +} + +impl<'a> CanvasGradientMethods for JSRef<'a, CanvasGradient> { + fn AddColorStop(self, offset: f32, color: String) { + let default_black = RGBA { + red: 0.0, + green: 0.0, + blue: 0.0, + alpha: 1.0, + }; + + self.stops.borrow_mut().push(CanvasGradientStop { + offset: offset as f64, + color: parse_color(color.as_slice()).unwrap_or(default_black), + }); + } +} + +pub trait ToFillOrStrokeStyle { + fn to_fill_or_stroke_style(&self) -> FillOrStrokeStyle; +} + +impl<'a> ToFillOrStrokeStyle for JSRef<'a, CanvasGradient> { + fn to_fill_or_stroke_style(&self) -> FillOrStrokeStyle { + let gradient_stops = self.stops.borrow().clone(); + match self.style { + CanvasGradientStyle::Linear(ref gradient) => { + FillOrStrokeStyle::LinearGradient( + LinearGradientStyle::new(gradient.x0, gradient.y0, + gradient.x1, gradient.y1, + gradient_stops)) + }, + CanvasGradientStyle::Radial(ref gradient) => { + FillOrStrokeStyle::RadialGradient( + RadialGradientStyle::new(gradient.x0, gradient.y0, gradient.r0, + gradient.x1, gradient.y1, gradient.r1, + gradient_stops)) + } + } + } +} diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index d481aca911f..4c2e05b4b9e 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -7,11 +7,12 @@ use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRen use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasWindingRule; use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods; use dom::bindings::codegen::UnionTypes::StringOrCanvasGradientOrCanvasPattern; -use dom::bindings::error::Error::IndexSize; +use dom::bindings::error::Error::{IndexSize, TypeError}; use dom::bindings::error::Fallible; use dom::bindings::global::{GlobalRef, GlobalField}; use dom::bindings::js::{JS, JSRef, LayoutJS, Temporary}; use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::canvasgradient::{CanvasGradient, CanvasGradientStyle, ToFillOrStrokeStyle}; use dom::htmlcanvaselement::{HTMLCanvasElement, HTMLCanvasElementHelpers}; use dom::imagedata::{ImageData, ImageDataHelpers}; @@ -23,7 +24,9 @@ use geom::rect::Rect; use geom::size::Size2D; use canvas::canvas_paint_task::{CanvasMsg, CanvasPaintTask, FillOrStrokeStyle}; +use canvas::canvas_paint_task::{LinearGradientStyle, RadialGradientStyle}; +use std::borrow::ToOwned; use std::cell::Cell; use std::num::{Float, ToPrimitive}; use std::sync::mpsc::{channel, Sender}; @@ -75,10 +78,12 @@ impl CanvasRenderingContext2D { } pub trait LayoutCanvasRenderingContext2DHelpers { + #[allow(unsafe_code)] unsafe fn get_renderer(&self) -> Sender<CanvasMsg>; } impl LayoutCanvasRenderingContext2DHelpers for LayoutJS<CanvasRenderingContext2D> { + #[allow(unsafe_code)] unsafe fn get_renderer(&self) -> Sender<CanvasMsg> { (*self.unsafe_get()).renderer.clone() } @@ -154,6 +159,11 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D> self.renderer.send(CanvasMsg::LineTo(Point2D(x as f32, y as f32))).unwrap(); } + fn QuadraticCurveTo(self, cpx: f64, cpy: f64, x: f64, y: f64) { + self.renderer.send(CanvasMsg::QuadraticCurveTo(Point2D(cpx as f32, cpy as f32), + Point2D(x as f32, y as f32))).unwrap(); + } + fn BezierCurveTo(self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, x: f64, y: f64) { self.renderer.send(CanvasMsg::BezierCurveTo(Point2D(cp1x as f32, cp1y as f32), Point2D(cp2x as f32, cp2y as f32), @@ -215,6 +225,9 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D> _ => {} } } + StringOrCanvasGradientOrCanvasPattern::eCanvasGradient(gradient) => { + self.renderer.send(CanvasMsg::SetFillStyle(gradient.root().r().to_fill_or_stroke_style())).unwrap(); + } _ => {} } } @@ -264,6 +277,22 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D> let canvas_size = self.canvas.root().r().get_size(); self.renderer.send(CanvasMsg::PutImageData(data, image_data_rect, dirty_rect, canvas_size)).unwrap() } + + fn CreateLinearGradient(self, x0: f64, y0: f64, x1: f64, y1: f64) -> Fallible<Temporary<CanvasGradient>> { + if [x0, y0, x1, y1].iter().any(|x| x.is_nan() || x.is_infinite()) { + return Err(TypeError("One of the arguments of createLinearGradient() is not a finite floating-point value.".to_owned())); + } + Ok(CanvasGradient::new(self.global.root().r(), + CanvasGradientStyle::Linear(LinearGradientStyle::new(x0, y0, x1, y1, Vec::new())))) + } + + fn CreateRadialGradient(self, x0: f64, y0: f64, r0: f64, x1: f64, y1: f64, r1: f64) -> Fallible<Temporary<CanvasGradient>> { + if [x0, y0, r0, x1, y1, r1].iter().any(|x| x.is_nan() || x.is_infinite()) { + return Err(TypeError("One of the arguments of createRadialGradient() is not a finite floating-point value.".to_owned())); + } + Ok(CanvasGradient::new(self.global.root().r(), + CanvasGradientStyle::Radial(RadialGradientStyle::new(x0, y0, r0, x1, y1, r1, Vec::new())))) + } } #[unsafe_destructor] diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs index 9320322f841..1f2b18f1b99 100644 --- a/components/script/dom/characterdata.rs +++ b/components/script/dom/characterdata.rs @@ -60,6 +60,7 @@ impl CharacterData { } #[inline] + #[allow(unsafe_code)] pub unsafe fn data_for_layout<'a>(&'a self) -> &'a str { self.data.borrow_for_layout().as_slice() } diff --git a/components/script/dom/console.rs b/components/script/dom/console.rs index 6308556ef2e..69ececca802 100644 --- a/components/script/dom/console.rs +++ b/components/script/dom/console.rs @@ -33,7 +33,8 @@ impl Console { impl<'a> ConsoleMethods for JSRef<'a, Console> { fn Log(self, message: DOMString) { println!("{}", message); - propagate_console_msg(&self, ConsoleMessage::LogMessage(message)); + //TODO: Sending fake values for filename, lineNumber and columnNumber in LogMessage; adjust later + propagate_console_msg(&self, ConsoleMessage::LogMessage(message, String::from_str("test"), 1, 1)); } fn Debug(self, message: DOMString) { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 1d1b8fb2968..c11c22b67b6 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -690,12 +690,14 @@ pub enum DocumentSource { } pub trait LayoutDocumentHelpers { + #[allow(unsafe_code)] unsafe fn is_html_document_for_layout(&self) -> bool; } impl LayoutDocumentHelpers for LayoutJS<Document> { #[allow(unrooted_must_root)] #[inline] + #[allow(unsafe_code)] unsafe fn is_html_document_for_layout(&self) -> bool { (*self.unsafe_get()).is_html_document } @@ -835,6 +837,19 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { self.url().serialize() } + // https://html.spec.whatwg.org/multipage/interaction.html#dom-document-activeelement + fn GetActiveElement(self) -> Option<Temporary<Element>> { + // TODO: Step 2. + + match self.get_focused_element() { + Some(element) => Some(element), // Step 3. and 4. + None => match self.GetBody() { // Step 5. + Some(body) => Some(ElementCast::from_temporary(body)), + None => self.GetDocumentElement(), + } + } + } + // http://dom.spec.whatwg.org/#dom-document-documenturi fn DocumentURI(self) -> DOMString { self.URL() @@ -1076,7 +1091,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { fn LastModified(self) -> DOMString { match self.last_modified { Some(ref t) => t.clone(), - None => format!("{}", time::now().strftime("%m/%d/%Y %H:%M:%S").unwrap()), + None => time::now().strftime("%m/%d/%Y %H:%M:%S").unwrap().to_string(), } } @@ -1202,22 +1217,23 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { return Ok(()); } - // Step 3. - match self.get_html_element().root() { - // Step 4. - None => return Err(HierarchyRequest), - Some(ref root) => { + match (self.get_html_element().root(), old_body) { + // Step 3. + (Some(ref root), Some(ref child)) => { + let root: JSRef<Node> = NodeCast::from_ref(root.r()); + let child: JSRef<Node> = NodeCast::from_ref(child.r()); let new_body: JSRef<Node> = NodeCast::from_ref(new_body); + assert!(root.ReplaceChild(new_body, child).is_ok()) + }, - let root: JSRef<Node> = NodeCast::from_ref(root.r()); - match old_body { - Some(ref child) => { - let child: JSRef<Node> = NodeCast::from_ref(child.r()); + // Step 4. + (None, _) => return Err(HierarchyRequest), - assert!(root.ReplaceChild(new_body, child).is_ok()) - } - None => assert!(root.AppendChild(new_body).is_ok()) - }; + // Step 5. + (Some(ref root), None) => { + let root: JSRef<Node> = NodeCast::from_ref(root.r()); + let new_body: JSRef<Node> = NodeCast::from_ref(new_body); + assert!(root.AppendChild(new_body).is_ok()); } } Ok(()) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 3d7ddff05a5..3173fdf7520 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -148,6 +148,7 @@ impl Element { } } +#[allow(unsafe_code)] pub trait RawLayoutElementHelpers { unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str>; @@ -171,6 +172,7 @@ pub trait RawLayoutElementHelpers { } #[inline] +#[allow(unsafe_code)] unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace, name: &Atom) -> Option<&'a JS<Attr>> { // cast to point to T in RefCell<T> directly let attrs = elem.attrs.borrow_for_layout(); @@ -181,6 +183,7 @@ unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace, name }) } +#[allow(unsafe_code)] impl RawLayoutElementHelpers for Element { #[inline] unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom) @@ -394,12 +397,15 @@ impl RawLayoutElementHelpers for Element { } pub trait LayoutElementHelpers { + #[allow(unsafe_code)] unsafe fn html_element_in_html_document_for_layout(&self) -> bool; + #[allow(unsafe_code)] unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool; } impl LayoutElementHelpers for LayoutJS<Element> { #[inline] + #[allow(unsafe_code)] unsafe fn html_element_in_html_document_for_layout(&self) -> bool { if (*self.unsafe_get()).namespace != ns!(HTML) { return false @@ -408,6 +414,7 @@ impl LayoutElementHelpers for LayoutJS<Element> { node.owner_doc_for_layout().is_html_document_for_layout() } + #[allow(unsafe_code)] unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool { get_attr_for_layout(&*self.unsafe_get(), namespace, name).is_some() } @@ -435,6 +442,7 @@ pub trait ElementHelpers<'a> { fn get_inline_style_declaration(self, property: &Atom) -> Option<PropertyDeclaration>; fn get_important_inline_style_declaration(self, property: &Atom) -> Option<PropertyDeclaration>; fn serialize(self, traversal_scope: TraversalScope) -> Fallible<DOMString>; + fn get_root_element(self) -> Option<Temporary<Element>>; } impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { @@ -593,6 +601,15 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { Err(_) => panic!("Cannot serialize element"), } } + + // https://html.spec.whatwg.org/multipage/infrastructure.html#root-element + fn get_root_element(self) -> Option<Temporary<Element>> { + let node: JSRef<Node> = NodeCast::from_ref(self); + match node.ancestors().last().map(ElementCast::to_ref) { + Some(n) => n.map(Temporary::from_rooted), + None => Some(self).map(Temporary::from_rooted), + } + } } pub trait AttributeHandlers { @@ -1415,7 +1432,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { } impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str> { self.get_attribute(namespace.clone(), attr).root().map(|attr| { // This transmute is used to cheat the lifetime restriction. @@ -1425,7 +1442,7 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { unsafe { mem::transmute(value.as_slice()) } }) } - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn get_attrs(self, attr: &Atom) -> Vec<&'a str> { self.get_attributes(attr).into_iter().map(|attr| attr.root()).map(|attr| { // FIXME(https://github.com/rust-lang/rust/issues/23338) diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 018579e6127..92aabfd0be3 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -191,15 +191,15 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> { }).map(|entry| entry.listener.get_listener())) } - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn set_event_handler_uncompiled(self, cx: *mut JSContext, url: Url, scope: *mut JSObject, ty: &str, source: DOMString) { - let url = CString::from_slice(url.serialize().as_bytes()); - let name = CString::from_slice(ty.as_bytes()); + let url = CString::new(url.serialize()).unwrap(); + let name = CString::new(ty).unwrap(); let lineno = 0; //XXXjdm need to get a real number here let nargs = 1; //XXXjdm not true for onerror diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index a40e269aaaa..98410ef02ef 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -82,7 +82,7 @@ impl<'a> FormDataMethods for JSRef<'a, FormData> { self.data.borrow_mut().remove(&name); } - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn Get(self, name: DOMString) -> Option<FileOrString> { // FIXME(https://github.com/rust-lang/rust/issues/23338) let data = self.data.borrow(); diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index 8f09c5d8745..e1d74d7a3a6 100644 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -211,7 +211,7 @@ impl<'a> Activatable for JSRef<'a, HTMLButtonElement> { } // https://html.spec.whatwg.org/multipage/forms.html#implicit-submission - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) { let doc = document_from_node(*self).root(); let node: JSRef<Node> = NodeCast::from_ref(doc.r()); diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 220e81bae51..9c3c11d5dbc 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -63,21 +63,27 @@ impl HTMLCanvasElement { } pub trait LayoutHTMLCanvasElementHelpers { + #[allow(unsafe_code)] unsafe fn get_renderer(&self) -> Option<Sender<CanvasMsg>>; + #[allow(unsafe_code)] unsafe fn get_canvas_width(&self) -> u32; + #[allow(unsafe_code)] unsafe fn get_canvas_height(&self) -> u32; } impl LayoutHTMLCanvasElementHelpers for LayoutJS<HTMLCanvasElement> { + #[allow(unsafe_code)] unsafe fn get_renderer(&self) -> Option<Sender<CanvasMsg>> { let context = (*self.unsafe_get()).context.get_inner_as_layout(); context.map(|cx| cx.get_renderer()) } + #[allow(unsafe_code)] unsafe fn get_canvas_width(&self) -> u32 { (*self.unsafe_get()).width.get() } + #[allow(unsafe_code)] unsafe fn get_canvas_height(&self) -> u32 { (*self.unsafe_get()).height.get() } diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 973de33d34d..a134b26584a 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -32,7 +32,6 @@ use util::str::DOMString; use string_cache::Atom; -use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::default::Default; diff --git a/components/script/dom/htmlheadelement.rs b/components/script/dom/htmlheadelement.rs index 5b38078e34c..7f2a03c96d2 100644 --- a/components/script/dom/htmlheadelement.rs +++ b/components/script/dom/htmlheadelement.rs @@ -2,15 +2,24 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; use dom::bindings::codegen::Bindings::HTMLHeadElementBinding; -use dom::bindings::codegen::InheritTypes::HTMLHeadElementDerived; -use dom::bindings::js::{JSRef, Temporary}; +use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; +use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; +use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLHeadElementDerived, NodeCast}; +use dom::bindings::js::{JSRef, OptionalRootable, Temporary, RootedReference}; use dom::document::Document; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::element::ElementTypeId; +use dom::element::AttributeHandlers; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{Node, NodeTypeId}; +use dom::node::{Node, NodeHelpers, NodeTypeId}; +use dom::virtualmethods::VirtualMethods; use util::str::DOMString; +use util::opts; +use util::resource_files::resources_dir_path; +use std::borrow::ToOwned; +use std::fs::read_dir; #[dom_struct] pub struct HTMLHeadElement { @@ -37,3 +46,40 @@ impl HTMLHeadElement { } } +impl<'a> VirtualMethods for JSRef<'a, HTMLHeadElement> { + fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> { + let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self); + Some(htmlelement as &VirtualMethods) + } + fn bind_to_tree(&self, tree_in_doc: bool) { + if !opts::get().userscripts { + return; + } + + let node: &JSRef<Node> = NodeCast::from_borrowed_ref(self); + let first_child = node.GetFirstChild().root(); + let doc = node.owner_doc().root(); + let doc = doc.r(); + + let mut path = resources_dir_path(); + path.push("user-agent-js"); + let mut files = match read_dir(&path) { + Ok(d) => d.filter_map(|e| e.ok()).map(|e| e.path()).collect::<Vec<_>>(), + Err(_) => return + }; + + files.sort(); + + for file in files { + let name = match file.into_os_string().into_string() { + Ok(ref s) if s.ends_with(".js") => "file://".to_owned() + &s[..], + _ => continue + }; + let new_script = doc.CreateElement("script".to_owned()).unwrap().root(); + let new_script = new_script.r(); + new_script.set_string_attribute(&atom!("src"), name); + let new_script_node: &JSRef<Node> = NodeCast::from_borrowed_ref(&new_script); + node.InsertBefore(*new_script_node, first_child.r()); + } + } +} diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index c3655ce1897..ea58f1e87c1 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -86,10 +86,12 @@ impl HTMLImageElement { } pub trait LayoutHTMLImageElementHelpers { + #[allow(unsafe_code)] unsafe fn image(&self) -> Option<Url>; } impl LayoutHTMLImageElementHelpers for LayoutJS<HTMLImageElement> { + #[allow(unsafe_code)] unsafe fn image(&self) -> Option<Url> { (*self.unsafe_get()).image.borrow_for_layout().clone() } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 670d02c9a37..ec117ad2e38 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -129,23 +129,31 @@ impl HTMLInputElement { } pub trait LayoutHTMLInputElementHelpers { + #[allow(unsafe_code)] unsafe fn get_value_for_layout(self) -> String; + #[allow(unsafe_code)] unsafe fn get_size_for_layout(self) -> u32; } pub trait RawLayoutHTMLInputElementHelpers { + #[allow(unsafe_code)] unsafe fn get_checked_state_for_layout(&self) -> bool; + #[allow(unsafe_code)] unsafe fn get_indeterminate_state_for_layout(&self) -> bool; + #[allow(unsafe_code)] unsafe fn get_size_for_layout(&self) -> u32; } impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> { #[allow(unrooted_must_root)] + #[allow(unsafe_code)] unsafe fn get_value_for_layout(self) -> String { + #[allow(unsafe_code)] unsafe fn get_raw_textinput_value(input: LayoutJS<HTMLInputElement>) -> String { (*input.unsafe_get()).textinput.borrow_for_layout().get_content() } + #[allow(unsafe_code)] unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>) -> Option<String> { let elem: LayoutJS<Element> = input.transmute_copy(); (*elem.unsafe_get()).get_attr_val_for_layout(&ns!(""), &atom!("value")) @@ -167,6 +175,7 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> { } #[allow(unrooted_must_root)] + #[allow(unsafe_code)] unsafe fn get_size_for_layout(self) -> u32 { (*self.unsafe_get()).get_size_for_layout() } @@ -174,16 +183,19 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> { impl RawLayoutHTMLInputElementHelpers for HTMLInputElement { #[allow(unrooted_must_root)] + #[allow(unsafe_code)] unsafe fn get_checked_state_for_layout(&self) -> bool { self.checked.get() } #[allow(unrooted_must_root)] + #[allow(unsafe_code)] unsafe fn get_indeterminate_state_for_layout(&self) -> bool { self.indeterminate.get() } #[allow(unrooted_must_root)] + #[allow(unsafe_code)] unsafe fn get_size_for_layout(&self) -> u32 { self.size.get() } @@ -307,7 +319,7 @@ pub trait HTMLInputElementHelpers { fn reset(self); } -#[allow(unsafe_blocks)] +#[allow(unsafe_code)] fn broadcast_radio_checked(broadcaster: JSRef<HTMLInputElement>, group: Option<&str>) { //TODO: if not in document, use root ancestor instead of document let owner = broadcaster.form_owner().root(); @@ -614,7 +626,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { } // https://html.spec.whatwg.org/multipage/interaction.html#run-pre-click-activation-steps - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn pre_click_activation(&self) { let mut cache = self.activation_state.borrow_mut(); let ty = self.input_type.get(); @@ -765,7 +777,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { } // https://html.spec.whatwg.org/multipage/forms.html#implicit-submission - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) { let doc = document_from_node(*self).root(); let node: JSRef<Node> = NodeCast::from_ref(doc.r()); diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index dcf79d70091..2b53e09a1a2 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -52,16 +52,20 @@ impl HTMLTextAreaElementDerived for EventTarget { } pub trait LayoutHTMLTextAreaElementHelpers { + #[allow(unsafe_code)] unsafe fn get_value_for_layout(self) -> String; } pub trait RawLayoutHTMLTextAreaElementHelpers { + #[allow(unsafe_code)] unsafe fn get_cols_for_layout(&self) -> u32; + #[allow(unsafe_code)] unsafe fn get_rows_for_layout(&self) -> u32; } impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> { #[allow(unrooted_must_root)] + #[allow(unsafe_code)] unsafe fn get_value_for_layout(self) -> String { (*self.unsafe_get()).textinput.borrow_for_layout().get_content() } @@ -69,11 +73,13 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> { impl RawLayoutHTMLTextAreaElementHelpers for HTMLTextAreaElement { #[allow(unrooted_must_root)] + #[allow(unsafe_code)] unsafe fn get_cols_for_layout(&self) -> u32 { self.cols.get() } #[allow(unrooted_must_root)] + #[allow(unsafe_code)] unsafe fn get_rows_for_layout(&self) -> u32 { self.rows.get() } diff --git a/components/script/dom/imagedata.rs b/components/script/dom/imagedata.rs index 4c88da4786d..c9da863096c 100644 --- a/components/script/dom/imagedata.rs +++ b/components/script/dom/imagedata.rs @@ -25,7 +25,7 @@ pub struct ImageData { } impl ImageData { - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn new_inherited(width: u32, height: u32, data: Option<Vec<u8>>, global: GlobalRef) -> ImageData { unsafe { let cx = global.get_cx(); @@ -33,7 +33,7 @@ impl ImageData { if let Some(vec) = data { let js_object_data: *mut uint8_t = JS_GetUint8ClampedArrayData(js_object, cx); - ptr::copy_nonoverlapping_memory(js_object_data, vec.as_ptr(), vec.len()) + ptr::copy_nonoverlapping(js_object_data, vec.as_ptr(), vec.len()) } ImageData { @@ -57,7 +57,7 @@ pub trait ImageDataHelpers { } impl<'a> ImageDataHelpers for JSRef<'a, ImageData> { - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn get_data_array(self, global: &GlobalRef) -> Vec<u8> { unsafe { let cx = global.get_cx(); diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 0981c5e802d..2363d2f119b 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -175,7 +175,7 @@ impl NodeFlags { #[unsafe_destructor] impl Drop for Node { - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn drop(&mut self) { self.layout_data.dispose(); } @@ -203,6 +203,7 @@ pub struct LayoutData { _data: NonZero<*const ()>, } +#[allow(unsafe_code)] unsafe impl Send for LayoutData {} pub struct LayoutDataRef { @@ -236,6 +237,7 @@ impl LayoutDataRef { /// happen if you try to mutate the layout data while this is held. This is the only thread- /// safe layout data accessor. #[inline] + #[allow(unsafe_code)] pub unsafe fn borrow_unchecked(&self) -> *const Option<LayoutData> { mem::transmute(&self.data_cell) } @@ -382,6 +384,7 @@ pub struct QuerySelectorIterator<'a> { } impl<'a> QuerySelectorIterator<'a> { + #[allow(unsafe_code)] unsafe fn new(iter: TreeIterator<'a>, selectors: Vec<Selector>) -> QuerySelectorIterator<'a> { QuerySelectorIterator { selectors: selectors, @@ -483,6 +486,7 @@ pub trait NodeHelpers<'a> { fn get_content_boxes(self) -> Vec<Rect<Au>>; fn query_selector(self, selectors: DOMString) -> Fallible<Option<Temporary<Element>>>; + #[allow(unsafe_code)] unsafe fn query_selector_iter(self, selectors: DOMString) -> Fallible<QuerySelectorIterator<'a>>; fn query_selector_all(self, selectors: DOMString) -> Fallible<Temporary<NodeList>>; @@ -773,6 +777,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { /// Get an iterator over all nodes which match a set of selectors /// Be careful not to do anything which may manipulate the DOM tree whilst iterating, otherwise /// the iterator may be invalidated + #[allow(unsafe_code)] unsafe fn query_selector_iter(self, selectors: DOMString) -> Fallible<QuerySelectorIterator<'a>> { // Step 1. @@ -790,7 +795,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-parentnode-queryselectorall - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn query_selector_all(self, selectors: DOMString) -> Fallible<Temporary<NodeList>> { // Step 1. unsafe { @@ -907,7 +912,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { /// If the given untrusted node address represents a valid DOM node in the given runtime, /// returns it. -#[allow(unsafe_blocks)] +#[allow(unsafe_code)] pub fn from_untrusted_node_address(runtime: *mut JSRuntime, candidate: UntrustedNodeAddress) -> Temporary<Node> { unsafe { @@ -923,68 +928,88 @@ pub fn from_untrusted_node_address(runtime: *mut JSRuntime, candidate: Untrusted } pub trait LayoutNodeHelpers { + #[allow(unsafe_code)] unsafe fn type_id_for_layout(&self) -> NodeTypeId; + #[allow(unsafe_code)] unsafe fn parent_node_ref(&self) -> Option<LayoutJS<Node>>; + #[allow(unsafe_code)] unsafe fn first_child_ref(&self) -> Option<LayoutJS<Node>>; + #[allow(unsafe_code)] unsafe fn last_child_ref(&self) -> Option<LayoutJS<Node>>; + #[allow(unsafe_code)] unsafe fn prev_sibling_ref(&self) -> Option<LayoutJS<Node>>; + #[allow(unsafe_code)] unsafe fn next_sibling_ref(&self) -> Option<LayoutJS<Node>>; + #[allow(unsafe_code)] unsafe fn owner_doc_for_layout(&self) -> LayoutJS<Document>; + #[allow(unsafe_code)] unsafe fn is_element_for_layout(&self) -> bool; + #[allow(unsafe_code)] unsafe fn get_flag(self, flag: NodeFlags) -> bool; + #[allow(unsafe_code)] unsafe fn set_flag(self, flag: NodeFlags, value: bool); } impl LayoutNodeHelpers for LayoutJS<Node> { #[inline] + #[allow(unsafe_code)] unsafe fn type_id_for_layout(&self) -> NodeTypeId { (*self.unsafe_get()).type_id } #[inline] + #[allow(unsafe_code)] unsafe fn is_element_for_layout(&self) -> bool { (*self.unsafe_get()).is_element() } #[inline] + #[allow(unsafe_code)] unsafe fn parent_node_ref(&self) -> Option<LayoutJS<Node>> { (*self.unsafe_get()).parent_node.get_inner_as_layout() } #[inline] + #[allow(unsafe_code)] unsafe fn first_child_ref(&self) -> Option<LayoutJS<Node>> { (*self.unsafe_get()).first_child.get_inner_as_layout() } #[inline] + #[allow(unsafe_code)] unsafe fn last_child_ref(&self) -> Option<LayoutJS<Node>> { (*self.unsafe_get()).last_child.get_inner_as_layout() } #[inline] + #[allow(unsafe_code)] unsafe fn prev_sibling_ref(&self) -> Option<LayoutJS<Node>> { (*self.unsafe_get()).prev_sibling.get_inner_as_layout() } #[inline] + #[allow(unsafe_code)] unsafe fn next_sibling_ref(&self) -> Option<LayoutJS<Node>> { (*self.unsafe_get()).next_sibling.get_inner_as_layout() } #[inline] + #[allow(unsafe_code)] unsafe fn owner_doc_for_layout(&self) -> LayoutJS<Document> { (*self.unsafe_get()).owner_doc.get_inner_as_layout().unwrap() } #[inline] + #[allow(unsafe_code)] unsafe fn get_flag(self, flag: NodeFlags) -> bool { (*self.unsafe_get()).flags.get().contains(flag) } #[inline] + #[allow(unsafe_code)] unsafe fn set_flag(self, flag: NodeFlags, value: bool) { let this = self.unsafe_get(); let mut flags = (*this).flags.get(); @@ -1000,22 +1025,28 @@ impl LayoutNodeHelpers for LayoutJS<Node> { } pub trait RawLayoutNodeHelpers { + #[allow(unsafe_code)] unsafe fn get_hover_state_for_layout(&self) -> bool; + #[allow(unsafe_code)] unsafe fn get_disabled_state_for_layout(&self) -> bool; + #[allow(unsafe_code)] unsafe fn get_enabled_state_for_layout(&self) -> bool; fn type_id_for_layout(&self) -> NodeTypeId; } impl RawLayoutNodeHelpers for Node { #[inline] + #[allow(unsafe_code)] unsafe fn get_hover_state_for_layout(&self) -> bool { self.flags.get().contains(IN_HOVER_STATE) } #[inline] + #[allow(unsafe_code)] unsafe fn get_disabled_state_for_layout(&self) -> bool { self.flags.get().contains(IN_DISABLED_STATE) } #[inline] + #[allow(unsafe_code)] unsafe fn get_enabled_state_for_layout(&self) -> bool { self.flags.get().contains(IN_ENABLED_STATE) } @@ -1245,6 +1276,7 @@ impl Node { } #[inline] + #[allow(unsafe_code)] pub unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData> { self.layout_data.borrow_unchecked() } @@ -2207,6 +2239,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { #[derive(Clone, PartialEq, Eq, Copy)] pub struct TrustedNodeAddress(pub *const c_void); +#[allow(unsafe_code)] unsafe impl Send for TrustedNodeAddress {} pub fn document_from_node<T: NodeBase+Reflectable>(derived: JSRef<T>) -> Temporary<Document> { @@ -2341,15 +2374,19 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> { } fn has_changed(self) -> bool { self.get_has_changed() } + #[allow(unsafe_code)] unsafe fn set_changed(self, value: bool) { self.set_has_changed(value) } fn is_dirty(self) -> bool { self.get_is_dirty() } + #[allow(unsafe_code)] unsafe fn set_dirty(self, value: bool) { self.set_is_dirty(value) } fn has_dirty_siblings(self) -> bool { self.get_has_dirty_siblings() } + #[allow(unsafe_code)] unsafe fn set_dirty_siblings(self, value: bool) { self.set_has_dirty_siblings(value) } fn has_dirty_descendants(self) -> bool { self.get_has_dirty_descendants() } + #[allow(unsafe_code)] unsafe fn set_dirty_descendants(self, value: bool) { self.set_has_dirty_descendants(value) } } diff --git a/components/script/dom/servohtmlparser.rs b/components/script/dom/servohtmlparser.rs index a1122df4ab1..22de46f4e3c 100644 --- a/components/script/dom/servohtmlparser.rs +++ b/components/script/dom/servohtmlparser.rs @@ -142,7 +142,7 @@ impl tree_builder::Tracer for Tracer { } impl JSTraceable for ServoHTMLParser { - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn trace(&self, trc: *mut JSTracer) { self.reflector_.trace(trc); diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs index a3e53f42bd3..05bd23307a2 100644 --- a/components/script/dom/virtualmethods.rs +++ b/components/script/dom/virtualmethods.rs @@ -11,6 +11,7 @@ use dom::bindings::codegen::InheritTypes::HTMLButtonElementCast; use dom::bindings::codegen::InheritTypes::HTMLCanvasElementCast; use dom::bindings::codegen::InheritTypes::HTMLElementCast; use dom::bindings::codegen::InheritTypes::HTMLFieldSetElementCast; +use dom::bindings::codegen::InheritTypes::HTMLHeadElementCast; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; use dom::bindings::codegen::InheritTypes::HTMLImageElementCast; use dom::bindings::codegen::InheritTypes::HTMLInputElementCast; @@ -39,6 +40,7 @@ use dom::htmlbuttonelement::HTMLButtonElement; use dom::htmlcanvaselement::HTMLCanvasElement; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::htmlfieldsetelement::HTMLFieldSetElement; +use dom::htmlheadelement::HTMLHeadElement; use dom::htmliframeelement::HTMLIFrameElement; use dom::htmlimageelement::HTMLImageElement; use dom::htmlinputelement::HTMLInputElement; @@ -162,6 +164,10 @@ pub fn vtable_for<'a>(node: &'a JSRef<'a, Node>) -> &'a (VirtualMethods + 'a) { let element: &'a JSRef<'a, HTMLFieldSetElement> = HTMLFieldSetElementCast::to_borrowed_ref(node).unwrap(); element as &'a (VirtualMethods + 'a) } + NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLHeadElement)) => { + let element: &'a JSRef<'a, HTMLHeadElement> = HTMLHeadElementCast::to_borrowed_ref(node).unwrap(); + element as &'a (VirtualMethods + 'a) + } NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLImageElement)) => { let element: &'a JSRef<'a, HTMLImageElement> = HTMLImageElementCast::to_borrowed_ref(node).unwrap(); element as &'a (VirtualMethods + 'a) diff --git a/components/script/dom/webidls/CanvasGradient.webidl b/components/script/dom/webidls/CanvasGradient.webidl index 1dc1ac4c1f0..fbeab843987 100644 --- a/components/script/dom/webidls/CanvasGradient.webidl +++ b/components/script/dom/webidls/CanvasGradient.webidl @@ -6,7 +6,7 @@ interface CanvasGradient { // opaque object // addColorStop should take a double - //void addColorStop(float offset, DOMString color); + void addColorStop(float offset, DOMString color); }; diff --git a/components/script/dom/webidls/CanvasRenderingContext2D.webidl b/components/script/dom/webidls/CanvasRenderingContext2D.webidl index f9a4c7b68f8..1cc40eb0f3f 100644 --- a/components/script/dom/webidls/CanvasRenderingContext2D.webidl +++ b/components/script/dom/webidls/CanvasRenderingContext2D.webidl @@ -52,8 +52,10 @@ interface CanvasRenderingContext2D { // colours and styles (see also the CanvasDrawingStyles interface) attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (default black) attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (default black) - //CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1); - //CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1); + [Throws] + CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1); + [Throws] + CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1); //CanvasPattern createPattern(CanvasImageSource image, [TreatNullAs=EmptyString] DOMString repetition); // shadows @@ -124,7 +126,7 @@ interface CanvasPathMethods { void closePath(); void moveTo(/*unrestricted*/ double x, /*unrestricted*/ double y); void lineTo(double x, double y); - //void quadraticCurveTo(double cpx, double cpy, double x, double y); + void quadraticCurveTo(double cpx, double cpy, double x, double y); void bezierCurveTo(/*unrestricted*/ double cp1x, /*unrestricted*/ double cp1y, diff --git a/components/script/dom/webidls/Document.webidl b/components/script/dom/webidls/Document.webidl index a591057fa1d..984f79eb528 100644 --- a/components/script/dom/webidls/Document.webidl +++ b/components/script/dom/webidls/Document.webidl @@ -13,6 +13,7 @@ interface Document : Node { readonly attribute DOMImplementation implementation; readonly attribute DOMString URL; + readonly attribute Element? activeElement; readonly attribute DOMString documentURI; readonly attribute DOMString compatMode; readonly attribute DOMString characterSet; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 1d91ecea59d..038ec358f73 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -407,7 +407,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> { debug!("{}", message); } - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn Gc(self) { unsafe { JS_GC(JS_GetRuntime(self.get_cx())); @@ -467,14 +467,14 @@ impl<'a, T: Reflectable> ScriptHelpers for JSRef<'a, T> { self.evaluate_script_on_global_with_result(code, "") } - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn evaluate_script_on_global_with_result(self, code: &str, filename: &str) -> JSVal { let this = self.reflector().get_jsobject(); let cx = global_object_for_js_object(this).root().r().get_cx(); let global = global_object_for_js_object(this).root().r().reflector().get_jsobject(); let code: Vec<u16> = code.as_slice().utf16_units().collect(); let mut rval = UndefinedValue(); - let filename = CString::from_slice(filename.as_bytes()); + let filename = CString::new(filename).unwrap(); with_compartment(cx, global, || { unsafe { @@ -499,7 +499,7 @@ impl<'a> WindowHelpers for JSRef<'a, Window> { *self.browser_context.borrow_mut() = None; } - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn clear_js_context_for_script_deallocation(self) { unsafe { *self.js_context.borrow_for_script_deallocation() = None; diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 36f9a0b06f7..ec65f98b7b9 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -208,7 +208,7 @@ impl XMLHttpRequest { xhr.r().process_partial_response(progress); } - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn fetch(fetch_type: &SyncOrAsync, resource_task: ResourceTask, mut load_data: LoadData, terminate_receiver: Receiver<TerminateReason>, cors_request: Result<Option<CORSRequest>,()>, gen_id: GenerationId, @@ -616,13 +616,13 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { referer_url.serialize_host().map(|ref h| buf.push_str(h.as_slice())); referer_url.port().as_ref().map(|&p| { buf.push_str(":".as_slice()); - buf.push_str(format!("{}", p).as_slice()); + buf.push_str(p.to_string().as_slice()); }); referer_url.serialize_path().map(|ref h| buf.push_str(h.as_slice())); self.request_headers.borrow_mut().set_raw("Referer".to_owned(), vec![buf.into_bytes()]); }, Ok(Some(ref req)) => self.insert_trusted_header("origin".to_owned(), - format!("{}", req.origin)), + req.origin.to_string()), _ => {} } @@ -711,7 +711,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { } } } - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] fn Response(self, cx: *mut JSContext) -> JSVal { match self.response_type.get() { _empty | Text => { diff --git a/components/script/lib.rs b/components/script/lib.rs index 901a5a19687..b4603a931b0 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -6,9 +6,8 @@ #![feature(box_syntax)] #![feature(collections)] #![feature(core)] -#![feature(hash)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(plugin)] #![feature(rustc_private)] #![feature(std_misc)] @@ -16,7 +15,7 @@ #![feature(unsafe_destructor)] #![feature(custom_attribute)] -#![deny(unsafe_blocks)] +#![deny(unsafe_code)] #![allow(non_snake_case)] #![doc="The script crate contains all matters DOM."] diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs index 261bf143ed8..ce7b75f9338 100644 --- a/components/script/parse/html.rs +++ b/components/script/parse/html.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#![allow(unsafe_blocks, unrooted_must_root)] +#![allow(unsafe_code, unrooted_must_root)] use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; @@ -30,8 +30,8 @@ use net::resource_task::{ProgressMsg, LoadResponse}; use util::task_state; use util::task_state::IN_HTML_PARSER; use std::ascii::AsciiExt; +use std::borrow::Cow; use std::old_io::{Writer, IoResult}; -use std::string::CowString; use url::Url; use html5ever::Attribute; use html5ever::serialize::{Serializable, Serializer, AttrRef}; @@ -120,7 +120,7 @@ impl<'a> TreeSink for servohtmlparser::Sink { Ok(()) } - fn parse_error(&mut self, msg: CowString<'static>) { + fn parse_error(&mut self, msg: Cow<'static, str>) { debug!("Parse error: {}", msg); } diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 7356b3d18c4..847da174eff 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -17,7 +17,7 @@ //! a page runs its course and the script task returns to processing events in the main event //! loop. -#![allow(unsafe_blocks)] +#![allow(unsafe_code)] use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState}; @@ -1252,7 +1252,11 @@ impl ScriptTask { fn handle_reflow_event(&self, pipeline_id: PipelineId) { debug!("script got reflow event"); let page = get_page(&self.root_page(), pipeline_id); - self.force_reflow(&*page, ReflowReason::ReceivedReflowEvent); + let document = page.document().root(); + let window = window_from_node(document.r()).root(); + window.r().reflow(ReflowGoal::ForDisplay, + ReflowQueryType::NoQuery, + ReflowReason::ReceivedReflowEvent); } /// Initiate a non-blocking fetch for a specified resource. Stores the InProgressLoad @@ -1334,5 +1338,5 @@ pub fn get_page(page: &Rc<Page>, pipeline_id: PipelineId) -> Rc<Page> { } fn dom_last_modified(tm: &Tm) -> String { - format!("{}", tm.to_local().strftime("%m/%d/%Y %H:%M:%S").unwrap()) + tm.to_local().strftime("%m/%d/%Y %H:%M:%S").unwrap().to_string() } diff --git a/components/script/timers.rs b/components/script/timers.rs index ea0c081d323..d0cb849b0a8 100644 --- a/components/script/timers.rs +++ b/components/script/timers.rs @@ -132,7 +132,7 @@ impl TimerManager { } } - #[allow(unsafe_blocks)] + #[allow(unsafe_code)] pub fn set_timeout_or_interval(&self, callback: TimerCallback, arguments: Vec<JSVal>, diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 2834d5d0c19..3e289cf5f2a 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -30,7 +30,7 @@ source = "git+https://github.com/tomaka/android-rs-glue#5a68056599fb498b0cf3715f [[package]] name = "azure" version = "0.1.0" -source = "git+https://github.com/servo/rust-azure#3fa95e4ce2c12234e75b7a68b1a2542e3804b67c" +source = "git+https://github.com/servo/rust-azure#110b98c7d39a275513c654644311f26b7eb75580" dependencies = [ "core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)", "core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)", @@ -686,7 +686,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "png" version = "0.1.0" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" dependencies = [ "gcc 0.3.1 (git+https://github.com/alexcrichton/gcc-rs)", "png-sys 1.6.16 (git+https://github.com/servo/rust-png)", @@ -695,7 +695,7 @@ dependencies = [ [[package]] name = "png-sys" version = "1.6.16" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" [[package]] name = "rand" @@ -707,15 +707,6 @@ dependencies = [ ] [[package]] -name = "rand" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "regex" version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -810,7 +801,7 @@ dependencies = [ "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "phf 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "phf_macros 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache_plugin 0.0.0 (git+https://github.com/servo/string-cache)", ] @@ -895,7 +886,7 @@ dependencies = [ "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", - "rand 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.1.0 (git+https://github.com/servo/rust-selectors)", diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml index bd9367ab0d6..5dfbbe8696c 100644 --- a/components/servo/Cargo.toml +++ b/components/servo/Cargo.toml @@ -34,11 +34,13 @@ default = ["glutin_app", "window"] window = ["glutin_app/window"] headless = ["glutin_app/headless"] -[profile.release] -opt-level = 3 -debug = true -rpath = false -lto = false +# Uncomment to profile on Linux: +# +# [profile.release] +# opt-level = 3 +# debug = true +# rpath = false +# lto = false [dependencies.compositing] path = "../compositing" diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 6b080f66193..0312fca761e 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -50,10 +50,6 @@ use util::taskpool::TaskPool; #[cfg(not(test))] use std::rc::Rc; -#[cfg(not(test))] -use std::sync::mpsc::channel; -#[cfg(not(test))] -use std::thread::Builder; pub struct Browser { compositor: Box<CompositorEventListener + 'static>, @@ -79,59 +75,47 @@ impl Browser { devtools::start_server(port) }); - let opts_clone = opts.clone(); - let time_profiler_chan_clone = time_profiler_chan.clone(); - let memory_profiler_chan_clone = memory_profiler_chan.clone(); - - let (result_chan, result_port) = channel(); - let compositor_proxy_for_constellation = compositor_proxy.clone_compositor_proxy(); - Builder::new() - .spawn(move || { - let opts = &opts_clone; - // Create a Servo instance. - let resource_task = new_resource_task(opts.user_agent.clone()); - // If we are emitting an output file, then we need to block on - // image load or we risk emitting an output file missing the - // image. - let image_cache_task = if opts.output_file.is_some() { - ImageCacheTask::new_sync(resource_task.clone(), shared_task_pool, - time_profiler_chan_clone.clone()) - } else { - ImageCacheTask::new(resource_task.clone(), shared_task_pool, - time_profiler_chan_clone.clone()) + // Create a Servo instance. + let resource_task = new_resource_task(opts.user_agent.clone()); + + // If we are emitting an output file, then we need to block on + // image load or we risk emitting an output file missing the + // image. + let image_cache_task = if opts.output_file.is_some() { + ImageCacheTask::new_sync(resource_task.clone(), shared_task_pool, + time_profiler_chan.clone()) + } else { + ImageCacheTask::new(resource_task.clone(), shared_task_pool, + time_profiler_chan.clone()) + }; + + let font_cache_task = FontCacheTask::new(resource_task.clone()); + let storage_task: StorageTask = StorageTaskFactory::new(); + + let constellation_chan = Constellation::<layout::layout_task::LayoutTask, + script::script_task::ScriptTask>::start( + compositor_proxy.clone_compositor_proxy(), + resource_task, + image_cache_task, + font_cache_task, + time_profiler_chan.clone(), + memory_profiler_chan.clone(), + devtools_chan, + storage_task); + + // Send the URL command to the constellation. + let cwd = env::current_dir().unwrap(); + for url in opts.urls.iter() { + let url = match url::Url::parse(&*url) { + Ok(url) => url, + Err(url::ParseError::RelativeUrlWithoutBase) + => url::Url::from_file_path(&*cwd.join(&*url)).unwrap(), + Err(_) => panic!("URL parsing failed"), }; - let font_cache_task = FontCacheTask::new(resource_task.clone()); - let storage_task: StorageTask = StorageTaskFactory::new(); - let constellation_chan = Constellation::<layout::layout_task::LayoutTask, - script::script_task::ScriptTask>::start( - compositor_proxy_for_constellation, - resource_task, - image_cache_task, - font_cache_task, - time_profiler_chan_clone, - memory_profiler_chan_clone, - devtools_chan, - storage_task); - - // Send the URL command to the constellation. - let cwd = env::current_dir().unwrap(); - for url in opts.urls.iter() { - let url = match url::Url::parse(&*url) { - Ok(url) => url, - Err(url::ParseError::RelativeUrlWithoutBase) - => url::Url::from_file_path(&*cwd.join(&*url)).unwrap(), - Err(_) => panic!("URL parsing failed"), - }; - - let ConstellationChan(ref chan) = constellation_chan; - chan.send(ConstellationMsg::InitLoadUrl(url)).unwrap(); - } - - // Send the constallation Chan as the result - result_chan.send(constellation_chan).unwrap(); - }); - let constellation_chan = result_port.recv().unwrap(); + let ConstellationChan(ref chan) = constellation_chan; + chan.send(ConstellationMsg::InitLoadUrl(url)).unwrap(); + } debug!("preparing to enter main loop"); let compositor = CompositorTask::create(window, diff --git a/components/servo/main.rs b/components/servo/main.rs index 4bef932e562..6acaf013572 100644 --- a/components/servo/main.rs +++ b/components/servo/main.rs @@ -81,16 +81,15 @@ fn redirect_output(file_no: c_int) { let mut pipes: [c_int; 2] = [ 0, 0 ]; pipe(pipes.as_mut_ptr()); dup2(pipes[1], file_no); - let mode = CString::from_slice("r".as_bytes()); + let mode = CString::new("r").unwrap(); let input_file = FilePtr(fdopen(pipes[0], mode.as_ptr())); spawn_named("android-logger".to_owned(), move || { loop { let mut read_buffer: [u8; 1024] = mem::zeroed(); let FilePtr(input_file) = input_file; fgets(read_buffer.as_mut_ptr() as *mut i8, read_buffer.len() as i32, input_file); - let cs = CString::from_slice(&read_buffer); - match from_utf8(cs.as_bytes()) { - Ok(s) => android_glue::write_log(s), + match from_utf8(&read_buffer) { + Ok(s) => android_glue::write_log(s.trim_right_matches('\0')), _ => {} } } diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index bb9c66462a5..fdf9e9e2829 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -1109,7 +1109,7 @@ pub mod longhands { Ok(_) => return Err(()), Err(_) => break, }; - if content::counter_name_is_illegal(counter_name.as_slice()) { + if content::counter_name_is_illegal(&counter_name) { return Err(()) } let counter_delta = input.try(|input| input.expect_integer()).unwrap_or(1) as i32; @@ -2075,7 +2075,7 @@ pub mod longhands { pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> { let mut lengths = [ None, None ]; - for i in range(0, 2) { + for i in 0..2 { match specified::Length::parse_non_negative(input) { Err(()) => break, Ok(length) => lengths[i] = Some(length), diff --git a/components/util/memory.rs b/components/util/memory.rs index 487d22aab86..54fd627d5d7 100644 --- a/components/util/memory.rs +++ b/components/util/memory.rs @@ -12,8 +12,6 @@ use std::ffi::CString; #[cfg(target_os = "linux")] use std::iter::AdditiveIterator; use std::old_io::timer::sleep; -#[cfg(target_os="linux")] -use std::old_io::File; use std::mem::{size_of, transmute}; use std::ptr::null_mut; use std::sync::Arc; @@ -489,15 +487,15 @@ macro_rules! option_try( #[cfg(target_os="linux")] fn get_proc_self_statm_field(field: usize) -> Option<u64> { - let mut f = File::open(&Path::new("/proc/self/statm")); - match f.read_to_string() { - Ok(contents) => { - let s = option_try!(contents.as_slice().words().nth(field)); - let npages = option_try!(s.parse::<u64>().ok()); - Some(npages * (::std::env::page_size() as u64)) - } - Err(_) => None - } + use std::fs::File; + use std::io::Read; + + let mut f = option_try!(File::open("/proc/self/statm").ok()); + let mut contents = String::new(); + option_try!(f.read_to_string(&mut contents).ok()); + let s = option_try!(contents.words().nth(field)); + let npages = option_try!(s.parse::<u64>().ok()); + Some(npages * (::std::env::page_size() as u64)) } #[cfg(target_os="linux")] @@ -535,6 +533,8 @@ fn get_resident_segments() -> Vec<(String, u64)> { use regex::Regex; use std::collections::HashMap; use std::collections::hash_map::Entry; + use std::fs::File; + use std::io::{BufReader, BufReadExt}; // The first line of an entry in /proc/<pid>/smaps looks just like an entry // in /proc/<pid>/maps: @@ -548,8 +548,10 @@ fn get_resident_segments() -> Vec<(String, u64)> { // // Rss: 132 kB - let path = Path::new("/proc/self/smaps"); - let mut f = ::std::old_io::BufferedReader::new(File::open(&path)); + let f = match File::open("/proc/self/smaps") { + Ok(f) => BufReader::new(f), + Err(_) => return vec![], + }; let seg_re = Regex::new( r"^[:xdigit:]+-[:xdigit:]+ (....) [:xdigit:]+ [:xdigit:]+:[:xdigit:]+ \d+ +(.*)").unwrap(); diff --git a/components/util/opts.rs b/components/util/opts.rs index 19198cc84da..24b945dfcf7 100644 --- a/components/util/opts.rs +++ b/components/util/opts.rs @@ -59,6 +59,7 @@ pub struct Opts { pub nonincremental_layout: bool, pub nossl: bool, + pub userscripts: bool, pub output_file: Option<String>, pub headless: bool, @@ -180,6 +181,7 @@ pub fn default_opts() -> Opts { layout_threads: 1, nonincremental_layout: false, nossl: false, + userscripts: false, output_file: None, headless: true, hard_fail: true, @@ -220,6 +222,7 @@ pub fn from_cmdline_args(args: &[String]) -> bool { getopts::optopt("y", "layout-threads", "Number of threads to use for layout", "1"), getopts::optflag("i", "nonincremental-layout", "Enable to turn off incremental layout."), getopts::optflag("", "no-ssl", "Disables ssl certificate verification."), + getopts::optflag("", "userscripts", "Uses userscripts in resources/user-agent-js"), getopts::optflag("z", "headless", "Headless mode"), getopts::optflag("f", "hard-fail", "Exit on task failure instead of displaying about:failure"), getopts::optflagopt("", "devtools", "Start remote devtools server on port", "6000"), @@ -234,7 +237,7 @@ pub fn from_cmdline_args(args: &[String]) -> bool { let opt_match = match getopts::getopts(args, opts.as_slice()) { Ok(m) => m, Err(f) => { - args_fail(format!("{}", f).as_slice()); + args_fail(f.to_string().as_slice()); return false; } }; @@ -296,6 +299,7 @@ pub fn from_cmdline_args(args: &[String]) -> bool { let nonincremental_layout = opt_match.opt_present("i"); let nossl = opt_match.opt_present("no-ssl"); + let userscripts = opt_match.opt_present("userscripts"); let mut bubble_inline_sizes_separately = debug_options.contains(&"bubble-widths"); let trace_layout = debug_options.contains(&"trace-layout"); @@ -331,6 +335,7 @@ pub fn from_cmdline_args(args: &[String]) -> bool { layout_threads: layout_threads, nonincremental_layout: nonincremental_layout, nossl: nossl, + userscripts: userscripts, output_file: opt_match.opt_str("o"), headless: opt_match.opt_present("z"), hard_fail: opt_match.opt_present("f"), diff --git a/components/util/str.rs b/components/util/str.rs index f4e3badab15..e763215633f 100644 --- a/components/util/str.rs +++ b/components/util/str.rs @@ -326,7 +326,7 @@ impl LowercaseString { impl Str for LowercaseString { #[inline] fn as_slice(&self) -> &str { - self.inner.as_slice() + &*self.inner } } diff --git a/components/util/task_state.rs b/components/util/task_state.rs index 290f2a08166..82dffa8ee4a 100644 --- a/components/util/task_state.rs +++ b/components/util/task_state.rs @@ -26,9 +26,14 @@ bitflags! { macro_rules! task_types ( ( $( $fun:ident = $flag:ident ; )* ) => ( impl TaskState { $( + #[cfg(not(ndebug))] pub fn $fun(self) -> bool { self.contains($flag) } + #[cfg(ndebug)] + pub fn $fun(self) -> bool { + true + } )* } diff --git a/components/util/taskpool.rs b/components/util/taskpool.rs index e091d0b5d6d..ff70bc4c1c0 100644 --- a/components/util/taskpool.rs +++ b/components/util/taskpool.rs @@ -31,7 +31,7 @@ impl TaskPool { let state = Arc::new(Mutex::new(rx)); - for i in range(0, tasks) { + for i in 0..tasks { let state = state.clone(); spawn_named( format!("TaskPoolWorker {}/{}", i+1, tasks), diff --git a/components/util/time.rs b/components/util/time.rs index c9cf32c0617..1cae21719d4 100644 --- a/components/util/time.rs +++ b/components/util/time.rs @@ -44,7 +44,7 @@ impl Formatable for Option<TimerMetadata> { match self { // TODO(cgaebel): Center-align in the format strings as soon as rustc supports it. &Some(ref meta) => { - let url = meta.url.as_slice(); + let url = &*meta.url; let url = if url.len() > 30 { &url[..30] } else { @@ -243,7 +243,7 @@ impl TimeProfiler { if data_len > 0 { let (mean, median, min, max) = (data.iter().map(|&x|x).sum() / (data_len as f64), - data.as_slice()[data_len / 2], + data[data_len / 2], data.iter().fold(f64::INFINITY, |a, &b| a.min(b)), data.iter().fold(-f64::INFINITY, |a, &b| a.max(b))); println!("{:-35}{} {:15.4} {:15.4} {:15.4} {:15.4} {:15}", diff --git a/components/util/workqueue.rs b/components/util/workqueue.rs index b1709cdf6e0..c368e56e930 100644 --- a/components/util/workqueue.rs +++ b/components/util/workqueue.rs @@ -231,7 +231,7 @@ impl<QueueData: Send, WorkData: Send> WorkQueue<QueueData, WorkData> { // Set up data structures. let (supervisor_chan, supervisor_port) = channel(); let (mut infos, mut threads) = (vec!(), vec!()); - for i in range(0, thread_count) { + for i in 0..thread_count { let (worker_chan, worker_port) = channel(); let pool = BufferPool::new(); let (worker, thief) = pool.deque(); @@ -250,8 +250,8 @@ impl<QueueData: Send, WorkData: Send> WorkQueue<QueueData, WorkData> { } // Connect workers to one another. - for i in range(0, thread_count) { - for j in range(0, thread_count) { + for i in 0..thread_count { + for j in 0..thread_count { if i != j { threads[i].other_deques.push(infos[j].thief.clone()) } @@ -312,7 +312,7 @@ impl<QueueData: Send, WorkData: Send> WorkQueue<QueueData, WorkData> { } // Get our deques back. - for _ in range(0, self.workers.len()) { + for _ in 0..self.workers.len() { match self.port.recv().unwrap() { SupervisorMsg::ReturnDeque(index, deque) => self.workers[index].deque = Some(deque), SupervisorMsg::Finished => panic!("unexpected finished message!"), diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 83edef2900c..555abedf97c 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -36,7 +36,7 @@ source = "git+https://github.com/tomaka/android-rs-glue#5a68056599fb498b0cf3715f [[package]] name = "azure" version = "0.1.0" -source = "git+https://github.com/servo/rust-azure#3fa95e4ce2c12234e75b7a68b1a2542e3804b67c" +source = "git+https://github.com/servo/rust-azure#110b98c7d39a275513c654644311f26b7eb75580" dependencies = [ "core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)", "core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)", @@ -692,7 +692,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "png" version = "0.1.0" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" dependencies = [ "gcc 0.3.1 (git+https://github.com/alexcrichton/gcc-rs)", "png-sys 1.6.16 (git+https://github.com/servo/rust-png)", @@ -701,7 +701,7 @@ dependencies = [ [[package]] name = "png-sys" version = "1.6.16" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" [[package]] name = "rand" @@ -713,15 +713,6 @@ dependencies = [ ] [[package]] -name = "rand" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "regex" version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -835,7 +826,7 @@ dependencies = [ "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "phf 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "phf_macros 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache_plugin 0.0.0 (git+https://github.com/servo/string-cache)", ] @@ -920,7 +911,7 @@ dependencies = [ "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", - "rand 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.1.0 (git+https://github.com/servo/rust-selectors)", diff --git a/ports/cef/command_line.rs b/ports/cef/command_line.rs index 6b0d91d4130..39b08869a9f 100644 --- a/ports/cef/command_line.rs +++ b/ports/cef/command_line.rs @@ -67,7 +67,7 @@ pub extern "C" fn command_line_get_switch_value(cmd: *mut cef_command_line_t, na if o.as_slice().starts_with(opt.as_slice()) { let mut string = mem::uninitialized(); let arg = o[opt.len() + 1..].as_bytes(); - let c_str = ffi::CString::from_slice(arg); + let c_str = ffi::CString::new(arg).unwrap(); cef_string_utf16_set(c_str.as_bytes().as_ptr() as *const _, arg.len() as size_t, &mut string, diff --git a/ports/cef/window.rs b/ports/cef/window.rs index 786d6d64f6d..330e9491cbb 100644 --- a/ports/cef/window.rs +++ b/ports/cef/window.rs @@ -47,7 +47,7 @@ fn load_gl() { gl::load_with(|s| { unsafe { - let c_str = CString::from_slice(s.as_bytes()); + let c_str = CString::new(s).unwrap(); dlsym(RTLD_DEFAULT, c_str.as_ptr()) as *const c_void } }); @@ -61,7 +61,7 @@ fn load_gl() { gl::load_with(|s| { unsafe { - let c_str = CString::from_slice(s.as_bytes()); + let c_str = CString::new(s).unwrap(); glXGetProcAddress(c_str.as_ptr()) as *const c_void } }); diff --git a/ports/glutin/lib.rs b/ports/glutin/lib.rs index c64ff2a4e91..ccf9570569c 100644 --- a/ports/glutin/lib.rs +++ b/ports/glutin/lib.rs @@ -5,7 +5,6 @@ //! A simple application that uses glutin to open a window for Servo to display in. #![feature(int_uint)] -#![feature(core)] #![feature(box_syntax)] #[macro_use] extern crate bitflags; diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index 5dedff7b46a..dc15454ba26 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -447,7 +447,7 @@ impl WindowMethods for Window { fn set_page_title(&self, title: Option<String>) { let title = match title { - Some(ref title) if title.len() > 0 => title.as_slice(), + Some(ref title) if title.len() > 0 => &**title, _ => "untitled", }; let title = format!("{} - Servo", title); diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 9ab2732a7c5..47ec887aa88 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "azure" version = "0.1.0" -source = "git+https://github.com/servo/rust-azure#3fa95e4ce2c12234e75b7a68b1a2542e3804b67c" +source = "git+https://github.com/servo/rust-azure#110b98c7d39a275513c654644311f26b7eb75580" dependencies = [ "core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)", "core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)", @@ -616,7 +616,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "png" version = "0.1.0" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" dependencies = [ "gcc 0.3.1 (git+https://github.com/alexcrichton/gcc-rs)", "png-sys 1.6.16 (git+https://github.com/servo/rust-png)", @@ -625,7 +625,7 @@ dependencies = [ [[package]] name = "png-sys" version = "1.6.16" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" [[package]] name = "rand" @@ -637,15 +637,6 @@ dependencies = [ ] [[package]] -name = "rand" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "regex" version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -758,7 +749,7 @@ dependencies = [ "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "phf 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "phf_macros 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache_plugin 0.0.0 (git+https://github.com/servo/string-cache)", ] @@ -835,7 +826,7 @@ dependencies = [ "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", - "rand 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.1.0 (git+https://github.com/servo/rust-selectors)", diff --git a/resources/user-agent-js/00.example.js b/resources/user-agent-js/00.example.js new file mode 100644 index 00000000000..c024b0f6a48 --- /dev/null +++ b/resources/user-agent-js/00.example.js @@ -0,0 +1,5 @@ +// Keep files in this directory which you would like executed before +// any other script when servo is run with `--userscripts` +// Files are sorted alphabetically. When committing polyfills +// order them with numbers, e.g. `01.innerhtml.js` will be executed before +// `05.jquery.js` diff --git a/tests/content/test_document_activeElement.html b/tests/content/test_document_activeElement.html new file mode 100644 index 00000000000..8cce6cfa210 --- /dev/null +++ b/tests/content/test_document_activeElement.html @@ -0,0 +1,19 @@ +<!doctype html> +<html> + <head > + <title></title> + <script src="harness.js"></script> + </head> + <body> + <input id="foo" type="text"></input> + <script> + is_not(document.activeElement, null, "test_1.1, document.activeElement"); + is(document.activeElement, document.body, "test_1.2, document.activeElement"); + + //TODO: uncomment following lines when focus() method will be available + //document.getElementById('foo').focus(); + is_not(document.activeElement, null, "test_2.1, document.activeElement"); + //is(document.activeElement, document.getElementById("foo"), "test_2.2, document.activeElement"); + </script> + </body> +</html> diff --git a/tests/contenttest.rs b/tests/contenttest.rs index 7e8bb71fd66..77210a8dbd8 100644 --- a/tests/contenttest.rs +++ b/tests/contenttest.rs @@ -45,7 +45,7 @@ fn parse_config(args: Vec<String>) -> Config { let opts = vec!(reqopt("s", "source-dir", "source-dir", "source-dir")); let matches = match getopts(args, opts.as_slice()) { Ok(m) => m, - Err(f) => panic!(format!("{}", f)) + Err(f) => panic!(f.to_string()) }; Config { @@ -73,7 +73,7 @@ fn find_tests(config: Config) -> Vec<TestDescAndFn> { _ => panic!("Error reading directory."), }; files.retain(|file| file.extension_str() == Some("html") ); - return files.iter().map(|file| make_test(format!("{}", file.display()))).collect(); + return files.iter().map(|file| make_test(file.display().to_string())).collect(); } fn make_test(file: String) -> TestDescAndFn { diff --git a/tests/ref/basic.list b/tests/ref/basic.list index ea43fdd0d20..d4f0bde917a 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -65,7 +65,9 @@ flaky_cpu == append_style_a.html append_style_b.html == box_sizing_sanity_check_a.html box_sizing_sanity_check_ref.html == br.html br-ref.html == canvas_as_block_element_a.html canvas_as_block_element_ref.html +== canvas_linear_gradient_a.html canvas_linear_gradient_ref.html == canvas_lineto_a.html canvas_lineto_ref.html +== canvas_radial_gradient_a.html canvas_radial_gradient_ref.html == canvas_transform_a.html canvas_transform_ref.html == case-insensitive-font-family.html case-insensitive-font-family-ref.html == clear_generated_content_table_a.html clear_generated_content_table_ref.html diff --git a/tests/ref/canvas_linear_gradient_a.html b/tests/ref/canvas_linear_gradient_a.html new file mode 100644 index 00000000000..5fc3f259e0a --- /dev/null +++ b/tests/ref/canvas_linear_gradient_a.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<html> +<body> +<style> + html, body { + margin: 0; + padding: 0; + } + canvas { + background-color: green; + } +</style> + +<canvas id="c" width="200" height="200"> +Your browser does not support the HTML5 canvas tag.</canvas> + +<script> +var c = document.getElementById("c"); +var ctx = c.getContext("2d"); + +var grd = ctx.createLinearGradient(10, 0, 190, 0); +grd.addColorStop(0, "red"); +grd.addColorStop(1, "yellow"); + +ctx.fillStyle = grd; +ctx.fillRect(10, 10, 180, 180); +</script> + +</body> +</html> diff --git a/tests/ref/canvas_linear_gradient_ref.html b/tests/ref/canvas_linear_gradient_ref.html new file mode 100644 index 00000000000..b820555a7d3 --- /dev/null +++ b/tests/ref/canvas_linear_gradient_ref.html @@ -0,0 +1,23 @@ +<!DOCTYPE html> +<html> +<body> +<style> + html, body { + margin: 0; + padding: 0; + } + section, div { + width: 180px; + height: 180px; + } + section { + padding: 10px; + background-color: green; + } + div { + background: linear-gradient(to right, red, yellow); + } +</style> +<section><div></div></section> +</body> +</html> diff --git a/tests/ref/canvas_radial_gradient.png b/tests/ref/canvas_radial_gradient.png Binary files differnew file mode 100644 index 00000000000..0192aa2b240 --- /dev/null +++ b/tests/ref/canvas_radial_gradient.png diff --git a/tests/ref/canvas_radial_gradient_a.html b/tests/ref/canvas_radial_gradient_a.html new file mode 100644 index 00000000000..7fe5f8e4186 --- /dev/null +++ b/tests/ref/canvas_radial_gradient_a.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<html> +<body> +<style> + html, body { + margin: 0; + padding: 0; + } + canvas { + background-color: green; + } +</style> + +<canvas id="c" width="200" height="200"> +Your browser does not support the HTML5 canvas tag.</canvas> + +<script> +var c = document.getElementById("c"); +var ctx = c.getContext("2d"); + +var grd = ctx.createRadialGradient(60, 60, 0, 60, 60, 150); +grd.addColorStop(0, "red"); +grd.addColorStop(1, "yellow"); + +ctx.fillStyle = grd; +ctx.fillRect(10, 10, 180, 180); +</script> + +</body> +</html> diff --git a/tests/ref/canvas_radial_gradient_ref.html b/tests/ref/canvas_radial_gradient_ref.html new file mode 100644 index 00000000000..4376341d31b --- /dev/null +++ b/tests/ref/canvas_radial_gradient_ref.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html> +<body> +<style> + html, body { + margin: 0; + padding: 0; + } +</style> +<img src="canvas_radial_gradient.png"> +</body> +</html> diff --git a/tests/reftest.rs b/tests/reftest.rs index 978a8f45318..4ce8a96cdcb 100644 --- a/tests/reftest.rs +++ b/tests/reftest.rs @@ -7,25 +7,24 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(collections, core, env, io, hash, os, path, std_misc, test)] +#![feature(collections, exit_status, fs_walk, io, old_io, path, path_ext, std_misc, test)] #[macro_use] extern crate bitflags; extern crate png; extern crate test; extern crate url; -use std::ascii::AsciiExt; use std::env; -use std::old_io as io; -use std::old_io::{File, Reader, Command, IoResult}; -use std::old_io::process::ExitStatus; -use std::old_io::fs::PathExtensions; -use std::old_path::Path; +use std::ffi::OsStr; +use std::fs::{PathExt, File, walk_dir}; +use std::io::Read; +use std::old_io::{Reader, IoResult}; +use std::path::{Path, PathBuf}; +use std::process::{Command, Stdio}; use std::thunk::Thunk; use test::{AutoColor, DynTestName, DynTestFn, TestDesc, TestOpts, TestDescAndFn, ShouldPanic}; use test::run_tests_console; use url::Url; - bitflags!( flags RenderMode: u32 { const CPU_RENDERING = 0x00000001, @@ -39,7 +38,7 @@ bitflags!( fn main() { let args: Vec<String> = env::args().collect(); - let mut parts = args.tail().split(|e| "--" == e.as_slice()); + let mut parts = args.tail().split(|e| &**e == "--"); let harness_args = parts.next().unwrap(); // .split() is never empty let servo_args = parts.next().unwrap_or(&[]); @@ -50,7 +49,7 @@ fn main() { [ref render_mode_string, ref base_path, ref testname, ..] => (render_mode_string, base_path, Some(testname.clone())), }; - let mut render_mode = match render_mode_string.as_slice() { + let mut render_mode = match &**render_mode_string { "cpu" => CPU_RENDERING, "gpu" => GPU_RENDERING, _ => panic!("First argument must specify cpu or gpu as rendering mode") @@ -68,11 +67,12 @@ fn main() { let mut all_tests = vec!(); println!("Scanning {} for manifests\n", base_path); - for file in io::fs::walk_dir(&Path::new(base_path)).unwrap() { - let maybe_extension = file.extension_str(); + for file in walk_dir(base_path).unwrap() { + let file = file.unwrap().path(); + let maybe_extension = file.extension(); match maybe_extension { Some(extension) => { - if extension.to_ascii_lowercase().as_slice() == "list" && file.is_file() { + if extension == OsStr::from_str("list") && file.is_file() { let mut tests = parse_lists(&file, servo_args, render_mode, all_tests.len()); println!("\t{} [{} tests]", file.display(), tests.len()); all_tests.append(&mut tests); @@ -106,15 +106,14 @@ fn run(test_opts: TestOpts, all_tests: Vec<TestDescAndFn>, // Verify that we're passing in valid servo arguments. Otherwise, servo // will exit before we've run any tests, and it will appear to us as if // all the tests are failing. - let mut command = match Command::new(servo_path()) - .args(servo_args.as_slice()).spawn() { + let output = match Command::new(&servo_path()).args(&servo_args).output() { Ok(p) => p, Err(e) => panic!("failed to execute process: {}", e), }; - let stderr = command.stderr.as_mut().unwrap().read_to_string().unwrap(); + let stderr = String::from_utf8(output.stderr).unwrap(); - if stderr.as_slice().contains("Unrecognized") { - println!("Servo: {}", stderr.as_slice()); + if stderr.contains("Unrecognized") { + println!("Servo: {}", stderr); return Ok(false); } @@ -130,7 +129,7 @@ enum ReftestKind { struct Reftest { name: String, kind: ReftestKind, - files: [Path; 2], + files: [PathBuf; 2], id: usize, servo_args: Vec<String>, render_mode: RenderMode, @@ -149,11 +148,14 @@ struct TestLine<'a> { fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_offset: usize) -> Vec<TestDescAndFn> { let mut tests = Vec::new(); - let contents = File::open_mode(file, io::Open, io::Read) - .and_then(|mut f| f.read_to_string()) - .ok().expect("Could not read file"); + let contents = { + let mut f = File::open(file).unwrap(); + let mut contents = String::new(); + f.read_to_string(&mut contents).unwrap(); + contents + }; - for line in contents.as_slice().lines() { + for line in contents.lines() { // ignore comments or empty lines if line.starts_with("#") || line.is_empty() { continue; @@ -183,7 +185,7 @@ fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_o part => panic!("reftest line: '{}' has invalid kind '{}'", line, part) }; - let base = Path::new(env::current_dir().unwrap().to_str().unwrap()).join(file.dir_path()); + let base = env::current_dir().unwrap().join(file.parent().unwrap()); let file_left = base.join(test_line.file_left); let file_right = base.join(test_line.file_right); @@ -244,16 +246,18 @@ fn make_test(reftest: Reftest) -> TestDescAndFn { fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec<u8>) { let png_filename = format!("/tmp/servo-reftest-{:06}-{}.png", reftest.id, side); - let mut command = Command::new(servo_path()); + let mut command = Command::new(&servo_path()); command + .stdout(Stdio::null()) + .stderr(Stdio::null()) .args(&reftest.servo_args[..]) // Allows pixel perfect rendering of Ahem font for reftests. .arg("-Z") .arg("disable-text-aa") - .args(["-f", "-o"].as_slice()) - .arg(png_filename.as_slice()) - .arg({ - let mut url = Url::from_file_path(&reftest.files[side]).unwrap(); + .args(&["-f", "-o"]) + .arg(&png_filename) + .arg(&{ + let mut url = Url::from_file_path(&*reftest.files[side]).unwrap(); url.fragment = reftest.fragment_identifier.clone(); url.to_string() }); @@ -275,10 +279,9 @@ fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec<u8>) { Ok(status) => status, Err(e) => panic!("failed to execute process: {}", e), }; - assert_eq!(retval, ExitStatus(0)); + assert!(retval.success()); - let path = png_filename.parse::<Path>().unwrap(); - let image = png::load_png(&path).unwrap(); + let image = png::load_png(&png_filename).unwrap(); let rgba8_bytes = match image.pixels { png::PixelsByColorType::RGBA8(pixels) => pixels, _ => panic!(), @@ -286,9 +289,9 @@ fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec<u8>) { (image.width, image.height, rgba8_bytes) } -fn servo_path() -> Path { +fn servo_path() -> PathBuf { let current_exe = env::current_exe().ok().expect("Could not locate current executable"); - Path::new(current_exe.to_str().unwrap()).dir_path().join("servo") + current_exe.parent().unwrap().join("servo") } fn check_reftest(reftest: Reftest) { @@ -319,8 +322,7 @@ fn check_reftest(reftest: Reftest) { }).collect::<Vec<u8>>(); if pixels.iter().any(|&a| a < 255) { - let output_str = format!("/tmp/servo-reftest-{:06}-diff.png", reftest.id); - let output = output_str.parse::<Path>().unwrap(); + let output = format!("/tmp/servo-reftest-{:06}-diff.png", reftest.id); let mut img = png::Image { width: left_width, @@ -331,8 +333,8 @@ fn check_reftest(reftest: Reftest) { assert!(res.is_ok()); match (reftest.kind, reftest.is_flaky) { - (ReftestKind::Same, true) => println!("flaky test - rendering difference: {}", output_str), - (ReftestKind::Same, false) => panic!("rendering difference: {}", output_str), + (ReftestKind::Same, true) => println!("flaky test - rendering difference: {}", output), + (ReftestKind::Same, false) => panic!("rendering difference: {}", output), (ReftestKind::Different, _) => {} // Result was different and that's what was expected } } else { diff --git a/tests/wpt/metadata/2dcontext/conformance-requirements/2d.missingargs.html.ini b/tests/wpt/metadata/2dcontext/conformance-requirements/2d.missingargs.html.ini deleted file mode 100644 index ce1cd9d0ff6..00000000000 --- a/tests/wpt/metadata/2dcontext/conformance-requirements/2d.missingargs.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.missingargs.html] - type: testharness - [Missing arguments cause TypeError] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.empty.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.empty.html.ini deleted file mode 100644 index 6be9b274256..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.empty.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.empty.html] - type: testharness - [Canvas test: 2d.gradient.empty] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.alpha.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.alpha.html.ini deleted file mode 100644 index 2da3282dd8e..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.alpha.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.interpolate.alpha.html] - type: testharness - [Canvas test: 2d.gradient.interpolate.alpha] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.colour.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.colour.html.ini deleted file mode 100644 index ec79d4dbc5f..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.colour.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.interpolate.colour.html] - type: testharness - [Canvas test: 2d.gradient.interpolate.colour] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.multiple.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.multiple.html.ini deleted file mode 100644 index c8562bae0e3..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.multiple.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.interpolate.multiple.html] - type: testharness - [Canvas test: 2d.gradient.interpolate.multiple] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.outside.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.outside.html.ini deleted file mode 100644 index 8cba4c2b674..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.outside.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.interpolate.outside.html] - type: testharness - [Canvas test: 2d.gradient.interpolate.outside] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.overlap.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.overlap.html.ini deleted file mode 100644 index a89907b67db..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.overlap.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.interpolate.overlap.html] - type: testharness - [Canvas test: 2d.gradient.interpolate.overlap] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.overlap2.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.overlap2.html.ini deleted file mode 100644 index af56df25104..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.overlap2.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.interpolate.overlap2.html] - type: testharness - [Canvas test: 2d.gradient.interpolate.overlap2] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.solid.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.solid.html.ini deleted file mode 100644 index ce470eb581d..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.solid.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.interpolate.solid.html] - type: testharness - [Canvas test: 2d.gradient.interpolate.solid] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.vertical.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.vertical.html.ini deleted file mode 100644 index 6d1e4837b87..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.interpolate.vertical.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.interpolate.vertical.html] - type: testharness - [Canvas test: 2d.gradient.interpolate.vertical] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.linear.transform.1.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.linear.transform.1.html.ini deleted file mode 100644 index de4f2bddebe..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.linear.transform.1.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.linear.transform.1.html] - type: testharness - [Linear gradient coordinates are relative to the coordinate space at the time of filling] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.linear.transform.2.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.linear.transform.2.html.ini deleted file mode 100644 index d7de096f800..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.linear.transform.2.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.linear.transform.2.html] - type: testharness - [Linear gradient coordinates are relative to the coordinate space at the time of filling] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.linear.transform.3.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.linear.transform.3.html.ini deleted file mode 100644 index 8f6a7dd384f..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.linear.transform.3.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.linear.transform.3.html] - type: testharness - [Linear gradient transforms do not experience broken caching effects] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.crosscanvas.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.crosscanvas.html.ini deleted file mode 100644 index 19d23d2d188..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.crosscanvas.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.object.crosscanvas.html] - type: testharness - [Canvas test: 2d.gradient.object.crosscanvas] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.current.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.current.html.ini deleted file mode 100644 index c849f911b7f..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.current.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.object.current.html] - type: testharness - [Canvas test: 2d.gradient.object.current] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.return.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.return.html.ini deleted file mode 100644 index 471d071ccf1..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.return.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.object.return.html] - type: testharness - [createLinearGradient() and createRadialGradient() returns objects implementing CanvasGradient] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.type.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.type.html.ini deleted file mode 100644 index 0f94a1ea962..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.object.type.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.object.type.html] - type: testharness - [window.CanvasGradient exists and has the right properties] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.behind.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.behind.html.ini deleted file mode 100644 index db248f89ae4..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.behind.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.cone.behind.html] - type: testharness - [Canvas test: 2d.gradient.radial.cone.behind] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.beside.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.beside.html.ini deleted file mode 100644 index 2283a856053..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.beside.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.cone.beside.html] - type: testharness - [Canvas test: 2d.gradient.radial.cone.beside] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.bottom.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.bottom.html.ini deleted file mode 100644 index fa196ab8fce..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.bottom.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.cone.bottom.html] - type: testharness - [Canvas test: 2d.gradient.radial.cone.bottom] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.cylinder.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.cylinder.html.ini deleted file mode 100644 index 5280a598777..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.cylinder.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.cone.cylinder.html] - type: testharness - [Canvas test: 2d.gradient.radial.cone.cylinder] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.front.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.front.html.ini deleted file mode 100644 index ba4f90807cf..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.front.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.cone.front.html] - type: testharness - [Canvas test: 2d.gradient.radial.cone.front] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.shape1.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.shape1.html.ini deleted file mode 100644 index 7f85b8a7964..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.shape1.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.cone.shape1.html] - type: testharness - [Canvas test: 2d.gradient.radial.cone.shape1] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.shape2.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.shape2.html.ini deleted file mode 100644 index ac163231f8b..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.shape2.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.cone.shape2.html] - type: testharness - [Canvas test: 2d.gradient.radial.cone.shape2] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.top.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.top.html.ini deleted file mode 100644 index 0b5e6257889..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.cone.top.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.cone.top.html] - type: testharness - [Canvas test: 2d.gradient.radial.cone.top] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.equal.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.equal.html.ini deleted file mode 100644 index 32ab0251122..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.equal.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.equal.html] - type: testharness - [Canvas test: 2d.gradient.radial.equal] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.inside1.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.inside1.html.ini deleted file mode 100644 index 008c2bdcf2b..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.inside1.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.inside1.html] - type: testharness - [Canvas test: 2d.gradient.radial.inside1] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.inside2.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.inside2.html.ini deleted file mode 100644 index 4a877166ec5..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.inside2.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.inside2.html] - type: testharness - [Canvas test: 2d.gradient.radial.inside2] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.inside3.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.inside3.html.ini deleted file mode 100644 index efb6671ff96..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.inside3.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.inside3.html] - type: testharness - [Canvas test: 2d.gradient.radial.inside3] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.outside1.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.outside1.html.ini deleted file mode 100644 index f04fb4e2e55..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.outside1.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.outside1.html] - type: testharness - [Canvas test: 2d.gradient.radial.outside1] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.outside2.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.outside2.html.ini deleted file mode 100644 index ae7beeb2c2d..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.outside2.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.outside2.html] - type: testharness - [Canvas test: 2d.gradient.radial.outside2] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.touch1.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.touch1.html.ini deleted file mode 100644 index df30497660a..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.touch1.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.touch1.html] - type: testharness - [Canvas test: 2d.gradient.radial.touch1] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.touch2.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.touch2.html.ini deleted file mode 100644 index 53c8947f53c..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.touch2.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.touch2.html] - type: testharness - [Canvas test: 2d.gradient.radial.touch2] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.touch3.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.touch3.html.ini deleted file mode 100644 index 354a08d0728..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.touch3.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.touch3.html] - type: testharness - [Canvas test: 2d.gradient.radial.touch3] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.transform.1.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.transform.1.html.ini deleted file mode 100644 index 3110be91ce8..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.transform.1.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.transform.1.html] - type: testharness - [Radial gradient coordinates are relative to the coordinate space at the time of filling] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.transform.2.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.transform.2.html.ini deleted file mode 100644 index 047159c7a5f..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.transform.2.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.transform.2.html] - type: testharness - [Radial gradient coordinates are relative to the coordinate space at the time of filling] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.transform.3.html.ini b/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.transform.3.html.ini deleted file mode 100644 index a19423b6ad4..00000000000 --- a/tests/wpt/metadata/2dcontext/fill-and-stroke-styles/2d.gradient.radial.transform.3.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.gradient.radial.transform.3.html] - type: testharness - [Radial gradient transforms do not experience broken caching effects] - expected: FAIL - diff --git a/tests/wpt/metadata/2dcontext/shadows/2d.shadow.gradient.transparent.1.html.ini b/tests/wpt/metadata/2dcontext/shadows/2d.shadow.gradient.transparent.1.html.ini deleted file mode 100644 index f52099df851..00000000000 --- a/tests/wpt/metadata/2dcontext/shadows/2d.shadow.gradient.transparent.1.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[2d.shadow.gradient.transparent.1.html] - type: testharness - [Shadows are not drawn for transparent gradient fills] - expected: FAIL - diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 8f47201cb86..a269b210e2f 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -30,9 +30,6 @@ [Document interface: operation writeln(DOMString)] expected: FAIL - [Document interface: attribute activeElement] - expected: FAIL - [Document interface: operation hasFocus()] expected: FAIL @@ -1125,9 +1122,6 @@ [Document interface: document.implementation.createDocument(null, "", null) must inherit property "defaultView" with the proper type (59)] expected: FAIL - [Document interface: document.implementation.createDocument(null, "", null) must inherit property "activeElement" with the proper type (60)] - expected: FAIL - [Document interface: document.implementation.createDocument(null, "", null) must inherit property "hasFocus" with the proper type (61)] expected: FAIL @@ -6984,12 +6978,6 @@ [CanvasRenderingContext2D interface: attribute imageSmoothingEnabled] expected: FAIL - [CanvasRenderingContext2D interface: operation createLinearGradient(double,double,double,double)] - expected: FAIL - - [CanvasRenderingContext2D interface: operation createRadialGradient(double,double,double,double,double,double)] - expected: FAIL - [CanvasRenderingContext2D interface: operation createPattern(CanvasImageSource,DOMString)] expected: FAIL @@ -7116,9 +7104,6 @@ [CanvasRenderingContext2D interface: attribute direction] expected: FAIL - [CanvasRenderingContext2D interface: operation quadraticCurveTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double)] - expected: FAIL - [CanvasRenderingContext2D interface: operation arcTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double)] expected: FAIL @@ -7176,18 +7161,6 @@ [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "fillStyle" with the proper type (17)] expected: FAIL - [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "createLinearGradient" with the proper type (18)] - expected: FAIL - - [CanvasRenderingContext2D interface: calling createLinearGradient(double,double,double,double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError] - expected: FAIL - - [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "createRadialGradient" with the proper type (19)] - expected: FAIL - - [CanvasRenderingContext2D interface: calling createRadialGradient(double,double,double,double,double,double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError] - expected: FAIL - [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "createPattern" with the proper type (20)] expected: FAIL @@ -7374,12 +7347,6 @@ [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "direction" with the proper type (69)] expected: FAIL - [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "quadraticCurveTo" with the proper type (73)] - expected: FAIL - - [CanvasRenderingContext2D interface: calling quadraticCurveTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError] - expected: FAIL - [CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "arcTo" with the proper type (75)] expected: FAIL @@ -7407,9 +7374,6 @@ [CanvasGradient interface object length] expected: FAIL - [CanvasGradient interface: operation addColorStop(double,DOMString)] - expected: FAIL - [CanvasPattern interface object length] expected: FAIL diff --git a/tests/wpt/metadata/html/semantics/disabled-elements/disabledElement.html.ini b/tests/wpt/metadata/html/semantics/disabled-elements/disabledElement.html.ini index badb1eabe69..734ef783331 100644 --- a/tests/wpt/metadata/html/semantics/disabled-elements/disabledElement.html.ini +++ b/tests/wpt/metadata/html/semantics/disabled-elements/disabledElement.html.ini @@ -1,8 +1,5 @@ [disabledElement.html] type: testharness - [The body element must be the active element if no element is focused] - expected: FAIL - [A disabled <button> should not be focusable] expected: FAIL diff --git a/tests/wpt/metadata/html/semantics/embedded-content/the-canvas-element/initial.reset.gradient.html.ini b/tests/wpt/metadata/html/semantics/embedded-content/the-canvas-element/initial.reset.gradient.html.ini deleted file mode 100644 index c2652dc9ee6..00000000000 --- a/tests/wpt/metadata/html/semantics/embedded-content/the-canvas-element/initial.reset.gradient.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[initial.reset.gradient.html] - type: testharness - [Resetting the canvas state does not invalidate any existing gradients] - expected: FAIL - |