diff --git a/Makefile.in b/Makefile.in index cd174129f93..8274db6eadc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -230,6 +230,8 @@ package: servo else +bindings: $(AUTOGEN_SRC_servo) + .PHONY: package package: diff --git a/src/cairo b/src/cairo index 95b4bd33554..c6402195adc 160000 --- a/src/cairo +++ b/src/cairo @@ -1 +1 @@ -Subproject commit 95b4bd335549b74c4d50f34ecb074122572291ea +Subproject commit c6402195adc8830d4b2eba3f755044842edb3ae6 diff --git a/src/mozjs b/src/mozjs index 6fc47a3120d..19a4939e13f 160000 --- a/src/mozjs +++ b/src/mozjs @@ -1 +1 @@ -Subproject commit 6fc47a3120d652e68522a0f1dfe85af0c7e23145 +Subproject commit 19a4939e13f2387cb7831623480d91301092c202 diff --git a/src/rust b/src/rust index 0ad3a110be9..783392f70fc 160000 --- a/src/rust +++ b/src/rust @@ -1 +1 @@ -Subproject commit 0ad3a110be9070b87ecd7e1c71d20a02660d8959 +Subproject commit 783392f70fcfd6770782796bef06bed47043cabf diff --git a/src/rust-azure b/src/rust-azure index a016a795bb9..5fc77111bbb 160000 --- a/src/rust-azure +++ b/src/rust-azure @@ -1 +1 @@ -Subproject commit a016a795bb9a021c06a665563c4aaf793b0b97ca +Subproject commit 5fc77111bbb003fbcd9ba15e4813b31eccf6943c diff --git a/src/rust-cairo b/src/rust-cairo index 252672fd902..861292b11bd 160000 --- a/src/rust-cairo +++ b/src/rust-cairo @@ -1 +1 @@ -Subproject commit 252672fd902723cca59423a135c829a70a0b3f0b +Subproject commit 861292b11bd66a654286c3731e5d1054da4e5cc4 diff --git a/src/rust-cocoa b/src/rust-cocoa index c8cf6f388da..12a7bb3fde3 160000 --- a/src/rust-cocoa +++ b/src/rust-cocoa @@ -1 +1 @@ -Subproject commit c8cf6f388da1446b267014154b36af85a752a438 +Subproject commit 12a7bb3fde3941be1050d46c495fb0fb23aa1880 diff --git a/src/rust-core-foundation b/src/rust-core-foundation index 363b2f0e6b0..2a69e1c0eeb 160000 --- a/src/rust-core-foundation +++ b/src/rust-core-foundation @@ -1 +1 @@ -Subproject commit 363b2f0e6b064e7a6fbf850706fe62597af28f03 +Subproject commit 2a69e1c0eeb30d659f784e00224647d6a40404df diff --git a/src/rust-core-graphics b/src/rust-core-graphics index bc86ccb7737..12a5b33342f 160000 --- a/src/rust-core-graphics +++ b/src/rust-core-graphics @@ -1 +1 @@ -Subproject commit bc86ccb773758b3e2ad7f689b67f77165048b9e6 +Subproject commit 12a5b33342fb0efdff9998838542026dd08f1fe9 diff --git a/src/rust-core-text b/src/rust-core-text index 97949ebdfd8..99d5af7047c 160000 --- a/src/rust-core-text +++ b/src/rust-core-text @@ -1 +1 @@ -Subproject commit 97949ebdfd8adb13eea639f1799a3bbb93868512 +Subproject commit 99d5af7047c219feaf7fa6d723dadfde0545b686 diff --git a/src/rust-css b/src/rust-css index 9f406c72c22..200034f4935 160000 --- a/src/rust-css +++ b/src/rust-css @@ -1 +1 @@ -Subproject commit 9f406c72c22fb68691d8d137df679a7d047ec135 +Subproject commit 200034f493565ddfc12c8899b2615aa113a74521 diff --git a/src/rust-fontconfig b/src/rust-fontconfig index 260f7062a4c..2cdbb170c35 160000 --- a/src/rust-fontconfig +++ b/src/rust-fontconfig @@ -1 +1 @@ -Subproject commit 260f7062a4cae7e3575a3cf97d1119bc076ab221 +Subproject commit 2cdbb170c3591c08a872e30584fcaf490680a100 diff --git a/src/rust-freetype b/src/rust-freetype index b414d3bf445..6852c4a04e4 160000 --- a/src/rust-freetype +++ b/src/rust-freetype @@ -1 +1 @@ -Subproject commit b414d3bf445ac63860a9cf44532280228f001a2b +Subproject commit 6852c4a04e44d29dc410666ef551654a7e181d6c diff --git a/src/rust-geom b/src/rust-geom index cdc1b0b8d17..89e5937773c 160000 --- a/src/rust-geom +++ b/src/rust-geom @@ -1 +1 @@ -Subproject commit cdc1b0b8d173be4e1c79961742a367dac39d7d86 +Subproject commit 89e5937773c265b0fd58ed0cedac777442f5c81c diff --git a/src/rust-glut b/src/rust-glut index 337bc5cb49b..e094a025477 160000 --- a/src/rust-glut +++ b/src/rust-glut @@ -1 +1 @@ -Subproject commit 337bc5cb49b2a518527d62cd9af08e169f4f6456 +Subproject commit e094a0254778c042229ea031cb9f2b4821e5ed93 diff --git a/src/rust-harfbuzz b/src/rust-harfbuzz index e416f03f489..e1967e56561 160000 --- a/src/rust-harfbuzz +++ b/src/rust-harfbuzz @@ -1 +1 @@ -Subproject commit e416f03f4898825bc8f24cfd890004a130e2457b +Subproject commit e1967e565616a973c4a4ab398cc31bb4142bf35a diff --git a/src/rust-http-client b/src/rust-http-client index 886cf481cbf..26b20203db9 160000 --- a/src/rust-http-client +++ b/src/rust-http-client @@ -1 +1 @@ -Subproject commit 886cf481cbf9c9eedfbab0344e5f887c11220497 +Subproject commit 26b20203db925e11cb5885da15a236067398c1a6 diff --git a/src/rust-hubbub b/src/rust-hubbub index 8e04c939c72..9045a321b5d 160000 --- a/src/rust-hubbub +++ b/src/rust-hubbub @@ -1 +1 @@ -Subproject commit 8e04c939c72083fa311ea709f5aafeaccd83975d +Subproject commit 9045a321b5d40f604da0e3cd8920ef7d6e9e65a5 diff --git a/src/rust-io-surface b/src/rust-io-surface index 020deaffff2..669971ff042 160000 --- a/src/rust-io-surface +++ b/src/rust-io-surface @@ -1 +1 @@ -Subproject commit 020deaffff282f36d8b1be8a98ee0e68f4a2b13b +Subproject commit 669971ff0424f9d298ffcdebf3510026cfb354e5 diff --git a/src/rust-layers b/src/rust-layers index 276a57d204f..92355d7224c 160000 --- a/src/rust-layers +++ b/src/rust-layers @@ -1 +1 @@ -Subproject commit 276a57d204f2d0ae74bda4ed76e63b830ca6332b +Subproject commit 92355d7224c16323c9d09b17ebcb340c6011e1e3 diff --git a/src/rust-mozjs b/src/rust-mozjs index 62558783027..b6a306a2690 160000 --- a/src/rust-mozjs +++ b/src/rust-mozjs @@ -1 +1 @@ -Subproject commit 62558783027d1aaccb4e689d3ff5aed057a1f5f5 +Subproject commit b6a306a26901ed7ce49f2b750c37972215c8ddaa diff --git a/src/rust-netsurfcss b/src/rust-netsurfcss index 9b6d463d904..6770cdad275 160000 --- a/src/rust-netsurfcss +++ b/src/rust-netsurfcss @@ -1 +1 @@ -Subproject commit 9b6d463d9045a90e6e3f31e35806af87e46e3852 +Subproject commit 6770cdad275cd5c269955dd2ff844448d0947971 diff --git a/src/rust-opengles b/src/rust-opengles index 7e127420530..942eac05bfd 160000 --- a/src/rust-opengles +++ b/src/rust-opengles @@ -1 +1 @@ -Subproject commit 7e127420530640c7ec3c79883b702041dfe13b14 +Subproject commit 942eac05bfd7397da0c8f9f92280bea4cf6021c4 diff --git a/src/rust-stb-image b/src/rust-stb-image index 06b790f2268..fd38ef064bb 160000 --- a/src/rust-stb-image +++ b/src/rust-stb-image @@ -1 +1 @@ -Subproject commit 06b790f226819e30c59b35523407bc671fe4d2ca +Subproject commit fd38ef064bbac1444079a5262922c7bb73311216 diff --git a/src/rust-wapcaplet b/src/rust-wapcaplet index ce75a426858..6a8f6677d38 160000 --- a/src/rust-wapcaplet +++ b/src/rust-wapcaplet @@ -1 +1 @@ -Subproject commit ce75a42685824a4c3c63a638a2c76762b7fac813 +Subproject commit 6a8f6677d38a8d2e85850971ef3e578a550ed6de diff --git a/src/rust-xlib b/src/rust-xlib index c8328148ec5..754ac8e774d 160000 --- a/src/rust-xlib +++ b/src/rust-xlib @@ -1 +1 @@ -Subproject commit c8328148ec5d1ec4fb8a496a41e34badf53e7f88 +Subproject commit 754ac8e774d9ac7b8577b6a0b775a54e1f00a262 diff --git a/src/servo-gfx/display_list.rs b/src/servo-gfx/display_list.rs index 7d219ba3108..44586f7a0ab 100644 --- a/src/servo-gfx/display_list.rs +++ b/src/servo-gfx/display_list.rs @@ -5,7 +5,6 @@ use render_context::RenderContext; use text::SendableTextRun; use util::range::Range; -use azure::azure_hl::DrawTarget; use clone_arc = std::arc::clone; use geom::Rect; use geom::Point2D; @@ -15,8 +14,8 @@ struct DisplayItemData { bounds : Rect, // TODO: whose coordinate system should this use? } -impl DisplayItemData { - static pure fn new(bounds: &Rect) -> DisplayItemData { +pub impl DisplayItemData { + fn new(bounds: &Rect) -> DisplayItemData { DisplayItemData { bounds: copy *bounds } } } @@ -31,8 +30,8 @@ pub enum DisplayItem { Border(DisplayItemData, Au, Color) } -impl DisplayItem { - pure fn d(&self) -> &self/DisplayItemData { +pub impl DisplayItem { + fn d(&self) -> &'self DisplayItemData { match *self { SolidColor(ref d, _) => d, Text(ref d, _, _, _) => d, @@ -68,23 +67,23 @@ impl DisplayItem { () }); } - static pure fn new_SolidColor(bounds: &Rect, color: Color) -> DisplayItem { + fn new_SolidColor(bounds: &Rect, color: Color) -> DisplayItem { SolidColor(DisplayItemData::new(bounds), color) } - static pure fn new_Border(bounds: &Rect, width: Au, color: Color) -> DisplayItem { + fn new_Border(bounds: &Rect, width: Au, color: Color) -> DisplayItem { Border(DisplayItemData::new(bounds), width, color) } - static pure fn new_Text(bounds: &Rect, - run: ~SendableTextRun, - range: Range, - color: Color) -> DisplayItem { + fn new_Text(bounds: &Rect, + run: ~SendableTextRun, + range: Range, + color: Color) -> DisplayItem { Text(DisplayItemData::new(bounds), run, range, color) } // ARC should be cloned into ImageData, but Images are not sendable - static pure fn new_Image(bounds: &Rect, image: ARC<~Image>) -> DisplayItem { + fn new_Image(bounds: &Rect, image: ARC<~Image>) -> DisplayItem { Image(DisplayItemData::new(bounds), image) } } @@ -95,7 +94,7 @@ pub struct DisplayList { } pub impl DisplayList { - static fn new() -> DisplayList { + fn new() -> DisplayList { DisplayList { list: ~[] } } diff --git a/src/servo-gfx/font.rs b/src/servo-gfx/font.rs index e1c50c8dcf4..bf8cdfb3620 100644 --- a/src/servo-gfx/font.rs +++ b/src/servo-gfx/font.rs @@ -8,8 +8,7 @@ use text::shaper::ShaperMethods; use text::{Shaper, TextRun}; use text::shaper::ShaperMethods; -use azure::{AzFloat, AzScaledFontRef, struct__AzDrawOptions, struct__AzGlyph}; -use azure::{struct__AzGlyphBuffer, struct__AzPoint}; +use azure::{AzFloat, AzScaledFontRef}; use azure::scaled_font::ScaledFont; use azure::azure_hl::{BackendType, ColorPattern}; use geom::{Point2D, Rect, Size2D}; @@ -26,18 +25,18 @@ use native; // resources needed by the graphics layer to draw glyphs. #[cfg(target_os = "macos")] -pub type FontHandle/& = quartz::font::QuartzFontHandle; +pub type FontHandle = quartz::font::QuartzFontHandle; #[cfg(target_os = "linux")] -pub type FontHandle/& = freetype_impl::font::FreeTypeFontHandle; +pub type FontHandle = freetype_impl::font::FreeTypeFontHandle; pub trait FontHandleMethods { // an identifier usable by FontContextHandle to recreate this FontHandle. - pure fn face_identifier(&self) -> ~str; - pure fn family_name(&self) -> ~str; - pure fn face_name(&self) -> ~str; - pure fn is_italic(&self) -> bool; - pure fn boldness(&self) -> CSSFontWeight; + fn face_identifier(&self) -> ~str; + fn family_name(&self) -> ~str; + fn face_name(&self) -> ~str; + fn is_italic(&self) -> bool; + fn boldness(&self) -> CSSFontWeight; fn clone_with_style(&self, fctx: &native::FontContextHandle, style: &UsedFontStyle) -> Result; fn glyph_index(&self, codepoint: char) -> Option; @@ -53,18 +52,18 @@ pub trait FontHandleMethods { pub impl FontHandle { #[cfg(target_os = "macos")] - static pub fn new_from_buffer(fctx: &native::FontContextHandle, - buf: ~[u8], - style: &SpecifiedFontStyle) - -> Result { + pub fn new_from_buffer(fctx: &native::FontContextHandle, + buf: ~[u8], + style: &SpecifiedFontStyle) + -> Result { quartz::font::QuartzFontHandle::new_from_buffer(fctx, buf, style) } #[cfg(target_os = "linux")] - static pub fn new_from_buffer(fctx: &native::FontContextHandle, - buf: ~[u8], - style: &SpecifiedFontStyle) - -> Result { + pub fn new_from_buffer(fctx: &native::FontContextHandle, + buf: ~[u8], + style: &SpecifiedFontStyle) + -> Result { freetype_impl::font::FreeTypeFontHandle::new_from_buffer(fctx, @buf, style) } } @@ -75,11 +74,11 @@ pub type FractionalPixel = float; pub type FontTableTag = u32; trait FontTableTagConversions { - pub pure fn tag_to_str(&self) -> ~str; + pub fn tag_to_str(&self) -> ~str; } impl FontTableTagConversions for FontTableTag { - pub pure fn tag_to_str(&self) -> ~str { + pub fn tag_to_str(&self) -> ~str { unsafe { let reversed = str::raw::from_buf_len(cast::transmute(self), 4); return str::from_chars([reversed.char_at(3), @@ -91,10 +90,10 @@ impl FontTableTagConversions for FontTableTag { } #[cfg(target_os = "macos")] -pub type FontTable/& = quartz::font::QuartzFontTable; +pub type FontTable = quartz::font::QuartzFontTable; #[cfg(target_os = "linux")] -pub type FontTable/& = freetype_impl::font::FreeTypeFontTable; +pub type FontTable = freetype_impl::font::FreeTypeFontTable; pub trait FontTableMethods { fn with_buffer(&self, &fn(*u8, uint)); @@ -112,7 +111,7 @@ pub struct FontMetrics { } // TODO(Issue #200): use enum from CSS bindings for 'font-weight' -#[deriving_eq] +#[deriving(Eq)] pub enum CSSFontWeight { FontWeight100, FontWeight200, @@ -126,7 +125,7 @@ pub enum CSSFontWeight { } pub impl CSSFontWeight { - pub pure fn is_bold(self) -> bool { + pub fn is_bold(self) -> bool { match self { FontWeight900 | FontWeight800 | FontWeight700 | FontWeight600 => true, _ => false @@ -140,7 +139,7 @@ pub impl CSSFontWeight { // the instance's properties. // // For now, the cases are differentiated with a typedef -#[deriving_eq] +#[deriving(Eq)] pub struct FontStyle { pt_size: float, weight: CSSFontWeight, @@ -165,14 +164,14 @@ struct ResolvedFont { // It's used to swizzle/unswizzle gfx::Font instances when // communicating across tasks, such as the display list between layout // and render tasks. -#[deriving_eq] +#[deriving(Eq)] pub struct FontDescriptor { style: UsedFontStyle, selector: FontSelector, } pub impl FontDescriptor { - static pure fn new(style: UsedFontStyle, selector: FontSelector) -> FontDescriptor { + fn new(style: UsedFontStyle, selector: FontSelector) -> FontDescriptor { FontDescriptor { style: style, selector: selector, @@ -181,7 +180,7 @@ pub impl FontDescriptor { } // A FontSelector is a platform-specific strategy for serializing face names. -#[deriving_eq] +#[deriving(Eq)] pub enum FontSelector { SelectorPlatformIdentifier(~str), SelectorStubDummy, // aka, use Josephin Sans @@ -203,7 +202,7 @@ pub struct FontGroup { } pub impl FontGroup { - static fn new(families: @str, style: &UsedFontStyle, fonts: ~[@mut Font]) -> FontGroup { + fn new(families: @str, style: &UsedFontStyle, fonts: ~[@mut Font]) -> FontGroup { FontGroup { families: families, style: copy *style, @@ -212,7 +211,7 @@ pub impl FontGroup { } fn create_textrun(&self, text: ~str) -> TextRun { - fail_unless!(self.fonts.len() > 0); + assert!(self.fonts.len() > 0); // TODO(Issue #177): Actually fall back through the FontGroup when a font is unsuitable. return TextRun::new(self.fonts[0], text); @@ -243,11 +242,11 @@ pub struct Font { } pub impl Font { - static fn new_from_buffer(ctx: &FontContext, - buffer: ~[u8], - style: &SpecifiedFontStyle, - backend: BackendType) - -> Result<@mut Font, ()> { + fn new_from_buffer(ctx: &FontContext, + buffer: ~[u8], + style: &SpecifiedFontStyle, + backend: BackendType) + -> Result<@mut Font, ()> { let handle = FontHandle::new_from_buffer(&ctx.handle, buffer, style); let handle = if handle.is_ok() { result::unwrap(handle) @@ -268,8 +267,8 @@ pub impl Font { }); } - static fn new_from_adopted_handle(_fctx: &FontContext, handle: FontHandle, - style: &SpecifiedFontStyle, backend: BackendType) -> @mut Font { + fn new_from_adopted_handle(_fctx: &FontContext, handle: FontHandle, + style: &SpecifiedFontStyle, backend: BackendType) -> @mut Font { let metrics = handle.get_metrics(); @mut Font { @@ -282,8 +281,8 @@ pub impl Font { } } - static fn new_from_existing_handle(fctx: &FontContext, handle: &FontHandle, - style: &SpecifiedFontStyle, backend: BackendType) -> Result<@mut Font,()> { + fn new_from_existing_handle(fctx: &FontContext, handle: &FontHandle, + style: &SpecifiedFontStyle, backend: BackendType) -> Result<@mut Font,()> { // TODO(Issue #179): convert between specified and used font style here? let styled_handle = match handle.clone_with_style(&fctx.handle, style) { @@ -334,7 +333,7 @@ pub impl Font { } #[cfg(target_os="macos")] - priv fn create_azure_font() -> ScaledFont { + priv fn create_azure_font(&mut self) -> ScaledFont { let cg_font = self.handle.get_CGFont(); let size = self.style.pt_size as AzFloat; ScaledFont::new(self.backend, &cg_font, size) @@ -353,26 +352,21 @@ pub impl Font { fn draw_text_into_context(&mut self, rctx: &RenderContext, run: &TextRun, - range: &const Range, + range: &Range, baseline_origin: Point2D, color: Color) { use core::libc::types::common::c99::{uint16_t, uint32_t}; - use azure::{AzDrawOptions, - struct__AzDrawOptions, - AzGlyph, + use azure::{struct__AzDrawOptions, struct__AzGlyph, - AzGlyphBuffer, struct__AzGlyphBuffer, struct__AzPoint}; - use azure::azure::bindgen::{AzCreateColorPattern}; use azure::azure::bindgen::{AzDrawTargetFillGlyphs}; - use azure::azure::bindgen::{AzReleaseColorPattern}; let target = rctx.get_draw_target(); let azfontref = self.get_azure_font(); let pattern = ColorPattern(color); let azure_pattern = pattern.azure_color_pattern; - fail_unless!(azure_pattern.is_not_null()); + assert!(azure_pattern.is_not_null()); let options = struct__AzDrawOptions { mAlpha: 1f as AzFloat, @@ -417,7 +411,7 @@ pub impl Font { ptr::null()); } - fn measure_text(&self, run: &TextRun, range: &const Range) -> RunMetrics { + fn measure_text(&self, run: &TextRun, range: &Range) -> RunMetrics { // TODO(Issue #199): alter advance direction for RTL // TODO(Issue #98): using inter-char and inter-word spacing settings when measuring text let mut advance = Au(0); @@ -479,7 +473,7 @@ fn should_get_glyph_indexes() { let matcher = @FontMatcher(fctx); let font = matcher.get_test_font(); let glyph_idx = font.glyph_index('w'); - fail_unless!(glyph_idx == Some(40u as GlyphIndex)); + assert!(glyph_idx == Some(40u as GlyphIndex)); } fn should_get_glyph_advance() { @@ -490,7 +484,7 @@ fn should_get_glyph_advance() { let matcher = @FontMatcher(fctx); let font = matcher.get_test_font(); let x = font.glyph_h_advance(40u as GlyphIndex); - fail_unless!(x == 15f || x == 16f); + assert!(x == 15f || x == 16f); } // Testing thread safety @@ -508,7 +502,7 @@ fn should_get_glyph_advance_stress() { let matcher = @FontMatcher(fctx); let _font = matcher.get_test_font(); let x = font.glyph_h_advance(40u as GlyphIndex); - fail_unless!(x == 15f || x == 16f); + assert!(x == 15f || x == 16f); chan.send(()); } } diff --git a/src/servo-gfx/font_context.rs b/src/servo-gfx/font_context.rs index 0a78bad5d6c..884e142f5e5 100644 --- a/src/servo-gfx/font_context.rs +++ b/src/servo-gfx/font_context.rs @@ -6,8 +6,7 @@ use util::cache::Cache; use util::cache::MonoCache; use azure::azure_hl::BackendType; -use core::hashmap::linear::LinearMap; -use core::hashmap::linear; +use core::hashmap::HashMap; #[cfg(target_os = "macos")] use quartz; @@ -16,7 +15,7 @@ use freetype_impl; use font_context; // TODO(Issue #164): delete, and get default font from font list -const TEST_FONT: [u8 * 33004] = include_bin!("JosefinSans-SemiBold.ttf"); +static TEST_FONT: [u8, ..33004] = include_bin!("JosefinSans-SemiBold.ttf"); fn test_font_bin() -> ~[u8] { return vec::from_fn(33004, |i| TEST_FONT[i]); @@ -36,13 +35,13 @@ pub fn dummy_style() -> FontStyle { } #[cfg(target_os = "macos")] -type FontContextHandle/& = quartz::font_context::QuartzFontContextHandle; +type FontContextHandle = quartz::font_context::QuartzFontContextHandle; #[cfg(target_os = "linux")] -type FontContextHandle/& = freetype_impl::font_context::FreeTypeFontContextHandle; +type FontContextHandle = freetype_impl::font_context::FreeTypeFontContextHandle; pub trait FontContextHandleMethods { - pure fn clone(&const self) -> FontContextHandle; + fn clone(&self) -> FontContextHandle; fn create_font_from_identifier(&self, ~str, UsedFontStyle) -> Result; } @@ -50,12 +49,12 @@ pub trait FontContextHandleMethods { // and typedefs not working well together. It should be removed. pub impl FontContextHandle { #[cfg(target_os = "macos")] - static pub fn new() -> FontContextHandle { + pub fn new() -> FontContextHandle { quartz::font_context::QuartzFontContextHandle::new() } #[cfg(target_os = "linux")] - static pub fn new() -> FontContextHandle { + pub fn new() -> FontContextHandle { freetype_impl::font_context::FreeTypeFontContextHandle::new() } } @@ -66,17 +65,17 @@ pub struct FontContext { font_list: Option, // only needed by layout handle: FontContextHandle, backend: BackendType, - generic_fonts: LinearMap<~str,~str>, + generic_fonts: HashMap<~str,~str>, } #[allow(non_implicitly_copyable_typarams)] -pub impl FontContext { - static fn new(backend: BackendType, needs_font_list: bool) -> FontContext { +pub impl<'self> FontContext { + fn new(backend: BackendType, needs_font_list: bool) -> FontContext { let handle = FontContextHandle::new(); let font_list = if needs_font_list { Some(FontList::new(&handle)) } else { None }; // TODO: Allow users to specify these. - let mut generic_fonts = linear::linear_map_with_capacity(5); + let mut generic_fonts = HashMap::with_capacity(5); generic_fonts.insert(~"serif", ~"Times New Roman"); generic_fonts.insert(~"sans-serif", ~"Arial"); generic_fonts.insert(~"cursive", ~"Apple Chancery"); @@ -94,11 +93,11 @@ pub impl FontContext { } } - priv pure fn get_font_list(&self) -> &self/FontList { - option::get_ref(&self.font_list) + priv fn get_font_list(&self) -> &'self FontList { + self.font_list.get_ref() } - fn get_resolved_font_for_style(&mut self, style: &SpecifiedFontStyle) -> @FontGroup { + fn get_resolved_font_for_style(@mut self, style: &SpecifiedFontStyle) -> @FontGroup { // TODO(Issue #178, E): implement a cache of FontGroup instances. self.create_font_group(style) } @@ -119,7 +118,7 @@ pub impl FontContext { } priv fn transform_family(&self, family: &str) -> ~str { - // FIXME: Need a find_like() in LinearMap. + // FIXME: Need a find_like() in HashMap. let family = family.to_str(); debug!("(transform family) searching for `%s`", family); match self.generic_fonts.find(&family) { @@ -129,13 +128,13 @@ pub impl FontContext { } // TODO:(Issue #196): cache font groups on the font context. - priv fn create_font_group(&mut self, style: &SpecifiedFontStyle) -> @FontGroup { + priv fn create_font_group(@mut self, style: &SpecifiedFontStyle) -> @FontGroup { let mut fonts = ~[]; debug!("(create font group) --- starting ---"); // TODO(Issue #193): make iteration over 'font-family' more robust. - for str::split_char_each(style.families, ',') |family| { + for str::each_split_char(style.families, ',') |family| { let family_name = str::trim(family); let transformed_family_name = self.transform_family(family_name); debug!("(create font group) transformed family is `%s`", transformed_family_name); @@ -168,7 +167,7 @@ pub impl FontContext { Err(()) => {} } } - fail_unless!(fonts.len() > 0); + assert!(fonts.len() > 0); // TODO(Issue #179): Split FontStyle into specified and used styles let used_style = copy *style; diff --git a/src/servo-gfx/font_list.rs b/src/servo-gfx/font_list.rs index 7db073c94b2..7b299c9b9ab 100644 --- a/src/servo-gfx/font_list.rs +++ b/src/servo-gfx/font_list.rs @@ -1,9 +1,9 @@ -use font::{CSSFontWeight, SpecifiedFontStyle, UsedFontStyle}; +use font::{CSSFontWeight, SpecifiedFontStyle}; use gfx_font::FontHandleMethods; use native::FontHandle; use gfx_font::FontHandleMethods; -use core::hashmap::linear; +use core::hashmap::HashMap; #[cfg(target_os = "linux")] use fontconfig; @@ -13,28 +13,28 @@ use native; use util::time::time; #[cfg(target_os = "macos")] -type FontListHandle/& = quartz::font_list::QuartzFontListHandle; +type FontListHandle = quartz::font_list::QuartzFontListHandle; #[cfg(target_os = "linux")] -type FontListHandle/& = fontconfig::font_list::FontconfigFontListHandle; +type FontListHandle = fontconfig::font_list::FontconfigFontListHandle; pub impl FontListHandle { #[cfg(target_os = "macos")] - static pub fn new(fctx: &native::FontContextHandle) -> Result { + pub fn new(fctx: &native::FontContextHandle) -> Result { Ok(quartz::font_list::QuartzFontListHandle::new(fctx)) } #[cfg(target_os = "linux")] - static pub fn new(fctx: &native::FontContextHandle) -> Result { + pub fn new(fctx: &native::FontContextHandle) -> Result { Ok(fontconfig::font_list::FontconfigFontListHandle::new(fctx)) } } -pub type FontFamilyMap = linear::LinearMap<~str, @mut FontFamily>; +pub type FontFamilyMap = HashMap<~str, @mut FontFamily>; trait FontListHandleMethods { - fn get_available_families(&const self, fctx: &native::FontContextHandle) -> FontFamilyMap; - fn load_variations_for_family(&const self, family: @mut FontFamily); + fn get_available_families(&self, fctx: &native::FontContextHandle) -> FontFamilyMap; + fn load_variations_for_family(&self, family: @mut FontFamily); } pub struct FontList { @@ -43,11 +43,11 @@ pub struct FontList { } pub impl FontList { - static fn new(fctx: &native::FontContextHandle) -> FontList { + fn new(fctx: &native::FontContextHandle) -> FontList { let handle = result::unwrap(FontListHandle::new(fctx)); let mut list = FontList { handle: handle, - family_map: linear::LinearMap::new(), + family_map: HashMap::new(), }; list.refresh(fctx); return list; @@ -90,7 +90,7 @@ pub impl FontList { debug!("FontList: %s font family with name=%s", decision, family_name); // TODO(Issue #188): look up localized font family names if canonical name not found - return family.map(|f| **f); + family.map(|f| **f) } } @@ -101,7 +101,7 @@ pub struct FontFamily { } pub impl FontFamily { - static fn new(family_name: &str) -> FontFamily { + fn new(family_name: &str) -> FontFamily { FontFamily { family_name: str::from_slice(family_name), entries: ~[], @@ -109,9 +109,10 @@ pub impl FontFamily { } priv fn load_family_variations(@mut self, list: &native::FontListHandle) { - if self.entries.len() > 0 { return; } + let this : &mut FontFamily = self; // FIXME: borrow checker workaround + if this.entries.len() > 0 { return; } list.load_variations_for_family(self); - fail_unless!(self.entries.len() > 0); + assert!(this.entries.len() > 0); } fn find_font_for_style(@mut self, list: &native::FontListHandle, style: &SpecifiedFontStyle) -> Option<@FontEntry> { @@ -124,7 +125,8 @@ pub impl FontFamily { // TODO(Issue #190): if not in the fast path above, do // expensive matching of weights, etc. - for self.entries.each |entry| { + let this : &mut FontFamily = self; // FIXME: borrow checker workaround + for this.entries.each |entry| { if (style.weight.is_bold() == entry.is_bold()) && (style.italic == entry.is_italic()) { @@ -151,7 +153,7 @@ pub struct FontEntry { } pub impl FontEntry { - static fn new(family: @mut FontFamily, handle: FontHandle) -> FontEntry { + fn new(family: @mut FontFamily, handle: FontHandle) -> FontEntry { FontEntry { family: family, face_name: handle.face_name(), @@ -161,9 +163,9 @@ pub impl FontEntry { } } - pure fn is_bold(&self) -> bool { + fn is_bold(&self) -> bool { self.weight.is_bold() } - pure fn is_italic(&self) -> bool { self.italic } + fn is_italic(&self) -> bool { self.italic } } diff --git a/src/servo-gfx/fontconfig/font_list.rs b/src/servo-gfx/fontconfig/font_list.rs index de302755bbb..9f6b3466b93 100644 --- a/src/servo-gfx/fontconfig/font_list.rs +++ b/src/servo-gfx/fontconfig/font_list.rs @@ -29,7 +29,7 @@ pub struct FontconfigFontListHandle { } pub impl FontconfigFontListHandle { - static pub fn new(fctx: &native::FontContextHandle) -> FontconfigFontListHandle { + pub fn new(fctx: &native::FontContextHandle) -> FontconfigFontListHandle { FontconfigFontListHandle { fctx: fctx.clone() } } diff --git a/src/servo-gfx/freetype_impl/font.rs b/src/servo-gfx/freetype_impl/font.rs index 778758476d2..2ab0fa6f882 100644 --- a/src/servo-gfx/freetype_impl/font.rs +++ b/src/servo-gfx/freetype_impl/font.rs @@ -100,7 +100,7 @@ impl Drop for FreeTypeFontHandle { } pub impl FreeTypeFontHandle { - static priv fn set_char_size(face: FT_Face, pt_size: float) -> Result<(), ()>{ + priv fn set_char_size(face: FT_Face, pt_size: float) -> Result<(), ()>{ let char_width = float_to_fixed_ft(pt_size) as FT_F26Dot6; let char_height = float_to_fixed_ft(pt_size) as FT_F26Dot6; let h_dpi = 72; @@ -110,8 +110,8 @@ pub impl FreeTypeFontHandle { if result.succeeded() { Ok(()) } else { Err(()) } } - static pub fn new_from_file(fctx: &FreeTypeFontContextHandle, file: ~str, - style: &SpecifiedFontStyle) -> Result { + pub fn new_from_file(fctx: &FreeTypeFontContextHandle, file: ~str, + style: &SpecifiedFontStyle) -> Result { let ft_ctx: FT_Library = fctx.ctx.ctx; if ft_ctx.is_null() { return Err(()); } @@ -131,7 +131,7 @@ pub impl FreeTypeFontHandle { } } - static pub fn new_from_file_unstyled(fctx: &FreeTypeFontContextHandle, file: ~str) + pub fn new_from_file_unstyled(fctx: &FreeTypeFontContextHandle, file: ~str) -> Result { let ft_ctx: FT_Library = fctx.ctx.ctx; if ft_ctx.is_null() { return Err(()); } @@ -149,8 +149,8 @@ pub impl FreeTypeFontHandle { Ok(FreeTypeFontHandle { source: FontSourceFile(file), face: face }) } - static pub fn new_from_buffer(fctx: &FreeTypeFontContextHandle, - buf: @~[u8], style: &SpecifiedFontStyle) -> Result { + pub fn new_from_buffer(fctx: &FreeTypeFontContextHandle, + buf: @~[u8], style: &SpecifiedFontStyle) -> Result { let ft_ctx: FT_Library = fctx.ctx.ctx; if ft_ctx.is_null() { return Err(()); } @@ -189,21 +189,21 @@ pub impl FreeTypeFontHandle { impl FontHandleMethods for FreeTypeFontHandle { // an identifier usable by FontContextHandle to recreate this FontHandle. - pure fn face_identifier(&self) -> ~str { + fn face_identifier(&self) -> ~str { /* FT_Get_Postscript_Name seems like a better choice here, but it doesn't give usable results for fontconfig when deserializing. */ unsafe { str::raw::from_c_str((*self.face).family_name) } } - pure fn family_name(&self) -> ~str { + fn family_name(&self) -> ~str { unsafe { str::raw::from_c_str((*self.face).family_name) } } - pure fn face_name(&self) -> ~str { + fn face_name(&self) -> ~str { unsafe { str::raw::from_c_str(FT_Get_Postscript_Name(self.face)) } } - pure fn is_italic(&self) -> bool { + fn is_italic(&self) -> bool { unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC != 0 } } - pure fn boldness(&self) -> CSSFontWeight { + fn boldness(&self) -> CSSFontWeight { let default_weight = FontWeight400; if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD == 0 } { default_weight @@ -305,7 +305,7 @@ impl FontHandleMethods for FreeTypeFontHandle { } pub impl FreeTypeFontHandle { - priv fn get_face_rec(&self) -> &self/FT_FaceRec { + priv fn get_face_rec(&self) -> &'self FT_FaceRec { unsafe { &(*self.face) } diff --git a/src/servo-gfx/freetype_impl/font_context.rs b/src/servo-gfx/freetype_impl/font_context.rs index 27617cdb4cf..4671b6d49ff 100644 --- a/src/servo-gfx/freetype_impl/font_context.rs +++ b/src/servo-gfx/freetype_impl/font_context.rs @@ -35,7 +35,7 @@ pub struct FreeTypeFontContextHandle { } pub impl FreeTypeFontContextHandle { - static pub fn new() -> FreeTypeFontContextHandle { + pub fn new() -> FreeTypeFontContextHandle { let ctx: FT_Library = ptr::null(); let result = FT_Init_FreeType(ptr::to_unsafe_ptr(&ctx)); if !result.succeeded() { fail!(); } @@ -47,7 +47,7 @@ pub impl FreeTypeFontContextHandle { } impl FontContextHandleMethods for FreeTypeFontContextHandle { - pure fn clone(&const self) -> FreeTypeFontContextHandle { + fn clone(&self) -> FreeTypeFontContextHandle { FreeTypeFontContextHandle { ctx: self.ctx } } diff --git a/src/servo-gfx/geometry.rs b/src/servo-gfx/geometry.rs index be05529a915..7bb140efbcd 100644 --- a/src/servo-gfx/geometry.rs +++ b/src/servo-gfx/geometry.rs @@ -7,62 +7,62 @@ use core::num::NumCast; pub struct Au(i32); impl Add for Au { - pure fn add(&self, other: &Au) -> Au { Au(**self + **other) } + fn add(&self, other: &Au) -> Au { Au(**self + **other) } } impl Sub for Au { - pure fn sub(&self, other: &Au) -> Au { Au(**self - **other) } + fn sub(&self, other: &Au) -> Au { Au(**self - **other) } } impl Mul for Au { - pure fn mul(&self, other: &Au) -> Au { Au(**self * **other) } + fn mul(&self, other: &Au) -> Au { Au(**self * **other) } } impl Div for Au { - pure fn div(&self, other: &Au) -> Au { Au(**self / **other) } + fn div(&self, other: &Au) -> Au { Au(**self / **other) } } impl Modulo for Au { - pure fn modulo(&self, other: &Au) -> Au { Au(**self % **other) } + fn modulo(&self, other: &Au) -> Au { Au(**self % **other) } } impl Neg for Au { - pure fn neg(&self) -> Au { Au(-**self) } + fn neg(&self) -> Au { Au(-**self) } } impl cmp::Ord for Au { - pure fn lt(&self, other: &Au) -> bool { **self < **other } - pure fn le(&self, other: &Au) -> bool { **self <= **other } - pure fn ge(&self, other: &Au) -> bool { **self >= **other } - pure fn gt(&self, other: &Au) -> bool { **self > **other } + fn lt(&self, other: &Au) -> bool { **self < **other } + fn le(&self, other: &Au) -> bool { **self <= **other } + fn ge(&self, other: &Au) -> bool { **self >= **other } + fn gt(&self, other: &Au) -> bool { **self > **other } } impl cmp::Eq for Au { - pure fn eq(&self, other: &Au) -> bool { **self == **other } - pure fn ne(&self, other: &Au) -> bool { **self != **other } + fn eq(&self, other: &Au) -> bool { **self == **other } + fn ne(&self, other: &Au) -> bool { **self != **other } } -pub pure fn min(x: Au, y: Au) -> Au { if x < y { x } else { y } } -pub pure fn max(x: Au, y: Au) -> Au { if x > y { x } else { y } } +pub fn min(x: Au, y: Au) -> Au { if x < y { x } else { y } } +pub fn max(x: Au, y: Au) -> Au { if x > y { x } else { y } } impl NumCast for Au { - static pure fn from(n: T) -> Au { Au(n.to_i32()) } + fn from(n: T) -> Au { Au(n.to_i32()) } - pure fn to_u8(&self) -> u8 { (**self).to_u8() } - pure fn to_u16(&self) -> u16 { (**self).to_u16() } - pure fn to_u32(&self) -> u32 { (**self).to_u32() } - pure fn to_u64(&self) -> u64 { (**self).to_u64() } - pure fn to_uint(&self) -> uint { (**self).to_uint() } + fn to_u8(&self) -> u8 { (**self).to_u8() } + fn to_u16(&self) -> u16 { (**self).to_u16() } + fn to_u32(&self) -> u32 { (**self).to_u32() } + fn to_u64(&self) -> u64 { (**self).to_u64() } + fn to_uint(&self) -> uint { (**self).to_uint() } - pure fn to_i8(&self) -> i8 { (**self).to_i8() } - pure fn to_i16(&self) -> i16 { (**self).to_i16() } - pure fn to_i32(&self) -> i32 { (**self).to_i32() } - pure fn to_i64(&self) -> i64 { (**self).to_i64() } - pure fn to_int(&self) -> int { (**self).to_int() } + fn to_i8(&self) -> i8 { (**self).to_i8() } + fn to_i16(&self) -> i16 { (**self).to_i16() } + fn to_i32(&self) -> i32 { (**self).to_i32() } + fn to_i64(&self) -> i64 { (**self).to_i64() } + fn to_int(&self) -> int { (**self).to_int() } - pure fn to_f32(&self) -> f32 { (**self).to_f32() } - pure fn to_f64(&self) -> f64 { (**self).to_f64() } - pure fn to_float(&self) -> float { (**self).to_float() } + fn to_f32(&self) -> f32 { (**self).to_f32() } + fn to_f64(&self) -> f64 { (**self).to_f64() } + fn to_float(&self) -> float { (**self).to_float() } } pub fn box + Sub>(x: T, y: T, w: T, h: T) -> Rect { @@ -70,76 +70,76 @@ pub fn box + Sub>(x: T, y: T, w: T, h: T) -> Rect Au { + pub fn scale_by(self, factor: float) -> Au { Au(((*self as float) * factor) as i32) } - static pub pure fn from_px(i: int) -> Au { + pub fn from_px(i: int) -> Au { NumCast::from(i * 60) } - pub pure fn to_px(&const self) -> int { + pub fn to_px(&self) -> int { (**self / 60) as int } - pub pure fn to_snapped(&const self) -> Au { + pub fn to_snapped(&self) -> Au { let res = **self % 60i32; return if res >= 30i32 { return Au(**self - res + 60i32) } else { return Au(**self - res) }; } - static pub pure fn zero_point() -> Point2D { + pub fn zero_point() -> Point2D { Point2D(Au(0), Au(0)) } - static pub pure fn zero_rect() -> Rect { + pub fn zero_rect() -> Rect { let z = Au(0); Rect(Point2D(z, z), Size2D(z, z)) } // assumes 72 points per inch, and 96 px per inch - static pub pure fn from_pt(f: float) -> Au { + pub fn from_pt(f: float) -> Au { from_px((f / 72f * 96f) as int) } - static pub pure fn from_frac_px(f: float) -> Au { + pub fn from_frac_px(f: float) -> Au { Au((f * 60f) as i32) } - static pub pure fn min(x: Au, y: Au) -> Au { if *x < *y { x } else { y } } - static pub pure fn max(x: Au, y: Au) -> Au { if *x > *y { x } else { y } } + pub fn min(x: Au, y: Au) -> Au { if *x < *y { x } else { y } } + pub fn max(x: Au, y: Au) -> Au { if *x > *y { x } else { y } } } -pub pure fn zero_rect() -> Rect { +pub fn zero_rect() -> Rect { let z = Au(0); Rect(Point2D(z, z), Size2D(z, z)) } -pub pure fn zero_point() -> Point2D { +pub fn zero_point() -> Point2D { Point2D(Au(0), Au(0)) } -pub pure fn zero_size() -> Size2D { +pub fn zero_size() -> Size2D { Size2D(Au(0), Au(0)) } -pub pure fn from_frac_px(f: float) -> Au { +pub fn from_frac_px(f: float) -> Au { Au((f * 60f) as i32) } -pub pure fn from_px(i: int) -> Au { +pub fn from_px(i: int) -> Au { NumCast::from(i * 60) } -pub pure fn to_px(au: Au) -> int { +pub fn to_px(au: Au) -> int { (*au / 60) as int } -pub pure fn to_frac_px(au: Au) -> float { +pub fn to_frac_px(au: Au) -> float { (*au as float) / 60f } // assumes 72 points per inch, and 96 px per inch -pub pure fn from_pt(f: float) -> Au { +pub fn from_pt(f: float) -> Au { from_px((f / 72f * 96f) as int) } diff --git a/src/servo-gfx/image/base.rs b/src/servo-gfx/image/base.rs index c0e8b9bcc55..ad6606de5fe 100644 --- a/src/servo-gfx/image/base.rs +++ b/src/servo-gfx/image/base.rs @@ -9,7 +9,7 @@ pub fn Image(width: uint, height: uint, depth: uint, data: ~[u8]) -> Image { stb_image::new_image(width, height, depth, data) } -const TEST_IMAGE: [u8 * 4962] = include_bin!("test.jpeg"); +static TEST_IMAGE: [u8, ..4962] = include_bin!("test.jpeg"); pub fn test_image_bin() -> ~[u8] { return vec::from_fn(4962, |i| TEST_IMAGE[i]); @@ -18,11 +18,11 @@ pub fn test_image_bin() -> ~[u8] { pub fn load_from_memory(buffer: &[u8]) -> Option { // Can't remember why we do this. Maybe it's what cairo wants - const FORCE_DEPTH: uint = 4; + static FORCE_DEPTH: uint = 4; match stb_image::load_from_memory_with_depth(buffer, FORCE_DEPTH, true) { stb_image::ImageU8(image) => { - fail_unless!(image.depth == 4); + assert!(image.depth == 4); // Do color space conversion :( let data = do vec::from_fn(image.width * image.height * 4) |i| { let color = i % 4; @@ -36,7 +36,7 @@ pub fn load_from_memory(buffer: &[u8]) -> Option { } }; - fail_unless!(image.data.len() == data.len()); + assert!(image.data.len() == data.len()); Some(Image(image.width, image.height, image.depth, data)) } diff --git a/src/servo-gfx/image/encode/tga.rs b/src/servo-gfx/image/encode/tga.rs index 17c13854cca..60bada116ee 100644 --- a/src/servo-gfx/image/encode/tga.rs +++ b/src/servo-gfx/image/encode/tga.rs @@ -1,8 +1,8 @@ use core::io::WriterUtil; use surface; -fn encode(writer: io::Writer, surface: &surface::ImageSurface) { - fail_unless!(surface.format == surface::fo_rgba_8888); +fn encode(writer: @io::Writer, surface: &surface::ImageSurface) { + assert!(surface.format == surface::fo_rgba_8888); writer.write_u8(0u8); // identsize writer.write_u8(0u8); // colourmaptype diff --git a/src/servo-gfx/image/holder.rs b/src/servo-gfx/image/holder.rs index 47caa5773a0..39e9b0eb291 100644 --- a/src/servo-gfx/image/holder.rs +++ b/src/servo-gfx/image/holder.rs @@ -1,6 +1,5 @@ use image::base::Image; -use resource::image_cache_task::{ImageCacheTask, ImageReady, ImageNotReady, ImageFailed}; -use resource::image_cache_task; +use resource::image_cache_task::{ImageReady, ImageNotReady, ImageFailed}; use resource::local_image_cache::LocalImageCache; use core::util::replace; @@ -23,25 +22,25 @@ pub struct ImageHolder { } pub impl ImageHolder { - static pub fn new(url: Url, local_image_cache: @mut LocalImageCache) -> ImageHolder { - debug!("ImageHolder::new() %?", url.to_str()); - let holder = ImageHolder { - url: url, - image: None, - cached_size: Size2D(0,0), - local_image_cache: local_image_cache, - }; + pub fn new(url: Url, local_image_cache: @mut LocalImageCache) -> ImageHolder { + debug!("ImageHolder::new() %?", url.to_str()); + let holder = ImageHolder { + url: url, + image: None, + cached_size: Size2D(0,0), + local_image_cache: local_image_cache, + }; - // Tell the image cache we're going to be interested in this url - // FIXME: These two messages must be sent to prep an image for use - // but they are intended to be spread out in time. Ideally prefetch - // should be done as early as possible and decode only once we - // are sure that the image will be used. - local_image_cache.prefetch(&holder.url); - local_image_cache.decode(&holder.url); + // Tell the image cache we're going to be interested in this url + // FIXME: These two messages must be sent to prep an image for use + // but they are intended to be spread out in time. Ideally prefetch + // should be done as early as possible and decode only once we + // are sure that the image will be used. + local_image_cache.prefetch(&holder.url); + local_image_cache.decode(&holder.url); - holder - } + holder + } /** This version doesn't perform any computation, but may be stale w.r.t. @@ -50,7 +49,7 @@ pub impl ImageHolder { The intent is that the impure version is used during layout when dimensions are used for computing layout. */ - pure fn size(&self) -> Size2D { + fn size(&self) -> Size2D { self.cached_size } diff --git a/src/servo-gfx/quartz/font.rs b/src/servo-gfx/quartz/font.rs index f54e2576d14..5dc5cbf6326 100644 --- a/src/servo-gfx/quartz/font.rs +++ b/src/servo-gfx/quartz/font.rs @@ -9,22 +9,19 @@ use gfx_font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTable, FontTab use gfx_font::{FontTableTag, FontWeight100, FontWeight200, FontWeight300, FontWeight400}; use gfx_font::{FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900}; use gfx_font::{FractionalPixel, SpecifiedFontStyle}; -use quartz::font::core_foundation::base::{CFIndex, CFTypeRef, CFWrapper}; -use quartz::font::core_foundation::data::{CFData, CFDataRef}; +use quartz::font::core_foundation::base::{CFIndex, CFWrapper}; +use quartz::font::core_foundation::data::CFData; use quartz::font::core_foundation::string::UniChar; -use quartz::font::core_graphics::base::{CGFloat, CGAffineTransform}; -use quartz::font::core_graphics::data_provider::{CGDataProviderRef, CGDataProvider}; -use quartz::font::core_graphics::font::{CGFont, CGFontRef, CGGlyph}; +use quartz::font::core_graphics::data_provider::CGDataProvider; +use quartz::font::core_graphics::font::{CGFont, CGGlyph}; use quartz::font::core_graphics::geometry::CGRect; -use quartz::font::core_text::font::CTFont; -use quartz::font::core_text::font_descriptor::{SymbolicTraitAccessors}; -use quartz::font::core_text::font_descriptor::{kCTFontDefaultOrientation, CTFontSymbolicTraits}; +use quartz::font::core_text::font::{CTFont, CTFontMethods, CTFontMethodsPrivate}; +use quartz::font::core_text::font_descriptor::{SymbolicTraitAccessors, TraitAccessors}; +use quartz::font::core_text::font_descriptor::kCTFontDefaultOrientation; use quartz::font_context::QuartzFontContextHandle; use quartz; use text::glyph::GlyphIndex; -use core::libc::size_t; - struct QuartzFontTable { data: CFData, } @@ -34,27 +31,25 @@ struct QuartzFontTable { impl Drop for QuartzFontTable { fn finalize(&self) {} } pub impl QuartzFontTable { - static fn wrap(data: CFData) -> QuartzFontTable { + fn wrap(data: CFData) -> QuartzFontTable { QuartzFontTable { data: data } } } impl FontTableMethods for QuartzFontTable { - fn with_buffer(blk: &fn(*u8, uint)) { + fn with_buffer(&self, blk: &fn(*u8, uint)) { blk(self.data.bytes(), self.data.len()); } } pub struct QuartzFontHandle { - priv mut cgfont: Option, + priv cgfont: Option, ctfont: CTFont, - - drop { } } pub impl QuartzFontHandle { - static fn new_from_buffer(_fctx: &QuartzFontContextHandle, buf: ~[u8], - style: &SpecifiedFontStyle) -> Result { + fn new_from_buffer(_fctx: &QuartzFontContextHandle, buf: ~[u8], + style: &SpecifiedFontStyle) -> Result { let fontprov : CGDataProvider = vec::as_imm_buf(buf, |cbuf, len| { quartz::font::core_graphics::data_provider::new_from_buffer(cbuf, len) }); @@ -70,7 +65,7 @@ pub impl QuartzFontHandle { return result; } - static fn new_from_CTFont(_fctx: &QuartzFontContextHandle, ctfont: CTFont) -> Result { + fn new_from_CTFont(_fctx: &QuartzFontContextHandle, ctfont: CTFont) -> Result { let result = Ok(QuartzFontHandle { mut cgfont: None, ctfont: ctfont, @@ -79,9 +74,9 @@ pub impl QuartzFontHandle { return result; } - fn get_CGFont() -> CGFont { + fn get_CGFont(&mut self) -> CGFont { match self.cgfont { - Some(ref font) => CFWrapper::wrap_shared(*font.borrow_ref()), + Some(ref font) => CFWrapper::wrap_shared(*(font.borrow_ref())), None => { let cgfont = self.ctfont.copy_to_CGFont(); self.cgfont = Some(CFWrapper::clone(&cgfont)); @@ -92,19 +87,19 @@ pub impl QuartzFontHandle { } impl FontHandleMethods for QuartzFontHandle { - pure fn family_name() -> ~str { + fn family_name(&self) -> ~str { self.ctfont.family_name() } - pure fn face_name() -> ~str { + fn face_name(&self) -> ~str { self.ctfont.face_name() } - pure fn is_italic() -> bool { + fn is_italic(&self) -> bool { self.ctfont.symbolic_traits().is_italic() } - pure fn boldness() -> CSSFontWeight { + fn boldness(&self) -> CSSFontWeight { // -1.0 to 1.0 let normalized = unsafe { self.ctfont.all_traits().normalized_weight() }; // 0.0 to 9.0 @@ -120,16 +115,16 @@ impl FontHandleMethods for QuartzFontHandle { return FontWeight900; } - fn clone_with_style(fctx: &QuartzFontContextHandle, + fn clone_with_style(&self, fctx: &QuartzFontContextHandle, style: &SpecifiedFontStyle) -> Result { let new_font = self.ctfont.clone_with_font_size(style.pt_size); return QuartzFontHandle::new_from_CTFont(fctx, new_font); } - fn glyph_index(codepoint: char) -> Option { - let characters: [UniChar * 1] = [codepoint as UniChar]; - let glyphs: [CGGlyph * 1] = [0 as CGGlyph]; + fn glyph_index(&self, codepoint: char) -> Option { + let characters: [UniChar, ..1] = [codepoint as UniChar]; + let glyphs: [CGGlyph, ..1] = [0 as CGGlyph]; let count: CFIndex = 1; let result = self.ctfont.get_glyphs_for_characters(ptr::to_unsafe_ptr(&characters[0]), @@ -141,11 +136,11 @@ impl FontHandleMethods for QuartzFontHandle { return None; } - fail_unless!(glyphs[0] != 0); // FIXME: error handling + assert!(glyphs[0] != 0); // FIXME: error handling return Some(glyphs[0] as GlyphIndex); } - fn glyph_h_advance(glyph: GlyphIndex) -> Option { + fn glyph_h_advance(&self, glyph: GlyphIndex) -> Option { let glyphs = [glyph as CGGlyph]; unsafe { let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation, @@ -156,7 +151,7 @@ impl FontHandleMethods for QuartzFontHandle { } } - fn get_metrics() -> FontMetrics { + fn get_metrics(&self) -> FontMetrics { let bounding_rect: CGRect = self.ctfont.bounding_box(); let ascent = Au::from_pt(self.ctfont.ascent() as float); let descent = Au::from_pt(self.ctfont.descent() as float); @@ -181,14 +176,14 @@ impl FontHandleMethods for QuartzFontHandle { return metrics; } - fn get_table_for_tag(tag: FontTableTag) -> Option { + fn get_table_for_tag(&self, tag: FontTableTag) -> Option { let result : Option = self.ctfont.get_font_table(tag); - return option::chain(result, |data| { + result.chain(|data| { Some(QuartzFontTable::wrap(data)) - }); + }) } - pure fn face_identifier() -> ~str { + fn face_identifier(&self) -> ~str { self.ctfont.postscript_name() } } diff --git a/src/servo-gfx/quartz/font_context.rs b/src/servo-gfx/quartz/font_context.rs index 3a318a68b6f..b610bdb576c 100644 --- a/src/servo-gfx/quartz/font_context.rs +++ b/src/servo-gfx/quartz/font_context.rs @@ -4,34 +4,31 @@ extern mod core_text; use quartz; use quartz::font::QuartzFontHandle; -use quartz::font_context::core_text::font::CTFont; use gfx_font::{FontHandle, UsedFontStyle}; use gfx_font_context::FontContextHandleMethods; pub struct QuartzFontContextHandle { - ctx: (), - - drop { } + ctx: () } pub impl QuartzFontContextHandle { // this is a placeholder until NSFontManager or whatever is bound in here. - static pub fn new() -> QuartzFontContextHandle { + pub fn new() -> QuartzFontContextHandle { QuartzFontContextHandle { ctx: () } } } impl FontContextHandleMethods for QuartzFontContextHandle { - pure fn clone(&const self) -> QuartzFontContextHandle { + fn clone(&self) -> QuartzFontContextHandle { QuartzFontContextHandle { ctx: self.ctx } } - fn create_font_from_identifier(name: ~str, style: UsedFontStyle) -> Result { + fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle) -> Result { let ctfont_result = quartz::font_context::core_text::font::new_from_name(name, style.pt_size); do result::chain(ctfont_result) |ctfont| { - QuartzFontHandle::new_from_CTFont(&self, ctfont) + QuartzFontHandle::new_from_CTFont(self, ctfont) } } } diff --git a/src/servo-gfx/quartz/font_list.rs b/src/servo-gfx/quartz/font_list.rs index 28a99c6fb23..10eaca28d0b 100644 --- a/src/servo-gfx/quartz/font_list.rs +++ b/src/servo-gfx/quartz/font_list.rs @@ -7,45 +7,43 @@ use quartz::font_list::core_foundation::array::CFArray; use quartz::font_list::core_foundation::base::CFWrapper; use quartz::font_list::core_foundation::string::{CFString, CFStringRef}; -use quartz::font_list::core_text::font::{CTFont, debug_font_names, debug_font_traits}; -use quartz::font_list::core_text::font_collection::CTFontCollection; -use quartz::font_list::core_text::font_descriptor::{CTFontDescriptor, CTFontDescriptorRef}; -use quartz::font_list::core_text::font_descriptor::{debug_descriptor}; +use quartz::font_list::core_text::font_descriptor::CTFontDescriptorRef; +use quartz::font_list::core_text::font_collection::CTFontCollectionMethods; use quartz::font::QuartzFontHandle; use quartz::font_context::QuartzFontContextHandle; -use gfx_font::{FontHandle, FontHandleMethods}; +use gfx_font::FontHandleMethods; use gfx_font_context::FontContextHandleMethods; use gfx_font_list::{FontEntry, FontFamily, FontFamilyMap}; -use core::dvec::DVec; -use core::hashmap::linear::LinearMap; +use core::hashmap::HashMap; pub struct QuartzFontListHandle { fctx: QuartzFontContextHandle, } pub impl QuartzFontListHandle { - static fn new(fctx: &native::FontContextHandle) -> QuartzFontListHandle { + fn new(fctx: &native::FontContextHandle) -> QuartzFontListHandle { QuartzFontListHandle { fctx: fctx.clone() } } - fn get_available_families() -> FontFamilyMap { + fn get_available_families(&self) -> FontFamilyMap { let family_names: CFArray = quartz::font_list::core_text::font_collection::get_family_names(); - let mut family_map : FontFamilyMap = LinearMap::new(); + let mut family_map : FontFamilyMap = HashMap::new(); for family_names.each |&strref: &CFStringRef| { let family_name = CFString::wrap_extern(strref).to_str(); debug!("Creating new FontFamily for family: %s", family_name); - let new_family = @FontFamily::new(family_name); + let new_family = @mut FontFamily::new(family_name); family_map.insert(family_name, new_family); } return family_map; } - fn load_variations_for_family(family: @FontFamily) { - let family_name = &family.family_name; + fn load_variations_for_family(&self, family: @mut FontFamily) { + let fam : &mut FontFamily = family; // FIXME: borrow checker workaround + let family_name = &fam.family_name; debug!("Looking for faces of family: %s", *family_name); let family_collection = diff --git a/src/servo-gfx/render_context.rs b/src/servo-gfx/render_context.rs index 37e3b927760..a36a8acc73b 100644 --- a/src/servo-gfx/render_context.rs +++ b/src/servo-gfx/render_context.rs @@ -3,27 +3,25 @@ use font_context::FontContext; use geometry::Au; use image::base::Image; use opts::Opts; -use text::TextRun; -use azure::azure_hl::{AsAzureRect, B8G8R8A8, Color, ColorPattern, DrawOptions}; +use azure::azure_hl::{B8G8R8A8, Color, ColorPattern, DrawOptions}; use azure::azure_hl::{DrawSurfaceOptions, DrawTarget, Linear, StrokeOptions}; -use azure::{AzDrawOptions, AzFloat}; +use azure::AzFloat; use core::libc::types::common::c99::uint16_t; -use core::ptr::to_unsafe_ptr; use geom::point::Point2D; use geom::rect::Rect; use geom::size::Size2D; use std::arc; use std::arc::ARC; -pub struct RenderContext { +pub struct RenderContext<'self> { canvas: &'self LayerBuffer, font_ctx: @mut FontContext, opts: &'self Opts } pub impl<'self> RenderContext<'self> { - pub fn get_draw_target(&self) -> &self/DrawTarget { + pub fn get_draw_target(&self) -> &'self DrawTarget { &self.canvas.draw_target } diff --git a/src/servo-gfx/render_layers.rs b/src/servo-gfx/render_layers.rs index f05e04877e4..cc5ba312c31 100644 --- a/src/servo-gfx/render_layers.rs +++ b/src/servo-gfx/render_layers.rs @@ -3,25 +3,20 @@ use display_list::DisplayList; use opts::Opts; use util::time; -use azure::AzFloat; use azure::azure_hl::{B8G8R8A8, DrawTarget}; -use core::libc::c_int; use core::comm::Chan; -use geom::matrix2d::Matrix2D; use geom::point::Point2D; use geom::rect::Rect; use geom::size::Size2D; -use std::arc::ARC; -use std::arc; pub struct RenderLayer { display_list: DisplayList, size: Size2D } -type RenderFn = &'self fn(layer: *RenderLayer, - buffer: LayerBuffer, - return_buffer: Chan); +type RenderFn<'self> = &'self fn(layer: *RenderLayer, + buffer: LayerBuffer, + return_buffer: Chan); /// Given a layer and a buffer, either reuses the buffer (if it's of the right size and format) /// or creates a new buffer (if it's not of the appropriate size and format) and invokes the @@ -56,8 +51,8 @@ pub fn render_layers(layer_ref: *RenderLayer, if stride % 32 != 0 { stride = (stride & !(32 - 1)) + 32; } - fail_unless!(stride % 32 == 0); - fail_unless!(stride >= width); + assert!(stride % 32 == 0); + assert!(stride >= width); debug!("tile stride %u", stride); diff --git a/src/servo-gfx/render_task.rs b/src/servo-gfx/render_task.rs index 6b294d3e254..6e58028ea76 100644 --- a/src/servo-gfx/render_task.rs +++ b/src/servo-gfx/render_task.rs @@ -10,13 +10,9 @@ use render_layers::{RenderLayer, render_layers}; use resource::util::spawn_listener; use util::time::time; -use core::libc::size_t; -use core::libc::types::common::c99::uint16_t; use core::cell::Cell; -use core::comm::{Chan, Port, SharedChan}; +use core::comm::{Port, SharedChan}; use core::task::SingleThreaded; -use std::arc::ARC; -use std::arc; use std::task_pool::TaskPool; pub enum Msg { diff --git a/src/servo-gfx/resource/file_loader.rs b/src/servo-gfx/resource/file_loader.rs index 60476f87fa0..c5a100ce9f2 100644 --- a/src/servo-gfx/resource/file_loader.rs +++ b/src/servo-gfx/resource/file_loader.rs @@ -1,14 +1,12 @@ -use core::comm::Chan; use core::task::spawn; -use resource::resource_task::{ProgressMsg, Payload, Done, LoaderTask}; -use std::net::url::Url; +use resource::resource_task::{Payload, Done, LoaderTask}; use core::io::{file_reader, ReaderUtil}; -const READ_SIZE: uint = 1024; +static READ_SIZE: uint = 1024; pub fn factory() -> LoaderTask { let f: LoaderTask = |url, progress_chan| { - fail_unless!(url.scheme == ~"file"); + assert!(url.scheme == ~"file"); do spawn { // FIXME: Resolve bug prevents us from moving the path out of the URL. match file_reader(&Path(url.path)) { diff --git a/src/servo-gfx/resource/http_loader.rs b/src/servo-gfx/resource/http_loader.rs index 31c85e21e96..549ec714802 100644 --- a/src/servo-gfx/resource/http_loader.rs +++ b/src/servo-gfx/resource/http_loader.rs @@ -1,25 +1,23 @@ -use core::comm::{Chan, SharedChan}; +use core::comm::SharedChan; use core::task::spawn; -use resource::resource_task::{ProgressMsg, Payload, Done, LoaderTask}; -use core::cell::Cell; -use std::net::url::Url; +use resource::resource_task::{Payload, Done, LoaderTask}; use http_client; use http_client::{uv_http_request}; pub fn factory() -> LoaderTask { let f: LoaderTask = |url, progress_chan| { - fail_unless!(url.scheme == ~"http"); + assert!(url.scheme == ~"http"); let progress_chan = SharedChan(progress_chan); do spawn { - debug!("http_loader: requesting via http: %?", copy url); - let mut request = uv_http_request(copy url); + debug!("http_loader: requesting via http: %?", url.clone()); + let mut request = uv_http_request(url.clone()); let errored = @mut false; - let url = copy url; + let url = url.clone(); { let progress_chan = progress_chan.clone(); do request.begin |event| { - let url = copy url; + let url = url.clone(); match event { http_client::Status(*) => { } http_client::Payload(data) => { diff --git a/src/servo-gfx/resource/image_cache_task.rs b/src/servo-gfx/resource/image_cache_task.rs index c9c54e74c03..e4c7aed156f 100644 --- a/src/servo-gfx/resource/image_cache_task.rs +++ b/src/servo-gfx/resource/image_cache_task.rs @@ -1,12 +1,11 @@ -use image::base::{Image, load_from_memory, test_image_bin}; +use image::base::{Image, load_from_memory}; use resource::resource_task; use resource::resource_task::ResourceTask; -use util::url::{make_url, UrlMap, url_map}; +use util::url::{UrlMap, url_map}; use clone_arc = std::arc::clone; use core::comm::{Chan, Port, SharedChan, stream}; use core::task::spawn; -use resource::util::spawn_listener; use core::to_str::ToStr; use core::util::replace; use std::arc::ARC; @@ -49,7 +48,7 @@ pub enum ImageResponseMsg { } impl ImageResponseMsg { - pure fn clone(&self) -> ImageResponseMsg { + fn clone(&self) -> ImageResponseMsg { match *self { ImageReady(ref img) => ImageReady(unsafe { clone_arc(img) }), ImageNotReady => ImageNotReady, @@ -59,7 +58,7 @@ impl ImageResponseMsg { } impl Eq for ImageResponseMsg { - pure fn eq(&self, other: &ImageResponseMsg) -> bool { + fn eq(&self, other: &ImageResponseMsg) -> bool { // FIXME: Bad copies match (self.clone(), other.clone()) { (ImageReady(*), ImageReady(*)) => fail!(~"unimplemented comparison"), @@ -71,7 +70,7 @@ impl Eq for ImageResponseMsg { | (ImageFailed, _) => false } } - pure fn ne(&self, other: &ImageResponseMsg) -> bool { + fn ne(&self, other: &ImageResponseMsg) -> bool { return !(*self).eq(other); } } @@ -199,7 +198,7 @@ impl ImageCache { } OnMsg(handler) => msg_handlers.push(handler), Exit(response) => { - fail_unless!(self.need_exit.is_none()); + assert!(self.need_exit.is_none()); self.need_exit = Some(response); } } @@ -234,7 +233,7 @@ impl ImageCache { priv fn get_state(&self, url: Url) -> ImageState { match self.state_map.find(&url) { - Some(state) => state, + Some(state) => *state, None => Init } } @@ -317,7 +316,7 @@ impl ImageCache { } Prefetched(data_cell) => { - fail_unless!(!data_cell.is_empty()); + assert!(!data_cell.is_empty()); let data = data_cell.take(); let to_cache = self.chan.clone(); @@ -329,7 +328,7 @@ impl ImageCache { debug!("image_cache_task: started image decode for %s", url.to_str()); let image = decode(data); let image = if image.is_some() { - Some(ARC(~option::unwrap(image))) + Some(ARC(~image.unwrap())) } else { None }; @@ -376,7 +375,7 @@ impl ImageCache { priv fn purge_waiters(&self, url: Url, f: &fn() -> ImageResponseMsg) { match self.wait_map.find(&url) { Some(waiters) => { - let waiters = &mut *waiters; + let waiters = *waiters; let mut new_waiters = ~[]; new_waiters <-> *waiters; @@ -427,7 +426,7 @@ impl ImageCache { // We don't have this image yet match self.wait_map.find(&url) { Some(waiters) => { - vec::push(&mut *waiters, response); + vec::push(*waiters, response); } None => { self.wait_map.insert(url, @mut ~[response]); @@ -598,7 +597,7 @@ fn should_not_request_url_from_resource_task_on_multiple_prefetches() { url_requested.recv(); image_cache_task.exit(); mock_resource_task.send(resource_task::Exit); - fail_unless!(!url_requested.peek()) + assert!(!url_requested.peek()) } #[test] @@ -621,7 +620,7 @@ fn should_return_image_not_ready_if_data_has_not_arrived() { image_cache_task.send(Decode(copy url)); let (response_chan, response_port) = stream(); image_cache_task.send(GetImage(url, response_chan)); - fail_unless!(response_port.recv() == ImageNotReady); + assert!(response_port.recv() == ImageNotReady); wait_chan.send(()); image_cache_task.exit(); mock_resource_task.send(resource_task::Exit); @@ -747,7 +746,7 @@ fn should_not_request_image_from_resource_task_if_image_is_already_available() { // Our resource task should not have received another request for the image // because it's already cached - fail_unless!(!image_bin_sent.peek()); + assert!(!image_bin_sent.peek()); } #[test] @@ -794,7 +793,7 @@ fn should_not_request_image_from_resource_task_if_image_fetch_already_failed() { // Our resource task should not have received another request for the image // because it's already cached - fail_unless!(!image_bin_sent.peek()); + assert!(!image_bin_sent.peek()); } #[test] diff --git a/src/servo-gfx/resource/local_image_cache.rs b/src/servo-gfx/resource/local_image_cache.rs index 0b3468510f8..078c80804b3 100644 --- a/src/servo-gfx/resource/local_image_cache.rs +++ b/src/servo-gfx/resource/local_image_cache.rs @@ -6,7 +6,7 @@ multiple times and thus triggering reflows multiple times. use clone_arc = std::arc::clone; use std::net::url::Url; -use core::comm::{Port, Chan, stream}; +use core::comm::Port; use resource::image_cache_task::{ImageCacheTask, ImageResponseMsg, Prefetch, Decode, GetImage}; use resource::image_cache_task::{ WaitForImage, ImageReady, ImageNotReady, ImageFailed}; use util::url::{UrlMap, url_map}; @@ -107,7 +107,7 @@ pub impl LocalImageCache { // the compositor should be resonsible for waiting // on the image to load and triggering layout let image_cache_task = self.image_cache_task.clone(); - fail_unless!(self.on_image_available.is_some()); + assert!(self.on_image_available.is_some()); let on_image_available = self.on_image_available.get()(); let url = copy *url; do task::spawn { @@ -134,7 +134,7 @@ pub impl LocalImageCache { priv fn get_state(&self, url: &Url) -> @mut ImageState { match self.state_map.find(url) { - Some(state) => state, + Some(state) => *state, None => { let new_state = @mut ImageState { prefetched: false, diff --git a/src/servo-gfx/resource/resource_task.rs b/src/servo-gfx/resource/resource_task.rs index 24da1999baf..c7c157a153a 100644 --- a/src/servo-gfx/resource/resource_task.rs +++ b/src/servo-gfx/resource/resource_task.rs @@ -7,7 +7,6 @@ A task that takes a URL and streams back the binary data use core::cell::Cell; use core::comm::{Chan, Port, SharedChan}; use resource::util::spawn_listener; -use std::net::url; use std::net::url::{Url, to_str}; use super::{file_loader, http_loader}; @@ -18,7 +17,7 @@ pub enum ControlMsg { } /// Messages sent in response to a `Load` message -#[deriving_eq] +#[deriving(Eq)] pub enum ProgressMsg { /// Binary data - there may be multiple of these Payload(~[u8]), @@ -80,7 +79,7 @@ impl ResourceManager { loop { match self.from_client.recv() { Load(url, progress_chan) => { - self.load(copy url, progress_chan) + self.load(url.clone(), progress_chan) } Exit => { break @@ -130,7 +129,7 @@ fn test_bad_scheme() { let progress = Port(); resource_task.send(Load(url::from_str(~"bogus://whatever").get(), progress.chan())); match progress.recv() { - Done(result) => { fail_unless!(result.is_err()) } + Done(result) => { assert!(result.is_err()) } _ => fail } resource_task.send(Exit); @@ -148,7 +147,7 @@ fn should_delegate_to_scheme_loader() { let resource_task = create_resource_task_with_loaders(loader_factories); let progress = Port(); resource_task.send(Load(url::from_str(~"snicklefritz://heya").get(), progress.chan())); - fail_unless!(progress.recv() == Payload(payload)); - fail_unless!(progress.recv() == Done(Ok(()))); + assert!(progress.recv() == Payload(payload)); + assert!(progress.recv() == Done(Ok(()))); resource_task.send(Exit); } diff --git a/src/servo-gfx/servo_gfx.rc b/src/servo-gfx/servo_gfx.rc index fcc8c221aa1..7baa4aa4bef 100644 --- a/src/servo-gfx/servo_gfx.rc +++ b/src/servo-gfx/servo_gfx.rc @@ -11,6 +11,14 @@ extern mod http_client; extern mod stb_image; extern mod std; +pub use servo_util = util; +pub use gfx_font = font; +pub use gfx_font_context = font_context; +pub use gfx_font_list = font_list; +pub use servo_gfx_font = font; +pub use servo_gfx_font_list = font_list; +pub use servo_gfx_util = util; + priv mod render_context; // Rendering @@ -82,12 +90,3 @@ pub mod util { pub mod url; pub mod vec; } - -pub use servo_util = util; -pub use gfx_font = font; -pub use gfx_font_context = font_context; -pub use gfx_font_list = font_list; -pub use servo_gfx_font = font; -pub use servo_gfx_font_list = font_list; -pub use servo_gfx_util = util; - diff --git a/src/servo-gfx/surface.rs b/src/servo-gfx/surface.rs index 0cbb3f9b817..0b57bc356ad 100644 --- a/src/servo-gfx/surface.rs +++ b/src/servo-gfx/surface.rs @@ -1,6 +1,6 @@ use geom::size::Size2D; -#[deriving_eq] +#[deriving(Eq)] pub enum format { fo_rgba_8888 // TODO: RGB 565, others? @@ -21,12 +21,12 @@ pub struct ImageSurface { } impl ImageSurface { - static pub fn new(size: Size2D, format: format) -> ImageSurface { - ImageSurface { - size: copy size, - format: format, - buffer: vec::from_elem((size.area() as uint) * format.bpp(), 0u8) - } + pub fn new(size: Size2D, format: format) -> ImageSurface { + ImageSurface { + size: copy size, + format: format, + buffer: vec::from_elem((size.area() as uint) * format.bpp(), 0u8) } + } } diff --git a/src/servo-gfx/text/glyph.rs b/src/servo-gfx/text/glyph.rs index c5f0e0137f4..7a91c5e128d 100644 --- a/src/servo-gfx/text/glyph.rs +++ b/src/servo-gfx/text/glyph.rs @@ -26,30 +26,30 @@ struct GlyphEntry { value : u32 } -pure fn GlyphEntry(value: u32) -> GlyphEntry { GlyphEntry { value: value } } +fn GlyphEntry(value: u32) -> GlyphEntry { GlyphEntry { value: value } } /// The index of a particular glyph within a font pub type GlyphIndex = u32; // TODO: unify with bit flags? -#[deriving_eq] +#[deriving(Eq)] pub enum BreakType { BreakTypeNone, BreakTypeNormal, BreakTypeHyphen } -const BREAK_TYPE_NONE : u8 = 0x0u8; -const BREAK_TYPE_NORMAL : u8 = 0x1u8; -const BREAK_TYPE_HYPHEN : u8 = 0x2u8; +static BREAK_TYPE_NONE : u8 = 0x0u8; +static BREAK_TYPE_NORMAL : u8 = 0x1u8; +static BREAK_TYPE_HYPHEN : u8 = 0x2u8; -pure fn break_flag_to_enum(flag: u8) -> BreakType { +fn break_flag_to_enum(flag: u8) -> BreakType { if (flag & BREAK_TYPE_NORMAL) != 0 { return BreakTypeNormal; } if (flag & BREAK_TYPE_HYPHEN) != 0 { return BreakTypeHyphen; } BreakTypeNone } -pure fn break_enum_to_flag(e: BreakType) -> u8 { +fn break_enum_to_flag(e: BreakType) -> u8 { match e { BreakTypeNone => BREAK_TYPE_NONE, BreakTypeNormal => BREAK_TYPE_NORMAL, @@ -59,16 +59,16 @@ pure fn break_enum_to_flag(e: BreakType) -> u8 { // TODO: make this more type-safe. -const FLAG_CHAR_IS_SPACE : u32 = 0x10000000u32; +static FLAG_CHAR_IS_SPACE : u32 = 0x10000000u32; // These two bits store some BREAK_TYPE_* flags -const FLAG_CAN_BREAK_MASK : u32 = 0x60000000u32; -const FLAG_CAN_BREAK_SHIFT : u32 = 29; -const FLAG_IS_SIMPLE_GLYPH : u32 = 0x80000000u32; +static FLAG_CAN_BREAK_MASK : u32 = 0x60000000u32; +static FLAG_CAN_BREAK_SHIFT : u32 = 29; +static FLAG_IS_SIMPLE_GLYPH : u32 = 0x80000000u32; // glyph advance; in Au's. -const GLYPH_ADVANCE_MASK : u32 = 0x0FFF0000u32; -const GLYPH_ADVANCE_SHIFT : u32 = 16; -const GLYPH_ID_MASK : u32 = 0x0000FFFFu32; +static GLYPH_ADVANCE_MASK : u32 = 0x0FFF0000u32; +static GLYPH_ADVANCE_SHIFT : u32 = 16; +static GLYPH_ID_MASK : u32 = 0x0000FFFFu32; // Non-simple glyphs (more than one glyph per char; missing glyph, // newline, tab, large advance, or nonzero x/y offsets) may have one @@ -79,38 +79,38 @@ const GLYPH_ID_MASK : u32 = 0x0000FFFFu32; // The number of detailed glyphs for this char. If the char couldn't // be mapped to a glyph (!FLAG_NOT_MISSING), then this actually holds // the UTF8 code point instead. -const GLYPH_COUNT_MASK : u32 = 0x00FFFF00u32; -const GLYPH_COUNT_SHIFT : u32 = 8; +static GLYPH_COUNT_MASK : u32 = 0x00FFFF00u32; +static GLYPH_COUNT_SHIFT : u32 = 8; // N.B. following Gecko, these are all inverted so that a lot of // missing chars can be memset with zeros in one fell swoop. -const FLAG_NOT_MISSING : u32 = 0x00000001u32; -const FLAG_NOT_CLUSTER_START : u32 = 0x00000002u32; -const FLAG_NOT_LIGATURE_GROUP_START : u32 = 0x00000004u32; +static FLAG_NOT_MISSING : u32 = 0x00000001u32; +static FLAG_NOT_CLUSTER_START : u32 = 0x00000002u32; +static FLAG_NOT_LIGATURE_GROUP_START : u32 = 0x00000004u32; -const FLAG_CHAR_IS_TAB : u32 = 0x00000008u32; -const FLAG_CHAR_IS_NEWLINE : u32 = 0x00000010u32; -const FLAG_CHAR_IS_LOW_SURROGATE : u32 = 0x00000020u32; -const CHAR_IDENTITY_FLAGS_MASK : u32 = 0x00000038u32; +static FLAG_CHAR_IS_TAB : u32 = 0x00000008u32; +static FLAG_CHAR_IS_NEWLINE : u32 = 0x00000010u32; +static FLAG_CHAR_IS_LOW_SURROGATE : u32 = 0x00000020u32; +static CHAR_IDENTITY_FLAGS_MASK : u32 = 0x00000038u32; -pure fn is_simple_glyph_id(glyphId: GlyphIndex) -> bool { +fn is_simple_glyph_id(glyphId: GlyphIndex) -> bool { ((glyphId as u32) & GLYPH_ID_MASK) == glyphId } -pure fn is_simple_advance(advance: Au) -> bool { +fn is_simple_advance(advance: Au) -> bool { let unsignedAu = advance.to_int() as u32; (unsignedAu & (GLYPH_ADVANCE_MASK >> GLYPH_ADVANCE_SHIFT)) == unsignedAu } type DetailedGlyphCount = u16; -pure fn InitialGlyphEntry() -> GlyphEntry { +fn InitialGlyphEntry() -> GlyphEntry { GlyphEntry { value: 0 } } // Creates a GlyphEntry for the common case -pure fn SimpleGlyphEntry(index: GlyphIndex, advance: Au) -> GlyphEntry { - fail_unless!(is_simple_glyph_id(index)); - fail_unless!(is_simple_advance(advance)); +fn SimpleGlyphEntry(index: GlyphIndex, advance: Au) -> GlyphEntry { + assert!(is_simple_glyph_id(index)); + assert!(is_simple_advance(advance)); let index_mask = index as u32; let advance_mask = (*advance as u32) << GLYPH_ADVANCE_SHIFT; @@ -122,8 +122,8 @@ pure fn SimpleGlyphEntry(index: GlyphIndex, advance: Au) -> GlyphEntry { // Create a GlyphEntry for uncommon case; should be accompanied by // initialization of the actual DetailedGlyph data in DetailedGlyphStore -pure fn ComplexGlyphEntry(startsCluster: bool, startsLigature: bool, glyphCount: uint) -> GlyphEntry { - fail_unless!(glyphCount <= u16::max_value as uint); +fn ComplexGlyphEntry(startsCluster: bool, startsLigature: bool, glyphCount: uint) -> GlyphEntry { + assert!(glyphCount <= u16::max_value as uint); debug!("Creating complex glyph entry: startsCluster=%?, startsLigature=%?, glyphCount=%?", startsCluster, startsLigature, glyphCount); @@ -145,8 +145,8 @@ pure fn ComplexGlyphEntry(startsCluster: bool, startsLigature: bool, glyphCount: // Create a GlyphEntry for the case where glyphs couldn't be found // for the specified character. -pure fn MissingGlyphsEntry(glyphCount: uint) -> GlyphEntry { - fail_unless!(glyphCount <= u16::max_value as uint); +fn MissingGlyphsEntry(glyphCount: uint) -> GlyphEntry { + assert!(glyphCount <= u16::max_value as uint); GlyphEntry { value: (glyphCount as u32) << GLYPH_COUNT_SHIFT @@ -158,91 +158,91 @@ pure fn MissingGlyphsEntry(glyphCount: uint) -> GlyphEntry { impl GlyphEntry { // getter methods #[inline(always)] - pure fn advance(&self) -> Au { - //fail_unless!(self.is_simple()); + fn advance(&self) -> Au { + //assert!(self.is_simple()); NumCast::from((self.value & GLYPH_ADVANCE_MASK) >> GLYPH_ADVANCE_SHIFT) } - pure fn index(&self) -> GlyphIndex { - //fail_unless!(self.is_simple()); + fn index(&self) -> GlyphIndex { + //assert!(self.is_simple()); self.value & GLYPH_ID_MASK } - pure fn offset(&self) -> Point2D { - //fail_unless!(self.is_simple()); + fn offset(&self) -> Point2D { + //assert!(self.is_simple()); Point2D(Au(0), Au(0)) } - pure fn is_ligature_start(&self) -> bool { + fn is_ligature_start(&self) -> bool { self.has_flag(!FLAG_NOT_LIGATURE_GROUP_START) } - pure fn is_cluster_start(&self) -> bool { + fn is_cluster_start(&self) -> bool { self.has_flag(!FLAG_NOT_CLUSTER_START) } // True if original char was normal (U+0020) space. Other chars may // map to space glyph, but this does not account for them. - pure fn char_is_space(&self) -> bool { + fn char_is_space(&self) -> bool { self.has_flag(FLAG_CHAR_IS_SPACE) } - pure fn char_is_tab(&self) -> bool { + fn char_is_tab(&self) -> bool { !self.is_simple() && self.has_flag(FLAG_CHAR_IS_TAB) } - pure fn char_is_newline(&self) -> bool { + fn char_is_newline(&self) -> bool { !self.is_simple() && self.has_flag(FLAG_CHAR_IS_NEWLINE) } - pure fn can_break_before(&self) -> BreakType { + fn can_break_before(&self) -> BreakType { let flag = ((self.value & FLAG_CAN_BREAK_MASK) >> FLAG_CAN_BREAK_SHIFT) as u8; break_flag_to_enum(flag) } // setter methods #[inline(always)] - pure fn set_char_is_space(&self) -> GlyphEntry { + fn set_char_is_space(&self) -> GlyphEntry { GlyphEntry(self.value | FLAG_CHAR_IS_SPACE) } #[inline(always)] - pure fn set_char_is_tab(&self) -> GlyphEntry { - fail_unless!(!self.is_simple()); + fn set_char_is_tab(&self) -> GlyphEntry { + assert!(!self.is_simple()); GlyphEntry(self.value | FLAG_CHAR_IS_TAB) } #[inline(always)] - pure fn set_char_is_newline(&self) -> GlyphEntry { - fail_unless!(!self.is_simple()); + fn set_char_is_newline(&self) -> GlyphEntry { + assert!(!self.is_simple()); GlyphEntry(self.value | FLAG_CHAR_IS_NEWLINE) } #[inline(always)] - pure fn set_can_break_before(&self, e: BreakType) -> GlyphEntry { + fn set_can_break_before(&self, e: BreakType) -> GlyphEntry { let flag = (break_enum_to_flag(e) as u32) << FLAG_CAN_BREAK_SHIFT; GlyphEntry(self.value | flag) } // helper methods - /*priv*/ pure fn glyph_count(&self) -> u16 { - fail_unless!(!self.is_simple()); + /*priv*/ fn glyph_count(&self) -> u16 { + assert!(!self.is_simple()); ((self.value & GLYPH_COUNT_MASK) >> GLYPH_COUNT_SHIFT) as u16 } #[inline(always)] - pure fn is_simple(&self) -> bool { + fn is_simple(&self) -> bool { self.has_flag(FLAG_IS_SIMPLE_GLYPH) } #[inline(always)] - /*priv*/ pure fn has_flag(&self, flag: u32) -> bool { + /*priv*/ fn has_flag(&self, flag: u32) -> bool { (self.value & flag) != 0 } #[inline(always)] - pure fn adapt_character_flags_of_entry(&self, other: GlyphEntry) -> GlyphEntry { + fn adapt_character_flags_of_entry(&self, other: GlyphEntry) -> GlyphEntry { GlyphEntry { value: self.value | other.value } } } @@ -267,7 +267,7 @@ fn DetailedGlyph(index: GlyphIndex, } } -#[deriving_eq] +#[deriving(Eq)] struct DetailedGlyphRecord { // source string offset/GlyphEntry offset in the TextRun entry_offset: uint, @@ -276,16 +276,16 @@ struct DetailedGlyphRecord { } impl Ord for DetailedGlyphRecord { - pure fn lt(&self, other: &DetailedGlyphRecord) -> bool { + fn lt(&self, other: &DetailedGlyphRecord) -> bool { self.entry_offset < other.entry_offset } - pure fn le(&self, other: &DetailedGlyphRecord) -> bool { + fn le(&self, other: &DetailedGlyphRecord) -> bool { self.entry_offset <= other.entry_offset } - pure fn ge(&self, other: &DetailedGlyphRecord) -> bool { + fn ge(&self, other: &DetailedGlyphRecord) -> bool { self.entry_offset >= other.entry_offset } - pure fn gt(&self, other: &DetailedGlyphRecord) -> bool { + fn gt(&self, other: &DetailedGlyphRecord) -> bool { self.entry_offset > other.entry_offset } } @@ -333,7 +333,7 @@ impl DetailedGlyphStore { self.lookup_is_sorted = false; } - pure fn get_detailed_glyphs_for_entry(&self, entry_offset: uint, count: u16) -> &self/[DetailedGlyph] { + fn get_detailed_glyphs_for_entry(&self, entry_offset: uint, count: u16) -> &'self [DetailedGlyph] { debug!("Requesting detailed glyphs[n=%u] for entry[off=%u]", count as uint, entry_offset); // FIXME: Is this right? --pcwalton @@ -342,8 +342,8 @@ impl DetailedGlyphStore { return vec::slice(self.detail_buffer, 0, 0); } - fail_unless!((count as uint) <= self.detail_buffer.len()); - fail_unless!(self.lookup_is_sorted); + assert!((count as uint) <= self.detail_buffer.len()); + assert!(self.lookup_is_sorted); let key = DetailedGlyphRecord { entry_offset: entry_offset, @@ -355,19 +355,19 @@ impl DetailedGlyphStore { match records.binary_search_index(&key) { None => fail!(~"Invalid index not found in detailed glyph lookup table!"), Some(i) => { - fail_unless!(i + (count as uint) <= self.detail_buffer.len()); + assert!(i + (count as uint) <= self.detail_buffer.len()); // return a slice into the buffer vec::slice(self.detail_buffer, i, i + count as uint) } } } - pure fn get_detailed_glyph_with_index(&self, - entry_offset: uint, - detail_offset: u16) - -> &self/DetailedGlyph { - fail_unless!((detail_offset as uint) <= self.detail_buffer.len()); - fail_unless!(self.lookup_is_sorted); + fn get_detailed_glyph_with_index(&self, + entry_offset: uint, + detail_offset: u16) + -> &'self DetailedGlyph { + assert!((detail_offset as uint) <= self.detail_buffer.len()); + assert!(self.lookup_is_sorted); let key = DetailedGlyphRecord { entry_offset: entry_offset, @@ -379,7 +379,7 @@ impl DetailedGlyphStore { match records.binary_search_index(&key) { None => fail!(~"Invalid index not found in detailed glyph lookup table!"), Some(i) => { - fail_unless!(i + (detail_offset as uint) < self.detail_buffer.len()); + assert!(i + (detail_offset as uint) < self.detail_buffer.len()); &self.detail_buffer[i+(detail_offset as uint)] } } @@ -417,13 +417,12 @@ pub struct GlyphData { ligature_start: bool, } -pub pure fn GlyphData(index: GlyphIndex, - advance: Au, - offset: Option>, - is_missing: bool, - cluster_start: bool, - ligature_start: bool) -> GlyphData { - +pub fn GlyphData(index: GlyphIndex, + advance: Au, + offset: Option>, + is_missing: bool, + cluster_start: bool, + ligature_start: bool) -> GlyphData { let _offset = match offset { None => geometry::zero_point(), Some(o) => o @@ -443,7 +442,7 @@ pub pure fn GlyphData(index: GlyphIndex, // through glyphs (either for a particular TextRun offset, or all glyphs). // Rather than eagerly assembling and copying glyph data, it only retrieves // values as they are needed from the GlyphStore, using provided offsets. -enum GlyphInfo { +enum GlyphInfo<'self> { SimpleGlyphInfo(&'self GlyphStore, uint), DetailGlyphInfo(&'self GlyphStore, uint, u16) } @@ -496,8 +495,8 @@ pub struct GlyphStore { pub impl GlyphStore { // Initializes the glyph store, but doesn't actually shape anything. // Use the set_glyph, set_glyphs() methods to store glyph data. - static fn new(length: uint) -> GlyphStore { - fail_unless!(length > 0); + fn new(length: uint) -> GlyphStore { + assert!(length > 0); GlyphStore { entry_buffer: vec::from_elem(length, InitialGlyphEntry()), @@ -511,15 +510,15 @@ pub impl GlyphStore { fn add_glyph_for_char_index(&mut self, i: uint, data: &GlyphData) { - pure fn glyph_is_compressible(data: &GlyphData) -> bool { + fn glyph_is_compressible(data: &GlyphData) -> bool { is_simple_glyph_id(data.index) && is_simple_advance(data.advance) && data.offset == geometry::zero_point() && data.cluster_start // others are stored in detail buffer } - fail_unless!(data.ligature_start); // can't compress ligature continuation glyphs. - fail_unless!(i < self.entry_buffer.len()); + assert!(data.ligature_start); // can't compress ligature continuation glyphs. + assert!(i < self.entry_buffer.len()); let entry = match (data.is_missing, glyph_is_compressible(data)) { (true, _) => MissingGlyphsEntry(1), @@ -535,8 +534,8 @@ pub impl GlyphStore { } fn add_glyphs_for_char_index(&mut self, i: uint, data_for_glyphs: &[GlyphData]) { - fail_unless!(i < self.entry_buffer.len()); - fail_unless!(data_for_glyphs.len() > 0); + assert!(i < self.entry_buffer.len()); + assert!(data_for_glyphs.len() > 0); let glyph_count = data_for_glyphs.len(); @@ -564,7 +563,7 @@ pub impl GlyphStore { // used when a character index has no associated glyph---for example, a ligature continuation. fn add_nonglyph_for_char_index(&mut self, i: uint, cluster_start: bool, ligature_start: bool) { - fail_unless!(i < self.entry_buffer.len()); + assert!(i < self.entry_buffer.len()); let entry = ComplexGlyphEntry(cluster_start, ligature_start, 0); debug!("adding spacer for chracter without associated glyph[idx=%u]", i); @@ -572,20 +571,20 @@ pub impl GlyphStore { self.entry_buffer[i] = entry; } - pure fn iter_glyphs_for_char_index(&self, i: uint, cb: &fn(uint, GlyphInfo/&self) -> bool) -> bool { - fail_unless!(i < self.entry_buffer.len()); + fn iter_glyphs_for_char_index(&self, i: uint, cb: &fn(uint, &GlyphInfo<'self>) -> bool) -> bool { + assert!(i < self.entry_buffer.len()); let entry = &self.entry_buffer[i]; match entry.is_simple() { true => { - let proxy = SimpleGlyphInfo(self, i); + let proxy = &SimpleGlyphInfo(self, i); cb(i, proxy); }, false => { let glyphs = self.detail_store.get_detailed_glyphs_for_entry(i, entry.glyph_count()); for uint::range(0, glyphs.len()) |j| { - let proxy = DetailGlyphInfo(self, i, j as u16); + let proxy = &DetailGlyphInfo(self, i, j as u16); cb(i, proxy); } } @@ -593,7 +592,7 @@ pub impl GlyphStore { return true; } - pure fn iter_glyphs_for_char_range(&self, range: &const Range, cb: &fn(uint, GlyphInfo/&self) -> bool) { + fn iter_glyphs_for_char_range(&self, range: &Range, cb: &fn(uint, &GlyphInfo<'self>) -> bool) { if range.begin() >= self.entry_buffer.len() { error!("iter_glyphs_for_range: range.begin beyond length!"); return; @@ -608,64 +607,64 @@ pub impl GlyphStore { } } - pure fn iter_all_glyphs(&self, cb: &fn(uint, GlyphInfo/&self) -> bool) { + fn iter_all_glyphs(&self, cb: &fn(uint, &GlyphInfo<'self>) -> bool) { for uint::range(0, self.entry_buffer.len()) |i| { if !self.iter_glyphs_for_char_index(i, cb) { break; } } } // getter methods - pure fn char_is_space(&self, i: uint) -> bool { - fail_unless!(i < self.entry_buffer.len()); + fn char_is_space(&self, i: uint) -> bool { + assert!(i < self.entry_buffer.len()); self.entry_buffer[i].char_is_space() } - pure fn char_is_tab(&self, i: uint) -> bool { - fail_unless!(i < self.entry_buffer.len()); + fn char_is_tab(&self, i: uint) -> bool { + assert!(i < self.entry_buffer.len()); self.entry_buffer[i].char_is_tab() } - pure fn char_is_newline(&self, i: uint) -> bool { - fail_unless!(i < self.entry_buffer.len()); + fn char_is_newline(&self, i: uint) -> bool { + assert!(i < self.entry_buffer.len()); self.entry_buffer[i].char_is_newline() } - pure fn is_ligature_start(&self, i: uint) -> bool { - fail_unless!(i < self.entry_buffer.len()); + fn is_ligature_start(&self, i: uint) -> bool { + assert!(i < self.entry_buffer.len()); self.entry_buffer[i].is_ligature_start() } - pure fn is_cluster_start(&self, i: uint) -> bool { - fail_unless!(i < self.entry_buffer.len()); + fn is_cluster_start(&self, i: uint) -> bool { + assert!(i < self.entry_buffer.len()); self.entry_buffer[i].is_cluster_start() } - pure fn can_break_before(&self, i: uint) -> BreakType { - fail_unless!(i < self.entry_buffer.len()); + fn can_break_before(&self, i: uint) -> BreakType { + assert!(i < self.entry_buffer.len()); self.entry_buffer[i].can_break_before() } // setter methods fn set_char_is_space(&mut self, i: uint) { - fail_unless!(i < self.entry_buffer.len()); + assert!(i < self.entry_buffer.len()); let entry = self.entry_buffer[i]; self.entry_buffer[i] = entry.set_char_is_space(); } fn set_char_is_tab(&mut self, i: uint) { - fail_unless!(i < self.entry_buffer.len()); + assert!(i < self.entry_buffer.len()); let entry = self.entry_buffer[i]; self.entry_buffer[i] = entry.set_char_is_tab(); } fn set_char_is_newline(&mut self, i: uint) { - fail_unless!(i < self.entry_buffer.len()); + assert!(i < self.entry_buffer.len()); let entry = self.entry_buffer[i]; self.entry_buffer[i] = entry.set_char_is_newline(); } fn set_can_break_before(&mut self, i: uint, t: BreakType) { - fail_unless!(i < self.entry_buffer.len()); + assert!(i < self.entry_buffer.len()); let entry = self.entry_buffer[i]; self.entry_buffer[i] = entry.set_can_break_before(t); } diff --git a/src/servo-gfx/text/harfbuzz/shaper.rs b/src/servo-gfx/text/harfbuzz/shaper.rs index 23bf2e2f3ee..a0f8cda7f0a 100644 --- a/src/servo-gfx/text/harfbuzz/shaper.rs +++ b/src/servo-gfx/text/harfbuzz/shaper.rs @@ -10,22 +10,18 @@ use text::glyph::{GlyphStore, GlyphIndex, GlyphData}; use text::shaper::ShaperMethods; use gfx_font::{FontHandleMethods, FontTableMethods}; -use servo_util::range; use util::range::Range; -use core::libc::types::common::c99::int32_t; use core::libc::{c_uint, c_int, c_void, c_char}; use core::util::ignore; -//use dvec::DVec; -use std::arc; use text::harfbuzz::shaper::harfbuzz::{HB_MEMORY_MODE_READONLY, HB_DIRECTION_LTR, hb_blob_t}; use text::harfbuzz::shaper::harfbuzz::{hb_face_t, hb_font_t}; use text::harfbuzz::shaper::harfbuzz::{hb_font_funcs_t, hb_buffer_t, hb_codepoint_t, hb_bool_t}; use text::harfbuzz::shaper::harfbuzz::{hb_glyph_position_t}; -use text::harfbuzz::shaper::harfbuzz::{hb_glyph_info_t, hb_var_int_t, hb_position_t}; -use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_blob_create, hb_blob_destroy}; -use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_face_create, hb_face_destroy}; +use text::harfbuzz::shaper::harfbuzz::{hb_glyph_info_t, hb_position_t}; +use text::harfbuzz::shaper::harfbuzz::bindgen::hb_blob_create; +use text::harfbuzz::shaper::harfbuzz::bindgen::hb_face_destroy; use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_font_create, hb_font_destroy}; use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_buffer_create}; use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_buffer_destroy}; @@ -40,14 +36,13 @@ use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_font_funcs_destroy}; use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_font_set_funcs}; use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_font_funcs_set_glyph_h_advance_func}; use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_font_funcs_set_glyph_func}; -use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_font_funcs_set_glyph_h_kerning_func}; use text::harfbuzz::shaper::harfbuzz::{HB_MEMORY_MODE_READONLY, HB_DIRECTION_LTR}; use text::harfbuzz::shaper::harfbuzz::{hb_blob_t, hb_face_t, hb_font_t, hb_font_funcs_t}; use text::harfbuzz::shaper::harfbuzz::{hb_buffer_t, hb_codepoint_t, hb_bool_t}; -use text::harfbuzz::shaper::harfbuzz::{hb_glyph_position_t, hb_glyph_info_t, hb_var_int_t}; +use text::harfbuzz::shaper::harfbuzz::{hb_glyph_position_t, hb_glyph_info_t}; use text::harfbuzz::shaper::harfbuzz::{hb_position_t, hb_tag_t}; -use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_blob_create, hb_blob_destroy, +use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_blob_create, hb_face_create_for_tables, hb_face_destroy, hb_font_create, hb_font_destroy, hb_buffer_create, hb_buffer_destroy, @@ -59,8 +54,7 @@ use text::harfbuzz::shaper::harfbuzz::bindgen::{hb_blob_create, hb_blob_destroy, hb_font_funcs_create, hb_font_funcs_destroy, hb_font_set_funcs, hb_font_funcs_set_glyph_h_advance_func, - hb_font_funcs_set_glyph_func, - hb_font_funcs_set_glyph_h_kerning_func}; + hb_font_funcs_set_glyph_func}; use text::util::{float_to_fixed, fixed_to_float, fixed_to_rounded_int}; @@ -78,16 +72,16 @@ pub struct ShapedGlyphEntry { } pub impl ShapedGlyphData { - static pure fn new(buffer: *hb_buffer_t) -> ShapedGlyphData { + fn new(buffer: *hb_buffer_t) -> ShapedGlyphData { unsafe { let glyph_count = 0 as c_uint; let glyph_infos = hb_buffer_get_glyph_infos(buffer, ptr::to_unsafe_ptr(&glyph_count)); let glyph_count = glyph_count as uint; - fail_unless!(glyph_infos.is_not_null()); + assert!(glyph_infos.is_not_null()); let pos_count = 0 as c_uint; let pos_infos = hb_buffer_get_glyph_positions(buffer, ptr::to_unsafe_ptr(&pos_count)); - fail_unless!(pos_infos.is_not_null()); - fail_unless!(glyph_count == pos_count as uint); + assert!(pos_infos.is_not_null()); + assert!(glyph_count == pos_count as uint); ShapedGlyphData { count: glyph_count, @@ -98,8 +92,8 @@ pub impl ShapedGlyphData { } #[inline(always)] - priv pure fn byte_offset_of_glyph(&const self, i: uint) -> uint { - fail_unless!(i < self.count); + priv fn byte_offset_of_glyph(&self, i: uint) -> uint { + assert!(i < self.count); let glyph_info_i = ptr::offset(self.glyph_infos, i); unsafe { @@ -107,11 +101,11 @@ pub impl ShapedGlyphData { } } - pure fn len(&self) -> uint { self.count } + fn len(&self) -> uint { self.count } // Returns shaped glyph data for one glyph, and updates the y-position of the pen. fn get_entry_for_glyph(&self, i: uint, y_pos: &mut Au) -> ShapedGlyphEntry { - fail_unless!(i < self.count); + assert!(i < self.count); let glyph_info_i = ptr::offset(self.glyph_infos, i); let pos_info_i = ptr::offset(self.pos_infos, i); @@ -128,7 +122,7 @@ pub impl ShapedGlyphData { *y_pos -= y_advance; } - Some(Point2D(x_offset, y_pos - y_offset)) + Some(Point2D(x_offset, *y_pos - y_offset)) }; unsafe { @@ -149,21 +143,22 @@ pub struct HarfbuzzShaper { priv hb_funcs: *hb_font_funcs_t, } +#[unsafe_destructor] impl Drop for HarfbuzzShaper { fn finalize(&self) { - fail_unless!(self.hb_face.is_not_null()); + assert!(self.hb_face.is_not_null()); hb_face_destroy(self.hb_face); - fail_unless!(self.hb_font.is_not_null()); + assert!(self.hb_font.is_not_null()); hb_font_destroy(self.hb_font); - fail_unless!(self.hb_funcs.is_not_null()); + assert!(self.hb_funcs.is_not_null()); hb_font_funcs_destroy(self.hb_funcs); } } pub impl HarfbuzzShaper { - static pub fn new(font: @mut Font) -> HarfbuzzShaper { + pub fn new(font: @mut Font) -> HarfbuzzShaper { let hb_face: *hb_face_t = hb_face_create_for_tables(get_font_table_func, ptr::to_unsafe_ptr(font) as *c_void, ptr::null()); let hb_font: *hb_font_t = hb_font_create(hb_face); // Set points-per-em. if zero, performs no hinting in that direction. @@ -192,15 +187,15 @@ pub impl HarfbuzzShaper { } } - static priv fn float_to_fixed(f: float) -> i32 { + priv fn float_to_fixed(f: float) -> i32 { float_to_fixed(16, f) } - static priv fn fixed_to_float(i: hb_position_t) -> float { + priv fn fixed_to_float(i: hb_position_t) -> float { fixed_to_float(16, i) } - static priv fn fixed_to_rounded_int(f: hb_position_t) -> int { + priv fn fixed_to_rounded_int(f: hb_position_t) -> int { fixed_to_rounded_int(16, f) } } @@ -240,7 +235,7 @@ pub impl HarfbuzzShaper { // so, we must be careful to increment this when saving glyph entries. let mut char_idx = 0; - fail_unless!(glyph_count <= char_max); + assert!(glyph_count <= char_max); debug!("Shaped text[char count=%u], got back %u glyph info records.", char_max, glyph_count); if char_max != glyph_count { @@ -248,8 +243,8 @@ pub impl HarfbuzzShaper { } // make map of what chars have glyphs - const NO_GLYPH : i32 = -1; - const CONTINUATION_BYTE : i32 = -2; + static NO_GLYPH : i32 = -1; + static CONTINUATION_BYTE : i32 = -2; let mut byteToGlyph : ~[i32]; // fast path: all chars are single-byte. @@ -271,7 +266,7 @@ pub impl HarfbuzzShaper { // loc refers to a *byte* offset within the utf8 string. let loc = glyph_data.byte_offset_of_glyph(i); if loc < byte_max { - fail_unless!(byteToGlyph[loc] != CONTINUATION_BYTE); + assert!(byteToGlyph[loc] != CONTINUATION_BYTE); byteToGlyph[loc] = i as i32; } else { debug!("ERROR: tried to set out of range byteToGlyph: idx=%u, glyph idx=%u", loc, i); } @@ -361,9 +356,9 @@ pub impl HarfbuzzShaper { } // character/glyph clump must contain characters. - fail_unless!(char_byte_span.length() > 0); + assert!(char_byte_span.length() > 0); // character/glyph clump must contain glyphs. - fail_unless!(glyph_span.length() > 0); + assert!(glyph_span.length() > 0); // now char_span is a ligature clump, formed by the glyphs in glyph_span. // we need to find the chars that correspond to actual glyphs (char_extended_span), @@ -387,12 +382,15 @@ pub impl HarfbuzzShaper { if covered_byte_span.begin() >= byte_max { // oops, out of range. clip and forget this clump. - glyph_span.reset(glyph_span.end(), 0); - char_byte_span.reset(char_byte_span.end(), 0); + let end = glyph_span.end(); // FIXME: borrow checker workaround + glyph_span.reset(end, 0); + let end = char_byte_span.end(); // FIXME: borrow checker workaround + char_byte_span.reset(end, 0); } // clamp to end of text. (I don't think this will be necessary, but..) - covered_byte_span.extend_to(uint::min(covered_byte_span.end(), byte_max)); + let end = covered_byte_span.end(); // FIXME: borrow checker workaround + covered_byte_span.extend_to(uint::min(end, byte_max)); // fast path: 1-to-1 mapping of single char and single glyph. if glyph_span.length() == 1 { @@ -416,7 +414,6 @@ pub impl HarfbuzzShaper { false, // not missing true, // treat as cluster start glyph_i > glyph_span.begin())); // all but first are ligature continuations - glyph_span.adjust_by(1,-1); } // now add the detailed glyph entry. @@ -435,8 +432,10 @@ pub impl HarfbuzzShaper { } // shift up our working spans past things we just handled. - glyph_span.reset(glyph_span.end(), 0); - char_byte_span.reset(char_byte_span.end(), 0); + let end = glyph_span.end(); // FIXME: borrow checker workaround + glyph_span.reset(end, 0); + let end = char_byte_span.end();; // FIXME: borrow checker workaround + char_byte_span.reset(end, 0); char_idx += 1; } @@ -454,7 +453,7 @@ extern fn glyph_func(_font: *hb_font_t, glyph: *mut hb_codepoint_t, _user_data: *c_void) -> hb_bool_t { let font: *Font = font_data as *Font; - fail_unless!(font.is_not_null()); + assert!(font.is_not_null()); unsafe { return match (*font).glyph_index(unicode as char) { Some(g) => { *glyph = g as hb_codepoint_t; true }, @@ -468,7 +467,7 @@ extern fn glyph_h_advance_func(_font: *hb_font_t, glyph: hb_codepoint_t, _user_data: *c_void) -> hb_position_t { let font: *Font = font_data as *Font; - fail_unless!(font.is_not_null()); + assert!(font.is_not_null()); unsafe { let advance = (*font).glyph_h_advance(glyph as GlyphIndex); @@ -480,7 +479,7 @@ extern fn glyph_h_advance_func(_font: *hb_font_t, extern fn get_font_table_func(_face: *hb_face_t, tag: hb_tag_t, user_data: *c_void) -> *hb_blob_t { unsafe { let font: *Font = user_data as *Font; - fail_unless!(font.is_not_null()); + assert!(font.is_not_null()); // TODO(Issue #197): reuse font table data, which will change the unsound trickery here. match (*font).get_table_for_tag(tag as FontTableTag) { @@ -496,7 +495,7 @@ extern fn get_font_table_func(_face: *hb_face_t, tag: hb_tag_t, user_data: *c_vo cast::transmute(skinny_font_table_ptr), // private context for below. destroy_blob_func); // HarfBuzz calls this when blob not needed. }); - fail_unless!(blob.is_not_null()); + assert!(blob.is_not_null()); return blob; } } diff --git a/src/servo-gfx/text/shaper.rs b/src/servo-gfx/text/shaper.rs index f4ea2b0ee47..b5f3d322931 100644 --- a/src/servo-gfx/text/shaper.rs +++ b/src/servo-gfx/text/shaper.rs @@ -8,7 +8,7 @@ use gfx_font::Font; use text::glyph::GlyphStore; use text::harfbuzz; -pub type Shaper/& = harfbuzz::shaper::HarfbuzzShaper; +pub type Shaper = harfbuzz::shaper::HarfbuzzShaper; pub trait ShaperMethods { fn shape_text(&self, text: &str, glyphs: &mut GlyphStore); @@ -17,7 +17,7 @@ pub trait ShaperMethods { // TODO(Issue #163): this is a workaround for static methods and // typedefs not working well together. It should be removed. pub impl Shaper { - static pub fn new(font: @mut Font) -> Shaper { + pub fn new(font: @mut Font) -> Shaper { harfbuzz::shaper::HarfbuzzShaper::new(font) } } diff --git a/src/servo-gfx/text/text_run.rs b/src/servo-gfx/text/text_run.rs index 56987a722e1..694d8236e77 100644 --- a/src/servo-gfx/text/text_run.rs +++ b/src/servo-gfx/text/text_run.rs @@ -1,15 +1,9 @@ use font_context::FontContext; use geometry::Au; use text::glyph::{BreakTypeNormal, GlyphStore}; -use servo_gfx_font::{Font, FontDescriptor, RunMetrics, FontHandleMethods}; +use servo_gfx_font::{Font, FontDescriptor, RunMetrics}; use servo_gfx_util::range::Range; -use core::libc::{c_void}; -use geom::point::Point2D; -use geom::size::Size2D; -use std::arc; -use std::arc::ARC; - pub struct TextRun { text: ~str, font: @mut Font, @@ -40,7 +34,7 @@ impl SendableTextRun { } pub impl TextRun { - static fn new(font: @mut Font, text: ~str) -> TextRun { + fn new(font: @mut Font, text: ~str) -> TextRun { let mut glyph_store = GlyphStore::new(str::char_len(text)); TextRun::compute_potential_breaks(text, &mut glyph_store); font.shape_text(text, &mut glyph_store); @@ -53,7 +47,7 @@ pub impl TextRun { return run; } - static fn compute_potential_breaks(text: &str, glyphs: &mut GlyphStore) { + fn compute_potential_breaks(text: &str, glyphs: &mut GlyphStore) { // TODO(Issue #230): do a better job. See Gecko's LineBreaker. let mut byte_i = 0u; @@ -103,10 +97,10 @@ pub impl TextRun { } } - pure fn char_len(&self) -> uint { self.glyphs.entry_buffer.len() } - pure fn glyphs(&self) -> &self/GlyphStore { &self.glyphs } + fn char_len(&self) -> uint { self.glyphs.entry_buffer.len() } + fn glyphs(&self) -> &'self GlyphStore { &self.glyphs } - pure fn range_is_trimmable_whitespace(&self, range: &const Range) -> bool { + fn range_is_trimmable_whitespace(&self, range: &Range) -> bool { for range.eachi |i| { if !self.glyphs.char_is_space(i) && !self.glyphs.char_is_tab(i) && @@ -115,11 +109,11 @@ pub impl TextRun { return true; } - fn metrics_for_range(&self, range: &const Range) -> RunMetrics { + fn metrics_for_range(&self, range: &Range) -> RunMetrics { self.font.measure_text(self, range) } - fn min_width_for_range(&self, range: &const Range) -> Au { + fn min_width_for_range(&self, range: &Range) -> Au { let mut max_piece_width = Au(0); debug!("iterating outer range %?", range); for self.iter_indivisible_pieces_for_range(range) |piece_range| { @@ -130,7 +124,7 @@ pub impl TextRun { return max_piece_width; } - fn iter_natural_lines_for_range(&self, range: &const Range, f: &fn(&const Range) -> bool) { + fn iter_natural_lines_for_range(&self, range: &Range, f: &fn(&Range) -> bool) { let mut clump = Range::new(range.begin(), 0); let mut in_clump = false; @@ -143,7 +137,7 @@ pub impl TextRun { (true, true) => { in_clump = false; // don't include the linebreak character itself in the clump. - if !f(&const clump) { break } + if !f(&clump) { break } } } } @@ -151,11 +145,11 @@ pub impl TextRun { // flush any remaining chars as a line if in_clump { clump.extend_to(range.end()); - f(&const clump); + f(&clump); } } - fn iter_indivisible_pieces_for_range(&self, range: &const Range, f: &fn(&const Range) -> bool) { + fn iter_indivisible_pieces_for_range(&self, range: &Range, f: &fn(&Range) -> bool) { let mut clump = Range::new(range.begin(), 0); loop { @@ -167,10 +161,11 @@ pub impl TextRun { } // now clump.end() is break-before or range.end() - if !f(&const clump) || clump.end() == range.end() { break; } + if !f(&clump) || clump.end() == range.end() { break; } // now clump includes one break-before character, or starts from range.end() - clump.reset(clump.end(), 1); + let end = clump.end(); // FIXME: borrow checker workaround + clump.reset(end, 1); } } } diff --git a/src/servo-gfx/text/util.rs b/src/servo-gfx/text/util.rs index b137ace8225..955163dbf9a 100644 --- a/src/servo-gfx/text/util.rs +++ b/src/servo-gfx/text/util.rs @@ -6,7 +6,7 @@ enum CompressionMode { } impl Eq for CompressionMode { - pure fn eq(&self, other: &CompressionMode) -> bool { + fn eq(&self, other: &CompressionMode) -> bool { match (*self, *other) { (CompressNone, CompressNone) => true, (CompressWhitespace, CompressWhitespace) => true, @@ -15,7 +15,7 @@ impl Eq for CompressionMode { _ => false } } - pure fn ne(&self, other: &CompressionMode) -> bool { + fn ne(&self, other: &CompressionMode) -> bool { !(*self).eq(other) } } diff --git a/src/servo-gfx/util/cache.rs b/src/servo-gfx/util/cache.rs index 6ae23b66426..5fa45aff605 100644 --- a/src/servo-gfx/util/cache.rs +++ b/src/servo-gfx/util/cache.rs @@ -1,10 +1,8 @@ -use core::cmp::*; - pub trait Cache { - static fn new(size: uint) -> Self; + fn new(size: uint) -> Self; fn insert(&mut self, key: &K, value: V); fn find(&self, key: &K) -> Option; - fn find_or_create(&mut self, key: &K, blk: &pure fn(&K) -> V) -> V; + fn find_or_create(&mut self, key: &K, blk: &fn(&K) -> V) -> V; fn evict_all(&mut self); } @@ -13,7 +11,7 @@ pub struct MonoCache { } impl Cache for MonoCache { - static fn new(_size: uint) -> MonoCache { + fn new(_size: uint) -> MonoCache { MonoCache { entry: None } } @@ -28,7 +26,7 @@ impl Cache for MonoCache { } } - fn find_or_create(&mut self, key: &K, blk: &pure fn(&K) -> V) -> V { + fn find_or_create(&mut self, key: &K, blk: &fn(&K) -> V) -> V { return match self.find(key) { None => { let value = blk(key); @@ -51,9 +49,9 @@ fn test_monocache() { let two = @"two"; cache.insert(&1, one); - fail_unless!(cache.find(&1).is_some()); - fail_unless!(cache.find(&2).is_none()); + assert!(cache.find(&1).is_some()); + assert!(cache.find(&2).is_none()); cache.find_or_create(&2, |_v| { two }); - fail_unless!(cache.find(&2).is_some()); - fail_unless!(cache.find(&1).is_none()); + assert!(cache.find(&2).is_some()); + assert!(cache.find(&1).is_none()); } diff --git a/src/servo-gfx/util/range.rs b/src/servo-gfx/util/range.rs index 86425500747..c359533fab6 100644 --- a/src/servo-gfx/util/range.rs +++ b/src/servo-gfx/util/range.rs @@ -14,28 +14,28 @@ pub struct Range { } pub impl Range { - static pub pure fn new(off: uint, len: uint) -> Range { + pub fn new(off: uint, len: uint) -> Range { Range { off: off, len: len } } - static pub pure fn empty() -> Range { + pub fn empty() -> Range { Range::new(0, 0) } } pub impl Range { - pure fn begin(&const self) -> uint { self.off } - pure fn length(&const self) -> uint { self.len } - pure fn end(&const self) -> uint { self.off + self.len } - pure fn eachi(&const self, cb: &fn(uint) -> bool) { + fn begin(&self) -> uint { self.off } + fn length(&self) -> uint { self.len } + fn end(&self) -> uint { self.off + self.len } + fn eachi(&self, cb: &fn(uint) -> bool) { do uint::range(self.off, self.off + self.len) |i| { cb(i) } } - pure fn contains(&const self, i: uint) -> bool { + fn contains(&self, i: uint) -> bool { i >= self.begin() && i < self.end() } - pure fn is_valid_for_string(&const self, s: &str) -> bool { + fn is_valid_for_string(&self, s: &str) -> bool { self.begin() < s.len() && self.end() <= s.len() && self.length() <= s.len() } @@ -64,7 +64,7 @@ pub impl Range { /// Computes the relationship between two ranges (`self` and `other`), /// from the point of view of `self`. So, 'EntirelyBefore' means /// that the `self` range is entirely before `other` range. - pure fn relation_to_range(&const self, other: &const Range) -> RangeRelation { + fn relation_to_range(&self, other: &Range) -> RangeRelation { if other.begin() > self.end() { return EntirelyBefore; } @@ -92,7 +92,7 @@ pub impl Range { self, other)); } - fn repair_after_coalesced_range(&mut self, other: &const Range) { + fn repair_after_coalesced_range(&mut self, other: &Range) { let relation = self.relation_to_range(other); debug!("repair_after_coalesced_range: possibly repairing range %?", self); debug!("repair_after_coalesced_range: relation of original range and coalesced range(%?): %?", diff --git a/src/servo-gfx/util/url.rs b/src/servo-gfx/util/url.rs index 803e4a26954..bcf880be480 100644 --- a/src/servo-gfx/util/url.rs +++ b/src/servo-gfx/util/url.rs @@ -1,7 +1,6 @@ -use core::path::Path; use std::net::url; use std::net::url::Url; -use std::oldmap::HashMap; +use core::hashmap::HashMap; /** Create a URL object from a string. Does various helpful browsery things like @@ -26,7 +25,11 @@ pub fn make_url(str_url: ~str, current_url: Option) -> Url { if current_url.path.is_empty() || current_url.path.ends_with("/") { current_url.scheme + "://" + current_url.host + "/" + str_url } else { - let path = str::split_char(current_url.path, '/'); + let mut path = ~[]; + for str::each_split_char(current_url.path, '/') |p| { + path.push(p.to_str()); + } + let path = path; // FIXME: borrow checker workaround let path = path.init(); let path = str::connect(path.map(|x| copy *x) + ~[str_url], "/"); @@ -98,10 +101,8 @@ mod make_url_tests { } -pub type UrlMap = HashMap; +pub type UrlMap = @mut HashMap; pub fn url_map() -> UrlMap { - use core::to_str::ToStr; - - HashMap::() + @mut HashMap::new() } diff --git a/src/servo-gfx/util/vec.rs b/src/servo-gfx/util/vec.rs index c12d0732b11..86d0251bfdc 100644 --- a/src/servo-gfx/util/vec.rs +++ b/src/servo-gfx/util/vec.rs @@ -1,19 +1,19 @@ use core::cmp::{Ord, Eq}; pub trait BinarySearchMethods { - pure fn binary_search(&self, key: &T) -> Option<&self/T>; - pure fn binary_search_index(&self, key: &T) -> Option; + fn binary_search(&self, key: &T) -> Option<&'self T>; + fn binary_search_index(&self, key: &T) -> Option; } impl<'self, T: Ord + Eq> BinarySearchMethods for &'self [T] { - pure fn binary_search(&self, key: &T) -> Option<&self/T> { + fn binary_search(&self, key: &T) -> Option<&'self T> { match self.binary_search_index(key) { None => None, Some(i) => Some(&self[i]) } } - pure fn binary_search_index(&self, key: &T) -> Option { + fn binary_search_index(&self, key: &T) -> Option { if self.len() == 0 { return None; } @@ -41,7 +41,7 @@ impl<'self, T: Ord + Eq> BinarySearchMethods for &'self [T] { fn test_find_all_elems(arr: &[T]) { let mut i = 0; while i < arr.len() { - fail_unless!(test_match(&arr[i], arr.binary_search(&arr[i]))); + assert!(test_match(&arr[i], arr.binary_search(&arr[i]))); i += 1; } } @@ -51,7 +51,7 @@ fn test_miss_all_elems(arr: &[T], misses: &[T]) { while i < misses.len() { let res = arr.binary_search(&misses[i]); debug!("%? == %? ?", misses[i], res); - fail_unless!(!test_match(&misses[i], arr.binary_search(&misses[i]))); + assert!(!test_match(&misses[i], arr.binary_search(&misses[i]))); i += 1; } } diff --git a/src/servo/content/content_task.rs b/src/servo/content/content_task.rs index 9582103c088..b0bd581520e 100644 --- a/src/servo/content/content_task.rs +++ b/src/servo/content/content_task.rs @@ -3,8 +3,6 @@ The content task is the main task that runs JavaScript and spawns layout tasks. */ -use dom::bindings::utils::rust_box; -use dom::bindings::utils::CacheableWrapper; use dom::bindings::utils::GlobalStaticData; use dom::document::Document; use dom::node::define_bindings; @@ -13,29 +11,25 @@ use dom::window::Window; use layout::layout_task; use layout::layout_task::{AddStylesheet, BuildData, BuildMsg, Damage, LayoutTask}; use layout::layout_task::{MatchSelectorsDamage, NoDamage, ReflowDamage}; -use util::task::spawn_listener; use core::cell::Cell; -use core::comm::{Port, Chan, SharedChan}; +use core::comm::{Port, SharedChan}; use core::pipes::select2i; use core::either; -use core::task::{SingleThreaded, spawn, task}; +use core::task::{SingleThreaded, task}; use core::io::{println, read_whole_file}; use core::ptr::null; use core::util::replace; use geom::size::Size2D; use gfx::resource::image_cache_task::ImageCacheTask; use gfx::resource::resource_task::ResourceTask; -use gfx::util::url::make_url; use js::JSVAL_NULL; use js::global::{global_class, debug_fns}; use js::glue::bindgen::RUST_JSVAL_TO_OBJECT; -use js::jsapi::{JSContext, JSVal}; +use js::jsapi::JSContext; use js::jsapi::bindgen::{JS_CallFunctionValue, JS_GetContextPrivate}; use js::rust::{Compartment, Cx}; use jsrt = js::rust::rt; -use newcss::stylesheet::Stylesheet; -use std::arc::{ARC, clone}; use std::net::url::Url; use url_to_str = std::net::url::to_str; use dom; @@ -223,7 +217,7 @@ pub impl Content { self.window = Some(window); self.doc_url = Some(url); - let compartment = option::expect(self.compartment, ~"TODO error checking"); + let compartment = self.compartment.expect(~"TODO error checking"); compartment.define_functions(debug_fns); define_bindings(compartment, document, window); @@ -235,7 +229,7 @@ pub impl Content { } Timer(timerData) => { - let compartment = option::expect(self.compartment, ~"TODO error checking"); + let compartment = self.compartment.expect(~"TODO error checking"); let thisValue = if timerData.args.len() > 0 { RUST_JSVAL_TO_OBJECT(timerData.args[0]) } else { @@ -258,7 +252,7 @@ pub impl Content { println(fmt!("Error opening %s: %s", url_to_str(&url), msg)); } Ok(bytes) => { - let compartment = option::expect(self.compartment, ~"TODO error checking"); + let compartment = self.compartment.expect(~"TODO error checking"); compartment.define_functions(debug_fns); self.cx.evaluate_script(compartment.global_obj, bytes, copy url.path, 1u); } @@ -349,7 +343,7 @@ pub impl Content { // Nothing to do. } Some(document) => { - fail_unless!(self.doc_url.is_some()); + assert!(self.doc_url.is_some()); self.relayout(document, &(copy self.doc_url).get()); } } @@ -364,7 +358,7 @@ pub impl Content { // Nothing to do. } Some(document) => { - fail_unless!(self.doc_url.is_some()); + assert!(self.doc_url.is_some()); self.relayout(document, &(copy self.doc_url).get()); } } diff --git a/src/servo/css/matching.rs b/src/servo/css/matching.rs index 2646aca4aad..a063020daba 100644 --- a/src/servo/css/matching.rs +++ b/src/servo/css/matching.rs @@ -3,12 +3,9 @@ use css::node_util::NodeUtil; use css::select_handler::NodeSelectHandler; use dom::node::AbstractNode; -use layout::context::LayoutContext; use newcss::complete::CompleteSelectResults; use newcss::select::{SelectCtx, SelectResults}; -use std::arc::{ARC, get, clone}; - pub trait MatchMethods { fn restyle_subtree(&self, select_ctx: &SelectCtx); } diff --git a/src/servo/css/node_style.rs b/src/servo/css/node_style.rs index 35a7a6fb8fb..ca3f984435a 100644 --- a/src/servo/css/node_style.rs +++ b/src/servo/css/node_style.rs @@ -6,12 +6,12 @@ use newcss::complete::CompleteStyle; /// Node mixin providing `style` method that returns a `NodeStyle` pub trait StyledNode { - fn style(&self) -> CompleteStyle/&self; + fn style(&self) -> CompleteStyle<'self>; } impl StyledNode for AbstractNode { - fn style(&self) -> CompleteStyle/&self { - fail_unless!(self.is_element()); // Only elements can have styles + fn style(&self) -> CompleteStyle<'self> { + assert!(self.is_element()); // Only elements can have styles let results = self.get_css_select_results(); results.computed_style() } diff --git a/src/servo/css/node_util.rs b/src/servo/css/node_util.rs index 153a51d5d30..ffca3310a3c 100644 --- a/src/servo/css/node_util.rs +++ b/src/servo/css/node_util.rs @@ -3,8 +3,8 @@ use newcss::complete::CompleteSelectResults; use core::cast::transmute; -pub trait NodeUtil { - fn get_css_select_results(self) -> &self/CompleteSelectResults; +pub trait NodeUtil<'self> { + fn get_css_select_results(self) -> &'self CompleteSelectResults; fn set_css_select_results(self, decl: CompleteSelectResults); } @@ -16,7 +16,7 @@ impl<'self> NodeUtil<'self> for AbstractNode { * FIXME: This isn't completely memory safe since the style is * stored in a box that can be overwritten */ - fn get_css_select_results(self) -> &self/CompleteSelectResults { + fn get_css_select_results(self) -> &'self CompleteSelectResults { if !self.has_layout_data() { fail!(~"style() called on a node without aux data!"); } diff --git a/src/servo/css/node_void_ptr.rs b/src/servo/css/node_void_ptr.rs index 60343b9c0d9..1eb4eb30722 100644 --- a/src/servo/css/node_void_ptr.rs +++ b/src/servo/css/node_void_ptr.rs @@ -1,16 +1,16 @@ //! CSS library requires that DOM nodes be convertable to *c_void through this trait +extern mod netsurfcss; use dom::node::AbstractNode; use core::cast; // FIXME: Rust #3908. rust-css can't reexport VoidPtrLike -extern mod netsurfcss; use css::node_void_ptr::netsurfcss::util::VoidPtrLike; impl VoidPtrLike for AbstractNode { - static fn from_void_ptr(node: *libc::c_void) -> AbstractNode { - fail_unless!(node.is_not_null()); + fn from_void_ptr(node: *libc::c_void) -> AbstractNode { + assert!(node.is_not_null()); unsafe { cast::transmute(node) } diff --git a/src/servo/dom/bindings/clientrect.rs b/src/servo/dom/bindings/clientrect.rs index 1c7c0726af3..a727102dce4 100644 --- a/src/servo/dom/bindings/clientrect.rs +++ b/src/servo/dom/bindings/clientrect.rs @@ -4,12 +4,12 @@ use dom::bindings::codegen::ClientRectBinding; use js::jsapi::{JSObject, JSContext}; pub trait ClientRect { - fn Top() -> f32; - fn Bottom() -> f32; - fn Left() -> f32; - fn Right() -> f32; - fn Width() -> f32; - fn Height() -> f32; + fn Top(&self) -> f32; + fn Bottom(&self) -> f32; + fn Left(&self) -> f32; + fn Right(&self) -> f32; + fn Width(&self) -> f32; + fn Height(&self) -> f32; } pub struct ClientRectImpl { @@ -21,27 +21,27 @@ pub struct ClientRectImpl { } impl ClientRect for ClientRectImpl { - fn Top() -> f32 { + fn Top(&self) -> f32 { self.top } - fn Bottom() -> f32 { + fn Bottom(&self) -> f32 { self.bottom } - fn Left() -> f32 { + fn Left(&self) -> f32 { self.left } - fn Right() -> f32 { + fn Right(&self) -> f32 { self.right } - fn Width() -> f32 { + fn Width(&self) -> f32 { f32::abs(self.right - self.left) } - fn Height() -> f32 { + fn Height(&self) -> f32 { f32::abs(self.bottom - self.top) } } @@ -63,7 +63,7 @@ impl CacheableWrapper for ClientRectImpl { ClientRectBinding::Wrap(cx, scope, self, &mut unused) } - fn wrap_object_shared(@self, cx: *JSContext, scope: *JSObject) -> *JSObject { + fn wrap_object_shared(@self, _cx: *JSContext, _scope: *JSObject) -> *JSObject { fail!(~"nyi") } } diff --git a/src/servo/dom/bindings/clientrectlist.rs b/src/servo/dom/bindings/clientrectlist.rs index 92ac7da6d78..c5218516ff8 100644 --- a/src/servo/dom/bindings/clientrectlist.rs +++ b/src/servo/dom/bindings/clientrectlist.rs @@ -2,8 +2,6 @@ use content::content_task::task_from_context; use dom::bindings::clientrect::{ClientRect, ClientRectImpl}; use dom::bindings::codegen::ClientRectListBinding; use dom::bindings::utils::{WrapperCache, CacheableWrapper, BindingObject, OpaqueBindingReference}; -use dom::window::Window; -use dom::bindings::window::Window; use js::jsapi::{JSObject, JSContext}; pub trait ClientRectList { @@ -37,8 +35,8 @@ impl ClientRectList for ClientRectListImpl { } } -impl ClientRectListImpl { - static fn new() -> ClientRectListImpl { +pub impl ClientRectListImpl { + fn new() -> ClientRectListImpl { ClientRectListImpl { wrapper: WrapperCache::new(), rects: ~[(5.6, 80.2, 3.7, 4.8), (800.1, 8001.1, -50.000001, -45.01)] @@ -56,7 +54,7 @@ impl CacheableWrapper for ClientRectListImpl { ClientRectListBinding::Wrap(cx, scope, self, &mut unused) } - fn wrap_object_shared(@self, cx: *JSContext, scope: *JSObject) -> *JSObject { + fn wrap_object_shared(@self, _cx: *JSContext, _scope: *JSObject) -> *JSObject { fail!(~"nyi") } } diff --git a/src/servo/dom/bindings/codegen/CodegenRust.py b/src/servo/dom/bindings/codegen/CodegenRust.py index 4421023bec8..7bd217569ea 100644 --- a/src/servo/dom/bindings/codegen/CodegenRust.py +++ b/src/servo/dom/bindings/codegen/CodegenRust.py @@ -1856,7 +1856,7 @@ class PropertyDefiner: specs.append(specTerminator) prefableSpecs.append(" { false, NULL }"); - arrays = (("const %s: [%s * %i] = [\n" + + arrays = (("static %s: [%s, ..%i] = [\n" + ',\n'.join(specs) + "\n" + "];\n\n") % (name, specType, len(specs))) #+ @@ -1864,7 +1864,7 @@ class PropertyDefiner: #',\n'.join(prefableSpecs) + "\n" + #"];\n\n") if doIdArrays: - arrays += ("const %s_ids: [jsid * %i] = [" % (name, len(specs))) + ", ".join(["JSID_VOID"] * len(specs)) + "];\n\n" + arrays += ("static %s_ids: [jsid, ..%i] = [" % (name, len(specs))) + ", ".join(["JSID_VOID"] * len(specs)) + "];\n\n" return arrays # The length of a method is the maximum of the lengths of the @@ -1945,7 +1945,7 @@ class MethodDefiner(PropertyDefiner): return (m["name"], accessor, jitinfo, m["length"], m["flags"]) def stringDecl(m): - return "const %s_name: [u8 * %i] = %s;\n" % (m["name"], len(m["name"]) + 1, + return "static %s_name: [u8, ..%i] = %s;\n" % (m["name"], len(m["name"]) + 1, str_to_const_array(m["name"])) decls = ''.join([stringDecl(m) for m in array]) @@ -1992,7 +1992,7 @@ class AttrDefiner(PropertyDefiner): def stringDecl(attr): name = attr.identifier.name - return "const %s_name: [u8 * %i] = %s;\n" % (name, len(name) + 1, + return "static %s_name: [u8, ..%i] = %s;\n" % (name, len(name) + 1, str_to_const_array(name)) decls = ''.join([stringDecl(m) for m in array]) @@ -2024,7 +2024,7 @@ class ConstDefiner(PropertyDefiner): def stringDecl(const): name = const.identifier.name - return "const %s_name: [u8 * %i] = %s;\n" % (name, len(name) + 1, + return "static %s_name: [u8, ..%i] = %s;\n" % (name, len(name) + 1, str_to_const_array(name)) decls = ''.join([stringDecl(m) for m in array]) @@ -2060,7 +2060,7 @@ class CGNativePropertyHooks(CGThing): parentHooks = ("&" + toBindingNamespace(parent.identifier.name) + "::NativeHooks" if parent else '0 as *NativePropertyHooks') return """ -const NativeHooks: NativePropertyHooks = NativePropertyHooks { resolve_own_property: /*%s*/ 0 as *u8, resolve_property: ResolveProperty, enumerate_own_properties: /*%s*/ 0 as *u8, enumerate_properties: /*EnumerateProperties*/ 0 as *u8, proto_hooks: %s }; +static NativeHooks: NativePropertyHooks = NativePropertyHooks { resolve_own_property: /*%s*/ 0 as *u8, resolve_property: ResolveProperty, enumerate_own_properties: /*%s*/ 0 as *u8, enumerate_properties: /*EnumerateProperties*/ 0 as *u8, proto_hooks: %s }; """ % (resolveOwnProperty, enumerateOwnProperties, parentHooks) # We'll want to insert the indent at the beginnings of lines, but we @@ -2142,9 +2142,9 @@ class CGImports(CGWrapper): # TODO imports to cover descriptors, etc. def _useString(imports): - return ''.join(['use %s;\n' % i for i in imports]) + '\n' + return '#[allow(unused_imports)];' + ''.join(['use %s;\n' % i for i in imports]) + '\n' CGWrapper.__init__(self, child, - definePre=_useString(sorted(defineImports))) + declarePre=_useString(sorted(declareImports))) class CGIfWrapper(CGWrapper): def __init__(self, child, condition): @@ -2197,8 +2197,8 @@ class CGDOMJSClass(CGThing): def define(self): traceHook = TRACE_HOOK_NAME if self.descriptor.customTrace else '0 as *u8' return """ -const Class_name: [u8 * %i] = %s; -const Class: DOMJSClass = DOMJSClass { +static Class_name: [u8, ..%i] = %s; +static Class: DOMJSClass = DOMJSClass { base: JSClass { name: &Class_name as *u8 as *libc::c_char, flags: JSCLASS_IS_DOMJSCLASS | ((1 & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT), //JSCLASS_HAS_RESERVED_SLOTS(1), addProperty: %s, /* addProperty */ @@ -2243,8 +2243,9 @@ class CGPrototypeJSClass(CGThing): # We're purely for internal consumption return "" def define(self): - return """const PrototypeClassName__: [u8 * %s] = %s; -const PrototypeClass: JSClass = JSClass { + return """ +static PrototypeClassName__: [u8, ..%s] = %s; +static PrototypeClass: JSClass = JSClass { name: &PrototypeClassName__ as *u8 as *libc::c_char, flags: (1 & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT, //JSCLASS_HAS_RESERVED_SLOTS(1) addProperty: crust::JS_PropertyStub, /* addProperty */ @@ -2285,7 +2286,7 @@ class CGInterfaceObjectJSClass(CGThing): ctorname = "0 as *u8" if not self.descriptor.interface.ctor() else CONSTRUCT_HOOK_NAME hasinstance = HASINSTANCE_HOOK_NAME return """ -const InterfaceObjectClass: JSClass = { +static InterfaceObjectClass: JSClass = { %s, 0, crust::JS_PropertyStub, /* addProperty */ crust::JS_PropertyStub, /* delProperty */ @@ -3149,7 +3150,7 @@ class CGSpecializedMethod(CGAbstractExternMethod): def __init__(self, descriptor, method): self.method = method name = method.identifier.name - args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', '++obj'), + args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', 'obj'), Argument('*%s' % descriptor.nativeType, 'self'), Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')] CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args) @@ -3194,7 +3195,7 @@ class CGSpecializedGetter(CGAbstractExternMethod): self.attr = attr name = 'get_' + attr.identifier.name args = [ Argument('*JSContext', 'cx'), - Argument('JSHandleObject', '++obj'), + Argument('JSHandleObject', 'obj'), Argument('*%s' % descriptor.nativeType, 'self'), Argument('*mut JSVal', 'vp') ] CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args) @@ -3245,7 +3246,7 @@ class CGMemberJITInfo(CGThing): depth = self.descriptor.interface.inheritanceDepth() failstr = "true" if infallible else "false" return ("\n" - "const %s: JSJitInfo = JSJitInfo {\n" + "static %s: JSJitInfo = JSJitInfo {\n" " op: %s,\n" " protoID: %s,\n" " depth: %s,\n" @@ -3690,7 +3691,7 @@ class CGDOMJSProxyHandlerDOMClass(CGThing): return "" def define(self): return """ -const Class: DOMClass = """ + DOMClass(self.descriptor) + """; +static Class: DOMClass = """ + DOMClass(self.descriptor) + """; """ @@ -3847,7 +3848,6 @@ class CGBindingRoot(CGThing): # Add imports curr = CGImports(descriptors, dictionaries, - [], ['js::*', 'js::jsapi::*', 'js::jsapi::bindgen::*', @@ -3863,6 +3863,7 @@ class CGBindingRoot(CGThing): 'dom::bindings::proxyhandler::*', 'content::content_task::task_from_context' ], + [], curr) # Add the auto-generated comment. diff --git a/src/servo/dom/bindings/conversions.rs b/src/servo/dom/bindings/conversions.rs index a53951379c5..d4c695da4b9 100644 --- a/src/servo/dom/bindings/conversions.rs +++ b/src/servo/dom/bindings/conversions.rs @@ -3,7 +3,7 @@ use js::glue::bindgen::{RUST_INT_TO_JSVAL, RUST_JSVAL_TO_INT}; pub trait JSValConvertible { fn to_jsval(&self) -> JSVal; - static fn from_jsval(val: JSVal) -> Option; + fn from_jsval(val: JSVal) -> Option; } impl JSValConvertible for u32 { @@ -11,7 +11,7 @@ impl JSValConvertible for u32 { RUST_INT_TO_JSVAL(*self as i32) } - static fn from_jsval(val: JSVal) -> Option { + fn from_jsval(val: JSVal) -> Option { Some(RUST_JSVAL_TO_INT(val) as u32) } } diff --git a/src/servo/dom/bindings/document.rs b/src/servo/dom/bindings/document.rs index 6879db9c837..911802d2c10 100644 --- a/src/servo/dom/bindings/document.rs +++ b/src/servo/dom/bindings/document.rs @@ -1,27 +1,23 @@ use js::rust::{Compartment, jsobj}; -use js::{JS_ARGV, JSCLASS_HAS_RESERVED_SLOTS, JSPROP_ENUMERATE, JSPROP_SHARED, +use js::{JS_ARGV, JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL, JS_THIS_OBJECT, JS_SET_RVAL, JSPROP_NATIVE_ACCESSORS}; -use js::jsapi::{JSContext, JSVal, JSObject, JSBool, jsid, JSClass, JSFreeOp, +use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSFreeOp, JSPropertySpec, JSPropertyOpWrapper, JSStrictPropertyOpWrapper, JSNativeWrapper, JSFunctionSpec}; -use js::jsapi::bindgen::{JS_ValueToString, JS_GetStringCharsZAndLength, JS_ReportError, - JS_GetReservedSlot, JS_SetReservedSlot, JS_NewStringCopyN, - JS_DefineFunctions, JS_DefineProperty, JS_DefineProperties}; +use js::jsapi::bindgen::{JS_GetReservedSlot, JS_SetReservedSlot, + JS_DefineFunctions, JS_DefineProperties}; use js::glue::bindgen::*; use js::glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB}; -use js::crust::{JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ConvertStub, JS_ResolveStub}; use core::ptr::null; use core::libc::c_uint; -use dom::bindings::utils::{DOMString, domstring_to_jsval, rust_box, squirrel_away, str}; +use dom::bindings::utils::{DOMString, rust_box, squirrel_away, str}; use dom::bindings::utils::{jsval_to_str, WrapNewBindingObject, CacheableWrapper}; use dom::bindings::utils::WrapperCache; -use dom::bindings::node::create; use dom::document::Document; use dom::bindings::htmlcollection::HTMLCollection; use dom::bindings::node; use dom::bindings::utils; -use dom::node::Node; extern fn getDocumentElement(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool { unsafe { @@ -36,7 +32,7 @@ extern fn getDocumentElement(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> J } } -extern fn getElementsByTagName(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool { +extern fn getElementsByTagName(cx: *JSContext, _argc: c_uint, vp: *JSVal) -> JSBool { unsafe { let obj = JS_THIS_OBJECT(cx, vp); @@ -56,7 +52,7 @@ extern fn getElementsByTagName(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBo JS_SET_RVAL(cx, vp, JSVAL_NULL); } else { let cache = doc.get_wrappercache(); - fail_unless!(WrapNewBindingObject(cx, cache.get_wrapper(), + assert!(WrapNewBindingObject(cx, cache.get_wrapper(), rval.get(), cast::transmute(vp))); } @@ -96,7 +92,7 @@ pub fn init(compartment: @mut Compartment, doc: @mut Document) { setter: JSStrictPropertyOpWrapper {op: null(), info: null()}}]; vec::push(&mut compartment.global_props, attrs); vec::as_imm_buf(*attrs, |specs, _len| { - fail_unless!(JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs) == 1); + assert!(JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs) == 1); }); let methods = @~[JSFunctionSpec {name: compartment.add_name(~"getElementsByTagName"), @@ -136,11 +132,11 @@ impl CacheableWrapper for Document { unsafe { cast::transmute(&self.wrapper) } } - fn wrap_object_unique(~self, cx: *JSContext, scope: *JSObject) -> *JSObject { + fn wrap_object_unique(~self, _cx: *JSContext, _scope: *JSObject) -> *JSObject { fail!(~"need to implement wrapping"); } - fn wrap_object_shared(@self, cx: *JSContext, scope: *JSObject) -> *JSObject { + fn wrap_object_shared(@self, _cx: *JSContext, _scope: *JSObject) -> *JSObject { fail!(~"need to implement wrapping"); } } diff --git a/src/servo/dom/bindings/element.rs b/src/servo/dom/bindings/element.rs index da3b2e4d440..a735e9ae1bb 100644 --- a/src/servo/dom/bindings/element.rs +++ b/src/servo/dom/bindings/element.rs @@ -1,23 +1,20 @@ -use content::content_task::{Content, task_from_context}; -use dom::bindings::utils::{rust_box, squirrel_away_unique, get_compartment}; +use content::content_task::task_from_context; use dom::bindings::utils::{domstring_to_jsval, WrapNewBindingObject}; use dom::bindings::utils::{str, CacheableWrapper, DOM_OBJECT_SLOT}; -use dom::bindings::clientrectlist::ClientRectListImpl; use dom::element::*; -use dom::node::{AbstractNode, Node, Element, ElementNodeTypeId}; +use dom::node::{AbstractNode, Element, ElementNodeTypeId}; use layout::layout_task; use super::utils; use core::libc::c_uint; use core::ptr::null; -use js::crust::{JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ConvertStub}; use js::glue::bindgen::*; use js::jsapi::bindgen::*; -use js::jsapi::{JSContext, JSVal, JSObject, JSBool, jsid, JSClass, JSFreeOp, JSPropertySpec}; +use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSFreeOp, JSPropertySpec}; use js::jsapi::{JSPropertyOpWrapper, JSStrictPropertyOpWrapper, JSFunctionSpec}; use js::jsapi::JSNativeWrapper; use js::rust::{Compartment, jsobj}; -use js::{JS_ARGV, JSCLASS_HAS_RESERVED_SLOTS, JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL}; +use js::{JS_ARGV, JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL}; use js::{JS_THIS_OBJECT, JS_SET_RVAL, JSPROP_NATIVE_ACCESSORS}; extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) { @@ -25,7 +22,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) { unsafe { let val = JS_GetReservedSlot(obj, DOM_OBJECT_SLOT as u32); let node: AbstractNode = cast::reinterpret_cast(&RUST_JSVAL_TO_PRIVATE(val)); - let elem: ~Element = cast::transmute(node.raw_object()); + let _elem: ~Element = cast::transmute(node.raw_object()); } } @@ -89,7 +86,7 @@ pub fn init(compartment: @mut Compartment) { }); } -extern fn getClientRects(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool { +extern fn getClientRects(cx: *JSContext, _argc: c_uint, vp: *JSVal) -> JSBool { unsafe { let obj = JS_THIS_OBJECT(cx, vp); let mut box = utils::unwrap::<*mut AbstractNode>(obj); @@ -101,7 +98,7 @@ extern fn getClientRects(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool { JS_SET_RVAL(cx, vp, JSVAL_NULL); } else { let cache = node.get_wrappercache(); - fail_unless!(WrapNewBindingObject(cx, cache.get_wrapper(), + assert!(WrapNewBindingObject(cx, cache.get_wrapper(), rval.get(), cast::transmute(vp))); } diff --git a/src/servo/dom/bindings/htmlcollection.rs b/src/servo/dom/bindings/htmlcollection.rs index 319f9095532..cd39e4c4c27 100644 --- a/src/servo/dom/bindings/htmlcollection.rs +++ b/src/servo/dom/bindings/htmlcollection.rs @@ -1,5 +1,4 @@ use content::content_task::task_from_context; -use dom::element::Element; use dom::node::AbstractNode; use dom::bindings::codegen::HTMLCollectionBinding; use dom::bindings::utils::{DOMString, ErrorResult, OpaqueBindingReference}; @@ -12,7 +11,7 @@ pub struct HTMLCollection { } pub impl HTMLCollection { - static fn new(elements: ~[AbstractNode]) -> HTMLCollection { + fn new(elements: ~[AbstractNode]) -> HTMLCollection { HTMLCollection { elements: elements, wrapper: WrapperCache::new() @@ -31,7 +30,7 @@ pub impl HTMLCollection { } } - fn NamedItem(&self, cx: *JSContext, name: DOMString, rv: &mut ErrorResult) -> *JSObject { + fn NamedItem(&self, _cx: *JSContext, _name: DOMString, rv: &mut ErrorResult) -> *JSObject { *rv = Ok(()); ptr::null() } @@ -59,7 +58,7 @@ impl CacheableWrapper for HTMLCollection { HTMLCollectionBinding::Wrap(cx, scope, self, &mut unused) } - fn wrap_object_shared(@self, cx: *JSContext, scope: *JSObject) -> *JSObject { + fn wrap_object_shared(@self, _cx: *JSContext, _scope: *JSObject) -> *JSObject { fail!(~"nyi") } } diff --git a/src/servo/dom/bindings/node.rs b/src/servo/dom/bindings/node.rs index f32128fd69d..27b3d8ea828 100644 --- a/src/servo/dom/bindings/node.rs +++ b/src/servo/dom/bindings/node.rs @@ -1,25 +1,20 @@ -use dom::bindings::utils::{rust_box, squirrel_away_unique, get_compartment}; -use dom::bindings::utils::{str, domstring_to_jsval, CacheableWrapper, WrapperCache}; +use dom::bindings::utils::{CacheableWrapper, WrapperCache}; use dom::bindings::utils::{DOM_OBJECT_SLOT}; use dom::node::{AbstractNode, Node, ElementNodeTypeId, TextNodeTypeId, CommentNodeTypeId}; use dom::node::{DoctypeNodeTypeId}; use super::element; use super::utils; -use core::cast::transmute; use core::libc::c_uint; use core::ptr::null; use js::glue::bindgen::*; use js::jsapi::bindgen::*; -use js::jsapi::bindgen::{JS_DefineFunctions, JS_DefineProperty, JS_GetContextPrivate}; -use js::jsapi::bindgen::{JS_GetReservedSlot, JS_SetReservedSlot, JS_NewStringCopyN}; -use js::jsapi::bindgen::{JS_ValueToString, JS_GetStringCharsZAndLength, JS_ReportError}; -use js::jsapi::{JSContext, JSVal, JSObject, JSBool, jsid, JSClass, JSFreeOp, JSPropertySpec}; +use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSPropertySpec}; use js::jsapi::{JSPropertyOpWrapper, JSStrictPropertyOpWrapper}; use js::jsval::{INT_TO_JSVAL, JSVAL_TO_PRIVATE}; use js::rust::{Compartment, jsobj}; -use js::{JS_ARGV, JSCLASS_HAS_RESERVED_SLOTS, JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL}; -use js::{JS_THIS_OBJECT, JS_SET_RVAL, JSPROP_NATIVE_ACCESSORS}; +use js::{JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL}; +use js::{JS_THIS_OBJECT, JSPROP_NATIVE_ACCESSORS}; use js; pub fn init(compartment: @mut Compartment) { @@ -172,11 +167,11 @@ impl CacheableWrapper for AbstractNode { } } - fn wrap_object_unique(~self, cx: *JSContext, scope: *JSObject) -> *JSObject { + fn wrap_object_unique(~self, _cx: *JSContext, _scope: *JSObject) -> *JSObject { fail!(~"need to implement wrapping"); } - fn wrap_object_shared(@self, cx: *JSContext, scope: *JSObject) -> *JSObject { + fn wrap_object_shared(@self, _cx: *JSContext, _scope: *JSObject) -> *JSObject { fail!(~"need to implement wrapping"); } } diff --git a/src/servo/dom/bindings/proxyhandler.rs b/src/servo/dom/bindings/proxyhandler.rs index 4d984271414..b5684baca81 100644 --- a/src/servo/dom/bindings/proxyhandler.rs +++ b/src/servo/dom/bindings/proxyhandler.rs @@ -1,6 +1,5 @@ use js::jsapi::{JSContext, jsid, JSPropertyDescriptor, JSObject, JSString, jschar}; -use js::jsapi::bindgen::{JS_GetPropertyDescriptorById, JS_GetPrototype}; -use js::jsapi::bindgen::{JS_NewUCString, JS_malloc, JS_free}; +use js::jsapi::bindgen::{JS_GetPropertyDescriptorById, JS_NewUCString, JS_malloc, JS_free}; use js::glue::bindgen::{RUST_JSVAL_IS_VOID, RUST_JSVAL_TO_OBJECT, GetProxyExtra}; use js::glue::bindgen::{GetObjectProto}; @@ -31,7 +30,7 @@ pub extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid, } fn _getOwnPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid, - set: c_bool, desc: *mut JSPropertyDescriptor) -> c_bool { + _set: c_bool, desc: *mut JSPropertyDescriptor) -> c_bool { unsafe { let v = GetProxyExtra(proxy, 0 /*JSPROXYSLOT_EXPANDO*/); if RUST_JSVAL_IS_VOID(v) == 0 { @@ -77,6 +76,6 @@ pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString { } } -pub fn GetExpandoObject(proxy: *JSObject) -> *JSObject { +pub fn GetExpandoObject(_proxy: *JSObject) -> *JSObject { ptr::null() } \ No newline at end of file diff --git a/src/servo/dom/bindings/utils.rs b/src/servo/dom/bindings/utils.rs index 35c74548bf8..70105cf77db 100644 --- a/src/servo/dom/bindings/utils.rs +++ b/src/servo/dom/bindings/utils.rs @@ -1,18 +1,18 @@ use js; use js::rust::Compartment; -use js::{JS_ARGV, JSCLASS_HAS_RESERVED_SLOTS, JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL, - JS_THIS_OBJECT, JS_SET_RVAL, JSFUN_CONSTRUCTOR, JS_CALLEE, JSPROP_READONLY, +use js::{JSCLASS_HAS_RESERVED_SLOTS, JSPROP_ENUMERATE, JSVAL_NULL, + JS_THIS_OBJECT, JSFUN_CONSTRUCTOR, JS_CALLEE, JSPROP_READONLY, JSPROP_PERMANENT, JSID_VOID, JSPROP_NATIVE_ACCESSORS, JSPROP_GETTER, JSPROP_SETTER}; -use js::jsapi::{JSContext, JSVal, JSObject, JSBool, jsid, JSClass, JSFreeOp, JSNative, - JSFunctionSpec, JSPropertySpec, JSVal, JSString, JSPropertyDescriptor}; -use js::jsapi::bindgen::{JS_ValueToString, JS_GetStringCharsZAndLength, JS_ReportError, +use js::jsapi::{JSContext, JSVal, JSObject, JSBool, jsid, JSClass, JSNative, + JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor}; +use js::jsapi::bindgen::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot, JS_NewStringCopyN, - JS_DefineFunctions, JS_DefineProperty, JS_GetContextPrivate, + JS_DefineFunctions, JS_DefineProperty, JS_GetClass, JS_GetPrototype, JS_LinkConstructorAndPrototype, JS_AlreadyHasOwnProperty, JS_NewObject, JS_NewFunction, JS_GetFunctionPrototype, JS_InternString, JS_GetFunctionObject, - JS_GetInternedStringCharsAndLength, JS_DefineProperties, - JS_WrapValue, JS_GetObjectPrototype, JS_ForwardGetPropertyTo, + JS_DefineProperties, + JS_WrapValue, JS_ForwardGetPropertyTo, JS_HasPropertyById, JS_GetPrototype, JS_GetGlobalForObject, JS_EncodeString, JS_free}; use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType; @@ -22,33 +22,33 @@ use js::glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB, ENUMERATE_STUB, CONVERT_STUB use js::glue::bindgen::*; use core::ptr::null; use core::cast; -use content::content_task::{Content, task_from_context}; +use content::content_task::task_from_context; -use core::hashmap::linear; +use core::hashmap::HashMap; use dom::bindings::node; use dom::node::AbstractNode; -const TOSTRING_CLASS_RESERVED_SLOT: u64 = 0; -const TOSTRING_NAME_RESERVED_SLOT: u64 = 1; +static TOSTRING_CLASS_RESERVED_SLOT: u64 = 0; +static TOSTRING_NAME_RESERVED_SLOT: u64 = 1; struct GlobalStaticData { - proxy_handlers: linear::LinearMap, - attribute_ids: linear::LinearMap, - method_ids: linear::LinearMap, - constant_ids: linear::LinearMap + proxy_handlers: HashMap, + attribute_ids: HashMap, + method_ids: HashMap, + constant_ids: HashMap } pub fn GlobalStaticData() -> GlobalStaticData { GlobalStaticData { - proxy_handlers: linear::LinearMap::new(), - attribute_ids: linear::LinearMap::new(), - method_ids: linear::LinearMap::new(), - constant_ids: linear::LinearMap::new() + proxy_handlers: HashMap::new(), + attribute_ids: HashMap::new(), + method_ids: HashMap::new(), + constant_ids: HashMap::new() } } -extern fn InterfaceObjectToString(cx: *JSContext, argc: uint, vp: *mut JSVal) -> JSBool { +extern fn InterfaceObjectToString(cx: *JSContext, _argc: uint, vp: *mut JSVal) -> JSBool { unsafe { let callee = RUST_JSVAL_TO_OBJECT(*JS_CALLEE(cx, cast::transmute(&vp))); let obj = JS_THIS_OBJECT(cx, cast::transmute(&vp)); @@ -160,10 +160,9 @@ pub unsafe fn domstring_to_jsval(cx: *JSContext, string: &DOMString) -> JSVal { pub fn get_compartment(cx: *JSContext) -> @mut Compartment { unsafe { let content = task_from_context(cx); - let compartment = option::expect((*content).compartment, - ~"Should always have compartment when \ - executing JS code"); - fail_unless!(cx == compartment.cx.ptr); + let compartment = (*content).compartment.expect(~"Should always have compartment when \ + executing JS code"); + assert!(cx == compartment.cx.ptr); compartment } } @@ -270,23 +269,23 @@ pub fn define_empty_prototype(name: ~str, proto: Option<~str>, compartment: @mut // We use slot 0 for holding the raw object. This is safe for both // globals and non-globals. -pub const DOM_OBJECT_SLOT: uint = 0; -const DOM_PROXY_OBJECT_SLOT: uint = js::JSSLOT_PROXY_PRIVATE as uint; +pub static DOM_OBJECT_SLOT: uint = 0; +static DOM_PROXY_OBJECT_SLOT: uint = js::JSSLOT_PROXY_PRIVATE as uint; // NOTE: This is baked into the Ion JIT as 0 in codegen for LGetDOMProperty and // LSetDOMProperty. Those constants need to be changed accordingly if this value // changes. -const DOM_PROTO_INSTANCE_CLASS_SLOT: u32 = 0; +static DOM_PROTO_INSTANCE_CLASS_SLOT: u32 = 0; // All DOM globals must have a slot at DOM_PROTOTYPE_SLOT. We have to // start at 1 past JSCLASS_GLOBAL_SLOT_COUNT because XPConnect uses // that one. -pub const DOM_PROTOTYPE_SLOT: u32 = js::JSCLASS_GLOBAL_SLOT_COUNT + 1; +pub static DOM_PROTOTYPE_SLOT: u32 = js::JSCLASS_GLOBAL_SLOT_COUNT + 1; // NOTE: This is baked into the Ion JIT as 0 in codegen for LGetDOMProperty and // LSetDOMProperty. Those constants need to be changed accordingly if this value // changes. -const JSCLASS_DOM_GLOBAL: u32 = js::JSCLASS_USERBIT1; +static JSCLASS_DOM_GLOBAL: u32 = js::JSCLASS_USERBIT1; pub struct NativeProperties { staticMethods: *JSFunctionSpec, @@ -330,7 +329,7 @@ pub struct ConstantSpec { pub struct DOMClass { // A list of interfaces that this object implements, in order of decreasing // derivedness. - interface_chain: [prototypes::id::Prototype * 2 /*max prototype chain length*/], + interface_chain: [prototypes::id::Prototype, ..2 /*max prototype chain length*/], unused: bool, // DOMObjectIsISupports (always false) native_hooks: *NativePropertyHooks @@ -418,7 +417,7 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject, JS_NewObject(cx, constructorClass, functionProto, global) } } else { - fail_unless!(constructorNative.is_not_null()); + assert!(constructorNative.is_not_null()); let fun = JS_NewFunction(cx, constructorNative, ctorNargs, JSFUN_CONSTRUCTOR, global, name); if fun.is_null() { @@ -535,13 +534,13 @@ fn CreateInterfacePrototypeObject(cx: *JSContext, global: *JSObject, return ourProto; } -pub extern fn ThrowingConstructor(cx: *JSContext, argc: uint, vp: *JSVal) -> JSBool { +pub extern fn ThrowingConstructor(_cx: *JSContext, _argc: uint, _vp: *JSVal) -> JSBool { //XXX should trigger exception here return 0; } pub fn initialize_global(global: *JSObject) { - let protoArray = @mut [0 as *JSObject, ..3]; //XXXjdm prototypes::_ID_COUNT + let protoArray = @mut ~[0 as *JSObject, ..3]; //XXXjdm prototypes::_ID_COUNT unsafe { //XXXjdm we should be storing the box pointer instead of the inner let box = squirrel_away(protoArray); @@ -571,7 +570,7 @@ pub impl WrapperCache { unsafe { self.wrapper = wrapper; } } - static fn new() -> WrapperCache { + fn new() -> WrapperCache { WrapperCache { wrapper: ptr::null() } @@ -642,7 +641,7 @@ pub impl BindingReference { } } - fn get_wrappercache(&mut self) -> &self/mut WrapperCache { + fn get_wrappercache(&mut self) -> &mut WrapperCache { match **self { Left(ref mut obj) => obj.get_wrappercache(), Right(ref mut obj) => obj.get_wrappercache() @@ -684,7 +683,7 @@ pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found: } } -pub fn GetArrayIndexFromId(cx: *JSContext, id: jsid) -> Option { +pub fn GetArrayIndexFromId(_cx: *JSContext, id: jsid) -> Option { if RUST_JSID_IS_INT(id) != 0 { return Some(RUST_JSID_TO_INT(id) as u32); } @@ -709,9 +708,9 @@ pub fn XrayResolveProperty(cx: *JSContext, wrapper: *JSObject, id: jsid, desc: *mut JSPropertyDescriptor, - methods: Option<~[(JSFunctionSpec, jsid)]>, + _methods: Option<~[(JSFunctionSpec, jsid)]>, attributes: Option<~[(JSPropertySpec, jsid)]>, - constants: Option<~[(ConstantSpec, jsid)]>) -> bool + _constants: Option<~[(ConstantSpec, jsid)]>) -> bool { unsafe { match attributes { @@ -785,7 +784,7 @@ pub trait DerivedWrapper { } impl DerivedWrapper for AbstractNode { - fn wrap(&mut self, cx: *JSContext, scope: *JSObject, vp: *mut JSVal) -> i32 { + fn wrap(&mut self, cx: *JSContext, _scope: *JSObject, vp: *mut JSVal) -> i32 { let cache = self.get_wrappercache(); let wrapper = cache.get_wrapper(); if wrapper.is_not_null() { diff --git a/src/servo/dom/bindings/window.rs b/src/servo/dom/bindings/window.rs index 475fe4a2b7a..4bcd9f490f2 100644 --- a/src/servo/dom/bindings/window.rs +++ b/src/servo/dom/bindings/window.rs @@ -1,34 +1,30 @@ // DOM bindings for the Window object. -use dom::bindings::node::create; -use dom::bindings::utils::{rust_box, squirrel_away, jsval_to_str, CacheableWrapper}; +use dom::bindings::utils::{rust_box, squirrel_away, CacheableWrapper}; use dom::bindings::utils::{WrapperCache}; -use dom::node::Node; -use dom::window::{Window, TimerMessage_Fire}; +use dom::window::Window; use super::utils; use core::libc::c_uint; use core::ptr::null; use core::ptr; -use js::crust::{JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ConvertStub}; -use js::crust::{JS_ResolveStub}; +use js::crust::{JS_PropertyStub, JS_StrictPropertyStub}; use js::global::jsval_to_rust_str; use js::glue::bindgen::*; use js::glue::bindgen::RUST_JSVAL_TO_INT; -use js::jsapi::bindgen::{JS_DefineFunctions, JS_DefineProperty, JS_DefineProperties}; -use js::jsapi::bindgen::{JS_EncodeString, JS_free}; -use js::jsapi::bindgen::{JS_GetReservedSlot, JS_SetReservedSlot, JS_NewStringCopyN}; -use js::jsapi::bindgen::{JS_ValueToString, JS_GetStringCharsZAndLength, JS_ReportError}; -use js::jsapi::{JSContext, JSVal, JSObject, JSBool, jsid, JSClass, JSFreeOp, JSFunctionSpec}; +use js::jsapi::bindgen::{JS_DefineFunctions}; +use js::jsapi::bindgen::{JS_GetReservedSlot, JS_SetReservedSlot}; +use js::jsapi::bindgen::{JS_ValueToString}; +use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSFreeOp, JSFunctionSpec}; use js::jsapi::{JSNativeWrapper}; use js::rust::Compartment; -use js::{JS_ARGV, JSCLASS_HAS_RESERVED_SLOTS, JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL}; +use js::{JS_ARGV, JSPROP_ENUMERATE, JSVAL_NULL}; use js::{JS_THIS_OBJECT, JS_SET_RVAL}; extern fn alert(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool { unsafe { let argv = JS_ARGV(cx, vp); - fail_unless!(argc == 1); + assert!(argc == 1); // Abstract this pattern and use it in debug, too? let jsstr = JS_ValueToString(cx, *ptr::offset(argv, 0)); @@ -42,7 +38,7 @@ extern fn alert(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool { extern fn setTimeout(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool { unsafe { let argv = JS_ARGV(cx, vp); - fail_unless!(argc >= 2); + assert!(argc >= 2); //TODO: don't crash when passed a non-integer value for the timeout @@ -137,11 +133,11 @@ impl CacheableWrapper for Window { unsafe { cast::transmute(&self.wrapper) } } - fn wrap_object_unique(~self, cx: *JSContext, scope: *JSObject) -> *JSObject { + fn wrap_object_unique(~self, _cx: *JSContext, _scope: *JSObject) -> *JSObject { fail!(~"should this be called?"); } - fn wrap_object_shared(@self, cx: *JSContext, scope: *JSObject) -> *JSObject { + fn wrap_object_shared(@self, _cx: *JSContext, _scope: *JSObject) -> *JSObject { fail!(~"should this be called?"); } } diff --git a/src/servo/dom/document.rs b/src/servo/dom/document.rs index d47b473663c..d44d596ab9d 100644 --- a/src/servo/dom/document.rs +++ b/src/servo/dom/document.rs @@ -1,9 +1,7 @@ use dom::bindings::htmlcollection::HTMLCollection; use dom::bindings::utils::{DOMString, WrapperCache, str}; use dom::node::AbstractNode; -use newcss::stylesheet::Stylesheet; -use std::arc::ARC; pub struct Document { root: AbstractNode, diff --git a/src/servo/dom/element.rs b/src/servo/dom/element.rs index 39fad8ea99d..3884f200e1a 100644 --- a/src/servo/dom/element.rs +++ b/src/servo/dom/element.rs @@ -15,7 +15,7 @@ pub struct Element { attrs: ~[Attr], } -#[deriving_eq] +#[deriving(Eq)] pub enum ElementTypeId { HTMLAnchorElementTypeId, HTMLAsideElementTypeId, @@ -109,7 +109,7 @@ pub struct HTMLImageElement { // pub impl Element { - static pub fn new(type_id: ElementTypeId, tag_name: ~str) -> Element { + pub fn new(type_id: ElementTypeId, tag_name: ~str) -> Element { Element { parent: Node::new(ElementNodeTypeId(type_id)), tag_name: tag_name, @@ -117,7 +117,7 @@ pub impl Element { } } - fn get_attr(&self, name: &str) -> Option<&self/str> { + fn get_attr(&self, name: &str) -> Option<&'self str> { // FIXME: Need an each() that links lifetimes in Rust. for uint::range(0, self.attrs.len()) |i| { if eq_slice(self.attrs[i].name, name) { @@ -151,7 +151,7 @@ pub struct Attr { } impl Attr { - static pub fn new(name: ~str, value: ~str) -> Attr { + pub fn new(name: ~str, value: ~str) -> Attr { Attr { name: name, value: value diff --git a/src/servo/dom/node.rs b/src/servo/dom/node.rs index 2f6bd608449..8894551708e 100644 --- a/src/servo/dom/node.rs +++ b/src/servo/dom/node.rs @@ -12,16 +12,9 @@ use dom::window::Window; use layout::debug::DebugMethods; use layout::flow::FlowContext; use newcss::complete::CompleteSelectResults; +use js::rust::Compartment; use core::cast::transmute; -use core::ptr::null; -use geom::size::Size2D; -use js::crust::*; -use js::glue::bindgen::RUST_OBJECT_TO_JSVAL; -use js::jsapi::{JSClass, JSObject, JSPropertySpec, JSContext, jsid, JSVal, JSBool}; -use js::jsapi::bindgen::JS_SetReservedSlot; -use js::rust::Compartment; -use std::arc::ARC; // // The basic Node structure @@ -36,8 +29,8 @@ pub struct AbstractNode { } impl Eq for AbstractNode { - pure fn eq(&self, other: &AbstractNode) -> bool { self.obj == other.obj } - pure fn ne(&self, other: &AbstractNode) -> bool { self.obj != other.obj } + fn eq(&self, other: &AbstractNode) -> bool { self.obj == other.obj } + fn ne(&self, other: &AbstractNode) -> bool { self.obj != other.obj } } pub struct Node { @@ -54,7 +47,7 @@ pub struct Node { priv layout_data: Option<@mut LayoutData> } -#[deriving_eq] +#[deriving(Eq)] pub enum NodeTypeId { DoctypeNodeTypeId, CommentNodeTypeId, @@ -72,7 +65,7 @@ pub struct LayoutData { } impl LayoutData { - static pub fn new() -> LayoutData { + pub fn new() -> LayoutData { LayoutData { style: None, flow: None, @@ -93,11 +86,11 @@ pub struct Doctype { } impl Doctype { - static pub fn new(name: ~str, - public_id: Option<~str>, - system_id: Option<~str>, - force_quirks: bool) - -> Doctype { + pub fn new(name: ~str, + public_id: Option<~str>, + system_id: Option<~str>, + force_quirks: bool) + -> Doctype { Doctype { parent: Node::new(DoctypeNodeTypeId), name: name, @@ -114,7 +107,7 @@ pub struct Comment { } impl Comment { - static pub fn new(text: ~str) -> Comment { + pub fn new(text: ~str) -> Comment { Comment { parent: Node::new(CommentNodeTypeId), text: text @@ -128,7 +121,7 @@ pub struct Text { } impl Text { - static pub fn new(text: ~str) -> Text { + pub fn new(text: ~str) -> Text { Text { parent: Node::new(TextNodeTypeId), text: text @@ -171,13 +164,13 @@ pub impl AbstractNode { // Invariant: `child` is disconnected from the document. fn append_child(self, child: AbstractNode) { - fail_unless!(self != child); + assert!(self != child); do self.with_mut_node |parent_n| { do child.with_mut_node |child_n| { - fail_unless!(child_n.parent_node.is_none()); - fail_unless!(child_n.prev_sibling.is_none()); - fail_unless!(child_n.next_sibling.is_none()); + assert!(child_n.parent_node.is_none()); + assert!(child_n.prev_sibling.is_none()); + assert!(child_n.next_sibling.is_none()); child_n.parent_node = Some(self); @@ -185,7 +178,7 @@ pub impl AbstractNode { None => parent_n.first_child = Some(child), Some(last_child) => { do last_child.with_mut_node |last_child_n| { - fail_unless!(last_child_n.next_sibling.is_none()); + assert!(last_child_n.next_sibling.is_none()); last_child_n.next_sibling = Some(child); } } @@ -323,12 +316,12 @@ pub impl AbstractNode { impl DebugMethods for AbstractNode { // Dumps the subtree rooted at this node, for debugging. - pure fn dump(&self) { + fn dump(&self) { self.dump_indent(0); } // Dumps the node tree, for debugging, with indentation. - pure fn dump_indent(&self, indent: uint) { + fn dump_indent(&self, indent: uint) { let mut s = ~""; for uint::range(0u, indent) |_i| { s += ~" "; @@ -345,7 +338,7 @@ impl DebugMethods for AbstractNode { } } - pure fn debug_str(&self) -> ~str { + fn debug_str(&self) -> ~str { // Unsafe due to the call to type_id(). unsafe { fmt!("%?", self.type_id()) @@ -354,14 +347,14 @@ impl DebugMethods for AbstractNode { } impl Node { - static pub unsafe fn as_abstract_node(node: ~N) -> AbstractNode { + pub unsafe fn as_abstract_node(node: ~N) -> AbstractNode { // This surrenders memory management of the node! AbstractNode { obj: transmute(node), } } - static pub fn new(type_id: NodeTypeId) -> Node { + pub fn new(type_id: NodeTypeId) -> Node { Node { wrapper: WrapperCache::new(), type_id: type_id, @@ -384,13 +377,13 @@ pub fn define_bindings(compartment: @mut Compartment, doc: @mut Document, win: @ bindings::element::init(compartment); bindings::utils::initialize_global(compartment.global_obj.ptr); let mut unused = false; - fail_unless!(codegen::ClientRectBinding::DefineDOMInterface(compartment.cx.ptr, - compartment.global_obj.ptr, - &mut unused)); - fail_unless!(codegen::ClientRectListBinding::DefineDOMInterface(compartment.cx.ptr, - compartment.global_obj.ptr, - &mut unused)); - fail_unless!(codegen::HTMLCollectionBinding::DefineDOMInterface(compartment.cx.ptr, - compartment.global_obj.ptr, - &mut unused)); + assert!(codegen::ClientRectBinding::DefineDOMInterface(compartment.cx.ptr, + compartment.global_obj.ptr, + &mut unused)); + assert!(codegen::ClientRectListBinding::DefineDOMInterface(compartment.cx.ptr, + compartment.global_obj.ptr, + &mut unused)); + assert!(codegen::HTMLCollectionBinding::DefineDOMInterface(compartment.cx.ptr, + compartment.global_obj.ptr, + &mut unused)); } diff --git a/src/servo/dom/window.rs b/src/servo/dom/window.rs index cc82730c2c0..35df464edb3 100644 --- a/src/servo/dom/window.rs +++ b/src/servo/dom/window.rs @@ -1,6 +1,6 @@ use content::content_task::{ControlMsg, Timer, ExitMsg}; use dom::bindings::utils::WrapperCache; -use js::jsapi::{JSVal, JSObject}; +use js::jsapi::JSVal; use util::task::spawn_listener; use core::comm::{Port, Chan}; diff --git a/src/servo/engine.rs b/src/servo/engine.rs index e195c3b2f56..3ff803c229f 100644 --- a/src/servo/engine.rs +++ b/src/servo/engine.rs @@ -1,4 +1,4 @@ -use content::content_task::{ContentTask, ExecuteMsg, ParseMsg, ExitMsg}; +use content::content_task::{ContentTask, ExecuteMsg, ParseMsg}; use content::content_task; use dom::event::Event; use layout::layout_task; diff --git a/src/servo/html/cssparse.rs b/src/servo/html/cssparse.rs index c8858809c85..a973f822428 100644 --- a/src/servo/html/cssparse.rs +++ b/src/servo/html/cssparse.rs @@ -5,13 +5,11 @@ Some little helpers for hooking up the HTML parser with the CSS parser use resource::resource_task::{ResourceTask, ProgressMsg, Load, Payload, Done}; use core::cell::Cell; -use core::comm::{Port, Chan}; -use core::pipes; +use core::comm::Port; use core::str; use newcss::stylesheet::Stylesheet; use newcss::util::DataStream; use std::net::url::Url; -use std::net::url; /// Where a style sheet comes from. pub enum StylesheetProvenance { diff --git a/src/servo/html/hubbub_html_parser.rs b/src/servo/html/hubbub_html_parser.rs index 2268de6c7ed..74035533dcb 100644 --- a/src/servo/html/hubbub_html_parser.rs +++ b/src/servo/html/hubbub_html_parser.rs @@ -1,19 +1,16 @@ -use content::content_task::ContentTask; use dom::element::*; -use dom::event::{Event, ReflowEvent}; use dom::node::{AbstractNode, Comment, Doctype, Element, ElementNodeTypeId, Node, Text}; use html::cssparse::{InlineProvenance, StylesheetProvenance, UrlProvenance, spawn_css_parser}; use newcss::stylesheet::Stylesheet; use resource::image_cache_task::ImageCacheTask; use resource::image_cache_task; use resource::resource_task::{Done, Load, Payload, ResourceTask}; -use util::task::{spawn_listener, spawn_conversation}; +use util::task::spawn_conversation; use core::cell::Cell; use core::comm::{Chan, Port, SharedChan}; use core::str::eq_slice; use gfx::util::url::make_url; -use hubbub::hubbub::Attribute; use hubbub::hubbub; use std::net::url::Url; use std::net::url; @@ -21,11 +18,11 @@ use std::net::url; macro_rules! handle_element( ($tag:expr, $string:expr, $ctor:ident, $type_id:expr) => ( if eq_slice($tag, $string) { - let element = ~$ctor { + let _element = ~$ctor { parent: Element::new($type_id, ($tag).to_str()) }; unsafe { - return Node::as_abstract_node(element); + return Node::as_abstract_node(_element); } } ) @@ -34,12 +31,12 @@ macro_rules! handle_element( macro_rules! handle_heading_element( ($tag:expr, $string:expr, $ctor:ident, $type_id:expr, $level:expr) => ( if eq_slice($tag, $string) { - let element = ~HTMLHeadingElement { + let _element = ~HTMLHeadingElement { parent: Element::new($type_id, ($tag).to_str()), level: $level }; unsafe { - return Node::as_abstract_node(element); + return Node::as_abstract_node(_element); } } ) @@ -65,14 +62,14 @@ struct HtmlParserResult { trait NodeWrapping { unsafe fn to_hubbub_node(self) -> hubbub::NodeDataPtr; - static unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr) -> Self; + unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr) -> Self; } impl NodeWrapping for AbstractNode { unsafe fn to_hubbub_node(self) -> hubbub::NodeDataPtr { cast::transmute(self) } - static unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr) -> AbstractNode { + unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr) -> AbstractNode { cast::transmute(n) } } @@ -221,7 +218,6 @@ pub fn parse_html(url: Url, }; let css_chan = SharedChan(css_chan); - let resource_task2 = resource_task.clone(); // Spawn a JS parser to receive JavaScript. let resource_task2 = resource_task.clone(); let (js_port, js_chan): (Port, Chan) = @@ -231,7 +227,7 @@ pub fn parse_html(url: Url, }; let js_chan = SharedChan(js_chan); - let url = @url; + let url2 = url.clone(), url3 = url.clone(); unsafe { // Build the root node. @@ -247,7 +243,7 @@ pub fn parse_html(url: Url, // consists of processing inline stylesheets, but in the future it might perform // prefetching, etc. let css_chan2 = css_chan.clone(); - let append_hook: @fn(AbstractNode, AbstractNode) = |parent_node, child_node| { + let append_hook: ~fn(AbstractNode, AbstractNode) = |parent_node, child_node| { if parent_node.is_style_element() && child_node.is_text() { debug!("found inline CSS stylesheet"); let url = url::from_str("http://example.com/"); // FIXME @@ -261,7 +257,7 @@ pub fn parse_html(url: Url, }; let (css_chan2, js_chan2) = (css_chan.clone(), js_chan.clone()); - parser.set_tree_handler(@hubbub::TreeHandler { + parser.set_tree_handler(~hubbub::TreeHandler { create_comment: |data: ~str| { debug!("create comment"); unsafe { @@ -310,7 +306,7 @@ pub fn parse_html(url: Url, (Some(rel), Some(href)) => { if rel == ~"stylesheet" { debug!("found CSS stylesheet: %s", href); - let url = make_url(href.to_str(), Some(copy *url)); + let url = make_url(href.to_str(), Some(url2.clone())); css_chan2.send(CSSTaskNewFile(UrlProvenance(url))); } } @@ -324,7 +320,7 @@ pub fn parse_html(url: Url, match src_opt { None => {} Some(src) => { - let img_url = make_url(src, Some(copy *url)); + let img_url = make_url(src, Some(url2.clone())); image_element.image = Some(copy img_url); // inform the image cache to load this, but don't store a handle. // TODO (Issue #84): don't prefetch if we are within a