aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authoryodalee <lc85301@gmail.com>2015-02-14 01:03:44 +0800
committeryodalee <lc85301@gmail.com>2015-02-28 10:21:36 +0800
commit0e29eabb879a7bbd7194b161cc023c2791d732ec (patch)
treee94790a345f08c63b0c65cbd49b91cd8014cf7a5 /components/script
parente45b104721540d75e628f3ff7dda0e9a9ba5492b (diff)
downloadservo-0e29eabb879a7bbd7194b161cc023c2791d732ec.tar.gz
servo-0e29eabb879a7bbd7194b161cc023c2791d732ec.zip
fix function on utf8 string, pass two tests
dom/nodes/Node-properties.html detachedForeignComment.length] detachedXmlComment.length]
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/characterdata.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs
index 9fc2f5ec0ff..b7703e7e72a 100644
--- a/components/script/dom/characterdata.rs
+++ b/components/script/dom/characterdata.rs
@@ -77,11 +77,11 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
}
fn Length(self) -> u32 {
- self.data.borrow().len() as u32
+ self.data.borrow().chars().count() as u32
}
fn SubstringData(self, offset: u32, count: u32) -> Fallible<DOMString> {
- Ok(self.data.borrow()[offset as usize .. count as usize].to_owned())
+ Ok(self.data.borrow().slice_chars(offset as usize, (offset + count) as usize).to_owned())
}
fn AppendData(self, arg: DOMString) -> ErrorResult {
@@ -98,7 +98,7 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
}
fn ReplaceData(self, offset: u32, count: u32, arg: DOMString) -> ErrorResult {
- let length = self.data.borrow().len() as u32;
+ let length = self.data.borrow().chars().count() as u32;
if offset > length {
return Err(IndexSize);
}
@@ -107,9 +107,9 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
} else {
count
};
- let mut data = self.data.borrow()[..offset as usize].to_owned();
+ let mut data = self.data.borrow().slice_chars(0, offset as usize).to_owned();
data.push_str(arg.as_slice());
- data.push_str(&self.data.borrow()[(offset + count) as usize..]);
+ data.push_str(&self.data.borrow().slice_chars((offset + count) as usize, length as usize));
*self.data.borrow_mut() = data;
// FIXME: Once we have `Range`, we should implement step7 to step11
Ok(())