diff options
author | Bruno de Oliveira Abinader <bruno.d@partner.samsung.com> | 2014-01-28 18:36:03 -0400 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno.d@partner.samsung.com> | 2014-01-29 14:58:22 -0400 |
commit | 0c6de1bb3489073448b60142aa19758cba765052 (patch) | |
tree | 8620af58a67a1c2ad68ebcfcef356c6b481259aa /src | |
parent | 6c63de1c03a99d55d1718829f9ba23dd09c69b54 (diff) | |
download | servo-0c6de1bb3489073448b60142aa19758cba765052.tar.gz servo-0c6de1bb3489073448b60142aa19758cba765052.zip |
Basic skeleton for DOMException
Spec:
http://dom.spec.whatwg.org/#domexception
This is a subtask for #1542.
Diffstat (limited to 'src')
-rw-r--r-- | src/components/script/dom/bindings/codegen/Bindings.conf | 4 | ||||
-rw-r--r-- | src/components/script/dom/domexception.rs | 105 | ||||
-rw-r--r-- | src/components/script/dom/webidls/DOMException.webidl | 47 | ||||
-rw-r--r-- | src/components/script/script.rc | 1 |
4 files changed, 157 insertions, 0 deletions
diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index 5ce384201a1..98d6ef23dd3 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -160,6 +160,10 @@ DOMInterfaces = { ], }, +'DOMException': { + 'nativeType': 'DOMException', +}, + 'DOMImplementation': { 'nativeType': 'DOMImplementation', }, diff --git a/src/components/script/dom/domexception.rs b/src/components/script/dom/domexception.rs new file mode 100644 index 00000000000..ba38943a6ed --- /dev/null +++ b/src/components/script/dom/domexception.rs @@ -0,0 +1,105 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use dom::bindings::codegen::DOMExceptionBinding; +use dom::bindings::utils::DOMString; +use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; +use dom::window::Window; + +#[repr(uint)] +#[deriving(ToStr)] +enum DOMErrorName { + IndexSizeError = 1, + HierarchyRequestError = 3, + WrongDocumentError = 4, + InvalidCharacterError = 5, + NoModificationAllowedError = 7, + NotFoundError = 8, + NotSupportedError = 9, + InvalidStateError = 11, + SyntaxError = 12, + InvalidModificationError = 13, + NamespaceError = 14, + InvalidAccessError = 15, + SecurityError = 18, + NetworkError = 19, + AbortError = 20, + URLMismatchError = 21, + QuotaExceededError = 22, + TimeoutError = 23, + InvalidNodeTypeError = 24, + DataCloneError = 25, + EncodingError +} + +pub struct DOMException { + code: DOMErrorName, + reflector_: Reflector +} + +impl DOMException { + pub fn new_inherited(code: DOMErrorName) -> DOMException { + DOMException { + code: code, + reflector_: Reflector::new() + } + } + + pub fn new(window: &Window, code: DOMErrorName) -> @mut DOMException { + reflect_dom_object(@mut DOMException::new_inherited(code), window, DOMExceptionBinding::Wrap) + } +} + +impl Reflectable for DOMException { + fn reflector<'a>(&'a self) -> &'a Reflector { + &self.reflector_ + } + + fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { + &mut self.reflector_ + } +} + +impl DOMException { + // http://dom.spec.whatwg.org/#dom-domexception-code + pub fn Code(&self) -> u16 { + match self.code { + // http://dom.spec.whatwg.org/#concept-throw + EncodingError => 0, + _ => self.code as u16 + } + } + + // http://dom.spec.whatwg.org/#error-names-0 + pub fn Name(&self) -> DOMString { + self.code.to_str() + } + + // http://dom.spec.whatwg.org/#error-names-0 + pub 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.", + WrongDocumentError => ~"The object is in the wrong document.", + InvalidCharacterError => ~"The string contains invalid characters.", + NoModificationAllowedError => ~"The object can not be modified.", + NotFoundError => ~"The object can not be found here.", + NotSupportedError => ~"The operation is not supported.", + InvalidStateError => ~"The object is in an invalid state.", + SyntaxError => ~"The string did not match the expected pattern.", + InvalidModificationError => ~"The object can not be modified in this way.", + NamespaceError => ~"The operation is not allowed by Namespaces in XML.", + InvalidAccessError => ~"The object does not support the operation or argument.", + SecurityError => ~"The operation is insecure.", + NetworkError => ~"A network error occurred.", + AbortError => ~"The operation was aborted.", + URLMismatchError => ~"The given URL does not match another URL.", + QuotaExceededError => ~"The quota has been exceeded.", + TimeoutError => ~"The operation timed out.", + InvalidNodeTypeError => ~"The supplied node is incorrect or has an incorrect ancestor for this operation.", + DataCloneError => ~"The object can not be cloned.", + EncodingError => ~"The encoding operation (either encoded or decoding) failed." + } + } +} diff --git a/src/components/script/dom/webidls/DOMException.webidl b/src/components/script/dom/webidls/DOMException.webidl new file mode 100644 index 00000000000..7347d2e76cc --- /dev/null +++ b/src/components/script/dom/webidls/DOMException.webidl @@ -0,0 +1,47 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is: + * http://dom.spec.whatwg.org/#domexception + */ + +// XXXkhuey this is an 'exception', not an interface, but we don't have any +// parser or codegen mechanisms for dealing with exceptions. +interface DOMException { + const unsigned short INDEX_SIZE_ERR = 1; + const unsigned short DOMSTRING_SIZE_ERR = 2; // historical + const unsigned short HIERARCHY_REQUEST_ERR = 3; + const unsigned short WRONG_DOCUMENT_ERR = 4; + const unsigned short INVALID_CHARACTER_ERR = 5; + const unsigned short NO_DATA_ALLOWED_ERR = 6; // historical + const unsigned short NO_MODIFICATION_ALLOWED_ERR = 7; + const unsigned short NOT_FOUND_ERR = 8; + const unsigned short NOT_SUPPORTED_ERR = 9; + const unsigned short INUSE_ATTRIBUTE_ERR = 10; // historical + const unsigned short INVALID_STATE_ERR = 11; + const unsigned short SYNTAX_ERR = 12; + const unsigned short INVALID_MODIFICATION_ERR = 13; + const unsigned short NAMESPACE_ERR = 14; + const unsigned short INVALID_ACCESS_ERR = 15; + const unsigned short VALIDATION_ERR = 16; // historical + const unsigned short TYPE_MISMATCH_ERR = 17; // historical; use JavaScript's TypeError instead + const unsigned short SECURITY_ERR = 18; + const unsigned short NETWORK_ERR = 19; + const unsigned short ABORT_ERR = 20; + const unsigned short URL_MISMATCH_ERR = 21; + const unsigned short QUOTA_EXCEEDED_ERR = 22; + const unsigned short TIMEOUT_ERR = 23; + const unsigned short INVALID_NODE_TYPE_ERR = 24; + const unsigned short DATA_CLONE_ERR = 25; + + // Error code as u16 + readonly attribute unsigned short code; + + // The name of the error code (ie, a string repr of |code|) + readonly attribute DOMString name; + + // A custom message set by the thrower. + readonly attribute DOMString message; +}; diff --git a/src/components/script/script.rc b/src/components/script/script.rc index dd2eff22e95..dcb6061b286 100644 --- a/src/components/script/script.rc +++ b/src/components/script/script.rc @@ -55,6 +55,7 @@ pub mod dom { pub mod document; pub mod documentfragment; pub mod documenttype; + pub mod domexception; pub mod domimplementation; pub mod domparser; pub mod element; |