Skip to content

Commit

Permalink
Implement CharacterData.{deleteData, insertData, replaceData}
Browse files Browse the repository at this point in the history
  • Loading branch information
lpy committed Apr 20, 2014
1 parent bb8a037 commit fd95413
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/script/dom/bindings/error.rs
Expand Up @@ -9,6 +9,7 @@ use js::glue::{ReportError};

#[deriving(Show)]
pub enum Error {
IndexSize,
FailureUnknown,
NotFound,
HierarchyRequest,
Expand Down
28 changes: 27 additions & 1 deletion src/components/script/dom/characterdata.rs
Expand Up @@ -6,7 +6,7 @@

use dom::bindings::codegen::InheritTypes::CharacterDataDerived;
use dom::bindings::js::JS;
use dom::bindings::error::{Fallible, ErrorResult};
use dom::bindings::error::{Fallible, ErrorResult, IndexSize};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
Expand Down Expand Up @@ -59,6 +59,32 @@ impl CharacterData {
self.data.push_str(arg);
Ok(())
}

pub fn InsertData(&mut self, offset: u32, arg: DOMString) -> ErrorResult {
self.ReplaceData(offset, 0, arg)
}

pub fn DeleteData(&mut self, offset: u32, count: u32) -> ErrorResult {
self.ReplaceData(offset, count, ~"")
}

pub fn ReplaceData(&mut self, offset: u32, count: u32, arg: DOMString) -> ErrorResult {
let length = self.data.len() as u32;
if offset > length {
return Err(IndexSize);
}
let count = if offset + count > length {
length - offset
} else {
count
};
let mut data = self.data.slice(0, offset as uint).to_owned();
data.push_str(arg);
data.push_str(self.data.slice((offset + count) as uint, length as uint));
self.data = data;
// FIXME: Once we have `Range`, we should implement step7 to step11
Ok(())
}
}

impl Reflectable for CharacterData {
Expand Down
6 changes: 6 additions & 0 deletions src/components/script/dom/webidls/CharacterData.webidl
Expand Up @@ -17,6 +17,12 @@ interface CharacterData : Node {
DOMString substringData(unsigned long offset, unsigned long count);
[Throws]
void appendData(DOMString data);
[Throws]
void insertData(unsigned long offset, DOMString data);
[Throws]
void deleteData(unsigned long offset, unsigned long count);
[Throws]
void replaceData(unsigned long offset, unsigned long count, DOMString data);
};

//CharacterData implements ChildNode;

5 comments on commit fd95413

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging lpy/servo/issue2190 = fd95413 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lpy/servo/issue2190 = fd95413 merged ok, testing candidate = 3c175c7

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 3c175c7

Please sign in to comment.