Bug 1358966 - Use assign_utf8 to set servo's string into nsAString. r?emilio draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 08 Jun 2017 12:19:50 +0900
changeset 590785 54f4d08a360fd34b4f2a068ccffe8fbd5e85b3d2
parent 590784 02ae44675daafdf2aa100f3373ea8b49b80f681f
child 590786 158367c7a1a88b233ed00475088fb96f9918dd0b
push id62829
push userhikezoe@mozilla.com
push dateThu, 08 Jun 2017 03:39:35 +0000
reviewersemilio
bugs1358966
milestone55.0a1
Bug 1358966 - Use assign_utf8 to set servo's string into nsAString. r?emilio MozReview-Commit-ID: oOaEgOeMEu
servo/ports/geckolib/glue.rs
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -550,17 +550,18 @@ pub extern "C" fn Servo_AnimationValue_S
                                                  buffer: *mut nsAString)
 {
     let uncomputed_value = AnimationValue::as_arc(&value).uncompute();
     let mut string = String::new();
     let rv = PropertyDeclarationBlock::with_one(uncomputed_value, Importance::Normal)
         .single_value_to_css(&get_property_id_from_nscsspropertyid!(property, ()), &mut string);
     debug_assert!(rv.is_ok());
 
-    write!(unsafe { &mut *buffer }, "{}", string).expect("Failed to copy string");
+    let buffer = unsafe { buffer.as_mut().unwrap() };
+    buffer.assign_utf8(&string);
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_AnimationValue_GetOpacity(value: RawServoAnimationValueBorrowed)
      -> f32
 {
     let value = AnimationValue::as_arc(&value);
     if let AnimationValue::Opacity(opacity) = **value {
@@ -1648,17 +1649,18 @@ pub extern "C" fn Servo_DeclarationBlock
     property_id: nsCSSPropertyID, buffer: *mut nsAString)
 {
     let property_id = get_property_id_from_nscsspropertyid!(property_id, ());
     read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
         let mut string = String::new();
         let rv = decls.single_value_to_css(&property_id, &mut string);
         debug_assert!(rv.is_ok());
 
-        write!(unsafe { &mut *buffer }, "{}", string).expect("Failed to copy string");
+        let buffer = unsafe { buffer.as_mut().unwrap() };
+        buffer.assign_utf8(&string);
     })
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_SerializeFontValueForCanvas(
     declarations: RawServoDeclarationBlockBorrowed,
     buffer: *mut nsAString) {
     use style::properties::shorthands::font;
@@ -1671,17 +1673,18 @@ pub extern "C" fn Servo_SerializeFontVal
                 return;
             }
         };
 
         let mut string = String::new();
         let rv = longhands.to_css_for_canvas(&mut string);
         debug_assert!(rv.is_ok());
 
-        write!(unsafe { &mut *buffer }, "{}", string).expect("Failed to copy string");
+        let buffer = unsafe { buffer.as_mut().unwrap() };
+        buffer.assign_utf8(&string);
     })
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_DeclarationBlock_Count(declarations: RawServoDeclarationBlockBorrowed) -> u32 {
     read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
         decls.declarations().len() as u32
     })