mirror of
https://github.com/servo/servo.git
synced 2025-10-08 20:49:24 +01:00
Move Error, Fallible, ErrorResult out of utils.rs (fixes #1749)
This commit is contained in:
parent
82b74a373a
commit
5c5cb3e9a7
80 changed files with 125 additions and 116 deletions
45
src/components/script/dom/bindings/error.rs
Normal file
45
src/components/script/dom/bindings/error.rs
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue