Bug 1334579: Ensure constructors for nsStyleContentData run. r=bholley

MozReview-Commit-ID: 9Y6tQ6BD2c8
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2017-01-28 00:05:16 +01:00
parent b5c94bad37
commit a5bc898c21
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 15 additions and 12 deletions

View file

@ -644,7 +644,8 @@ extern "C" {
pub fn Gecko_DropElementSnapshot(snapshot: ServoElementSnapshotOwned);
}
extern "C" {
pub fn Gecko_ClearStyleContents(content: *mut nsStyleContent);
pub fn Gecko_ClearAndResizeStyleContents(content: *mut nsStyleContent,
how_many: u32);
}
extern "C" {
pub fn Gecko_CopyStyleContentsFrom(content: *mut nsStyleContent,

View file

@ -2692,7 +2692,7 @@ clip-path
use properties::longhands::content::computed_value::T;
use properties::longhands::content::computed_value::ContentItem;
use gecko_bindings::structs::nsStyleContentType::*;
use gecko_bindings::bindings::Gecko_ClearStyleContents;
use gecko_bindings::bindings::Gecko_ClearAndResizeStyleContents;
// Converts a string as utf16, and returns an owned, zero-terminated raw buffer.
fn as_utf16_and_forget(s: &str) -> *mut u16 {
@ -2704,19 +2704,21 @@ clip-path
ptr
}
// Ensure destructors run, otherwise we could leak.
if !self.gecko.mContents.is_empty() {
unsafe {
Gecko_ClearStyleContents(&mut self.gecko);
}
}
match v {
T::none |
T::normal => {}, // Do nothing, already cleared.
T::normal => {
// Ensure destructors run, otherwise we could leak.
if !self.gecko.mContents.is_empty() {
unsafe {
Gecko_ClearAndResizeStyleContents(&mut self.gecko, 0);
}
}
},
T::Content(items) => {
// NB: set_len also reserves the appropriate space.
unsafe { self.gecko.mContents.set_len(items.len() as u32) }
unsafe {
Gecko_ClearAndResizeStyleContents(&mut self.gecko,
items.len() as u32);
}
for (i, item) in items.into_iter().enumerate() {
// TODO: Servo lacks support for attr(), and URIs.
// NB: Gecko compares the mString value if type is not image