auto merge of #5099 : Ms2ger/servo/exceptions, r=saneyuki

This commit is contained in:
bors-servo 2015-02-28 11:09:55 -07:00
commit 5eaf1144c3
6 changed files with 60 additions and 64 deletions

View file

@ -4643,7 +4643,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::codegen::{PrototypeList, RegisterBindings, UnionTypes}',
'dom::bindings::codegen::Bindings::*',
'dom::bindings::error::{Fallible, Error, ErrorResult}',
'dom::bindings::error::Error::FailureUnknown',
'dom::bindings::error::Error::JSFailed',
'dom::bindings::error::throw_dom_exception',
'dom::bindings::error::throw_type_error',
'dom::bindings::proxyhandler',
@ -4812,14 +4812,14 @@ class CGCallback(CGClass):
setupCall = ("let s = CallSetup::new(self, aExceptionHandling);\n"
"if s.get_context().is_null() {\n"
" return Err(FailureUnknown);\n"
" return Err(JSFailed);\n"
"}\n")
bodyWithThis = string.Template(
setupCall+
"let thisObjJS = wrap_call_this_object(s.get_context(), thisObj);\n"
"if thisObjJS.is_null() {\n"
" return Err(FailureUnknown);\n"
" return Err(JSFailed);\n"
"}\n"
"return ${methodName}(${callArgs});").substitute({
"callArgs" : ", ".join(argnamesWithThis),
@ -4948,7 +4948,7 @@ class CallbackMember(CGNativeMember):
jsObjectsArePtr=True)
# We have to do all the generation of our body now, because
# the caller relies on us throwing if we can't manage it.
self.exceptionCode= "return Err(FailureUnknown);"
self.exceptionCode = "return Err(JSFailed);"
self.body = self.getImpl()
def getImpl(self):
@ -5078,7 +5078,7 @@ class CallbackMember(CGNativeMember):
"CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling);\n"
"JSContext* cx = s.get_context();\n"
"if (!cx) {\n"
" return Err(FailureUnknown);\n"
" return Err(JSFailed);\n"
"}\n")
def getArgcDecl(self):
@ -5123,7 +5123,7 @@ class CallbackMethod(CallbackMember):
" ${argc}, ${argv}, &mut rval)\n"
"};\n"
"if ok == 0 {\n"
" return Err(FailureUnknown);\n"
" return Err(JSFailed);\n"
"}\n").substitute(replacements)
class CallCallback(CallbackMethod):
@ -5160,7 +5160,7 @@ class CallbackOperationBase(CallbackMethod):
}
getCallableFromProp = string.Template(
'match self.parent.get_callable_property(cx, "${methodName}") {\n'
' Err(_) => return Err(FailureUnknown),\n'
' Err(_) => return Err(JSFailed),\n'
' Ok(callable) => callable,\n'
'}').substitute(replacements)
if not self.singleOperation:
@ -5204,7 +5204,7 @@ class CallbackGetter(CallbackMember):
}
return string.Template(
'if (!JS_GetProperty(cx, mCallback, "${attrName}", &rval)) {\n'
' return Err(FailureUnknown);\n'
' return Err(JSFailed);\n'
'}\n').substitute(replacements);
class CallbackSetter(CallbackMember):
@ -5230,7 +5230,7 @@ class CallbackSetter(CallbackMember):
return string.Template(
'MOZ_ASSERT(argv.length() == 1);\n'
'if (!JS_SetProperty(cx, mCallback, "${attrName}", ${argv})) {\n'
' return Err(FailureUnknown);\n'
' return Err(JSFailed);\n'
'}\n').substitute(replacements)
def getArgcDecl(self):

View file

@ -6,7 +6,9 @@
use dom::bindings::conversions::ToJSValConvertible;
use dom::bindings::global::GlobalRef;
use dom::domexception::DOMException;
use dom::domexception::{DOMException, DOMErrorName};
use util::str::DOMString;
use js::jsapi::{JSContext, JSBool, JSObject};
use js::jsapi::{JS_IsExceptionPending, JS_SetPendingException, JS_ReportPendingException};
@ -22,38 +24,42 @@ use std::ptr;
/// DOM exceptions that can be thrown by a native DOM method.
#[derive(Debug, Clone)]
pub enum Error {
/// IndexSizeError
/// IndexSizeError DOMException
IndexSize,
/// NotFoundError
/// NotFoundError DOMException
NotFound,
/// HierarchyRequestError
/// HierarchyRequestError DOMException
HierarchyRequest,
/// InvalidCharacterError
/// InvalidCharacterError DOMException
InvalidCharacter,
/// NotSupportedError
/// NotSupportedError DOMException
NotSupported,
/// InvalidStateError
/// InvalidStateError DOMException
InvalidState,
/// SyntaxError
/// SyntaxError DOMException
Syntax,
/// NamespaceError
/// NamespaceError DOMException
NamespaceError,
/// InvalidAccessError
/// InvalidAccessError DOMException
InvalidAccess,
/// SecurityError
/// SecurityError DOMException
Security,
/// NetworkError
/// NetworkError DOMException
Network,
/// AbortError
/// AbortError DOMException
Abort,
/// TimeoutError
/// TimeoutError DOMException
Timeout,
/// DataCloneError
/// DataCloneError DOMException
DataClone,
/// NoModificationAllowedError
/// NoModificationAllowedError DOMException
NoModificationAllowedError,
/// Unknown failure
FailureUnknown,
/// TypeError JavaScript Error
TypeError(DOMString),
/// A JavaScript exception is already pending.
JSFailed,
}
/// The return type for IDL operations that can throw DOM exceptions.
@ -67,7 +73,29 @@ pub type ErrorResult = Fallible<()>;
pub fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef,
result: Error) {
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
let exception = DOMException::new_from_error(global, result).root();
let code = match result {
Error::IndexSize => DOMErrorName::IndexSizeError,
Error::NotFound => DOMErrorName::NotFoundError,
Error::HierarchyRequest => DOMErrorName::HierarchyRequestError,
Error::InvalidCharacter => DOMErrorName::InvalidCharacterError,
Error::NotSupported => DOMErrorName::NotSupportedError,
Error::InvalidState => DOMErrorName::InvalidStateError,
Error::Syntax => DOMErrorName::SyntaxError,
Error::NamespaceError => DOMErrorName::NamespaceError,
Error::InvalidAccess => DOMErrorName::InvalidAccessError,
Error::Security => DOMErrorName::SecurityError,
Error::Network => DOMErrorName::NetworkError,
Error::Abort => DOMErrorName::AbortError,
Error::Timeout => DOMErrorName::TimeoutError,
Error::DataClone => DOMErrorName::DataCloneError,
Error::NoModificationAllowedError => DOMErrorName::NoModificationAllowedError,
Error::TypeError(message) => {
throw_type_error(cx, &message);
return;
}
Error::JSFailed => panic!(),
};
let exception = DOMException::new(global, code).root();
let thrown = exception.to_jsval(cx);
unsafe {
JS_SetPendingException(cx, thrown);