aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/error.rs
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2014-02-28 03:10:44 -0500
committerbors-servo <release+servo@mozilla.com>2014-02-28 03:10:44 -0500
commit83ff59e5f14b3f8a69c27a6d43cb9e04f0f0eb5c (patch)
treec74e56e1cf9d90921d9dd453ba52d5d618d7d132 /src/components/script/dom/bindings/error.rs
parent82b74a373a404c334ae711ec78dd4d06690f2cbb (diff)
parent5c5cb3e9a724508956791c8b3089fd2c40e7fe2d (diff)
downloadservo-83ff59e5f14b3f8a69c27a6d43cb9e04f0f0eb5c.tar.gz
servo-83ff59e5f14b3f8a69c27a6d43cb9e04f0f0eb5c.zip
auto merge of #1773 : sawrubh/servo/issue1749, r=Ms2ger
Diffstat (limited to 'src/components/script/dom/bindings/error.rs')
-rw-r--r--src/components/script/dom/bindings/error.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/components/script/dom/bindings/error.rs b/src/components/script/dom/bindings/error.rs
new file mode 100644
index 00000000000..8ea949b28f6
--- /dev/null
+++ b/src/components/script/dom/bindings/error.rs
@@ -0,0 +1,45 @@
+/* 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 js::jsapi::{JSContext, JSBool};
+use js::jsapi::{JS_IsExceptionPending};
+
+use js::glue::{ReportError};
+
+#[deriving(ToStr)]
+pub enum Error {
+ FailureUnknown,
+ NotFound,
+ HierarchyRequest,
+ InvalidCharacter,
+ NotSupported,
+ InvalidState,
+ NamespaceError
+}
+
+pub type Fallible<T> = Result<T, Error>;
+
+pub type ErrorResult = Fallible<()>;
+
+pub fn throw_method_failed_with_details<T>(cx: *JSContext,
+ result: Result<T, Error>,
+ interface: &'static str,
+ member: &'static str) -> JSBool {
+ assert!(result.is_err());
+ assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
+ let message = format!("Method failed: {}.{}", interface, member);
+ message.with_c_str(|string| {
+ unsafe { ReportError(cx, string) };
+ });
+ return 0;
+}
+
+pub fn throw_not_in_union(cx: *JSContext, names: &'static str) -> JSBool {
+ assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
+ let message = format!("argument could not be converted to any of: {}", names);
+ message.with_c_str(|string| {
+ unsafe { ReportError(cx, string) };
+ });
+ return 0;
+}