use webcore::value::Reference;
use webapi::error::{IError, Error};
pub trait IDomException: IError {}
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(instance_of = "DOMException")]
#[reference(subclass_of(Error))]
pub struct DomException( Reference );
impl IError for DomException {}
impl IDomException for DomException {}
error_boilerplate! { DomException }
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct HierarchyRequestError( Reference );
impl IError for HierarchyRequestError {}
impl IDomException for HierarchyRequestError {}
error_boilerplate! { HierarchyRequestError, name = "HierarchyRequestError" }
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct InvalidAccessError( Reference );
impl IError for InvalidAccessError {}
impl IDomException for InvalidAccessError {}
error_boilerplate! { InvalidAccessError, name = "InvalidAccessError" }
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct NotFoundError( Reference );
impl IError for NotFoundError {}
impl IDomException for NotFoundError {}
error_boilerplate! { NotFoundError, name = "NotFoundError" }
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct SecurityError( Reference );
impl IError for SecurityError {}
impl IDomException for SecurityError {}
error_boilerplate! { SecurityError, name = "SecurityError" }
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct SyntaxError( Reference );
impl IError for SyntaxError {}
impl IDomException for SyntaxError {}
error_boilerplate! { SyntaxError, name = "SyntaxError" }
#[derive(Clone, Debug, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct IndexSizeError( Reference );
impl IError for IndexSizeError {}
impl IDomException for IndexSizeError {}
error_boilerplate! { IndexSizeError, name = "IndexSizeError" }
#[derive(Clone, Debug, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct InvalidStateError( Reference );
impl IError for InvalidStateError {}
impl IDomException for InvalidStateError {}
error_boilerplate! { InvalidStateError, name = "InvalidStateError" }
#[derive(Clone, Debug, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct TypeError( Reference );
impl IError for TypeError {}
impl IDomException for TypeError {}
error_boilerplate! { TypeError, name = "TypeError" }
#[derive(Clone, Debug, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct NotSupportedError( Reference );
impl IError for NotSupportedError {}
impl IDomException for NotSupportedError {}
error_boilerplate! { NotSupportedError, name = "NotSupportedError" }
#[cfg(all(test, feature = "web_test"))]
mod test {
use super::*;
use webcore::try_from::TryInto;
fn new_dom_exception(message: &str, name: &str) -> DomException {
js!(
return new DOMException(@{message}, @{name});
).try_into().unwrap()
}
#[test]
fn test_error() {
let name = "HierarchyRequestError";
let err: DomException = new_dom_exception("foo", name);
let err: HierarchyRequestError = err.try_into().expect("Expected HierarchyRequestError");
assert_eq!(err.name(), name);
let err: DomException = new_dom_exception("foo", name);
let err: Result<SyntaxError, _> = err.try_into();
assert!(err.is_err());
}
}