mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
auto merge of #4928 : yodalee/servo/issue4906-fix-characterdata-substringdata, r=jdm
issue #4906 Fix substringData function, and add a test case for all function in characterdata.
This commit is contained in:
commit
55f7636549
3 changed files with 49 additions and 11 deletions
|
@ -77,11 +77,11 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Length(self) -> u32 {
|
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> {
|
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 {
|
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 {
|
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 {
|
if offset > length {
|
||||||
return Err(IndexSize);
|
return Err(IndexSize);
|
||||||
}
|
}
|
||||||
|
@ -107,9 +107,9 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
|
||||||
} else {
|
} else {
|
||||||
count
|
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(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;
|
*self.data.borrow_mut() = data;
|
||||||
// FIXME: Once we have `Range`, we should implement step7 to step11
|
// FIXME: Once we have `Range`, we should implement step7 to step11
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
44
tests/content/test_characterdata.html
Normal file
44
tests/content/test_characterdata.html
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="harness.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>This is the character data</p>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
var a = document.getElementsByTagName('p')[0].childNodes[0];
|
||||||
|
is(a.data, "This is the character data");
|
||||||
|
// append test utf8
|
||||||
|
a.appendData(", append more 資料,測試資料");
|
||||||
|
is(a.data, "This is the character data, append more 資料,測試資料");
|
||||||
|
|
||||||
|
// length test utf8
|
||||||
|
is(a.length, 47);
|
||||||
|
|
||||||
|
// insert test non-utf8
|
||||||
|
a.insertData(26, " test");
|
||||||
|
is(a.data, "This is the character data test, append more 資料,測試資料");
|
||||||
|
// insert test utf8
|
||||||
|
a.insertData(48, "更多");
|
||||||
|
is(a.data, "This is the character data test, append more 資料,更多測試資料");
|
||||||
|
|
||||||
|
// delete test non-utf8
|
||||||
|
a.deleteData(40, 5);
|
||||||
|
is(a.data, "This is the character data test, append 資料,更多測試資料");
|
||||||
|
// delete test utf8
|
||||||
|
a.deleteData(45, 2);
|
||||||
|
is(a.data, "This is the character data test, append 資料,更多資料");
|
||||||
|
|
||||||
|
// replace test non-utf8
|
||||||
|
a.replaceData(33, 6, "other");
|
||||||
|
is(a.data, "This is the character data test, other 資料,更多資料");
|
||||||
|
// replace test non-utf8
|
||||||
|
a.replaceData(44, 2, "文字");
|
||||||
|
is(a.data, "This is the character data test, other 資料,更多文字");
|
||||||
|
|
||||||
|
// substring test non-utf8
|
||||||
|
is(a.substringData(12, 4), "char");
|
||||||
|
// substring test utf8
|
||||||
|
is(a.substringData(39, 2), "資料");
|
||||||
|
</script>
|
||||||
|
</html>
|
|
@ -132,12 +132,6 @@
|
||||||
[detachedXmlTextNode.wholeText]
|
[detachedXmlTextNode.wholeText]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[detachedForeignComment.length]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[detachedXmlComment.length]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[paras[0\].previousElementSibling]
|
[paras[0\].previousElementSibling]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue