Move WebIDL methods to traits implemented by JSRef types.

This commit is contained in:
Josh Matthews 2014-04-10 21:29:54 -04:00
parent dfdda0098a
commit 76783b029e
106 changed files with 3644 additions and 1912 deletions

View file

@ -64,9 +64,15 @@ impl Reflectable for DOMException {
}
}
impl DOMException {
pub trait DOMExceptionMethods {
fn Code(&self) -> u16;
fn Name(&self) -> DOMString;
fn Message(&self) -> DOMString;
}
impl<'a> DOMExceptionMethods for JSRef<'a, DOMException> {
// http://dom.spec.whatwg.org/#dom-domexception-code
pub fn Code(&self) -> u16 {
fn Code(&self) -> u16 {
match self.code {
// http://dom.spec.whatwg.org/#concept-throw
EncodingError => 0,
@ -75,12 +81,12 @@ impl DOMException {
}
// http://dom.spec.whatwg.org/#error-names-0
pub fn Name(&self) -> DOMString {
fn Name(&self) -> DOMString {
self.code.to_str()
}
// http://dom.spec.whatwg.org/#error-names-0
pub fn Message(&self) -> DOMString {
fn Message(&self) -> DOMString {
match self.code {
IndexSizeError => ~"The index is not in the allowed range.",
HierarchyRequestError => ~"The operation would yield an incorrect node tree.",